I've been re-working some things in my engine recently, and I'm trying to implement the Model-View-Controller pattern as part of this.
I'm not really sure I'm doing it right though with regards to the view/model relationship.
Currently I have various types of basic objects (the models), which currently are just acting as wrappers around PhysX objects, so I have box, sphere, capsule, mesh, etc, with public properties to access matrices for translation, rotation, scale needed for drawing.
I then I have my views, which (taking box as an input model) are for example, wooden crate, filing cabinet, brick, etc. These contain references to the effect (HLSL), textures (diffuse, normal) and vertex/index buffers needed to draw them. It contains a reference to the model.
Finally I have the controllers, which I won't mention any further, because I'm happy with the way they are setup.
When setting up my objects I do as follows (psuedo-code):
Box b = new Box(...);
Box b2 = new Box(...);
CrateView crateView = new CrateView();
crateView.Add(b);
crateView.Add(b2);
Box b3 = new Box(...);
BrickView brickView = new BrickView();
brickView.Add(b3);
Renderer.Add(crateView);
Renderer.Add(brickView);
When Render() is called my renderer loops through each view registered and calls it's draw method.
The View's draw method looks as follows:
void Draw(Matrix matViewProj)
{
foreach(Model m in models)
if (m.InFrustum = true)
{
// Set effect world matrix as m.Scale * m.Rotation * m.Translation * matViewProj
// Set Textures
// Set Vertex/Index Buffers
// Draw Primatives
}
}
Is this the best way to decouple model and view? Is decoupling the two even needed?
Should the models hold details of it's textures etc and the view be more generic, such as say MainCameraView, TopDownMapView. Since at the moment setting up lots of objects takes literally forever, and having different views for what are essentially the same object except for the texture seems stupid.
The current views I have only really apply to the main camera, although the info I have in the models allows me to add to say a TopDownView which would hold it's own effect.
I'm really in two minds about how all this should work.