Wrong rotation?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
kallaspriit
Posts: 27
Joined: Thu Sep 15, 2005 3:22 pm

Wrong rotation?

Post 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:
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post 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
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
kallaspriit
Posts: 27
Joined: Thu Sep 15, 2005 3:22 pm

Post 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
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post 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
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post 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);
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
kallaspriit
Posts: 27
Joined: Thu Sep 15, 2005 3:22 pm

Post 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
kallaspriit
Posts: 27
Joined: Thu Sep 15, 2005 3:22 pm

Post by kallaspriit »

Still cant figure it out, any ideas anyone? :cry:
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post 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);
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
kallaspriit
Posts: 27
Joined: Thu Sep 15, 2005 3:22 pm

Post by kallaspriit »

Thank you, working now :)
Guest

Post by Guest »

can you tell me where you got the tutorial from?
or at least the full code for the camera?
thanks
Post Reply