List of usage examples for com.google.gwt.typedarrays.shared Float64Array length
int length();
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 ww w.j a v a 2 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;//ww w . j av a 2s .c om } 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 {/* w w w. j a va 2s . 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
/** * Based on < href="http://www.terathon.com/code/tangent.html">terathon.com</a> * (per vertex tangents)/*from www. j a v a 2 s. c o m*/ */ @Override public void computeTangents() { if (getWebGlIndexArray() == null || getWebGlVertexArray() == null || getWebGlNormalArray() == null || getWebGlUvArray() == null) { Log.warn( "Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()"); return; } Int16Array indices = getWebGlIndexArray(); Float64Array positions = getWebGlVertexArray(); getWebGlNormalArray(); getWebGlUvArray(); int nVertices = positions.length() / 3; if (getWebGlTangentArray() == null) { int nTangentElements = 4 * nVertices; setWebGlTangentArray(TypedArrays.createFloat64Array(nTangentElements)); } getWebGlTangentArray(); List<Vector3> tan1 = new ArrayList<Vector3>(); List<Vector3> tan2 = new ArrayList<Vector3>(); for (int k = 0; k < nVertices; k++) { tan1.add(new Vector3()); tan2.add(new Vector3()); } List<GeometryBuffer.Offset> offsets = this.offsets; 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 iA = index + indices.get(i); int iB = index + indices.get(i + 1); int iC = index + indices.get(i + 2); handleTriangle(tan1, tan2, iA, iB, iC); } } 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 iA = index + indices.get(i); int iB = index + indices.get(i + 1); int iC = index + indices.get(i + 2); handleVertex(tan1, tan2, iA); handleVertex(tan1, tan2, iB); handleVertex(tan1, tan2, iC); } } this.setHasTangents(true); this.setTangentsNeedUpdate(true); }
From source file:thothbot.parallax.core.shared.lights.AmbientLight.java
License:Open Source License
@Override public void setupRendererLights(RendererLights zlights, boolean isGammaInput) { Float64Array colors = zlights.ambient.colors; Color color = getColor();/*from w w w. ja v a 2 s . c om*/ double r = 0, g = 0, b = 0; if (colors.length() == 3) { r = colors.get(0); g = colors.get(1); b = colors.get(2); } if (isGammaInput) { r += color.getR() * color.getR(); g += color.getG() * color.getG(); b += color.getB() * color.getB(); } else { r += color.getR(); g += color.getG(); b += color.getB(); } colors.set(0, r); colors.set(1, g); colors.set(2, b); }
From source file:thothbot.parallax.core.shared.lights.DirectionalLight.java
License:Open Source License
@Override public void setupRendererLights(RendererLights zlights, boolean isGammaInput) { Float64Array dirColors = zlights.directional.colors; Float64Array dirPositions = zlights.directional.positions; double intensity = getIntensity(); int dirOffset = dirColors.length(); if (isGammaInput) setColorGamma(dirColors, dirOffset, getColor(), intensity); else/*ww w . j a v a 2 s . co m*/ setColorLinear(dirColors, dirOffset, getColor(), intensity); Vector3 position = new Vector3(); position.copy(getMatrixWorld().getPosition()); position.sub(getTarget().getMatrixWorld().getPosition()); position.normalize(); dirPositions.set(dirOffset, position.getX()); dirPositions.set(dirOffset + 1, position.getY()); dirPositions.set(dirOffset + 2, position.getZ()); }
From source file:thothbot.parallax.core.shared.lights.HemisphereLight.java
License:Open Source License
@Override public void setupRendererLights(RendererLights zlights, boolean isGammaInput) { Float64Array hemiSkyColors = zlights.hemi.skyColors; Float64Array hemiGroundColors = zlights.hemi.groundColors; Float64Array hemiPositions = zlights.hemi.positions; Color skyColor = getColor();//from w w w . ja va2 s.co m Color groundColor = getGroundColor(); double intensity = getIntensity(); int hemiOffset = hemiSkyColors.length() * 3; if (isGammaInput) { setColorGamma(hemiSkyColors, hemiOffset, skyColor, intensity); setColorGamma(hemiGroundColors, hemiOffset, groundColor, intensity); } else { setColorLinear(hemiSkyColors, hemiOffset, skyColor, intensity); setColorLinear(hemiGroundColors, hemiOffset, groundColor, intensity); } Vector3 position = getMatrixWorld().getPosition(); hemiPositions.set(hemiOffset, position.getX()); hemiPositions.set(hemiOffset + 1, position.getY()); hemiPositions.set(hemiOffset + 2, position.getZ()); }
From source file:thothbot.parallax.core.shared.lights.PointLight.java
License:Open Source License
@Override public void setupRendererLights(RendererLights zlights, boolean isGammaInput) { Float64Array pointColors = zlights.point.colors; Float64Array pointPositions = zlights.point.positions; Float64Array pointDistances = zlights.point.distances; double intensity = getIntensity(); double distance = getDistance(); int pointOffset = pointColors.length(); if (isGammaInput) setColorGamma(pointColors, pointOffset, getColor(), intensity); else//from w w w .jav a 2s .com setColorLinear(pointColors, pointOffset, getColor(), intensity); Vector3 position = getMatrixWorld().getPosition(); pointPositions.set(pointOffset, position.getX()); pointPositions.set(pointOffset + 1, position.getY()); pointPositions.set(pointOffset + 2, position.getZ()); pointDistances.set(pointOffset / 3, distance); }
From source file:thothbot.parallax.core.shared.lights.SpotLight.java
License:Open Source License
@Override public void setupRendererLights(RendererLights zlights, boolean isGammaInput) { Float64Array spotColors = zlights.spot.colors; Float64Array spotPositions = zlights.spot.positions; Float64Array spotDistances = zlights.spot.distances; Float64Array spotDirections = zlights.spot.directions; Float64Array spotAngles = zlights.spot.angles; Float64Array spotExponents = zlights.spot.exponents; double intensity = getIntensity(); double distance = getDistance(); int spotOffset = spotColors.length(); if (isGammaInput) setColorGamma(spotColors, spotOffset, getColor(), intensity); else/*from w ww . j a va 2 s . c om*/ setColorLinear(spotColors, spotOffset, getColor(), intensity); Vector3 position = getMatrixWorld().getPosition(); spotPositions.set(spotOffset, position.getX()); spotPositions.set(spotOffset + 1, position.getY()); spotPositions.set(spotOffset + 2, position.getZ()); spotDistances.set(spotOffset / 3, distance); Vector3 direction = new Vector3(); direction.copy(position); direction.sub(getTarget().getMatrixWorld().getPosition()); direction.normalize(); spotDirections.set(spotOffset, direction.getX()); spotDirections.set(spotOffset + 1, direction.getY()); spotDirections.set(spotOffset + 2, direction.getZ()); spotAngles.set(spotOffset / 3, Math.cos(getAngle())); spotExponents.set(spotOffset / 3, getExponent()); }