MVC roles of objects in pattern

  • Does the following legitimately conform to the MVC design pattern? It seems
    as though the camera object is fulfilling 2 roles: Model and View. Something
    doesn't ring true about this kind of design, but I can't see another way of
    doing it.

    Here goes!

    1. My View class has an instance of an object: Camera, which is updated
    according to mouse events.

    2. I also have an array of these camera objects being managed by an
    arrayController in my AppController instance, so that the user may save
    camera positions.

    3. SelectionIndex changes in the arrayController  causes the view to animate
    and update its Camera's iVars to those of the selectedCameraObject in the
    array.

    Using this method I can decouple the array of Cameras, but still have a
    functioning view.

    Is this okay, or should I do it differently?

    Thanks.
  • > In my understanding of MVC, your view should only communicate with
    > controller object(s).

    That's my understanding, too.

    > Thus, it should not have an instance of Camera
    > (a model object.  It is a model object, right?)  So, mouse events
    > should be captured by a controller object.  The controller should
    > update your model object (reposition coordinates of the world or
    > objects or whatever), then another controller object (or the same
    > one) will update the view using the data in your model.
    >
    > Did that answer any of your questions?
    >

    Very helpful, thanks.

    In /Developer/Examples/OpenGL/Cocoa/GLSLEditorSample we find the
    following snippet from GLSLView.h

    typedef struct {
      GLdouble x,y,z;
    } recVec;

    typedef struct {
    recVec viewPos; // View position
    recVec viewDir; // View direction vector
    recVec viewUp; // View up direction
    recVec rotPoint; // Point to rotate about
    GLdouble aperture; // pContextInfo->camera aperture
    GLint viewWidth, viewHeight; // current window/screen height and width
    } recCamera;

    I have put Class wrappers around these 2 structs and then manage an
    array of them in my controller class, which kind of shifts them out of
    the View side of things. However, as my view is in the business of
    handling mouse events and updating the camera's coordinates, it seems
    logical to me that the best kind of object to bind the arrays selected
    object to is an instance of camera in the View.

    You see, what I really want to do is animate between camera objects.
    So my plan was to leave the View with its Camera instance, and then
    when the selectionIndex changes in the controller, trigger an
    animation that handles transitions between the 2 objects, i.e. the
    (view) Camera moves to new Camera (model).

    In the case I've outlined it seems that without the bound array, one
    still has a functioning View, managing an array of cameras is
    something the View is almost unaware of - a bonus, so to speak.

    That's not to say that what I've just said doesn't smell fishy to me,
    because it does! I'm just playing Devil's advocate to my own
    ignorance.
  • Is it not the case that certain kinds of objects will exist in the model as
    well as the view?

    I think what I'm saying is that my OpenGLView class depends upon a Camera
    object for deciding all sorts of things inc. how things should be rendered,
    but also that it's useful to be able to store cameras (copies of the view
    camera) in an array as part of the model, and then update the OpenGLView's
    camera when the selected camera changes, and save them to persistent store
    etc.

    Without this array of cameras, I still have a fully functioning view, but
    without any kind of camera, I can't even code it!
  • This is comes from the documentation:
    http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCTutorial/chap
    ter02/chapter_2_section_3.html


    "MVC, strictly observed, is not advisable in all circumstances. Sometimes
    it's best to combine roles. For instance, in a graphics-intensive
    application, such as an arcade game, you might have several View objects
    that merge the roles of View and Model."
    A view's Camera and the model's Cameras[] would seem to be a case in point,
    unless I'm misunderstanding things ;)
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today