• Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a \$50 Amazon gift card. Click here to get started!

# quasar3d

Member Since 01 Dec 2001
Offline Last Active Aug 25 2015 10:00 AM

### quaternions?

29 June 2005 - 09:20 AM

I am trying to use quaternions for my animations, but I can't really get them working correctly. I made a plugin for maya, which gets the quaternion from the items transformation matrix. Most of the time this seems to work fine, but especially if I try to blend between multiply animations, it sometimes gives very weird results. I think the problem has something to do with the fact that you can represent each rotation by 2 diffent quaternions.
I did a little test with a cube which rotates only around it's x axis. This is a part of the quaternion keyframes I got, and there is indead a flip of signs:

<key t = "5" value = ".7330, -.6801, 0, 0"/>
<key t = "6" value = ".6234, -.7818, 0, 0"/>
<key t = "7" value = "-.4999, .8660, 0, 0"/>
<key t = "8" value = "-.3653, .9308, 0, 0"/>

Is there a way to get the quaternions in a way that those sign flips won't occur?

This is my matrix to quaternion code
```Quaternion Matrix4::ToQuaternion() const
{
float trace = m[0][0] + m[1][1] + m[2][2];

if(trace > 0)
{
float root = sqrtf(trace + 1);

Quaternion ret;
ret.w = root * .5f;
root = .5f / root;
ret.x = (m[2][1] - m[1][2]) * root;
ret.y = (m[0][2] - m[2][0]) * root;
ret.z = (m[1][0] - m[0][1]) * root;
ret.Normalize();
return ret;
}
else
{
const int next[] = {1,2,0};
int i = 0;
if(m[1][1] > m[0][0])
i = 1;
if(m[2][2] > m[i][i])
i = 2;
int j = next[i];
int k = next[j];

float root = sqrtf(m[i][i] - m[j][j] - m[k][k] + 1);

Quaternion ret;
ret.vec[i] = root * .5f;
root = .5f / root;
ret.w = (m[k][j] - m[j][k]) * root;
ret.vec[j] = (m[j][i] + m[i][j]) * root;
ret.vec[k] = (m[k][i] + m[i][k]) * root;
ret.Normalize();
return ret;
}
}

```

### Maya coordinates?

22 May 2005 - 11:26 PM

Maya is driving me nuts. I am writing an exporter plugin. According to the documentation maya uses centimeters for all it's units, and most of the time, this seems to be the case. But on some objects, it suddenly seems to be using meters, and so my object comes out 100 times smaller than it is in maya. Does anyone know what I could be doing wrong?

### sampling twice from the same texture

22 December 2004 - 11:13 PM

In my pixel shader, i want to sample from the same texture twice, with different texture coordinates. I can only use pixel shaders 1.3. I tried to move a different texture coordinate to t0, and then sample again, but that shader didn't compile. I could try to bind the same texture to two sampler stages, but i'm not sure if that will work/is safe. What is the best way to do this?