Hi All,
If I'm looking at a spot in space, how do I get the x,z coordinates of the intersection of the Mouse cursor on the Y-Plane set at 0??
Thx in Advance.
How do I Get the X,Z Coordinate from the Mouse Position
ehm, what??
get 2d mouse position:
get 3d mouse position:
i hope that can help you
get 2d mouse position:
Code: Select all
position2d<s32> position = yourCursorControl->getPosition();
Code: Select all
vector3df get3DCursorPosition(ITriangleSelector* TriangleSelector, ICursorControl* CursorControl, ISceneManager* SceneManager)
{
vector3df Result;
triangle3df Triangle;
line3d<f32> Ray;
Ray = SceneManager->getSceneCollisionManager()->
getRayFromScreenCoordinates(CursorControl->getPosition(),
SceneManager->getActiveCamera());
CollisionManager->getCollisionPoint(Ray, TriangleSelector, Result, Triangle);
return Result;
}
well it sorta pointed me in the right direction, and after looking around the internet, I came up with this,
Which gives me the X,Z coordinates on the Y-Plane without having any scene nodes created yet.
Code: Select all
bool Runner::OnEvent( SEvent event ){
bool retValue = false;
if( event.EventType == EET_MOUSE_INPUT_EVENT ){
if( event.MouseInput.Event == EMIE_MOUSE_MOVED ) {
ray = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(
position2d<s32>(event.MouseInput.X, event.MouseInput.Y) );
point = lineIntersectWithPlane( ray, vector3df(0,0,0), vector3df(0,1,0) );
retValue=true;
}
}
return retValue;
}
vector3df Runner::lineIntersectWithPlane( line3d<f32> S, vector3df origin, vector3df Pn ) {
vector3df u = S.end - S.start;
vector3df w = S.start - origin;
float D = Pn.dotProduct(u);
float N = -Pn.dotProduct(w);
if(fabs(D) < 0.00000001) {
if (N == 0)
return vector3df(0,0,0);
else
return vector3df(0,0,0);
}
float sI = N / D;
if (sI < 0 || sI > 1)
return vector3df(0,0,0);
u.X *= sI;
u.Y *= sI;
u.Z *= sI;
return S.start + u;
}