Ray question

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
Valor
Posts: 40
Joined: Fri Jul 30, 2010 1:20 pm

Ray question

Post by Valor »

How would I have a ray not only from the camera but wherever the mouse in on the screen????? I edited the camera to allow a mode to free the mouse to be moved anywhere on the screen and I need to have a ray coming from wherever the mouse is on the screen...how do I do that? this is the code from the collision tutorial:

Code: Select all

		ray.start = camera->getPosition();
		ray.end = ray.start + (camera->getTarget() - ray.start).normalize() * 1000.0f;
how would i modify this to be a ray not only from the camera but also coming from where ever the mouse is on the screen???
blAaarg
Posts: 94
Joined: Tue Mar 02, 2010 9:11 pm
Location: SoCal

Post by blAaarg »

line3d<f32> irr::scene::ISceneCollisionManager::getRayFromScreenCoordinates ( const core::position2d< s32 > & pos, ICameraSceneNode * camera = 0 )
Use it like:

Code: Select all

position2di pos = device->getCursorControl()->getPosition();
line3df ray = collisionMgr->getRayFromScreenCoordinates(pos);
What you would do with/to the line depends. For other collisions you would just use it as a parameter when calling the other collision manager methods. The code you showed normalizes and scales the ray but whether you need to do that depends on what you want to do with the ray-under-the-cursor once you have it.
"Computers don't make mistakes! What they do they do on purpose!!"

-Dale Gribble
Valor
Posts: 40
Joined: Fri Jul 30, 2010 1:20 pm

Post by Valor »

Thank you!
Post Reply