Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (575) Games in Android Showcase (154) games submitted by our members Games in WIP (623) 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
 Ball Physics  (Read 2238 times) 0 Members and 1 Guest are viewing this topic.
HornDog

Junior Newbie

 « Posted 2013-03-11 07:49:19 »

Hi guys and gals, first post so be gentle!

I have the requirement to model the movements of a ball across a 3d terrain.

I have the terrain in an extremely high resolution of data, which I currently (for testing purposes) have exported to create a surface (terrain) that is 20,000 polygons (triangles) in size. Its roughly 100 squares by 100 squares with each square made out of a pair of triangles.

The surface does not need to be in that layout, but as I say thats just testing at the moment whilst I find out the best structure.

I would like to simulate a ball rolling across this surface, and was wondering what peoples views are on either,

1) using one of the 3d physics engines out there, and if so any recommendations for this function?
2) simply calculating the angle of the polygon the ball is on and calculating the roll myself.

I am not scared of the maths involved in doing it myself, but if there is a simple library out there then simply for speed it makes sense to use that.

Id appreciate any feedback from the forum.

Dave
deepthought
 « Reply #1 - Posted 2013-03-14 03:07:20 »

I would use JBullet.  It's easy enough to use, and there are plenty of tutorials.

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Oskuro

JGO Knight

Medals: 44
Exp: 6 years

Coding in Style

 « Reply #2 - Posted 2013-03-14 12:32:26 »

If you are going the manual route, for this particular exercise there are a few things that I think greatly simplify calculations:

• If the terrain is being rendered, you can reuse the surface normals used for smoothing to calculate physics interactions with the ball.
• Since the object is a sphere, collisions can be an extension of point-collisions (using the radius to create an spherical bounding box, rather than bothering with bounding box geometry).
• If the sphere has specific physical properties that limit how fast it can possibly move (wind drag / terminal velocity), the (maximum) potential collision area can be drastically reduced.
• If the terrain can be simplified to a heightmap (no overhangs or other complex structures, just slopes), determining when the sphere is touching the ground is even simpler. Even if there are overhangs, maybe a large portion of the terrain can be abstracted as a heightmap to speed up detection.

But these are just ideas I've come up with while thinking about your problem. Maybe someone else has more experience on this sort of thing and can debunk/enhance these points.

As for a physics engine, I personally don't like adding a complex engine if it is overkill, mostly because of the performance hit that might result from having more functionalities than those I require. But if the engine is scalable enough to mitigate that issue, go for it.

 Games published by our own members! Check 'em out!
relminator
 « Reply #3 - Posted 2013-03-14 13:42:09 »

Adding to Oskuro's post...

Given a point(sphere center + radius)

Use the plane equation to find the distance (Ax + By + Cz + D = 0)  We want to find D.
So, we come up with D = -(Ax + By + Cz)
Basically, the negated dot product of the normal of the plane and the point.

normal is the triangle normal of the terrain and vpoint is your point to test.

 1 `planeDistance = - ((normal.x * vpoint.x) + (normal.y * vpoint.y) + (normal.z * vpoint.z))`

After finding the distance, you need to know what side of the triangle your point is.

We use the famous distance formula to find the distance the center point of the sphere is from the polygon's plane.

 1 `distance = (vnormal.x * vcenter.x + vnormal.y * vcenter.y + vnormal.z * vcenter.z + planeDistance)`

where: vcenter is the center of the sphere.

Now check where the sphere lies in relation to the plane defined by your triangle...

If the absolute value of the distance we just found is less than the radius, the sphere intersected the plane.
 1  2  3  4  5  6  7  8  9  10  11  12  13 `        if( abs(distance) < radius )    {   INTERSECTS    }        else if( abs(distance) >= radius )    {            FRONT    }    else    {        BEHIND    }`

Then just project the sphere's center to the plane and do your response.
HornDog

Junior Newbie

 « Reply #4 - Posted 2013-05-15 21:32:25 »

Hi guys, sorry for the silence on this, I have been busy getting my application to the point of needing the ball physics and remembered I had posted this question.

The ground is on one level (no overhangs, cliffs etc) and I think using the plane (normal?) of the surface the ball is on to calculate its roll should pretty much do.

I am not even rendering the ball moving, simply want to know the path it took. I am going to begin this section of code and will be back for assistance no doubt!

Thanks again

D
Pages: [1]
 ignore  |  Print

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

 BurntPizza (29 views) 2015-04-23 03:42:11 theagentd (34 views) 2015-04-22 16:23:07 Riven (48 views) 2015-04-16 10:48:47 Duke0200 (59 views) 2015-04-16 01:59:01 Fairy Tailz (41 views) 2015-04-14 20:13:12 Riven (43 views) 2015-04-12 21:36:37 bus hotdog (60 views) 2015-04-10 02:39:32 CopyableCougar4 (66 views) 2015-04-10 00:51:04 BurntPizza (69 views) 2015-04-06 22:06:58 ags1 (67 views) 2015-04-02 10:58:48
 theagentd 23x BurntPizza 16x wessles 15x 65K 11x kingroka123 11x alwex 11x Rayvolution 8x kevglass 8x Roquen 7x chrislo27 7x Hanksha 7x Riven 7x Olo 7x Ecumene 7x ra4king 7x KevinWorkman 6x
 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