Jump to content
  • Advertisement
Sign in to follow this  
ryan mccabe

Manageable model loading and controls

This topic is 2551 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 guys. Im hoping someone can shed some light on making the code more manageable. Its for a direct3d framework. The framework itself functions well enough, but it needs some serious tweaking.

Right now each model is loaded in the main graphics class that does rendering calls. Functions inside the class are specific to each model.


load:

// Create the model object.
m_Model = new ModelClass;
if(!m_Model)
{
return false;
}

// Initialize the model object.
result = m_Model->Initialize(m_D3D->GetDevice(), "../Engine/Assets/SphereMesh.txt", L"../Engine/Assets/earthlights.dds");
if(!result)
{
MessageBox(hwnd, L"Could not initialize the model object.", L"Error", MB_OK);
return false;
}



function method:


m_BeaconModel->Render(m_D3D->GetDeviceContext());
m_testTexture->Render(m_D3D->GetDeviceContext(), m_BeaconModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_BeaconModel->GetTexture(), m_Light->GetDirection(), color);
......


if(m_Frustum->CheckSphere(x,y,z, 2.0f))
{
D3DXMatrixTranslation(&transMatrix, x, y, z);
worldMatrix = transMatrix;
m_BeaconModel->Render(m_D3D->GetDeviceContext());
m_testTexture->Render(m_D3D->GetDeviceContext(), m_BeaconModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_BeaconModel->GetTexture(), m_Light->GetDirection(), color);
}





As you can see its very hard coded. If I want to use another model with the function above I have to alter the function and not the call. I know this isn't right.
Do I use something like this->render( ... ) inside functions to make them work upon whatever i call them with as opposed to what Ive hard-coded?
Also right now the model loading bothers me. Hard coding in all the models and textures seems wrong if not impossible for anything with a significant number of meshes and textures. Is it possible to write a function or a manager class that will load and unload as needed given a lookup table or some such?

I dont necessarily need exact methods, but Im a little aimless in how to write my code in a more manageable way so any direction is very helpful right now. Thanks all.

Share this post


Link to post
Share on other sites
Advertisement
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!