• Create Account

# I cannot seem to translate any of my models on the z axis using a model translation

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.

3 replies to this topic

### #1cineclick  Members   -  Reputation: 133

Like
0Likes
Like

Posted 21 February 2013 - 08:23 AM

I had a question up on stackoverflow where a user and myself were able to dig through an issue, and determined it must be an issue with either how I am transposing my matrices, or multiplying them.

To summarize the problem I'm having, I can set a model at a fixed z position without any problem by setting the actual model origin z coordinate value to any non-zero value, and this works, however, if I try to create a model with with an origin of [0,0,0] and use a model matrix to transform it, I can transform the x and y coordinates with no problems, but if my z value is not between 0.0f and -0.9999f it just disappears.  pivotnig (the user that was helping me on stackoverflow) had suggested it may be a matrix multiplication order issue, so I tried reversing the order, and just experimenting with different orderings, which mostly just made my scene disappear.

To jump back an idea for a second, another suspicion was that I maybe shouldn't be transposing the matrices before sending them to the vertex shader.  The reason I am is because every example I have came across on msdn and some other places have always sent the matrices to the vertex shader after a XMMatrixTranspose().

Another thing that I haven't tried because I do not have a great understanding of it is using the camera's inverse matrix.  I noticed that some samples I looked at used it, but some did not.  I don't know if the issue resides in the camera matrix, however, because while running the application, I can move the camera without any problems, and the scene seems to response appropriately in terms of distance and projection.

I have no found any other person with a similar issue in DirectX 11, and any similar issues otherwise are with versions of DirectX where the matrices were managed internally.

For the sake of convenience, here are my code snippets that I'm possibly having trouble with - I can upload other snippets if anyone thinks the problem is elsewhere.

I'll admit that I'm not particularly skilled in 3d math, so if anyone has a very mathy answer, can you try and simplify it as much as possible for me please.

### #2GuardianX  Crossbones+   -  Reputation: 1486

Like
2Likes
Like

Posted 21 February 2013 - 09:21 AM

Are you sure about what do you want to do in this code:

void TransformMatrix::Rotate( float x, float y, float z, float ang )
{
if ( x * ang != 0.0f ) rotate *= XMMatrixRotationX( x * ang );
if ( y * ang != 0.0f ) rotate *= XMMatrixRotationY( y * ang );
if ( z * ang != 0.0f ) rotate *= XMMatrixRotationZ( z * ang );
}


Don't you want to rotate around vector with x, y, z coordinates actually? Because if so, rotating around each orthogonal axis for angle ang is not the same as rotating around specified vector for angle ang and you should use XMMatrixRotationAxis instead.

Also, I couldn't find any code, responsible for view and projection matrix creation.

To jump back an idea for a second, another suspicion was that I maybe shouldn't be transposing the matrices before sending them to the vertex shader.  The reason I am is because every example I have came across on msdn and some other places have always sent the matrices to the vertex shader after a XMMatrixTranspose().

You must use XMMatrixTranspose(), because matrices in shaders are transposed version of XNA SSE matrices by default.

Also make sure that you constant buffer structure has the same member's order as your shader constant buffer:

cbuffer ProjectionBuffer : register(b0)
{
matrix p;
matrix m;
matrix v;
}; 

Edited by GuardianX, 21 February 2013 - 09:21 AM.

### #3cineclick  Members   -  Reputation: 133

Like
0Likes
Like

Posted 21 February 2013 - 10:18 AM

Ah, your last point may have fixed it.  I could have sworn that they were the same order, but I hadn't really checked it or thought about it.  Thanks for that catch, I'll test it out soon.

That rotation function was mostly put there out of frustration; I was originally using XMMatrixRotationAxis, but was having some issues with rotation that was a result from some other odd behaviour I was having a while ago.  I haven't been doing a lot of rotation with my models yet so I didn't get around to fixing it.  Thanks for the catch on that one, too, I can mark it as a todo task for me.

### #4Burnt_Fyr  Members   -  Reputation: 1201

Like
0Likes
Like

Posted 21 February 2013 - 12:15 PM

What vertex shader are you using? objects disappearing as you describe lead me to believe that perhaps your projection is not correct, as alluded to by GuardianX. Projective space spans from 0->1 ranging from near plane to far plane, anything outside of that range will not be visible.

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.

PARTNERS