#### Archived

This topic is now archived and is closed to further replies.

# moving something in 3d by position and direction

This topic is 5147 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i need to move a point within 3d space, only knowing the position and direction the direction vector contains three values, x,y,z x and z are always 0, y determines the direction the point is facing (for example, and enemy in a first person shooter, facing north might be a direction.y of 0) i need to move the point forward, towards its direction... i know how to do this with a camera, because the camera has a View vector, but the point im trying to move does not have a view vector, and i want to know how to do this without having a view vector... your help is appreciated

##### Share on other sites
newpos.x = oldpos.x + direction.x*distance
newpos.y = oldpos.y + direction.y*distance
newpos.z = oldpos.z + direction.z*distance

:-? this what u wanted?

assuming the direction vector is of unit length...

##### Share on other sites
eh, i dont think thats it

the direction.x and direction.z is always 0

all direction does right now is determine how to rotate the model

glRotatef(direction.y,0,1,0);

but i need to make the model walk forward according to direction...

i have this, but it doesnt work correctly...

	void MoveMD2Forward(float speed)	{		float kspeed = speed * CalculateFrameRate();		Position.x+= (float)cos(Direction.y-1.57f) * kspeed;		Position.z+= (float)-sin(Direction.y-1.57f) *kspeed;	}

##### Share on other sites
i got it, had to convert into radians from degrees

void MoveMD2Forward(float speed)
{
float kspeed = speed * CalculateFrameRate();
float dir = (3.14 / 180) * Direction.y;
Position.x+= (float)cos(dir) * kspeed;
Position.z+= (float)-sin(dir) * kspeed;
}

##### Share on other sites
i think you are confused with the differences between a rotation vector and a direction vector...

direction vector points in the direction the object is moving (either of unit length or the length = to the distance u want to move by)...

rotation vector points in the direction of the rotation axis (the length of the vector could represent the rotation in radians i guess, but i think usually it is of unit length and then the rotation is specified seperatly)...

• ### Forum Statistics

• Total Topics
628705
• Total Posts
2984307

• 23
• 10
• 9
• 13
• 13