Original Post
Hello. I've got a design issue that I just ran into and I'd like to discuss it here to see if anyone who has had a similar situation can help me out. I just noticed the description got kind of lengthy so please bear with me.
So far I've got this class called "Model" which holds model data - vertices, indices, and normals. Apart from that I have an "Entity" class, which amongst other things has a member variable which is a pointer to a Model instance; this way, all entities of the same kind share the same geometric data.
So, for example, to draw a bunch of trees in the scene, I'd have several instances of Entity and a single Model for the tree. Each tree Entity would apply its transformation matrix and then call the Model's draw method.
So far so good.
Now say I want to perform a collision test between two trees. First I'd build a bounding box around each one of them, test for box collision, and if the box test passes then I'd perform a more accurate per-triangle one.
However, I have a problem: the Model class holds the tree's data in local space - i.e. I don't have the vertex data for each tree in world space.
What I thought about the bounding box is the following:
Each tree Entity would have a box which is updated every time the tree entity is transformed; the box would first be calculated in local space and then I'd apply the Entity's particular transformation matrix over the box to transform it to world space. This way each tree would have its own bounding box in world space ready for collision.
However, what shall I do with vertices? I need each of the tree's vertices in world space to perform an accurate collision after the box one, and I don't have these.
Letting the Entity have an updated copy of its vertices in world space would kind of defeat the purpose of having a Model instance shared between all entities of the same kind.
Transforming each of the entity's vertices to world space before performing the collision test would bring a performance hit if several collision tests are carried since these would be recalculated for every test.
I'm not sure if I'm being clear enough so please ask for clarifications if you have the time/will to help me out.
Perhaps I should take a whole different approach. Your feedback is all welcome :)
So far I've got this class called "Model" which holds model data - vertices, indices, and normals. Apart from that I have an "Entity" class, which amongst other things has a member variable which is a pointer to a Model instance; this way, all entities of the same kind share the same geometric data.
So, for example, to draw a bunch of trees in the scene, I'd have several instances of Entity and a single Model for the tree. Each tree Entity would apply its transformation matrix and then call the Model's draw method.
So far so good.
Now say I want to perform a collision test between two trees. First I'd build a bounding box around each one of them, test for box collision, and if the box test passes then I'd perform a more accurate per-triangle one.
However, I have a problem: the Model class holds the tree's data in local space - i.e. I don't have the vertex data for each tree in world space.
What I thought about the bounding box is the following:
Each tree Entity would have a box which is updated every time the tree entity is transformed; the box would first be calculated in local space and then I'd apply the Entity's particular transformation matrix over the box to transform it to world space. This way each tree would have its own bounding box in world space ready for collision.
However, what shall I do with vertices? I need each of the tree's vertices in world space to perform an accurate collision after the box one, and I don't have these.
Letting the Entity have an updated copy of its vertices in world space would kind of defeat the purpose of having a Model instance shared between all entities of the same kind.
Transforming each of the entity's vertices to world space before performing the collision test would bring a performance hit if several collision tests are carried since these would be recalculated for every test.
I'm not sure if I'm being clear enough so please ask for clarifications if you have the time/will to help me out.
Perhaps I should take a whole different approach. Your feedback is all welcome :)