views:

188

answers:

2

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.

+1  A: 

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.

climbage
Yeah, I already had thought of that.
devoured elysium
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
a *collision has occurred, that is
climbage
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
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
Yes but you are not getting the point. If the object is a 2x2 block and you rotate it 10º, if you try to draw it it will not correspond to what you'd expect.
devoured elysium
Gotcha. Well this is over my head then sorry.
climbage
+1  A: 

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.

Stringer Bell
Actually I will have walls and obstacles but probably just one moving object.
devoured elysium
So each object in your second file are in fact static?
Stringer Bell
No, they move. But you only have one moving object at once.
devoured elysium