Thanks for the replies!
I used RotateCameraLocalX or RotateCameraGlobalX, but it gave the camera a constant spin, or am I doing something wrong? (EDIT: Setcamerarotation(1,0,0,0) before rotation would do it)
Stab in the Dark Software, you libraries are very powerful, but as far as I can see the functions is rotating the camera only on X and Y axis. How can I add the Z axis?
I still have no clue how to get the angles in euler for the camera rotation, but your code gave me a hint:
function GetCameraForwardDirectionVector( cameraID as integer )
x = sin( GetCameraAngleY( cameraID ) )
z = cos( GetCameraAngleY( cameraID ) )
y = -tan( GetCameraAngleX( cameraID ) )
camVecID = CreateVector3( x, y, z )
endfunction camVecID
This function takes camera angles and convert them into a vector. I thought I could reverse the equation but:
asin(x) =AngleY#
acos(z) = AngleY#
-atan(y) = AngleX#
gives two AngleY# angles, both seem not to work correctly.
have I missed something?
I still can't rotate the camera in the given vectors. Better said, I had already created a custom lookat command, but the z rotation flips once the x axis points upwards or downwards.
Edit:
I tried to convert the code from this helpful source:
http://pastebin.com/ubATCxJY
But it does not work right now, do you see any problems involving this code?:
function QuaternionObjectLookRotation(object as integer, forwardvecin as integer, upvecin as integer)
forwardvec = CreateVector3(GetVector3X(forwardvecin),GetVector3Y(forwardvecin),GetVector3Z(forwardvecin))
upvec = CreateVector3(GetVector3X(upvecin),GetVector3Y(upvecin),GetVector3Z(upvecin))
normalizeVector3(forwardvec)
// normalizeVector3(upvec)
vector = forwardvec
vector2 = CreateVector3()
vector3 = CreateVector3()
GetVector3Cross(vector2,upvec,vector)
normalizeVector3(vector2)
GetVector3Cross(vector3,vector,vector2)
m00# = GetVector3X(vector2)
m01# = GetVector3Y(vector2)
m02# = GetVector3Z(vector2)
m10# = GetVector3X(vector3)
m11# = GetVector3Y(vector3)
m12# = GetVector3Z(vector3)
m20# = GetVector3X(vector)
m21# = GetVector3Y(vector)
m22# = GetVector3Z(vector)
num8# = (m00# + m11#) + m22#
if num8# > 0.0
num# = sqrt(num8# + 1.0)
w# = num# * 0.5
num# = 0.5 / num#
x# = (m12# - m21#) * num#
y# = (m20# - m02#) * num#
z# = (m01# - m10#) * num#
DeleteVector3(forwardvec)
DeleteVector3(upvec)
DeleteVector3(vector2)
DeleteVector3(vector3)
SetObjectRotationQuat(object,w#,x#,y#,z#)
exitfunction
endif
if m00# >= m11# and m00# >= m22#
num7# = sqrt(((1.0 + m00#) - m11#) - m22#)
num4# = 0.5 / num7#
x# = 0.5 * num7#
y# = (m01# + m10#) * num4#
z# = (m02# + m20#) * num4#
w# = (m12# - m21#) * num4#
DeleteVector3(forwardvec)
DeleteVector3(upvec)
DeleteVector3(vector2)
DeleteVector3(vector3)
SetObjectRotationQuat(object,w#,x#,y#,z#)
exitfunction
endif
if m11# > m22#
num6# = sqrt(((1.0 + m11#) - m00#) - m22#)
num3# = 0.5 / num6#
x# = (m10# + m01#) * num3#
y# = 0.5 * num6#
z# = (m21# + m12#) * num3#
w# = (m20# - m02#) * num3#
DeleteVector3(forwardvec)
DeleteVector3(upvec)
DeleteVector3(vector2)
DeleteVector3(vector3)
SetObjectRotationQuat(object,w#,x#,y#,z#)
exitfunction
endif
num5# = sqrt(((1.0 + m22#) - m00#) - m11#)
num2# = 0.5 / num5#
w# = (m01# - m10#) * num2#
x# = (m20# + m02#) * num2#
y# = (m21# + m12#) * num2#
z# = 0.5 * num5#
DeleteVector3(forwardvec)
DeleteVector3(upvec)
DeleteVector3(vector2)
DeleteVector3(vector3)
SetObjectRotationQuat(object,w#,x#,y#,z#)
endfunction
// normalize vector (from source to result)
function normalizeVector3(vsource)
d# = getVector3Length(vsource)
x# = GetVector3X(vsource) / d#
y# = GetVector3Y(vsource) / d#
z# = GetVector3Z(vsource) / d#
SetVector3(vsource,x#,y#,z#) // update source vector
endfunction
Another not working attempt would be:
function QuaternionObjectLookRotation2(object as integer, forwardvecin as integer, upvecin as integer)
forwardvec=CreateVector3(GetVector3X(forwardvecin),GetVector3Y(forwardvecin),GetVector3Z(forwardvecin))
upvec=CreateVector3(GetVector3X(upvecin),GetVector3Y(upvecin),GetVector3Z(upvecin))
rightvec=CreateVector3()
normalizeVector3(forwardvec)
normalizeVector3(upvec)
GetVector3Cross(rightvec,upvec,forwardvec) // define rightvec
m00# = GetVector3X(rightvec)
m01# = GetVector3X(upvec)
m02# = GetVector3X(forwardvec)
m10# = GetVector3Y(rightvec)
m11# = GetVector3Y(upvec)
m12# = GetVector3Y(forwardvec)
m20# = GetVector3Z(rightvec)
m21# = GetVector3Z(upvec)
m22# = GetVector3Z(forwardvec)
w# = sqrt(1.0 + m00# + m11# + m22#) * 0.5
w4_recip# = 1.0 / (4.0 * w#)
x# = (m21# - m12#) * w4_recip#
y# = (m02# - m20#) * w4_recip#
z# = (m10# - m01#) * w4_recip#
SetObjectRotationQuat(object,w#,x#,y#,z#)
DeleteVector3(forwardvec)
DeleteVector3(upvec)
DeleteVector3(rightvec)
endfunction
okay, that quat roation is getting strange, sometimes the object dissapears and then returns.
Any ideas? I think the problem can be reduced to =>
convert UP, RIGHT, FORWARD vector to euler angles or quaternion
or is there a better solution?