Java Code Examples for com.jme3.math.Vector3f#getY()
The following examples show how to use
com.jme3.math.Vector3f#getY() .
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: FloatToFixed.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private static void convertNormals(FloatBuffer input, ByteBuffer output){ if (output.capacity() < input.capacity()) throw new RuntimeException("Output must be at least as large as input!"); input.clear(); output.clear(); Vector3f temp = new Vector3f(); int vertexCount = input.capacity() / 3; for (int i = 0; i < vertexCount; i++){ BufferUtils.populateFromBuffer(temp, input, i); // offset and scale vector into -128 ... 127 temp.multLocal(127).addLocal(0.5f, 0.5f, 0.5f); // quantize byte v1 = (byte) temp.getX(); byte v2 = (byte) temp.getY(); byte v3 = (byte) temp.getZ(); // store output.put(v1).put(v2).put(v3); } }
Example 2
Source File: SpawnToolControl.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
protected BoundingVolume addPadding(@NotNull BoundingVolume boundingVolume, @NotNull Vector3f padding) { if (boundingVolume instanceof BoundingBox) { var box = (BoundingBox) boundingVolume; var xExtent = box.getXExtent() + padding.getX(); var yExtent = box.getYExtent() + padding.getY(); var zExtent = box.getZExtent() + padding.getZ(); return new BoundingBox(box.getCenter(), xExtent, yExtent, zExtent); } return boundingVolume; }
Example 3
Source File: EditorUtil.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Check visibility the position on the screen. * * @param position the position for checking. * @param camera the camera of the screen. * @return true of we can see the position on the screen. */ @FromAnyThread public static boolean isVisibleOnScreen(@NotNull Vector3f position, @NotNull Camera camera) { var maxHeight = camera.getHeight(); var maxWidth = camera.getWidth(); var isBottom = position.getY() < 0; var isTop = position.getY() > maxHeight; var isLeft = position.getX() < 0; var isRight = position.getX() > maxWidth; return !isBottom && !isLeft && !isTop && !isRight && position.getZ() < 1F; }
Example 4
Source File: CompactVector3Array.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void serialize(int i, Vector3f store) { int j = i*getTupleSize(); array[j] = store.getX(); array[j+1] = store.getY(); array[j+2] = store.getZ(); }
Example 5
Source File: Arrow.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Creates an arrow mesh with the given extent. * The arrow will start at the origin (0,0,0) and finish * at the given extent. * * @param extent Extent of the arrow from origin */ public Arrow(Vector3f extent) { float len = extent.length(); Vector3f dir = extent.normalize(); tempQuat.lookAt(dir, Vector3f.UNIT_Y); tempQuat.normalizeLocal(); float[] newPositions = new float[positions.length]; for (int i = 0; i < positions.length; i += 3) { Vector3f vec = tempVec.set(positions[i], positions[i + 1], positions[i + 2]); vec.multLocal(len); tempQuat.mult(vec, vec); newPositions[i] = vec.getX(); newPositions[i + 1] = vec.getY(); newPositions[i + 2] = vec.getZ(); } setBuffer(Type.Position, 3, newPositions); setBuffer(Type.Index, 2, new short[]{ 0, 1, 1, 2, 1, 3, 1, 4, 1, 5,}); setMode(Mode.Lines); updateBound(); updateCounts(); }
Example 6
Source File: Curve.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void createLinearMesh() { float[] array = new float[spline.getControlPoints().size() * 3]; short[] indices = new short[(spline.getControlPoints().size() - 1) * 2]; int i = 0; int cpt = 0; int k; int j = 0; for (Iterator<Vector3f> it = spline.getControlPoints().iterator(); it.hasNext();) { Vector3f vector3f = it.next(); array[i] = vector3f.getX(); i++; array[i] = vector3f.getY(); i++; array[i] = vector3f.getZ(); i++; if (it.hasNext()) { k = j; indices[cpt] = (short) k; cpt++; k++; indices[cpt] = (short) k; cpt++; j++; } } this.setMode(Mesh.Mode.Lines); this.setBuffer(VertexBuffer.Type.Position, 3, array); this.setBuffer(VertexBuffer.Type.Index, 2, indices); this.updateBound(); this.updateCounts(); }
Example 7
Source File: PhysicsHoverControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void prePhysicsTick(PhysicsSpace space, float f) { Vector3f angVel = getAngularVelocity(); float rotationVelocity = angVel.getY(); Vector3f dir = getForwardVector(tempVect2).multLocal(1, 0, 1).normalizeLocal(); getLinearVelocity(tempVect3); Vector3f linearVelocity = tempVect3.multLocal(1, 0, 1); if (steeringValue != 0) { if (rotationVelocity < 1 && rotationVelocity > -1) { applyTorque(tempVect1.set(0, steeringValue, 0)); } } else { // counter the steering value! if (rotationVelocity > 0.2f) { applyTorque(tempVect1.set(0, -mass * 20, 0)); } else if (rotationVelocity < -0.2f) { applyTorque(tempVect1.set(0, mass * 20, 0)); } } if (accelerationValue > 0) { // counter force that will adjust velocity // if we are not going where we want to go. // this will prevent "drifting" and thus improve control // of the vehicle float d = dir.dot(linearVelocity.normalize()); Vector3f counter = dir.project(linearVelocity).normalizeLocal().negateLocal().multLocal(1 - d); applyForce(counter.multLocal(mass * 10), Vector3f.ZERO); if (linearVelocity.length() < 30) { applyForce(dir.multLocal(accelerationValue), Vector3f.ZERO); } } else { // counter the acceleration value if (linearVelocity.length() > FastMath.ZERO_TOLERANCE) { linearVelocity.normalizeLocal().negateLocal(); applyForce(linearVelocity.mult(mass * 10), Vector3f.ZERO); } } }
Example 8
Source File: CompactVector3Array.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override protected void serialize(int i, Vector3f store) { int j = i*getTupleSize(); array[j] = store.getX(); array[j+1] = store.getY(); array[j+2] = store.getZ(); }
Example 9
Source File: Arrow.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Creates an arrow mesh with the given extent. * The arrow will start at the origin (0,0,0) and finish * at the given extent. * * @param extent Extent of the arrow from origin */ public Arrow(Vector3f extent) { float len = extent.length(); Vector3f dir = extent.normalize(); tempQuat.lookAt(dir, Vector3f.UNIT_Y); tempQuat.normalizeLocal(); float[] newPositions = new float[positions.length]; for (int i = 0; i < positions.length; i += 3) { Vector3f vec = tempVec.set(positions[i], positions[i + 1], positions[i + 2]); vec.multLocal(len); tempQuat.mult(vec, vec); newPositions[i] = vec.getX(); newPositions[i + 1] = vec.getY(); newPositions[i + 2] = vec.getZ(); } setBuffer(Type.Position, 3, newPositions); setBuffer(Type.Index, 2, new short[]{ 0, 1, 1, 2, 1, 3, 1, 4, 1, 5,}); setMode(Mode.Lines); updateBound(); updateCounts(); }
Example 10
Source File: Curve.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private void createLinearMesh() { float[] array = new float[spline.getControlPoints().size() * 3]; short[] indices = new short[(spline.getControlPoints().size() - 1) * 2]; int i = 0; int cpt = 0; int k = 0; int j = 0; for (Iterator<Vector3f> it = spline.getControlPoints().iterator(); it.hasNext();) { Vector3f vector3f = it.next(); array[i] = vector3f.getX(); i++; array[i] = vector3f.getY(); i++; array[i] = vector3f.getZ(); i++; if (it.hasNext()) { k = j; indices[cpt] = (short) k; cpt++; k++; indices[cpt] = (short) k; cpt++; j++; } } this.setMode(Mesh.Mode.Lines); this.setBuffer(VertexBuffer.Type.Position, 3, array); this.setBuffer(VertexBuffer.Type.Index, 2, indices); this.updateBound(); this.updateCounts(); }
Example 11
Source File: RoughTerrainToolControl.java From jmonkeybuilder with Apache License 2.0 | 4 votes |
/** * Modify height of terrain points. * * @param contactPoint the contact point. */ @JmeThread private void modifyHeight(@NotNull final Vector3f contactPoint) { final LocalObjects local = getLocalObjects(); final Spatial paintedModel = notNull(getPaintedModel()); final Geometry brush = getBrush(); final float brushSize = getBrushSize(); final int twoBrushSize = (int) (brushSize * 2); final Basis fractalFilter = createFractalGenerator(); final List<Vector2f> locs = new ArrayList<>(); final List<Float> heights = new ArrayList<>(); for (final Terrain terrain : getTerrains()) { final Node terrainNode = (Node) terrain; locs.clear(); heights.clear(); final Vector3f worldTranslation = terrainNode.getWorldTranslation(); final Vector3f localScale = terrainNode.getLocalScale(); final Vector3f localPoint = contactPoint.subtract(worldTranslation, local.nextVector()); final Vector2f terrainLoc = local.nextVector2f(); final Vector2f effectPoint = local.nextVector2f(); final FloatBuffer buffer = fractalFilter.getBuffer(terrainLoc.getX(), terrainLoc.getY(), 0, twoBrushSize); final int radiusStepsX = (int) (brushSize / localScale.getX()); final int radiusStepsZ = (int) (brushSize / localScale.getY()); final float xStepAmount = localScale.getX(); final float zStepAmount = localScale.getZ(); for (int z = -radiusStepsZ, yfb = 0; z < radiusStepsZ; z++, yfb++) { for (int x = -radiusStepsX, xfb = 0; x < radiusStepsX; x++, xfb++) { final float locX = localPoint.getX() + (x * xStepAmount); final float locZ = localPoint.getZ() + (z * zStepAmount); effectPoint.set(locX - localPoint.getX(), locZ - localPoint.getZ()); if (!isContains(brush, effectPoint.getX(), effectPoint.getX())) { continue; } final float height = buffer.get(yfb * twoBrushSize + xfb); terrainLoc.set(locX, locZ); final float heightmapHeight = terrain.getHeightmapHeight(terrainLoc); if (Float.isNaN(heightmapHeight)) { continue; } final float currentHeight = heightmapHeight * localScale.getY(); // see if it is in the radius of the tool final float newHeight = calculateHeight(brushSize, height, effectPoint); locs.add(terrainLoc.clone()); heights.add(currentHeight + newHeight); } } locs.forEach(location -> change(terrain, location)); // do the actual height adjustment terrain.setHeight(locs, heights); } // or else we won't collide with it where we just edited paintedModel.updateModelBound(); }
Example 12
Source File: RaiseLowerTerrainToolControl.java From jmonkeybuilder with Apache License 2.0 | 4 votes |
/** * Modify height of terrain points. * * @param input the type of input. * @param contactPoint the contact point. */ @JmeThread private void modifyHeight(@NotNull final PaintingInput input, @NotNull final Vector3f contactPoint) { final LocalObjects local = getLocalObjects(); final Spatial paintedModel = notNull(getPaintedModel()); final Geometry brush = getBrush(); final float brushSize = getBrushSize(); final float brushPower = input == PaintingInput.MOUSE_PRIMARY ? getBrushPower() : getBrushPower() * -1F; final List<Vector2f> locs = new ArrayList<>(); final List<Float> heights = new ArrayList<>(); for (final Terrain terrain : getTerrains()) { final Node terrainNode = (Node) terrain; locs.clear(); heights.clear(); final Vector3f worldTranslation = terrainNode.getWorldTranslation(); final Vector3f localScale = terrainNode.getLocalScale(); final Vector3f localPoint = contactPoint.subtract(worldTranslation, local.nextVector()); final Vector2f terrainLoc = local.nextVector2f(); final Vector2f effectPoint = local.nextVector2f(); final int radiusStepsX = (int) (brushSize / localScale.getX()); final int radiusStepsZ = (int) (brushSize / localScale.getY()); final float xStepAmount = localScale.getX(); final float zStepAmount = localScale.getZ(); for (int z = -radiusStepsZ; z < radiusStepsZ; z++) { for (int x = -radiusStepsX; x < radiusStepsX; x++) { float locX = localPoint.getX() + (x * xStepAmount); float locZ = localPoint.getZ() + (z * zStepAmount); effectPoint.set(locX - localPoint.getX(), locZ - localPoint.getZ()); if (!isContains(brush, effectPoint.getX(), effectPoint.getY())) { continue; } terrainLoc.set(locX, locZ); final float heightmapHeight = terrain.getHeightmapHeight(terrainLoc); if (Float.isNaN(heightmapHeight)) { continue; } final float currentHeight = heightmapHeight * localScale.getY(); // adjust height based on radius of the tool final float newHeight = calculateHeight(brushSize, brushPower, effectPoint.getX(), effectPoint.getY()); // increase the height locs.add(terrainLoc.clone()); heights.add(currentHeight + newHeight); } } locs.forEach(location -> change(terrain, location)); // do the actual height adjustment terrain.setHeight(locs, heights); } // or else we won't collide with it where we just edited paintedModel.updateModelBound(); }
Example 13
Source File: PhysicsHoverControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void prePhysicsTick(PhysicsSpace space, float f) { Vector3f angVel = getAngularVelocity(); float rotationVelocity = angVel.getY(); Vector3f dir = getForwardVector(tempVect2).multLocal(1, 0, 1).normalizeLocal(); getLinearVelocity(tempVect3); Vector3f linearVelocity = tempVect3.multLocal(1, 0, 1); float groundSpeed = linearVelocity.length(); if (steeringValue != 0) { if (rotationVelocity < 1 && rotationVelocity > -1) { applyTorque(tempVect1.set(0, steeringValue, 0)); } } else { // counter the steering value! if (rotationVelocity > 0.2f) { applyTorque(tempVect1.set(0, -mass * 20, 0)); } else if (rotationVelocity < -0.2f) { applyTorque(tempVect1.set(0, mass * 20, 0)); } } if (accelerationValue > 0) { // counter force that will adjust velocity // if we are not going where we want to go. // this will prevent "drifting" and thus improve control // of the vehicle if (groundSpeed > FastMath.ZERO_TOLERANCE) { float d = dir.dot(linearVelocity.normalize()); Vector3f counter = dir.project(linearVelocity).normalizeLocal().negateLocal().multLocal(1 - d); applyForce(counter.multLocal(mass * 10), Vector3f.ZERO); } if (linearVelocity.length() < 30) { applyForce(dir.multLocal(accelerationValue), Vector3f.ZERO); } } else { // counter the acceleration value if (groundSpeed > FastMath.ZERO_TOLERANCE) { linearVelocity.normalizeLocal().negateLocal(); applyForce(linearVelocity.mult(mass * 10), Vector3f.ZERO); } } }
Example 14
Source File: AbstractStrengthSteeringBehavior.java From MonkeyBrains with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * If you call this function you will be able to modify the raw steering * force on the specific axis (x, y, z). * * @param x X axis multiplier * @param y Y axis multiplier * @param z Z axis multiplier * * @throws NegativeValueException If any axis multiplier is lower than 0 */ public void setupStrengthControl(Vector3f vector) { validateScalar(vector.getX()); validateScalar(vector.getY()); validateScalar(vector.getZ()); x = vector.getX(); y = vector.getY(); z = vector.getZ(); type = SteerStrengthType.AXIS; }