/** * 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; }
/** * Acquire an instance of the TempVar class. * You have to release the instance after use by calling the * release() method. * If more than STACK_SIZE (currently 5) instances are requested * in a single thread then an ArrayIndexOutOfBoundsException will be thrown. * * @return A TempVar instance */ public static TempVars get() { TempVarsStack stack = varsLocal.get(); TempVars instance = stack.tempVars[stack.index]; if (instance == null) { // Create new instance = new TempVars(); // Put it in there stack.tempVars[stack.index] = instance; } stack.index++; instance.isUsed = true; return instance; }
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(); }
/** * 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; }
/** * Checks to see if the given Vector3f is equals to the data stored in the * buffer at the given data index. * * @param check * the vector to check against - null will return false. * @param buf * the buffer to compare data with * @param index * the position (in terms of vectors, not floats) of the vector * in the buffer to check against * @return true if the data is equivalent, otherwise false. */ public static boolean equals(Vector3f check, FloatBuffer buf, int index) { TempVars vars = TempVars.get(); Vector3f tempVec3 = vars.vect1; populateFromBuffer(tempVec3, buf, index); boolean eq = tempVec3.equals(check); vars.release(); return eq; }
/** * Checks to see if the given Vector2f is equals to the data stored in the * buffer at the given data index. * * @param check * the vector to check against - null will return false. * @param buf * the buffer to compare data with * @param index * the position (in terms of vectors, not floats) of the vector * in the buffer to check against * @return true if the data is equivalent, otherwise false. */ public static boolean equals(Vector2f check, FloatBuffer buf, int index) { TempVars vars = TempVars.get(); Vector2f tempVec2 = vars.vect2d; populateFromBuffer(tempVec2, buf, index); boolean eq = tempVec2.equals(check); vars.release(); return eq; }
/** * 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(); } }
/** * 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(); }
/** * Multiply and store a Vector2f in-buffer. * * @param toMult * the vector to multiply against * @param buf * the buffer to find the Vector2f within * @param index * the position (in terms of vectors, not floats) of the vector * to multiply */ public static void multInBuffer(Vector2f toMult, FloatBuffer buf, int index) { TempVars vars = TempVars.get(); Vector2f tempVec2 = vars.vect2d; populateFromBuffer(tempVec2, buf, index); tempVec2.multLocal(toMult); setInBuffer(tempVec2, buf, index); vars.release(); }
/** * Add to a Vector3f in-buffer. * * @param toAdd * the vector to add from * @param buf * the buffer to find the Vector3f within * @param index * the position (in terms of vectors, not floats) of the vector * to add to */ public static void addInBuffer(Vector3f toAdd, FloatBuffer buf, int index) { TempVars vars = TempVars.get(); Vector3f tempVec3 = vars.vect1; populateFromBuffer(tempVec3, buf, index); tempVec3.addLocal(toAdd); setInBuffer(tempVec3, buf, index); vars.release(); }
/** * Multiply and store a Vector3f in-buffer. * * @param toMult * the vector to multiply against * @param buf * the buffer to find the Vector3f within * @param index * the position (in terms of vectors, not floats) of the vector * to multiply */ public static void multInBuffer(Vector3f toMult, FloatBuffer buf, int index) { TempVars vars = TempVars.get(); Vector3f tempVec3 = vars.vect1; populateFromBuffer(tempVec3, buf, index); tempVec3.multLocal(toMult); setInBuffer(tempVec3, buf, index); vars.release(); }
/** * Add to a Vector2f in-buffer. * * @param toAdd * the vector to add from * @param buf * the buffer to find the Vector2f within * @param index * the position (in terms of vectors, not floats) of the vector * to add to */ public static void addInBuffer(Vector2f toAdd, FloatBuffer buf, int index) { TempVars vars = TempVars.get(); Vector2f tempVec2 = vars.vect2d; populateFromBuffer(tempVec2, buf, index); tempVec2.addLocal(toAdd); setInBuffer(tempVec2, buf, index); 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(); } }