Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (degenerate_762, dr_panther, AndrewAMD, Ayumi), 789 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 4 of 5 1 2 3 4 5
Re: quaternions [Re: JibbSmart] #272241
06/17/09 04:49
06/17/09 04:49
Joined: Jun 2008
Posts: 31
Moscow, Russia
L
LunaticX Offline
Newbie
LunaticX  Offline
Newbie
L

Joined: Jun 2008
Posts: 31
Moscow, Russia
dunno if this will help
but when i use something like this:

quaternize(45,pan_rel_to_me,rot_offset);
quat_to_unit(rot_offset);
quat_multiply(my_rotation,rot_offset,my_rotation);

ang_for_quat(tempang,my_rotation);
vec_set(my.[an,tempang);

.pan of entity is set to something like 45.012 instead of just 45, while tilt and roll stay unchanged

Re: quaternions [Re: LunaticX] #272254
06/17/09 06:16
06/17/09 06:16
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline OP
Expert
JibbSmart  Offline OP
Expert
J

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 frown.

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
J
JibbSmart Offline OP
Expert
JibbSmart  Offline OP
Expert
J

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
J
JibbSmart Offline OP
Expert
JibbSmart  Offline OP
Expert
J

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 Offline
Senior Expert
Pappenheimer  Offline
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
J
JibbSmart Offline OP
Expert
JibbSmart  Offline OP
Expert
J

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 laugh

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 laugh

Last edited by JulzMighty; 08/13/09 14:00.

Formerly known as JulzMighty.
I made KarBOOM!
Re: quaternions [Re: JibbSmart] #284479
08/13/09 14:10
08/13/09 14:10
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Thank's for the explanation, although I'm not sure whether I understood everything, but that's my part to inform myself.
For now, I wish you good progress with the development of your contest entry!

Re: quaternions [Re: Pappenheimer] #285233
08/17/09 18:09
08/17/09 18:09
Joined: Apr 2009
Posts: 2
Russia
E
EvGenius Offline
Guest
EvGenius  Offline
Guest
E

Joined: Apr 2009
Posts: 2
Russia
Hi, new function ang_for_axis is very helpful, but I am cant understand how about angle parameter: In manual you can read - Rotation about vAxis in 0..360 degrees counterclockwise. but it works well only in rads 0 ~ 3.14 ~ 6.28 o_O
so I convert angles in rads and after rotate, get some divergence with rotation
May be I am not correct use this function?

Re: quaternions [Re: EvGenius] #285287
08/17/09 22:46
08/17/09 22:46
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline OP
Expert
JibbSmart  Offline OP
Expert
J

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 laugh

Jibb


Formerly known as JulzMighty.
I made KarBOOM!
Re: quaternions [Re: JibbSmart] #285343
08/18/09 07:56
08/18/09 07:56
Joined: Apr 2009
Posts: 2
Russia
E
EvGenius Offline
Guest
EvGenius  Offline
Guest
E

Joined: Apr 2009
Posts: 2
Russia
Ok =)
I am trying to test your 5 steps with this function, and I receive surprises- mistakes with function results =)
and now think, that maybe easy will be use quaternions)

Page 4 of 5 1 2 3 4 5

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1