picking - sending ray from camera, depending on mouse coords

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
Melsiu
Posts: 3
Joined: Sun May 30, 2010 10:11 am

picking - sending ray from camera, depending on mouse coords

Post by Melsiu »

Hi..
I am working on first person shooter game engine, i need to create ray from camera. I know only camera's angle, origin, and the screen coordinates of mouse cursor. Do anyone know how can I calculate the ray direction?
thanks in advance[/u]
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

Code: Select all

// from mouse coordinates:
core::vector2d<s32> mousePos( X, Y);
core::line3d<f32> yourRay = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(mousePos, yourCameraOrNorhingForActiveCamHere);
Your ray direction in this case is core::vector3df dir = (ray.end - ray.start).normalize();
But usually you want to shoot from the screen center, so you can directly use camera +z vector. Please take a look at the irrlicht-1.7.1\examples\07.Collision to have some better explanation. As a whole, you can use the collision demo as a base.

Please post such questions in the "Beginner`s help" section. Thank you and good luck! See ya around... :wink:
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
Melsiu
Posts: 3
Joined: Sun May 30, 2010 10:11 am

Post by Melsiu »

uhm...
I asked for the mathematical solution for my problem, and not for the irrlicht funtion name .
nvm Ill check out the source of getRayFromScreenCoordinates...
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

In that case this is the wrong forum, moving to games forum.
Post Reply