Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  2D rotational velocity  (Read 2376 times)
0 Members and 1 Guest are viewing this topic.
Offline Antiharpist

Senior Newbie

Medals: 2

« Posted 2011-10-12 03:30:04 »

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.



No, no, it's greater than keen; it's cugat.
Offline Roquen
« Reply #1 - Posted 2011-10-12 09:44:04 »

If you're going to buy one book on this subject, you should probably check-out then you might need to take a math course to read it.  Wink
Offline delt0r

JGO Knight

Medals: 33
Exp: 18 years

Computers can do that?

« Reply #2 - Posted 2011-10-12 12:37:28 »

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. 

I have no special talents. I am only passionately curious.--Albert Einstein
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Antiharpist

Senior Newbie

Medals: 2

« Reply #3 - Posted 2011-10-13 06:39:11 »

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.


No, no, it's greater than keen; it's cugat.
Offline dishmoth
« Reply #4 - Posted 2011-10-13 08:15:51 »

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.

Offline delt0r

JGO Knight

Medals: 33
Exp: 18 years

Computers can do that?

« Reply #5 - Posted 2011-10-13 09:05:59 »

Delt0r, I just drew stuff on the back of an envelope in initial planning...
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 have no special talents. I am only passionately curious.--Albert Einstein
Offline Antiharpist

Senior Newbie

Medals: 2

« Reply #6 - Posted 2011-10-21 02:32:12 »

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.

No, no, it's greater than keen; it's cugat.
Offline SmokeNWrite

Junior Devvie

Projects: 1

« Reply #7 - Posted 2011-11-24 01:24:42 »

Perfecting collision detection...
Ah.. you are my nemesis.. Smiley
Offline Catharsis

JGO Knight

Medals: 24
Projects: 1
Exp: 19 years

TyphonRT rocks!

« Reply #8 - Posted 2011-11-24 01:53:39 »

Check these tutorials. Demo code is in Flash, but can easily be ported:

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

Check out the TyphonRT Video Suite:

Founder & Principal Architect; TyphonRT, Inc.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

bilznatch (28 views)
2015-08-04 11:03:17

SHC (44 views)
2015-08-01 03:58:20

Jesse (25 views)
2015-07-29 04:35:27

Riven (48 views)
2015-07-27 16:38:00

Riven (26 views)
2015-07-27 15:35:20

Riven (28 views)
2015-07-27 12:26:13

Riven (19 views)
2015-07-27 12:23:39

BurntPizza (42 views)
2015-07-25 00:14:37

BurntPizza (56 views)
2015-07-24 22:06:39

BurntPizza (35 views)
2015-07-24 06:06:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!