Java Code Examples for com.jme3.math.Vector3f#UNIT_Z
The following examples show how to use
com.jme3.math.Vector3f#UNIT_Z .
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: TestAttachGhostObject.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void setupJoint() { Node holderNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.1f, .1f, .1f)), 0); holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, 0, 0f)); rootNode.attachChild(holderNode); getPhysicsSpace().add(holderNode); Node hammerNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.3f, .3f, .3f)), 1); hammerNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -1, 0f)); rootNode.attachChild(hammerNode); getPhysicsSpace().add(hammerNode); //immovable collisionNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.3f, .3f, .3f)), 0); collisionNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(1.8f, 0, 0f)); rootNode.attachChild(collisionNode); getPhysicsSpace().add(collisionNode); //ghost node ghostControl = new GhostControl(new SphereCollisionShape(0.7f)); hammerNode.addControl(ghostControl); getPhysicsSpace().add(ghostControl); joint = new HingeJoint(holderNode.getControl(RigidBodyControl.class), hammerNode.getControl(RigidBodyControl.class), Vector3f.ZERO, new Vector3f(0f, -1, 0f), Vector3f.UNIT_Z, Vector3f.UNIT_Z); getPhysicsSpace().add(joint); }
Example 2
Source File: TestAttachGhostObject.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public void setupJoint() { Node holderNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.1f, .1f, .1f)), 0); holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, 0, 0f)); rootNode.attachChild(holderNode); getPhysicsSpace().add(holderNode); Node hammerNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.3f, .3f, .3f)), 1); hammerNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -1, 0f)); rootNode.attachChild(hammerNode); getPhysicsSpace().add(hammerNode); //immovable collisionNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.3f, .3f, .3f)), 0); collisionNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(1.8f, 0, 0f)); rootNode.attachChild(collisionNode); getPhysicsSpace().add(collisionNode); //ghost node ghostControl = new GhostControl(new SphereCollisionShape(0.7f)); hammerNode.addControl(ghostControl); getPhysicsSpace().add(ghostControl); joint = new HingeJoint(holderNode.getControl(RigidBodyControl.class), hammerNode.getControl(RigidBodyControl.class), Vector3f.ZERO, new Vector3f(0f, -1, 0f), Vector3f.UNIT_Z, Vector3f.UNIT_Z); getPhysicsSpace().add(joint); }
Example 3
Source File: EditorTransformSupport.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Get a vector to calculate transformations by the Axis. * * @param transform the base transform. * @param pickedAxis the picked Axis. * @param camera the camera. * @return the axis vector. */ @JmeThread protected @NotNull Vector3f getPickedVector(@NotNull final Transform transform, @NotNull final PickedAxis pickedAxis, @NotNull final Camera camera) { if (pickedAxis == PickedAxis.Y) { return Vector3f.UNIT_Y; } else if (pickedAxis == PickedAxis.Z) { return Vector3f.UNIT_Z; } else { return Vector3f.UNIT_X; } }
Example 4
Source File: EditorTransformSupport.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Get a vector to calculate scaling by the axis. * * @param transform the base transform. * @param pickedAxis the picked Axis. * @param camera the camera. * @return the axis vector. */ @JmeThread protected @NotNull Vector3f getScaleAxis(@NotNull final Transform transform, @NotNull final PickedAxis pickedAxis, @NotNull final Camera camera) { if (pickedAxis == PickedAxis.Y) { return Vector3f.UNIT_Y; } else if (pickedAxis == PickedAxis.Z) { return Vector3f.UNIT_Z; } else return Vector3f.UNIT_X; }
Example 5
Source File: TestPhysicsHingeJoint.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void setupJoint() { Node holderNode=PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f( .1f, .1f, .1f)),0); holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f,0,0f)); rootNode.attachChild(holderNode); getPhysicsSpace().add(holderNode); Node hammerNode=PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f( .3f, .3f, .3f)),1); hammerNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f,-1,0f)); rootNode.attachChild(hammerNode); getPhysicsSpace().add(hammerNode); joint=new HingeJoint(holderNode.getControl(RigidBodyControl.class), hammerNode.getControl(RigidBodyControl.class), Vector3f.ZERO, new Vector3f(0f,-1,0f), Vector3f.UNIT_Z, Vector3f.UNIT_Z); getPhysicsSpace().add(joint); }
Example 6
Source File: DebugTools.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Render all the debug geometries to the specified view port. * * @param rm the render manager (not null) * @param vp the view port (not null) */ public void show(RenderManager rm, ViewPort vp) { if (!Vector3f.UNIT_X.equals(UNIT_X_CHECK) || !Vector3f.UNIT_Y.equals(UNIT_Y_CHECK) || !Vector3f.UNIT_Z.equals(UNIT_Z_CHECK) || !Vector3f.UNIT_XYZ.equals(UNIT_XYZ_CHECK) || !Vector3f.ZERO.equals(ZERO_CHECK)) { throw new IllegalStateException("Unit vectors compromised!" + "\nX: " + Vector3f.UNIT_X + "\nY: " + Vector3f.UNIT_Y + "\nZ: " + Vector3f.UNIT_Z + "\nXYZ: " + Vector3f.UNIT_XYZ + "\nZERO: " + Vector3f.ZERO); } debugNode.updateLogicalState(0); debugNode.updateGeometricState(); rm.renderScene(debugNode, vp); }
Example 7
Source File: BoundingCollisionTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testBoxRayCollision() { BoundingBox box = new BoundingBox(Vector3f.ZERO, 1, 1, 1); Ray ray = new Ray(Vector3f.ZERO, Vector3f.UNIT_Z); // XXX: seems incorrect, ray inside box should only generate // one result... checkCollision(box, ray, 2); ray.setOrigin(new Vector3f(0, 0, -5)); checkCollision(box, ray, 2); // XXX: is this right? the ray origin is on the box's side.. ray.setOrigin(new Vector3f(0, 0, 2f)); checkCollision(box, ray, 0); ray.setOrigin(new Vector3f(0, 0, -2f)); checkCollision(box, ray, 2); // parallel to the edge, touching the side ray.setOrigin(new Vector3f(0, 1f, -2f)); checkCollision(box, ray, 2); // still parallel, but not touching the side ray.setOrigin(new Vector3f(0, 1f + FastMath.ZERO_TOLERANCE, -2f)); checkCollision(box, ray, 0); }
Example 8
Source File: TestPhysicsHingeJoint.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void setupJoint() { Node holderNode=PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f( .1f, .1f, .1f)),0); holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f,0,0f)); rootNode.attachChild(holderNode); getPhysicsSpace().add(holderNode); Node hammerNode=PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f( .3f, .3f, .3f)),1); hammerNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f,-1,0f)); rootNode.attachChild(hammerNode); getPhysicsSpace().add(hammerNode); joint=new HingeJoint(holderNode.getControl(RigidBodyControl.class), hammerNode.getControl(RigidBodyControl.class), Vector3f.ZERO, new Vector3f(0f,-1,0f), Vector3f.UNIT_Z, Vector3f.UNIT_Z); getPhysicsSpace().add(joint); }
Example 9
Source File: TestPhysicsReadWrite.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); 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 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: BetterCharacterControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Realign the local forward vector to given direction vector, if null is * supplied Vector3f.UNIT_Z is used. The input vector must be perpendicular * to gravity vector. This normally only needs to be invoked when the * gravity direction changed continuously and the local forward vector is * off due to drift. E.g. after walking around on a sphere "planet" for a * while and then going back to a Y-up coordinate system the local Z-forward * might not be 100% aligned with the Z axis. * * @param vec the desired forward vector (perpendicular to the gravity * vector, may be null, default=0,0,1) */ public void resetForward(Vector3f vec) { if (vec == null) { vec = Vector3f.UNIT_Z; } localForward.set(vec); updateLocalCoordinateSystem(); }