coordinates of the camera

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
chemi
Posts: 10
Joined: Wed Mar 14, 2007 5:57 pm

coordinates of the camera

Post by chemi »

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.
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

Do you mean that you want to move your node along camera-aligned xyz-axis? (sortof)
If you don't have anything nice to say, don't say anything at all.
chemi
Posts: 10
Joined: Wed Mar 14, 2007 5:57 pm

Post by chemi »

yes!.
can you say to me like doing it?


thanks. a greeting
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

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.
chemi
Posts: 10
Joined: Wed Mar 14, 2007 5:57 pm

Post by chemi »

thank you very much Luben. It already works.
Post Reply