com.jme3.math.Plane Java Examples
The following examples show how to use
com.jme3.math.Plane.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimplePlayerAttackBehavior.java From MonkeyBrains with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void onAction(String name, boolean isPressed, float tpf) { operation = name; if (isPressed) { supportedOperations.get(operation).setEnabled(true); Vector2f click2d = MonkeyBrainsAppState.getInstance().getApp().getInputManager().getCursorPosition(); Vector3f click3d = agent.getCamera().getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0f).clone(); Vector3f dir = agent.getCamera().getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 1f).subtractLocal(click3d).normalizeLocal(); Ray ray = new Ray(click3d, dir); Plane ground = new Plane(Vector3f.UNIT_Y, 0); Vector3f groundpoint = new Vector3f(); ray.intersectsWherePlane(ground, groundpoint); ((SimpleAttackBehavior) supportedOperations.get(operation)).setTarget(groundpoint); } else { operation = null; } }
Example #2
Source File: ReflectionProcessor.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void postQueue(RenderQueue rq) { //we need special treatement for the sky because it must not be clipped rm.getRenderer().setFrameBuffer(reflectionBuffer); reflectionCam.setProjectionMatrix(null); rm.setCamera(reflectionCam, false); rm.getRenderer().clearBuffers(true, true, true); //Rendering the sky whithout clipping rm.getRenderer().setDepthRange(1, 1); vp.getQueue().renderQueue(RenderQueue.Bucket.Sky, rm, reflectionCam, true); rm.getRenderer().setDepthRange(0, 1); //setting the clip plane to the cam reflectionCam.setClipPlane(reflectionClipPlane, Plane.Side.Positive);//,1 rm.setCamera(reflectionCam, false); }
Example #3
Source File: PlaneCollisionShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * De-serialize this shape, for example when loading from a J3O file. * * @param im importer (not null) * @throws IOException from importer */ @Override public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule capsule = im.getCapsule(this); plane = (Plane) capsule.readSavable("collisionPlane", new Plane()); createShape(); }
Example #4
Source File: SpotLight.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean intersectsFrustum(Camera cam, TempVars vars) { if (spotRange == 0) { // The algorithm below does not support infinite spot range. return true; } Vector3f farPoint = vars.vect1.set(position).addLocal(vars.vect2.set(direction).multLocal(spotRange)); for (int i = 5; i >= 0; i--) { //check origin against the plane Plane plane = cam.getWorldPlane(i); float dot = plane.pseudoDistance(position); if(dot < 0){ // outside, check the far point against the plane dot = plane.pseudoDistance(farPoint); if(dot < 0){ // outside, check the projection of the far point along the normal of the plane to the base disc perimeter of the cone //computing the radius of the base disc float farRadius = (spotRange / outerAngleCos) * outerAngleSin; //computing the projection direction : perpendicular to the light direction and coplanar with the direction vector and the normal vector Vector3f perpDirection = vars.vect2.set(direction).crossLocal(plane.getNormal()).normalizeLocal().crossLocal(direction); //projecting the far point on the base disc perimeter Vector3f projectedPoint = vars.vect3.set(farPoint).addLocal(perpDirection.multLocal(farRadius)); //checking against the plane dot = plane.pseudoDistance(projectedPoint); if(dot < 0){ // Outside, the light can be culled return false; } } } } return true; }
Example #5
Source File: PlaneCollisionShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule capsule = im.getCapsule(this); plane = (Plane) capsule.readSavable("collisionPlane", new Plane()); createShape(); }
Example #6
Source File: WaterUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void updateReflectionCam(Camera reflectionCam, Plane plane, Camera sceneCam){ TempVars vars = TempVars.get(); //Temp vects for reflection cam orientation calculation Vector3f sceneTarget = vars.vect1; Vector3f reflectDirection = vars.vect2; Vector3f reflectUp = vars.vect3; Vector3f reflectLeft = vars.vect4; Vector3f camLoc = vars.vect5; camLoc = plane.reflect(sceneCam.getLocation(), camLoc); reflectionCam.setLocation(camLoc); reflectionCam.setFrustum(sceneCam.getFrustumNear(), sceneCam.getFrustumFar(), sceneCam.getFrustumLeft(), sceneCam.getFrustumRight(), sceneCam.getFrustumTop(), sceneCam.getFrustumBottom()); reflectionCam.setParallelProjection(sceneCam.isParallelProjection()); sceneTarget.set(sceneCam.getLocation()).addLocal(sceneCam.getDirection(vars.vect6)); reflectDirection = plane.reflect(sceneTarget, reflectDirection); reflectDirection.subtractLocal(camLoc); sceneTarget.set(sceneCam.getLocation()).subtractLocal(sceneCam.getUp(vars.vect6)); reflectUp = plane.reflect(sceneTarget, reflectUp); reflectUp.subtractLocal(camLoc); sceneTarget.set(sceneCam.getLocation()).addLocal(sceneCam.getLeft(vars.vect6)); reflectLeft = plane.reflect(sceneTarget, reflectLeft); reflectLeft.subtractLocal(camLoc); reflectionCam.setAxes(reflectLeft, reflectUp, reflectDirection); vars.release(); }
Example #7
Source File: PlaneCollisionShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Serialize this shape, for example when saving to a J3O file. * * @param ex exporter (not null) * @throws IOException from exporter */ @Override public void write(JmeExporter ex) throws IOException { super.write(ex); OutputCapsule capsule = ex.getCapsule(this); capsule.write(plane, "collisionPlane", new Plane()); }
Example #8
Source File: ReflectionProcessor.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void postQueue(RenderQueue rq) { //we need special treatement for the sky because it must not be clipped rm.getRenderer().setFrameBuffer(reflectionBuffer); reflectionCam.setProjectionMatrix(null); rm.setCamera(reflectionCam, false); rm.getRenderer().clearBuffers(true, true, true); //Rendering the sky whithout clipping rm.getRenderer().setDepthRange(1, 1); vp.getQueue().renderQueue(RenderQueue.Bucket.Sky, rm, reflectionCam, true); rm.getRenderer().setDepthRange(0, 1); //setting the clip plane to the cam reflectionCam.setClipPlane(reflectionClipPlane, Plane.Side.Positive);//,1 rm.setCamera(reflectionCam, false); }
Example #9
Source File: AbstractStrengthSteeringBehavior.java From MonkeyBrains with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @see AbstractStrengthSteeringBehavior#setupStrengthControl(float) * @see * AbstractStrengthSteeringBehavior#setupStrengthControl(com.jme3.math.Plane) */ public void setupStrengthControl(Plane plane, float scalar) { this.validateScalar(scalar); this.scalar = scalar; this.plane = plane; this.type = SteerStrengthType.PLANE; }
Example #10
Source File: TestPhysicsReadWrite.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); bulletAppState.getPhysicsSpace().enableDebug(assetManager); physicsRootNode=new Node("PhysicsRootNode"); rootNode.attachChild(physicsRootNode); // Add a physics sphere to the world Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1); physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0)); rootNode.attachChild(physicsSphere); getPhysicsSpace().add(physicsSphere); // Add a physics sphere to the world using the collision shape from sphere one Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, physicsSphere.getControl(RigidBodyControl.class).getCollisionShape(), 1); physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0)); rootNode.attachChild(physicsSphere2); getPhysicsSpace().add(physicsSphere2); // Add a physics box to the world Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1); physicsBox.getControl(RigidBodyControl.class).setFriction(0.1f); physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f)); rootNode.attachChild(physicsBox); getPhysicsSpace().add(physicsBox); // Add a physics cylinder to the world Node physicsCylinder = PhysicsTestHelper.createPhysicsTestNode(assetManager, new CylinderCollisionShape(new Vector3f(1f, 1f, 1.5f)), 1); physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0)); rootNode.attachChild(physicsCylinder); getPhysicsSpace().add(physicsCylinder); // an obstacle mesh, does not move (mass=0) Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0); node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f)); rootNode.attachChild(node2); getPhysicsSpace().add(node2); // the floor mesh, does not move (mass=0) Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0); node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f)); rootNode.attachChild(node3); getPhysicsSpace().add(node3); // Join the physics objects with a Point2Point joint HingeJoint joint=new HingeJoint(physicsSphere.getControl(RigidBodyControl.class), physicsBox.getControl(RigidBodyControl.class), new Vector3f(-2,0,0), new Vector3f(2,0,0), Vector3f.UNIT_Z,Vector3f.UNIT_Z); getPhysicsSpace().add(joint); //save and load the physicsRootNode try { //remove all physics objects from physics space getPhysicsSpace().removeAll(physicsRootNode); physicsRootNode.removeFromParent(); //export to byte array ByteArrayOutputStream bout=new ByteArrayOutputStream(); BinaryExporter.getInstance().save(physicsRootNode, bout); //import from byte array ByteArrayInputStream bin=new ByteArrayInputStream(bout.toByteArray()); BinaryImporter imp=BinaryImporter.getInstance(); imp.setAssetManager(assetManager); Node newPhysicsRootNode=(Node)imp.load(bin); //add all physics objects to physics space getPhysicsSpace().addAll(newPhysicsRootNode); rootNode.attachChild(newPhysicsRootNode); } catch (IOException ex) { Logger.getLogger(TestPhysicsReadWrite.class.getName()).log(Level.SEVERE, null, ex); } }
Example #11
Source File: TestSimplePhysics.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); bulletAppState.getPhysicsSpace().enableDebug(assetManager); // Add a physics sphere to the world Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1); physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0)); rootNode.attachChild(physicsSphere); getPhysicsSpace().add(physicsSphere); // Add a physics sphere to the world using the collision shape from sphere one Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, physicsSphere.getControl(RigidBodyControl.class).getCollisionShape(), 1); physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0)); rootNode.attachChild(physicsSphere2); getPhysicsSpace().add(physicsSphere2); // Add a physics box to the world Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1); physicsBox.getControl(RigidBodyControl.class).setFriction(0.1f); physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f)); rootNode.attachChild(physicsBox); getPhysicsSpace().add(physicsBox); // Add a physics cylinder to the world Node physicsCylinder = PhysicsTestHelper.createPhysicsTestNode(assetManager, new CylinderCollisionShape(new Vector3f(1f, 1f, 1.5f)), 1); physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0)); rootNode.attachChild(physicsCylinder); getPhysicsSpace().add(physicsCylinder); // an obstacle mesh, does not move (mass=0) Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0); node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f)); rootNode.attachChild(node2); getPhysicsSpace().add(node2); // the floor mesh, does not move (mass=0) Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0); node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f)); rootNode.attachChild(node3); getPhysicsSpace().add(node3); // Join the physics objects with a Point2Point joint // PhysicsPoint2PointJoint joint=new PhysicsPoint2PointJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0)); // PhysicsHingeJoint joint=new PhysicsHingeJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0), Vector3f.UNIT_Z,Vector3f.UNIT_Z); // getPhysicsSpace().add(joint); }
Example #12
Source File: PlaneCollisionShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule capsule = im.getCapsule(this); plane = (Plane) capsule.readSavable("collisionPlane", new Plane()); createShape(); }
Example #13
Source File: TestKinematicAddToPhysicsSpaceIssue.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); bulletAppState.getPhysicsSpace().enableDebug(assetManager); // Add a physics sphere to the world Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1); physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0)); rootNode.attachChild(physicsSphere); //Setting the rigidBody to kinematic before adding it to the physic space physicsSphere.getControl(RigidBodyControl.class).setKinematic(true); //adding it to the physic space getPhysicsSpace().add(physicsSphere); //Making it not kinematic again, it should fall under gravity, it doesn't physicsSphere.getControl(RigidBodyControl.class).setKinematic(false); // Add a physics sphere to the world using the collision shape from sphere one Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1); physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(5, 6, 0)); rootNode.attachChild(physicsSphere2); //Adding the rigid body to physic space getPhysicsSpace().add(physicsSphere2); //making it kinematic physicsSphere2.getControl(RigidBodyControl.class).setKinematic(false); //Making it not kinematic again, it works properly, the rigidbody is affected by grvity. physicsSphere2.getControl(RigidBodyControl.class).setKinematic(false); // an obstacle mesh, does not move (mass=0) Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0); node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f)); rootNode.attachChild(node2); getPhysicsSpace().add(node2); // the floor mesh, does not move (mass=0) Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0); node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f)); rootNode.attachChild(node3); getPhysicsSpace().add(node3); }
Example #14
Source File: PlaneCollisionShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void write(JmeExporter ex) throws IOException { super.write(ex); OutputCapsule capsule = ex.getCapsule(this); capsule.write(plane, "collisionPlane", new Plane()); }
Example #15
Source File: TestLocalPhysics.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); bulletAppState.getPhysicsSpace().enableDebug(assetManager); // Add a physics sphere to the world Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1); physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0)); physicsSphere.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsSphere); getPhysicsSpace().add(physicsSphere); // Add a physics sphere to the world using the collision shape from sphere one Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, physicsSphere.getControl(RigidBodyControl.class).getCollisionShape(), 1); physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0)); physicsSphere2.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsSphere2); getPhysicsSpace().add(physicsSphere2); // Add a physics box to the world Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1); physicsBox.getControl(RigidBodyControl.class).setFriction(0.1f); physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f)); physicsBox.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsBox); getPhysicsSpace().add(physicsBox); // Add a physics cylinder to the world Node physicsCylinder = PhysicsTestHelper.createPhysicsTestNode(assetManager, new CylinderCollisionShape(new Vector3f(1f, 1f, 1.5f)), 1); physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0)); physicsCylinder.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsCylinder); getPhysicsSpace().add(physicsCylinder); // an obstacle mesh, does not move (mass=0) Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0); node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f)); node2.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(node2); getPhysicsSpace().add(node2); // the floor mesh, does not move (mass=0) Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0); node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f)); node3.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(node3); getPhysicsSpace().add(node3); // Join the physics objects with a Point2Point joint // PhysicsPoint2PointJoint joint=new PhysicsPoint2PointJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0)); // PhysicsHingeJoint joint=new PhysicsHingeJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0), Vector3f.UNIT_Z,Vector3f.UNIT_Z); // getPhysicsSpace().add(joint); }
Example #16
Source File: PlaneCollisionShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void write(JmeExporter ex) throws IOException { super.write(ex); OutputCapsule capsule = ex.getCapsule(this); capsule.write(plane, "collisionPlane", new Plane()); }
Example #17
Source File: TestSceneWater.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void simpleInitApp() { this.flyCam.setMoveSpeed(10); Node mainScene=new Node(); cam.setLocation(new Vector3f(-27.0f, 1.0f, 75.0f)); cam.setRotation(new Quaternion(0.03f, 0.9f, 0f, 0.4f)); // load sky mainScene.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false)); File file = new File("wildhouse.zip"); if (file.exists()) { useHttp = false; } // create the geometry and attach it // load the level from zip or http zip if (useHttp) { assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/wildhouse.zip", HttpZipLocator.class.getName()); } else { assetManager.registerLocator("wildhouse.zip", ZipLocator.class.getName()); } Spatial scene = assetManager.loadModel("main.scene"); DirectionalLight sun = new DirectionalLight(); Vector3f lightDir=new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f); sun.setDirection(lightDir); sun.setColor(ColorRGBA.White.clone().multLocal(2)); scene.addLight(sun); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); //add lightPos Geometry Sphere lite=new Sphere(8, 8, 3.0f); Geometry lightSphere=new Geometry("lightsphere", lite); lightSphere.setMaterial(mat); Vector3f lightPos=lightDir.multLocal(-400); lightSphere.setLocalTranslation(lightPos); rootNode.attachChild(lightSphere); SimpleWaterProcessor waterProcessor = new SimpleWaterProcessor(assetManager); waterProcessor.setReflectionScene(mainScene); waterProcessor.setDebug(false); waterProcessor.setLightPosition(lightPos); waterProcessor.setRefractionClippingOffset(1.0f); //setting the water plane Vector3f waterLocation=new Vector3f(0,-20,0); waterProcessor.setPlane(new Plane(Vector3f.UNIT_Y, waterLocation.dot(Vector3f.UNIT_Y))); WaterUI waterUi=new WaterUI(inputManager, waterProcessor); waterProcessor.setWaterColor(ColorRGBA.Brown); waterProcessor.setDebug(true); //lower render size for higher performance // waterProcessor.setRenderSize(128,128); //raise depth to see through water // waterProcessor.setWaterDepth(20); //lower the distortion scale if the waves appear too strong // waterProcessor.setDistortionScale(0.1f); //lower the speed of the waves if they are too fast // waterProcessor.setWaveSpeed(0.01f); Quad quad = new Quad(400,400); //the texture coordinates define the general size of the waves quad.scaleTextureCoordinates(new Vector2f(6f,6f)); Geometry water=new Geometry("water", quad); water.setShadowMode(ShadowMode.Receive); water.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); water.setMaterial(waterProcessor.getMaterial()); water.setLocalTranslation(-200, -20, 250); rootNode.attachChild(water); viewPort.addProcessor(waterProcessor); mainScene.attachChild(scene); rootNode.attachChild(mainScene); }
Example #18
Source File: PlaneCollisionShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public final Plane getPlane() { return plane; }
Example #19
Source File: PlaneCollisionShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Creates a plane Collision shape * @param plane the plane that defines the shape */ public PlaneCollisionShape(Plane plane) { this.plane = plane; createShape(); }
Example #20
Source File: PlaneCollisionShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule capsule = im.getCapsule(this); plane = (Plane) capsule.readSavable("collisionPlane", new Plane()); createShape(); }
Example #21
Source File: PlaneCollisionShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void write(JmeExporter ex) throws IOException { super.write(ex); OutputCapsule capsule = ex.getCapsule(this); capsule.write(plane, "collisionPlane", new Plane()); }
Example #22
Source File: PlaneCollisionShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public final Plane getPlane() { return plane; }
Example #23
Source File: AbstractStrengthSteeringBehavior.java From MonkeyBrains with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Forces the steer to stay inside a plane. * * @param Plane plane where the steer will be */ public void setupStrengthControl(Plane plane) { this.scalar = 1.0f; this.plane = plane; this.type = SteerStrengthType.PLANE; }
Example #24
Source File: PlaneCollisionShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
public final Plane getPlane() { return plane; }
Example #25
Source File: PlaneCollisionShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Creates a plane Collision shape * @param plane the plane that defines the shape */ public PlaneCollisionShape(Plane plane) { this.plane = plane; createShape(); }
Example #26
Source File: PlaneCollisionShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Creates a plane Collision shape * @param plane the plane that defines the shape */ public PlaneCollisionShape(Plane plane) { this.plane = plane; createShape(); }
Example #27
Source File: PathFollowBehavior.java From MonkeyBrains with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * @see AbstractStrengthSteeringBehavior#calculateRawSteering() */ @Override protected Vector3f calculateRawSteering() { Vector3f steer = new Vector3f(); if (active) { //Start to follow from the beginning if (this.nextSpineJoint < 0) { this.nextSpineJoint = 0; } if (this.nextSpineJoint < this.orderedPointsList.size()) { //Calculate the next exit Vector3f exitNormal; if (this.nextSpineJoint == 0) { exitNormal = this.orderedPointsList.get(this.nextSpineJoint + 1).subtract(this.orderedPointsList.get(this.nextSpineJoint)); } else { exitNormal = this.orderedPointsList.get(this.nextSpineJoint).subtract(this.orderedPointsList.get(this.nextSpineJoint - 1)); } this.nextExit = new Plane(); this.nextExit.setOriginNormal( this.orderedPointsList.get(this.nextSpineJoint), exitNormal); Vector3f posProjection = this.nextExit.getClosestPoint(this.agent.getLocalTranslation()); float distanceToCenter = posProjection.subtract(this.orderedPointsList.get(this.nextSpineJoint)).length(); //chaeck if the agent is outside the path if (distanceToCenter > this.pathRadius) { //Move to the next spine and inside the path Vector3f moveToSpine = this.agent.offset(this.orderedPointsList.get(this.nextSpineJoint)).normalize(); Vector3f moveToCenter = this.orderedPointsList.get(this.nextSpineJoint).subtract(posProjection).normalize(); steer = moveToSpine.add(moveToCenter); } else { //Move through the path Vector3f moveThroughPathSteer = exitNormal.normalize(); Vector3f predictedPos = this.agent.getPredictedPosition(); Vector3f predictedOffsetFromNextCenter = predictedPos.subtract(this.orderedPointsList.get(this.nextSpineJoint)); Vector3f projectionIntoSpine = this.orderedPointsList.get(this.nextSpineJoint).add( exitNormal.mult(predictedOffsetFromNextCenter.dot(exitNormal) / exitNormal.lengthSquared())); Vector3f predictedOffset = predictedPos.subtract(projectionIntoSpine); Vector3f predictedOffsetFromSurface = predictedOffset.subtract(predictedOffset.normalize().mult(this.pathRadius)); //Path containment if (predictedOffset.length() > this.pathRadius) { moveThroughPathSteer = moveThroughPathSteer.add(predictedOffsetFromSurface.mult(cohesionStrength)); } steer = moveThroughPathSteer; if (this.nextExit.whichSide(this.agent.getLocalTranslation()) == Side.Positive) { this.nextSpineJoint++; } } } else { //The path has ended this.active = false; } } return steer; }
Example #28
Source File: TestSimplePhysics.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); bulletAppState.setDebugEnabled(true); // Add a physics sphere to the world Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1); physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0)); rootNode.attachChild(physicsSphere); getPhysicsSpace().add(physicsSphere); // Add a physics sphere to the world using the collision shape from sphere one Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, physicsSphere.getControl(RigidBodyControl.class).getCollisionShape(), 1); physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0)); rootNode.attachChild(physicsSphere2); getPhysicsSpace().add(physicsSphere2); // Add a physics box to the world Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1); physicsBox.getControl(RigidBodyControl.class).setFriction(0.1f); physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f)); rootNode.attachChild(physicsBox); getPhysicsSpace().add(physicsBox); // Add a physics cylinder to the world Node physicsCylinder = PhysicsTestHelper.createPhysicsTestNode(assetManager, new CylinderCollisionShape(new Vector3f(1f, 1f, 1.5f)), 1); physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0)); rootNode.attachChild(physicsCylinder); getPhysicsSpace().add(physicsCylinder); // an obstacle mesh, does not move (mass=0) Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0); node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f)); rootNode.attachChild(node2); getPhysicsSpace().add(node2); // the floor mesh, does not move (mass=0) Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0); node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f)); rootNode.attachChild(node3); getPhysicsSpace().add(node3); // Join the physics objects with a Point2Point joint // PhysicsPoint2PointJoint joint=new PhysicsPoint2PointJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0)); // PhysicsHingeJoint joint=new PhysicsHingeJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0), Vector3f.UNIT_Z,Vector3f.UNIT_Z); // getPhysicsSpace().add(joint); }
Example #29
Source File: TestLocalPhysics.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); bulletAppState.setDebugEnabled(true); // Add a physics sphere to the world Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1); physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0)); physicsSphere.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsSphere); getPhysicsSpace().add(physicsSphere); // Add a physics sphere to the world using the collision shape from sphere one Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, physicsSphere.getControl(RigidBodyControl.class).getCollisionShape(), 1); physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0)); physicsSphere2.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsSphere2); getPhysicsSpace().add(physicsSphere2); // Add a physics box to the world Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1); physicsBox.getControl(RigidBodyControl.class).setFriction(0.1f); physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f)); physicsBox.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsBox); getPhysicsSpace().add(physicsBox); // Add a physics cylinder to the world Node physicsCylinder = PhysicsTestHelper.createPhysicsTestNode(assetManager, new CylinderCollisionShape(new Vector3f(1f, 1f, 1.5f)), 1); physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0)); physicsCylinder.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsCylinder); getPhysicsSpace().add(physicsCylinder); // an obstacle mesh, does not move (mass=0) Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0); node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f)); node2.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(node2); getPhysicsSpace().add(node2); // the floor mesh, does not move (mass=0) Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0); node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f)); node3.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(node3); getPhysicsSpace().add(node3); // Join the physics objects with a Point2Point joint // PhysicsPoint2PointJoint joint=new PhysicsPoint2PointJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0)); // PhysicsHingeJoint joint=new PhysicsHingeJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0), Vector3f.UNIT_Z,Vector3f.UNIT_Z); // getPhysicsSpace().add(joint); }
Example #30
Source File: TestKinematicAddToPhysicsSpaceIssue.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); bulletAppState.setDebugEnabled(true); // Add a physics sphere to the world Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1); physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0)); rootNode.attachChild(physicsSphere); //Setting the rigidBody to kinematic before adding it to the physics space physicsSphere.getControl(RigidBodyControl.class).setKinematic(true); //adding it to the physics space getPhysicsSpace().add(physicsSphere); //Making it not kinematic again, it should fall under gravity, it doesn't physicsSphere.getControl(RigidBodyControl.class).setKinematic(false); // Add a physics sphere to the world using the collision shape from sphere one Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1); physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(5, 6, 0)); rootNode.attachChild(physicsSphere2); //Adding the rigid body to physics space getPhysicsSpace().add(physicsSphere2); //making it kinematic physicsSphere2.getControl(RigidBodyControl.class).setKinematic(false); //Making it not kinematic again, it works properly, the rigidbody is affected by grvity. physicsSphere2.getControl(RigidBodyControl.class).setKinematic(false); // an obstacle mesh, does not move (mass=0) Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0); node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f)); rootNode.attachChild(node2); getPhysicsSpace().add(node2); // the floor mesh, does not move (mass=0) Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0); node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f)); rootNode.attachChild(node3); getPhysicsSpace().add(node3); }