private void doCopyBuffer(FloatBuffer inBuf, int offset, FloatBuffer outBuf, int componentSize) { TempVars vars = TempVars.get(); Vector3f pos = vars.vect1; // offset is given in element units // convert to be in component units offset *= componentSize; for (int i = 0; i < inBuf.limit() / componentSize; i++) { pos.x = inBuf.get(i * componentSize); pos.y = inBuf.get(i * componentSize + 1); pos.z = inBuf.get(i * componentSize + 2); outBuf.put(offset + i * componentSize, pos.x); outBuf.put(offset + i * componentSize + 1, pos.y); outBuf.put(offset + i * componentSize + 2, pos.z); } vars.release(); }
/** * Compute the skining matrices for each bone of the skeleton that would be used to transform vertices of associated meshes * @return */ public Matrix4f[] computeSkinningMatrices() { TempVars vars = TempVars.get(); for (int i = 0; i < boneList.length; i++) { boneList[i].getOffsetTransform(skinningMatrixes[i], vars.quat1, vars.vect1, vars.vect2, vars.tempMat3); } vars.release(); return skinningMatrixes; }
public static void methodThatUsesTempVars() { TempVars vars = TempVars.get(); { vars.vect1.set(0.1f, 0.2f, 0.3f); sumCompute.addLocal(vars.vect1); } vars.release(); } }
/** * Internal use only. */ @Override protected void controlUpdate(float tpf) { if (skeleton != null) { skeleton.reset(); // reset skeleton to bind pose } TempVars vars = TempVars.get(); for (int i = 0; i < channels.size(); i++) { channels.get(i).update(tpf, vars); } vars.release(); if (skeleton != null) { skeleton.updateWorldVectors(); } }
public int collideWith(Collidable other) { TempVars tempVars = TempVars.get(); try { CollisionResults tempResults = tempVars.collisionResults; tempResults.clear(); return collideWith(other, tempResults); } finally { tempVars.release(); } } }
/** * Rotates the spatial by the xAngle, yAngle and zAngle angles (in radians), * (aka pitch, yaw, roll) in the local coordinate space. * * @return The spatial on which this method is called, e.g <code>this</code>. */ public Spatial rotate(float xAngle, float yAngle, float zAngle) { TempVars vars = TempVars.get(); Quaternion q = vars.quat1; q.fromAngles(xAngle, yAngle, zAngle); rotate(q); vars.release(); return this; }
public static void recursiveMethod(int recurse) { TempVars vars = TempVars.get(); { vars.vect1.set(0.1f, 0.2f, 0.3f); if (recurse < 4) { recursiveMethod(recurse + 1); } sumCompute.addLocal(vars.vect1); } vars.release(); }
/** * Normalize a Vector3f in-buffer. * * @param buf * the buffer to find the Vector3f within * @param index * the position (in terms of vectors, not floats) of the vector * to normalize */ public static void normalizeVector3(FloatBuffer buf, int index) { TempVars vars = TempVars.get(); Vector3f tempVec3 = vars.vect1; populateFromBuffer(tempVec3, buf, index); tempVec3.normalizeLocal(); setInBuffer(tempVec3, buf, index); vars.release(); }
/** * Normalize a Vector2f in-buffer. * * @param buf * the buffer to find the Vector2f within * @param index * the position (in terms of vectors, not floats) of the vector * to normalize */ public static void normalizeVector2(FloatBuffer buf, int index) { TempVars vars = TempVars.get(); Vector2f tempVec2 = vars.vect2d; populateFromBuffer(tempVec2, buf, index); tempVec2.normalizeLocal(); setInBuffer(tempVec2, buf, index); vars.release(); }
public void setArg(int index, Matrix3f mat) { TempVars vars = TempVars.get(); try { Matrix4f m = vars.tempMat4; m.zero(); for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { m.set(i, j, mat.get(i, j)); } } setArg(index, m); } finally { vars.release(); } }
public static boolean intersect(BoundingSphere sphere, Vector3f center, float radius) { assert Vector3f.isValidVector(center) && Vector3f.isValidVector(sphere.center); TempVars vars = TempVars.get(); try { Vector3f diff = center.subtract(sphere.center, vars.vect1); float rsum = sphere.getRadius() + radius; return (diff.dot(diff) <= rsum * rsum); } finally { vars.release(); } }
public void reset(boolean rewind){ if(rewind){ setTime(0); if(control.getSkeleton()!=null){ control.getSkeleton().resetAndUpdate(); }else{ TempVars vars = TempVars.get(); update(0, vars); vars.release(); } } animation = null; notified = false; }
/** * rotate the camera around the target */ protected void rotateCamera() { verticalRotation = FastMath.clamp(verticalRotation, minVerticalRotation, maxVerticalRotation); TempVars vars = TempVars.get(); Quaternion rot = vars.quat1; Quaternion rot2 = vars.quat2; rot.fromAngleNormalAxis(verticalRotation, leftVector); rot2.fromAngleNormalAxis(horizontalRotation, upVector); rot2.multLocal(rot); target.setLocalRotation(rot2); vars.release(); }
public float distanceSquared(Vector3f point) { TempVars vars = TempVars.get(); Vector3f compVec1 = vars.vect1; Vector3f compVec2 = vars.vect2; point.subtract(origin, compVec1); float lineParameter = direction.dot(compVec1); origin.add(direction.mult(lineParameter, compVec2), compVec2); compVec2.subtract(point, compVec1); float len = compVec1.lengthSquared(); vars.release(); return len; }
public void fromTransformMatrix(Matrix4f mat) { TempVars vars = TempVars.get(); translation.set(mat.toTranslationVector(vars.vect1)); rot.set(mat.toRotationQuat(vars.quat1)); scale.set(mat.toScaleVector(vars.vect2)); vars.release(); }
@Override protected Matrix4f getTransformMatrix(Geometry g){ // Compute the Local matrix for the geometry cachedLocalMat.loadIdentity(); cachedLocalMat.setRotationQuaternion(g.localTransform.getRotation()); cachedLocalMat.setTranslation(g.localTransform.getTranslation()); TempVars vars = TempVars.get(); Matrix4f scaleMat = vars.tempMat4; scaleMat.loadIdentity(); scaleMat.scale(g.localTransform.getScale()); cachedLocalMat.multLocal(scaleMat); vars.release(); return cachedLocalMat; }
private BoundingBox createBox(int l, int r) { TempVars vars = TempVars.get(); Vector3f min = vars.vect1.set(new Vector3f(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)); Vector3f max = vars.vect2.set(new Vector3f(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY)); Vector3f v1 = vars.vect3, v2 = vars.vect4, v3 = vars.vect5; for (int i = l; i <= r; i++) { getTriangle(i, v1, v2, v3); BoundingBox.checkMinMax(min, max, v1); BoundingBox.checkMinMax(min, max, v2); BoundingBox.checkMinMax(min, max, v3); } BoundingBox bbox = new BoundingBox(min, max); vars.release(); return bbox; }
private void spatialToLight(Light light) { final Vector3f worldTranslation = spatial.getWorldTranslation(); if (light instanceof PointLight) { ((PointLight) light).setPosition(worldTranslation); return; } final TempVars vars = TempVars.get(); final Vector3f vec = vars.vect1; if (light instanceof DirectionalLight) { ((DirectionalLight) light).setDirection(vec.set(worldTranslation).multLocal(-1.0f)); } if (light instanceof SpotLight) { final SpotLight spotLight = (SpotLight) light; spotLight.setPosition(worldTranslation); spotLight.setDirection(spatial.getWorldRotation().multLocal(vec.set(Vector3f.UNIT_Y).multLocal(-1))); } vars.release(); }
private void lightToSpatial(Light light) { TempVars vars = TempVars.get(); if (light instanceof PointLight) { PointLight pLight = (PointLight) light; Vector3f vecDiff = vars.vect1.set(pLight.getPosition()).subtractLocal(spatial.getWorldTranslation()); spatial.setLocalTranslation(vecDiff.addLocal(spatial.getLocalTranslation())); } if (light instanceof DirectionalLight) { DirectionalLight dLight = (DirectionalLight) light; vars.vect1.set(dLight.getDirection()).multLocal(-1.0f); Vector3f vecDiff = vars.vect1.subtractLocal(spatial.getWorldTranslation()); spatial.setLocalTranslation(vecDiff.addLocal(spatial.getLocalTranslation())); } vars.release(); //TODO add code for Spot light here when it's done }
@Override public void simpleUpdate(float tpf) { area.setCenter(ln.getLocalTranslation()); area.setRotation(ln.getLocalRotation()); TempVars vars = TempVars.get(); boolean intersectBox = area.intersectsBox(aabb, vars); boolean intersectFrustum = area.intersectsFrustum(frustumCam, vars); boolean intersectSphere = area.intersectsSphere(sphere, vars); vars.release(); boolean intersect = intersectBox || intersectFrustum || intersectSphere; areaGeom.getMaterial().setColor("Color", intersect ? ColorRGBA.Green : ColorRGBA.White); sphereGeom.getMaterial().setColor("Color", intersectSphere ? ColorRGBA.Cyan : ColorRGBA.White); frustumGeom.getMaterial().setColor("Color", intersectFrustum ? ColorRGBA.Cyan : ColorRGBA.White); aabbGeom.getMaterial().setColor("Color", intersectBox ? ColorRGBA.Cyan : ColorRGBA.White); } }