Hi all,
i have a little question about 2D projection :
I'm working with event.MouseInput, but the X and Y parameter of event.MouseInput is in screen coordinate... how can i cast a ray from camera for finding the projection of event.MouseInput.X and event.MouseInput.Y in the world coordinate (vector3df) of a BSP level ?
Thanks for your help and sorry for my bad english...
Regards.
cyb
PS : i don't want to use Camera->getTarget() because it's a customized camera
Hi,
Thanks for your response, but i can't use this function, why ?
Because i want to select more than one node with a dragging box (the dragging box is Draw2DRectangle), one the dragging box is choosed i want to check all node's coordinates to see if UpperLeft.X and LowerRight.X (UpperLeft.Y and LowerRight.Y too) is in my dragging box...
The only solution is to projectate the coordinates of my 2D dragging box in the 3D world... (or maybe inverse... project the 3D Coordinate of the nodes in my 2D screen coordinate.... someone have a better solution ?)
The main idea is :in the future, instead of having a 2DRectangle on the screen, i'll made a 3DBox for selecting node.
if i use getSceneNodeFromScreenCoordinatesBB and my dragging box is 150x150 pixels, i must call 22500 getSceneNodeFromScreenCoordinatesBB !
Take a look at the source code of getSceneNodeFromScreenCoordinatesBB(), in there a ray is created exaclty as you need it. I'll add a getRayFromScreenCoordinates in the next release. But until then, simply create the ray manually, like it is done in getSceneNodeFromScreenCoordinatesBB().
if (event.EventType==EET_MOUSE_INPUT_EVENT &&
event.MouseInput.Event==EMIE_LMOUSE_LEFT_UP)
{
drawSelected=false;
if (drawRect)
{
std::cerr<<"LEFT CLICKED UP"<<std::endl;
vector3df lowerRightCorner, upperLeftCorner;
lowerRightCorner = getSceneNodeFromScreenCoordinatesBB(position2d<s32>(event.MouseInput.X,event.MouseInput.Y),0);
upperLeftCorner = getSceneNodeFromScreenCoordinatesBB(position2d<s32>(selectionRect.UpperLeftCorner.X,selectionRect.UpperLeftCorner.Y),0);
std::cerr<<"UPPER LEFT X :"<<upperLeftCorner.X<<std::endl;
std::cerr<<"UPPER LEFT Z :"<<upperLeftCorner.Z<<std::endl;
std::cerr<<"LOWER RIGHT X :"<<lowerRightCorner.X<<std::endl;
std::cerr<<"LOWER RIGHT Z :"<<lowerRightCorner.Z<<std::endl;
std::cerr<<"NODE POSITION X :"<<node->getPosition().X<<std::endl;
std::cerr<<"NODE POSITION Z :"<<node->getPosition().Z<<std::endl;
if (node->getPosition().X<upperLeftCorner.X && node->getPosition().X>lowerRightCorner.X
&& node->getPosition().Z>lowerRightCorner.Z && node->getPosition().Z<upperLeftCorner.Z)
{
std::cerr<<"SELECTED"<<std::endl;
drawSelected=true;
}
}
else
{
if (smgr->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(position2d<s32>(event.MouseInput.X,event.MouseInput.Y),0))
{
std::cerr<<"SELECTED"<<std::endl;
drawSelected=true;
}
}
oldMouseInputX=0;
oldMouseInputY=0;
stayLClicked=false;
drawRect=false;