-
Does anyone have the functions to determine the x,y,z function of a vector based on its angle(s) in degrees? Basically, I'm playing around with objects moving in three dimensions (think 8-ball in space) and cant find the equations to figure out what to add to x,y and z based on the direction of the object.
-
This is a cut from my 3d-engine
The things here are:
position, an userdef-type
.x
.y
.z
alfa is the vertical angle
beta is the horisontal angle
v is the velocity
-------------------------
Sub flightsim() 'Flygsimulatorn förflyttar positionen
position.z = position.z + Sin(-alfa) * Cos(beta) * v
position.Y = position.Y + Cos(-alfa) * Cos(beta) * v
position.X = position.X + Sin(-beta) * v
alfa = alfa + alfav: beta = beta + betav
betav = betav * 0.95 'Friktion vid svängningar
alfav = alfav * 0.95
If alfa > 3.1415 Then alfa = alfa - 3.1415 * 2 '360 grader snurr lösning
If alfa < -3.1415 Then alfa = alfa + 3.1415 * 2
If beta > 3.1415 Then beta = beta - 3.1415 * 2
If beta < -3.1415 Then beta = beta + 3.1415 * 2
End Sub
--------------------------
Don't have time to modify it for your need, but try to get use of the three first lines. Don't bother to translate my swedish comments.
-
Thanks, but, it doesn't seem to be doing quite what I expected. How about this, on a 2d plane, the origin in the top left corner, what would one add to the x coordinate of an object if it was moving in a direction described by Q degrees, with Q=0 being the top of the plane, Q=180 being the bottom.
-
OK add R*Cos(Q/57.2958) to y and R* sin(Q/57.2958) to x
VB likes it's angles in radians which is why the 57.2958 is there.
-
Your code is commented in Swedish.
Is there a fellow Swede out there?
Myself, I live in Kungsbacka, south of Gothenbourgh.
Pentax