public FirstPersonControls(Object3D object, RenderingContext context) { super(object, context); this.viewHalfX = context.getWidth() / 2; this.viewHalfY = context.getHeight() / 2; this.target = new Vector3(); context.getInput().addInputHandler( this ); }
private Raycaster.Intersect intersectObjects(int screenX, int screenY, List<Object3D> objects ) { double posX = (screenX / (double) this.context.getWidth() ) * 2.0 - 1.0; double posY = - (screenY / (double) this.context.getHeight() ) * 2.0 + 1.0; this.pointerVector.set(posX, posY,0.5); this.pointerVector.unproject(this.camera); this.ray.set(this.camera.getPosition(), this.pointerVector.sub(this.camera.getPosition()).normalize()); List<Raycaster.Intersect> intersections = this.ray.intersectObjects(objects,true); if(intersections!=null && !intersections.isEmpty()) { return intersections.get(0); } return null; }
public FlyControls(Object3D object, RenderingContext context) { super(object, context); this.viewHalfX = context.getWidth() / 2.0; this.viewHalfY = context.getHeight() / 2.0; // disable default target object behavior this.tmpQuaternion = new Quaternion(); this.mouseStatus = 0; this.moveState = new MoveState(); this.moveVector = new Vector3( 0, 0, 0 ); this.rotationVector = new Vector3( 0, 0, 0 ); context.getInput().addInputHandler( this ); }
public TrackballControls(Object3D object, RenderingContext context) { super(object, context); this.radius = ( context.getWidth() + context.getHeight() ) / 4.0; this.target = new Vector3(); this.lastPosition = new Vector3(); this.eye = new Vector3(); this.rotateStart = new Vector3(); this.rotateEnd = new Vector3(); this.zoomStart = new Vector2(); this.zoomEnd = new Vector2(); this.panStart = new Vector2(); this.panEnd = new Vector2(); context.getInput().addInputHandler( 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; }