Entity Type

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Arch3r
Posts: 4
Joined: Sun Jul 04, 2010 10:57 am

Entity Type

Post by Arch3r »

Im lokking for a way to get the type of entity of something, im currently using an entity as a parameter for a drawing class and im trying to get different funcitons for different entities ie.Box, Sphere, triangle..etc
heres my code:

public void add(Entity type, Model model, Color color, Vector3 position)

ive looked through the Entity Class and Box class but cant find a way to do this becuase each entity inherits the Entity Class itself,
I guess i could just have different add functions for each entity like so

public void add(Box box, Model mode....etc)
&
public void add(Sphere sphere, Model model...etc)

but i was hoping for a more effecient way for doing this?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity Type

Post by Norbo »

If the goal is to do something specific for each entity type, all of the options are going to require some amount of arbitrary annoyance.

The multiple method is one option. Another way is to just convert using the "as" keyword and test for null in an if-chain. If you need a Type, you can use the object.GetType method, though you cannot switch on Types in C#. Some general alternatives can be found here: http://stackoverflow.com/questions/2989 ... ch-on-type

Changing it to a polymorphic class design would work too, possibly mixed with generics or type dictionaries (somewhat like how the demo drawer system works).
Post Reply