• Advertisement
Sign in to follow this  

Where do collision in render loop?

This topic is 2318 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


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:

while(render) {




notifyInputHandler() just calls an input callback, where a specific game can check input and move objects. In Pseudocode something like this:

if(action == MOVE_LEFT)
player->moveLeft(mTimeDt); // Manipulates the position of the player

Currently I am using a 2D Grid as space partition structure. updateScene() basically makes this:

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

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
Sign in to follow this  

  • Advertisement