Skip to main content
gamedev.net
🔒 Locked

Entity and model classes

Started by SAE Superman 4 replies 1.5k views
Original Post
SAE Superman
SAE Superman
I'd like to hear people's opinions on the design of entity and model classes. I've seen some entity classes, CEntity for example, that derive from a model class, CMilkShapeModel for example. I'd like to hear you thoughts on if this is a good way to design entity and model relationships, or if it would be better for the CEntity class to *have* a CMilkShapeModel. So basically, what's the pros/cons from these two things: CEntity->animate(); CEntity->getModel()->animate(); Thanks in advance...
Fancy Art
Fancy Art
I Seperate Entity date from its operation
Entity
mesh
EntityListener(it equals to material)
load
unload
render
SimpleEntityRenderer: public EntityListener
XFileListener:public EntityListener
SimpleEntityRender renderer
render()
renderer->render()
in this architecture I can easily change the render code of my entity(or change my entity's material) and apply composite pattern.
SAE Superman
SAE Superman
Bump...Any other thoughts?

Why would it be better one way over the other. For instance, if you had many model file formats you wanted to support, would the CEntity->getModel()->render() way be better? What are the drawbacks of these different ways?
Fancy Art
Fancy Art
Quote:
Original post by SAE Superman
would the CEntity->getModel()->render() way be better?


I want to Seperate Entity date from its operation(just like visiter pattern).in this way I can add new Materials(by Materials I mean shader and its driven c++ code),for example when doing GPU water simulation,I can just assign a MeshGridSurfaceListener to Entity->mesh (now this it is a regular rectangle mesh grid), to render(the operation) this mesh I call WaterSurfaceEntityListener->render().in this way I can make most part of my material framework reuseable.
JohnBolton
JohnBolton
My opinion is that you shouldn't derive an entity from a model.

There are two problems with deriving an entity from a model. It depends your definition of an "entity", but what about an entity that is not rendered? Also, suppose you want to extend Model (AnimatedModel, for example), and use the AnimatedModel with Entity. If Entity is derived from Model, you can't. Well, I guess you could derive AnimatedEntity from both Entity and AnimatedModel using virtual inheritance.

An entity is not a model. The model is only the visual component of an entity.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Giallanon
Giallanon
In my engine I've a class Entity which holds a position and a rotation and provide some function to manipulate its data (ie: Warp(x,y,z), RotateX()...).

Then there's a class named Actor which is derived from Entity. Actor can hold a list of Mesh and/or a list of models.

A Model is simply a list of meshes.

A Mesh is a list of 3d point (and index) with a Material.

This way I can define an Actor (position+rotation) that holds a Model (ie: 3 meshes imported from Milkshape) and maybe another pair of meshes (like a sword and a shield).

Using the Entity interface I can move/rotate the actor.

Also the entity can be used to define a camera...actually a camera is derived from entity. This way I have an uniform way of manipulating position and orientantion for all the object in the scene.
In short, anything that needs a position and orientation, is derived from Entity.

I've a set of functions to load from diffent models/meshes formats. Something like Mesh::LoadFromMS3DAscii() and Model::LoadFromASE().

Actor does not have to bother with the source model/mesh format because anything is handled inside the mesh/model class.

Last, actor has a set of functions to override the default material for any mesh/models it holds so that I can have the same mesh shared among many actors but any actor can still use a different materials to render it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.