List of usage examples for com.google.gwt.typedarrays.shared Float64Array set
void set(double[] array, int offset);
From source file:thothbot.parallax.core.shared.core.GeometryBuffer.java
License:Open Source License
@Override public void computeVertexNormals() { if (getWebGlVertexArray() != null && getWebGlIndexArray() != null) { int nVertexElements = getWebGlVertexArray().length(); if (getWebGlNormalArray() == null) { setWebGlNormalArray(TypedArrays.createFloat64Array(nVertexElements)); } else {// w w w . ja v a2 s . c o m // reset existing normals to zero for (int i = 0, il = getWebGlNormalArray().length(); i < il; i++) { getWebGlNormalArray().set(i, 0); } } List<GeometryBuffer.Offset> offsets = this.offsets; Int16Array indices = getWebGlIndexArray(); Float64Array positions = getWebGlVertexArray(); Float64Array normals = getWebGlNormalArray(); Vector3 pA = new Vector3(); Vector3 pB = new Vector3(); Vector3 pC = new Vector3(); Vector3 cb = new Vector3(); Vector3 ab = new Vector3(); for (int j = 0, jl = offsets.size(); j < jl; ++j) { int start = offsets.get(j).start; int count = offsets.get(j).count; int index = offsets.get(j).index; for (int i = start, il = start + count; i < il; i += 3) { int vA = index + indices.get(i); int vB = index + indices.get(i + 1); int vC = index + indices.get(i + 2); pA.set(positions.get(vA * 3), positions.get(vA * 3 + 1), positions.get(vA * 3 + 2)); pB.set(positions.get(vB * 3), positions.get(vB * 3 + 1), positions.get(vB * 3 + 2)); pC.set(positions.get(vC * 3), positions.get(vC * 3 + 1), positions.get(vC * 3 + 2)); cb.sub(pC, pB); ab.sub(pA, pB); cb.cross(ab); normals.set(vA * 3, normals.get(vA * 3) + cb.x); normals.set(vA * 3 + 1, normals.get(vA * 3 + 1) + cb.y); normals.set(vA * 3 + 2, normals.get(vA * 3 + 2) + cb.z); normals.set(vB * 3, normals.get(vB * 3) + cb.x); normals.set(vB * 3 + 1, normals.get(vB * 3 + 1) + cb.y); normals.set(vB * 3 + 2, normals.get(vB * 3 + 2) + cb.z); normals.set(vC * 3, normals.get(vC * 3) + cb.x); normals.set(vC * 3 + 1, normals.get(vC * 3 + 1) + cb.y); normals.set(vC * 3 + 2, normals.get(vC * 3 + 2) + cb.z); } } // normalize normals for (int i = 0, il = normals.length(); i < il; i += 3) { double x = normals.get(i); double y = normals.get(i + 1); double z = normals.get(i + 2); double n = 1.0 / Math.sqrt(x * x + y * y + z * z); normals.set(i, normals.get(i) * n); normals.set(i + 1, normals.get(i + 1) * n); normals.set(i + 2, normals.get(i + 2) * n); } setNormalsNeedUpdate(true); } }
From source file:thothbot.parallax.core.shared.core.GeometryBuffer.java
License:Open Source License
private void handleVertex(List<Vector3> tan1, List<Vector3> tan2, int v) { Float64Array normals = getWebGlNormalArray(); Float64Array tangents = getWebGlTangentArray(); Vector3 n = new Vector3(normals.get(v * 3), normals.get(v * 3 + 1), normals.get(v * 3 + 2)); Vector3 n2 = n.clone();//www . j av a 2s.com Vector3 t = tan1.get(v); // Gram-Schmidt orthogonalize Vector3 tmp = t.clone(); tmp.sub(n.multiply(n.dot(t))).normalize(); // Calculate handedness Vector3 tmp2 = new Vector3(); tmp2.cross(n2, t); double test = tmp2.dot(tan2.get(v)); double w = (test < 0.0) ? -1.0 : 1.0; tangents.set(v * 4, tmp.getX()); tangents.set(v * 4 + 1, tmp.getY()); tangents.set(v * 4 + 2, tmp.getZ()); tangents.set(v * 4 + 3, w); }
From source file:thothbot.parallax.core.shared.core.Matrix3.java
License:Open Source License
/** * Transpose the current matrix where its rows will be the * columns or its columns are the rows of the current matrix. *///from w ww . j a v a2 s. c o m public void transpose() { double tmp; Float64Array m = this.getArray(); tmp = m.get(1); m.set(1, m.get(3)); m.set(3, tmp); tmp = m.get(2); m.set(2, m.get(6)); m.set(6, tmp); tmp = m.get(5); m.set(5, m.get(7)); m.set(7, tmp); }
From source file:thothbot.parallax.core.shared.core.Matrix3.java
License:Open Source License
/** * Transpose the current matrix into new Matrix which is represented * by Array[9] /* ww w .j ava2 s .c o m*/ * * @return an array of new transposed matrix. */ public Float64Array transposeIntoArray() { Float64Array r = TypedArrays.createFloat64Array(9); Float64Array m = this.getArray(); r.set(0, m.get(0)); r.set(1, m.get(3)); r.set(2, m.get(6)); r.set(3, m.get(1)); r.set(4, m.get(4)); r.set(5, m.get(7)); r.set(6, m.get(2)); r.set(7, m.get(5)); r.set(8, m.get(8)); return r; }
From source file:thothbot.parallax.core.shared.core.Matrix4.java
License:Open Source License
/** * Modifies the current matrix by looking at target on defined eye. * //w w w .j a va 2s. co m * @param eye the Eye vector * @param target the Target vector * @param up the Up vector * * @return the current matrix */ public Matrix4 lookAt(Vector3 eye, Vector3 target, Vector3 up) { Float64Array te = this.getArray(); Vector3 x = Matrix4.__v1; Vector3 y = Matrix4.__v2; Vector3 z = Matrix4.__v3; z.sub(eye, target).normalize(); if (z.length() == 0) z.setZ(1); x.cross(up, z).normalize(); if (x.length() == 0) { z.addX(0.0001); x.cross(up, z).normalize(); } y.cross(z, x); te.set(0, x.getX()); te.set(4, y.getX()); te.set(8, z.getX()); te.set(1, x.getY()); te.set(5, y.getY()); te.set(9, z.getY()); te.set(2, x.getZ()); te.set(6, y.getZ()); te.set(10, z.getZ()); return this; }
From source file:thothbot.parallax.core.shared.core.Matrix4.java
License:Open Source License
/** * Transpose the current matrix where its rows will be the * columns or its columns are the rows of the current matrix. * /*from w w w .j av a 2s . c o m*/ * @return the current matrix */ public Matrix4 transpose() { Float64Array te = this.getArray(); double tmp; tmp = te.get(1); te.set(1, te.get(4)); te.set(4, tmp); tmp = te.get(2); te.set(2, te.get(8)); te.set(8, tmp); tmp = te.get(6); te.set(6, te.get(9)); te.set(9, tmp); tmp = te.get(3); te.set(3, te.get(12)); te.set(12, tmp); tmp = te.get(7); te.set(7, te.get(13)); te.set(13, tmp); tmp = te.get(11); te.set(11, te.get(14)); te.set(14, tmp); return this; }
From source file:thothbot.parallax.core.shared.core.Matrix4.java
License:Open Source License
/** * Sets the value of input array to the values of the current matrix. * The indexes in the array will be the following: * // w w w .ja va 2 s . c o m * <pre>{@code * 0 4 8 12 * 1 5 9 13 * 2 6 10 14 * 3 7 11 15 * }</pre> * * @param flat the array for storing matrix values * @param offset the offset value * * @return the modified input vector */ public Float64Array flattenToArray(Float64Array flat, int offset) { flat.set(offset, this.getArray().get(0)); flat.set(offset + 1, this.getArray().get(1)); flat.set(offset + 2, this.getArray().get(2)); flat.set(offset + 3, this.getArray().get(3)); flat.set(offset + 4, this.getArray().get(4)); flat.set(offset + 5, this.getArray().get(5)); flat.set(offset + 6, this.getArray().get(6)); flat.set(offset + 7, this.getArray().get(7)); flat.set(offset + 8, this.getArray().get(8)); flat.set(offset + 9, this.getArray().get(9)); flat.set(offset + 10, this.getArray().get(10)); flat.set(offset + 11, this.getArray().get(11)); flat.set(offset + 12, this.getArray().get(12)); flat.set(offset + 13, this.getArray().get(13)); flat.set(offset + 14, this.getArray().get(14)); flat.set(offset + 15, this.getArray().get(15)); return flat; }
From source file:thothbot.parallax.core.shared.core.Matrix4.java
License:Open Source License
/** * Sets the value of this matrix to the matrix inverse of the passed matrix * m.//from www. j av a 2 s .c om * * Based on <a href="http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm">http://www.euclideanspace.com</a> * * @param m the matrix to be inverted */ public Matrix4 getInverse(Matrix4 m) { Float64Array te = this.getArray(); Float64Array me = m.getArray(); double n11 = me.get(0), n12 = me.get(4), n13 = me.get(8), n14 = me.get(12); double n21 = me.get(1), n22 = me.get(5), n23 = me.get(9), n24 = me.get(13); double n31 = me.get(2), n32 = me.get(6), n33 = me.get(10), n34 = me.get(14); double n41 = me.get(3), n42 = me.get(7), n43 = me.get(11), n44 = me.get(15); te.set(0, n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44); te.set(4, n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44); te.set(8, n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44); te.set(12, n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34); te.set(1, n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44); te.set(5, n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44); te.set(9, n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44); te.set(13, n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34); te.set(2, n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44); te.set(6, n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44); te.set(10, n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44); te.set(14, n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34); te.set(3, n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43); te.set(7, n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43); te.set(11, n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43); te.set(15, n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33); this.multiply(1.0 / m.determinant()); return this; }
From source file:thothbot.parallax.core.shared.core.Matrix4.java
License:Open Source License
public Matrix4 setRotationFromEuler(Vector3 v, Euler order) { Float64Array te = this.elements; double x = v.x, y = v.y, z = v.z; double a = Math.cos(x), b = Math.sin(x); double c = Math.cos(y), d = Math.sin(y); double e = Math.cos(z), f = Math.sin(z); if (order == Euler.XYZ) { double ae = a * e, af = a * f, be = b * e, bf = b * f; te.set(0, c * e); te.set(4, -c * f);/* www .j a v a2s .c o m*/ te.set(8, d); te.set(1, af + be * d); te.set(5, ae - bf * d); te.set(9, -b * c); te.set(2, bf - ae * d); te.set(6, be + af * d); te.set(10, a * c); } else if (order == Euler.YXZ) { double ce = c * e, cf = c * f, de = d * e, df = d * f; te.set(0, ce + df * b); te.set(4, de * b - cf); te.set(8, a * d); te.set(1, a * f); te.set(5, a * e); te.set(9, -b); te.set(2, cf * b - de); te.set(6, df + ce * b); te.set(10, a * c); } else if (order == Euler.ZXY) { double ce = c * e, cf = c * f, de = d * e, df = d * f; te.set(0, ce - df * b); te.set(4, -a * f); te.set(8, de + cf * b); te.set(1, cf + de * b); te.set(5, a * e); te.set(9, df - ce * b); te.set(2, -a * d); te.set(6, b); te.set(10, a * c); } else if (order == Euler.ZYX) { double ae = a * e, af = a * f, be = b * e, bf = b * f; te.set(0, c * e); te.set(4, be * d - af); te.set(8, ae * d + bf); te.set(1, c * f); te.set(5, bf * d + ae); te.set(9, af * d - be); te.set(2, -d); te.set(6, b * c); te.set(10, a * c); } else if (order == Euler.YZX) { double ac = a * c, ad = a * d, bc = b * c, bd = b * d; te.set(0, c * e); te.set(4, bd - ac * f); te.set(8, bc * f + ad); te.set(1, f); te.set(5, a * e); te.set(9, -b * e); te.set(2, -d * e); te.set(6, ad * f + bc); te.set(10, ac - bd * f); } else if (order == Euler.XZY) { double ac = a * c, ad = a * d, bc = b * c, bd = b * d; te.set(0, c * e); te.set(4, -f); te.set(8, d * e); te.set(1, ac * f + bd); te.set(5, a * e); te.set(9, ad * f - bc); te.set(2, bc * f - ad); te.set(6, b * e); te.set(10, bd * f + ac); } return this; }
From source file:thothbot.parallax.core.shared.core.Matrix4.java
License:Open Source License
/** * Creates a frustum matrix.//from w w w . ja va 2 s .c o m */ public Matrix4 makeFrustum(double left, double right, double bottom, double top, double near, double far) { Float64Array te = this.getArray(); double x = 2.0 * near / (right - left); double y = 2.0 * near / (top - bottom); double a = (right + left) / (right - left); double b = (top + bottom) / (top - bottom); double c = -(far + near) / (far - near); double d = -2.0 * far * near / (far - near); te.set(0, x); te.set(4, 0); te.set(8, a); te.set(12, 0); te.set(1, 0); te.set(5, y); te.set(9, b); te.set(13, 0); te.set(2, 0); te.set(6, 0); te.set(10, c); te.set(14, d); te.set(3, 0); te.set(7, 0); te.set(11, -1); te.set(15, 0); return this; }