Deadline and i'm desperate,this should be Easy for you pros

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

Deadline and i'm desperate,this should be Easy for you pros

Post by Elazul »

Before anyone tells me to search the forums, i have, and everything i've found is either out of date (irrlicht 1.2 and below) or irrelevant, or is someone asking just like me and not getting an answer, or has a solution that just doesn't work.I've looked into the IcameraScenenodeFPS and tried to mimic it to my own controls, and it more or less behaves in the exact same manner as the code below, so i've done my homework. i've reached a dead end and for the love of all that is sacred and decent i need the help of someone who has a clue what the problems are since i can't seem to find a logical error.


OK for the ...9th time i believe now, here's the problem
i'm making a custom fps camera so therefore i'm using a standard icamerascenenode and manipulating it myself

i'm using a CUSTOM input event handler and not the Irrlicht one, therefore using cursors and such is out of the question

1- now the following code SHOULD make me walk forward however the character reaches a certain point then stops, after tracing i've realized that the camTarget.X starts becomming smaller than the camPosition.X, and i cannot understand why.
changing the line to make camTarget.X+=5000*FwdDirection.X;
didn't work even and camTarget.X still stays smaller.

another glitch is if i'm looking upwards or so, it'll sometimes change my p.o.v to face forward again.

can someone PLEASE tell me what's wrong? here's the code that's placed under the event handler for moving forward.
core::vector3df UpDirection;
core::vector3df FwdDirection;
core::vector3df RgtDirection;
core::vector3df camTarget =camera->getTarget();
core::vector3df camPosition = camera->getPosition() ;

FwdDirection= camTarget-camPosition;
FwdDirection.normalize();

camPosition.X+=1000*FwdDirection.X;
camPosition.Z+=1000*FwdDirection.Z;

camTarget.X+=1000*FwdDirection.X;
camTarget.Z+=1000*FwdDirection.Z;


camera->setPosition(camPosition);
camera->setTarget(camTarget);
2- second problem, strafing, again it SHOULD work however it ends up rotating the camera again , with no understanding of why it does that , the code is as follows that's placed under the event handler for moving to the right

///Rady Note: obtain the initial details
UpDirection=camera->getUpVector();
UpDirection.normalize();
FwdDirection= camTarget-camPosition;
FwdDirection.normalize();
RgtDirection= FwdDirection.crossProduct(UpDirection);
////End initial details obtaining

//Rady note Changing position

camPosition.X+=1000*RgtDirection.X;
camPosition.Z+=1000*RgtDirection.Z;

camTarget.X+=1000*RgtDirection.X;
camTarget.Z+=1000*RgtDirection.Z;


camera->setPosition(camPosition);
camera->setTarget(camTarget);


//// end Changing Position




////////////////Rady Note: End Right Strafing Code///////////
again what am i doing wrong? someone PLEASE tell me , my deadline is DEADLY soon.
mhack
Posts: 38
Joined: Sun Apr 01, 2007 2:13 am
Location: Montana, USA

Post by mhack »

Well, I'm no pro, but I have implemented something similar to what you seem to be trying. If you are both rotating and translating your camera, you may need to convert the directions in the camera frame to the world frame. I don't know if my way is the best way, but here is how I do it. Consider the following situation:

Image

In the image above, the red, green and blue lines represent the world frame x, y and z axes, coming out of the origin, which has a cube located there. My CameraSceneNode is approximately located at (10,0,0) and is looking at the origin as its target.

Now, consider the local camera frame +x direction (local frame: (1,0,0), pointing to the right of the screen). What is this vector in the world frame? According to the image, it is (0,0,1), the +z world-frame direction. Similarly, the camera frame +z is pointing away from the viewer, into the screen. Its world-frame direction is (-1,0,0), the direction of the world frame -x axis.

When doing your setTarget and camera setPosition, you must use world-frame directions, or everything will get weird. But how to convert from the local camera frame to the world frame? The trick that I learned is to use some columns of the 4x4 transform matrix. If you look at the print out of the two matrices in the image, the upper one is the absolute transform of the CameraSceneNode (camera->getAbsoluteTransformation()) and the lower one is the camera view matrix (camera->getViewMatrix() ).

If you look carefully, you can see that the matrix gives you the world-frame directions of your current camera view frame. If we number the matrix as

Code: Select all

m00  m01  m02  m03
m10  m11  m12  m13
m20  m21  m22  m23
m30  m31  m32  m33
Then the world-frame x-direction of the camera is (m00, m10, m20) (in the image above, (-0.03, 0, 1)) and the world-frame z-direction of the camera is (m02,m12,m22) (in the image above: (-0.99, -0.1, -0.03)).

So try using those world-frame directions for manipulating your camera. I also found it necessary to call camera->updateAbsolutePosition() and camera->OnRegisterSceneNode() first, to make sure you are really using the current transform and view frame matrices.

Hope that helps and good luck on your deadline.
Post Reply