Java Code Examples for com.jme3.math.Vector3f#getX()
The following examples show how to use
com.jme3.math.Vector3f#getX() .
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: PaintTerrainToolControl.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@JmeThread private @NotNull Vector2f getPointPercentagePosition(@NotNull final Terrain terrain, @NotNull final Vector3f localPoint, @NotNull final Vector3f localScale, @NotNull final Vector2f result) { result.set(localPoint.x, -localPoint.z); float scale = localScale.getX(); // already centered on Terrain's node origin (0,0) float scaledSize = terrain.getTerrainSize() * scale; result.addLocal(scaledSize / 2, scaledSize / 2); // shift the bottom left corner up to 0,0 result.divideLocal(scaledSize); // get the location as a percentage return result; }
Example 2
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 3
Source File: PaintTerrainToolControl.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Paint texture. * * @param input the editing input. * @param contactPoint the contact point. */ @JmeThread private void paintTexture(@NotNull final PaintingInput input, @NotNull final Vector3f contactPoint) { final Texture alphaTexture = getAlphaTexture(); if (alphaTexture == null) { return; } final LocalObjects local = getLocalObjects(); final Spatial terrainNode = notNull(getPaintedModel()); final Terrain terrain = (Terrain) terrainNode; final Image image = alphaTexture.getImage(); final Vector3f worldTranslation = terrainNode.getWorldTranslation(); final Vector3f localPoint = contactPoint.subtract(worldTranslation, local.nextVector()); final Vector3f localScale = terrainNode.getLocalScale(); final Vector2f uv = getPointPercentagePosition(terrain, localPoint, localScale, local.nextVector2f()); final Vector2f temp = local.nextVector2f(); final ColorRGBA color = local.nextColor(); final int layer = getLayer(); // get the radius of the brush in pixel-percent float brushSize = getBrushSize() / (terrain.getTerrainSize() * localScale.getX()); float brushPower = getBrushPower(); if (input == PaintingInput.MOUSE_SECONDARY) { brushPower *= -1; } // selectedTextureIndex/4 is an int floor, do not simplify the equation final ObjectFloatObjectConsumer<ColorRGBA, Boolean> colorFunction = COLOR_FUNCTIONS[layer - ((layer / 4) * 4)]; doPaintAction(colorFunction, image, uv, temp, color, brushSize, false, brushPower); image.setUpdateNeeded(); }
Example 4
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 5
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 6
Source File: MapModel3D.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Converts a world position into a Mercator position. * * @param posVec <code>Vector</code> containing the world unit * coordinates that are to be converted into * longitude / latitude coordinates. * @return The resulting <code>Position</code> in degrees of * latitude and longitude. * @since 1.0 */ public Position toPosition(Vector3f posVec) { double lat, lon; Position pos = null; try { Vector3f worldCentre = toWorldUnit(new Position(0, 0)); // Get the difference between position and the centre double xDistance = difference(xCentre, posVec.getX()); double yDistance = difference(worldCentre.getZ(), posVec.getZ()); double lonDistanceInDegrees = (xDistance * minutesPerWorldUnit) / 60; double mp = (yDistance * minutesPerWorldUnit); // If we are zoomed in past a certain point, then use linear search. // Otherwise use binary search if (getMinutesPerWu() < 0.05) { lat = findLat(mp, getCentre().getLatitude()); if (lat == -1000) { System.out.println("lat: " + lat); } } else { lat = findLat(mp, 0.0, 85.0); } lon = (posVec.getX() < xCentre ? centre.getLongitude() - lonDistanceInDegrees : centre.getLongitude() + lonDistanceInDegrees); if (posVec.getZ() > worldCentre.getZ()) { lat = -1 * lat; } if (lat == -1000 || lon == -1000) { return pos; } pos = new Position(lat, lon); } catch (InvalidPositionException ipe) { ipe.printStackTrace(); } return pos; }
Example 7
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 8
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 9
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 10
Source File: MapModel3D.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Converts a world position into a Mercator position. * * @param p <code>Vector</code> containing the world unit * coordinates that are to be converted into * longitude / latitude coordinates. * @return The resulting <code>Position</code> in degrees of * latitude and longitude. * @since 1.0 */ public Position toPosition(Vector3f posVec) { double lat, lon; Position pos = null; try { Vector3f worldCentre = toWorldUnit(new Position(0, 0)); // Get the difference between position and the centre double xDistance = difference(xCentre, posVec.getX()); double yDistance = difference(worldCentre.getZ(), posVec.getZ()); double lonDistanceInDegrees = (xDistance * minutesPerWorldUnit) / 60; double mp = (yDistance * minutesPerWorldUnit); // If we are zoomed in past a certain point, then use linear search. // Otherwise use binary search if (getMinutesPerWu() < 0.05) { lat = findLat(mp, getCentre().getLatitude()); if (lat == -1000) { System.out.println("lat: " + lat); } } else { lat = findLat(mp, 0.0, 85.0); } lon = (posVec.getX() < xCentre ? centre.getLongitude() - lonDistanceInDegrees : centre.getLongitude() + lonDistanceInDegrees); if (posVec.getZ() > worldCentre.getZ()) { lat = -1 * lat; } if (lat == -1000 || lon == -1000) { return pos; } pos = new Position(lat, lon); } catch (InvalidPositionException ipe) { ipe.printStackTrace(); } return pos; }
Example 11
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 12
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 13
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 14
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 15
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 16
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; }