Jump to content
• Advertisement

#### Archived

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

# moving something in 3d by position and direction

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

If you intended to correct an error in the post then please contact us.

## 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 this post

##### Share on other sites
Advertisement
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 this post

##### 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 this post

##### 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 this post

##### 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)...

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
18
• Advertisement

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009805
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!