Page 1 of 1

Wrong rotation?

Posted: Wed Jan 04, 2006 10:53 am
by kallaspriit
I'm trying to implement 3rd person camera for a vehicle and I ran into problems calculating the right angle. I did some testing and found out that I'm getting the wrong rotation values of a node on the Y axis (up).

Here's a picture to demonstrate my problem:
Image

And here's the code from some tutorial:

Code: Select all

int cOffset = 180;
int cZoom = 5;
int cDist = 3;

core::matrix4 transformation = n->getAbsoluteTransformation(); 

core::vector3df p = transformation.getTranslation();
core::vector3df r = transformation.getRotationDegrees();
//core::vector3df r = n->getRotation(); // same

std::cout << "ROT: " << r.Y << std::endl;

camNode->setTarget(p);
camNode->setPosition(core::vector3df(( -1 * cZoom * cos( -1 * ( r.Y + cOffset ) * 3.14159265/180 ) ) + p.X,p.Y+cDist,( -1 * cZoom * sin( -1 * ( r.Y + cOffset ) * 3.14159265/180 ) ) + p.Z));
Where am I going wrong? :cry:

Posted: Wed Jan 04, 2006 11:49 am
by bitplane
hmm I'm no expert but it looks like a bug to me.
edit: maybe we're missing something, cos it does this at least back to irrlicht 0.11

Posted: Wed Jan 04, 2006 5:39 pm
by kallaspriit
Anyone else has any idea? It's such a basic building block of Irrlicht that I dont belive that it has never been working.. I must be missing something :P

Posted: Wed Jan 04, 2006 6:44 pm
by bitplane
aha! I see it. change your cout line to-
std::cout << "ROT= X: " << r.X << "Y: " << r.Y << "Z:" << r.Z << std::endl;

X and Z are flipping between 0 and 180, which makes sense I guess. you're getting the transformation in 3d but setting the rotation in 2d. I guess I'd transform a vector with the matrix, then work out the angle 2d trig

Posted: Wed Jan 04, 2006 7:38 pm
by bitplane
this works

Code: Select all

       
        f32 camZoom = 5;
        core::vector3df camDist = core::vector3df(0,0,3.0f) * camZoom;
        core::vector3df camRot(0,90,0);
        
        core::matrix4 transformation = anms->getAbsoluteTransformation();
        core::vector3df p = transformation.getTranslation();
        
        core::vector3df r = transformation.getRotationDegrees();
        transformation.setRotationDegrees(r+camRot);
        transformation.rotateVect(camDist);
        
        camNode->setTarget(p);
        camNode->setPosition(p + camDist);

Posted: Wed Jan 04, 2006 11:03 pm
by kallaspriit
Thanks alot for the help, you've almoust got it!

The problem is that for 180 degrees it shows the car from the back (as it should) and the rest of the 180 degrees it shows it from the front.

I guess during the first half round I should be adding the camRot (as it's currently done) and substract it the other half but I haven't managed to figure out when is it the first half and when the other so no luck.

I should also say that I'm a bit new to matrixes and 3d vectors :P

Posted: Thu Jan 05, 2006 7:38 pm
by kallaspriit
Still cant figure it out, any ideas anyone? :cry:

Posted: Fri Jan 06, 2006 4:03 pm
by bitplane
doh! i guess if we don't get matrices we shouldn't mess around with them. ;)
use another matrix for the rotation instead of messing with the existing one.

Code: Select all

    f32 camZoom = 5;
    core::vector3df camDist = core::vector3df(0,0,5.0f) * camZoom;
    core::vector3df camRot(0,-90,0);

    core::matrix4 rotation;
    rotation.setRotationDegrees(camRot); 
    rotation.rotateVect(camDist);

    core::matrix4 transformation = anms->getAbsoluteTransformation();
    transformation.transformVect(camDist);
        
    camNode->setTarget(transformation.getTranslation());
    camNode->setPosition(camDist);

Posted: Sun Jan 08, 2006 2:23 pm
by kallaspriit
Thank you, working now :)

Posted: Wed Feb 08, 2006 11:07 pm
by Guest
can you tell me where you got the tutorial from?
or at least the full code for the camera?
thanks