scsdcc
This commit is contained in:
parent
e1987bfd1f
commit
764fd5eec0
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisionshapes;
|
||||||
|
|
||||||
|
import net.frameworkgl.gameobjects.GameObject;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import org.atriasoft.ephysics.body.RigidBody;
|
||||||
|
import org.atriasoft.ephysics.collision.shapes.CollisionShape;
|
||||||
|
import org.atriasoft.ephysics.engine.DynamicsWorld;
|
||||||
|
import org.atriasoft.ephysics.mathematics.Matrix3x3;
|
||||||
|
import org.atriasoft.etk.math.Quaternion;
|
||||||
|
import org.atriasoft.ephysics.mathematics.Transform;
|
||||||
|
import org.atriasoft.ephysics.mathematics.Vector3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public abstract class AbstractGameObjectShape extends GameObject {
|
||||||
|
|
||||||
|
private CollisionShape collisionShape;
|
||||||
|
private RigidBody rigidBody;
|
||||||
|
|
||||||
|
protected void createRigidBody(CollisionShape collisionShape, Vector3f position, float mass, DynamicsWorld dynamicsWorld) {
|
||||||
|
|
||||||
|
this.collisionShape = collisionShape;
|
||||||
|
|
||||||
|
Matrix3x3 inertiaTensor = collisionShape.computeLocalInertiaTensor(mass);
|
||||||
|
|
||||||
|
Quaternion initOrientation = new Quaternion().identity();
|
||||||
|
Vector3 initPosition = new Vector3(position.getX(), position.getY(), position.getZ());
|
||||||
|
Transform transform = new Transform(initPosition, initOrientation);
|
||||||
|
|
||||||
|
rigidBody = dynamicsWorld.createRigidBody(transform, mass, inertiaTensor, collisionShape);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CollisionShape getCollisionShape() {
|
||||||
|
return collisionShape;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RigidBody getRigidBody() {
|
||||||
|
return rigidBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTransform() {
|
||||||
|
|
||||||
|
// Get the interpolated transform of the rigid body
|
||||||
|
Transform transform = rigidBody.getInterpolatedTransform(new Transform());
|
||||||
|
|
||||||
|
// Compute the transform used for rendering the box
|
||||||
|
float[] glMatrix = new float[16];
|
||||||
|
transform.getOpenGLMatrix(glMatrix);
|
||||||
|
|
||||||
|
// Apply the scaling matrix to have the correct box dimensions
|
||||||
|
getWorldTransform().fromOpenGLArray(glMatrix);
|
||||||
|
getWorldTransform().multiply(getScalingTransform());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisionshapes;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import net.frameworkgl.Fw;
|
||||||
|
import net.frameworkgl.math.Transform4f;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import net.frameworkgl.opengl.GL;
|
||||||
|
import net.frameworkgl.opengl.mesh.Mesh;
|
||||||
|
import net.frameworkgl.opengl.renderable.AbstractRenderable;
|
||||||
|
import org.atriasoft.ephysics.collision.shapes.BoxShape;
|
||||||
|
import org.atriasoft.ephysics.engine.DynamicsWorld;
|
||||||
|
import org.atriasoft.ephysics.mathematics.Vector3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class Box extends AbstractGameObjectShape {
|
||||||
|
|
||||||
|
public Box(Vector3f position, Vector3f size, float mass, DynamicsWorld dynamicsWorld) {
|
||||||
|
|
||||||
|
// Scaling
|
||||||
|
Vector3f halfSize = new Vector3f(size).multiply(0.5f);
|
||||||
|
Transform4f scaling = new Transform4f();
|
||||||
|
scaling.getRotation().setDiagonal(halfSize);
|
||||||
|
setScalingTransform(scaling); // Attach to game object
|
||||||
|
|
||||||
|
Vector3 extent = new Vector3(size.getX(), size.getY(), size.getZ()).multiply(0.5f);
|
||||||
|
BoxShape collisionShape = new BoxShape(extent, 0.02f);
|
||||||
|
createRigidBody(collisionShape, position, mass, dynamicsWorld);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Mesh
|
||||||
|
Mesh mesh = GL.meshFactory.createMesh();
|
||||||
|
setMesh(mesh); // Attach mesh to game object
|
||||||
|
Fw.graphics.loadMesh("primitives/cube.obj", mesh);
|
||||||
|
mesh.setAllColors(0.3f, 0.3f, 0.3f, 1.0f);
|
||||||
|
mesh.updateHasBooleansFromSegment();
|
||||||
|
|
||||||
|
// Renderable
|
||||||
|
AbstractRenderable renderable = Fw.graphics.createInterleavedRenderable();
|
||||||
|
renderable.create(mesh);
|
||||||
|
setRenderable(renderable); // Attach to game object
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisionshapes;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import net.frameworkgl.Fw;
|
||||||
|
import net.frameworkgl.math.Transform4f;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import net.frameworkgl.opengl.GL;
|
||||||
|
import net.frameworkgl.opengl.mesh.Mesh;
|
||||||
|
import net.frameworkgl.opengl.renderable.AbstractRenderable;
|
||||||
|
import org.atriasoft.ephysics.collision.shapes.CapsuleShape;
|
||||||
|
import org.atriasoft.ephysics.engine.DynamicsWorld;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class Capsule extends AbstractGameObjectShape {
|
||||||
|
|
||||||
|
public Capsule(Vector3f position, float height, float radius, float mass, DynamicsWorld dynamicsWorld) {
|
||||||
|
|
||||||
|
// Scaling
|
||||||
|
Vector3f size = new Vector3f(radius, (height + 2.0f * radius) / 3.0f, radius);
|
||||||
|
Transform4f scaling = new Transform4f();
|
||||||
|
scaling.getRotation().setDiagonal(size);
|
||||||
|
setScalingTransform(scaling); // Attach to game object
|
||||||
|
|
||||||
|
CapsuleShape collisionShape = new CapsuleShape(radius, height, 0.02f);
|
||||||
|
createRigidBody(collisionShape, position, mass, dynamicsWorld);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Mesh
|
||||||
|
Mesh mesh = GL.meshFactory.createMesh();
|
||||||
|
setMesh(mesh); // Attach mesh to game object
|
||||||
|
Fw.graphics.loadMesh("primitives/capsule.obj", mesh);
|
||||||
|
mesh.setAllColors(0.8f, 0.8f, 0.8f, 1.0f);
|
||||||
|
mesh.updateHasBooleansFromSegment();
|
||||||
|
|
||||||
|
// Renderable
|
||||||
|
AbstractRenderable renderable = Fw.graphics.createInterleavedRenderable();
|
||||||
|
renderable.create(mesh);
|
||||||
|
setRenderable(renderable); // Attach to game object
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,408 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisionshapes;
|
||||||
|
|
||||||
|
import java.nio.FloatBuffer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import net.frameworkgl.Fw;
|
||||||
|
import net.frameworkgl.gameobjects.GameObject;
|
||||||
|
import net.frameworkgl.Screen;
|
||||||
|
import net.frameworkgl.helpers.Keyboard;
|
||||||
|
import net.frameworkgl.math.MathHelper;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import net.frameworkgl.opengl.GL;
|
||||||
|
import net.frameworkgl.opengl.camera.LegacyCamera;
|
||||||
|
import net.frameworkgl.opengl.camera.LegacyCameraController;
|
||||||
|
import net.frameworkgl.opengl.constants.GetString;
|
||||||
|
import net.frameworkgl.opengl.constants.Light;
|
||||||
|
import net.frameworkgl.utils.FpsTimer;
|
||||||
|
import net.frameworkgl.utils.MemoryUsage;
|
||||||
|
import org.atriasoft.ephysics.body.RigidBody;
|
||||||
|
import org.atriasoft.ephysics.constraint.ContactPoint;
|
||||||
|
import org.atriasoft.ephysics.engine.ContactManifold;
|
||||||
|
import org.atriasoft.ephysics.engine.DynamicsWorld;
|
||||||
|
import org.atriasoft.ephysics.engine.Material;
|
||||||
|
import org.atriasoft.ephysics.mathematics.Vector3;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class CollisionShapes extends Screen {
|
||||||
|
|
||||||
|
private final static Logger log = LoggerFactory.getLogger(CollisionShapes.class);
|
||||||
|
private static final float BOX_MASS = 1.0f;
|
||||||
|
private static final float CAPSULE_HEIGHT = 1.0f;
|
||||||
|
private static final float CAPSULE_MASS = 1.0f;
|
||||||
|
private static final float CAPSULE_RADIUS = 1.0f;
|
||||||
|
private static final float CONE_HEIGHT = 3.0f;
|
||||||
|
private static final float CONE_MASS = 1.0f;
|
||||||
|
private static final float CONE_RADIUS = 2.0f;
|
||||||
|
private static final float CYLINDER_HEIGHT = 5.0f;
|
||||||
|
private static final float CYLINDER_MASS = 1.0f;
|
||||||
|
private static final float CYLINDER_RADIUS = 1.0f;
|
||||||
|
private static final float FLOOR_MASS = 100.0f;
|
||||||
|
private static final float SPHERE_MASS = 1.5f;
|
||||||
|
private static final float SPHERE_RADIUS = 1.0f;
|
||||||
|
private static final int MAX_BOXES = 5;
|
||||||
|
private static final int MAX_CAPSULES = 5;
|
||||||
|
private static final int MAX_CONES = 5;
|
||||||
|
private static final int MAX_CYLINDERS = 5;
|
||||||
|
private static final int MAX_SPHERES = 5;
|
||||||
|
private static final Vector3f BOX_SIZE = new Vector3f(2.0f, 2.0f, 2.0f);
|
||||||
|
private static final Vector3f FLOOR_SIZE = new Vector3f(50.0f, 0.5f, 50.0f);
|
||||||
|
|
||||||
|
private DynamicsWorld dynamicsWorld;
|
||||||
|
private FloatBuffer lightFloatBuffer;
|
||||||
|
private FpsTimer fpsTimer;
|
||||||
|
private LegacyCamera camera;
|
||||||
|
private LegacyCameraController cameraController;
|
||||||
|
private final List<AbstractGameObjectShape> gameObjectShapes;
|
||||||
|
private final List<VisualContactPoint> visualContactPoints;
|
||||||
|
private MemoryUsage memoryUsage;
|
||||||
|
|
||||||
|
public CollisionShapes(String[] args) {
|
||||||
|
gameObjectShapes = new ArrayList<>();
|
||||||
|
visualContactPoints = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createBoxes() {
|
||||||
|
|
||||||
|
// Create all the boxes of the scene
|
||||||
|
for (int i = 0; i < MAX_BOXES; i++) {
|
||||||
|
|
||||||
|
// Position
|
||||||
|
float angle = i * 30.0f;
|
||||||
|
float radius = 3.0f;
|
||||||
|
Vector3f position = new Vector3f(
|
||||||
|
radius * MathHelper.Cos(angle),
|
||||||
|
60.0f + i * (BOX_SIZE.getY() + 0.8f),
|
||||||
|
radius * MathHelper.Sin(angle));
|
||||||
|
|
||||||
|
// Create a box and a corresponding rigid body in the dynamics world
|
||||||
|
Box box = new Box(position, BOX_SIZE, BOX_MASS, dynamicsWorld);
|
||||||
|
|
||||||
|
// The box is a moving rigid body
|
||||||
|
RigidBody rigidBody = (RigidBody) box.getRigidBody();
|
||||||
|
rigidBody.setIsMotionEnabled(true);
|
||||||
|
|
||||||
|
// Change the material properties of the rigid body
|
||||||
|
Material material = rigidBody.getMaterial();
|
||||||
|
material.setBounciness(0.2f);
|
||||||
|
|
||||||
|
// Add the box to the list of game objects in the scene
|
||||||
|
gameObjectShapes.add(box);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createCapsule() {
|
||||||
|
|
||||||
|
// Create all the capsules of the scene
|
||||||
|
for (int i = 0; i < MAX_CAPSULES; i++) {
|
||||||
|
|
||||||
|
// Position
|
||||||
|
float angle = i * 45.0f;
|
||||||
|
float radius = 3.0f;
|
||||||
|
Vector3f position = new Vector3f(
|
||||||
|
radius * MathHelper.Cos(angle),
|
||||||
|
15.0f + i * (CAPSULE_HEIGHT + 0.5f),
|
||||||
|
radius * MathHelper.Sin(angle));
|
||||||
|
|
||||||
|
// Create a capsule and a corresponding rigid body in the dynamics world
|
||||||
|
Capsule capsule = new Capsule(position, CAPSULE_HEIGHT, CAPSULE_RADIUS, CAPSULE_MASS, dynamicsWorld);
|
||||||
|
|
||||||
|
// The cylinder is a moving rigid body
|
||||||
|
RigidBody rigidBody = (RigidBody) capsule.getRigidBody();
|
||||||
|
rigidBody.setIsMotionEnabled(true);
|
||||||
|
|
||||||
|
// Change the material properties of the rigid body
|
||||||
|
Material material = rigidBody.getMaterial();
|
||||||
|
material.setBounciness(0.2f);
|
||||||
|
|
||||||
|
// Add the capsule to the list of game objects in the scene
|
||||||
|
gameObjectShapes.add(capsule);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createCones() {
|
||||||
|
|
||||||
|
// Create all the cones of the scene
|
||||||
|
for (int i = 0; i < MAX_CONES; i++) {
|
||||||
|
|
||||||
|
// Position
|
||||||
|
float angle = i * 50.0f;
|
||||||
|
float radius = 3.0f;
|
||||||
|
Vector3f position = new Vector3f(
|
||||||
|
radius * MathHelper.Cos(angle),
|
||||||
|
35.0f + i * (CONE_HEIGHT + 0.3f),
|
||||||
|
radius * MathHelper.Sin(angle));
|
||||||
|
|
||||||
|
// Create a cone and a corresponding rigid body in the dynamics world
|
||||||
|
Cone cone = new Cone(position, CONE_HEIGHT, CONE_RADIUS, CONE_MASS, dynamicsWorld);
|
||||||
|
|
||||||
|
// The cone is a moving rigid body
|
||||||
|
RigidBody rigidBody = (RigidBody) cone.getRigidBody();
|
||||||
|
rigidBody.setIsMotionEnabled(true);
|
||||||
|
|
||||||
|
// Change the material properties of the rigid body
|
||||||
|
Material material = rigidBody.getMaterial();
|
||||||
|
material.setBounciness(0.2f);
|
||||||
|
|
||||||
|
// Add the cone to the list of game objects in the scene
|
||||||
|
gameObjectShapes.add(cone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createCylinder() {
|
||||||
|
|
||||||
|
// Create all the cylinders of the scene
|
||||||
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
||||||
|
|
||||||
|
// Position
|
||||||
|
float angle = i * 35.0f;
|
||||||
|
float radius = 3.0f;
|
||||||
|
Vector3f position = new Vector3f(
|
||||||
|
radius * MathHelper.Cos(angle),
|
||||||
|
25.0f + i * (CYLINDER_HEIGHT + 0.3f),
|
||||||
|
radius * MathHelper.Sin(angle));
|
||||||
|
|
||||||
|
// Create a cylinder and a corresponding rigid body in the dynamics world
|
||||||
|
Cylinder cylinder = new Cylinder(position, CYLINDER_HEIGHT, CYLINDER_RADIUS, CYLINDER_MASS, dynamicsWorld);
|
||||||
|
|
||||||
|
// The cylinder is a moving rigid body
|
||||||
|
RigidBody rigidBody = (RigidBody) cylinder.getRigidBody();
|
||||||
|
rigidBody.setIsMotionEnabled(true);
|
||||||
|
|
||||||
|
// Change the material properties of the rigid body
|
||||||
|
Material material = rigidBody.getMaterial();
|
||||||
|
material.setBounciness(0.2f);
|
||||||
|
|
||||||
|
// Add the cylinder to the list of game objects in the scene
|
||||||
|
gameObjectShapes.add(cylinder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createFloor() {
|
||||||
|
|
||||||
|
// Create the floor
|
||||||
|
Vector3f floorPosition = new Vector3f();
|
||||||
|
Box floor = new Box(floorPosition, FLOOR_SIZE, FLOOR_MASS, dynamicsWorld);
|
||||||
|
|
||||||
|
// The floor must be a non-moving rigid body
|
||||||
|
RigidBody rigidBody = (RigidBody) floor.getRigidBody();
|
||||||
|
rigidBody.setIsMotionEnabled(false);
|
||||||
|
|
||||||
|
// Change the material properties of the rigid body
|
||||||
|
Material material = rigidBody.getMaterial();
|
||||||
|
material.setBounciness(0.2f);
|
||||||
|
|
||||||
|
// Add the floor to the list of game objects in the scene
|
||||||
|
gameObjectShapes.add(floor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createSpheres() {
|
||||||
|
|
||||||
|
// Create all the spheres of the scene
|
||||||
|
for (int i = 0; i < MAX_SPHERES; i++) {
|
||||||
|
|
||||||
|
// Position
|
||||||
|
float angle = i * 35.0f;
|
||||||
|
float radius = 3.0f;
|
||||||
|
Vector3f position = new Vector3f(
|
||||||
|
radius * MathHelper.Cos(angle),
|
||||||
|
50.0f + i * (SPHERE_RADIUS + 0.8f),
|
||||||
|
radius * MathHelper.Sin(angle));
|
||||||
|
|
||||||
|
// Create a sphere and a corresponding rigid body in the dynamics world
|
||||||
|
Sphere sphere = new Sphere(position, SPHERE_RADIUS, SPHERE_MASS, dynamicsWorld);
|
||||||
|
|
||||||
|
// The sphere is a moving rigid body
|
||||||
|
RigidBody rigidBody = (RigidBody) sphere.getRigidBody();
|
||||||
|
rigidBody.setIsMotionEnabled(true);
|
||||||
|
|
||||||
|
// Change the material properties of the rigid body
|
||||||
|
Material material = rigidBody.getMaterial();
|
||||||
|
material.setBounciness(0.2f);
|
||||||
|
|
||||||
|
// Add the sphere to the list of game objects in the scene
|
||||||
|
gameObjectShapes.add(sphere);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateContactPoints() {
|
||||||
|
visualContactPoints.clear();
|
||||||
|
List<ContactManifold> contactManifolds = dynamicsWorld.getContactManifolds();
|
||||||
|
for (ContactManifold contactManifold : contactManifolds) {
|
||||||
|
for (int i = 0; i < contactManifold.getNumContactPoints(); i++) {
|
||||||
|
ContactPoint point = contactManifold.getContactPoint(i);
|
||||||
|
Vector3 pos = point.getWorldPointOnBody1();
|
||||||
|
Vector3f position = new Vector3f(pos.getX(), pos.getY(), pos.getZ());
|
||||||
|
VisualContactPoint visualPoint = new VisualContactPoint(position);
|
||||||
|
visualContactPoints.add(visualPoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleInput() {
|
||||||
|
if (Fw.input.isKeyDown(Keyboard.ESCAPE) == true) {
|
||||||
|
Fw.app.stopRunning();
|
||||||
|
}
|
||||||
|
cameraController.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
for (GameObject gameObjectShape : gameObjectShapes) {
|
||||||
|
gameObjectShape.destroy();
|
||||||
|
}
|
||||||
|
VisualContactPoint.Destroy();
|
||||||
|
Fw.input.removeInputProcessor(cameraController);
|
||||||
|
Fw.input.releaseMouseCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
|
||||||
|
// Create timer
|
||||||
|
fpsTimer = new FpsTimer();
|
||||||
|
|
||||||
|
// Setup camera and controller
|
||||||
|
camera = GL.cameraFactory.createLegacyCamera();
|
||||||
|
camera.setPosition(0.0f, 6.0f, 25.0f);
|
||||||
|
cameraController = GL.cameraFactory.createLegacyCameraController();
|
||||||
|
cameraController.setCamera(camera);
|
||||||
|
|
||||||
|
// Time step and gravity for the physics simulation
|
||||||
|
float timeStep = 1.0f / 60.0f;
|
||||||
|
Vector3 gravity = new Vector3(0, -9.81f, 0);
|
||||||
|
|
||||||
|
// Create dynamics world
|
||||||
|
dynamicsWorld = new DynamicsWorld(gravity, timeStep);
|
||||||
|
dynamicsWorld.start();
|
||||||
|
|
||||||
|
// Float buffer for light and matrices
|
||||||
|
lightFloatBuffer = GL.bufferHelper.createFloatBuffer(4);
|
||||||
|
|
||||||
|
// Memory usage
|
||||||
|
memoryUsage = new MemoryUsage();
|
||||||
|
|
||||||
|
// Create game objects
|
||||||
|
createBoxes();
|
||||||
|
createCapsule();
|
||||||
|
createCones();
|
||||||
|
createCylinder();
|
||||||
|
createFloor();
|
||||||
|
createSpheres();
|
||||||
|
|
||||||
|
GL.o1.enableCulling();
|
||||||
|
GL.o1.cullBackFaces();
|
||||||
|
GL.o1.enableDepthTest();
|
||||||
|
GL.o1.setDepthFuncLess();
|
||||||
|
GL.o1.enableDepthMask();
|
||||||
|
GL.o1.setClearDepth(1.0f);
|
||||||
|
GL.o1.enableColorMaterial();
|
||||||
|
GL.o1.enableLight0();
|
||||||
|
GL.o1.enableLighting();
|
||||||
|
GL.o1.setSmoothLighting(true);
|
||||||
|
GL.o1.enableNormalize();
|
||||||
|
GL.o1.clear();
|
||||||
|
|
||||||
|
GL.o1.setProjectionPerspective(
|
||||||
|
70.0f,
|
||||||
|
(float) Fw.config.getCurrentWidth() / (float) Fw.config.getCurrentHeight(),
|
||||||
|
0.05f, 512.0f);
|
||||||
|
GL.o1.setModelViewIdentity();
|
||||||
|
|
||||||
|
// Light position
|
||||||
|
lightFloatBuffer.put(0.0f);
|
||||||
|
lightFloatBuffer.put(15.0f);
|
||||||
|
lightFloatBuffer.put(0.0f);
|
||||||
|
lightFloatBuffer.put(1.0f);
|
||||||
|
lightFloatBuffer.flip();
|
||||||
|
|
||||||
|
log.info("OpenGL version: " + GL.o1.getString(GetString.VERSION));
|
||||||
|
|
||||||
|
Fw.input.addInputProcessor(cameraController);
|
||||||
|
Fw.input.grabMouseCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pause() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render() {
|
||||||
|
fpsTimer.update();
|
||||||
|
memoryUsage.update();
|
||||||
|
|
||||||
|
if (Fw.timer.isGameTick()) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Fw.timer.isRenderTick()) {
|
||||||
|
handleInput();
|
||||||
|
|
||||||
|
// Take a simulation step
|
||||||
|
dynamicsWorld.update();
|
||||||
|
|
||||||
|
// Generate the new visual contact points
|
||||||
|
generateContactPoints();
|
||||||
|
|
||||||
|
// Clear screen and reset modelview matrix
|
||||||
|
GL.o1.clear();
|
||||||
|
GL.o1.setModelViewIdentity();
|
||||||
|
|
||||||
|
camera.updateOpenGL();
|
||||||
|
|
||||||
|
GL.o1.light(Light.LIGHT0, Light.POSITION, lightFloatBuffer);
|
||||||
|
|
||||||
|
// Render directly
|
||||||
|
for (AbstractGameObjectShape gameObjectShape : gameObjectShapes) {
|
||||||
|
gameObjectShape.updateTransform();
|
||||||
|
Fw.graphics.render(gameObjectShape);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render contact points
|
||||||
|
GL.o1.disableDepthTest();
|
||||||
|
for (GameObject visualContactPoint : visualContactPoints) {
|
||||||
|
Fw.graphics.render(visualContactPoint);
|
||||||
|
}
|
||||||
|
GL.o1.enableDepthTest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resize(int width, int height) {
|
||||||
|
GL.o1.setViewport(0, 0, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resume() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisionshapes;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import net.frameworkgl.Fw;
|
||||||
|
import net.frameworkgl.math.Transform4f;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import net.frameworkgl.opengl.GL;
|
||||||
|
import net.frameworkgl.opengl.mesh.Mesh;
|
||||||
|
import net.frameworkgl.opengl.renderable.AbstractRenderable;
|
||||||
|
import org.atriasoft.ephysics.collision.shapes.ConeShape;
|
||||||
|
import org.atriasoft.ephysics.engine.DynamicsWorld;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class Cone extends AbstractGameObjectShape {
|
||||||
|
|
||||||
|
public Cone(Vector3f position, float height, float radius, float mass, DynamicsWorld dynamicsWorld) {
|
||||||
|
|
||||||
|
// Scaling
|
||||||
|
Vector3f size = new Vector3f(radius, height, radius);
|
||||||
|
Transform4f scaling = new Transform4f();
|
||||||
|
scaling.getRotation().setDiagonal(size);
|
||||||
|
setScalingTransform(scaling); // Attach to game object
|
||||||
|
|
||||||
|
ConeShape collisionShape = new ConeShape(radius, height, 0.02f);
|
||||||
|
createRigidBody(collisionShape, position, mass, dynamicsWorld);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Mesh
|
||||||
|
Mesh mesh = GL.meshFactory.createMesh();
|
||||||
|
setMesh(mesh); // Attach mesh to game object
|
||||||
|
Fw.graphics.loadMesh("primitives/cone.obj", mesh);
|
||||||
|
mesh.setAllColors(0.8f, 0.8f, 0.8f, 1.0f);
|
||||||
|
mesh.updateHasBooleansFromSegment();
|
||||||
|
|
||||||
|
// Renderable
|
||||||
|
AbstractRenderable renderable = Fw.graphics.createInterleavedRenderable();
|
||||||
|
renderable.create(mesh);
|
||||||
|
setRenderable(renderable); // Attach to game object
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisionshapes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class Configuration extends net.frameworkgl.Configuration {
|
||||||
|
|
||||||
|
public Configuration(String[] args) {
|
||||||
|
super(args);
|
||||||
|
withOpenGL33ProfileCompatibility();
|
||||||
|
setWindowTitle("Collision Shapes");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisionshapes;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import net.frameworkgl.Fw;
|
||||||
|
import net.frameworkgl.math.Transform4f;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import net.frameworkgl.opengl.GL;
|
||||||
|
import net.frameworkgl.opengl.mesh.Mesh;
|
||||||
|
import net.frameworkgl.opengl.renderable.AbstractRenderable;
|
||||||
|
import org.atriasoft.ephysics.collision.shapes.CylinderShape;
|
||||||
|
import org.atriasoft.ephysics.engine.DynamicsWorld;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class Cylinder extends AbstractGameObjectShape {
|
||||||
|
|
||||||
|
public Cylinder(Vector3f position, float height, float radius, float mass, DynamicsWorld dynamicsWorld) {
|
||||||
|
|
||||||
|
// Scaling
|
||||||
|
Vector3f size = new Vector3f(radius, height, radius);
|
||||||
|
Transform4f scaling = new Transform4f();
|
||||||
|
scaling.getRotation().setDiagonal(size);
|
||||||
|
setScalingTransform(scaling); // Attach to game object
|
||||||
|
|
||||||
|
CylinderShape collisionShape = new CylinderShape(radius, height, 0.02f);
|
||||||
|
createRigidBody(collisionShape, position, mass, dynamicsWorld);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Mesh
|
||||||
|
Mesh mesh = GL.meshFactory.createMesh();
|
||||||
|
setMesh(mesh); // Attach mesh to game object
|
||||||
|
Fw.graphics.loadMesh("primitives/cylinder.obj", mesh);
|
||||||
|
mesh.setAllColors(0.8f, 0.8f, 0.8f, 1.0f);
|
||||||
|
mesh.updateHasBooleansFromSegment();
|
||||||
|
|
||||||
|
// Renderable
|
||||||
|
AbstractRenderable renderable = Fw.graphics.createInterleavedRenderable();
|
||||||
|
renderable.create(mesh);
|
||||||
|
setRenderable(renderable); // Attach to game object
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisionshapes;
|
||||||
|
|
||||||
|
import net.frameworkgl.Bootstrap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class Demo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param args the command line arguments
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Bootstrap boot = new Bootstrap();
|
||||||
|
boot.start(Configuration.class, CollisionShapes.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisionshapes;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import net.frameworkgl.Fw;
|
||||||
|
import net.frameworkgl.math.Transform4f;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import net.frameworkgl.opengl.GL;
|
||||||
|
import net.frameworkgl.opengl.mesh.Mesh;
|
||||||
|
import net.frameworkgl.opengl.renderable.AbstractRenderable;
|
||||||
|
import org.atriasoft.ephysics.collision.shapes.SphereShape;
|
||||||
|
import org.atriasoft.ephysics.engine.DynamicsWorld;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class Sphere extends AbstractGameObjectShape {
|
||||||
|
|
||||||
|
public Sphere(Vector3f position, float radius, float mass, DynamicsWorld dynamicsWorld) {
|
||||||
|
|
||||||
|
// Scaling
|
||||||
|
Vector3f size = new Vector3f(radius, radius, radius);
|
||||||
|
Transform4f scaling = new Transform4f();
|
||||||
|
scaling.getRotation().setDiagonal(size);
|
||||||
|
setScalingTransform(scaling); // Attach to game object
|
||||||
|
|
||||||
|
SphereShape collisionShape = new SphereShape(radius, 0.02f);
|
||||||
|
createRigidBody(collisionShape, position, mass, dynamicsWorld);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Mesh
|
||||||
|
Mesh mesh = GL.meshFactory.createMesh();
|
||||||
|
setMesh(mesh); // Attach mesh to game object
|
||||||
|
Fw.graphics.loadMesh("primitives/uvsphere.obj", mesh);
|
||||||
|
mesh.setAllColors(0.8f, 0.8f, 0.8f, 1.0f);
|
||||||
|
mesh.updateHasBooleansFromSegment();
|
||||||
|
|
||||||
|
// Renderable
|
||||||
|
AbstractRenderable renderable = Fw.graphics.createInterleavedRenderable();
|
||||||
|
renderable.create(mesh);
|
||||||
|
setRenderable(renderable); // Attach to game object
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisionshapes;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import net.frameworkgl.Fw;
|
||||||
|
import net.frameworkgl.gameobjects.GameObject;
|
||||||
|
import net.frameworkgl.math.Transform4f;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import net.frameworkgl.opengl.GL;
|
||||||
|
import net.frameworkgl.opengl.mesh.Mesh;
|
||||||
|
import net.frameworkgl.opengl.renderable.AbstractRenderable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class VisualContactPoint extends GameObject {
|
||||||
|
|
||||||
|
private static final float VISUAL_CONTACT_POINT_RADIUS = 0.1f;
|
||||||
|
|
||||||
|
private static boolean initialized;
|
||||||
|
private static Mesh staticMesh;
|
||||||
|
private static AbstractRenderable staticRenderable;
|
||||||
|
|
||||||
|
public VisualContactPoint(Vector3f position) {
|
||||||
|
|
||||||
|
// Scaling
|
||||||
|
Vector3f size = new Vector3f(VISUAL_CONTACT_POINT_RADIUS, VISUAL_CONTACT_POINT_RADIUS, VISUAL_CONTACT_POINT_RADIUS);
|
||||||
|
Transform4f scaling = new Transform4f();
|
||||||
|
scaling.getRotation().setDiagonal(size);
|
||||||
|
setScalingTransform(scaling); // Attach to game object
|
||||||
|
|
||||||
|
getWorldTransform().getPosition().set(position);
|
||||||
|
getWorldTransform().multiply(getScalingTransform());
|
||||||
|
|
||||||
|
CreateStaticData();
|
||||||
|
setMesh(staticMesh); // Attach mesh to game object
|
||||||
|
setRenderable(staticRenderable); // Attach to game object
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CreateStaticData() {
|
||||||
|
if (initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Mesh
|
||||||
|
staticMesh = GL.meshFactory.createMesh();
|
||||||
|
Fw.graphics.loadMesh("primitives/cone.obj", staticMesh);
|
||||||
|
staticMesh.setAllColors(1.0f, 1.0f, 0.0f, 1.0f);
|
||||||
|
staticMesh.updateHasBooleansFromSegment();
|
||||||
|
|
||||||
|
// Renderable
|
||||||
|
staticRenderable = Fw.graphics.createInterleavedRenderable();
|
||||||
|
staticRenderable.create(staticMesh);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only do this once
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Destroy() {
|
||||||
|
if (!initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
staticRenderable.destroy();
|
||||||
|
staticRenderable = null;
|
||||||
|
initialized = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisiontest;
|
||||||
|
|
||||||
|
import net.frameworkgl.gameobjects.GameObject;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import org.atriasoft.ephysics.body.RigidBody;
|
||||||
|
import org.atriasoft.ephysics.collision.shapes.CollisionShape;
|
||||||
|
import org.atriasoft.ephysics.engine.DynamicsWorld;
|
||||||
|
import org.atriasoft.ephysics.mathematics.Matrix3x3;
|
||||||
|
import org.atriasoft.etk.math.Quaternion;
|
||||||
|
import org.atriasoft.ephysics.mathematics.Transform;
|
||||||
|
import org.atriasoft.ephysics.mathematics.Vector3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public abstract class AbstractGameObjectShape extends GameObject {
|
||||||
|
|
||||||
|
private CollisionShape collisionShape;
|
||||||
|
private RigidBody rigidBody;
|
||||||
|
|
||||||
|
protected void createRigidBody(
|
||||||
|
CollisionShape collisionShape, Vector3f position, float mass, DynamicsWorld dynamicsWorld) {
|
||||||
|
|
||||||
|
this.collisionShape = collisionShape;
|
||||||
|
|
||||||
|
Matrix3x3 inertiaTensor = collisionShape.computeLocalInertiaTensor(mass);
|
||||||
|
|
||||||
|
Quaternion initOrientation = new Quaternion().identity();
|
||||||
|
Vector3 initPosition = new Vector3(position.getX(), position.getY(), position.getZ());
|
||||||
|
Transform transform = new Transform(initPosition, initOrientation);
|
||||||
|
|
||||||
|
rigidBody = dynamicsWorld.createRigidBody(transform, mass, inertiaTensor, collisionShape);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CollisionShape getCollisionShape() {
|
||||||
|
return collisionShape;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RigidBody getRigidBody() {
|
||||||
|
return rigidBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTransform() {
|
||||||
|
|
||||||
|
// Get the interpolated transform of the rigid body
|
||||||
|
Transform transform = rigidBody.getInterpolatedTransform(new Transform());
|
||||||
|
|
||||||
|
// Compute the transform used for rendering the box
|
||||||
|
float[] glMatrix = new float[16];
|
||||||
|
transform.getOpenGLMatrix(glMatrix);
|
||||||
|
|
||||||
|
// Apply the scaling matrix to have the correct box dimensions
|
||||||
|
getWorldTransform().fromOpenGLArray(glMatrix);
|
||||||
|
getWorldTransform().multiply(getScalingTransform());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisiontest;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import net.frameworkgl.Fw;
|
||||||
|
import net.frameworkgl.math.Transform4f;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import net.frameworkgl.opengl.GL;
|
||||||
|
import net.frameworkgl.opengl.mesh.Mesh;
|
||||||
|
import net.frameworkgl.opengl.renderable.AbstractRenderable;
|
||||||
|
import org.atriasoft.ephysics.collision.shapes.BoxShape;
|
||||||
|
import org.atriasoft.ephysics.engine.DynamicsWorld;
|
||||||
|
import org.atriasoft.ephysics.mathematics.Vector3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class Box extends AbstractGameObjectShape {
|
||||||
|
|
||||||
|
public Box(Vector3f position, Vector3f size, float mass, DynamicsWorld dynamicsWorld) {
|
||||||
|
|
||||||
|
// Scaling
|
||||||
|
Vector3f halfSize = new Vector3f(size).multiply(0.5f);
|
||||||
|
Transform4f scaling = new Transform4f();
|
||||||
|
scaling.getRotation().setDiagonal(halfSize);
|
||||||
|
setScalingTransform(scaling); // Attach to game object
|
||||||
|
|
||||||
|
Vector3 extent = new Vector3(size.getX(), size.getY(), size.getZ()).multiply(0.5f);
|
||||||
|
BoxShape collisionShape = new BoxShape(extent, 0.02f);
|
||||||
|
createRigidBody(collisionShape, position, mass, dynamicsWorld);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Mesh
|
||||||
|
Mesh mesh = GL.meshFactory.createMesh();
|
||||||
|
setMesh(mesh); // Attach mesh to game object
|
||||||
|
Fw.graphics.loadMesh("primitives/cube.obj", mesh);
|
||||||
|
mesh.setAllColors(0.3f, 0.3f, 0.3f, 1.0f);
|
||||||
|
mesh.updateHasBooleansFromSegment();
|
||||||
|
|
||||||
|
// Renderable
|
||||||
|
AbstractRenderable renderable = Fw.graphics.createInterleavedRenderable();
|
||||||
|
renderable.create(mesh);
|
||||||
|
setRenderable(renderable); // Attach to game object
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisiontest;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import net.frameworkgl.Fw;
|
||||||
|
import net.frameworkgl.math.Transform4f;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import net.frameworkgl.opengl.GL;
|
||||||
|
import net.frameworkgl.opengl.mesh.Mesh;
|
||||||
|
import net.frameworkgl.opengl.renderable.AbstractRenderable;
|
||||||
|
import org.atriasoft.ephysics.collision.shapes.CapsuleShape;
|
||||||
|
import org.atriasoft.ephysics.engine.DynamicsWorld;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class Capsule extends AbstractGameObjectShape {
|
||||||
|
|
||||||
|
public Capsule(Vector3f position, float height, float radius, float mass, DynamicsWorld dynamicsWorld) {
|
||||||
|
|
||||||
|
// Scaling
|
||||||
|
Vector3f size = new Vector3f(radius, (height + 2.0f * radius) / 3.0f, radius);
|
||||||
|
Transform4f scaling = new Transform4f();
|
||||||
|
scaling.getRotation().setDiagonal(size);
|
||||||
|
setScalingTransform(scaling); // Attach to game object
|
||||||
|
|
||||||
|
CapsuleShape collisionShape = new CapsuleShape(radius, height, 0.02f);
|
||||||
|
createRigidBody(collisionShape, position, mass, dynamicsWorld);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Mesh
|
||||||
|
Mesh mesh = GL.meshFactory.createMesh();
|
||||||
|
setMesh(mesh); // Attach mesh to game object
|
||||||
|
Fw.graphics.loadMesh("primitives/capsule.obj", mesh);
|
||||||
|
mesh.setAllColors(0.8f, 0.8f, 0.8f, 1.0f);
|
||||||
|
mesh.updateHasBooleansFromSegment();
|
||||||
|
|
||||||
|
// Renderable
|
||||||
|
AbstractRenderable renderable = Fw.graphics.createInterleavedRenderable();
|
||||||
|
renderable.create(mesh);
|
||||||
|
setRenderable(renderable); // Attach to game object
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,280 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisiontest;
|
||||||
|
|
||||||
|
import java.nio.FloatBuffer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import net.frameworkgl.Fw;
|
||||||
|
import net.frameworkgl.gameobjects.GameObject;
|
||||||
|
import net.frameworkgl.Screen;
|
||||||
|
import net.frameworkgl.helpers.Keyboard;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import net.frameworkgl.opengl.GL;
|
||||||
|
import net.frameworkgl.opengl.camera.LegacyCamera;
|
||||||
|
import net.frameworkgl.opengl.camera.LegacyCameraController;
|
||||||
|
import net.frameworkgl.opengl.constants.GetString;
|
||||||
|
import net.frameworkgl.opengl.constants.Light;
|
||||||
|
import net.frameworkgl.utils.FpsTimer;
|
||||||
|
import net.frameworkgl.utils.MemoryUsage;
|
||||||
|
import org.atriasoft.ephysics.body.RigidBody;
|
||||||
|
import org.atriasoft.ephysics.constraint.ContactPoint;
|
||||||
|
import org.atriasoft.ephysics.engine.ContactManifold;
|
||||||
|
import org.atriasoft.ephysics.engine.DynamicsWorld;
|
||||||
|
import org.atriasoft.ephysics.engine.Material;
|
||||||
|
import org.atriasoft.ephysics.mathematics.Vector3;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class CollisionTest extends Screen {
|
||||||
|
|
||||||
|
private final static Logger log = LoggerFactory.getLogger(CollisionTest.class);
|
||||||
|
private static final float BOX_MASS = 1.0f;
|
||||||
|
private static final float CAPSULE_HEIGHT = 1.0f;
|
||||||
|
private static final float CAPSULE_MASS = 1.0f;
|
||||||
|
private static final float CAPSULE_RADIUS = 1.0f;
|
||||||
|
private static final float CONE_HEIGHT = 3.0f;
|
||||||
|
private static final float CONE_MASS = 1.0f;
|
||||||
|
private static final float CONE_RADIUS = 2.0f;
|
||||||
|
private static final float CYLINDER_HEIGHT = 5.0f;
|
||||||
|
private static final float CYLINDER_MASS = 1.0f;
|
||||||
|
private static final float CYLINDER_RADIUS = 1.0f;
|
||||||
|
private static final float FLOOR_MASS = 100.0f;
|
||||||
|
private static final float SPHERE_MASS = 1.5f;
|
||||||
|
private static final float SPHERE_RADIUS = 1.0f;
|
||||||
|
private static final Vector3f BOX_SIZE = new Vector3f(2.0f, 2.0f, 2.0f);
|
||||||
|
|
||||||
|
private DynamicsWorld dynamicsWorld;
|
||||||
|
private FloatBuffer lightFloatBuffer;
|
||||||
|
private FpsTimer fpsTimer;
|
||||||
|
private LegacyCamera camera;
|
||||||
|
private LegacyCameraController cameraController;
|
||||||
|
private final List<AbstractGameObjectShape> gameObjectShapes;
|
||||||
|
private final List<VisualContactPoint> visualContactPoints;
|
||||||
|
private MemoryUsage memoryUsage;
|
||||||
|
|
||||||
|
public CollisionTest(String[] args) {
|
||||||
|
gameObjectShapes = new ArrayList<>();
|
||||||
|
visualContactPoints = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateContactPoints() {
|
||||||
|
visualContactPoints.clear();
|
||||||
|
List<ContactManifold> contactManifolds = dynamicsWorld.getContactManifolds();
|
||||||
|
for (ContactManifold contactManifold : contactManifolds) {
|
||||||
|
for (int i = 0; i < contactManifold.getNumContactPoints(); i++) {
|
||||||
|
ContactPoint point = contactManifold.getContactPoint(i);
|
||||||
|
Vector3 pos = point.getWorldPointOnBody1();
|
||||||
|
Vector3f position = new Vector3f(pos.getX(), pos.getY(), pos.getZ());
|
||||||
|
VisualContactPoint visualPoint = new VisualContactPoint(position);
|
||||||
|
visualContactPoints.add(visualPoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleInput() {
|
||||||
|
if (Fw.input.isKeyDown(Keyboard.ESCAPE) == true) {
|
||||||
|
Fw.app.stopRunning();
|
||||||
|
}
|
||||||
|
Vector3f direction = new Vector3f();
|
||||||
|
if (Fw.input.isKeyDown(Keyboard.NUM0) == true) {
|
||||||
|
direction.setY(1.0f);
|
||||||
|
}
|
||||||
|
if (Fw.input.isKeyDown(Keyboard.NUM2) == true) {
|
||||||
|
direction.setY(-1.0f);
|
||||||
|
}
|
||||||
|
if (Fw.input.isKeyDown(Keyboard.NUM4) == true) {
|
||||||
|
direction.setX(-1.0f);
|
||||||
|
}
|
||||||
|
if (Fw.input.isKeyDown(Keyboard.NUM6) == true) {
|
||||||
|
direction.setX(1.0f);
|
||||||
|
}
|
||||||
|
if (Fw.input.isKeyDown(Keyboard.NUM7) == true) {
|
||||||
|
direction.setZ(-1.0f);
|
||||||
|
}
|
||||||
|
if (Fw.input.isKeyDown(Keyboard.NUM9) == true) {
|
||||||
|
direction.setZ(1.0f);
|
||||||
|
}
|
||||||
|
RigidBody rigidBody = (RigidBody) cylinderMoveable.getRigidBody();
|
||||||
|
if (Fw.input.isKeyDown(Keyboard.NUM1) == true) {
|
||||||
|
rigidBody.applyTorque(new Vector3(0.5f, 0.0f, 0.0f));
|
||||||
|
}
|
||||||
|
if (Fw.input.isKeyDown(Keyboard.NUM3) == true) {
|
||||||
|
rigidBody.applyTorque(new Vector3(-0.5f, 0.0f, 0.0f));
|
||||||
|
}
|
||||||
|
if (direction.magnitudeSquared() > 0) {
|
||||||
|
direction.normalize();
|
||||||
|
rigidBody.applyForceToCenter(new Vector3(direction.getX(), direction.getY(), direction.getZ()));
|
||||||
|
}
|
||||||
|
cameraController.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
for (GameObject gameObjectShape : gameObjectShapes) {
|
||||||
|
gameObjectShape.destroy();
|
||||||
|
}
|
||||||
|
VisualContactPoint.Destroy();
|
||||||
|
Fw.input.removeInputProcessor(cameraController);
|
||||||
|
Fw.input.releaseMouseCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Cylinder cylinderMoveable;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
|
||||||
|
// Create timer
|
||||||
|
fpsTimer = new FpsTimer();
|
||||||
|
|
||||||
|
// Setup camera and controller
|
||||||
|
camera = GL.cameraFactory.createLegacyCamera();
|
||||||
|
camera.setPosition(0.0f, 1.0f, 5.0f);
|
||||||
|
cameraController = GL.cameraFactory.createLegacyCameraController();
|
||||||
|
cameraController.setCamera(camera);
|
||||||
|
|
||||||
|
// Time step and gravity for the physics simulation
|
||||||
|
float timeStep = 1.0f / 60.0f;
|
||||||
|
Vector3 gravity = new Vector3(0, -9.81f, 0);
|
||||||
|
|
||||||
|
// Create dynamics world
|
||||||
|
dynamicsWorld = new DynamicsWorld(gravity, timeStep);
|
||||||
|
dynamicsWorld.setIsGratityEnabled(false);
|
||||||
|
dynamicsWorld.start();
|
||||||
|
|
||||||
|
// Float buffer for light and matrices
|
||||||
|
lightFloatBuffer = GL.bufferHelper.createFloatBuffer(4);
|
||||||
|
|
||||||
|
// Memory usage
|
||||||
|
memoryUsage = new MemoryUsage();
|
||||||
|
|
||||||
|
// Add spheres
|
||||||
|
Material material;
|
||||||
|
RigidBody rigidBody;
|
||||||
|
Box floor;
|
||||||
|
floor = new Box(new Vector3f(), new Vector3f(40.0f, 0.5f, 40.0f), FLOOR_MASS, dynamicsWorld);
|
||||||
|
rigidBody = (RigidBody) floor.getRigidBody();
|
||||||
|
rigidBody.setIsMotionEnabled(false);
|
||||||
|
material = rigidBody.getMaterial();
|
||||||
|
material.setBounciness(0.2f);
|
||||||
|
gameObjectShapes.add(floor);
|
||||||
|
cylinderMoveable = new Cylinder(new Vector3f(0.0f, 3.0f, 0.0f), CYLINDER_HEIGHT, CYLINDER_RADIUS, CYLINDER_MASS, dynamicsWorld);
|
||||||
|
rigidBody = (RigidBody) cylinderMoveable.getRigidBody();
|
||||||
|
rigidBody.setIsMotionEnabled(true);
|
||||||
|
material = rigidBody.getMaterial();
|
||||||
|
material.setBounciness(0.2f);
|
||||||
|
gameObjectShapes.add(cylinderMoveable);
|
||||||
|
|
||||||
|
GL.o1.enableCulling();
|
||||||
|
GL.o1.cullBackFaces();
|
||||||
|
GL.o1.enableDepthTest();
|
||||||
|
GL.o1.setDepthFuncLess();
|
||||||
|
GL.o1.enableDepthMask();
|
||||||
|
GL.o1.setClearDepth(1.0f);
|
||||||
|
GL.o1.enableColorMaterial();
|
||||||
|
GL.o1.enableLight0();
|
||||||
|
GL.o1.enableLighting();
|
||||||
|
GL.o1.setSmoothLighting(true);
|
||||||
|
GL.o1.enableNormalize();
|
||||||
|
GL.o1.clear();
|
||||||
|
|
||||||
|
GL.o1.setProjectionPerspective(
|
||||||
|
70.0f,
|
||||||
|
(float) Fw.config.getCurrentWidth() / (float) Fw.config.getCurrentHeight(),
|
||||||
|
0.05f, 512.0f);
|
||||||
|
GL.o1.setModelViewIdentity();
|
||||||
|
|
||||||
|
// Light position
|
||||||
|
lightFloatBuffer.put(0.0f);
|
||||||
|
lightFloatBuffer.put(15.0f);
|
||||||
|
lightFloatBuffer.put(0.0f);
|
||||||
|
lightFloatBuffer.put(1.0f);
|
||||||
|
lightFloatBuffer.flip();
|
||||||
|
|
||||||
|
log.info("OpenGL version: " + GL.o1.getString(GetString.VERSION));
|
||||||
|
|
||||||
|
Fw.input.addInputProcessor(cameraController);
|
||||||
|
Fw.input.grabMouseCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pause() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render() {
|
||||||
|
fpsTimer.update();
|
||||||
|
memoryUsage.update();
|
||||||
|
|
||||||
|
if (Fw.timer.isGameTick()) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Fw.timer.isRenderTick()) {
|
||||||
|
handleInput();
|
||||||
|
|
||||||
|
// Take a simulation step
|
||||||
|
dynamicsWorld.update();
|
||||||
|
|
||||||
|
// Generate the new visual contact points
|
||||||
|
generateContactPoints();
|
||||||
|
|
||||||
|
// Clear screen and reset modelview matrix
|
||||||
|
GL.o1.clear();
|
||||||
|
GL.o1.setModelViewIdentity();
|
||||||
|
|
||||||
|
camera.updateOpenGL();
|
||||||
|
|
||||||
|
GL.o1.light(Light.LIGHT0, Light.POSITION, lightFloatBuffer);
|
||||||
|
|
||||||
|
// Render directly
|
||||||
|
for (AbstractGameObjectShape gameObjectShape : gameObjectShapes) {
|
||||||
|
gameObjectShape.updateTransform();
|
||||||
|
Fw.graphics.render(gameObjectShape);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render contact points
|
||||||
|
GL.o1.disableDepthTest();
|
||||||
|
for (GameObject visualContactPoint : visualContactPoints) {
|
||||||
|
Fw.graphics.render(visualContactPoint);
|
||||||
|
}
|
||||||
|
GL.o1.enableDepthTest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resize(int width, int height) {
|
||||||
|
GL.o1.setViewport(0, 0, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resume() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisiontest;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import net.frameworkgl.Fw;
|
||||||
|
import net.frameworkgl.math.Transform4f;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import net.frameworkgl.opengl.GL;
|
||||||
|
import net.frameworkgl.opengl.mesh.Mesh;
|
||||||
|
import net.frameworkgl.opengl.renderable.AbstractRenderable;
|
||||||
|
import org.atriasoft.ephysics.collision.shapes.ConeShape;
|
||||||
|
import org.atriasoft.ephysics.engine.DynamicsWorld;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class Cone extends AbstractGameObjectShape {
|
||||||
|
|
||||||
|
public Cone(Vector3f position, float height, float radius, float mass, DynamicsWorld dynamicsWorld) {
|
||||||
|
|
||||||
|
// Scaling
|
||||||
|
Vector3f size = new Vector3f(radius, height, radius);
|
||||||
|
Transform4f scaling = new Transform4f();
|
||||||
|
scaling.getRotation().setDiagonal(size);
|
||||||
|
setScalingTransform(scaling); // Attach to game object
|
||||||
|
|
||||||
|
ConeShape collisionShape = new ConeShape(radius, height, 0.02f);
|
||||||
|
createRigidBody(collisionShape, position, mass, dynamicsWorld);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Mesh
|
||||||
|
Mesh mesh = GL.meshFactory.createMesh();
|
||||||
|
setMesh(mesh); // Attach mesh to game object
|
||||||
|
Fw.graphics.loadMesh("primitives/cone.obj", mesh);
|
||||||
|
mesh.setAllColors(0.8f, 0.8f, 0.8f, 1.0f);
|
||||||
|
mesh.updateHasBooleansFromSegment();
|
||||||
|
|
||||||
|
// Renderable
|
||||||
|
AbstractRenderable renderable = Fw.graphics.createInterleavedRenderable();
|
||||||
|
renderable.create(mesh);
|
||||||
|
setRenderable(renderable); // Attach to game object
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisiontest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class Configuration extends net.frameworkgl.Configuration {
|
||||||
|
|
||||||
|
public Configuration(String[] args) {
|
||||||
|
super(args);
|
||||||
|
withOpenGL33ProfileCompatibility();
|
||||||
|
setWindowTitle("Collision Test");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisiontest;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import net.frameworkgl.Fw;
|
||||||
|
import net.frameworkgl.math.Transform4f;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import net.frameworkgl.opengl.GL;
|
||||||
|
import net.frameworkgl.opengl.mesh.Mesh;
|
||||||
|
import net.frameworkgl.opengl.renderable.AbstractRenderable;
|
||||||
|
import org.atriasoft.ephysics.collision.shapes.CylinderShape;
|
||||||
|
import org.atriasoft.ephysics.engine.DynamicsWorld;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class Cylinder extends AbstractGameObjectShape {
|
||||||
|
|
||||||
|
public Cylinder(Vector3f position, float height, float radius, float mass, DynamicsWorld dynamicsWorld) {
|
||||||
|
|
||||||
|
// Scaling
|
||||||
|
Vector3f size = new Vector3f(radius, height, radius);
|
||||||
|
Transform4f scaling = new Transform4f();
|
||||||
|
scaling.getRotation().setDiagonal(size);
|
||||||
|
setScalingTransform(scaling); // Attach to game object
|
||||||
|
|
||||||
|
CylinderShape collisionShape = new CylinderShape(radius, height, 0.02f);
|
||||||
|
createRigidBody(collisionShape, position, mass, dynamicsWorld);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Mesh
|
||||||
|
Mesh mesh = GL.meshFactory.createMesh();
|
||||||
|
setMesh(mesh); // Attach mesh to game object
|
||||||
|
Fw.graphics.loadMesh("primitives/cylinder.obj", mesh);
|
||||||
|
mesh.setAllColors(0.8f, 0.8f, 0.8f, 1.0f);
|
||||||
|
mesh.updateHasBooleansFromSegment();
|
||||||
|
|
||||||
|
// Renderable
|
||||||
|
AbstractRenderable renderable = Fw.graphics.createInterleavedRenderable();
|
||||||
|
renderable.create(mesh);
|
||||||
|
setRenderable(renderable); // Attach to game object
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisiontest;
|
||||||
|
|
||||||
|
import net.frameworkgl.Bootstrap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class Demo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param args the command line arguments
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Bootstrap boot = new Bootstrap();
|
||||||
|
boot.start(Configuration.class, CollisionTest.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisiontest;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import net.frameworkgl.Fw;
|
||||||
|
import net.frameworkgl.math.Transform4f;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import net.frameworkgl.opengl.GL;
|
||||||
|
import net.frameworkgl.opengl.mesh.Mesh;
|
||||||
|
import net.frameworkgl.opengl.renderable.AbstractRenderable;
|
||||||
|
import org.atriasoft.ephysics.collision.shapes.SphereShape;
|
||||||
|
import org.atriasoft.ephysics.engine.DynamicsWorld;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class Sphere extends AbstractGameObjectShape {
|
||||||
|
|
||||||
|
public Sphere(Vector3f position, float radius, float mass, DynamicsWorld dynamicsWorld) {
|
||||||
|
|
||||||
|
// Scaling
|
||||||
|
Vector3f size = new Vector3f(radius, radius, radius);
|
||||||
|
Transform4f scaling = new Transform4f();
|
||||||
|
scaling.getRotation().setDiagonal(size);
|
||||||
|
setScalingTransform(scaling); // Attach to game object
|
||||||
|
|
||||||
|
SphereShape collisionShape = new SphereShape(radius, 0.02f);
|
||||||
|
createRigidBody(collisionShape, position, mass, dynamicsWorld);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Mesh
|
||||||
|
Mesh mesh = GL.meshFactory.createMesh();
|
||||||
|
setMesh(mesh); // Attach mesh to game object
|
||||||
|
Fw.graphics.loadMesh("primitives/uvsphere.obj", mesh);
|
||||||
|
mesh.setAllColors(0.8f, 0.8f, 0.8f, 1.0f);
|
||||||
|
mesh.updateHasBooleansFromSegment();
|
||||||
|
|
||||||
|
// Renderable
|
||||||
|
AbstractRenderable renderable = Fw.graphics.createInterleavedRenderable();
|
||||||
|
renderable.create(mesh);
|
||||||
|
setRenderable(renderable); // Attach to game object
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/
|
||||||
|
* Copyright (c) 2010-2013 Daniel Chappuis
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
* In no event will the authors be held liable for any damages arising from the
|
||||||
|
* use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a
|
||||||
|
* product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
* This file has been modified during the port to Java and differ from the source versions.
|
||||||
|
*/
|
||||||
|
package org.atriasoft.ephysics.examples.collisiontest;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import net.frameworkgl.Fw;
|
||||||
|
import net.frameworkgl.gameobjects.GameObject;
|
||||||
|
import net.frameworkgl.math.Transform4f;
|
||||||
|
import net.frameworkgl.math.Vector3f;
|
||||||
|
import net.frameworkgl.opengl.GL;
|
||||||
|
import net.frameworkgl.opengl.mesh.Mesh;
|
||||||
|
import net.frameworkgl.opengl.renderable.AbstractRenderable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason Sorensen <sorensenj@smert.net>
|
||||||
|
*/
|
||||||
|
public class VisualContactPoint extends GameObject {
|
||||||
|
|
||||||
|
private static final float VISUAL_CONTACT_POINT_RADIUS = 0.1f;
|
||||||
|
|
||||||
|
private static boolean initialized;
|
||||||
|
private static Mesh staticMesh;
|
||||||
|
private static AbstractRenderable staticRenderable;
|
||||||
|
|
||||||
|
public VisualContactPoint(Vector3f position) {
|
||||||
|
|
||||||
|
// Scaling
|
||||||
|
Vector3f size = new Vector3f(VISUAL_CONTACT_POINT_RADIUS, VISUAL_CONTACT_POINT_RADIUS, VISUAL_CONTACT_POINT_RADIUS);
|
||||||
|
Transform4f scaling = new Transform4f();
|
||||||
|
scaling.getRotation().setDiagonal(size);
|
||||||
|
setScalingTransform(scaling); // Attach to game object
|
||||||
|
|
||||||
|
getWorldTransform().getPosition().set(position);
|
||||||
|
getWorldTransform().multiply(getScalingTransform());
|
||||||
|
|
||||||
|
CreateStaticData();
|
||||||
|
setMesh(staticMesh); // Attach mesh to game object
|
||||||
|
setRenderable(staticRenderable); // Attach to game object
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CreateStaticData() {
|
||||||
|
if (initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Mesh
|
||||||
|
staticMesh = GL.meshFactory.createMesh();
|
||||||
|
Fw.graphics.loadMesh("primitives/cone.obj", staticMesh);
|
||||||
|
staticMesh.setAllColors(1.0f, 1.0f, 0.0f, 1.0f);
|
||||||
|
staticMesh.updateHasBooleansFromSegment();
|
||||||
|
|
||||||
|
// Renderable
|
||||||
|
staticRenderable = Fw.graphics.createInterleavedRenderable();
|
||||||
|
staticRenderable.create(staticMesh);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only do this once
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Destroy() {
|
||||||
|
if (!initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
staticRenderable.destroy();
|
||||||
|
staticRenderable = null;
|
||||||
|
initialized = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -5,8 +5,20 @@ import org.atriasoft.etk.math.Vector3f;
|
|||||||
public class Triangle {
|
public class Triangle {
|
||||||
public final Vector3f[] value = new Vector3f[3];
|
public final Vector3f[] value = new Vector3f[3];
|
||||||
|
|
||||||
|
public Triangle() {}
|
||||||
|
|
||||||
|
public Triangle(Vector3f data1, Vector3f data2, Vector3f data3) {
|
||||||
|
this.value[0] = data1;
|
||||||
|
this.value[1] = data2;
|
||||||
|
this.value[2] = data3;
|
||||||
|
}
|
||||||
|
|
||||||
public Vector3f get(final int id) {
|
public Vector3f get(final int id) {
|
||||||
return this.value[id];
|
return this.value[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void set(final int id, Vector3f data) {
|
||||||
|
this.value[id] = data;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package org.atriasoft.ephysics.collision.broadphase;
|
|||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@SuppressWarnings("preview")
|
|
||||||
public record PairDTree(
|
public record PairDTree(
|
||||||
DTree first,
|
DTree first,
|
||||||
DTree second) {
|
DTree second) {
|
||||||
|
@ -85,7 +85,7 @@ public class BoxShape extends ConvexShape {
|
|||||||
@Override
|
@Override
|
||||||
public boolean raycast(final Ray ray, final RaycastInfo raycastInfo, final ProxyShape proxyShape) {
|
public boolean raycast(final Ray ray, final RaycastInfo raycastInfo, final ProxyShape proxyShape) {
|
||||||
final Vector3f rayDirection = ray.point2.less(ray.point1);
|
final Vector3f rayDirection = ray.point2.less(ray.point1);
|
||||||
float tMin = Float.MIN_VALUE;
|
float tMin = -Float.MAX_VALUE;
|
||||||
float tMax = Float.MAX_VALUE;
|
float tMax = Float.MAX_VALUE;
|
||||||
Vector3f normalDirection = Vector3f.ZERO;
|
Vector3f normalDirection = Vector3f.ZERO;
|
||||||
Vector3f currentNormal = Vector3f.ZERO;
|
Vector3f currentNormal = Vector3f.ZERO;
|
||||||
|
@ -210,7 +210,7 @@ public class ConvexMeshShape extends ConvexShape {
|
|||||||
// If the edges information is used to speed up the collision detection
|
// If the edges information is used to speed up the collision detection
|
||||||
if (!this.isEdgesInformationUsed) {
|
if (!this.isEdgesInformationUsed) {
|
||||||
// If the edges information is not used
|
// If the edges information is not used
|
||||||
double maxDotProduct = Float.MIN_VALUE;
|
double maxDotProduct = -Float.MAX_VALUE;
|
||||||
int indexMaxDotProduct = 0;
|
int indexMaxDotProduct = 0;
|
||||||
// For each vertex of the mesh
|
// For each vertex of the mesh
|
||||||
for (int i = 0; i < this.numberVertices; i++) {
|
for (int i = 0; i < this.numberVertices; i++) {
|
||||||
|
@ -30,7 +30,7 @@ public class Defaults {
|
|||||||
// Maximum decimal value
|
// Maximum decimal value
|
||||||
public static final float DECIMAL_LARGEST = Float.MAX_VALUE;
|
public static final float DECIMAL_LARGEST = Float.MAX_VALUE;
|
||||||
// Smallest decimal value (negative)
|
// Smallest decimal value (negative)
|
||||||
public static final float DECIMAL_SMALLEST = Float.MIN_VALUE;
|
public static final float DECIMAL_SMALLEST = -Float.MAX_VALUE;
|
||||||
|
|
||||||
// Default bounciness factor for a rigid body
|
// Default bounciness factor for a rigid body
|
||||||
public static final float DEFAULT_BOUNCINESS = 0.5f;
|
public static final float DEFAULT_BOUNCINESS = 0.5f;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user