• Create Account

## world matrix problem

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1gnomgrol  Members

Posted 05 July 2012 - 06:19 AM

Hello guys, im getting a pretty wierd problem.
When I try to move my model by changing its worldmatrix, it gets draw some frames at the 0 0 0 position, and some other frams as totally messed up something. Same for rotation, but scaling works fine.

[source lang="cpp"]D3DXMatrixIdentity(&World);D3DXVECTOR3 rotaxisX = D3DXVECTOR3(1.0f, 0.0f, 0.0f);D3DXVECTOR3 rotaxisY = D3DXVECTOR3(0.0f, 1.0f, 0.0f);D3DXVECTOR3 rotaxisZ = D3DXVECTOR3(0.0f, 0.0f, 1.0f);D3DXMATRIX temprot1, temprot2, temprot3; D3DXMatrixRotationAxis(&temprot1, &rotaxisX, 0); D3DXMatrixRotationAxis(&temprot2, &rotaxisY, 0); D3DXMatrixRotationAxis(&temprot3, &rotaxisZ, 0);Rotation = temprot1 *temprot2 * temprot3;D3DXMatrixTranslation(&Translation, 0.0f, 10.0f, 0.0f);D3DXMatrixScaling(&Scale, 0.02f, 0.02f, 0.02f);//Set objs world space using the transformationsWorld = Translation * Rotation * Scale;[/source]

[source lang="cpp"]cbuffer cbPerObject{ matrix worldMatrix; matrix viewMatrix; matrix projectionMatrix;};// Change the position vector to be 4 units for proper matrix calculations.input.position.w = 1.0f; // Calculate the position of the vertex against the world, view, and projection matrices. output.position = mul(input.position, worldMatrix); output.position = mul(output.position, viewMatrix); output.position = mul(output.position, projectionMatrix);[/source]

I really cant see what is going wrong here. If all matrixchanges are 0, then its drawn fine.
Has it something to do with the math? The constantbuffer is set fine thought, light is set the same way and it works fine.

It looks like this (switching between these two frames randomly, ignore the terrain):
http://imageshack.us...3/32408839.png/
http://imageshack.us.../42/failjf.png/

Edited by gnomgrol, 05 July 2012 - 06:49 AM.

### #2clb  Members

Posted 05 July 2012 - 06:23 AM

one thing I notice is that you do "World = Translate * Rotate * Scale", and in the shader "output.position = input.position * World". As a result, you first translate the point, then rotate it about the origin, and then scale it w.r.t the origin. It's more conventional to first scale, then rotate and finally translate, so try changing the code to "World = Scale * Rotate * Translate".
Me+PC=clb.demon.fi | C++ Math and Geometry library: MathGeoLib, test it live! | C++ Game Networking: kNet | 2D Bin Packing: RectangleBinPack | Use gcc/clang/emcc from VS: vs-tool | Resume+Portfolio | gfxapi, test it live!

### #3gnomgrol  Members

Posted 05 July 2012 - 06:26 AM

Thank you, but that didnt do any good =(
The object now gets some times drawn in the right position, but the wierd flickering didnt change.

Edited by gnomgrol, 05 July 2012 - 06:29 AM.

### #4clb  Members

Posted 05 July 2012 - 06:29 AM

When I encounter issues like this, my first go-to is PIX (and more recently, nVidia Paraller nSight). It's very helpful in disassembling the device state for evaluating that everything is as you'd expect.
Me+PC=clb.demon.fi | C++ Math and Geometry library: MathGeoLib, test it live! | C++ Game Networking: kNet | 2D Bin Packing: RectangleBinPack | Use gcc/clang/emcc from VS: vs-tool | Resume+Portfolio | gfxapi, test it live!

### #5gnomgrol  Members

Posted 05 July 2012 - 06:41 AM

Well, I AM currently trying to figure out the problem with PIX myself, but I really cant see where the problem lies ..
I added two pictures to my first post.

Edit: Im through with analysing the buffers in PIX. I still cant see what the problem is, everything seems to be just fine....

Edited by gnomgrol, 05 July 2012 - 09:18 AM.

### #6clb  Members

Posted 05 July 2012 - 05:25 PM

Perhaps you're accidentally transposing some of the matrices, and you end up processing the translation elements of the matrix to affect the .w component of the output. This bug causes results that look a bit like the second image - vertices flying towards "infinity" in one direction.
Me+PC=clb.demon.fi | C++ Math and Geometry library: MathGeoLib, test it live! | C++ Game Networking: kNet | 2D Bin Packing: RectangleBinPack | Use gcc/clang/emcc from VS: vs-tool | Resume+Portfolio | gfxapi, test it live!

### #7gnomgrol  Members

Posted 06 July 2012 - 02:18 AM

You are right. When I delete the line that transposes the worldmatrix, it keeps looking like pic2. Now I need to figure why the matrix only gets transposed in some frames, while in others not. Here is the drawingcode:

D3DXMatrixTranspose(&World, &World);
D3DXMatrixTranspose(&camView, &camView);
D3DXMatrixTranspose(&camProjection, &camProjection);
// Lock the constant buffer so it can be written to.
D3D11_MAPPED_SUBRESOURCE mappedResource;
cbPerObject* dataPtr;
dataPtr = (cbPerObject*)mappedResource.pData;
// Copy the matrices into the constant buffer.
dataPtr->worldMatrix = World;
dataPtr->viewMatrix = camView;
dataPtr->projectionMatrix = camProjection;
// Unlock the constant buffer.
d3d11DevCon->Unmap(matrixBuffer, 0);
d3d11DevCon->VSSetConstantBuffers(0, 1, &matrixBuffer);


### #8gnomgrol  Members

Posted 06 July 2012 - 03:23 AM

I fixed it, but I dont know what caused it exactly. I have to call this code EVERY frame, not only once (I have no idea why)
[source lang="cpp"]D3DXMatrixIdentity(&World);D3DXVECTOR3 rotaxisX = D3DXVECTOR3(1.0f, 0.0f, 0.0f);D3DXVECTOR3 rotaxisY = D3DXVECTOR3(0.0f, 1.0f, 0.0f);D3DXVECTOR3 rotaxisZ = D3DXVECTOR3(0.0f, 0.0f, 1.0f);D3DXMATRIX temprot1, temprot2, temprot3; D3DXMatrixRotationAxis(&temprot1, &rotaxisX, 0); D3DXMatrixRotationAxis(&temprot2, &rotaxisY, 0); D3DXMatrixRotationAxis(&temprot3, &rotaxisZ, 0);Rotation = temprot1 *temprot2 * temprot3;D3DXMatrixTranslation(&Translation, 0.0f, 10.0f, 0.0f);D3DXMatrixScaling(&Scale, 0.02f, 0.02f, 0.02f);//Set objs world space using the transformationsWorld = Scale * Rotation * Translation;[/source]

Now it works, but can you tell me why?

Edited by gnomgrol, 06 July 2012 - 03:24 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.