Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I do have a pretty wierd problem today. As soon as I try to change my translation- or rotationmatrix for an object to something else than (0,0,0), the object starts to flicker (scaling works fine). It rapid and randomly switches between the spot it should be in and a crippled something. I first thought that the problem would be z-fighting, but now Im pretty sure it isn't.

I have now clue at all what it could be, here are two screenshots of the two states the plant is switching between.

http://imageshack.us/photo/my-images/819/73395561.png/

http://imageshack.us/photo/my-images/31/faildt.png/

I already used PIX, but could find anything of use (Im not a very good debugger anyway) I would appreciate any help, thanks a lot!

Important code:

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 transformations
World = Scale * Rotation * Translation;

shader:

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);

I figured the following: When I delete the line that Transaltes the worldmatrix before sending it to the shader, the object keeps looking like pic2. So it seems like the worldmatrix doesnt get transposed in some frames. 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;
d3d11DevCon->Map(matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &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);
share|improve this question
    
I think you'll need to post the code you're using to modify the translation & rotation. –  BpHinch Jul 5 '12 at 16:55
    
Try using World = Scale * Rotation * Translation –  Unreal_Me Jul 5 '12 at 21:42
    
Thanks, I see the problem with that. I fixed it, but the mainproblem remains. –  gnomgrol Jul 6 '12 at 7:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.