Sign in to follow this  

Manageable model loading and controls

This topic is 2335 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:
[code]
// 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;
}
[/code]


function method:
[code]

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);
}

[/code]



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

This topic is 2335 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.

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