A Better Way to do 3D Movement?

Started by
4 comments, last by 31337 21 years, 4 months ago
Throughout my short and limited openGL career I have always used sine and cosine in order to do 3d movement, however this seems to be the hard way to do things. After reading through some tutorials on gamedev.net I see that they used vectors to move the camera in the height mapping tutorial. This brings up a lot of questions for me. Isn''t a vector a 3d point with its direction pointed out by its relation to the origin? How can I use vectors for 3d movement? What are some equations I should look up? Thanks a bunch.
OpenGL Revolutions http://students.hightechhigh.org/~jjensen/
Advertisement
A vector is simply a quantity that has both magnitude and direction. The magnitude can be the distance, e.g. of a point from the origin, or it could be speed or acceleration.

If the vector has the length of the distance from the origin and points in the direction from the origin it can be used to describe a point at that distance and direction from the origin. But that is just one use of a vector, not the definition of it.

As for using vectors for 3D motion, some equations you can use are

F = Ma, a = dv/dt, v = dx/dt

where F (force), a (acceleration), v (velocity) and x (displacement) are all vectors. The derivatives means you have to use integration to work with such equations.
John BlackburneProgrammer, The Pitbull Syndicate
Using OpenGL (or doing 3D graphics in general) without a solid understanding of vectors and matrices, i.e., linear algebra, is indeed the hard way of doing things. Fortunately, the basics are not hard to master and are well worth the time to learn. Get a good book and study up.
Well I''ve taken a physics class so I know all of those equations but my physics teature never showed us vectors in this respect. So is it possible to use vectors to replace sine and cosine for 3d movement? Thanks
OpenGL Revolutions http://students.hightechhigh.org/~jjensen/
Think about how you are using sin and cos. Say you are moving in a direction 45 degrees north of east at 50 mph. How far north and east do you travel in an hour? What about in a half hour? What about in two hours? Do you really have to calculate the sin and cos for each of those to figure it out? Couldn't you just find what it is in an hour and multiply by one half or two? That is how you use a vector.

Sorry, missed the part about 3D movement, but it works the same. In 3D you need two angles. So you are travelling 45 degrees north of east and climbing at an angle of 5 degrees above the horizontal. Your hypotheneous is still 50mph. 50mph*sin(5 degrees) tells your change in elevation. 50mph*cos(5 degrees) tells you your speed in the horizontal plane. 50mph*cos(5 degrees)*cos(45 degrees) tells you your speed east and 50mph*cos(5 degrees)*sin(45 degrees) tells you your speed north. Multiply those by time and you have your displacement over that period of time assuming your velocity is constant.

[edited by - LilBudyWizer on December 4, 2002 11:55:57 AM]
Keys to success: Ability, ambition and opportunity.
a [bold] free vector [/bold] refers to a vector which may be possisioned anywhere in space without loss or change of meaning provided that magnitude and direction are preserved. (such as speed)

a [bold] line vector [/bold] refers to a vector whcih along with a direction and magnitued, is also dependent on its line of action as far as determining its effects....

In physics, you prolly worked with free vectors(accelleretion, speed) much more than line vectors(such as possition, movement in time)...

a line using a vector takes this form,

Position = Start + (time)DistanceTraveled

where time goes from zero to one....

hopefully, this will get you started :-P
~~~~~Screaming Statue Software. | OpenGL FontLibWhy does Data talk to the computer? Surely he's Wi-Fi enabled... - phaseburn

This topic is closed to new replies.

Advertisement