Matrix4f rotationXMatrix = new Matrix4f(); rotationXMatrix.rotX(angleToRotX); Matrix4f rotationYMatrix = new Matrix4f(); rotationYMatrix.rotY(angleToRotY); Matrix4f rotationZMatrix = new Matrix4f(); rotationZMatrix.rotZ(angleToRotZ); Matrix4f translationMatrix = new Matrix4f(); translationMatrix.setTranslate(new Vector3f(1.5, 1, 1.5)); Matrix4f rotationMatrix = new Matrix4f(); rotationMatrix.mul(rotationXMatrix); rotationMatrix.mul(rotationYMatrix); rotationMatrix.mul(rotationZMatrix); worldMatrix.mul(rotationMatrix); worldMatrix.transform(vertex);
public static Matrix4f createTransformationMatrix(Vector3f translation, float rx, float ry, float rz, float scale) { Matrix4f translations = new Matrix4f(); translations.setIdentity(); translations = Matrix4f.translate(translation.x, translation.y, translation.y); // Bug ... }
private static Point3f[] makeVertices(final Point3f from, final Point3f to, final float r, final int parallels) { final Point3f[] p = new Point3f[parallels + 2]; p[0] = new Point3f(from); p[1] = new Point3f(to); for (int i = 0; i < parallels; i++) { final double a = (i - 6) * (2 * Math.PI) / 12; final double c = r * Math.cos(a); final double s = r * Math.sin(a); p[i + 2] = new Point3f((float) c, (float) s, 0); } final Matrix4f ry = new Matrix4f(); final float ay = (float) Math.atan2((to.x - from.x), (to.z - from.z)); ry.rotY(ay); final Matrix4f rx = new Matrix4f(); final float ax = -(float) Math.asin((to.y - from.y) / from.distance(to)); rx.rotX(ax); rx.mul(ry, rx); for (int i = 2; i < p.length; i++) { final Point3f pi = p[i]; rx.transform(pi); pi.add(from); } return p; }
@Override Object get() { return new Matrix4f(value); }
//the object's default forward size without any transformations Vector3f forward = new Vector3f(0.0f, 0.0f, 1.0f); //rotation axis Vector3f axis = new Vector3f(); axis.cross(forward, inter); axis.normalize(); //New rotation matrix to be applied Matrix4f rotationMatrix = new Matrix4f(); rotationMatrix.setIdentity(); rotationMatrix.setRotation(new AxisAngle4f(axis, forward.angle(inter)));
Vector4f vpos = new Vector4f(0, 0, 0, 1); // (0,0,0,1) because it's relative to the cam float mv[]=new float[16]; ByteBuffer temp = ByteBuffer.allocateDirect(64); temp.order(ByteOrder.nativeOrder()); GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, (FloatBuffer)temp.asFloatBuffer()); temp.asFloatBuffer().get(mv); Matrix4f m4 = new Matrix4f(); m4.load((FloatBuffer)temp.asFloatBuffer()); m4.invert(); vpos = Matrix4f.transform(m4, vpos, vpos);
Matrix4f matrix = new Matrix4f(); Point3f vtx = new Point3f(); Vector3f n1, n2; ind1 = ind; j1 = triRef.fetchData(ind1); matrix.transform((Point3f)triRef.vertices[j1], vtx); j1 = triRef.storePoint(vtx.x, vtx.y); triRef.updateIndex(ind1, j1); j1 = triRef.fetchData(ind1); while (ind1 != ind) { matrix.transform(triRef.vertices[j1], vtx); j1 = triRef.storePoint(vtx.x, vtx.y); triRef.updateIndex(ind1, j1);
public static void compose(final AxisAngle4f rot, final Vector3f origin, final Vector3f translation, final Matrix4f ret) { ret.set(rot); final Vector3f trans = new Vector3f(origin); trans.scale(-1); ret.transform(trans); trans.add(translation); trans.add(origin); ret.setTranslation(trans); }
@Override public void focusLost(final FocusEvent e) { final Matrix4f m = new Matrix4f(); try { fromString(matrixTA.getText(), m); if (m.determinant() != 0) setTransformation(m, origin, true); } catch (final Exception ex) { System.out.println(ex.getMessage()); } } });
public static float[] getRotation(Matrix4f matrix) { float x,y,z; Matrix3f m = new Matrix3f(); matrix.get(m); if(Math.abs(m.m02 - 1) < 0.0000001) { x = (float) Math.atan2(-m.m10,m.m11); y = (float) (-3.1415926535897931/2); z = 0.0f; } else if(Math.abs(m.m02 + 1)< 0.0000001) { x = (float) Math.atan2(m.m10,m.m11); y = (float) (3.1415926535897931/2); z = 0.0f; } else { x = (float) Math.atan2(m.m12,m.m22); y = (float) Math.atan2(-m.m02, Math.sqrt(m.m12 * m.m12 + m.m22 * m.m22)); z = (float) Math.atan2(m.m01,m.m00); } return new float[] {x,y,z}; }
// Given xAxis and zAxis. Vector3f xAxis = new Vector3f(1, 0, 0); Vector3f zAxis = new Vector3f(0, 0, 1); // Create yAxis. Vector3f yAxis = new Vector3f(); yAxis.cross(zAxis, xAxis); // Create rotation matrix from axes. Matrix4f rotationMatrix = new Matrix4f(); rotationMatrix.setRow(0, new Vector4f(xAxis)); rotationMatrix.setRow(1, new Vector4f(yAxis)); rotationMatrix.setRow(2, new Vector4f(zAxis)); rotationMatrix.setRow(3, new Vector4f(0, 0, 0, 1)); // Create transform. Transform3D transform = new Transform3D(rotationMatrix); // Transform points. Vector3f vector = new Vector3f(0, 1, 0); transform.transform(vector); System.out.println(vector);
public void fromString(final String s, final Matrix4f mat) { try { final Matcher m = matrixPattern.matcher(s); m.matches(); final float[] v = new float[16]; for (int i = 0; i < 12; i++) v[i] = Float.parseFloat(m.group(i + 1)); v[15] = 1; mat.set(v); } catch (final Exception e) { throw new IllegalArgumentException("Cannot parse " + s, e); } }
@Override public void transformationUpdated(final Matrix4f mat) { univ.fireTransformationStarted(); conc.mul(mat, m); c.setTransform(new Transform3D(conc)); univ.fireTransformationFinished(); }
Matrix4f ry = new Matrix4f(); float ay = (float) Math.atan2((p1.x - p0.x), (p1.z - p0.z)); ry.rotY(ay); Matrix4f rx = new Matrix4f(); float ax = -(float) Math.asin((p1.y - p0.y) / p1.distance(p0)); rx.rotX(ax); rx.mul(ry, rx); for (int i = 0; i < parallels; i++) { final Point3f pi = p[i]; rx.transform(pi); pi.add(p0); ry = new Matrix4f(); ay = (float) Math.atan2((p1.x - p0.x), (p1.z - p0.z)); ry.rotY(ay); rx = new Matrix4f(); ax = -(float) Math.asin((p1.y - p0.y) / p1.distance(p0)); rx.rotX(ax); rx.mul(ry, rx); for (int i = 0; i < parallels; i++) { final Point3f pi = p[offset + i]; rx.transform(pi); pi.add(p1);
@Override Object get() { Matrix4f[] arr = new Matrix4f[this.length]; for (int i = 0; i < this.length; i++) { int j = i * 16; arr[i] = new Matrix4f(); arr[i].m00 = this.value[j+0]; arr[i].m01 = this.value[j+1]; arr[i].m02 = this.value[j+2]; arr[i].m03 = this.value[j+3]; arr[i].m10 = this.value[j+4]; arr[i].m11 = this.value[j+5]; arr[i].m12 = this.value[j+6]; arr[i].m13 = this.value[j+7]; arr[i].m20 = this.value[j+8]; arr[i].m21 = this.value[j+9]; arr[i].m22 = this.value[j+10]; arr[i].m23 = this.value[j+11]; arr[i].m30 = this.value[j+12]; arr[i].m31 = this.value[j+13]; arr[i].m32 = this.value[j+14]; arr[i].m33 = this.value[j+15]; } return arr; }
@Override public void keyTyped(final KeyEvent e) { final Matrix4f m = new Matrix4f(); try { fromString(matrixTA.getText(), m); if (m.determinant() != 0) setTransformation(m, origin, false); } catch (final Exception ex) { System.out.println(ex.getMessage()); } } });
m1.get(m3f);
Matrix4f transform = new Matrix4f(new float[][] { new float[] { 1, 0, 0, vector.x }, new float[] { 0, 1, 0, vector.y }, Matrix4f matrix = new Matrix4f(new float[][] { new float[] { (matrixA.values[0] * matrixB.values[0]) + (matrixA.values[1] * matrixB.values[4]) + (matrixA.values[2] * matrixB.values[8]) + (matrixA.values[3] * matrixB.values[12]),