• Advertisement

Archived

This topic is now archived and is closed to further replies.

strange .x problem

This topic is 5803 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to write a wrapper to load and render .x files, so I spend the last couple of hours writing it and finally it compiles, but when I run it, I get the funny green and pink lines. I went and checked the debugger, and it says this: D3DXOF:800: syntax error near "0" D3DXOF:XStreamRead::GetNextObject: Error while parsing stream D3DXOF:GetNextObject: Parse error. Direct3D8: (ERROR) :Cannot invert view matrix " " ".... I''m assuming that this is a runtime error, but I dont exactly know whats going on. I can post some code, but I want to see if anyone has any ideas before I do. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Could you put here some code of your pro?
Probably anyone sees then the problem.
C.Ruiz

Share this post


Link to post
Share on other sites
Sounds a little like the X file is corrupt, are you using one of the x files in the media library contained with the DirectX SDK, if not, try one of them first, as they are all tested. (I would hope

Share this post


Link to post
Share on other sites
The first error is most likely from an unregistered template while the second error is because you are trying to invert or transpose a matrix that can''t be transposed or inverted (check the SDK docs for info).

Jim Adams

Share this post


Link to post
Share on other sites
I had problems like that when i was loading the X files but most of the time the X file was corrupt so i had to re convert it from 3ds to X again read the converter info it helps to know what it can do

Share this post


Link to post
Share on other sites
Well, you were right. My file was corrupt...I was using Milkshape to export the file, but once I tried loading a .x file using the common files utilities, and then milkshapes files worked fine. Now to go look at this whole matrix thing....

Share this post


Link to post
Share on other sites
Well, I have returned from the SDK and cannot think of anything that could cause this. I a have not inverted any matrices in all of my code unless some of the .x functions are doing it. Any ideas? I post some code if you want...its 35 lines at the most. Thanks.

Share this post


Link to post
Share on other sites
No one? Well, I will post some code anyways. Here is the code I am using to load and render the mesh:

  HRESULT CX::CreateModel( LPDIRECT3DDEVICE8 pDevice, char *fileName )
{

LPD3DXBUFFER pD3DXMtrlBuffer; // Material buffer


// Load the mesh from the specified file

if( FAILED( D3DXLoadMeshFromX( fileName, D3DXMESH_SYSTEMMEM,
pDevice, NULL,
&pD3DXMtrlBuffer, &m_dwNumMaterials,
&m_pMesh ) ) )
{
return E_FAIL;
}

// Get material properties

m_d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
m_pMeshMaterials = new D3DMATERIAL8[m_dwNumMaterials];


for( DWORD i=0; i<m_dwNumMaterials; i++ )
{
// Copy the material

m_pMeshMaterials[i] = m_d3dxMaterials[i].MatD3D;

// Set the ambient color for the material (D3DX does not do this)

m_pMeshMaterials[i].Ambient = m_pMeshMaterials[i].Diffuse;
}

// Done with the material buffer

pD3DXMtrlBuffer->Release();


return S_OK;
}


And this to render it:

  HRESULT CX::Render( LPDIRECT3DDEVICE8 pDevice )
{
for( DWORD i=0; i<m_dwNumMaterials; i++ )
{
// Set the material for this subset

pDevice->SetMaterial( &m_pMeshMaterials[i] );

// Draw the mesh subset

m_pMesh->DrawSubset( i );
}

return S_OK;
}


As you can see, most of this code was ripped from tutorial 6 from the SDK. As far as I can tell, I''m not doing anything with the matrices...The rest of the code works fine when I don''t do anything with the models. Any suggestions would be appreciated. Thanks.

Share this post


Link to post
Share on other sites
You might want to show the code where you are setting the projection, view, and world transformation matrices.

Jim Adams

Share this post


Link to post
Share on other sites
Ok...didnt think that it would matter because I am not attempting to invert the view matrix, but here it is:

      //-----------------------------------------------------------------------------

// Name: SetWorld()

// Desc: Sets and returns the world matrix

//-----------------------------------------------------------------------------

D3DXMATRIX CWorld::SetWorld( LPDIRECT3DDEVICE8 pDevice )
{
D3DXMATRIX matWorld; // Create the world matrix


pDevice->SetTransform( D3DTS_WORLD, &matWorld ); // Set world matrix to &matWorld


return matWorld; // Return the world matrix

}

//-----------------------------------------------------------------------------

// Name: SetView()

// Desc: Sets and returns the view matrix

//-----------------------------------------------------------------------------

D3DXMATRIX CWorld::SetView( LPDIRECT3DDEVICE8 pDevice, const D3DXVECTOR3* pEye,
const D3DXVECTOR3* pAt,
const D3DXVECTOR3* pUp )
{
D3DXMATRIX matView; // Create the view matrix


// Look at the *pAt parameter passed in

D3DXMatrixLookAtLH( &matView, pEye,
pAt,
pUp );

pDevice->SetTransform( D3DTS_VIEW, &matView ); // Set the view matrix to &matView


return matView; // Return the view matrix

}

//-----------------------------------------------------------------------------

// Name: SetProjection()

// Desc: Sets and returns the projection matrix

//-----------------------------------------------------------------------------

D3DXMATRIX CWorld::SetProjection( LPDIRECT3DDEVICE8 pDevice )
{
// Create the projection matrix

D3DXMATRIX matProj;

// Set the perspective

D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );

// Set the view matrix to &matProj

pDevice->SetTransform( D3DTS_PROJECTION, &matProj );

// return the projection matrix

return matProj;
}


Any ideas?

Edited by - Sheep on February 27, 2002 1:41:34 PM

Edited by - Sheep on February 27, 2002 8:24:07 PM

Share this post


Link to post
Share on other sites
Here's a problem:

    
D3DXMATRIX CWorld::SetWorld( LPDIRECT3DDEVICE8 pDevice )
{
D3DXMATRIX matWorld; // Create the world matrix


// PROBLEM HERE


// Set world matrix to &matWorld

pDevice->SetTransform(D3DTS_WORLD, &matWorld );

return matWorld; // Return the world matrix

}


There's nothing set in the matWorld - you want to set it to identity at least with D3DXMatrixIdentity(&matWorld) before setting it via SetTransform. The rest looks fine.

Jim Adams
home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX"


Edited by - jim adams on February 28, 2002 1:44:53 AM

Share this post


Link to post
Share on other sites
Hmmm...thanks for the tip, but that didn''t do it. I think I have tracked the error (if the debugger isnt lying) to my render function:

  
HRESULT CX::Render( LPDIRECT3DDEVICE8 pDevice )
{
for( DWORD i=0; i<m_dwNumMaterials; i++ )
{
// Set the material for this subset

pDevice->SetMaterial( &m_pMeshMaterials[i] );

// Draw the mesh subset

m_pMesh->DrawSubset( i ); // I get the error here.

// Any ideas?

}

return S_OK;
}


Thanks

Share this post


Link to post
Share on other sites

  • Advertisement