Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [T1] Camera rotation angles from "Up", "Right" and "View" vector?

Author
Message
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 9th Jun 2016 02:39 Edited at: 13th Jun 2016 17:19
Hello folks!

Does anyone know a way to rotate a camera using the UP, Right and View (forward) vector?

I tried several approaches with atan2 or setcameralookat() but they failed, as far as I know because of gimbal lock "z rotation".
What I came up with are 3 vectors blue, cyan and yellow. They are perpendicular aligned. I can even create some sort of view frustrum
with the information and position the camera on the center point, but I can`t find the right method to convert the three vectors to
euler angles or a quat for the camera rotation


[/url]

Attachments

Login to view attachments
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 9th Jun 2016 07:59
normal with this commands
RotateCameraLocalX
RotateCameraLocalY
RotateCameraLocalZ
AGK (Steam) V2.0.18 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 9th Jun 2016 09:12 Edited at: 9th Jun 2016 09:12
Actually,
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 9th Jun 2016 16:41 Edited at: 9th Jun 2016 16:43








The coffee is lovely dark and deep,and I have code to write before I sleep.
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 9th Jun 2016 19:14 Edited at: 10th Jun 2016 04:38
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?:





Another not working attempt would be:


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?

[/url]
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Jun 2016 07:37
Quote: "I used RotateCameraLocalX or RotateCameraGlobalX, but it gave the camera a constant spin,"


it should just turn arount the angleĀ° value once.

AGK (Steam) V2.0.19 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 11th Jun 2016 23:44 Edited at: 13th Jun 2016 06:25
I dont have any angles, I only have 3 vectors representing the directions of forward, up and down
I need the angles to rotate the camera and can't find them. :S So the quest in this thread would be how
to get a proper camera rotation based in the 3 directional vectors.


EDIT:
This code does a pretty interesting job so far, it works for about 95% - 98%, but sometimes there are errors and the object is just gone. I think there are some errors in it, even though it should be a port of the unity core engine code. If I apply it to a camera, some objects in the viewport dissapear at some angles of the forward, up and right vector and I have no clue how to fix that


On this site is some other helpful code, similar to that one I posted below, maybe I will give their calculations a try.
http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/



98% is good, but not good enough, I need the 100%.
To sum up my informations, I have to create a matrix based on the
UP / FORWARD and RIGHT vectors and create a quaternion from this matrix to get the camera /object rotated. Because my math function set is incomplete and limited and Matrix commands are not present in AppGameKit, we have to do this by hand.
I suspect the function has a floating point error, because double floats where used in the original.

Can anyone find the error in the code posted above?
We are already done for 98%...

[/url]

Attachments

Login to view attachments
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 13th Jun 2016 03:27 Edited at: 13th Jun 2016 20:26
Just added quat normalization to this debug code, it is still broken and will cause jumps when the if parts are changed, but they are urgent and dependent on correct arguments... maybe I can figure it out...

Debug code:


Still not perfect, but I would say its now 99%...

[/url]
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 13th Jun 2016 06:24 Edited at: 13th Jun 2016 06:28
Use the following code to setup vectors correctly, and it will work like a charm:



Case closed.

Quaternion 4d rotation skills +1
Custom Matrix4 skills +1
Anger +4
Pride +1
Awesome code +1

Use this code as a base, if you have to convert euler angle, direction vector or forward, up and down vector to a quat rotation.
And think about all the problems you won't have using this code, that I have lived through.

[/url]

Login to post a reply

Server time is: 2024-09-29 15:17:12
Your offset time is: 2024-09-29 15:17:12