Jump to content
  • Advertisement
Sign in to follow this  
darkm00n

cModel and X file parsing

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

Hey all, I'm using the cModel class that Jason Jurecka developed in his article "Working with the DirectX .X File Format and Animation in DirectX 9.0". It's going fine, except for some reason the program is jerking (as in the screen stutters) when the model appears on the screen for the first time. I have no idea why this is occuring, but here is the drawing function I'm using: void cModel::Draw() { LPMESHCONTAINER pMesh = m_pFirstMesh; //While there is a mesh try to draw it while(pMesh) { //Select the mesh to draw LPD3DXMESH pDrawMesh = (pMesh->pSkinInfo) ? pMesh->pSkinMesh: pMesh->MeshData.pMesh; // Set object world transformation m_Graphics->GetDeviceCOM()->SetTransform(D3DTS_WORLD, m_Pos.GetMatrix()); //Draw each mesh subset with correct materials and texture for (DWORD i = 0; i < pMesh->NumMaterials; ++i) { m_pd3dDevice->SetMaterial(&pMesh->pMaterials9); m_pd3dDevice->SetTexture(0, pMesh->ppTextures); pDrawMesh->DrawSubset(i); } //Go to the next one pMesh = (LPMESHCONTAINER)pMesh->pNextMeshContainer; } } m_Pos is just a class that controls a matrix for scaling, rotation, translation etc. Now, is there anything here that could be slowing down the drawing process? He said it wasn't the most optimised code, but if it's this unoptimised, is there anyway I could make it somewhat faster during the drawing process? Here's a link to the run-time: http://users.tpg.com.au/rojasma5/HOM/Demo.zip Thanks for any help you may offer me : )

Share this post


Link to post
Share on other sites
Advertisement
I used the same article for my Mesh class, and didn't have that problem. However, I do remember that the sample code had some Sleep commands in there which created a 'stutter' between animation sets. Just double check u don't have them in your code as well.

Matt Hughson

Share this post


Link to post
Share on other sites
I just realised - I'd updated the WHOLE engine to directx 9, not just the
.X file mesh loader. So maybe it's something new in directx 9 that I have not
correctly configured.

Here's the basic graphic engine initialisation code - is there something in it
that might cause meshes to stutter on first view? (I loaded a mesh in the camera's view when the game loads, and it seemed fine, but when i turned the camera the other meshes stuttered when they came into view).


BOOL cGraphics::SetMode(HWND hWnd, BOOL Windowed, BOOL UseZBuffer, long Width, long Height, char BPP)
{
D3DPRESENT_PARAMETERS d3dpp;
D3DFORMAT Format, AltFormat;
RECT WndRect, ClientRect;
long WndWidth, WndHeight;
float Aspect;

// Error checking
if((m_hWnd = hWnd) == NULL)
return FALSE;
if(m_pD3D == NULL)
return FALSE;

// Get the current display format
if(FAILED(m_pD3D-&gt;GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &m_d3ddm)))
return FALSE;

// Configure width
if(!Width)
{
// Default to screen width if fullscreen
if(Windowed == FALSE)
{
m_Width = m_d3ddm.Width;
}
else
{
// Otherwise grab from client size
GetClientRect(m_hWnd, &ClientRect);
m_Width = ClientRect.right;
}
}
else
{
m_Width = Width;
}

// Configure height
if(!Height)
{
// Default to screen height if fullscreen
if(Windowed == FALSE)
{
m_Height = m_d3ddm.Height;
}
else
{
// Otherwise grab from client size
GetClientRect(m_hWnd, &ClientRect);
m_Height = ClientRect.bottom;
}
}
else
{
m_Height = Height;
}

// Configure BPP
if(!(m_BPP = BPP) || Windowed == TRUE)
{
if(!(m_BPP = GetFormatBPP(m_d3ddm.Format)))
return FALSE;
}

// Resize client window if using windowed mode
if(Windowed == TRUE)
{
GetWindowRect(m_hWnd, &WndRect);
GetClientRect(m_hWnd, &ClientRect);

WndWidth = (WndRect.right - (ClientRect.right - m_Width)) - WndRect.left;
WndHeight = (WndRect.bottom - (ClientRect.bottom - m_Height)) - WndRect.top;

MoveWindow(m_hWnd, WndRect.left, WndRect.top, WndWidth, WndHeight, TRUE);
}

// Clear presentation structure
ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));

