Java Code Examples for com.jme3.math.Vector3f#clone()
The following examples show how to use
com.jme3.math.Vector3f#clone() .
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: GuiGlobals.java From Lemur with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Deprecated public Vector3f getScreenCoordinates( Spatial relativeTo, Vector3f pos ) { ViewPort vp = getCollisionViewPort(relativeTo); if( vp == null ) { throw new RuntimeException("Could not find viewport for:" + relativeTo); } // Calculate the world position relative to the spatial pos = relativeTo.localToWorld(pos, null); Camera cam = vp.getCamera(); if( cam.isParallelProjection() ) { return pos.clone(); } return cam.getScreenCoordinates(pos); }
Example 2
Source File: BresenhamTerrainPicker.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * This method adds the found Collision to an existing collisionResult. * @param results The results to add this collision to * @param patch The TerrainPatch which collided * @param intersection The actual intersection position * @param hit The hit triangle * @param distance The distance at which the hit occurred * @return Whether the collision was accepted to the list or whether it has been deduplicated */ private boolean addCollision(CollisionResults results, TerrainPatch patch, Vector3f intersection, Triangle hit, float distance) { CollisionResult cr = new CollisionResult(intersection.clone(), distance); cr.setGeometry(patch); cr.setContactNormal(hit.getNormal()); cr.setTriangleIndex(hit.getIndex()); // this will probably always be 0 for (int i = 0; i < results.size(); i++) { CollisionResult compare = results.getCollision(i); if (compare.getDistance() == cr.getDistance() && compare.getGeometry() == cr.getGeometry() && compare.getContactPoint().equals(cr.getContactPoint()) && compare.getContactNormal().equals(cr.getContactNormal())) { return false; // Collision already available, deduplicate. } } results.addCollision(cr); return true; }
Example 3
Source File: ConstraintDefinitionSizeLike.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void bake(Transform ownerTransform, Transform targetTransform, float influence) { Vector3f ownerScale = ownerTransform.getScale(); Vector3f targetScale = targetTransform.getScale(); Vector3f offset = Vector3f.ZERO; if ((flag & LOCLIKE_OFFSET) != 0) {// we add the original scale to the // copied scale offset = ownerScale.clone(); } if ((flag & SIZELIKE_X) != 0) { ownerScale.x = targetScale.x * influence + (1.0f - influence) * ownerScale.x; } if ((flag & SIZELIKE_Y) != 0) { ownerScale.y = targetScale.y * influence + (1.0f - influence) * ownerScale.y; } if ((flag & SIZELIKE_Z) != 0) { ownerScale.z = targetScale.z * influence + (1.0f - influence) * ownerScale.z; } ownerScale.addLocal(offset); }
Example 4
Source File: AbstractCursorEvent.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Vector3f getRelativeViewCoordinates( Spatial relativeTo, Vector3f pos ) { // Calculate the world position relative to the spatial pos = relativeTo.localToWorld(pos, null); Camera cam = view.getCamera(); if( cam.isParallelProjection() ) { return pos.clone(); } return cam.getScreenCoordinates(pos); }
Example 5
Source File: BoxLayout.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void calculatePreferredSize( Vector3f size ) { // Calculate the size we'd like to be to let // all of the children have space Vector3f pref = new Vector3f(); preferredSizes.clear(); for( Node n : children ) { Vector3f v = n.getControl(GuiControl.class).getPreferredSize(); preferredSizes.add(v.clone()); // We do a little trickery here by adding the // axis direction to the returned preferred size. // That way we can just "max" the whole thing. switch( axis ) { case X: v.x += pref.x; break; case Y: v.y += pref.y; break; case Z: v.z += pref.z; break; } pref.maxLocal(v); } lastPreferredSize = pref.clone(); // The preferred size is the size... because layouts will always // be the decider in a component stack. They are always first // in the component chain for preferred size and last for reshaping. size.set(pref); }
Example 6
Source File: DynamicInsetsComponent.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void calculatePreferredSize( Vector3f size ) { // Keep track of the preferred size of the rest of // the stack up to this point. We don't add any insets // here. lastPreferredSize = size.clone(); }
Example 7
Source File: GuiControl.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void setSize( Vector3f size ) { if( size.x < 0 || size.y < 0 || size.z < 0 ) { throw new IllegalArgumentException("Size cannot be negative:" + size); } lastSize.set(size); // The components will take their parts out of size. // The caller may not be expecting their size to change... especially // since it might have been the getPreferredSize() of some other GUI element Vector3f stackSize = size.clone(); Vector3f offset = new Vector3f(); for( GuiComponent c : componentStack.getArray() ) { c.reshape(offset, stackSize); stackSize.x = Math.max(0, stackSize.x); stackSize.y = Math.max(0, stackSize.y); stackSize.z = Math.max(0, stackSize.z); } if( layout != null ) { layout.reshape(offset, stackSize); } if( listeners != null ) { // Call the listeners with the original size befoe // the components took a whack at it. for( GuiControlListener l : listeners.getArray() ) { l.reshape(this, offset, size); } } }
Example 8
Source File: CameraTweens.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
public MoveCamera( Camera target, Vector3f from, Vector3f to, double length ) { super(length); this.target = target; this.from = from.clone(); this.to = to.clone(); this.value = new Vector3f(from); }
Example 9
Source File: SpatialTweens.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
public MoveSpatial( Spatial target, Vector3f from, Vector3f to, double length ) { super(length); this.target = target; this.from = from.clone(); this.to = to.clone(); this.value = new Vector3f(from); }
Example 10
Source File: SpatialTweens.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
public ScaleSpatial( Spatial target, Vector3f from, Vector3f to, double length ) { super(length); this.target = target; this.from = from.clone(); this.to = to.clone(); this.value = from.clone(); }
Example 11
Source File: LevelTerrainTool.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void actionPrimary(Vector3f point, int textureIndex, AbstractSceneExplorerNode rootNode, DataObject dataObject) { if (radius == 0 || weight == 0) return; if (desiredHeight == null) desiredHeight = point.clone(); LevelTerrainToolAction action = new LevelTerrainToolAction(point, radius, weight, desiredHeight); action.doActionPerformed(rootNode, dataObject); }
Example 12
Source File: PaintTerrainToolAction.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public PaintTerrainToolAction(Vector3f markerLocation, float radius, float weight, int selectedTextureIndex) { this.worldLoc = markerLocation.clone(); this.radius = radius; this.weight = weight; this.selectedTextureIndex = selectedTextureIndex; name = "Paint terrain"; }
Example 13
Source File: LevelTerrainToolAction.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public LevelTerrainToolAction(Vector3f markerLocation, float radius, float height, Vector3f levelTerrainLocation) { this.worldLoc = markerLocation.clone(); this.radius = radius; this.height = height; this.levelTerrainLocation = levelTerrainLocation; name = "Level terrain"; }
Example 14
Source File: SmoothTerrainToolAction.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public SmoothTerrainToolAction(Vector3f markerLocation, float radius, float height) { this.worldLoc = markerLocation.clone(); this.radius = radius; this.height = height; name = "Smooth terrain"; }
Example 15
Source File: ShadowUtil.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Updates the points array to contain the frustum corners of the given * camera. The nearOverride and farOverride variables can be used * to override the camera's near/far values with own values. * * TODO: Reduce creation of new vectors * * @param viewCam * @param nearOverride * @param farOverride */ public static void updateFrustumPoints(Camera viewCam, float nearOverride, float farOverride, float scale, Vector3f[] points) { Vector3f pos = viewCam.getLocation(); Vector3f dir = viewCam.getDirection(); Vector3f up = viewCam.getUp(); float depthHeightRatio = viewCam.getFrustumTop() / viewCam.getFrustumNear(); float near = nearOverride; float far = farOverride; float ftop = viewCam.getFrustumTop(); float fright = viewCam.getFrustumRight(); float ratio = fright / ftop; float near_height; float near_width; float far_height; float far_width; if (viewCam.isParallelProjection()) { near_height = ftop; near_width = near_height * ratio; far_height = ftop; far_width = far_height * ratio; } else { near_height = depthHeightRatio * near; near_width = near_height * ratio; far_height = depthHeightRatio * far; far_width = far_height * ratio; } Vector3f right = dir.cross(up).normalizeLocal(); Vector3f temp = new Vector3f(); temp.set(dir).multLocal(far).addLocal(pos); Vector3f farCenter = temp.clone(); temp.set(dir).multLocal(near).addLocal(pos); Vector3f nearCenter = temp.clone(); Vector3f nearUp = temp.set(up).multLocal(near_height).clone(); Vector3f farUp = temp.set(up).multLocal(far_height).clone(); Vector3f nearRight = temp.set(right).multLocal(near_width).clone(); Vector3f farRight = temp.set(right).multLocal(far_width).clone(); points[0].set(nearCenter).subtractLocal(nearUp).subtractLocal(nearRight); points[1].set(nearCenter).addLocal(nearUp).subtractLocal(nearRight); points[2].set(nearCenter).addLocal(nearUp).addLocal(nearRight); points[3].set(nearCenter).subtractLocal(nearUp).addLocal(nearRight); points[4].set(farCenter).subtractLocal(farUp).subtractLocal(farRight); points[5].set(farCenter).addLocal(farUp).subtractLocal(farRight); points[6].set(farCenter).addLocal(farUp).addLocal(farRight); points[7].set(farCenter).subtractLocal(farUp).addLocal(farRight); if (scale != 1.0f) { // find center of frustum Vector3f center = new Vector3f(); for (int i = 0; i < 8; i++) { center.addLocal(points[i]); } center.divideLocal(8f); Vector3f cDir = new Vector3f(); for (int i = 0; i < 8; i++) { cDir.set(points[i]).subtractLocal(center); cDir.multLocal(scale - 1.0f); points[i].addLocal(cDir); } } }
Example 16
Source File: TangentBinormalGenerator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static TriangleData processTriangle(int[] index, Vector3f[] v, Vector2f[] t) { TempVars tmp = TempVars.get(); try { Vector3f edge1 = tmp.vect1; Vector3f edge2 = tmp.vect2; Vector2f edge1uv = tmp.vect2d; Vector2f edge2uv = tmp.vect2d2; Vector3f tangent = tmp.vect3; Vector3f binormal = tmp.vect4; Vector3f normal = tmp.vect5; t[1].subtract(t[0], edge1uv); t[2].subtract(t[0], edge2uv); float det = edge1uv.x * edge2uv.y - edge1uv.y * edge2uv.x; boolean normalize = false; if (Math.abs(det) < ZERO_TOLERANCE) { log.log(Level.WARNING, "Colinear uv coordinates for triangle " + "[{0}, {1}, {2}]; tex0 = [{3}, {4}], " + "tex1 = [{5}, {6}], tex2 = [{7}, {8}]", new Object[]{index[0], index[1], index[2], t[0].x, t[0].y, t[1].x, t[1].y, t[2].x, t[2].y}); det = 1; normalize = true; } v[1].subtract(v[0], edge1); v[2].subtract(v[0], edge2); tangent.set(edge1); tangent.normalizeLocal(); binormal.set(edge2); binormal.normalizeLocal(); if (Math.abs(Math.abs(tangent.dot(binormal)) - 1) < ZERO_TOLERANCE) { log.log(Level.WARNING, "Vertices are on the same line " + "for triangle [{0}, {1}, {2}].", new Object[]{index[0], index[1], index[2]}); } float factor = 1 / det; tangent.x = (edge2uv.y * edge1.x - edge1uv.y * edge2.x) * factor; tangent.y = (edge2uv.y * edge1.y - edge1uv.y * edge2.y) * factor; tangent.z = (edge2uv.y * edge1.z - edge1uv.y * edge2.z) * factor; if (normalize) { tangent.normalizeLocal(); } binormal.x = (edge1uv.x * edge2.x - edge2uv.x * edge1.x) * factor; binormal.y = (edge1uv.x * edge2.y - edge2uv.x * edge1.y) * factor; binormal.z = (edge1uv.x * edge2.z - edge2uv.x * edge1.z) * factor; if (normalize) { binormal.normalizeLocal(); } tangent.cross(binormal, normal); normal.normalizeLocal(); return new TriangleData( tangent.clone(), binormal.clone(), normal.clone()); } finally { tmp.release(); } }
Example 17
Source File: ShadowUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Updates the points array to contain the frustum corners of the given * camera. The nearOverride and farOverride variables can be used to * override the camera's near/far values with own values. * * TODO: Reduce creation of new vectors * * @param viewCam * @param nearOverride * @param farOverride */ public static void updateFrustumPoints(Camera viewCam, float nearOverride, float farOverride, float scale, Vector3f[] points) { Vector3f pos = viewCam.getLocation(); Vector3f dir = viewCam.getDirection(); Vector3f up = viewCam.getUp(); float depthHeightRatio = viewCam.getFrustumTop() / viewCam.getFrustumNear(); float near = nearOverride; float far = farOverride; float ftop = viewCam.getFrustumTop(); float fright = viewCam.getFrustumRight(); float ratio = fright / ftop; float near_height; float near_width; float far_height; float far_width; if (viewCam.isParallelProjection()) { near_height = ftop; near_width = near_height * ratio; far_height = ftop; far_width = far_height * ratio; } else { near_height = depthHeightRatio * near; near_width = near_height * ratio; far_height = depthHeightRatio * far; far_width = far_height * ratio; } Vector3f right = dir.cross(up).normalizeLocal(); Vector3f temp = new Vector3f(); temp.set(dir).multLocal(far).addLocal(pos); Vector3f farCenter = temp.clone(); temp.set(dir).multLocal(near).addLocal(pos); Vector3f nearCenter = temp.clone(); Vector3f nearUp = temp.set(up).multLocal(near_height).clone(); Vector3f farUp = temp.set(up).multLocal(far_height).clone(); Vector3f nearRight = temp.set(right).multLocal(near_width).clone(); Vector3f farRight = temp.set(right).multLocal(far_width).clone(); points[0].set(nearCenter).subtractLocal(nearUp).subtractLocal(nearRight); points[1].set(nearCenter).addLocal(nearUp).subtractLocal(nearRight); points[2].set(nearCenter).addLocal(nearUp).addLocal(nearRight); points[3].set(nearCenter).subtractLocal(nearUp).addLocal(nearRight); points[4].set(farCenter).subtractLocal(farUp).subtractLocal(farRight); points[5].set(farCenter).addLocal(farUp).subtractLocal(farRight); points[6].set(farCenter).addLocal(farUp).addLocal(farRight); points[7].set(farCenter).subtractLocal(farUp).addLocal(farRight); if (scale != 1.0f) { // find center of frustum Vector3f center = new Vector3f(); for (int i = 0; i < 8; i++) { center.addLocal(points[i]); } center.divideLocal(8f); Vector3f cDir = new Vector3f(); for (int i = 0; i < 8; i++) { cDir.set(points[i]).subtractLocal(center); cDir.multLocal(scale - 1.0f); points[i].addLocal(cDir); } } }
Example 18
Source File: RaiseTerrainToolAction.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public RaiseTerrainToolAction(Vector3f markerLocation, float radius, float height) { this.worldLoc = markerLocation.clone(); this.radius = radius; this.height = height; name = "Raise terrain"; }
Example 19
Source File: SpringGridLayout.java From Lemur with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void reshape(Vector3f pos, Vector3f size) { // This is somewhat trickier because placement requires // knowing all of the rows/cols prior and we don't really // process them in order. Ah... can just precalculate // the sizes and positions, I guess. // Make sure the preferred size book-keeping is up to date. calculatePreferredSize(new Vector3f()); // We could keep these arrays around but I think the GC churn // pales in comparison to the distribute calls if reshape is called a lot. float[] rowSizes = new float[rowCount]; distribute(rowSizes, rowPrefs, getMajor(size), getMajor(lastPreferredSize), mainFill, mainAxis); float[] colSizes = new float[columnCount]; distribute(colSizes, colPrefs, getMinor(size), getMinor(lastPreferredSize), minorFill, minorAxis); float[] rowOffsets = new float[rowCount]; float f = 0; for( int i = 0; i < rowOffsets.length; i++ ) { rowOffsets[i] = f; f += rowSizes[i]; } float[] colOffsets = new float[columnCount]; f = 0; for( int i = 0; i < colOffsets.length; i++ ) { colOffsets[i] = f; f += colSizes[i]; } // Now we can process the actual children for( Map<Integer, Entry> r : children.values() ) { for( Entry e : r.values() ) { Vector3f offset = new Vector3f(); addMajor(offset, rowOffsets[e.row]); addMinor(offset, colOffsets[e.col]); offset.y *= -1; e.setTranslation(pos.add(offset)); Vector3f childSize = size.clone(); setMajor(childSize, rowSizes[e.row]); setMinor(childSize, colSizes[e.col]); e.setSize(childSize); } } }
Example 20
Source File: ToneMapFilter.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Creates a tone-mapping filter with the specified white-point. * * @param whitePoint The intensity of the brightest part of the scene. */ public ToneMapFilter(Vector3f whitePoint) { this(); this.whitePoint = whitePoint.clone(); }