com.jme3.math.FastMath Java Examples
The following examples show how to use
com.jme3.math.FastMath.
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: TestHalfFloat.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public static void main(String[] args){ Scanner scan = new Scanner(System.in); while (true){ System.out.println("Enter float to convert or 'x' to exit: "); String s = scan.nextLine(); if (s.equals("x")) break; float flt = Float.valueOf(s); short half = FastMath.convertFloatToHalf(flt); float flt2 = FastMath.convertHalfToFloat(half); System.out.println("Input float: "+flt); System.out.println("Result float: "+flt2); } }
Example #2
Source File: EmitterMeshFaceShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * This method fills the point with coordinates of randomly selected point on a random face. * The normal param is filled with selected face's normal. * @param store * the variable to store with coordinates of randomly selected selected point on a random face * @param normal * filled with selected face's normal */ @Override public void getRandomPointAndNormal(Vector3f store, Vector3f normal) { int meshIndex = FastMath.nextRandomInt(0, vertices.size() - 1); // the index of the first vertex of a face (must be dividable by 3) int faceIndex = FastMath.nextRandomInt(0, vertices.get(meshIndex).size() / 3 - 1); int vertIndex = faceIndex * 3; // put the point somewhere between the first and the second vertex of a face float moveFactor = FastMath.nextRandomFloat(); store.set(Vector3f.ZERO); store.addLocal(vertices.get(meshIndex).get(vertIndex)); store.addLocal((vertices.get(meshIndex).get(vertIndex + 1).x - vertices.get(meshIndex).get(vertIndex).x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).y - vertices.get(meshIndex).get(vertIndex).y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).z - vertices.get(meshIndex).get(vertIndex).z) * moveFactor); // move the result towards the last face vertex moveFactor = FastMath.nextRandomFloat(); store.addLocal((vertices.get(meshIndex).get(vertIndex + 2).x - store.x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).y - store.y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).z - store.z) * moveFactor); normal.set(normals.get(meshIndex).get(faceIndex)); }
Example #3
Source File: TestSpotLightTerrain.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void simpleInitApp() { makeTerrain(); flyCam.setMoveSpeed(50); sl = new SpotLight(); sl.setSpotRange(100); sl.setSpotOuterAngle(20 * FastMath.DEG_TO_RAD); sl.setSpotInnerAngle(15 * FastMath.DEG_TO_RAD); sl.setDirection(new Vector3f(-0.39820394f, -0.73094344f, 0.55421597f)); sl.setPosition(new Vector3f(-64.61567f, -87.615425f, -202.41328f)); rootNode.addLight(sl); AmbientLight ambLight = new AmbientLight(); ambLight.setColor(new ColorRGBA(0.8f, 0.8f, 0.8f, 0.2f)); rootNode.addLight(ambLight); cam.setLocation(new Vector3f(-41.219646f, -84.8363f, -171.67267f)); cam.setRotation(new Quaternion(-0.04562731f, 0.89917684f, -0.09668826f, -0.4243236f)); sl.setDirection(cam.getDirection()); sl.setPosition(cam.getLocation()); }
Example #4
Source File: TerrainQuad.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected Vector3f getNormal(float x, float z, Vector2f xz) { x-=0.5f; z-=0.5f; float col = FastMath.floor(x); float row = FastMath.floor(z); boolean onX = false; if(1 - (x - col)-(z - row) < 0) // what triangle to interpolate on onX = true; // v1--v2 ^ // | / | | // | / | | // v3--v4 | Z // | // <-------Y // X Vector3f n1 = getMeshNormal((int) FastMath.ceil(x), (int) FastMath.ceil(z)); Vector3f n2 = getMeshNormal((int) FastMath.floor(x), (int) FastMath.ceil(z)); Vector3f n3 = getMeshNormal((int) FastMath.ceil(x), (int) FastMath.floor(z)); Vector3f n4 = getMeshNormal((int) FastMath.floor(x), (int) FastMath.floor(z)); return n1.add(n2).add(n3).add(n4).normalize(); }
Example #5
Source File: Circle.java From OpenRTS with MIT License | 6 votes |
protected void updateGeometry() { FloatBuffer positions = BufferUtils.createFloatBuffer(samples * 3); FloatBuffer normals = BufferUtils.createFloatBuffer(samples * 3); short[] indices = new short[samples * 2]; float rate = FastMath.TWO_PI / samples; float angle = 0; for (int i = 0; i < samples; i++) { float x = FastMath.cos(angle) + center.x; float y = FastMath.sin(angle) + center.y; positions.put(x * radius).put(y * radius).put(center.z); normals.put(new float[] { 0, 1, 0 }); indices[i * 2] = (short) i; indices[i * 2 + 1] = (short) ((i + 1) % samples); angle += rate; } setBuffer(Type.Position, 3, positions); setBuffer(Type.Normal, 3, normals); setBuffer(Type.Index, 2, indices); setBuffer(Type.TexCoord, 2, new float[] { 0, 0, 1, 1 }); updateBound(); }
Example #6
Source File: BetterCharacterControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * This checks if the character can go from ducked to unducked state by * doing a ray test. */ protected boolean checkCanUnDuck() { TempVars vars = TempVars.get(); Vector3f location = vars.vect1; Vector3f rayVector = vars.vect2; location.set(localUp).multLocal(FastMath.ZERO_TOLERANCE).addLocal(this.location); rayVector.set(localUp).multLocal(height + FastMath.ZERO_TOLERANCE).addLocal(location); List<PhysicsRayTestResult> results = space.rayTest(location, rayVector); vars.release(); for (PhysicsRayTestResult physicsRayTestResult : results) { if (!physicsRayTestResult.getCollisionObject().equals(rigidBody)) { return false; } } return true; }
Example #7
Source File: NewtonianParticleInfluencer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void influenceParticle(Particle particle, EmitterShape emitterShape) { emitterShape.getRandomPointAndNormal(particle.position, particle.velocity); // influencing the particle's velocity if (surfaceTangentFactor == 0.0f) { particle.velocity.multLocal(normalVelocity); } else { // calculating surface tangent (velocity contains the 'normal' value) temp.set(particle.velocity.z * surfaceTangentFactor, particle.velocity.y * surfaceTangentFactor, -particle.velocity.x * surfaceTangentFactor); if (surfaceTangentRotation != 0.0f) {// rotating the tangent Matrix3f m = new Matrix3f(); m.fromAngleNormalAxis(FastMath.PI * surfaceTangentRotation, particle.velocity); temp = m.multLocal(temp); } // applying normal factor (this must be done first) particle.velocity.multLocal(normalVelocity); // adding tangent vector particle.velocity.addLocal(temp); } if (velocityVariation != 0.0f) { this.applyVelocityVariation(particle); } }
Example #8
Source File: SweepSphere.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private static float getLowestRoot(float a, float b, float c, float maxR) { float determinant = b * b - 4f * a * c; if (determinant < 0){ return Float.NaN; } float sqrtd = FastMath.sqrt(determinant); float r1 = (-b - sqrtd) / (2f * a); float r2 = (-b + sqrtd) / (2f * a); if (r1 > r2){ float temp = r2; r2 = r1; r1 = temp; } if (r1 > 0 && r1 < maxR){ return r1; } if (r2 > 0 && r2 < maxR){ return r2; } return Float.NaN; }
Example #9
Source File: TestDoppler.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void simpleInitApp() { flyCam.setMoveSpeed(10); Torus torus = new Torus(10, 6, 1, 3); Geometry g = new Geometry("Torus Geom", torus); g.rotate(-FastMath.HALF_PI, 0, 0); g.center(); g.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m")); // rootNode.attachChild(g); ufoNode = new AudioNode(assetManager, "Sound/Effects/Beep.ogg", AudioData.DataType.Buffer); ufoNode.setLooping(true); ufoNode.setPitch(0.5f); ufoNode.setRefDistance(1); ufoNode.setMaxDistance(100000000); ufoNode.setVelocityFromTranslation(true); ufoNode.play(); Geometry ball = new Geometry("Beeper", new Sphere(10, 10, 0.1f)); ball.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m")); ufoNode.attachChild(ball); rootNode.attachChild(ufoNode); }
Example #10
Source File: TestBatchNode.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void simpleUpdate(float tpf) { if (!done) { done = true; batch.attachChild(cube2); batch.batch(); } updateBoindPoints(points); frustum.update(points); time += tpf; dl.setDirection(cam.getDirection()); cube2.setLocalTranslation(FastMath.sin(-time) * 3, FastMath.cos(time) * 3, 0); cube2.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z)); cube2.setLocalScale(Math.max(FastMath.sin(time), 0.5f)); // batch.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z)); }
Example #11
Source File: LeaderFollowingBehavior.java From MonkeyBrains with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @see AbstractStrengthSteeringBehavior#calculateRawSteering() */ @Override protected Vector3f calculateRawSteering() { Vector3f steer; float distanceBetwen = this.agent.distanceRelativeToGameEntity(this.getTarget()); //See how far ahead we need to leed Vector3f fullProjectedLocation = this.getTarget().getPredictedPosition(); Vector3f predictedPositionDiff = fullProjectedLocation.subtract(this.getTarget().getLocalTranslation()); Vector3f projectedLocation = this.getTarget().getLocalTranslation().add(predictedPositionDiff.mult( this.calculateFocusFactor(distanceBetwen))); this.arriveBehavior.setSeekingPosition(projectedLocation); steer = this.arriveBehavior.calculateRawSteering(); if (!(distanceBetwen > this.distanceToEvade) && !(this.getTarget().forwardness(this.agent) < FastMath.cos(this.minimumAngle))) { //Incorrect angle and Is in the proper distance to evade -> Evade the leader Vector3f arriveSteer = steer.mult(distanceBetwen / this.distanceToEvade); Vector3f evadeSteer = this.evadeBehavior.calculateRawSteering(); evadeSteer.mult(this.distanceToEvade / (1 + distanceBetwen)); steer = (new Vector3f()).add(arriveSteer).add(evadeSteer); } return steer; }
Example #12
Source File: SeparationBehavior.java From MonkeyBrains with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @see AbstractSteeringBehavior#calculateSteering() */ @Override protected Vector3f calculateRawSteering() { //Propities whom behaviour belongs. Vector3f agentLocation = super.agent.getLocalTranslation(); Vector3f steering = new Vector3f(); for (GameEntity obstacle : this.obstacles) { //If the obstacle is not himself if (obstacle != this.agent && obstacle.distanceRelativeToGameEntity(this.agent) < this.minDistance) { Vector3f location = obstacle.getLocalTranslation().subtract(agentLocation); float lengthSquared = location.lengthSquared(); location.normalizeLocal(); steering.addLocal(location.negate().mult(1f / ((float) FastMath.pow(lengthSquared, 2)))); } } return steering; }
Example #13
Source File: FlyByCamera.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
protected void zoomCamera(float value){ // derive fovY value float h = cam.getFrustumTop(); float w = cam.getFrustumRight(); float aspect = w / h; float near = cam.getFrustumNear(); float fovY = FastMath.atan(h / near) / (FastMath.DEG_TO_RAD * .5f); fovY += value * 0.1f; h = FastMath.tan( fovY * FastMath.DEG_TO_RAD * .5f) * near; w = h * aspect; cam.setFrustumTop(h); cam.setFrustumBottom(-h); cam.setFrustumLeft(-w); cam.setFrustumRight(w); }
Example #14
Source File: EmitterMeshFaceShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * This method fills the point with coordinates of randomly selected point on a random face. * The normal param is filled with selected face's normal. * @param store * the variable to store with coordinates of randomly selected selected point on a random face * @param normal * filled with selected face's normal */ @Override public void getRandomPointAndNormal(Vector3f store, Vector3f normal) { int meshIndex = FastMath.nextRandomInt(0, vertices.size() - 1); // the index of the first vertex of a face (must be dividable by 3) int faceIndex = FastMath.nextRandomInt(0, vertices.get(meshIndex).size() / 3 - 1); int vertIndex = faceIndex * 3; // put the point somewhere between the first and the second vertex of a face float moveFactor = FastMath.nextRandomFloat(); store.set(Vector3f.ZERO); store.addLocal(vertices.get(meshIndex).get(vertIndex)); store.addLocal((vertices.get(meshIndex).get(vertIndex + 1).x - vertices.get(meshIndex).get(vertIndex).x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).y - vertices.get(meshIndex).get(vertIndex).y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).z - vertices.get(meshIndex).get(vertIndex).z) * moveFactor); // move the result towards the last face vertex moveFactor = FastMath.nextRandomFloat(); store.addLocal((vertices.get(meshIndex).get(vertIndex + 2).x - store.x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).y - store.y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).z - store.z) * moveFactor); normal.set(normals.get(meshIndex).get(faceIndex)); }
Example #15
Source File: MaterialPreviewWidget.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private void initWidget() { SceneApplication.getApplication().addSceneListener(this); Sphere sphMesh = new Sphere(32, 32, 2.5f); sphMesh.setTextureMode(Sphere.TextureMode.Projected); sphMesh.updateGeometry(32, 32, 2.5f, false, false); TangentBinormalGenerator.generate(sphMesh); sphere = new Geometry("previewSphere", sphMesh); sphere.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.QUARTER_PI, Vector3f.UNIT_X)); Box boxMesh = new Box(new Vector3f(0, 0, 0), 1.75f, 1.75f, 1.75f); TangentBinormalGenerator.generate(boxMesh); box = new Geometry("previewBox", boxMesh); box.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.DEG_TO_RAD * 30, Vector3f.UNIT_X).multLocal(new Quaternion().fromAngleAxis(FastMath.QUARTER_PI, Vector3f.UNIT_Y))); Quad quadMesh = new Quad(4.5f, 4.5f); TangentBinormalGenerator.generate(quadMesh); quad = new Geometry("previewQuad", quadMesh); quad.setLocalTranslation(new Vector3f(-2.25f, -2.25f, 0)); currentGeom = sphere; sphereButton.setSelected(true); init=true; }
Example #16
Source File: TestGimpactShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private RigidBodyControl drop(Vector3f offset, String model, float scale, float mass) { scale *= scaleMod; Node n = (Node) assetManager.loadModel(model); n.setLocalTranslation(offset); n.rotate(0, 0, -FastMath.HALF_PI); Geometry tp = ((Geometry) n.getChild(0)); tp.scale(scale); Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); tp.setMaterial(mat); Mesh mesh = tp.getMesh(); GImpactCollisionShape shape = new GImpactCollisionShape(mesh); shape.setScale(new Vector3f(scale, scale, scale)); RigidBodyControl control = new RigidBodyControl(shape, mass); n.addControl(control); addObject(n); return control; }
Example #17
Source File: BIHTree.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private int sortTriangles(int l, int r, float split, int axis) { int pivot = l; int j = r; TempVars vars = TempVars.get(); Vector3f v1 = vars.vect1, v2 = vars.vect2, v3 = vars.vect3; while (pivot <= j) { getTriangle(pivot, v1, v2, v3); v1.addLocal(v2).addLocal(v3).multLocal(FastMath.ONE_THIRD); if (v1.get(axis) > split) { swapTriangles(pivot, j); --j; } else { ++pivot; } } vars.release(); pivot = (pivot == l && j < pivot) ? j : pivot; return pivot; }
Example #18
Source File: TerrainQuad.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
protected TerrainQuad(String name, int patchSize, int quadSize, Vector3f scale, float[] heightMap, int totalSize, Vector2f offset, float offsetAmount) { super(name); if (heightMap == null) heightMap = generateDefaultHeightMap(quadSize); if (!FastMath.isPowerOfTwo(quadSize - 1)) { throw new RuntimeException("size given: " + quadSize + " Terrain quad sizes may only be (2^N + 1)"); } if (FastMath.sqrt(heightMap.length) > quadSize) { Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Heightmap size is larger than the terrain size. Make sure your heightmap image is the same size as the terrain!"); } this.offset = offset; this.offsetAmount = offsetAmount; this.totalSize = totalSize; this.size = quadSize; this.patchSize = patchSize; this.stepScale = scale; split(patchSize, heightMap); }
Example #19
Source File: NewtonianParticleInfluencer.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void influenceParticle(Particle particle, EmitterShape emitterShape) { emitterShape.getRandomPointAndNormal(particle.position, particle.velocity); // influencing the particle's velocity if (surfaceTangentFactor == 0.0f) { particle.velocity.multLocal(normalVelocity); } else { // calculating surface tangent (velocity contains the 'normal' value) temp.set(particle.velocity.z * surfaceTangentFactor, particle.velocity.y * surfaceTangentFactor, -particle.velocity.x * surfaceTangentFactor); if (surfaceTangentRotation != 0.0f) {// rotating the tangent Matrix3f m = new Matrix3f(); m.fromAngleNormalAxis(FastMath.PI * surfaceTangentRotation, particle.velocity); temp = m.multLocal(temp); } // applying normal factor (this must be done first) particle.velocity.multLocal(normalVelocity); // adding tangent vector particle.velocity.addLocal(temp); } if (velocityVariation != 0.0f) { this.applyVelocityVariation(particle); } }
Example #20
Source File: HeightfieldCollisionShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
protected void createCollisionHeightfield(float[] heightmap, Vector3f worldScale) { this.scale = worldScale; this.heightScale = 1;//don't change away from 1, we use worldScale instead to scale this.heightfieldData = heightmap; float min = heightfieldData[0]; float max = heightfieldData[0]; // calculate min and max height for (int i = 0; i < heightfieldData.length; i++) { if (heightfieldData[i] < min) { min = heightfieldData[i]; } if (heightfieldData[i] > max) { max = heightfieldData[i]; } } // we need to center the terrain collision box at 0,0,0 for BulletPhysics. And to do that we need to set the // min and max height to be equal on either side of the y axis, otherwise it gets shifted and collision is incorrect. if (max < 0) { max = -min; } else { if (Math.abs(max) > Math.abs(min)) { min = -max; } else { max = -min; } } this.minHeight = min; this.maxHeight = max; this.upAxis = 1; this.flipQuadEdges = false; heightStickWidth = (int) FastMath.sqrt(heightfieldData.length); heightStickLength = heightStickWidth; createShape(); }
Example #21
Source File: PssmShadowUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Updates the frustum splits stores in <code>splits</code> using PSSM. */ public static void updateFrustumSplits(float[] splits, float near, float far, float lambda) { for (int i = 0; i < splits.length; i++) { float IDM = i / (float) splits.length; float log = near * FastMath.pow((far / near), IDM); float uniform = near + (far - near) * IDM; splits[i] = log * lambda + uniform * (1.0f - lambda); } // This is used to improve the correctness of the calculations. Our main near- and farplane // of the camera always stay the same, no matter what happens. splits[0] = near; splits[splits.length - 1] = far; }
Example #22
Source File: PhysicsTestHelper.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static float getY(float x, float z, float max) { float yMaxHeight = 8; float xv = FastMath.unInterpolateLinear(FastMath.abs(x - (max / 2)), 0, max) * FastMath.TWO_PI; float zv = FastMath.unInterpolateLinear(FastMath.abs(z - (max / 2)), 0, max) * FastMath.TWO_PI; float xComp = (FastMath.sin(xv) + 1) * 0.5f; float zComp = (FastMath.sin(zv) + 1) * 0.5f; return -yMaxHeight * xComp * zComp; }
Example #23
Source File: TestRenderToMemory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void simpleUpdate(float tpf){ Quaternion q = new Quaternion(); angle += tpf; angle %= FastMath.TWO_PI; q.fromAngles(angle, 0, angle); offBox.setLocalRotation(q); offBox.updateLogicalState(tpf); offBox.updateGeometricState(); }
Example #24
Source File: TestMovingParticle.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void simpleUpdate(float tpf) { angle += tpf; angle %= FastMath.TWO_PI; float x = FastMath.cos(angle) * 2; float y = FastMath.sin(angle) * 2; emit.setLocalTranslation(x, 0, y); }
Example #25
Source File: AreaUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static float calcScreenArea(BoundingSphere bound, float distance, float screenWidth) { // Where is the center point and a radius point that lies in a plan parallel to the view plane? // // Calc radius based on these two points and plug into circle area formula. // Vector2f centerSP = null; // Vector2f outerSP = null; // float radiusSq = centerSP.subtract(outerSP).lengthSquared(); float radius = (bound.getRadius() * screenWidth) / (distance * 2); return radius * radius * FastMath.PI; }
Example #26
Source File: TestLightRadius.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { Torus torus = new Torus(10, 6, 1, 3); // Torus torus = new Torus(50, 30, 1, 3); Geometry g = new Geometry("Torus Geom", torus); g.rotate(-FastMath.HALF_PI, 0, 0); g.center(); // g.move(0, 1, 0); Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat.setFloat("Shininess", 32f); mat.setBoolean("UseMaterialColors", true); mat.setColor("Ambient", ColorRGBA.Black); mat.setColor("Diffuse", ColorRGBA.White); mat.setColor("Specular", ColorRGBA.White); // mat.setBoolean("VertexLighting", true); // mat.setBoolean("LowQuality", true); g.setMaterial(mat); rootNode.attachChild(g); lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f)); lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m")); rootNode.attachChild(lightMdl); pl = new PointLight(); pl.setColor(ColorRGBA.Green); pl.setRadius(4f); rootNode.addLight(pl); DirectionalLight dl = new DirectionalLight(); dl.setColor(ColorRGBA.Red); dl.setDirection(new Vector3f(0, 1, 0)); rootNode.addLight(dl); }
Example #27
Source File: InputManager.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private float computeAnalogValue(long timeDelta) { if (safeMode || frameDelta == 0) { return 1f; } else { return FastMath.clamp((float) timeDelta / (float) frameDelta, 0, 1); } }
Example #28
Source File: BIHTriangle.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public BIHTriangle(Vector3f p1, Vector3f p2, Vector3f p3) { pointa.set(p1); pointb.set(p2); pointc.set(p3); center.set(pointa); center.addLocal(pointb).addLocal(pointc).multLocal(FastMath.ONE_THIRD); }
Example #29
Source File: TestMultiRenderTarget.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleUpdate(float tpf) { super.simpleUpdate(tpf);//To change body of generated methods, choose Tools | Templates. for (int i = 0; i < 3; i++){ PointLight pl = pls[i]; float angle = (float)Math.PI * (i + (timer.getTimeInSeconds() % 6)/3); // 3s for full loop pl.setPosition( new Vector3f(FastMath.cos(angle)*3f, 0, FastMath.sin(angle)*3f)); } }
Example #30
Source File: TestRenderToCubemap.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleUpdate(float tpf){ Quaternion q = new Quaternion(); angle += tpf; angle %= FastMath.TWO_PI; q.fromAngles(angle, 0, angle); offBox.setLocalRotation(q); offBox.updateLogicalState(tpf); offBox.updateGeometricState(); }