coordinates of the camera
coordinates of the camera
hello! I want to move a node by the screen with the mouse. This already I have obtained it but one moves in the coordinates of the scene and I want that she moves in the coordinates of the observer. Since I can do it? Thanks.
I could try. I don't think this solution will work when you'r facing straight up or down though.
Code: Select all
ISceneNode* TheNodeToMove; //The node you want to move
ICameraSceneNode* Cam;
vector3df CameraDirection;
vector3df CamUp; //The down(Or up) vector
vector3df CamRight; //The right (Or left, i don't know for sure =P)
vector3df CamInto; //CamInto could just be replaced with CameraDirection
const vector3df UpVec(0,1,0);
C=Device->getSceneManager()->getActiveCamera();
CameraDirection = Cam->getTarget() - Cam->getPosition();
CameraDrivetion.normalize();
CamInto = CameraDirection;
//The cross-product produces a vector that is pointing straight away from the plane the other two vectors form. When we do the cross of a (1,0,0) and a (0,1,0) we get a (0,0,±1) (± because i don't remember if we get a positive/negative vector right now, sortof ]=P )
CamRight = CamInto.crossProduct(UpVec);
CamUp = CamRight.crossProduct(CamInto);
f32 DeltaX;
f32 DeltaY;
vector3df NodePosition = TheNodeToMove->getPosition();
//Move Delta[X|Y] along the camera aligned axises.
NodePosition += (DeltaX * CamRight) + (DeltaY * CamUp);
TheNodeToMove->setPosition(NodePosition);
If you don't have anything nice to say, don't say anything at all.