• Create Account

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a \$50 Amazon gift card. Click here to get started!

# wtherapy

Member Since 05 Oct 2012
Offline Last Active Mar 18 2015 12:37 PM

### Simple question on rotation matrix and quaternions

07 February 2015 - 04:47 AM

I am having a nightmare question these days with my Matrix -> TRS ( translation / rotation / scaling ) conversion and back ( working on a skeletal animation sys ).

Given a SO(3) matrix, which should equivalently produce a unit quaternion ( with the real part positive ), I cannot successfully convert the matrix to a quaternion and then, converting back the quaternion, to obtain the original matrix back.

Code for conversion is straighforward, copy-pasted from Internet and also determined by me on the paper.

The matrix is:

-0.99064791 , 2.6822096e-007, -0.13643673,
0.13169301, -0.26139921, -0.95620453,
0.035664752, 0.96523124, -0.25895494

row major.

I assume there are people around that have competent code for this kind of conversion. Can someone convert this matrix to a unit quaternion, then convert it back to a matrix and confirm they get back the same matrix?

Cristian.

### PowerVR POD files data conversion problem

19 November 2012 - 10:20 AM

Hello,

I am importing various animations from PowerVR POD files. I need conversions from matrices to quaternions & stuff, as I want to implement animation blending and inter-frame interpolation.

My problem is that, when reading data exported from powervr as quaternions, translations and rotations, matrices converted from those TRS does not equal ( even by far ) the matrices read if I export the models with matrices.
Also, if I try to decompose the matrix into TRS, after extracting the scaling component, the resulting matrix is not a rotation matrix: columns are unit length, but rows aren't ( I have removed the translation component ).

For example, when I export as matrices ( model has about 100 bones, with about 250 frames ), the 11174 matrix is, COLUMN ORDERED:

-0.209940,
-0.409073,
-0.000002,
0.000000,
0.960153,
-0.089445,
-0.000002,
0.000000,
0.000003,
-0.000001,
0.725079,
0.000000,
-0.116999,
-0.340356,
-0.732254,
1.000000

but, when I export as TRS, the 11174 set of parameters are:

Trans = (-0.116999, -0.340356, -0.732254)
Scale = (0.418738, 0.982837, 0.725079)
Quat = (0.000000, -0.000002, 0.778976, 0.627054)

I have checked and by no means the TRS could be converted to a matrix that comes even close to the one read from powervr.

Objects are read from the POD file as follow:

translation: Vector3(&(node->pfAnimPosition[j * 3]));
rotation: Quaternion(
node->pfAnimRotation[j * 4 + 0],
node->pfAnimRotation[j * 4 + 1],
node->pfAnimRotation[j * 4 + 2],
node->pfAnimRotation[j * 4 + 3]
);
scale: Vector3(&(node->pfAnimScale[j * 7]))

Perhaps there is some bug in my conversion code although I have checked 1000 times, also I have created random translation, rotations and scaling and converted to matrices and then converted back to TRS and got the same values. That's why I have put here the parameters read from POD file.
Or perhaps the frame matrices does not come from a simple T*R*S transform and there is something more.
Animations are done in 3dmax.

Any solution or explanation for this is welcome.
Useless to say, the model, when used with matrices that come from TRS read from the POD file, deforms horribly. The first frame looks good, but the following not.

### Sending a simple heightmap as texture to vertex shader

18 November 2012 - 07:10 AM

Hello,

I am developing a fractal terrain generation based on an original 256x256 heightmap.
I need to use a texture to represent this heightmap, together with other gradients in each point, that is, 3 floats per 'texel'.

//////////////////////////////////////////////////////////////////////////////in the vertex shader, I am doing:

uniform sampler2D TexHeightMap;

vec4 GetVertCellParameters( uint i, uint j )
{
return texture( TexHeightMap, vec2( i, j ) ) * 2500.0f;
}

the * 2500.0f multiplication was used just to make sure the values are not somewhere between 0-1; in the final code,
the function will just return texture( TexHeightMap, vec2( i, j ) );

//////////////////////////////////////////////////////////////////////////////in the CPU, I am using:

void GLTexture::CreateHTExture( const void* pvBytes, unsigned int unW, unsigned int unH )
{
glEnable( GL_TEXTURE_2D );
glGenTextures( 1, &m_uglID );
glBindTexture( GL_TEXTURE_2D , m_uglID );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB32F, unW + 1, unH + 1, 0, GL_RGB, GL_FLOAT, pvBytes );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
}

glEnable(GL_TEXTURE_2D );
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D , pTexture->GetID());
glUniform1i(m_ugl_HeightMapTexture, 0);

pTexture is of type GLTexture;

m_ugl_HeightMapTexture = glGetUniformLocation(m_uglProgram, "TexHeightMap");

for some reason, I am only getting zeros in the vertex shader ( when calling GetVertCellParameters ).
I checked the parameters pvBytes with memory view and they look fine.
I just need to get the float values, unmodified, just as I send them, in the vertex shader, and access them via texture as vec4.

Thank you.

### Reading a grid stored in the video card's memory

05 October 2012 - 10:18 AM

Hello,

I am working on a simple terrain demo and I have a 256x256 height-map that stores not only height but also other information, each grid point having 8 floats.
I need this grid available in the video card memory ( so I can create a VBO or smth ).
The most important, in the vertex shader, when drawing the terrain, when getting the x and y ( Z is vertical ) of a vertex in the terrain, I will compute the cell grid in which the x-y point lies and then I need to be able to access in the vertex shader those 8 floats that are stored in the closest grid point of the 256x256 points "height map".

If someone has a suggestion on how to do it, any help is appreciated.

PARTNERS