I want to control the camera direct via a direction vector.
Simply... its not working... the camera view flips when pointing directly up or directly down.
also
when the X axis is added to the equation it spirals the view sometimes....
There must be an easier way to use a direction vector to control the camera angle?
This is what Ive been trying (800x600 windowed)...
Simply... its not working... the camera view flips when pointing directly up or directly down.
also
when the X axis is added to the equation it spirals the view sometimes....
There must be an easier way to use a direction vector to control the camera angle?
This is what Ive been trying (800x600 windowed)...
Code (glbasic) Select
// View code
TYPE Tvector
x
y
z
magnitude
ENDTYPE
GLOBAL cam_pos AS Tvector; cam_pos.x = 0; cam_pos.y = 0; cam_pos.z = 0 // Camera position
GLOBAL cam_vec AS Tvector; cam_vec.x = 0; cam_vec.y = 0; cam_vec.z = 0 // Camera angle
// Mouse look along vector code...
MOUSESTATE mx, my, b1, b2
cam_vec.x = 0; cam_vec.y = 0; cam_vec.z = -1 // Initial view
mx=(mx/800)*3600 // Get an x rotation value
my=(my/600)*3600 // Get an y rotation value
cam_vec = Vector_RotateAroundY(cam_vec, mx/10) // Rotatate around x axis
cam_vec = Vector_RotateAroundX(cam_vec, my/10) // Rotate around y axis
X_CAMERA cam_pos.x, cam_pos.y, cam_pos.z, cam_vec.x, cam_vec.y, cam_vec.z
Functions from the vector lib.Code (glbasic) Select
FUNCTION Vector_RotateAroundX AS Tvector: vec1 AS Tvector, angle
LOCAL result AS Tvector
result.x = vec1.x
result.y = COS(angle) * vec1.y - SIN(angle) * vec1.z
result.z = SIN(angle) * vec1.y + COS(angle) * vec1.z
RETURN result
ENDFUNCTION
FUNCTION Vector_RotateAroundY AS Tvector: vec1 AS Tvector, angle
LOCAL result AS Tvector
result.x = COS(angle) * vec1.x + SIN(angle) * vec1.z
result.y = vec1.y
result.z = -SIN(angle) * vec1.x + COS(angle) * vec1.z
RETURN result
ENDFUNCTION
FUNCTION Vector_RotateAroundZ AS Tvector: vec1 AS Tvector, angle
LOCAL result AS Tvector
result.x = COS(angle) * vec1.x - SIN(angle) * vec1.y
result.y = SIN(angle) * vec1.x + COS(angle) * vec1.y
result.z = vec1.z
RETURN result
ENDFUNCTION