|
Re: quaternions
[Re: LunaticX]
#272254
06/17/09 06:16
06/17/09 06:16
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
I'll look into how I can improve the accuracy next week. I'm afraid I really have to get back to studying now  . Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: quaternions
[Re: JibbSmart]
#272316
06/17/09 13:04
06/17/09 13:04
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
Cool feature, very much worth looking forward to: ang_for_axis! Kinda makes my Quaternions redundant. Good, though. The fewer wheels we have to re-invent, the better! Jibb EDIT: Ironically, we're also getting ang_for_matrix, which would've allowed me to convert from a Quaternion to an A7-native Euler angle without dealing with any trigonometry (and probably result in more accurate Euler representations of my Quats).
Last edited by JulzMighty; 06/17/09 14:19. Reason: Saw another feature.
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: quaternions
[Re: JibbSmart]
#284378
08/13/09 05:57
08/13/09 05:57
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
Now that A7.80 is out I realized I mis-interpreted the use of ang_for_axis. It'll actually be very useful for converting Quaternions to Euler angles (which was the main issue with my old code), so I will fix and update my Quaternion code.
Hopefully this will happen next week, as the Shader Contest will be over.
Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: quaternions
[Re: JibbSmart]
#284433
08/13/09 11:31
08/13/09 11:31
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
Maybe, you are the expert to answer this: I want to turn a model's tilt and roll depending the normal of the surface traced beneath it. For a long while, I thought this is easily done by vec_to_angle:
c_trace(my.x, vector(my.x,my.y,my.z-1000), IGNORE_ME|IGNORE_PASSABLE); vec_to_angle(temp, normal);
But, it obviously is not.
What's your advice?
|
|
|
Re: quaternions
[Re: Pappenheimer]
#284478
08/13/09 13:56
08/13/09 13:56
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
This is fairly easy to do with Quaternions -- though I can definitely understand your trouble trying to deal with this in Euler angles. In fact this is the type of situation where it's particularly useful to have Quaternions, but perhaps you don't want to convert to Quaternions just for this. That's okay, because the latest update (A7.80) adds ang_for_axis, which will be very helpful. Here's how I've done it with Quaternions (should work without, and I've briefly outlined how to do it without Quaternions too) : 1. The player has a vector (just a local VECTOR) that always has its relative up vector (simple vec_rotate(up, my.pan) where "up" is (0, 0, 1)). 2. c_trace to get the normal (as you've done). 3. Find the angle between my "up" and the normal -- acos(vec_dot(up, normal)) -- we don't have to divide by the length of either vector since they are both unit vectors. This angle is how much we want to rotate our model. 4. Find the axis we want to rotate around by getting vec_cross(up, normal) (since the axis has to be perpindicular to both our starting vector and the vector we want to line it up with). 5. Lastly, to line the model up with the normal, we want to line the player up with the normal beneath it by rotating it by the angle we found in "3." around the axis we found in "4.". I did this with Quaternions (very easy that way), but if you want to do it without and you have the latest update, you can probably use "ang_for_axis(ANGLE* result, axis, angle);" to find the Euler version of the rotation, and then use ang_add to rotate your model by that amount. I hope this is helpful. Let me know if you need a little more, and I'll be happy to help more, but as the shader contest deadline approaches Friday night I won't be able to help until Saturday. On a side-note, a threw in a couple of small snippets from my Quaternion code into my contest entry, and have found ang_for_axis very useful for a very clean conversion back to Euler angles  Jibb EDIT: In step 1 I actually used my own Quaternion version of vec_rotate, because it would be inconsistent and slightly less stable to alternate between using the entity's Euler orientation and its Quaternion rotation. That won't change how you do it, though 
Last edited by JulzMighty; 08/13/09 14:00.
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: quaternions
[Re: EvGenius]
#285287
08/17/09 22:46
08/17/09 22:46
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
Yes, that's right. The way I've utilised it uses rads as well. It's probably worth telling jcl in the "Blame the Manual" or "Bug" forums, as since vars are only accurate to 3 decimal places it'd probably be better in the 0-360 range like the manual describes. I'll open a thread now  Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
|