Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 4328 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 Ninja

Medals: 77
Exp: 10 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  

EgonOlsen (58 views)
2018-06-10 19:43:48

EgonOlsen (40 views)
2018-06-10 19:43:44

EgonOlsen (60 views)
2018-06-10 19:43:20

DesertCoockie (225 views)
2018-05-13 18:23:11

nelsongames (141 views)
2018-04-24 18:15:36

nelsongames (140 views)
2018-04-24 18:14:32

ivj94 (881 views)
2018-03-24 14:47:39

ivj94 (142 views)
2018-03-24 14:46:31

ivj94 (793 views)
2018-03-24 14:43:53

Solater (157 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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!