Help - Wheel Rotation

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
kaliber
Posts: 117
Joined: Sat Jan 17, 2009 12:51 pm

Help - Wheel Rotation

Post by kaliber »

I have a wheel and i want to rotate it like a wheel :roll:

Image

im doing Y rotation then if im doing the Z rotation it's like the Z1, i want it like the Z2. Any Help ?? :lol:
CodeDragon
Posts: 10
Joined: Sun Oct 17, 2010 8:45 am
Location: Belgium

Post by CodeDragon »

Hmm, Try to use the node->Rotate,
You can let it rotate with a simple loop.
kaliber
Posts: 117
Joined: Sat Jan 17, 2009 12:51 pm

Post 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.
kaliber
Posts: 117
Joined: Sat Jan 17, 2009 12:51 pm

Post by kaliber »

Radikalizm wrote:what you want is a local transformation

check out this thread http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=42036
okay, finnaly 8) 8)
kaliber
Posts: 117
Joined: Sat Jan 17, 2009 12:51 pm

Post by kaliber »

err, now the code : Node->setRotation(..) is ignored
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post 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. :D
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
kaliber
Posts: 117
Joined: Sat Jan 17, 2009 12:51 pm

Post 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.
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post 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));
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
kaliber
Posts: 117
Joined: Sat Jan 17, 2009 12:51 pm

Post 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.
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post 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))
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
kaliber
Posts: 117
Joined: Sat Jan 17, 2009 12:51 pm

Post by kaliber »

its rotating

but when its rotate in Z axis, the Y Axis rotated

Image
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post 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. :lol:
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
kaliber
Posts: 117
Joined: Sat Jan 17, 2009 12:51 pm

Post by kaliber »

hahaha

ok
kaliber
Posts: 117
Joined: Sat Jan 17, 2009 12:51 pm

Post 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;
}
Post Reply