Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (711)
Games in Android Showcase (213)
games submitted by our members
Games in WIP (785)
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 3671 times)
0 Members and 1 Guest are viewing this topic.
Offline 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.

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

Mad Scientist
Offline Oskuro

JGO Knight

Medals: 59
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!
Legends of Yore - The Casual Retro Roguelike
Offline 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.

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.

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.
    if( abs(distance) < radius )
    else if( abs(distance) >= radius )

Then just project the sphere's center to the plane and do your response.
Offline 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

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

numerical (319 views)
2017-02-21 07:32:16

numerical (319 views)
2017-02-21 07:31:46

theagentd (430 views)
2017-02-18 13:42:33

theagentd (428 views)
2017-02-18 13:35:16

h.pernpeintner (1596 views)
2017-01-24 22:39:11

h.pernpeintner (1583 views)
2017-01-24 22:38:32

Galdo (2147 views)
2017-01-12 13:44:09

Archive (2122 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2658 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2352 views)
2016-12-15 21:50:57
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55: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!