Sign in to follow this  
Pianka

[Solved] Matrix Translation Problem

Recommended Posts

I'm a neophyte when it comes to DirectX, but I've been researching as much as I can because it interests the hell out of me. So I started a new basic project to become more familar with it and I've run into some trouble. I'm using two .X meshes, one is a plane and the other is a tiger I got from an example. When I load and render these two meshes, they work as expected--so there's no error there. The problem occurs when I attempt to translate either of these meshes. First let me post the code and then explain:
void CMesh::objectRender( void ) {

    D3DXMatrixIdentity(&m_matrix);
    D3DXMatrixTranslation(&m_matrix, t_x, t_y, t_z);
    this->getDevice()->SetTransform(D3DTS_WORLD, &m_matrix);

    for (DWORD i = 0; i < m_dwNumMaterials; i++) {
        this->getDevice()->SetMaterial(&m_pMeshMaterials[i]);
        this->getDevice()->SetTexture(0, m_pMeshTextures[i]);
        
        m_pMesh->DrawSubset( i );
    }

}



I looked into this beforehand (that's how I found my way to this forum) and came across this topic: http://www.gamedev.net/community/forums/topic.asp?topic_id=377499 This was of some help, but apparently not enough. The variables t_x, t_y and t_z are floats with the value zero--so I'm not trying to even translate this anywhere yet, just get the code in order. If I comment out the first three lines of this function, it renders fine, but when I compile with them something strange happens. Instead of a plane and a tiger, I get two odd v-shaped brown things...I've no idea how to describe them because they're not exactly recognizable. Though I called them brown, there are lighter tan lines on them, still in the v-shaped direction. I'm sorry if any of this was unclear, but this is my first time posting here. Thanks in advance for any help. [Edited by - Pianka on June 8, 2006 9:13:58 PM]

Share this post


Link to post
Share on other sites
That's a little strange. Code looks good to me. What's your world transform normally set to? Anything special if you just comment out the D3DXMatrixTranslation(&m_matrix, t_x, t_y, t_z);?

(Incidentally, what you're probably seeing is the tiger in a strange position in relation to your near plane. Those colors sound like tiger's texture.)

Share this post


Link to post
Share on other sites
My world transformation:


void CScene::sceneSetupMatrices( void ) {

camera = new CCamera(this->getDevice());
camera->cameraInitialize();

D3DXMATRIXA16 matWorld;
D3DXMatrixTranslation(&matWorld, 0, 0, 0);
this->getDevice()->SetTransform( D3DTS_WORLD, &matWorld );

D3DXVECTOR3 vEyePt( camera->x, camera->y+5, camera->z-5);
D3DXVECTOR3 vLookatPt (camera->x, camera->y, camera->z+10 );
D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
this->getDevice()->SetTransform( D3DTS_WORLD, &matView );

D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
this->getDevice()->SetTransform( D3DTS_PROJECTION, &matProj );

}



Please excuse the how messy that code is; the camera's x is 0, the y is 1, the z is -8 and the lookahead is 10. If I comment out the D3DXMatrixTranslation, I get the exact same result (which would make sense, being as it's translating 0, 0, 0).

Share this post


Link to post
Share on other sites
That's just odd. The only thing I can think of:

Try using a local D3DXMATRIXA16 instead of m_matrix. Is m_matrix a D3DXMATRIX or a D3DXMATRIXA16? Maybe if you're using an aligned one that's declared on a heap it gets fouled up--I belive D3DXMATRIXA16 uses a declspec to specify alignment for a stack-based variable, but that won't work on a heap-based allocation. When passing in a D3DXMATRIX16A the overloaded function will be expecting a 16-byte-aligned piece of memory, and using faster variant xmm instructions which rely on that. The basic idea being that D3DXMATRIX16A is only good for stack allocations, and D3DXMATRIX is good for heap.

Share this post


Link to post
Share on other sites
It was originally a D3DXMATRIXA16 and then I changed it to a D3DXMATRIX when screwing around with it trying to figure out what was wrong. I get the exact same results both times. I changed it and declared a different matrix inside of the function instead of the class (and it's a D3DXMATRIXA16), but either way I always get the same result.

Share this post


Link to post
Share on other sites
t_x, t_y and t_z are all 0.0f. Debugging to the matrix, the values are all 0.0 excluding (1, 1), (2, 2), (3, 3) and (4, 4) which are all 1.0; and yes it's one thread. I'm really at a loss here, I can't figure out for the life of me why this is happening. :(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this