proper rotation after collision?

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

proper rotation after collision?

Postby seed » Sun May 02, 2010 2:43 pm

Hey all.

I am making a rolling ball game. My ball rotation is great when it is on the ground but terrible when airborne. I need a good formula for the new rotation on a sphere after a collision with a plane. I have the current rotation the prior and new direction vectors and the normal of the plane available. Anyone have any. Ideas?
Visit Exit 4 Gaming - http://www.exit4games.com/
Home of LavaBall - http://exit4games.com/?page_id=3
Home of Rebound - http://exit4games.com/?page_id=138
Home of Tap Crazy - http://exit4games.com/?page_id=219
Download "Caveman Pool" From the Market Today!
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Top

Postby MichaelEGR » Mon May 03, 2010 5:34 pm

Not a full response, but check out:
http://www.myphysicslab.com/collision.html

This demo is using rectangles, but if you use an OBB (oriented bounding box) around your balls and apply similar collision equations as the example above it seems you will have the mechanics you are trying to implement.
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Postby seed » Mon May 03, 2010 5:57 pm

Thanks Michael.

I will give it a look when I have more time. At first glance it is far more complicated than I think I need. I actually worked on this some this weekend and had it just about right - except for some darn quarternion problems. Maybe this source will help some.

Regards
Visit Exit 4 Gaming - http://www.exit4games.com/
Home of LavaBall - http://exit4games.com/?page_id=3
Home of Rebound - http://exit4games.com/?page_id=138
Home of Tap Crazy - http://exit4games.com/?page_id=219
Download "Caveman Pool" From the Market Today!
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Postby MichaelEGR » Mon May 03, 2010 6:18 pm

Oh yeah.. The goal of course is to do the minimum of calculations to get a desired result often fudging any mechanics. It seems like you are looking to integrate angular velocity into your simulation/game and control collision effects on angular velocity for the spheres. Off the top of my head you may be able to fudge it by calculating angles based on colliding plane normal / velocity of sphere and do some sort of addition/subtraction to angular velocity which controls rotation of the sphere. It sounds like you are just interested in a graphic presentation rather than simulation accuracy, so something simple and simulation inaccurate is the way to go.

It'd be cool if you can post a video and your solution as it could be helpful for others on this forum.
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Postby seed » Mon May 03, 2010 8:38 pm

Yeah, no, I am not looking for accuracy. Just a good look. Right now, I am creating an axis of rotation based on the cross of the plane normal and the reflected motion vector and I am creating an angle of rotation scaled by the dot of the rotation vector to the plane normal (smaller equals less rotation because it is a more dead on hit). This works ok. My problem is that I think I also want to maintain some of the existing rotation, but I am really flubbing this part ;) I think it is one of those things I am better off putting aside for a little while and coming back to.

Funny you should mention a tutorial. I was hoping to do a quick tutorial using quarternions to accumulate accurate rotations around arbitrary axis in a sphere, both to provide some code for a sphere which people are always asking for and to introduce quarternions. I will get to it at some point.
Visit Exit 4 Gaming - http://www.exit4games.com/
Home of LavaBall - http://exit4games.com/?page_id=3
Home of Rebound - http://exit4games.com/?page_id=138
Home of Tap Crazy - http://exit4games.com/?page_id=219
Download "Caveman Pool" From the Market Today!
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Postby MichaelEGR » Mon May 03, 2010 8:52 pm

seed wrote:This works ok. My problem is that I think I also want to maintain some of the existing rotation, but I am really flubbing this part ;)


It sounds like you need to include angular velocity that controls entity/sphere rotation over time and then modify the angular velocity on collision based on some sort of scaling derived from the calculations you described. A collision will add/subtract angular velocity.
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Top

Postby seed » Mon May 03, 2010 10:39 pm

Yep, that. Two quarternions. A current rotational state, call it q. And new rotation per time period, call it tq. Each frame q gets multiplied by tq. The issue is how to re-invent tq after a collision. Do I replace tq with the new axis/angle from my calculations I described before or do I modify tq by multiplying in the quarternion from my collision. The former is OK but sometimes can look really wierd when too much rotation suddenly disappears. The latter can create crazy uncontrollable rotation when there are collisions all going the same direction, like a skipping scenerio. My solution is to keep some of the prior rotation and then multiply in the new rotation, but I had some bad quarternion math in there somewhere. Talking about it now makes me wonder if a quarternion wasn't a unit quarternion. I will check that when I get home later tonight.
Visit Exit 4 Gaming - http://www.exit4games.com/
Home of LavaBall - http://exit4games.com/?page_id=3
Home of Rebound - http://exit4games.com/?page_id=138
Home of Tap Crazy - http://exit4games.com/?page_id=219
Download "Caveman Pool" From the Market Today!
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest