• Advertisement
Sign in to follow this  

XNA Model

This topic is 3318 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! I have created a couple of classes which create 3d primtives, such as a sphere, box etc.. Now im in the process of making a really simple scene graph, however my original idea, was that I would create a ModelNode which would contain a reference to either a XNA model or my own custom model.. However, since you can't derive or modify an XNA model(at least I haven't found a way to do it), I can't just simply put a single reference to a XNA model. Instead I would either have to create 2 scene nodes, one for a XNA model and one for my own type of model or I would have to keep 2 references in my scene node.. And I guess the last option would be to store an Object reference and a type member, and cast the model to the right one and then draw it... Err.. I guess I can't be the only one who have faced this problem, so any ideas? I suck at explaining things, so here's some code to clear my dilemma:
class MyModel;

class Sphere : MyModel;
class Box : MyModel;

// either this:
class XNAModelNode : SceneNode {
  Model model;

  void Draw() {
    // draw the model
  }
}

class MyModelNode : SceneNode {
  MyModel model;

  void Draw() {
    // draw the model
  }
}


// or this:
class ModelNode : SceneNode {
  Model xnaModel;
  MyModel myModel;

  void Draw() {
    // okay, this is just plain stupid i know
    if(xnaModel == null) // draw my model
    else  // draw xna model
  }
}

// or this:
class ModelNode : SceneNode {
  Object model;
  ModelType type;

  void Draw() {
    if(type == ModelType.MyModel) {
      // cast the model member and draw
    } else if(type == ModelType.XnaModel) {
      // cast the model member and draw
    }
 }
}

Now that I look at it, I guess the last option looks best, even though I don't like having an Object reference, since that would allow me to put basically anything in there... Anyways, suggestions?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement