use of com.jme3.bullet.collision.shapes.SphereCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class RollingTheMonkey method simpleInitApp.
@Override
public void simpleInitApp() {
flyCam.setEnabled(false);
cam.setLocation(new Vector3f(0.0f, 12.0f, 21.0f));
viewPort.setBackgroundColor(new ColorRGBA(0.2118f, 0.0824f, 0.6549f, 1.0f));
// init physics
BulletAppState bulletState = new BulletAppState();
stateManager.attach(bulletState);
space = bulletState.getPhysicsSpace();
space.addCollisionListener(this);
// create light
DirectionalLight sun = new DirectionalLight();
sun.setDirection((new Vector3f(-0.7f, -0.3f, -0.5f)).normalizeLocal());
System.out.println("Here We Go: " + sun.getDirection());
sun.setColor(ColorRGBA.White);
rootNode.addLight(sun);
// create materials
Material materialRed = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
materialRed.setBoolean("UseMaterialColors", true);
materialRed.setBoolean("HardwareShadows", true);
materialRed.setColor("Diffuse", new ColorRGBA(0.9451f, 0.0078f, 0.0314f, 1.0f));
materialRed.setColor("Specular", ColorRGBA.White);
materialRed.setFloat("Shininess", 64.0f);
Material materialGreen = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
materialGreen.setBoolean("UseMaterialColors", true);
materialGreen.setBoolean("HardwareShadows", true);
materialGreen.setColor("Diffuse", new ColorRGBA(0.0431f, 0.7725f, 0.0078f, 1.0f));
materialGreen.setColor("Specular", ColorRGBA.White);
materialGreen.setFloat("Shininess", 64.0f);
Material logoMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
logoMaterial.setBoolean("UseMaterialColors", true);
logoMaterial.setBoolean("HardwareShadows", true);
logoMaterial.setTexture("DiffuseMap", assetManager.loadTexture("com/jme3/app/Monkey.png"));
logoMaterial.setColor("Diffuse", ColorRGBA.White);
logoMaterial.setColor("Specular", ColorRGBA.White);
logoMaterial.setFloat("Shininess", 32.0f);
Material materialYellow = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
materialYellow.setBoolean("UseMaterialColors", true);
materialYellow.setBoolean("HardwareShadows", true);
materialYellow.setColor("Diffuse", new ColorRGBA(0.9529f, 0.7843f, 0.0078f, 1.0f));
materialYellow.setColor("Specular", ColorRGBA.White);
materialYellow.setFloat("Shininess", 64.0f);
// create level spatial
// TODO: create your own level mesh
Node level = new Node("level");
level.setShadowMode(ShadowMode.CastAndReceive);
Geometry floor = new Geometry("floor", new Box(22.0f, 0.5f, 22.0f));
floor.setShadowMode(ShadowMode.Receive);
floor.setLocalTranslation(0.0f, -0.5f, 0.0f);
floor.setMaterial(materialGreen);
Geometry wallNorth = new Geometry("wallNorth", new Box(22.0f, 2.0f, 0.5f));
wallNorth.setLocalTranslation(0.0f, 2.0f, 21.5f);
wallNorth.setMaterial(materialRed);
Geometry wallSouth = new Geometry("wallSouth", new Box(22.0f, 2.0f, 0.5f));
wallSouth.setLocalTranslation(0.0f, 2.0f, -21.5f);
wallSouth.setMaterial(materialRed);
Geometry wallEast = new Geometry("wallEast", new Box(0.5f, 2.0f, 21.0f));
wallEast.setLocalTranslation(-21.5f, 2.0f, 0.0f);
wallEast.setMaterial(materialRed);
Geometry wallWest = new Geometry("wallWest", new Box(0.5f, 2.0f, 21.0f));
wallWest.setLocalTranslation(21.5f, 2.0f, 0.0f);
wallWest.setMaterial(materialRed);
level.attachChild(floor);
level.attachChild(wallNorth);
level.attachChild(wallSouth);
level.attachChild(wallEast);
level.attachChild(wallWest);
// The easy way: level.addControl(new RigidBodyControl(0));
// create level Shape
CompoundCollisionShape levelShape = new CompoundCollisionShape();
BoxCollisionShape floorShape = new BoxCollisionShape(new Vector3f(22.0f, 0.5f, 22.0f));
BoxCollisionShape wallNorthShape = new BoxCollisionShape(new Vector3f(22.0f, 2.0f, 0.5f));
BoxCollisionShape wallSouthShape = new BoxCollisionShape(new Vector3f(22.0f, 2.0f, 0.5f));
BoxCollisionShape wallEastShape = new BoxCollisionShape(new Vector3f(0.5f, 2.0f, 21.0f));
BoxCollisionShape wallWestShape = new BoxCollisionShape(new Vector3f(0.5f, 2.0f, 21.0f));
levelShape.addChildShape(floorShape, new Vector3f(0.0f, -0.5f, 0.0f));
levelShape.addChildShape(wallNorthShape, new Vector3f(0.0f, 2.0f, -21.5f));
levelShape.addChildShape(wallSouthShape, new Vector3f(0.0f, 2.0f, 21.5f));
levelShape.addChildShape(wallEastShape, new Vector3f(-21.5f, 2.0f, 0.0f));
levelShape.addChildShape(wallEastShape, new Vector3f(21.5f, 2.0f, 0.0f));
level.addControl(new RigidBodyControl(levelShape, 0));
rootNode.attachChild(level);
space.addAll(level);
// create Pickups
// TODO: create your own pickUp mesh
// create single mesh for all pickups
// HINT: think particles.
pickUps = new Node("pickups");
Quaternion rotation = new Quaternion();
Vector3f translation = new Vector3f(0.0f, PICKUP_SIZE * 1.5f, -PICKUP_RADIUS);
int index = 0;
float ammount = FastMath.TWO_PI / PICKUP_COUNT;
for (float angle = 0; angle < FastMath.TWO_PI; angle += ammount) {
Geometry pickUp = new Geometry("pickUp" + (index++), new Box(PICKUP_SIZE, PICKUP_SIZE, PICKUP_SIZE));
pickUp.setShadowMode(ShadowMode.CastAndReceive);
pickUp.setMaterial(materialYellow);
pickUp.setLocalRotation(rotation.fromAngles(FastMath.rand.nextFloat() * FastMath.TWO_PI, FastMath.rand.nextFloat() * FastMath.TWO_PI, FastMath.rand.nextFloat() * FastMath.TWO_PI));
rotation.fromAngles(0.0f, angle, 0.0f);
rotation.mult(translation, pickUp.getLocalTranslation());
pickUps.attachChild(pickUp);
pickUp.addControl(new GhostControl(new SphereCollisionShape(PICKUP_SIZE)));
space.addAll(pickUp);
//space.addCollisionListener(pickUpControl);
}
rootNode.attachChild(pickUps);
// Create player
// TODO: create your own player mesh
Geometry playerGeometry = new Geometry("player", new Sphere(16, 32, PLAYER_RADIUS));
playerGeometry.setShadowMode(ShadowMode.CastAndReceive);
playerGeometry.setLocalTranslation(PLAYER_START.clone());
playerGeometry.setMaterial(logoMaterial);
// Store control for applying forces
// TODO: create your own player control
player = new RigidBodyControl(new SphereCollisionShape(PLAYER_RADIUS), PLAYER_MASS);
player.setRestitution(PLAYER_REST);
playerGeometry.addControl(player);
rootNode.attachChild(playerGeometry);
space.addAll(playerGeometry);
inputManager.addMapping(INPUT_MAPPING_FORWARD, new KeyTrigger(KeyInput.KEY_UP), new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping(INPUT_MAPPING_BACKWARD, new KeyTrigger(KeyInput.KEY_DOWN), new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping(INPUT_MAPPING_LEFT, new KeyTrigger(KeyInput.KEY_LEFT), new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping(INPUT_MAPPING_RIGHT, new KeyTrigger(KeyInput.KEY_RIGHT), new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping(INPUT_MAPPING_RESET, new KeyTrigger(KeyInput.KEY_R));
inputManager.addListener(this, INPUT_MAPPING_FORWARD, INPUT_MAPPING_BACKWARD, INPUT_MAPPING_LEFT, INPUT_MAPPING_RIGHT, INPUT_MAPPING_RESET);
// init UI
infoText = new BitmapText(guiFont, false);
infoText.setText(INFO_MESSAGE);
guiNode.attachChild(infoText);
scoreText = new BitmapText(guiFont, false);
scoreText.setText("Score: 0");
guiNode.attachChild(scoreText);
messageText = new BitmapText(guiFont, false);
messageText.setText(MESSAGE);
messageText.setLocalScale(0.0f);
guiNode.attachChild(messageText);
infoText.setLocalTranslation(0.0f, cam.getHeight(), 0.0f);
scoreText.setLocalTranslation((cam.getWidth() - scoreText.getLineWidth()) / 2.0f, scoreText.getLineHeight(), 0.0f);
messageText.setLocalTranslation((cam.getWidth() - messageText.getLineWidth()) / 2.0f, (cam.getHeight() - messageText.getLineHeight()) / 2, 0.0f);
// init shadows
FilterPostProcessor processor = new FilterPostProcessor(assetManager);
DirectionalLightShadowFilter filter = new DirectionalLightShadowFilter(assetManager, 2048, 1);
filter.setLight(sun);
processor.addFilter(filter);
viewPort.addProcessor(processor);
}
use of com.jme3.bullet.collision.shapes.SphereCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class TestQ3 method simpleInitApp.
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
flyCam.setMoveSpeed(100);
setupKeys();
this.cam.setFrustumFar(2000);
DirectionalLight dl = new DirectionalLight();
dl.setColor(ColorRGBA.White.clone().multLocal(2));
dl.setDirection(new Vector3f(-1, -1, -1).normalize());
rootNode.addLight(dl);
AmbientLight am = new AmbientLight();
am.setColor(ColorRGBA.White.mult(2));
rootNode.addLight(am);
// load the level from zip or http zip
if (useHttp) {
assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/quake3level.zip", HttpZipLocator.class);
} else {
assetManager.registerLocator("quake3level.zip", ZipLocator.class);
}
// create the geometry and attach it
MaterialList matList = (MaterialList) assetManager.loadAsset("Scene.material");
OgreMeshKey key = new OgreMeshKey("main.meshxml", matList);
gameLevel = (Node) assetManager.loadAsset(key);
gameLevel.setLocalScale(0.1f);
// add a physics control, it will generate a MeshCollisionShape based on the gameLevel
gameLevel.addControl(new RigidBodyControl(0));
player = new PhysicsCharacter(new SphereCollisionShape(5), .01f);
player.setJumpSpeed(20);
player.setFallSpeed(30);
player.setGravity(30);
player.setPhysicsLocation(new Vector3f(60, 10, -60));
rootNode.attachChild(gameLevel);
getPhysicsSpace().addAll(gameLevel);
getPhysicsSpace().add(player);
}
use of com.jme3.bullet.collision.shapes.SphereCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class TestBoneRagdoll method simpleInitApp.
public void simpleInitApp() {
initCrossHairs();
initMaterial();
cam.setLocation(new Vector3f(0.26924422f, 6.646658f, 22.265987f));
cam.setRotation(new Quaternion(-2.302544E-4f, 0.99302495f, -0.117888905f, -0.0019395084f));
bulletAppState = new BulletAppState();
bulletAppState.setEnabled(true);
stateManager.attach(bulletAppState);
bullet = new Sphere(32, 32, 1.0f, true, false);
bullet.setTextureMode(TextureMode.Projected);
bulletCollisionShape = new SphereCollisionShape(1.0f);
// bulletAppState.getPhysicsSpace().enableDebug(assetManager);
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
setupLight();
model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
// model.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_X));
//debug view
AnimControl control = model.getControl(AnimControl.class);
SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton", control.getSkeleton());
Material mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
mat2.getAdditionalRenderState().setWireframe(true);
mat2.setColor("Color", ColorRGBA.Green);
mat2.getAdditionalRenderState().setDepthTest(false);
skeletonDebug.setMaterial(mat2);
skeletonDebug.setLocalTranslation(model.getLocalTranslation());
//Note: PhysicsRagdollControl is still TODO, constructor will change
ragdoll = new KinematicRagdollControl(0.5f);
setupSinbad(ragdoll);
ragdoll.addCollisionListener(this);
model.addControl(ragdoll);
float eighth_pi = FastMath.PI * 0.125f;
ragdoll.setJointLimit("Waist", eighth_pi, eighth_pi, eighth_pi, eighth_pi, eighth_pi, eighth_pi);
ragdoll.setJointLimit("Chest", eighth_pi, eighth_pi, 0, 0, eighth_pi, eighth_pi);
//Oto's head is almost rigid
// ragdoll.setJointLimit("head", 0, 0, eighth_pi, -eighth_pi, 0, 0);
getPhysicsSpace().add(ragdoll);
speed = 1.3f;
rootNode.attachChild(model);
// rootNode.attachChild(skeletonDebug);
flyCam.setMoveSpeed(50);
animChannel = control.createChannel();
animChannel.setAnim("Dance");
control.addListener(this);
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("toggle") && isPressed) {
Vector3f v = new Vector3f();
v.set(model.getLocalTranslation());
v.y = 0;
model.setLocalTranslation(v);
Quaternion q = new Quaternion();
float[] angles = new float[3];
model.getLocalRotation().toAngles(angles);
q.fromAngleAxis(angles[1], Vector3f.UNIT_Y);
model.setLocalRotation(q);
if (angles[0] < 0) {
animChannel.setAnim("StandUpBack");
ragdoll.blendToKinematicMode(0.5f);
} else {
animChannel.setAnim("StandUpFront");
ragdoll.blendToKinematicMode(0.5f);
}
}
if (name.equals("bullet+") && isPressed) {
bulletSize += 0.1f;
}
if (name.equals("bullet-") && isPressed) {
bulletSize -= 0.1f;
}
if (name.equals("stop") && isPressed) {
ragdoll.setEnabled(!ragdoll.isEnabled());
ragdoll.setRagdollMode();
}
if (name.equals("shoot") && !isPressed) {
Geometry bulletg = new Geometry("bullet", bullet);
bulletg.setMaterial(matBullet);
bulletg.setLocalTranslation(cam.getLocation());
bulletg.setLocalScale(bulletSize);
bulletCollisionShape = new SphereCollisionShape(bulletSize);
RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, bulletSize * 10);
bulletNode.setCcdMotionThreshold(0.001f);
bulletNode.setLinearVelocity(cam.getDirection().mult(80));
bulletg.addControl(bulletNode);
rootNode.attachChild(bulletg);
getPhysicsSpace().add(bulletNode);
}
if (name.equals("boom") && !isPressed) {
Geometry bulletg = new Geometry("bullet", bullet);
bulletg.setMaterial(matBullet);
bulletg.setLocalTranslation(cam.getLocation());
bulletg.setLocalScale(bulletSize);
bulletCollisionShape = new SphereCollisionShape(bulletSize);
BombControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1);
bulletNode.setForceFactor(8);
bulletNode.setExplosionRadius(20);
bulletNode.setCcdMotionThreshold(0.001f);
bulletNode.setLinearVelocity(cam.getDirection().mult(180));
bulletg.addControl(bulletNode);
rootNode.attachChild(bulletg);
getPhysicsSpace().add(bulletNode);
}
}
}, "toggle", "shoot", "stop", "bullet+", "bullet-", "boom");
inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addMapping("boom", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_H));
inputManager.addMapping("bullet-", new KeyTrigger(KeyInput.KEY_COMMA));
inputManager.addMapping("bullet+", new KeyTrigger(KeyInput.KEY_PERIOD));
}
use of com.jme3.bullet.collision.shapes.SphereCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class TestBrickTower method simpleInitApp.
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
// bulletAppState.setEnabled(false);
stateManager.attach(bulletAppState);
bullet = new Sphere(32, 32, 0.4f, true, false);
bullet.setTextureMode(TextureMode.Projected);
bulletCollisionShape = new SphereCollisionShape(0.4f);
brick = new Box(brickWidth, brickHeight, brickDepth);
brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
//bulletAppState.getPhysicsSpace().enableDebug(assetManager);
initMaterial();
initTower();
initFloor();
initCrossHairs();
this.cam.setLocation(new Vector3f(0, 25f, 8f));
cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
cam.setFrustumFar(80);
inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(actionListener, "shoot");
rootNode.setShadowMode(ShadowMode.Off);
bsr = new PssmShadowRenderer(assetManager, 1024, 2);
bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
bsr.setLambda(0.55f);
bsr.setShadowIntensity(0.6f);
bsr.setCompareMode(CompareMode.Hardware);
bsr.setFilterMode(FilterMode.PCF4);
viewPort.addProcessor(bsr);
}
use of com.jme3.bullet.collision.shapes.SphereCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class TestBrickWall method simpleInitApp.
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
stateManager.attach(bulletAppState);
bullet = new Sphere(32, 32, 0.4f, true, false);
bullet.setTextureMode(TextureMode.Projected);
bulletCollisionShape = new SphereCollisionShape(0.4f);
brick = new Box(bLength, bHeight, bWidth);
brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
initMaterial();
initWall();
initFloor();
initCrossHairs();
this.cam.setLocation(new Vector3f(0, 6f, 6f));
cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
cam.setFrustumFar(15);
inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(actionListener, "shoot");
inputManager.addMapping("gc", new KeyTrigger(KeyInput.KEY_X));
inputManager.addListener(actionListener, "gc");
rootNode.setShadowMode(ShadowMode.Off);
bsr = new BasicShadowRenderer(assetManager, 256);
bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
viewPort.addProcessor(bsr);
}
Aggregations