// Default to no hardware acceleration detected
m_HAL = FALSE;

// Setup Windowed or fullscreen usage
if((m_Windowed = Windowed) == TRUE)
{
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = m_d3ddm.Format;

// See if card supports HAL
if(CheckFormat(m_d3ddm.Format, TRUE, TRUE) == TRUE)
{
m_HAL = TRUE;
}
else
{
// Return error if not emulated
if(CheckFormat(m_d3ddm.Format, TRUE, FALSE) == FALSE)
return FALSE;
}
}
else
{
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP;

d3dpp.BackBufferWidth = m_Width;
d3dpp.BackBufferHeight = m_Height;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;

// Figure display format to use
if(m_BPP == 32)
{
Format = D3DFMT_X8R8G8B8;
AltFormat = D3DFMT_X8R8G8B8;
}
if(m_BPP == 24)
{
Format = D3DFMT_R8G8B8;
AltFormat = D3DFMT_R8G8B8;
}
if(m_BPP == 16)
{
Format = D3DFMT_R5G6B5;
AltFormat = D3DFMT_X1R5G5B5;
}
if(m_BPP == 8)
{
Format = D3DFMT_P8;
AltFormat = D3DFMT_P8;
}

// Check for HAL device
if(CheckFormat(Format, FALSE, TRUE) == TRUE)
{
m_HAL = TRUE;
}
else
{
// Check for HAL device in alternate format
if(CheckFormat(AltFormat, FALSE, TRUE) == TRUE)
{
m_HAL = TRUE;
Format = AltFormat;
}
else
{
// Check for Emulation device
if(CheckFormat(Format, FALSE, FALSE) == FALSE)
{
// Check for Emulation device in alternate format
if(CheckFormat(AltFormat, FALSE, FALSE) == FALSE)
return FALSE;
else
Format = AltFormat;
}
}
}

d3dpp.BackBufferFormat = Format;
}

// Setup Zbuffer format - 16 bit
if((m_ZBuffer = UseZBuffer) == TRUE)
{
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
}
else
{
d3dpp.EnableAutoDepthStencil = FALSE;
}

// Create the Direct3D Device object
if(FAILED(m_pD3D-&gt;CreateDevice(D3DADAPTER_DEFAULT,
(m_HAL == TRUE) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF,
hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &m_pD3DDevice)))
{

// Try to create Direct3D without ZBuffer support
// if selected and first call failed.
if(m_ZBuffer == TRUE)
{
m_ZBuffer = FALSE;
d3dpp.EnableAutoDepthStencil = FALSE;

if(FAILED(m_pD3D-&gt;CreateDevice(D3DADAPTER_DEFAULT,
(m_HAL == TRUE) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF,
hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &m_pD3DDevice)))
return FALSE;
}
else
return FALSE;
}

// Set default rendering states
EnableLighting(FALSE);
EnableZBuffer(m_ZBuffer);
EnableAlphaBlending(FALSE);
EnableAlphaTesting(FALSE);

// Enable texture rendering stages and filter types
m_pD3DDevice-&gt;SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pD3DDevice-&gt;SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
m_pD3DDevice-&gt;SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
m_pD3DDevice-&gt;SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
m_pD3DDevice-&gt;SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);

// Fix anisotropy
/*m_pD3DDevice-&gt;SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);
m_pD3DDevice-&gt;SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
m_pD3DDevice-&gt;SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_ANISOTROPIC);
m_pD3DDevice-&gt;SetSamplerState(0, D3DSAMP_MAXANISOTROPY, 8);*/


// Set default ambient color to white
SetAmbientLight(255,255,255);

// Calculate the aspect ratio based on window size
Aspect = (float)m_Height / (float)m_Width;
SetPerspective(D3DX_PI/4, Aspect, 1.0f, 10000.0f);

// Create a sprite interface
if(FAILED(D3DXCreateSprite(m_pD3DDevice, &m_pSprite)))
return FALSE;

return TRUE;
}

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!