position calculation problem

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
gammaray
Posts: 23
Joined: Wed Jun 28, 2006 9:38 pm

position calculation problem

Post by gammaray »

Hello, it's me again:)

I'm trying to implement a sort of chase cam, that stays sticky to it's target (effect: the target looks still, only the world rotates). I use the following code to calculate the camera position:
/* fix main cam stuff */
matrix4 mat = getSceneNode()->getRelativeTransformation();
matrix4 fixmat;
fixmat.setRotationDegrees(mat.getRotationDegrees());

// calculate cam position and target
vector3df lookat(0,0,(getSceneNode()->getBoundingBox().getExtent().Z + 1));
mat.transformVect(lookat);

// calculate cameras up vector
vector3df up(0,1,0);
fixmat.transformVect(up);
up.normalize();

vector3df campos(0,2,-3);
mat.transformVect(campos);

cams[E_CAMERA_FRONT]->setUpVector(up);
cams[E_CAMERA_FRONT]->setPosition(campos);
cams[E_CAMERA_FRONT]->setTarget(lookat);
Now in my app, the position and target get updated correctly, but there seem to be problems with the up vector - camera rotation doesn't match the rotation of the target.
What's strange, I use the same code in my other test app and it works like it should.
The main difference between both apps is that the first (not working) updates the camera from within a class method, the second one (working) updates the cam from within irrlicht main loop, without use of class methods - can it have any influence?

Any ideas what am I doing wrong?
Last edited by gammaray on Sun Aug 19, 2007 11:14 pm, edited 1 time in total.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

It should not matter if you do this in a class or in the main loop...
Sometimes I had problems with a camera when I changed the position and/or target of it and forgot to call updateAbsolutePosition on the camera afterwards, maybe this is your peoblem too...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
gammaray
Posts: 23
Joined: Wed Jun 28, 2006 9:38 pm

Re:

Post by gammaray »

The position itself seems to be ok, only the up vector gets screwed somehow.
I've checked the output of camera->getUpVector() and it seems to be updated correctly, but the cam behaves almost the same as with a non-transformed (0,1,0). And whats weird in the other app it behaves like it should while the only difference is the classes layout;/ Am' totally confused...
gammaray
Posts: 23
Joined: Wed Jun 28, 2006 9:38 pm

solved:)

Post by gammaray »

/* fix main cam stuff */
matrix4 mat;

mat.setTranslation(getSceneNode()->getAbsolutePosition());
mat.setRotationDegrees(getSceneNode()->getRotation());

matrix4 fixmat;
fixmat.setRotationDegrees(mat.getRotationDegrees());
Slight change in the code and it works now. I was convinced that mat = SceneNode->getAbsolute/RelativeTransformation should produce the same effect as the solution above? What's the difference? I'd be grateful for an explanation:) Cheers!
Nextor
Posts: 35
Joined: Wed Feb 16, 2005 9:06 am
Location: Madrid, SPAIN

Post by Nextor »

Wouldn't be simpler to create an empty node at/near the position of target and parented to it, and then, parent the camera to the empty node? So, your camera always follows the target, and if you want to rotate the camera around the target, you only have to rotate the empty node.
That's the way I did it in one of my projects.
Get away from her, you B*TCH !!! - Ellen Ripley
Post Reply