rotationconcept of irrlicht is inconsistent

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
rincewind
Posts: 35
Joined: Thu Mar 25, 2004 5:28 pm
Location: Germany --> Bonn

rotationconcept of irrlicht is inconsistent

Post by rincewind »

well, as the subject says: the way irrlicht implements rotation is inconsistent.
if you do something like

Code: Select all

mySceneNode->setRotation(mySceneNode->getRotation()+vector3df(10,0,0));
the scenenode rotates around it's own x-axis.
But if you try to do the same for the y-axis or the z-axis, eg:

Code: Select all

mySceneNode->setRotation(mySceneNode->getRotation()+vector3df(0,10,0));
the node rotates around the y-axis of it's parent. same for the z-axis.


you can test it with this little program:

Code: Select all

#include "irrlicht.h"

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;

matrix4 mat;
vector3df xAxis,yAxis,zAxis,pos;
ISceneNode *node = 0;

class MyEventReceiver : public IEventReceiver {
    bool OnEvent(SEvent event){
        if(event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown){
            /* press 'x' to rotate 10 degrees around x-axis */
            if(event.KeyInput.Key == irr::KEY_KEY_X){
                node->setRotation(node->getRotation()+vector3df(10,0,0));  
            }
            /* press 'y' to rotate 10 degrees around y-axis */
            if(event.KeyInput.Key == KEY_KEY_Y){
                node->setRotation(node->getRotation()+vector3df(0,10,0));
            }  
            /* press 'z' to rotate 10 degrees around z-axis */
            if(event.KeyInput.Key == KEY_KEY_Z){
                node->setRotation(node->getRotation()+vector3df(0,0,10));
            }    
            /* press 'r' to reset rotation */
            if(event.KeyInput.Key == KEY_KEY_R){
                node->setRotation(vector3df(0,0,0));
            }                    
        }    
        return false;
    }    
};    


int main(int argc, char *argv[])
{
  MyEventReceiver receiver;  
  IrrlichtDevice *device = createDevice(EDT_OPENGL,
                                        dimension2d<s32>(800,600),
                                        32,
                                        false,
                                        false,
                                        &receiver);
  ISceneManager *smgr = device->getSceneManager();
  IVideoDriver *driver = device->getVideoDriver();
  node = smgr->addTestSceneNode();
  smgr->addCameraSceneNodeFPS();

  matrix4 ident;
  ident.makeIdentity();
  while(device->run()){
        driver->beginScene(true,true,SColor(255,100,10,180));
        smgr->drawAll();
        /* compute the (relative) axes of the scenenode */
        mat = node->getAbsoluteTransformation();
        mat.makeInverse();
        xAxis.X = mat.M[0];
        xAxis.Y = mat.M[4];
        xAxis.Z = mat.M[8];
        yAxis.X = mat.M[1];
        yAxis.Y = mat.M[5];
        yAxis.Z = mat.M[9];
        zAxis.X = mat.M[2];
        zAxis.Y = mat.M[6];
        zAxis.Z = mat.M[10];
        pos = node->getAbsolutePosition();
        driver->setTransform(ETS_WORLD,ident);
        /* draw absolute axes in black */
        driver->draw3DLine(pos,vector3df(100,0,0)+pos,SColor(255,0,0,0));
        driver->draw3DLine(pos,vector3df(0,100,0)+pos,SColor(255,0,0,0));
        driver->draw3DLine(pos,vector3df(0,0,100)+pos,SColor(255,0,0,0));
        /* draw relative x-axis in red */
        driver->draw3DLine(pos,xAxis*100+pos,SColor(255,255,0,0));
        /* draw relative y-axis in green */
        driver->draw3DLine(pos,yAxis*100+pos,SColor(255,0,255,0));
        /* draw relative z-axis in white */
        driver->draw3DLine(pos,zAxis*100+pos,SColor(255,255,255,255));
        driver->endScene(); 
  }   
  device->drop();  
  return 0;
}
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Did not check out your test program, but this sounds strange to me. I'll try it out when I come home.
Post Reply