Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (578)
games submitted by our members
Games in WIP (499)
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 1725 times)
0 Members and 1 Guest are viewing this topic.
Offline HornDog

Junior Newbie





« Posted 2013-03-11 08: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
Offline deepthought
« Reply #1 - Posted 2013-03-14 04: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
Offline Oskuro

JGO Coder


Medals: 32
Exp: 6 years


Coding in Style


« Reply #2 - Posted 2013-03-14 13: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 14: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.
Offline HornDog

Junior Newbie





« Reply #4 - Posted 2013-05-15 23: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.

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (28 views)
2014-04-15 18:08:23

BurntPizza (25 views)
2014-04-15 03:46:01

UprightPath (40 views)
2014-04-14 17:39:50

UprightPath (22 views)
2014-04-14 17:35:47

Porlus (38 views)
2014-04-14 15:48:38

tom_mai78101 (62 views)
2014-04-10 04:04:31

BurntPizza (121 views)
2014-04-08 23:06:04

tom_mai78101 (221 views)
2014-04-05 13:34:39

trollwarrior1 (188 views)
2014-04-04 12:06:45

CJLetsGame (195 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!