List of usage examples for com.google.gwt.typedarrays.shared Float64Array get
double get(int index);
From source file:thothbot.parallax.core.shared.core.Frustum.java
License:Open Source License
/** * Setting planes of the Frustum from the projection matrix * /*from w ww . j av a 2s . co m*/ * @param m the projection matrix */ public void setFromMatrix(Matrix4 m) { Float64Array me = m.getArray(); double me0 = me.get(0), me1 = me.get(1), me2 = me.get(2), me3 = me.get(3); double me4 = me.get(4), me5 = me.get(5), me6 = me.get(6), me7 = me.get(7); double me8 = me.get(8), me9 = me.get(9), me10 = me.get(10), me11 = me.get(11); double me12 = me.get(12), me13 = me.get(13), me14 = me.get(14), me15 = me.get(15); planes.get(0).set(me3 - me0, me7 - me4, me11 - me8, me15 - me12); planes.get(1).set(me3 + me0, me7 + me4, me11 + me8, me15 + me12); planes.get(2).set(me3 + me1, me7 + me5, me11 + me9, me15 + me13); planes.get(3).set(me3 - me1, me7 - me5, me11 - me9, me15 - me13); planes.get(4).set(me3 - me2, me7 - me6, me11 - me10, me15 - me14); planes.get(5).set(me3 + me2, me7 + me6, me11 + me10, me15 + me14); for (int i = 0; i < 6; i++) { Vector4 plane = planes.get(i); plane.divide(Math.sqrt(plane.x * plane.x + plane.y * plane.y + plane.z * plane.z)); } }
From source file:thothbot.parallax.core.shared.core.Frustum.java
License:Open Source License
/** * Checking if the 3D object located inside Frustum. * // w w w. j a v a2 s.c om * @param object any of 3D object */ public boolean contains(GeometryObject object) { Matrix4 matrix = object.getMatrixWorld(); Float64Array me = matrix.getArray(); double radius = object.getGeometryBuffer() != null ? -object.getGeometryBuffer().getBoundingSphere().radius * matrix.getMaxScaleOnAxis() : -object.getGeometry().getBoundingSphere().radius * matrix.getMaxScaleOnAxis(); for (int i = 0; i < 6; i++) { Vector4 plane = planes.get(i); double distance = plane.getX() * me.get(12) + plane.getY() * me.get(13) + plane.getZ() * me.get(14) + plane.getW(); if (distance <= radius) return false; } return true; }
From source file:thothbot.parallax.core.shared.core.GeometryBuffer.java
License:Open Source License
@Override public void computeBoundingBox() { if (getBoundingBox() == null) { setBoundingBox(new BoundingBox( new Vector3(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY), new Vector3(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY))); }//from w w w .j a va2 s . c o m BoundingBox boundingBox = getBoundingBox(); Float64Array positions = getWebGlVertexArray(); if (positions != null) { for (int i = 0, il = positions.length(); i < il; i += 3) { double x = positions.get(i); double y = positions.get(i + 1); double z = positions.get(i + 2); // bounding box if (x < boundingBox.min.getX()) { boundingBox.min.setX(x); } else if (x > boundingBox.max.getX()) { boundingBox.max.setX(x); } if (y < boundingBox.min.getY()) { boundingBox.min.setY(y); } else if (y > boundingBox.max.getY()) { boundingBox.max.setY(y); } if (z < boundingBox.min.getZ()) { boundingBox.min.setZ(z); } else if (z > boundingBox.max.getZ()) { boundingBox.max.setZ(z); } } } if (positions == null || positions.length() == 0) { this.boundingBox.min.set(0, 0, 0); this.boundingBox.max.set(0, 0, 0); } }
From source file:thothbot.parallax.core.shared.core.GeometryBuffer.java
License:Open Source License
@Override public void computeBoundingSphere() { if (getBoundingSphere() == null) setBoundingSphere(new BoundingSphere(0)); Float64Array positions = getWebGlVertexArray(); if (positions != null) { double maxRadiusSq = 0; for (int i = 0, il = positions.length(); i < il; i += 3) { double x = positions.get(i); double y = positions.get(i + 1); double z = positions.get(i + 2); double radiusSq = x * x + y * y + z * z; if (radiusSq > maxRadiusSq) maxRadiusSq = radiusSq;//from w w w .ja v a 2s .c o m } this.boundingSphere.radius = Math.sqrt(maxRadiusSq); } }
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 {//from w w w . jav a2 s . com // 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 handleTriangle(List<Vector3> tan1, List<Vector3> tan2, int a, int b, int c) { Float64Array positions = getWebGlVertexArray(); Float64Array uvs = getWebGlUvArray(); double xA = positions.get(a * 3); double yA = positions.get(a * 3 + 1); double zA = positions.get(a * 3 + 2); double xB = positions.get(b * 3); double yB = positions.get(b * 3 + 1); double zB = positions.get(b * 3 + 2); double xC = positions.get(c * 3); double yC = positions.get(c * 3 + 1); double zC = positions.get(c * 3 + 2); double uA = uvs.get(a * 2); double vA = uvs.get(a * 2 + 1); double uB = uvs.get(b * 2); double vB = uvs.get(b * 2 + 1); double uC = uvs.get(c * 2); double vC = uvs.get(c * 2 + 1); double x1 = xB - xA; double x2 = xC - xA; double y1 = yB - yA; double y2 = yC - yA; double z1 = zB - zA; double z2 = zC - zA; double s1 = uB - uA; double s2 = uC - uA; double t1 = vB - vA; double t2 = vC - vA; double r = 1.0 / (s1 * t2 - s2 * t1); Vector3 sdir = new Vector3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r); Vector3 tdir = new Vector3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r); tan1.get(a).add(sdir);/*from www . j a va 2 s.c om*/ tan1.get(b).add(sdir); tan1.get(c).add(sdir); tan2.get(a).add(tdir); tan2.get(b).add(tdir); tan2.get(c).add(tdir); }
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();/*w w w. j av a2 s .c o m*/ 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
/** * Sets the value of this matrix to the matrix inverse of the passed matrix * m.// ww w . ja va 2 s . c om * * @param m the matrix to be inverted */ public void getInverse(Matrix4 m) { // input: THREE.Matrix4 // ( based on http://code.google.com/p/webgl-mjs/ ) Float64Array me = m.getArray(); double a11 = me.get(10) * me.get(5) - me.get(6) * me.get(9); double a21 = -me.get(10) * me.get(1) + me.get(2) * me.get(9); double a31 = me.get(6) * me.get(1) - me.get(2) * me.get(5); double a12 = -me.get(10) * me.get(4) + me.get(6) * me.get(8); double a22 = me.get(10) * me.get(0) - me.get(2) * me.get(8); double a32 = -me.get(6) * me.get(0) + me.get(2) * me.get(4); double a13 = me.get(9) * me.get(4) - me.get(5) * me.get(8); double a23 = -me.get(9) * me.get(0) + me.get(1) * me.get(8); double a33 = me.get(5) * me.get(0) - me.get(1) * me.get(4); double det = me.get(0) * a11 + me.get(1) * a12 + me.get(2) * a13; // no inverse if (det == 0) Log.error("Matrix3.invert(): determinant == 0"); double idet = 1.0 / det; this.getArray().set(0, idet * a11); this.getArray().set(1, idet * a21); this.getArray().set(2, idet * a31); this.getArray().set(3, idet * a12); this.getArray().set(4, idet * a22); this.getArray().set(5, idet * a32); this.getArray().set(6, idet * a13); this.getArray().set(7, idet * a23); this.getArray().set(8, idet * a33); }
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 w w . j a va 2s. com*/ 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] /* w ww. ja v a2 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; }