Page 1 of 2
Help - Wheel Rotation
Posted: Sat Dec 11, 2010 11:35 pm
by kaliber
I have a wheel and i want to rotate it like a wheel
im doing Y rotation then if im doing the Z rotation it's like the Z1, i want it like the Z2. Any Help ??
Posted: Sun Dec 12, 2010 12:05 am
by CodeDragon
Hmm, Try to use the node->Rotate,
You can let it rotate with a simple loop.
Posted: Sun Dec 12, 2010 12:25 am
by kaliber
CodeDragon wrote:Hmm, Try to use the node->Rotate,
You can let it rotate with a simple loop.
yes i did, but its not rotate right.
when the wheel straight, the Z rotation make the whell spin clockwise. but when its not staight(Y r0tation) the wheell spin awfully.
Posted: Sun Dec 12, 2010 12:44 am
by Radikalizm
what you want is a local transformation
check out this thread
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=42036
Posted: Sun Dec 12, 2010 12:48 am
by kaliber
okay, finnaly
Posted: Sun Dec 12, 2010 12:59 am
by kaliber
err, now the code : Node->setRotation(..) is ignored
Posted: Sun Dec 12, 2010 2:45 am
by lazerblade
Are you talking about the line in my function or are you talking about applying the rotation yourself? Keep in mind that calling "setRotation" on a scene node is NOT local and is NOT affected by the node's current rotation.
BTW, it's great to see other people using this code.
Posted: Sun Dec 12, 2010 2:58 am
by kaliber
here's my code :
Code: Select all
if(rcv.IsKeyDown(KEY_KEY_D))
rotateNode(MyNode,vector3df(0,0.1f,0));
else
rotateNode(MyNode,vector3df(0,0,1));
i want the wheel turn when i press the D key, but it turn in wrong.
the wheel spin well when im not press the D key.
Posted: Sun Dec 12, 2010 3:06 am
by lazerblade
Hmmm...
You could try increasing the amount that the wheel turns along the Y axis,
0.1 won't go very fast.
I would try something like:
Code: Select all
if(rcv.IsKeyDown(KEY_KEY_D))
rotateNode(MyNode,vector3df(0,1,0));
else
rotateNode(MyNode,vector3df(0,0,1));
Posted: Sun Dec 12, 2010 3:20 am
by kaliber
it seem the Y Axis rotated by this code :
Code: Select all
rotateNode(MyNode,vector3df(0,0,1));
the speed is normal, i did change the 0.1f value to 1.
Posted: Sun Dec 12, 2010 3:28 am
by lazerblade
Uhm, actually the last parameter is the Z axis. But as long as you get the
effect you want, it doesn't matter.
I'm not sure I understand your problem perfectly, is the node rotating in the
wrong direction, wrong axis, or is it not rotating at all?
If it's rotating in the wrong direction, you could try negating the value like so:
Code: Select all
rotateNode(MyNode, vector3df(0,-0.1f,0))
Posted: Sun Dec 12, 2010 3:46 am
by kaliber
its rotating
but when its rotate in Z axis, the Y Axis rotated
Posted: Sun Dec 12, 2010 3:52 am
by lazerblade
Okay, I think I understand the problem then.
You see the XYZ axis', are relative to the mesh. They are completely unaffected by the global axis. So whatever got exported from the 3d modeler as the Y axis, will be preserved in Irrlicht.
So in short, your XYZ axis' might be different for every mesh/sceneNode. Try rotating along a different axis and see what happens.
BTW I'm online right now in the #irrlicht channel on irc.freenode.net, so you might want to join it there so that we both won't have to go through this agonizing pain and mental anguish of checking the forum again and again.
Posted: Sun Dec 12, 2010 4:01 am
by kaliber
hahaha
ok
Posted: Sun Dec 12, 2010 7:04 am
by kaliber
any help ???
i want to make the wheel spin while turning
here my whole code :
Code: Select all
#include <irrlicht.h>
#include "eventreceiver.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
/*
==========
rotateNode -- rotate a scene node locally
==========
*/
void rotateNode(irr::scene::ISceneNode *node, irr::core::vector3df rot)
{
irr::core::matrix4 m;
m = node->getAbsoluteTransformation();
irr::core::matrix4 n;
n.setRotationDegrees(rot);
m *=n;
node->setRotation(m.getRotationDegrees());
node->updateAbsolutePosition();
}
int main(){
IrrlichtDevice* device = createDevice(video::EDT_DIRECT3D9,dimension2d<u32>(800,600),32);
MyEventReceiver rcv;
device->setEventReceiver(&rcv);
ISceneManager* Mgr = device->getSceneManager();
IVideoDriver* Video = device->getVideoDriver();
IMeshSceneNode* Wheel= Mgr->addMeshSceneNode(Mgr->getMesh("ban.x"));
ICameraSceneNode* kamera = Mgr->addCameraSceneNodeFPS();//,vector3df(70,20,5),vector3df(0,0,0));
while(device->run()){
rotateNode(Wheel,vector3df(0,0,1));
rotateNode(Wheel,vector3df(0,1,0));
Video->beginScene(true,true,SColor(255,255,255,255));
Mgr->drawAll();
Video->endScene();
}
device->drop();
return 0;
}