Sign up ×

I am doing a project where there is a room filled with objects with different shapes.

I am drawing the room in paint, being the picture all white and painting all the walls/obstacles red.

I am drawing each movable object in a different file, also using paint.

Now, I load both the map of the room and the objects as matrix of 1's and 0's to my program. I have one matrix for the first, and another matrix for each of the objects I load on the room.

The object will be able to move freely in the room, moving by any distance, any angle, and being allowed to rotate itself. How should I go about devising a method that allows me to rotate the object by any angle and still being able to detect collisions? What I mean is that if the object could just go up, down, left and right, I could just check both the matrix to see if they "overlap" any of the 1's. But if I want to rotate the object, let's say, by 10º, I can't see how I can convert that to a matrix and check it against the wall's matrix.

Should I drop the matrix representation and create mathematical regions and deal with this as we deal with it in IR^2 calculus, with some library? Wouldn't it be pretty expensive in computation terms?

What is a simple method to do this? It doesn't need to be a top notch method, but I am using it for a complex algorithm and I wouldn't want to be losing too much computing time at each iteration with this.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

This likely won't completely answer your question, but it may help. When I was doing collision detection in a small game I was writing, I would have a collision 'hit box' surrounding the object as well as a more complex detection method. You don't have to use the complex method until the two hit boxes overlap, and then you only have to calculate collision for the two objects, rather than every object to every other object in space.

share|improve this answer
Yeah, I already had thought of that. – devoured elysium Nov 23 '09 at 15:19
As far as the more exact method, I had my objects and my obstacles drawn on a different bitmap. Then when my hitboxes overlapped I would scan the overlapping pixels in each bitmap and when I found a pixel that had been drawn in both the obstacle map and the object map, a has occurred. This only works if you don't worry about objects colliding with each other though. – climbage Nov 23 '09 at 15:28
a *collision has occurred, that is – climbage Nov 23 '09 at 15:29
Yes, but if you read carefully what I wrote the problem is that I can't do that as the level of detail a bitmap entails is not enough for rotations or arbitrary angles of my object. – devoured elysium Nov 23 '09 at 15:50
Ah right, what I mean is after you have rotated your object and drawn it to your buffer (the bitmap for the objects), you can scan for collisions. – climbage Nov 23 '09 at 16:17

I did a similar thing years ago. Each object of my 3D scene was composed of basic wall/floor/ceiling object patterns. Each object was a mesh with his own bounding sphere. Then I first tested my camera's bouding sphere against each object's bounding sphere for detecting collision, and if they collided I performed a more precise collision test (mesh/sphere).

It was fast enough (Duron 600 MHz) and it was really easy to implement.

For your scenario, you seem to have a lot of dynamic objects (I only had the camera in my project, as a moving object) so it might help to have some kind of space partitioning techniques like BSP-trees of quadtrees.

share|improve this answer
Actually I will have walls and obstacles but probably just one moving object. – devoured elysium Nov 23 '09 at 15:51
So each object in your second file are in fact static? – Stringer Nov 23 '09 at 16:04
No, they move. But you only have one moving object at once. – devoured elysium Nov 24 '09 at 8:05

Your Answer


