/** * Angle around the Y axis, counter-clockwise when looking from above. */ protected double azimuth( Vector3 vector ) { return Math.atan2( vector.getZ(), -vector.getX() ); }
@Override public void update() { double vecX = -LensFlare.this.positionScreen.getX() * 2.0; double vecY = -LensFlare.this.positionScreen.getY() * 2.0; for( int f = 0; f < LensFlare.this.lensFlares.size(); f ++ ) { LensSprite flare = LensFlare.this.lensFlares.get( f ); flare.x = LensFlare.this.positionScreen.getX() + vecX * flare.distance; flare.y = LensFlare.this.positionScreen.getY() + vecY * flare.distance; flare.wantedRotation = flare.x * Math.PI * 0.25; flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25; } } });
@Override public Vector3 getPoint(double t) { Vector3 v = new Vector3(); // This needs to be from 0-length +1 double point = points.size() * t; int intPoint = (int) Math.floor( point ); double weight = point - intPoint; intPoint += intPoint > 0 ? 0 : ( Math.abs( intPoint ) / points.size() + 1 ) * points.size(); int c0 = ( intPoint - 1 ) % points.size(); int c1 = ( intPoint ) % points.size(); int c2 = ( intPoint + 1 ) % points.size(); int c3 = ( intPoint + 2 ) % points.size(); v.setX( CurveUtils.interpolate( points.get(c0).getX(), points.get(c1).getX(), points.get(c2).getX(), points.get(c3).getX(), weight) ); v.setY( CurveUtils.interpolate( points.get(c0).getY(), points.get(c1).getY(), points.get(c2).getY(), points.get(c3).getY(), weight) ); v.setZ( CurveUtils.interpolate( points.get(c0).getZ(), points.get(c1).getZ(), points.get(c2).getZ(), points.get(c3).getZ(), weight) ); return v; } }
@Override public Vector3 getPoint(double t) { Vector3 v = new Vector3(); double point = ( points.size() - 1.0 ) * t; int intPoint = (int) Math.floor( point ); double weight = point - intPoint; int c0 = intPoint == 0 ? intPoint : intPoint - 1; int c1 = intPoint; int c2 = intPoint > points.size() - 2 ? points.size() -1 : intPoint + 1; int c3 = intPoint > points.size() - 3 ? points.size() -1 : intPoint + 2; v.setX( CurveUtils.interpolate( points.get(c0).getX(), points.get(c1).getX(), points.get(c2).getX(), points.get(c3).getX(), weight) ); v.setY( CurveUtils.interpolate( points.get(c0).getY(), points.get(c1).getY(), points.get(c2).getY(), points.get(c3).getY(), weight) ); v.setZ( CurveUtils.interpolate( points.get(c0).getZ(), points.get(c1).getZ(), points.get(c2).getZ(), points.get(c3).getZ(), weight) ); return v; } }
public static List<Vector2> generateTopUV( Geometry geometry, int indexA, int indexB, int indexC ) { double ax = geometry.getVertices().get( indexA ).getX(); double ay = geometry.getVertices().get( indexA ).getY(); double bx = geometry.getVertices().get( indexB ).getX(); double by = geometry.getVertices().get( indexB ).getY(); double cx = geometry.getVertices().get( indexC ).getX(); double cy = geometry.getVertices().get( indexC ).getY(); return Arrays.asList( new Vector2( ax, 1 - ay ), new Vector2( bx, 1 - by ), new Vector2( cx, 1 - cy ) ); }
@Override public Vector3 getPoint(double t) { double tx = ShapeUtils.b3(t, this.v0.getX(), this.v1.getX(), this.v2.getX(), this.v3.getX()); double ty = ShapeUtils.b3(t, this.v0.getY(), this.v1.getY(), this.v2.getY(), this.v3.getY()); double tz = ShapeUtils.b3(t, this.v0.getZ(), this.v1.getZ(), this.v2.getZ(), this.v3.getZ()); return new Vector3(tx, ty, tz); }
public Vector3 clone() { return new Vector3(this.getX(), this.getY(), this.getZ()); }
/** * Set value of the vector from another vector. * * @param v the other vector * * @return the current vector */ public Vector3 copy(Vector3 v) { this.set(v.getX(), v.getY(), v.getZ()); return this; }
@Override public Vector3 getPoint(double t) { double tx = ShapeUtils.b2(t, this.v0.getX(), this.v1.getX(), this.v2.getX()); double ty = ShapeUtils.b2(t, this.v0.getY(), this.v1.getY(), this.v2.getY()); double tz = ShapeUtils.b2(t, this.v0.getZ(), this.v1.getZ(), this.v2.getZ()); return new Vector3(tx, ty, tz); } }
@Override public void raycast(Raycaster raycaster, List<Raycaster.Intersect> intersects) { Vector3 matrixPosition = new Vector3(); matrixPosition.setFromMatrixPosition( this.matrixWorld ); double distance = raycaster.getRay().distanceToPoint( matrixPosition ); if ( distance > this.scale.getX() ) { return; } Raycaster.Intersect intersect = new Raycaster.Intersect(); intersect.distance = distance; intersect.point = this.position; intersect.object = this; intersects.add( intersect ); }
/** * Texture fixing helper. Spheres have some odd behaviours. */ protected Vector2 correctUV( Vector2 uv, Vector3 vector, double azimuth ) { if ( (azimuth < 0) && (uv.getX() == 1) ) uv = new Vector2( uv.getX() - 1.0, uv.getY() ); if ( (vector.getX() == 0) && (vector.getZ() == 0) ) uv = new Vector2( azimuth / 2.0 / Math.PI + 0.5, uv.getY() ); return uv.clone(); } }
public void setDirection( Vector3 dir ) { Vector3 axis = new Vector3(); double radians; // dir is assumed to be normalized if ( dir.getY() > 0.99999 ) { this.quaternion.set( 0, 0, 0, 1 ); } else if ( dir.getY() < - 0.99999 ) { this.quaternion.set( 1, 0, 0, 0 ); } else { axis.set( dir.getZ(), 0, - dir.getX() ).normalize(); radians = Math.acos( dir.getY() ); this.quaternion.setFromAxisAngle( axis, radians ); } }
private void testPoint(Raycaster raycaster, List<Raycaster.Intersect> intersects, Ray ray, Vector3 point, int index ) { double rayPointDistance = ray.distanceToPoint( point ); double localThreshold = RAYCASTER_THRESHOLD / ( ( this.scale.getX() + this.scale.getY() + this.scale.getZ() ) / 3.0 ); if ( rayPointDistance < localThreshold ) { Vector3 intersectPoint = ray.closestPointToPoint( point ); intersectPoint.apply( this.getMatrixWorld() ); double distance = raycaster.getRay().getOrigin().distanceTo( intersectPoint ); Raycaster.Intersect intersect = new Raycaster.Intersect(); intersect.distance = distance; intersect.distanceToRay = rayPointDistance; intersect.point = intersectPoint.clone(); intersect.object = this; intersects.add( intersect ); } }
/** * Setting position values of the current matrix to the values of * input vector. * * @param v the input vector * * @return the current matrix */ public Matrix4 setPosition(Vector3 v) { this.getArray().set(12, v.getX()); this.getArray().set(13, v.getY()); this.getArray().set(14, v.getZ()); return this; }
public Vector3 center() { this.computeBoundingBox(); Vector3 offset = new Vector3(); offset.add( this.boundingBox.getMin(), this.boundingBox.getMax() ); offset.multiply( - 0.5 ); this.applyMatrix( new Matrix4().makeTranslation( offset.getX(), offset.getY(), offset.getZ() ) ); this.computeBoundingBox(); return offset; }
public void update( double delta ) { delta *= 0.0001; double moveMult = delta * this.movementSpeed; double rotMult = delta * this.rollSpeed; getObject().translateX( this.moveVector.getX() * moveMult ); getObject().translateY( this.moveVector.getY() * moveMult ); getObject().translateZ( this.moveVector.getZ() * moveMult ); this.tmpQuaternion.set( this.rotationVector.getX() * rotMult, this.rotationVector.getY() * rotMult, this.rotationVector.getZ() * rotMult, 1.0).normalize(); getObject().getQuaternion().multiply( this.tmpQuaternion ); // expose the rotation vector for convenience getObject().getRotation().setFromQuaternion( getObject().getQuaternion(), getObject().getRotation().getOrder() ); }
@Override public void setupRendererLights(RendererLights zlights, boolean isGammaInput) { Float32Array pointColors = zlights.point.colors; Float32Array pointPositions = zlights.point.positions; Float32Array pointDistances = zlights.point.distances; double intensity = getIntensity(); double distance = getDistance(); int pointOffset = pointColors.getLength(); if ( isGammaInput ) setColorGamma( pointColors, pointOffset, getColor(), intensity ); else setColorLinear( pointColors, pointOffset, getColor(), intensity ); Vector3 position = new Vector3(); position.setFromMatrixPosition( getMatrixWorld() ); pointPositions.set(pointOffset, position.getX()); pointPositions.set(pointOffset + 1, position.getY()); pointPositions.set(pointOffset + 2, position.getZ()); pointDistances.set(pointOffset / 3, distance); } }
private Vector3 getMouseProjectionOnBall ( int clientX, int clientY ) { Vector3 mouseOnBall = new Vector3( ( clientX - getContext().getWidth() * 0.5) / this.radius, ( getContext().getHeight() * 0.5 - clientY ) / this.radius, 0.0 ); double length = mouseOnBall.length(); if ( length > 1.0 ) mouseOnBall.normalize(); else mouseOnBall.setZ( Math.sqrt( 1.0 - length * length ) ); eye.copy( getObject().getPosition() ).sub( this.target ); Vector3 projection = getObject().getUp().clone().setLength( mouseOnBall.getY() ); projection.add( getObject().getUp().clone().cross( eye ).setLength( mouseOnBall.getX() ) ); projection.add( eye.setLength( mouseOnBall.getZ() ) ); return projection; }
private void handleVertex( Vector3[] tan1, Vector3[] tan2, Float32Array normals, Float32Array tangents, int v ) { Vector3 tmp = new Vector3(), tmp2 = new Vector3(); Vector3 n = new Vector3(), n2 = new Vector3(); n.fromArray( normals, v * 3 ); n2.copy( n ); Vector3 t = tan1[ v ]; // Gram-Schmidt orthogonalize tmp.copy( t ); tmp.sub( n.multiply( n.dot( t ) ) ).normalize(); // Calculate handedness tmp2.cross( n2, t ); double test = tmp2.dot( tan2[ 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); }