Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (565) Games in Android Showcase (152) games submitted by our members Games in WIP (607) 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 2255 times) 0 Members and 1 Guest are viewing this topic.
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.

Thanks,

Rich

No, no, it's greater than keen; it's cugat.
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 http://realtimecollisiondetection.net/...but then you might need to take a math course to read it.
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!
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.

Antiharpist

No, no, it's greater than keen; it's cugat.
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.
Simon

delt0r

JGO Knight

Medals: 33
Exp: 18 years

Computers can do that?

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

Quote
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
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.
SmokeNWrite

Junior Devvie

Projects: 1

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

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

JGO Knight

Medals: 24
Projects: 1
Exp: 18 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:
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.

Check out the TyphonRT Video Suite:
http://www.typhonvideo.com/

Founder & Principal Architect; TyphonRT, Inc.
http://www.typhonrt.org/
http://www.egrsoftware.com/
https://plus.google.com/u/0/+MichaelLeahy/
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Riven (10 views) 2015-04-01 18:27:05 ags1 (27 views) 2015-03-31 10:55:12 theagentd (13 views) 2015-03-27 23:08:20 wxwsk8er (54 views) 2015-03-20 15:39:46 Fairy Tailz (48 views) 2015-03-15 21:52:20 Olo (29 views) 2015-03-13 17:51:59 Olo (33 views) 2015-03-13 17:50:51 Olo (40 views) 2015-03-13 17:50:16 Olo (44 views) 2015-03-13 17:47:07 ClaasJG (61 views) 2015-03-10 11:36:42
 BurntPizza 21x LiquidNitrogen 21x KevinWorkman 18x EgonOlsen 17x theagentd 16x basil_ 16x Roquen 15x Varkas 12x wessles 11x 65K 11x Riven 9x Rayvolution 9x phu004 8x SHC 8x princec 8x Ashedragon 8x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 java-gaming.org 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‑gaming.org