Page 1 of 1

move node "forward" regarding direction

Posted: Mon Dec 18, 2006 9:28 pm
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?


};


Posted: Mon Dec 18, 2006 10:05 pm
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?

Posted: Mon Dec 18, 2006 10:44 pm
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);

Posted: Thu Dec 21, 2006 3:31 pm
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.

Posted: Thu Dec 21, 2006 5:15 pm
by arras
look at "Move ship in space:" post:
http://irrlicht.sourceforge.net/phpBB2/ ... ght=flight