if you do something like
Code: Select all
mySceneNode->setRotation(mySceneNode->getRotation()+vector3df(10,0,0));
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));
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;
}