I am beginning to learn about OpenGL development, specifically using Mac OS X and the Cocoa and/or CGL API's, so I will use those classes as examples, but my question is more about design rather than a particular implementation. Here's the situation:
I have a 'scene' object, that can contain or reference the data to render itself, and responds to a 'render' message to draw itself, without any transformations.
I have an NSView
or NSOpenGLView
object that creates the openGLContext and pixelFormats, resizes the view, and updates the ModelView and Projection based on any transformations that are passed to it. The view object also contains a camera struct
that is the basis for the openGL transformations.
I have a controller object that is an NSResponder
object, and responds to user inputs.
I don't know if this is the best arrangement; 'model' in this case should be the scene, and I suppose classically the controller should mediate action between the model and view, but it seems odd for the view to send [[controller scene] render]
every time it wants to draw the view.
And I am not sure if the best place for the 'camera' is in the view. Should I have the scene object also include th开发者_运维百科e camera looking at it, and have it respond to UI input from the controller, which is currently passed to the view?
Or is this the wrong approach altogether? I am trying to shoehorn something into MVC that really isn't meant for it. I am curious as to what sort of design patterns people out there use with OpenGL.
I see it the way you described. View is designed to control the view point and projection, so keeping a camera reference in it is logical. Scene, on the other side, works as a pure data container for me, not touching the rendering methods, contrary to your model.
精彩评论