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.

DarkBASIC Professional Discussion / I have a forward vector and an up vector. Now how do I get the Euler angles?

Author
Message
Bluespark
13
Years of Service
User Offline
Joined: 18th Mar 2011
Location:
Posted: 28th Aug 2011 00:08 Edited at: 28th Aug 2011 00:35
Question is in the topic title.

EDIT: More specifically, I have a vector representing the camera's forward direction, and a vector representing the camera's up direction (which is not always 0,1,0). How do I find the Euler angles for use in the rotate camera command?
Bluespark
13
Years of Service
User Offline
Joined: 18th Mar 2011
Location:
Posted: 28th Aug 2011 02:39 Edited at: 28th Aug 2011 02:40
Alternatively:
Quote: "In mathematics, the angle from the first to the second coordinate axis of a coordinate system is considered as positive. Therefore angles given a sign are positive angles if measured anticlockwise, and negative angles if measured clockwise, from a given line. If no line is specified, it can be assumed to be the first coordinate axis (x-axis) in the Cartesian plane. In many geometrical situations a negative angle of −θ is effectively equivalent to a positive angle of "one full turn less θ". For example, a clockwise rotation of 45° (that is, an angle of −45°) is often effectively equivalent to an anticlockwise rotation of 360° − 45° (that is, an angle of 315°).
In three dimensional geometry, "clockwise" and "anticlockwise" have no absolute meaning, so the direction of positive and negative angles must be defined relative to some reference, which is typically a vector passing through the angle's vertex and perpendicular to the plane in which the rays of the angle lie."


What is the angle between two (3d) vectors (on the same plane) if the reference vector is defined to be the cross product of the two vectors?
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 28th Aug 2011 04:41
Well... to get euler angles from a rotation matrix:



So this is similar to a part of the problem in your other question. Where A is the up vector of your camera and B is the forward vector of your camera, you have the square rotation matrix:


using the cross product and guess and check thing I described in the other thread, we can see that the matrix you want to insert into the function is:


To use that matrix in my above code, ianM's utils has a function called setmatrix. Either use that, or edit the function so that all the variables are set correctly. The variable setting part of the first function transposes the matrix and sets needed values in one fell swoop. So:

C31#=B.x (row 1 column 3 of the above matrix, indexed from 0 unlike in my notation)
C32#=B.y
C33#=B.z
C21#=A.x
C11#=A.y*B.z-A.z*B.y
C12#=A.z*B.x-A.x*B.z
C13#=A.x*B.y-A.y*B.x

I might be wrong, but those values should work.

In the two solutions i posted for you... I think they're correct, but there might be a typo in there somewhere. Typos are hard to avoid when editing plaintext to do math...


Why does blue text appear every time you are near?
Bluespark
13
Years of Service
User Offline
Joined: 18th Mar 2011
Location:
Posted: 28th Aug 2011 18:36
First, thanks for the extremely quick reply.
I've examined the code snippet and it is coded correctly, based on "Computing Euler angles from a rotation matrix". However, when selecting values for C31#, C32# etc, you mixed up the rows and columns. I think the typo stems from the "M4Element(" function, as it gets values from a transposed matrix. But mathematically, it does work quite flawlessly.

Also, I'm wondering why you use a custom defined "absolut" function when the regular "abs(" function works just as well. Just curious.

Thanks a lot!
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 30th Aug 2011 22:49
:\

heheh, I wrote that function a while ago, so I was going on the basis of assuming it works.

All the linear algebra I know is self-taught, so... I've gotten confused and have done some pretty weird stuff that barely works. sorry about that, but at the worst case that euler.pdf paper is still extremely useful.

As for the absolut function, I think there was a problem with a plug-in I installed, and so any time I typed in abs() it gave me an error. I just used that function instead of figuring out what was wrong


Why does blue text appear every time you are near?

Login to post a reply

Server time is: 2024-03-29 07:38:42
Your offset time is: 2024-03-29 07:38:42