!! Problem with getting position

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
lor
Posts: 22
Joined: Sat Aug 27, 2005 2:07 pm

!! Problem with getting position

Post by lor »

I want to place the camera in some place each time when i click. I mean, I want camera to move to the correct place. For example i click in A=(500,200) (my app's window is 800x600). I want the camera to move to that place, where I clicked. I wrote something like this:

Code: Select all

if(event.MouseInput.Event==EMIE_LMOUSE_PRESSED_DOWN) {
   pozycja_2d = device->getCursorControl()->getPosition();
   przes_x = static_cast<int>(pozycja_2d.X) - 400;
   przes_y = static_cast<int>(pozycja_2d.Y) - 300;
}
(...)
obecne_x = static_cast<int>(camera->getPosition().X);
obecne_y = static_cast<int>(camera->getPosition().Y);
camera->setPosition(vector3df((obecne_x + przes_x),500,(obecne_y + przes_y)));
camera->setTarget(vector3df((obecne_x + przes_x),0,(obecne_y + przes_y)));
przes_x = 0;
przes_y = 0;
But it doesn't work - the numbers it returns as przes_x and przes_y are somehow strange (they are never smaller then 0, and usually somewhere over 300000). Why does it happen?? I only know that it isn't coused by too big or too small values for int becouse I've counted it on the paper and all was ok (ofc they were between (-400, 400) and (-300, 300)).
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

your camera lives in 3d space, your mouse pointer in 2d space. you need to beam a ray out of your camera and see where it hits the mesh
have a look at the collision tutorial and also picking a point on the mesh in the wiki

also, you shouldnt be casting your f32s to ints because you lose accuracy
lor
Posts: 22
Joined: Sat Aug 27, 2005 2:07 pm

Post by lor »

Thank you for your answer but I think you didn't understand my intensions. I know that my camera is in 3d space and my screen is a 2d plane. I simply want to move my cammera in 2 planes and in 2 directions in each one. I mean, that if I click in some place at the screen, for example in (450,350) and my camera should move left 50 points left and 50 down. That's all. I think that it's possible to move my 3d camera in 2d space and leave its Z coordinate alone... But I simply don't know why my counts are wrong.

Or maybe I wrongly understood you :roll: :wink: If so, than try to explain it to me in another way, please :wink:

I know that this casting isn't very good but I think that it's simply necessary in this situation :roll:
Post Reply