Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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 2176 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.

Thanks,

Rich

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 http://realtimecollisiondetection.net/...but then you might need to take a math course to read it.  Wink
Offline delt0r

JGO Knight


Medals: 30
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.

Antiharpist


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.
Simon

Offline delt0r

JGO Knight


Medals: 30
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
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 Coder


Medals: 21
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.

Please support my Kickstarter for next-gen video apps for Android:
http://kck.st/1xA3R61

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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (48 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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
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!