/** * Constructor instantiates a new <code>Matrix</code> that is set to the * identity matrix. * */ public Matrix4f() { loadIdentity(); }
public void fromFrustum(float near, float far, float left, float right, float top, float bottom, boolean parallel) { loadIdentity(); if (parallel) { // scale m00 = 2.0f / (right - left); //m11 = 2.0f / (bottom - top); m11 = 2.0f / (top - bottom); m22 = -2.0f / (far - near); m33 = 1f; // translation m03 = -(right + left) / (right - left); //m31 = -(bottom + top) / (bottom - top); m13 = -(top + bottom) / (top - bottom); m23 = -(far + near) / (far - near); } else { m00 = (2.0f * near) / (right - left); m11 = (2.0f * near) / (top - bottom); m32 = -1.0f; m33 = -0.0f; // A m02 = (right + left) / (right - left); // B m12 = (top + bottom) / (top - bottom); // C m22 = -(far + near) / (far - near); // D m23 = -(2.0f * far * near) / (far - near); } }
/** * <code>copy</code> transfers the contents of a given matrix to this * matrix. If a null matrix is supplied, this matrix is set to the identity * matrix. * * @param matrix * the matrix to copy. */ public void copy(Matrix4f matrix) { if (null == matrix) { loadIdentity(); } else { m00 = matrix.m00; m01 = matrix.m01; m02 = matrix.m02; m03 = matrix.m03; m10 = matrix.m10; m11 = matrix.m11; m12 = matrix.m12; m13 = matrix.m13; m20 = matrix.m20; m21 = matrix.m21; m22 = matrix.m22; m23 = matrix.m23; m30 = matrix.m30; m31 = matrix.m31; m32 = matrix.m32; m33 = matrix.m33; } }
/** * Overrides the projection matrix used by the camera. Will * use the matrix for computing the view projection matrix as well. * Use null argument to return to normal functionality. * * @param projMatrix */ public void setProjectionMatrix(Matrix4f projMatrix) { if (projMatrix == null) { overrideProjection = false; projectionMatrixOverride.loadIdentity(); } else { overrideProjection = true; projectionMatrixOverride.set(projMatrix); } updateViewProjection(); }
/** * Copy the values from a LibOVR matrix into a jMonkeyEngine matrix. * * @param from The matrix to copy from. * @param to The matrix to copy to. * @return The {@code to} argument. */ public static Matrix4f matrixO2J(OVRMatrix4f from, Matrix4f to) { to.loadIdentity(); // For the additional columns (unless I'm badly misunderstanding matricies) for (int x = 0; x < 4; x++) { for (int y = 0; y < 4; y++) { float val = from.M(x + y * 4); // TODO verify this to.set(x, y, val); } } to.transposeLocal(); // jME vs LibOVR coordinate spaces - Yay! return to; }
/** * Converts given transformation parameters into the matrix. * * @param position * the position of the feature * @param rotation * the rotation of the feature * @param scale * the scale of the feature * @param store * the matrix where the result will be stored * @return the store matrix */ private Matrix4f toMatrix(Vector3f position, Quaternion rotation, Vector3f scale, Matrix4f store) { store.loadIdentity(); store.setTranslation(position); store.setRotationQuaternion(rotation); store.setScale(scale); return store; }
public void renderQuad(int x, int y, int width, int height, Color topLeft, Color topRight, Color bottomRight, Color bottomLeft) { ByteBuffer buf = (ByteBuffer) quadColor.getData(); buf.rewind(); buf.putInt(convertColor(topRight)); buf.putInt(convertColor(topLeft)); buf.putInt(convertColor(bottomLeft)); buf.putInt(convertColor(bottomRight)); buf.flip(); quadColor.updateData(buf); tempMat.loadIdentity(); tempMat.setTranslation(x, getHeight() - y, 0); tempMat.setScale(width, height, 0); rm.setWorldMatrix(tempMat); rm.setForcedRenderState(renderState); vertexColorMaterial.render(quadGeom, rm); //System.out.format("renderQuad2(%d, %d, %d, %d, %s, %s, %s, %s)\n", x, y, width, height, topLeft.toString(), // topRight.toString(), // bottomRight.toString(), // bottomLeft.toString()); }
@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; }
/** * Converts given transform to the matrix. * * @param transform * the transform to be converted * @param store * the matrix where the result will be stored * @return the store matrix */ public Matrix4f toMatrix(Transform transform, Matrix4f store) { if (transform != null) { return this.toMatrix(transform.getTranslation(), transform.getRotation(), transform.getScale(), store); } store.loadIdentity(); return store; }
/** * Recomputes the matrix returned by {@link Geometry#getWorldMatrix() }. * This will require a localized transform update for this geometry. */ public void computeWorldMatrix() { // Force a local update of the geometry's transform checkDoTransformUpdate(); // Compute the cached world matrix cachedWorldMat.loadIdentity(); if (ignoreTransform) { return; } cachedWorldMat.setRotationQuaternion(worldTransform.getRotation()); cachedWorldMat.setTranslation(worldTransform.getTranslation()); TempVars vars = TempVars.get(); Matrix4f scaleMat = vars.tempMat4; scaleMat.loadIdentity(); scaleMat.scale(worldTransform.getScale()); cachedWorldMat.multLocal(scaleMat); vars.release(); }
float y0 = centerY + (y - centerY) * scale; tempMat.loadIdentity(); tempMat.setTranslation(x0, getHeight() - y0, 0); tempMat.setScale(w * scale, h * scale, 0);
float y0 = y; // + 0.5f * height * (1f - sizeY); tempMat.loadIdentity(); tempMat.setTranslation(x0, getHeight() - y0, 0); tempMat.setScale(sizeX, sizeY, 0);
/** * Creates a transform matrix that will convert from this spatials' * local coordinate space to the world coordinate space * based on the world transform. * * @param store Matrix where to store the result, if null, a new one * will be created and returned. * * @return store if not null, otherwise, a new matrix containing the result. * * @see Spatial#getWorldTransform() */ public Matrix4f getLocalToWorldMatrix(Matrix4f store) { if (store == null) { store = new Matrix4f(); } else { store.loadIdentity(); } // multiply with scale first, then rotate, finally translate (cf. // Eberly) store.scale(getWorldScale()); store.multLocal(getWorldRotation()); store.setTranslation(getWorldTranslation()); return store; }
public void renderQuad(int x, int y, int width, int height, Color color) { //We test for alpha >0 as an optimization to prevent the render of completely transparent quads. //Nifty use layers that are often used for logical positionning and not rendering. //each layer is rendered as a quad, but that can bump up the number of geometry rendered by a lot. //Since we disable depth write, there is absolutely no point in rendering those quads //This optimization can result in a huge increase of perfs on complex Nifty UIs. if(color.getAlpha() >0){ colorMaterial.setColor("Color", convertColor(color, tempColor)); tempMat.loadIdentity(); tempMat.setTranslation(x, getHeight() - y, 0); tempMat.setScale(width, height, 0); rm.setWorldMatrix(tempMat); rm.setForcedRenderState(renderState); colorMaterial.render(quadGeom, rm); } //System.out.format("renderQuad1(%d, %d, %d, %d, %s)\n", x, y, width, height, color.toString()); }
public void renderImage(RenderImage image, int x, int y, int width, int height, Color color, float imageScale) { RenderImageJme jmeImage = (RenderImageJme) image; textureColorMaterial.setColor("Color", convertColor(color, tempColor)); textureColorMaterial.setTexture("ColorMap", jmeImage.getTexture()); quad.clearBuffer(Type.TexCoord); quad.setBuffer(quadDefaultTC); float x0 = x + 0.5f * width * (1f - imageScale); float y0 = y + 0.5f * height * (1f - imageScale); tempMat.loadIdentity(); tempMat.setTranslation(x0, getHeight() - y0, 0); tempMat.setScale(width * imageScale, height * imageScale, 0); rm.setWorldMatrix(tempMat); rm.setForcedRenderState(renderState); textureColorMaterial.render(quadGeom, rm); //System.out.format("renderImage1(%s, %d, %d, %d, %d, %s, %f)\n", jmeImage.getTexture().getKey().toString(), x, y, width, height, color.toString(), imageScale); }
hmdRelativeEyePoses[eye].loadIdentity(); hmdRelativeEyePoses[eye].setTranslation(hmdRelativeEyePositions[eye]); hmdRelativeEyePoses[eye].setRotationQuaternion(rotation);
public void render() { renderState.setBlendMode(convertBlend(blendMode)); vertexPosBuffer.flip(); vertexPos.updateData(vertexPosBuffer); vertexTexCoordBuffer.flip(); vertexTexCoord.updateData(vertexTexCoordBuffer); vertexColorBuffer.flip(); vertexColor.updateData(vertexColorBuffer); indexBufferBuffer.flip(); indexBuffer.updateData(indexBufferBuffer); tempMat.loadIdentity(); renderManager.setWorldMatrix(tempMat); renderManager.setForcedRenderState(renderState); material.setTexture("ColorMap", texture); mesh.updateCounts(); material.render(meshGeometry, renderManager); renderManager.setForcedRenderState(null); }
private void setViewPort(Camera cam) { // this will make sure to update viewport only if needed if (cam != prevCam || cam.isViewportChanged()) { viewX = (int) (cam.getViewPortLeft() * cam.getWidth()); viewY = (int) (cam.getViewPortBottom() * cam.getHeight()); int viewX2 = (int) (cam.getViewPortRight() * cam.getWidth()); int viewY2 = (int) (cam.getViewPortTop() * cam.getHeight()); viewWidth = viewX2 - viewX; viewHeight = viewY2 - viewY; uniformBindingManager.setViewPort(viewX, viewY, viewWidth, viewHeight); renderer.setViewPort(viewX, viewY, viewWidth, viewHeight); renderer.setClipRect(viewX, viewY, viewWidth, viewHeight); cam.clearViewportChanged(); prevCam = cam; // float translateX = viewWidth == viewX ? 0 : -(viewWidth + viewX) / (viewWidth - viewX); // float translateY = viewHeight == viewY ? 0 : -(viewHeight + viewY) / (viewHeight - viewY); // float scaleX = viewWidth == viewX ? 1f : 2f / (viewWidth - viewX); // float scaleY = viewHeight == viewY ? 1f : 2f / (viewHeight - viewY); // // orthoMatrix.loadIdentity(); // orthoMatrix.setTranslation(translateX, translateY, 0); // orthoMatrix.setScale(scaleX, scaleY, 0); orthoMatrix.loadIdentity(); orthoMatrix.setTranslation(-1f, -1f, 0f); orthoMatrix.setScale(2f / cam.getWidth(), 2f / cam.getHeight(), 0f); } }
/** * This method calculates local transformation for the object. Parentage is * taken under consideration. * * @param objectStructure * the object's structure * @return objects transformation relative to its parent */ public Transform getTransformation(Structure objectStructure, BlenderContext blenderContext) { TempVars tempVars = TempVars.get(); Matrix4f parentInv = tempVars.tempMat4; Pointer pParent = (Pointer) objectStructure.getFieldValue("parent"); if (pParent.isNotNull()) { Structure parentObjectStructure = (Structure) blenderContext.getLoadedFeature(pParent.getOldMemoryAddress(), LoadedDataType.STRUCTURE); this.getMatrix(parentObjectStructure, "obmat", fixUpAxis, parentInv).invertLocal(); } else { parentInv.loadIdentity(); } Matrix4f globalMatrix = this.getMatrix(objectStructure, "obmat", fixUpAxis, tempVars.tempMat42); Matrix4f localMatrix = parentInv.multLocal(globalMatrix); this.getSizeSignums(objectStructure, tempVars.vect1); localMatrix.toTranslationVector(tempVars.vect2); localMatrix.toRotationQuat(tempVars.quat1); localMatrix.toScaleVector(tempVars.vect3); Transform t = new Transform(tempVars.vect2, tempVars.quat1.normalizeLocal(), tempVars.vect3.multLocal(tempVars.vect1)); tempVars.release(); return t; }
/** * Constructor instantiates a new <code>Matrix</code> that is set to the * identity matrix. * */ public Matrix4f() { loadIdentity(); }