Jump to content
  • Advertisement
Sign in to follow this  
MasterSlowPoke

A problem getting meshes and lists to render properly.

This topic is 4053 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

In my program, I'm rendering two skinned meshes and a triangle list that represents a grid of squares. When I had only one mesh I had no problems. However when I added the second mesh, the square grid triangle list won't render at all. There's no way the new mesh is obscuring the grid, as the grid is much larger. I can't figure out any clues as to why this is happening. Here's the rendering code, which is inbetween a BeginScene and EndScene.
		IDirect3DDevice9 *device = g_VideoSystem->GetDevice();
		ID3DXEffect* fx = g_VideoSystem->GetEffect();

		D3DXVECTOR3 w = D3DXVECTOR3( 24.0f, 0.0f, -12.0f );
		D3DVIEWPORT9 viewport;
		g_VideoSystem->GetDevice()->GetViewport( &viewport );

		D3DXVec3Project( &w, &w, &viewport, g_VideoSystem->GetProj(), g_VideoSystem->GetView(), g_VideoSystem->GetWorld() );
		
		D3DXMATRIX local,toWorld,viewProj;
		D3DXMATRIX worldInvTrans;
		viewProj = g_VideoSystem->GetViewProj();

		// Let Direct3D know the vertex buffer, index buffer and vertex 
		// declaration we are using.
		HR(device->SetVertexDeclaration(VertexPNT::Decl));
		HR(device->SetStreamSource(0, m_GridVB, 0, sizeof(VertexPNT)));
		HR(device->SetIndices(m_GridIB));

		// Draw the Grid
		HR(fx->SetTexture(mh_Tex, m_GridTex));
		HR(fx->Begin(0, 0)); HR(fx->BeginPass(0));

		HR(device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 42, 0, 60));

		HR(fx->EndPass()); HR( fx->End() );

		//Draw the player
		local	=	m_Muncher->GetLocal();
		toWorld =	m_Muncher->GetToWorld();
		HR(fx->SetMatrixArray(mh_FinalXForms, m_Muncher->getFinalXFormArray(), m_Muncher->numBones()));
		HR(fx->SetMatrix(g_VideoSystem->GetWVP(), &( local*toWorld*viewProj ) ));
		D3DXMatrixInverse(&worldInvTrans, 0, &toWorld);
		D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans);
		HR(fx->SetMatrix(mh_WorldInvTrans, &worldInvTrans));
		HR(fx->SetMatrix(mh_World, &toWorld));
		HR(fx->SetTexture(mh_Tex, m_MuncherTex));
		HR(fx->Begin(0, 0)); HR(fx->BeginPass(0));
		m_Muncher->draw();	
		HR(fx->EndPass()); HR(fx->End());

		//Draw the Reggie 
		local	=	m_Reggie->GetLocal();
		toWorld =	m_Reggie->GetToWorld();

		HR(fx->SetMatrixArray(mh_FinalXForms, m_Reggie->getFinalXFormArray(), m_Reggie->numBones()));
		HR(fx->SetMatrix(g_VideoSystem->GetWVP(), &( local*toWorld*viewProj ) ));
		D3DXMatrixInverse(&worldInvTrans, 0, &toWorld);
		D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans);
		HR(fx->SetMatrix(mh_WorldInvTrans, &worldInvTrans));
		HR(fx->SetMatrix(mh_World, &toWorld));
		HR(fx->SetTexture(mh_Tex, m_ReggieTex));
		HR(fx->Begin(0, 0)); HR(fx->BeginPass(0));
		m_Reggie->draw();	
		HR(fx->EndPass()); HR(fx->End());

Share this post


Link to post
Share on other sites
Advertisement
I've figured out where the triangle grid went, but I can't figure out how to get it back. The grid is attached to the root bone of the Reggie model, and moves along with it. Keeping it from being attached seems like a fairly simple operation, but I have no idea how to do it. The code from above should still be accurate.

Here's an image of the problem:
http://www.craigsniffen.com/index/images/reggiegridattach.jpg

Share this post


Link to post
Share on other sites
You're not setting up a world matrix when you draw the grid, so it is using the last one that was set.
Try setting an identity matrix as the world matrix.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!