Sign in to follow this  
schupf

Where do collision in render loop?

Recommended Posts

Hello,

I have finally implemented collision detection in my Engine and it seems to work. Though I am not very happy about the setup of my render loop. The render loop (simplified) of my engine looks like this:
[code]
while(render) {

WindowUtilities::messagePump();

notifyInputHandler(mTimeDt);

updateScene(mTimeDt);

render();
}[/code]notifyInputHandler() just calls an input callback, where a specific game can check input and move objects. In Pseudocode something like this:
[code]
if(action == MOVE_LEFT)
player->moveLeft(mTimeDt); // Manipulates the position of the player
[/code]
Currently I am using a 2D Grid as space partition structure. updateScene() basically makes this:
[code]
void updateScene(float timeDt) {

relocateSceneObjects(); // Updates the cell (for example if player moved from cell 2 to 3,
//the object is removed from cell 2 etc

resolveCollisions(); // Detects and resolves collisions

relocateSceneObjects(); // Update cells again (because the collision resolving might
// have pushed an object out of an object into another cell);

updateAnimations(timeDt); // Now I know the final world matrices of the scene objects
// and I can compute the bone matrices

[/code]

Here are my questions:
1) Is the basic structure of my render loop ok?

2) updateScene() seems to work, but I am not sure if the layout is good (probably not, since its my first engine..). I do not like that I update the space partition structure (the 2D grid) per relocateSceneObjects(), then do collision detection and then calling relocateSceneObjects() again. But I could not find a way to avoid this: To make collision response the objects need to be in the right cells (the first relocateSceneObjects), then I do collision resolving and this might lead to a cell change of some objects (very unlikely though), so I have to call relocateSceneObjects() again.
Do you know what I mean? Is there a way to avoid this and only update the space partition structure ONCE?

3) I update the skeletal animations at the very end of my update() method. I do this because I need the final world matrix for the bone matrices. And since the final world matrix depends on collision (if an object is pushed out of a collided box, the world matrix changes), I update the animations AFTER the collision. Is this ok or bad?

Thanks for any help/suggestions!:)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this