-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3271c8d
commit 9976b71
Showing
1 changed file
with
106 additions
and
0 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
apps/src/main/java/jme3utilities/tutorial/HelloStaticBody.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
Copyright (c) 2020-2024 Stephen Gold | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of the copyright holder nor the names of its contributors | ||
may be used to endorse or promote products derived from this software without | ||
specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package jme3utilities.tutorial; | ||
|
||
import com.jme3.app.SimpleApplication; | ||
import com.jme3.bullet.BulletAppState; | ||
import com.jme3.bullet.PhysicsSpace; | ||
import com.jme3.bullet.collision.shapes.CollisionShape; | ||
import com.jme3.bullet.collision.shapes.SphereCollisionShape; | ||
import com.jme3.bullet.objects.PhysicsBody; | ||
import com.jme3.bullet.objects.PhysicsRigidBody; | ||
import com.jme3.math.Vector3f; | ||
|
||
/** | ||
* A simple example combining static and dynamic rigid bodies. | ||
* <p> | ||
* Builds upon HelloRigidBody. | ||
* | ||
* @author Stephen Gold [email protected] | ||
*/ | ||
public class HelloStaticBody extends SimpleApplication { | ||
// ************************************************************************* | ||
// constructors | ||
|
||
/** | ||
* Instantiate the HelloStaticBody application. | ||
* <p> | ||
* This no-arg constructor was made explicit to avoid javadoc warnings from | ||
* JDK 18+. | ||
*/ | ||
public HelloStaticBody() { | ||
// do nothing | ||
} | ||
// ************************************************************************* | ||
// new methods exposed | ||
|
||
/** | ||
* Main entry point for the HelloStaticBody application. | ||
* | ||
* @param arguments array of command-line arguments (not null) | ||
*/ | ||
public static void main(String[] arguments) { | ||
HelloStaticBody application = new HelloStaticBody(); | ||
application.start(); | ||
} | ||
// ************************************************************************* | ||
// SimpleApplication methods | ||
|
||
/** | ||
* Initialize the application. Invoked once. | ||
*/ | ||
@Override | ||
public void simpleInitApp() { | ||
// Attach a BulletAppState and create a physics space: | ||
BulletAppState bulletAppState = new BulletAppState(); | ||
stateManager.attach(bulletAppState); | ||
PhysicsSpace physicsSpace = bulletAppState.getPhysicsSpace(); | ||
|
||
// Enable debug visualization to reveal what occurs in physics space. | ||
bulletAppState.setDebugEnabled(true); | ||
|
||
// Create a CollisionShape for balls. | ||
float ballRadius = 1f; | ||
CollisionShape ballShape = new SphereCollisionShape(ballRadius); | ||
|
||
// Create a dynamic body and add it to the space. | ||
float mass = 2f; | ||
PhysicsRigidBody dynaBall = new PhysicsRigidBody(ballShape, mass); | ||
physicsSpace.addCollisionObject(dynaBall); | ||
|
||
// Create a static body and add it to the space. | ||
PhysicsRigidBody statBall | ||
= new PhysicsRigidBody(ballShape, PhysicsBody.massForStatic); | ||
physicsSpace.addCollisionObject(statBall); | ||
|
||
// Position the balls in physics space. | ||
dynaBall.setPhysicsLocation(new Vector3f(0f, 4f, 0f)); | ||
statBall.setPhysicsLocation(new Vector3f(0.1f, 0f, 0f)); | ||
|
||
// BulletAppState drives the physics simulation... | ||
} | ||
} |