public Plane normalize() { // Note: will lead to a divide by zero if the plane is invalid. double inverseNormalLength = 1.0 / this.normal.length(); this.normal.multiply(inverseNormalLength); this.constant *= inverseNormalLength; return this; }
public Vector3 setLength(double l) { double oldLength = this.length(); if ( oldLength != 0 && l != oldLength ) { this.multiply( l / oldLength ); } return this; }
/** * Normalizes this vector in place. */ @Override public Vector3 normalize() { return this.divide( this.length() ); }
public double distanceToPoint( Vector3 point ) { Vector3 clampedPoint = _v1.copy( point ).clamp( this.min, this.max ); return clampedPoint.sub( point ).length(); }
public double area() { _v0.sub( this.c, this.b ); _v1.sub( this.a, this.b ); return _v0.cross( _v1 ).length() * 0.5; }
public Sphere getBoundingSphere( Sphere optionalTarget ) { optionalTarget.setCenter( this.center() ); optionalTarget.setRadius( this.size( _v1 ).length() * 0.5 ); return optionalTarget; }
public Vector3 setFromMatrixScale( Matrix4 m ) { Float32Array el = m.getArray(); double sx = this.set( el.get(0), el.get(1), el.get(2) ).length(); double sy = this.set( el.get(4), el.get(5), el.get(6) ).length(); double sz = this.set( el.get(8), el.get(9), el.get(10) ).length(); this.x = sx; this.y = sy; this.z = sz; return this; }
vec.cross( tangents.get( i - 1 ), tangents.get( i ) ); if ( vec.length() > epsilon )
vec.cross( tangents.get( i - 1 ), tangents.get( i ) ); if ( vec.length() > epsilon )
private void rotateCamera() { double angle = Math.acos( rotateStart.dot( rotateEnd ) / rotateStart.length() / rotateEnd.length() ); if ( angle > 0 ) { Vector3 axis = ( new Vector3() ).cross( rotateStart, rotateEnd ).normalize(); Quaternion quaternion = new Quaternion(); angle *= this.rotateSpeed; quaternion.setFromAxisAngle( axis, -angle ); quaternion.multiplyVector3( eye ); quaternion.multiplyVector3( getObject().getUp() ); quaternion.multiplyVector3( rotateEnd ); if ( this.isStaticMoving ) { rotateStart = rotateEnd; } else { quaternion.setFromAxisAngle( axis, angle * ( this.dynamicDampingFactor - 1.0 ) ); quaternion.multiplyVector3( rotateStart ); } } } }
/** * Modifies the current matrix by looking at target on defined eye. * * @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) { Float32Array te = this.elements; _z.sub( eye, target ).normalize(); if ( _z.length() == 0 ) { _z.z = 1.0; } _x.cross( up, _z ).normalize(); if ( _x.length() == 0 ) { _z.x += 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; }
/** * Setting rotation values to the rotation values of the input matrix. * * @param m the input matrix */ public Matrix4 extractRotation(Matrix4 m) { Float32Array me = m.getArray(); Vector3 v1 = new Vector3(); double scaleX = 1.0 / v1.set(me.get(0), me.get(1), me.get(2)).length(); double scaleY = 1.0 / v1.set(me.get(4), me.get(5), me.get(6)).length(); double scaleZ = 1.0 / v1.set(me.get(8), me.get(9), me.get(10)).length(); this.getArray().set(0, me.get(0) * scaleX); this.getArray().set(1, me.get(1) * scaleX); this.getArray().set(2, me.get(2) * scaleX); this.getArray().set(4, me.get(4) * scaleY); this.getArray().set(5, me.get(5) * scaleY); this.getArray().set(6, me.get(6) * scaleY); this.getArray().set(8, me.get(8) * scaleZ); this.getArray().set(9, me.get(9) * scaleZ); this.getArray().set(10, me.get(10) * scaleZ); return this; }
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 panCamera() { Vector2 mouseChange = panEnd.clone().sub( panStart ); if ( mouseChange.lengthSq() > 0 ) { mouseChange.multiply( eye.length() * this.panSpeed ); Vector3 pan = eye.clone().cross( getObject().getUp() ).setLength( mouseChange.getX() ); pan.add( getObject().getUp().clone().setLength( mouseChange.getY() ) ); getObject().getPosition().add( pan ); this.target.add( pan ); if ( this.isStaticMoving ) panStart = panEnd; else panStart.add( mouseChange.sub( panEnd, panStart ).multiply( this.dynamicDampingFactor ) ); } }
&& ((HasRaytracingPhysicalAttenuation) light).isPhysicalAttenuation()) { attenuation = lightVector.length(); attenuation = 1.0 / (attenuation * attenuation);