trying to create a colliding ray from an on screen cursor

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
Elazul
Posts: 38
Joined: Fri Mar 23, 2007 4:47 pm

trying to create a colliding ray from an on screen cursor

Post by Elazul »

i'm trying to use the position of an on screen cursor instead of the center of the screen for collision, the code i'm using (Based on what i understood from graphics programming is as follows) note that ms->pt.x and ms->pt.y is a custom input event handler code to point out where the mouse cursor is on screen at the moment.
core::line3d<f32> line;
core::matrix4 Proj,View;
Proj=camera->getProjectionMatrix();
View=camera->getViewMatrix();
Proj.makeInverse();
View.makeInverse();



core::vector3df S(ms->pt.x,ms->pt.y,0);
core::vector3df E(ms->pt.x,ms->pt.y,100);

Proj.transformVect( S, S );
S.Z=0;
Proj.transformVect( E, E );
E.Z=12000;
View.transformVect( S, S );
View.transformVect( E, E );
however, it's either NOT working, or the detection checks (red triangle, or models lightening up) is NOT working, so what's wrong?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The scene collision manager has a method for getting a ray from the camera position and a screen coordinate.

Travis
trivtn
Posts: 132
Joined: Tue Jan 17, 2006 12:30 pm
Location: Viet Nam
Contact:

Post by trivtn »

//Use as : (device is the Irrlicht device)
//get the mouse position
irr::core::vector3df pos = device->getCursorControl()->getPosition();
//get the line ray from the active camera to mouse position
irr::core::line3df ray = device->getSceneManager()->getSceneCollisionManager()->getRayFromScreenCoordinates(pos,0);
//finally get the scenceNode for collision
irr::scene::ISceneNode* node = device->getSceneManager()->getSceneCollisionManager()->getSceneNodeFromRayBB(ray);
There's something is fantastic, there's nothing is absolute.
Elazul
Posts: 38
Joined: Fri Mar 23, 2007 4:47 pm

Post by Elazul »

thanks trivtn
Post Reply