I also don't understand the dot product. What is the intention?
In java the * operator is not working for quaternions that's why i used the getDotProduct function;
---
But I'm sorry, but i still can't get it working
I changed the HelloWorld tutorial a bit to make the code small and easy to read. But the ball is just moving a little but no real rotation. I really tried everything, changed every value to get a better rotation, tried to switch rotation = rotation * current; to rotation = current * rotation; without effect. I've no idea anymore, in you're example it looks good to understand but I can't get it working the way it should be.
I've uploaded a zip with the c file, exe, model and irrlicht.dll in it:
http://www.yourfilelink.com/get.php?fid=79362
This is my complete test file: (switched back from java to c to test this)
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
#pragma comment(lib, "Irrlicht.lib")
int main()
{
//Setup irrlicht
IrrlichtDevice *device = createDevice(EDT_SOFTWARE, dimension2d<s32>(640, 480), 16, false, false, false, 0);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
smgr->addCameraSceneNode(0, vector3df(0,10,-100), vector3df(0,5,0));
//Load the model
device->getFileSystem()->addZipFileArchive("Ball2.zip");
IAnimatedMesh* mesh = smgr->getMesh("Ball2.3DS");
ISceneNode* node = smgr->addOctTreeSceneNode(mesh->getMesh(0));
node->setPosition( core::vector3df(0,0,0) );
while(device->run())
{
// Get the balls current rotation and convert it to a quaternion
vector3df euler = node->getRotation();
quaternion current(euler.X, euler.Y, euler.Z);
// Create the rotation to be applied from the angle/axis
// IMPORTANT: Axis has to be normalised.
vector3df axis = vector3df(0.75f, 0.0f, 0.75f);
axis.normalize();
quaternion rotation;
rotation.fromAngleAxis(0.1f * 3.14f, axis);
// Apply the new ortation to the current orientation
// Not sure here, might be rotation = current * rotation;
// Quaternion mulitplication is not commutative
rotation = rotation * current;
// convert to euler angles and apply result to node
rotation.toEuler(euler);
node->setRotation(euler);
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
I hope you could take some time to look at the code for one more time, i will be very happy if the example should work normally.