Mouse collision

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Guest

Mouse collision

Post by Guest »

Hi, I've read all the stuff on 2d-to-3d and mouse collision on this board. But my program is still not working:

My mouse acts independently from the camera, the camera is aimed at the player. The below code doesn't work, as in I don't get any hits. If I use the intersection with the line (commented out bit), though, I get tons of hits.

Code: Select all

       line3d<f32> mouse3d = colmgr->getRayFromScreenCoordinates(Cursor_Position,camera);

        core::line3d<f32> line;
        line.start = Camera_Position;
        line.end = line.start + (camera->getTarget() - line.start).normalize() * 1000.0f;

        core::vector3df intersection;
        core::triangle3df tri;


        if(colmgr->getCollisionPoint(mouse3d, metaScene, intersection, tri))
//      if (smgr->getSceneCollisionManager()->getCollisionPoint(line, metaScene, intersection, tri))
 printf("Hit\n");
The mouse coordinates are given to me properly, so I think the problem must be in the getRayFromScreenCoordinates function. Any idea what it could be ??
kmh
Posts: 11
Joined: Tue Nov 02, 2004 1:36 pm
Location: Oxford, UK

Post by kmh »

Sorry, that was me. Not logged in ...

I've solved the problem, at least partially:

Changing

Code: Select all

colmgr->getRayFromScreenCoordinates(Cursor_Position,camera);
to

Code: Select all

colmgr->getRayFromScreenCoordinates(Cursor_Position);
does the job. I don't understand, why, though. How can my camera be different from the actual camera?
Just above the code posted earlier on, I have two lines:

Code: Select all

   camera->setTarget(Player_Position);
   camera->setPosition(Camera_Position);
Shouldn't the camera be the same as the "camera" ?
Post Reply