static Vector2f[] toVector2(double[] data) { Vector2f[] vectors = new Vector2f[data.length / 2]; for (int i = 0; i < vectors.length; i++) { float x = (float) data[i * 2]; float y = (float) data[i * 2 + 1]; vectors[i] = new Vector2f(x, y); } return vectors; }
/** * compute the index of the waypoint and the interpolation value according to a distance * returns a vector 2 containing the index in the x field and the interpolation value in the y field * @param distance the distance traveled on this path * @return the waypoint index and the interpolation value in a vector2 */ public Vector2f getWayPointIndexForDistance(float distance, Vector2f store) { float sum = 0; if(spline.getTotalLength() == 0){ store.set(0, 0); return store; } distance = distance % spline.getTotalLength(); int i = 0; for (Float len : spline.getSegmentsLength()) { if (sum + len >= distance) { return new Vector2f((float) i, (distance - sum) / len); } sum += len; i++; } store.set((float) spline.getControlPoints().size() - 1, 1.0f); return store; }
@Override public Face clone() { Face result = new Face(); result.indexes = indexes.clone(); result.smooth = smooth; result.materialNumber = materialNumber; if (faceUVCoords != null) { result.faceUVCoords = new HashMap<String, List<Vector2f>>(faceUVCoords.size()); for (Entry<String, List<Vector2f>> entry : faceUVCoords.entrySet()) { List<Vector2f> uvs = new ArrayList<Vector2f>(entry.getValue().size()); for (Vector2f v : entry.getValue()) { uvs.add(v.clone()); } result.faceUVCoords.put(entry.getKey(), uvs); } } if (vertexColors != null) { result.vertexColors = new ArrayList<byte[]>(vertexColors.size()); for (byte[] colors : vertexColors) { result.vertexColors.add(colors.clone()); } } result.temporalMesh = temporalMesh; return result; }
protected Vector2f readVector2(){ Vector2f v = new Vector2f(); String line = scan.nextLine().trim(); String[] split = line.split("\\s+"); v.setX( Float.parseFloat(split[0].trim()) ); v.setY( Float.parseFloat(split[1].trim()) ); // v.setX(scan.nextFloat()); // if (scan.hasNextFloat()){ // v.setY(scan.nextFloat()); // if (scan.hasNextFloat()){ // scan.nextFloat(); // ignore // } // } return v; }
Material mat = new Material(manager, "Common/MatDefs/Hdr/LogLum.j3md"); Vector2f blockSize = new Vector2f(1f / bufW, 1f / bufH); Vector2f pixelSize = new Vector2f(1f / srcW, 1f / srcH); Vector2f blocks = new Vector2f(); float numPixels = Float.POSITIVE_INFINITY; if (iters != -1){ do { pixelSize.multLocal(2); blocks.set(blockSize.x / pixelSize.x, blockSize.y / pixelSize.y); numPixels = blocks.x * blocks.y; } while (numPixels > iters); }else{ blocks.set(blockSize.x / pixelSize.x, blockSize.y / pixelSize.y); numPixels = blocks.x * blocks.y;
public Vector2f getUV(int x, int y, Vector2f store, Vector2f offset, float offsetAmount, int totalSize) { float offsetX = offset.x + (offsetAmount * 1.0f); float offsetY = -offset.y + (offsetAmount * 1.0f);//note the -, we flip the tex coords store.set((((float) x) + offsetX) / (float) (totalSize - 1), // calculates percentage of texture here (((float) y) + offsetY) / (float) (totalSize - 1)); return store; }
private static void convertTexCoords2D(FloatBuffer input, Buffer output){ if (output.capacity() < input.capacity()) throw new RuntimeException("Output must be at least as large as input!"); input.clear(); output.clear(); Vector2f temp = new Vector2f(); int vertexCount = input.capacity() / 2; ShortBuffer sb = null; IntBuffer ib = null; if (output instanceof ShortBuffer) sb = (ShortBuffer) output; else if (output instanceof IntBuffer) ib = (IntBuffer) output; else throw new UnsupportedOperationException(); for (int i = 0; i < vertexCount; i++){ BufferUtils.populateFromBuffer(temp, input, i); if (sb != null){ sb.put( (short) (temp.getX()*Short.MAX_VALUE) ); sb.put( (short) (temp.getY()*Short.MAX_VALUE) ); }else{ int v1 = (int) (temp.getX() * ((float)(1 << 16))); int v2 = (int) (temp.getY() * ((float)(1 << 16))); ib.put(v1).put(v2); } } }
return -1; if (!uvs.get(i).equals(entry.getValue())) { return -1;
@Override public Vector2f getAxisDeltaSinceLastCall(int controllerIndex, VRInputType forAxis) { int axisIndex = forAxis.getValue(); temp2Axis.set(lastCallAxis[axisIndex]); lastCallAxis[axisIndex].set(getAxis(controllerIndex, forAxis)); if( (temp2Axis.x != 0f || temp2Axis.y != 0f) && (lastCallAxis[axisIndex].x != 0f || lastCallAxis[axisIndex].y != 0f) ) { temp2Axis.subtractLocal(lastCallAxis[axisIndex]); } else { // move made from rest, don't count as a delta move temp2Axis.x = 0f; temp2Axis.y = 0f; } return temp2Axis; }
public void update(float tpf) { synchronized (MovieMaterial.this) { if (latestFrame != null && latestFrame != jmeFrame) { if (!aspectValues.equals(material.getParam("AspectValues").getValue())) { material.setVector2("AspectValues", aspectValues.clone()); } if (!validRange.equals(material.getParam("ValidRange").getValue())) { material.setVector2("ValidRange", validRange.clone()); } if (noFrame) { noFrame = false; material.setBoolean("NoFrame", noFrame); } updateTexture(textureLuma, latestFrame.getBufferForPlane(TgqFrame.YCBCR_PLANE_LUMA), latestFrame.getLinesize(TgqFrame.YCBCR_PLANE_LUMA)); updateTexture(textureCr, latestFrame.getBufferForPlane(TgqFrame.YCBCR_PLANE_CR), latestFrame.getLinesize(TgqFrame.YCBCR_PLANE_CR)); updateTexture(textureCb, latestFrame.getBufferForPlane(TgqFrame.YCBCR_PLANE_CB), latestFrame.getLinesize(TgqFrame.YCBCR_PLANE_CB)); jmeFrame = latestFrame; } } }
/** * <code>subtract</code> subtracts the values of a given vector from those * of this vector creating a new vector object. If the provided vector is * null, an exception is thrown. * * @param vec * the vector to subtract from this vector. * @return the result vector. */ public Vector2f subtract(Vector2f vec) { return subtract(vec, null); }
/** * Creates a 3D draggable that will move the specified spatial relative to * its current translation in a plane relative to the current viewport camera. */ public DefaultDraggable( ViewPort view, Spatial spatial, Vector2f start ) { Camera cam = view.getCamera(); Vector3f origin = spatial.getWorldTranslation(); Vector3f screenPos = cam.getScreenCoordinates(origin); Vector2f xScreen = new Vector2f(screenPos.x + 1, screenPos.y); Vector2f yScreen = new Vector2f(screenPos.x, screenPos.y + 1); // Find the world location for one pixel right and one pixel up // in the plane of our object. Vector3f xWorld = cam.getWorldCoordinates(xScreen, screenPos.z); Vector3f yWorld = cam.getWorldCoordinates(yScreen, screenPos.z); this.start = start.clone(); this.spatial = spatial; this.origin = origin.clone(); this.xAxis = xWorld.subtractLocal(origin); this.yAxis = yWorld.subtractLocal(origin); this.currentLocation = start.clone(); }
float x11 = source[0].getX() * sourceSize[0]; float x12 = source[0].getY() * sourceSize[1]; float x21 = source[1].getX() * sourceSize[0]; float x22 = source[1].getY() * sourceSize[1]; float x31 = source[2].getX() * sourceSize[0]; float x32 = source[2].getY() * sourceSize[1]; float y11 = dest[0].getX() * targetSize[0]; float y12 = dest[0].getY() * targetSize[1]; float y21 = dest[1].getX() * targetSize[0]; float y22 = dest[1].getY() * targetSize[1]; float y31 = dest[2].getX() * targetSize[0]; float y32 = dest[2].getY() * targetSize[1];
/** * Set the distance from the eye where the shadows will be rendered default * value is dynamically computed to the shadow casters/receivers union bound * zFar, capped to view frustum far value. * * @param zFar the zFar values that override the computed one */ public void setShadowZExtend(float zFar) { if (fadeInfo != null) { fadeInfo.set(zFar - fadeLength, 1f / fadeLength); } this.zFarOverride = zFar; }