2D rotational velocity

I’m an vacation/holiday this week, and got 2D rotated rectangle collision detection working. I’m not smart enough for Separating Axis Theorem right now, so just leave the rotation on the first rectangle at 0 degrees, and then rotate the second rectangle by the negative degrees of the first rectangle around the axis of the first rectangle. It works pretty well, and seems to be plenty fast, even though I have to do it twice, so I’ll leave it for now.

Now I’m trying to get the collision response working with rotated rectangles. What I’m going to try, is to record all of the collision points, then register if there are left-bottom or right-bottom collisions on the rotated rectangles. If so, I’m thinking I could just increase or decrease the rotational velocity.

It makes sense and could work good-enough, but I’m curious as to how any of you have handled it. If you tell me I should just take a math class, that’s not gonna happen, but I will buy any books you recommend.

Thanks,

Rich

If you’re going to buy one book on this subject, you should probably check-out http://realtimecollisiondetection.net/...but then you might need to take a math course to read it. :wink:

You don’t need to take a math class. But you do need to be prepared to learn some math. The Separating Axis Theorem is pretty easy once you get past the word theorem. What you are doing is basically correct. Transform one rectangle into the coordinate system of the other then check to see if there is any overlap. This is what you are doing as i understand. Just remember that you need to consider the cases when the rectangles are different sizes (maybe you don’t).

For many real cases Axis Alined Bounding Boxes (AABB) work pretty well for many convex or close to convex models. Then there is basic grid methods, there are a post or to on that here on that.

Thanks Roquen, I’ll see if that book is something I could digest. Even if I can’t, I’ll be very persuaded to take classes so that I can have a better understanding. Collision handling/response has definitely been the most challenging thing for me with the project I am working on. I also have a book on 3D math, but I always feel humbled and really intimidated. I guess it might be a good thing to do some rote learning, even if I don’t desire it.

Delt0r, I just drew stuff on the back of an envelope in initial planning, and realized that I had to check both rectangles to see if coordinates/vertices of either intersect with the other rectangle. I don’t know if that’s what you mean about different sized rectangles, but in testing I tried many different sizes and it all worked. SAT is nicer in that earlier escapes are possible, but then there is also the benefit that if I test every point, I can record all collision points (at least corners) for special handling later on. Everything I’ll want to test is definitely convex.

The hardest part isn’t the detection; it’s the response. I was thinking if I want to make it so that gravity actually pulls down a dangling half of a block pushed over a ledge, I have to know where the collision points are in order to influence the rotational velocity. I’ve faked it, but it just isn’t right. Is it typical to record points, or subdivide a rectangle in order to know how to influence rotation velocity? I guess I can always try. If it works, then it’s not the wrong way.

Antiharpist

Even if you’re not planning to use one, it might be worth reading through the documentation for an existing physics engine.
If nothing else it might give you a feel for how realistic you want your own physics to be.
Simon

[quote]Delt0r, I just drew stuff on the back of an envelope in initial planning…
[/quote]
Then i think you will not find the math that difficult and you can learn as you go. Just don’t expect to understand everything immediately and try examples/to write code. Nothing teaches like doing.

Also when it comes to games remember you are faking everything, including the physics. It just needs to be faked well enough to work with your game play. The top thing that is typically faked is that objects do penetrate each other to a limited degree.

I’ve talked with my partner on the game, and we’ve decided to keep it simple. Our whole goal is to make a C64/NES style game that would make us proud at age 10. We are very good at what we know, and it feels like a good idea to try to learn some new stuff to push it further, but in the end, the 10 year old only cares about the well done bits. If anything, I’ll use the rotated code simply for aesthetics, so we can do slopes that aren’t just boring 45 degree simple pixel things.

Thanks for all of the input, but we are in the finishing run, having a mostly playable game with good old-school mechanics and playability. I’m not doing anything epic, and I’m not in it for fame or money. Sometimes you do things from your heart, and if anything we’ll put out a pretty, nice sounding game out that only we appreciate; So be it. I’m happy with the where we are, and that’s coming from the unpretentious kid inside. It’s better to do something simple and highly polished than releasing an unfinished learning experiment. I’m not giving up, but the project/game is my focus, and sometimes limitations are great amigos. I’ll save the newly acquired things I’m not very good at for another project.

Perfecting collision detection…
Ah… you are my nemesis… :slight_smile:

Check these tutorials. Demo code is in Flash, but can easily be ported:
http://www.wildbunny.co.uk/blog/2011/04/20/collision-detection-for-dummies/
http://www.wildbunny.co.uk/blog/2011/04/06/physics-engines-for-dummies/

OBB vs OBB is covered above. Other interesting posts on this fellows blog too.