2 registered members (Ayumi, 1 invisible),
584
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: quaternions
[Re: JibbSmart]
#114072
03/14/07 09:39
03/14/07 09:39
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
little update: vec_for_quat creates a unity vector in the direction of the quaternion. <-- not the direction of the quaternion's vector, but the direction that the rotation points please reply if you do or already have downloaded it, i'd like to know if these are any use to anyone. regardless, if i update the script, i'll upload it and let you know. the link is in my last post ^^ julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: quaternions
[Re: JibbSmart]
#114073
03/29/07 03:37
03/29/07 03:37
|
Joined: Mar 2006
Posts: 15 Kansas, USA
quantum69
Newbie
|
Newbie
Joined: Mar 2006
Posts: 15
Kansas, USA
|
Was looking at your lib and noticed you could get better performance by doing the <x>/2 ahead of time, store it in a local var and use it instead of performing all the divides. Not that todays FPU's aren't fast, but every little bit helps.
Just a thought.
Quantum Mechanic Better living at the subatomic level.
------------------------------------ Quantum Mechanic Better living at the subatomic level
|
|
|
Re: quaternions
[Re: quantum69]
#114074
03/29/07 10:31
03/29/07 10:31
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
thanks for the tip but local variables slow down function calls too. i don't know which would be slower, but it isnt the end of the world i've uploaded it again. quat_to_unit has been fixed up so that the value of the angle is preserved. this wasn't a problem when the magnitude was only slightly off, but i was having problems when quaternizing long vectors. julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: quaternions
[Re: ventilator]
#114075
03/30/07 23:03
03/30/07 23:03
|
Joined: Jul 2004
Posts: 1,924 Finland
Ambassador
Serious User
|
Serious User
Joined: Jul 2004
Posts: 1,924
Finland
|
Quote:
Quote:
[...] which is ridiculously easy if u know a little about complex numbers, and possibly even if you don't.
really? damn, i didn't get them when i looked into them a while ago. maybe i should (re)learn complex numbers first.
Actually I don't know how quaternion inner systems work but I'm still using them in my engine . Just looked into some examples and tutorials/stuff and coded my own quaternion class.
|
|
|
Re: quaternions
[Re: Ambassador]
#114076
03/31/07 07:05
03/31/07 07:05
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
yeh the main thing isn't knowing exactly how they work, but what produces the results u are looking for
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: quaternions
[Re: JibbSmart]
#114077
05/11/07 06:48
05/11/07 06:48
|
Joined: May 2002
Posts: 7,441
ventilator
Senior Expert
|
Senior Expert
Joined: May 2002
Posts: 7,441
|
i still don't understand quaternions. i can't imagine what they are but i borrowed some of your code: Code:
void ent_getrbmatrix1(ENTITY *entity, D3DXMATRIX *mout) { // ignores entity scale -> not needed for rigid bodies -> collision shape size gets defined by bounding box D3DXMATRIX mpan; D3DXMatrixRotationZ(&mpan, entity->pan * DEG2RAD); D3DXMATRIX mtilt; D3DXMatrixRotationY(&mtilt, -entity->tilt * DEG2RAD); // -tilt? D3DXMATRIX mroll; D3DXMatrixRotationX(&mroll, entity->roll * DEG2RAD); D3DXMATRIX mtranslation; D3DXMatrixTranslation(&mtranslation, entity->x * QUANTTOMETER, entity->y * QUANTTOMETER, entity->z * QUANTTOMETER); D3DXMATRIX mtemp1; D3DXMatrixMultiply(&mtemp1, &mroll, &mtilt); D3DXMATRIX mtemp2; D3DXMatrixMultiply(&mtemp2, &mtemp1, &mpan); D3DXMatrixMultiply(mout, &mtemp2, &mtranslation); //printmatrix("g1", mout); }
void ent_getrbmatrix2(ENTITY *entity, float *mout) // does the same as ent_getrbmatrix1 but in a different way { VECTOR xaxis; vec_set(&xaxis, vector(1, 0, 0)); VECTOR yaxis; vec_set(&yaxis, vector(0, 1, 0)); VECTOR zaxis; vec_set(&zaxis, vector(0, 0, 1)); // ignores entity scale -> not needed for rigid bodies -> collision shape size gets defined by bounding box vec_rotate(&xaxis, &entity->pan); vec_rotate(&yaxis, &entity->pan); vec_rotate(&zaxis, &entity->pan); mout[0] = xaxis.x; mout[1] = xaxis.y; mout[2] = xaxis.z; mout[3] = 0; mout[4] = yaxis.x; mout[5] = yaxis.y; mout[6] = yaxis.z; mout[7] = 0; mout[8] = zaxis.x; mout[9] = zaxis.y; mout[10] = zaxis.z; mout[11] = 0; mout[12] = entity->x * QUANTTOMETER; mout[13] = entity->y * QUANTTOMETER; mout[14] = entity->z * QUANTTOMETER; mout[15] = 1; //printmatrix("g2", mout); }
void ent_setrbmatrix(ENTITY *entity, float *m) { D3DXVECTOR3 s; D3DXQUATERNION q; D3DXVECTOR3 t; D3DXMatrixDecompose(&s, &q, &t, (D3DXMATRIX*)m); //todo: check for gimbal lock? entity->pan = RAD2DEG * atan2f(2 * (q.w*q.z + q.x*q.y), (1-2 * (q.y*q.y + q.z*q.z))); entity->tilt = RAD2DEG * -asinf((2 * (q.w*q.y - q.x*q.z))); entity->roll = RAD2DEG * atan2f(2 * (q.w*q.x + q.y*q.z), (1-2 * (q.x*q.x + q.y*q.y))); entity->x = t.x * METERTOQUANT; entity->y = t.y * METERTOQUANT; entity->z = t.z * METERTOQUANT; }
using quaternions seemed to be the easiest way to convert between eulers and matrices. this is needed if you want to use newton with lite-c. do you really understand these three quaternion lines? is it 100% reliable this way? with google i found some similar conversion code with checks for gimbal lock? it seems to work though!
|
|
|
Re: quaternions
[Re: Tor]
#114079
05/11/07 07:53
05/11/07 07:53
|
Joined: May 2002
Posts: 7,441
ventilator
Senior Expert
|
Senior Expert
Joined: May 2002
Posts: 7,441
|
i know that quaternions don't experience gimbal lock. but if you convert quaternions to eulers probably you have to check if the resulting eulers will have some kind if gimbal lock problem? i came across quaternion->euler conversion examples which did gimbal lock checks. <edit>hm... i think i noticed some jittering now in very rare cases. looks like there has to be some kind of gimbal lock check like that: Code:
float st = -2 * (q.w*q.y - q.x*q.z); if(fabs(st) > 0.9999) { draw_text("gimbal lock!", 10, 10, vector(255,255,255)); // but i have no clue what belongs here
} else { entity->pan = RAD2DEG * atan2f(2 * (q.w*q.z + q.x*q.y), (1 - 2 * (q.y*q.y + q.z*q.z))); entity->tilt = RAD2DEG * asinf(st); entity->roll = RAD2DEG * atan2f(2 * (q.w*q.x + q.y*q.z), (1 - 2 * (q.x*q.x + q.y*q.y))); }
</edit>
|
|
|
Re: quaternions
[Re: ventilator]
#114080
05/11/07 12:03
05/11/07 12:03
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
i saw a few mention gimbal lock problems but i cannot imagine how that would happen, as it never tries to move from one euler to another, coz it converts to quaternions before rotating. it could be referring to a couple of singularities as certain cumulative values approach +-90 because the conversion involves atan, which cannot use those values. this isn't a problem in my script. Quote:
it seems to work though!
for this i am so glad! jcl said atan2 would be available in lite-c soon, and as soon as that happens my code will be slightly more accurate. good to see u know what you're doing, even if quaternions are confusing, enough to use them!
i find quaternions so valuable in writing my own physics, which i'm doing for a school project.
julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
[UPDATE] quatRad
[Re: JibbSmart]
#114081
05/30/07 07:46
05/30/07 07:46
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
g'day,
in case any of you are using my quaternion code, i've uploaded a new zip (same link -- check my sig if you can't find it) which also contains quatRad.c as an alternative to quaternions.c.
quatRad uses doubles instead of floats, and uses radians instead of degrees. this update is due to a devastating recent discovery that objects won't rotate less than about 2.5 degrees (slightly smaller values get rounded up) in a frame. by using doubles and radians, quatRad will rotate as little as about 0.1 degrees in a frame.
enjoy,
julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
|