/** * Converts the given position from world space to screen space. * * @see Camera#getScreenCoordinates(Vector3f, Vector3f) */ public Vector3f getScreenCoordinates(Vector3f worldPosition, Vector3f store) { if (store == null) { store = new Vector3f(); } // TempVars vars = vars.lock(); // Quaternion tmp_quat = vars.quat1; // tmp_quat.set( worldPosition.x, worldPosition.y, worldPosition.z, 1 ); // viewProjectionMatrix.mult(tmp_quat, tmp_quat); // tmp_quat.multLocal( 1.0f / tmp_quat.getW() ); // store.x = ( ( tmp_quat.getX() + 1 ) * ( viewPortRight - viewPortLeft ) / 2 + viewPortLeft ) * getWidth(); // store.y = ( ( tmp_quat.getY() + 1 ) * ( viewPortTop - viewPortBottom ) / 2 + viewPortBottom ) * getHeight(); // store.z = ( tmp_quat.getZ() + 1 ) / 2; // vars.release(); float w = viewProjectionMatrix.multProj(worldPosition, store); store.divideLocal(w); store.x = ((store.x + 1f) * (viewPortRight - viewPortLeft) / 2f + viewPortLeft) * getWidth(); store.y = ((store.y + 1f) * (viewPortTop - viewPortBottom) / 2f + viewPortBottom) * getHeight(); store.z = (store.z + 1f) / 2f; return store; }
private Vector3f getClipCoordinates(Vector3f worldPosition, Vector3f store, Camera cam) { float w = cam.getViewProjectionMatrix().multProj(worldPosition, store); store.divideLocal(w); store.x = ((store.x + 1f) * (cam.getViewPortRight() - cam.getViewPortLeft()) / 2f + cam.getViewPortLeft()); store.y = ((store.y + 1f) * (cam.getViewPortTop() - cam.getViewPortBottom()) / 2f + cam.getViewPortBottom()); store.z = (store.z + 1f) / 2f; return store; }
/** * @see Camera#getWorldCoordinates */ public Vector3f getWorldCoordinates(Vector2f screenPosition, float projectionZPos, Vector3f store) { if (store == null) { store = new Vector3f(); } Matrix4f inverseMat = new Matrix4f(viewProjectionMatrix); inverseMat.invertLocal(); store.set( (screenPosition.x / getWidth() - viewPortLeft) / (viewPortRight - viewPortLeft) * 2 - 1, (screenPosition.y / getHeight() - viewPortBottom) / (viewPortTop - viewPortBottom) * 2 - 1, projectionZPos * 2 - 1); float w = inverseMat.multProj(store, store); store.multLocal(1f / w); return store; }
/** * Compute bounds from an array of points * @param pts * @param mat * @return */ public static BoundingBox computeBoundForPoints(Vector3f[] pts, Matrix4f mat) { Vector3f min = new Vector3f(Vector3f.POSITIVE_INFINITY); Vector3f max = new Vector3f(Vector3f.NEGATIVE_INFINITY); TempVars vars = TempVars.get(); Vector3f temp = vars.vect1; for (int i = 0; i < pts.length; i++) { float w = mat.multProj(pts[i], temp); temp.x /= w; temp.y /= w; // Why was this commented out? temp.z /= w; min.minLocal(temp); max.maxLocal(temp); } vars.release(); Vector3f center = min.add(max).multLocal(0.5f); Vector3f extent = max.subtract(min).multLocal(0.5f); //Nehon 08/18/2010 : Added an offset to the extend to avoid banding artifacts when the frustum are aligned return new BoundingBox(center, extent.x + 2.0f, extent.y + 2.0f, extent.z + 2.5f); }
public BoundingVolume transform(Matrix4f trans, BoundingVolume store) { BoundingBox box; if (store == null || store.getType() != Type.AABB) { box = new BoundingBox(); } else { box = (BoundingBox) store; } TempVars vars = TempVars.get(); float w = trans.multProj(center, box.center); box.center.divideLocal(w); Matrix3f transMatrix = vars.tempMat3; trans.toRotationMatrix(transMatrix); // Make the rotation matrix all positive to get the maximum x/y/z extent transMatrix.absoluteLocal(); vars.vect1.set(xExtent, yExtent, zExtent); transMatrix.mult(vars.vect1, vars.vect1); // Assign the biggest rotations after scales. box.xExtent = FastMath.abs(vars.vect1.getX()); box.yExtent = FastMath.abs(vars.vect1.getY()); box.zExtent = FastMath.abs(vars.vect1.getZ()); vars.release(); return box; }
/** * Converts the given position from world space to screen space. * * @see Camera#getScreenCoordinates(Vector3f, Vector3f) */ public Vector3f getScreenCoordinates(Vector3f worldPosition, Vector3f store) { if (store == null) { store = new Vector3f(); } // TempVars vars = vars.lock(); // Quaternion tmp_quat = vars.quat1; // tmp_quat.set( worldPosition.x, worldPosition.y, worldPosition.z, 1 ); // viewProjectionMatrix.mult(tmp_quat, tmp_quat); // tmp_quat.multLocal( 1.0f / tmp_quat.getW() ); // store.x = ( ( tmp_quat.getX() + 1 ) * ( viewPortRight - viewPortLeft ) / 2 + viewPortLeft ) * getWidth(); // store.y = ( ( tmp_quat.getY() + 1 ) * ( viewPortTop - viewPortBottom ) / 2 + viewPortBottom ) * getHeight(); // store.z = ( tmp_quat.getZ() + 1 ) / 2; // vars.release(); float w = viewProjectionMatrix.multProj(worldPosition, store); store.divideLocal(w); store.x = ((store.x + 1f) * (viewPortRight - viewPortLeft) / 2f + viewPortLeft) * getWidth(); store.y = ((store.y + 1f) * (viewPortTop - viewPortBottom) / 2f + viewPortBottom) * getHeight(); store.z = (store.z + 1f) / 2f; return store; }
/** * Converts the given position from world space to screen space. * * @see Camera#getScreenCoordinates(Vector3f, Vector3f) */ public Vector3f getScreenCoordinates(Vector3f worldPosition, Vector3f store) { if (store == null) { store = new Vector3f(); } // TempVars vars = vars.lock(); // Quaternion tmp_quat = vars.quat1; // tmp_quat.set( worldPosition.x, worldPosition.y, worldPosition.z, 1 ); // viewProjectionMatrix.mult(tmp_quat, tmp_quat); // tmp_quat.multLocal( 1.0f / tmp_quat.getW() ); // store.x = ( ( tmp_quat.getX() + 1 ) * ( viewPortRight - viewPortLeft ) / 2 + viewPortLeft ) * getWidth(); // store.y = ( ( tmp_quat.getY() + 1 ) * ( viewPortTop - viewPortBottom ) / 2 + viewPortBottom ) * getHeight(); // store.z = ( tmp_quat.getZ() + 1 ) / 2; // vars.release(); float w = viewProjectionMatrix.multProj(worldPosition, store); store.divideLocal(w); store.x = ((store.x + 1f) * (viewPortRight - viewPortLeft) / 2f + viewPortLeft) * getWidth(); store.y = ((store.y + 1f) * (viewPortTop - viewPortBottom) / 2f + viewPortBottom) * getHeight(); store.z = (store.z + 1f) / 2f; return store; }
private Vector3f getClipCoordinates(Vector3f worldPosition, Vector3f store, Camera cam) { float w = cam.getViewProjectionMatrix().multProj(worldPosition, store); store.divideLocal(w); store.x = ((store.x + 1f) * (cam.getViewPortRight() - cam.getViewPortLeft()) / 2f + cam.getViewPortLeft()); store.y = ((store.y + 1f) * (cam.getViewPortTop() - cam.getViewPortBottom()) / 2f + cam.getViewPortBottom()); store.z = (store.z + 1f) / 2f; return store; }
private Vector3f getClipCoordinates(Vector3f worldPosition, Vector3f store, Camera cam) { float w = cam.getViewProjectionMatrix().multProj(worldPosition, store); store.divideLocal(w); store.x = ((store.x + 1f) * (cam.getViewPortRight() - cam.getViewPortLeft()) / 2f + cam.getViewPortLeft()); store.y = ((store.y + 1f) * (cam.getViewPortTop() - cam.getViewPortBottom()) / 2f + cam.getViewPortBottom()); store.z = (store.z + 1f) / 2f; return store; }
private Vector3f getClipCoordinates(Vector3f worldPosition, Vector3f store, Camera cam) { float w = cam.getViewProjectionMatrix().multProj(worldPosition, store); store.divideLocal(w); store.x = ((store.x + 1f) * (cam.getViewPortRight() - cam.getViewPortLeft()) / 2f + cam.getViewPortLeft()); store.y = ((store.y + 1f) * (cam.getViewPortTop() - cam.getViewPortBottom()) / 2f + cam.getViewPortBottom()); store.z = (store.z + 1f) / 2f; return store; }
/** * @see Camera#getWorldCoordinates */ public Vector3f getWorldCoordinates(Vector2f screenPosition, float projectionZPos, Vector3f store) { if (store == null) { store = new Vector3f(); } Matrix4f inverseMat = new Matrix4f(viewProjectionMatrix); inverseMat.invertLocal(); store.set( (screenPosition.x / getWidth() - viewPortLeft) / (viewPortRight - viewPortLeft) * 2 - 1, (screenPosition.y / getHeight() - viewPortBottom) / (viewPortTop - viewPortBottom) * 2 - 1, projectionZPos * 2 - 1); float w = inverseMat.multProj(store, store); store.multLocal(1f / w); return store; }
/** * @see Camera#getWorldCoordinates */ public Vector3f getWorldCoordinates(Vector2f screenPosition, float projectionZPos, Vector3f store) { if (store == null) { store = new Vector3f(); } Matrix4f inverseMat = new Matrix4f(viewProjectionMatrix); inverseMat.invertLocal(); store.set( (screenPosition.x / getWidth() - viewPortLeft) / (viewPortRight - viewPortLeft) * 2 - 1, (screenPosition.y / getHeight() - viewPortBottom) / (viewPortTop - viewPortBottom) * 2 - 1, projectionZPos * 2 - 1); float w = inverseMat.multProj(store, store); store.multLocal(1f / w); return store; }
/** * Compute bounds from an array of points * @param pts * @param mat * @return */ public static BoundingBox computeBoundForPoints(Vector3f[] pts, Matrix4f mat) { Vector3f min = new Vector3f(Vector3f.POSITIVE_INFINITY); Vector3f max = new Vector3f(Vector3f.NEGATIVE_INFINITY); Vector3f temp = new Vector3f(); for (int i = 0; i < pts.length; i++) { float w = mat.multProj(pts[i], temp); temp.x /= w; temp.y /= w; // Why was this commented out? temp.z /= w; min.minLocal(temp); max.maxLocal(temp); } Vector3f center = min.add(max).multLocal(0.5f); Vector3f extent = max.subtract(min).multLocal(0.5f); //Nehon 08/18/2010 : Added an offset to the extend to avoid banding artifacts when the frustum are aligned return new BoundingBox(center, extent.x + 2.0f, extent.y + 2.0f, extent.z + 2.5f); }
/** * Compute bounds from an array of points * @param pts * @param mat * @return */ public static BoundingBox computeBoundForPoints(Vector3f[] pts, Matrix4f mat) { Vector3f min = new Vector3f(Vector3f.POSITIVE_INFINITY); Vector3f max = new Vector3f(Vector3f.NEGATIVE_INFINITY); TempVars vars = TempVars.get(); Vector3f temp = vars.vect1; for (int i = 0; i < pts.length; i++) { float w = mat.multProj(pts[i], temp); temp.x /= w; temp.y /= w; // Why was this commented out? temp.z /= w; min.minLocal(temp); max.maxLocal(temp); } vars.release(); Vector3f center = min.add(max).multLocal(0.5f); Vector3f extent = max.subtract(min).multLocal(0.5f); //Nehon 08/18/2010 : Added an offset to the extend to avoid banding artifacts when the frustum are aligned return new BoundingBox(center, extent.x + 2.0f, extent.y + 2.0f, extent.z + 2.5f); }
public BoundingVolume transform(Matrix4f trans, BoundingVolume store) { BoundingBox box; if (store == null || store.getType() != Type.AABB) { box = new BoundingBox(); } else { box = (BoundingBox) store; } TempVars vars = TempVars.get(); float w = trans.multProj(center, box.center); box.center.divideLocal(w); Matrix3f transMatrix = vars.tempMat3; trans.toRotationMatrix(transMatrix); // Make the rotation matrix all positive to get the maximum x/y/z extent transMatrix.absoluteLocal(); vars.vect1.set(xExtent, yExtent, zExtent); transMatrix.mult(vars.vect1, vars.vect1); // Assign the biggest rotations after scales. box.xExtent = FastMath.abs(vars.vect1.getX()); box.yExtent = FastMath.abs(vars.vect1.getY()); box.zExtent = FastMath.abs(vars.vect1.getZ()); vars.release(); return box; }
public BoundingVolume transform(Matrix4f trans, BoundingVolume store) { BoundingBox box; if (store == null || store.getType() != Type.AABB) { box = new BoundingBox(); } else { box = (BoundingBox) store; } TempVars vars = TempVars.get(); float w = trans.multProj(center, box.center); box.center.divideLocal(w); Matrix3f transMatrix = vars.tempMat3; trans.toRotationMatrix(transMatrix); // Make the rotation matrix all positive to get the maximum x/y/z extent transMatrix.absoluteLocal(); vars.vect1.set(xExtent, yExtent, zExtent); transMatrix.mult(vars.vect1, vars.vect1); // Assign the biggest rotations after scales. box.xExtent = FastMath.abs(vars.vect1.getX()); box.yExtent = FastMath.abs(vars.vect1.getY()); box.zExtent = FastMath.abs(vars.vect1.getZ()); vars.release(); return box; }