com.jme3.scene.shape.Cylinder Java Examples
The following examples show how to use
com.jme3.scene.shape.Cylinder.
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: TestCylinder.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void simpleInitApp() { Cylinder t = new Cylinder(20, 50, 1, 2, true); Geometry geom = new Geometry("Cylinder", t); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true); key.setGenerateMips(true); Texture tex = assetManager.loadTexture(key); tex.setMinFilter(Texture.MinFilter.Trilinear); mat.setTexture("ColorMap", tex); geom.setMaterial(mat); rootNode.attachChild(geom); }
Example #2
Source File: TestCylinder.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void simpleInitApp() { Cylinder t = new Cylinder(20, 50, 1, 2, true); Geometry geom = new Geometry("Cylinder", t); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true); key.setGenerateMips(true); Texture tex = assetManager.loadTexture(key); tex.setMinFilter(Texture.MinFilter.Trilinear); mat.setTexture("ColorMap", tex); geom.setMaterial(mat); rootNode.attachChild(geom); }
Example #3
Source File: TestCollisionShapeFactory.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); bulletAppState.setDebugEnabled(true); createMaterial(); Node node = new Node("node1"); attachRandomGeometry(node, mat1); randomizeTransform(node); Node node2 = new Node("node2"); attachRandomGeometry(node2, mat2); randomizeTransform(node2); node.attachChild(node2); rootNode.attachChild(node); RigidBodyControl control = new RigidBodyControl(0); node.addControl(control); getPhysicsSpace().add(control); //test single geometry too Geometry myGeom = new Geometry("cylinder", new Cylinder(16, 16, 0.5f, 1)); myGeom.setMaterial(mat3); randomizeTransform(myGeom); rootNode.attachChild(myGeom); RigidBodyControl control3 = new RigidBodyControl(0); myGeom.addControl(control3); getPhysicsSpace().add(control3); }
Example #4
Source File: ShapeGeometryTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testCylinders() { Random random = new Random(); // Create a cylinder, cast a random ray, and ensure everything goes well. Node scene = new Node("Scene Node"); for (int i = 0; i < NUMBER_OF_TRIES; i++) { scene.detachAllChildren(); Cylinder cylinder = new Cylinder(2, 8, 1, 1, true); Geometry geometry = new Geometry("cylinder", cylinder); geometry.rotate(FastMath.HALF_PI, 0, 0); scene.attachChild(geometry); // Cast a random ray, and count successes and IndexOutOfBoundsExceptions. Vector3f randomPoint = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat()); Vector3f randomDirection = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat()); randomDirection.normalizeLocal(); Ray ray = new Ray(randomPoint, randomDirection); CollisionResults collisionResults = new CollisionResults(); // If the geometry is invalid, this should throw various exceptions. scene.collideWith(ray, collisionResults); } }
Example #5
Source File: TestCollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); bulletAppState.getPhysicsSpace().enableDebug(assetManager); createMaterial(); Node node = new Node("node1"); attachRandomGeometry(node, mat1); randomizeTransform(node); Node node2 = new Node("node2"); attachRandomGeometry(node2, mat2); randomizeTransform(node2); node.attachChild(node2); rootNode.attachChild(node); RigidBodyControl control = new RigidBodyControl(0); node.addControl(control); getPhysicsSpace().add(control); //test single geometry too Geometry myGeom = new Geometry("cylinder", new Cylinder(16, 16, 0.5f, 1)); myGeom.setMaterial(mat3); randomizeTransform(myGeom); rootNode.attachChild(myGeom); RigidBodyControl control3 = new RigidBodyControl(0); myGeom.addControl(control3); getPhysicsSpace().add(control3); }
Example #6
Source File: TestBaseAnimSerialization.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
private Mesh createMesh() { Cylinder c = new Cylinder(30, 16, 0.1f, 1, true); ShortBuffer jointIndex = (ShortBuffer) VertexBuffer.createBuffer(VertexBuffer.Format.UnsignedShort, 4, c.getVertexCount()); jointIndex.rewind(); c.setMaxNumWeights(1); FloatBuffer jointWeight = (FloatBuffer) VertexBuffer.createBuffer(VertexBuffer.Format.Float, 4, c.getVertexCount()); jointWeight.rewind(); VertexBuffer vb = c.getBuffer(VertexBuffer.Type.Position); FloatBuffer fvb = (FloatBuffer) vb.getData(); fvb.rewind(); for (int i = 0; i < c.getVertexCount(); i++) { fvb.get(); fvb.get(); float z = fvb.get(); int index = 0; if (z > 0) { index = 0; } else if (z > -0.2) { index = 1; } else { index = 2; } jointIndex.put((short) index).put((short) 0).put((short) 0).put((short) 0); jointWeight.put(1f).put(0f).put(0f).put(0f); } c.setBuffer(VertexBuffer.Type.BoneIndex, 4, jointIndex); c.setBuffer(VertexBuffer.Type.BoneWeight, 4, jointWeight); c.updateCounts(); c.updateBound(); VertexBuffer weightsHW = new VertexBuffer(VertexBuffer.Type.HWBoneWeight); VertexBuffer indicesHW = new VertexBuffer(VertexBuffer.Type.HWBoneIndex); indicesHW.setUsage(VertexBuffer.Usage.CpuOnly); weightsHW.setUsage(VertexBuffer.Usage.CpuOnly); c.setBuffer(weightsHW); c.setBuffer(indicesHW); c.generateBindPose(); c.prepareForAnim(false); return c; }
Example #7
Source File: TestArmature.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
private Mesh createMesh() { Cylinder c = new Cylinder(30, 16, 0.1f, 1, true); ShortBuffer jointIndex = (ShortBuffer) VertexBuffer.createBuffer(VertexBuffer.Format.UnsignedShort, 4, c.getVertexCount()); jointIndex.rewind(); c.setMaxNumWeights(1); FloatBuffer jointWeight = (FloatBuffer) VertexBuffer.createBuffer(VertexBuffer.Format.Float, 4, c.getVertexCount()); jointWeight.rewind(); VertexBuffer vb = c.getBuffer(VertexBuffer.Type.Position); FloatBuffer fvb = (FloatBuffer) vb.getData(); fvb.rewind(); for (int i = 0; i < c.getVertexCount(); i++) { fvb.get(); fvb.get(); float z = fvb.get(); int index = 0; if (z > 0) { index = 0; } else if (z > -0.2) { index = 1; } else { index = 2; } jointIndex.put((short) index).put((short) 0).put((short) 0).put((short) 0); jointWeight.put(1f).put(0f).put(0f).put(0f); } c.setBuffer(VertexBuffer.Type.BoneIndex, 4, jointIndex); c.setBuffer(VertexBuffer.Type.BoneWeight, 4, jointWeight); c.updateCounts(); c.updateBound(); VertexBuffer weightsHW = new VertexBuffer(VertexBuffer.Type.HWBoneWeight); VertexBuffer indicesHW = new VertexBuffer(VertexBuffer.Type.HWBoneIndex); indicesHW.setUsage(VertexBuffer.Usage.CpuOnly); weightsHW.setUsage(VertexBuffer.Usage.CpuOnly); c.setBuffer(weightsHW); c.setBuffer(indicesHW); c.generateBindPose(); c.prepareForAnim(false); return c; }
Example #8
Source File: TestIssue1120.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void dropTest() { attachTestObject(new Cylinder(2, 16, 0.2f, 2f, true), new Vector3f(0f, 2f, -5f), 2); attachTestObject(new Cylinder(2, 16, 0.2f, 2f, true), new Vector3f(-1f, 2f, -5f), 2); attachTestObject(new Cylinder(2, 16, 0.2f, 2f, true), new Vector3f(-2f, 2f, -5f), 2); attachTestObject(new Cylinder(2, 16, 0.2f, 2f, true), new Vector3f(-3f, 2f, -5f), 2); }
Example #9
Source File: TestPhysicsCar.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void buildPlayer() { Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); mat.getAdditionalRenderState().setWireframe(true); mat.setColor("Color", ColorRGBA.Red); //create a compound shape and attach the BoxCollisionShape for the car body at 0,1,0 //this shifts the effective center of mass of the BoxCollisionShape to 0,-1,0 CompoundCollisionShape compoundShape = new CompoundCollisionShape(); BoxCollisionShape box = new BoxCollisionShape(new Vector3f(1.2f, 0.5f, 2.4f)); compoundShape.addChildShape(box, new Vector3f(0, 1, 0)); //create vehicle node Node vehicleNode=new Node("vehicleNode"); vehicle = new VehicleControl(compoundShape, 400); vehicleNode.addControl(vehicle); //setting suspension values for wheels, this can be a bit tricky //see also https://docs.google.com/Doc?docid=0AXVUZ5xw6XpKZGNuZG56a3FfMzU0Z2NyZnF4Zmo&hl=en float stiffness = 60.0f;//200=f1 car float compValue = .3f; //(should be lower than damp) float dampValue = .4f; vehicle.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness)); vehicle.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness)); vehicle.setSuspensionStiffness(stiffness); vehicle.setMaxSuspensionForce(10000.0f); //Create four wheels and add them at their locations Vector3f wheelDirection = new Vector3f(0, -1, 0); // was 0, -1, 0 Vector3f wheelAxle = new Vector3f(-1, 0, 0); // was -1, 0, 0 float radius = 0.5f; float restLength = 0.3f; float yOff = 0.5f; float xOff = 1f; float zOff = 2f; Cylinder wheelMesh = new Cylinder(16, 16, radius, radius * 0.6f, true); Node node1 = new Node("wheel 1 node"); Geometry wheels1 = new Geometry("wheel 1", wheelMesh); node1.attachChild(wheels1); wheels1.rotate(0, FastMath.HALF_PI, 0); wheels1.setMaterial(mat); vehicle.addWheel(node1, new Vector3f(-xOff, yOff, zOff), wheelDirection, wheelAxle, restLength, radius, true); Node node2 = new Node("wheel 2 node"); Geometry wheels2 = new Geometry("wheel 2", wheelMesh); node2.attachChild(wheels2); wheels2.rotate(0, FastMath.HALF_PI, 0); wheels2.setMaterial(mat); vehicle.addWheel(node2, new Vector3f(xOff, yOff, zOff), wheelDirection, wheelAxle, restLength, radius, true); Node node3 = new Node("wheel 3 node"); Geometry wheels3 = new Geometry("wheel 3", wheelMesh); node3.attachChild(wheels3); wheels3.rotate(0, FastMath.HALF_PI, 0); wheels3.setMaterial(mat); vehicle.addWheel(node3, new Vector3f(-xOff, yOff, -zOff), wheelDirection, wheelAxle, restLength, radius, false); Node node4 = new Node("wheel 4 node"); Geometry wheels4 = new Geometry("wheel 4", wheelMesh); node4.attachChild(wheels4); wheels4.rotate(0, FastMath.HALF_PI, 0); wheels4.setMaterial(mat); vehicle.addWheel(node4, new Vector3f(xOff, yOff, -zOff), wheelDirection, wheelAxle, restLength, radius, false); vehicleNode.attachChild(node1); vehicleNode.attachChild(node2); vehicleNode.attachChild(node3); vehicleNode.attachChild(node4); rootNode.attachChild(vehicleNode); getPhysicsSpace().add(vehicle); }
Example #10
Source File: TestPhysicsCar.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
private void buildPlayer() { Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); mat.getAdditionalRenderState().setWireframe(true); mat.setColor("Color", ColorRGBA.Red); //create a compound shape and attach the BoxCollisionShape for the car body at 0,1,0 //this shifts the effective center of mass of the BoxCollisionShape to 0,-1,0 CompoundCollisionShape compoundShape = new CompoundCollisionShape(); BoxCollisionShape box = new BoxCollisionShape(new Vector3f(1.2f, 0.5f, 2.4f)); compoundShape.addChildShape(box, new Vector3f(0, 1, 0)); //create vehicle node Node vehicleNode=new Node("vehicleNode"); vehicle = new VehicleControl(compoundShape, 400); vehicleNode.addControl(vehicle); //setting suspension values for wheels, this can be a bit tricky //see also https://docs.google.com/Doc?docid=0AXVUZ5xw6XpKZGNuZG56a3FfMzU0Z2NyZnF4Zmo&hl=en float stiffness = 60.0f;//200=f1 car float compValue = .3f; //(should be lower than damp) float dampValue = .4f; vehicle.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness)); vehicle.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness)); vehicle.setSuspensionStiffness(stiffness); vehicle.setMaxSuspensionForce(10000.0f); //Create four wheels and add them at their locations Vector3f wheelDirection = new Vector3f(0, -1, 0); // was 0, -1, 0 Vector3f wheelAxle = new Vector3f(-1, 0, 0); // was -1, 0, 0 float radius = 0.5f; float restLength = 0.3f; float yOff = 0.5f; float xOff = 1f; float zOff = 2f; Cylinder wheelMesh = new Cylinder(16, 16, radius, radius * 0.6f, true); Node node1 = new Node("wheel 1 node"); Geometry wheels1 = new Geometry("wheel 1", wheelMesh); node1.attachChild(wheels1); wheels1.rotate(0, FastMath.HALF_PI, 0); wheels1.setMaterial(mat); vehicle.addWheel(node1, new Vector3f(-xOff, yOff, zOff), wheelDirection, wheelAxle, restLength, radius, true); Node node2 = new Node("wheel 2 node"); Geometry wheels2 = new Geometry("wheel 2", wheelMesh); node2.attachChild(wheels2); wheels2.rotate(0, FastMath.HALF_PI, 0); wheels2.setMaterial(mat); vehicle.addWheel(node2, new Vector3f(xOff, yOff, zOff), wheelDirection, wheelAxle, restLength, radius, true); Node node3 = new Node("wheel 3 node"); Geometry wheels3 = new Geometry("wheel 3", wheelMesh); node3.attachChild(wheels3); wheels3.rotate(0, FastMath.HALF_PI, 0); wheels3.setMaterial(mat); vehicle.addWheel(node3, new Vector3f(-xOff, yOff, -zOff), wheelDirection, wheelAxle, restLength, radius, false); Node node4 = new Node("wheel 4 node"); Geometry wheels4 = new Geometry("wheel 4", wheelMesh); node4.attachChild(wheels4); wheels4.rotate(0, FastMath.HALF_PI, 0); wheels4.setMaterial(mat); vehicle.addWheel(node4, new Vector3f(xOff, yOff, -zOff), wheelDirection, wheelAxle, restLength, radius, false); vehicleNode.attachChild(node1); vehicleNode.attachChild(node2); vehicleNode.attachChild(node3); vehicleNode.attachChild(node4); rootNode.attachChild(vehicleNode); getPhysicsSpace().add(vehicle); }