(Before anyone complains, this isn't TorqueScript so it doesn't belong in Coding Help. That's for blockland coding only.)
I'm making some programs with OpenTK (which wraps OpenGL for Visual Basic and other C# languages.)
I have an object with three sets of variables:
-Location XYZ
-Rotation YawPitchRoll
-Velocity XYZ (shouldn't affect anything)
I want OpenGL to set the camera behind the object with its up vector being the object's up vector. But...
How do I get the up vector?
Edit: Okay, what I need to do is find a way to rotate a vector on a specific plane instead of the origin. Does anyone know how I can do this?
(GAME TICK SNIPPET)
'FIND THE FORWARDS VECTOR
'The forwards vector will be a 2-point vector representing the way the object is pointing
'First point is the object's transform, second point...
Dim forwardsVector = Pol2Cart(New OpenTK.Vector3(1, playerRotation.X, playerRotation.Y))
playerDispVector(5) = forwardsVector
'FIND THE UP VECTOR
'The up vector will be the forwards vector with an YZ (pitch) rotation of 90
Dim upVector = Cart2Pol(forwardsVector)
upVector = Pol2Cart(New OpenTK.Vector3(1, upVector.Y, upVector.Z + 90))
playerDispVector(4) = upVector
'FIND THE ROLL VECTOR
'The roll vector will alter the camera's angle on the XZ (roll) plane as well as the display of the object's 'wings'
(SUPPORT FUNCTIONS)
Function Cart2Pol(a As OpenTK.Vector3) As OpenTK.Vector3 'r-theta-pitch
Dim b As OpenTK.Vector3 = OpenTK.Vector3.Zero
b.X = Math.Sqrt(a.X ^ 2 + a.Y ^ 2 + a.Z ^ 2)
b.Y = Math.Atan2(a.Y, a.X)
b.Z = Math.Acos(a.Z / b.X)
Return b
End Function
Function Pol2dCart(a As OpenTK.Vector2) As OpenTK.Vector3 'x-y
a.Y = deg2rad(a.Y)
Dim b As OpenTK.Vector3 = OpenTK.Vector3.Zero
b.X = Math.Cos(a.Y) * a.X
b.Y = Math.Sin(a.Y) * a.X
Return b
End Function
Function Pol2Cart(a As OpenTK.Vector3) As OpenTK.Vector3 'x-y-z
a.Y = deg2rad(a.Y)
a.Z = deg2rad(a.Z)
Dim b As OpenTK.Vector3 = OpenTK.Vector3.Zero
b.X = Math.Sin(a.Z) * Math.Cos(a.Y) * a.X
b.Y = Math.Sin(a.Z) * Math.Sin(a.Y) * a.X
b.Z = Math.Cos(a.Z) * a.X
Return b
End Function
(RENDER TICK SNIPPET)
modelview = OpenTK.Matrix4.LookAt(playerTransform - playerDispVector(5), playerTransform, playerDispVector(4))