move node "forward" regarding direction

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.
Post Reply
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

move node "forward" regarding direction

Post by suliman »

Hi

I have spaceships like seen below. What would be a smart way to update their position in the world given i have a velocity and a direction? I can rotate the node according to the turn-speeds (turn,pitch,bank) but how would i thrust the node "forward", if this direction is defined by the current rotation?

Thanks for any tips
Erik

Code: Select all

class craft{
public:

	float vel;
	float fallSpeed;

	float turn;
	float pitch;
	float bank;

	vect3d pos;

	irr::scene::IAnimatedMeshSceneNode* node;

	void control();

	craft(){
		vel=0;
		fallSpeed=0;

		turn=0;
		pitch=0;
		bank=0;	
	}
};



void craft::control(){

	float acc=0.001f;
	float turnSpeed=1.0f;

	mydraw(0,10,30,"Vel : %.2f",vel);
	mydraw(0,10,50,"Turn : %.1f",turn);


		if(kh.keyDown(KEY_UP))
			vel+=acc;
		if(kh.keyDown(KEY_DOWN))
			vel-=acc;

		if(kh.keyDown(KEY_LEFT))
			turn-=turnSpeed;
		if(kh.keyDown(KEY_RIGHT))
			turn+=turnSpeed;
	

		//move
		howTo?


};

esaptonor
Posts: 145
Joined: Sat May 06, 2006 11:59 pm

Post by esaptonor »

well i dont know about 3d, but you can move them foward in 2 dimensions with the y rotation and some trigernometry.

Code: Select all

float myx = node->getPosition().X;
float myz = node->getPosition().Z;
float rot = node->getRotation().Y;
float toRadians = 3.141592654/180;
//
myz -= speed*sin((rot+90)*toRadians);
myx += speed*cos((rot+90)*toRadians);
//
node->setPosition(core::vector3df(myx, 0, myz));
the +90 may need to change depending on what direction your mesh faced to start with.


maybe you can figure out 3d movement from that?
nomad
Posts: 53
Joined: Thu Jan 05, 2006 12:35 pm
Location: Wales

Post by nomad »

You could rotate a unit vector to match the node orientation, then move along that vector, something like this:

Code: Select all

vector3df pos = node->getPosition();
vector3df rot = node->getRotation();

//get direction
matrix4 m;
m.setRotationDegrees(rot);
vector3df dir(0,0,1);
m.rotateVect(dir);
//now dir matches node orientation
pos += dir*somevalue;
node->setPosition(pos);
CodeDog
Posts: 106
Joined: Sat Oct 07, 2006 8:00 pm
Location: CA. USA
Contact:

Post by CodeDog »

If your camera is in your spaceship then you can use your look at point to get a vector to use as a thrust vector.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

look at "Move ship in space:" post:
http://irrlicht.sourceforge.net/phpBB2/ ... ght=flight
Post Reply