/** Move the listener with the a camera - for 3D audio. */ @Override public void simpleUpdate(float tpf) { listener.setLocation(cam.getLocation()); listener.setRotation(cam.getRotation()); }
public void onAction(String name, boolean value, float tpf) { if (!value) { return; } if (name.equals(INPUT_MAPPING_CAMERA_POS)) { Camera cam = app.getCamera(); if (cam != null) { Vector3f loc = cam.getLocation(); Quaternion rot = cam.getRotation(); System.out.println("Camera Position: (" + loc.x + ", " + loc.y + ", " + loc.z + ")"); System.out.println("Camera Rotation: " + rot); System.out.println("Camera Direction: " + cam.getDirection()); System.out.println("cam.setLocation(new Vector3f(" + loc.x + "f, " + loc.y + "f, " + loc.z + "f));"); System.out.println("cam.setRotation(new Quaternion(" + rot.getX() + "f, " +rot.getY()+ "f, " + rot.getZ() + "f, " + rot.getW() + "f));"); } } else if (name.equals(INPUT_MAPPING_MEMORY)) { BufferUtils.printCurrentDirectMemory(null); } } }
/** * Get the observer final rotation within the scene. * @return the observer final rotation within the scene. * @see #getFinalObserverPosition() */ public Quaternion getFinalObserverRotation() { if( viewmanager == null ) { if( observer == null ) { return getCamera().getRotation(); } else return observer.getWorldRotation(); } if( observer == null ) { tempq.set(dummyCam.getRotation()); } else { tempq.set(observer.getWorldRotation()); } return tempq.multLocal(VRhardware.getOrientation()); }
@Override public Quaternion getFinalObserverRotation(int index) { if (environment != null) { VRViewManager vrvm = environment.getVRViewManager(); if (vrvm != null) { if (isInputDeviceTracking(index) == false) { return null; } Object obs = environment.getObserver(); if (obs instanceof Camera) { tempq.set(((Camera) obs).getRotation()); } else { tempq.set(((Spatial) obs).getWorldRotation()); } return tempq.multLocal(getOrientation(index)); } else { throw new IllegalStateException("VR environment has no valid view manager."); } } else { throw new IllegalStateException("VR input is not attached to a VR environment."); } }
@Override public Quaternion getFinalObserverRotation(int index) { if (environment != null){ OpenVRViewManager vrvm = (OpenVRViewManager)environment.getVRViewManager(); if (vrvm != null){ if(isInputDeviceTracking(index) == false ){ return null; } Object obs = environment.getObserver(); if( obs instanceof Camera ) { tempq.set(((Camera)obs).getRotation()); } else { tempq.set(((Spatial)obs).getWorldRotation()); } return tempq.multLocal(getOrientation(index)); } else { throw new IllegalStateException("VR environment has no valid view manager."); } } else { throw new IllegalStateException("VR input is not attached to a VR environment."); } }
@Override protected void updateShadowCams(Camera viewCam) { if (light == null) { logger.warning("The light can't be null for a " + getClass().getName()); return; } float zFar = zFarOverride; if (zFar == 0) { zFar = viewCam.getFrustumFar(); } //We prevent computing the frustum points and splits with zeroed or negative near clip value float frustumNear = Math.max(viewCam.getFrustumNear(), 0.001f); ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points); //shadowCam.setDirection(direction); shadowCam.setFrustumPerspective(light.getSpotOuterAngle() * FastMath.RAD_TO_DEG * 2.0f, 1, 1f, light.getSpotRange()); shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp()); shadowCam.setLocation(light.getPosition()); shadowCam.update(); shadowCam.updateViewProjection(); }
/** * * @param viewCam * @return */ @Override protected boolean checkCulling(Camera viewCam) { Camera cam = viewCam; if(frustumCam != null){ cam = frustumCam; cam.setLocation(viewCam.getLocation()); cam.setRotation(viewCam.getRotation()); } TempVars vars = TempVars.get(); boolean intersects = light.intersectsFrustum(cam,vars); vars.release(); return intersects; }
@Override public Quaternion getFinalObserverRotation(int index) { OSVRViewManager vrvm = (OSVRViewManager)environment.getVRViewManager(); if( vrvm == null || isInputDeviceTracking(index) == false ) return null; Object obs = environment.getObserver(); if( obs instanceof Camera ) { tempq.set(((Camera)obs).getRotation()); } else { tempq.set(((Spatial)obs).getWorldRotation()); } return tempq.multLocal(getOrientation(index)); }
@Override public Vector3f getFinalObserverPosition(int index) { if (environment != null) { VRViewManager vrvm = (VRViewManager) environment.getVRViewManager(); if (vrvm != null) { if (isInputDeviceTracking(index) == false) { return null; } Object obs = environment.getObserver(); Vector3f pos = getPosition(index); if (obs instanceof Camera) { ((Camera) obs).getRotation().mult(pos, pos); return pos.addLocal(((Camera) obs).getLocation()); } else { ((Spatial) obs).getWorldRotation().mult(pos, pos); return pos.addLocal(((Spatial) obs).getWorldTranslation()); } } else { throw new IllegalStateException("VR environment has no valid view manager."); } } else { throw new IllegalStateException("VR input is not attached to a VR environment."); } }
/** * Get the observer final rotation within the scene. * @return the observer final rotation within the scene. * @see #getFinalObserverPosition() */ public Quaternion getFinalObserverRotation() { if( environment.getVRViewManager() == null ) { if( environment.getObserver() == null ) { return environment.getCamera().getRotation(); } else { return ((Spatial)environment.getObserver()).getWorldRotation(); } } if( environment.getObserver() == null ) { tempq.set(environment.getDummyCamera().getRotation()); } else { tempq.set(((Spatial)environment.getObserver()).getWorldRotation()); } return tempq.multLocal(environment.getVRHardware().getOrientation()); }
/** * Forcefully takes over Camera adding functionality and placing it behind the character * @param tpf Tickes Per Frame */ private void camTakeOver(float tpf) { cam.setLocation(player.getLocalTranslation().add(-8, 2, 0)); cam.lookAt(player.getLocalTranslation(), Vector3f.UNIT_Y); Quaternion rot = new Quaternion(); rot.fromAngleNormalAxis(camAngle, Vector3f.UNIT_Z); cam.setRotation(cam.getRotation().mult(rot)); camAngle *= FastMath.pow(.99f, fpsRate * tpf); }
@Override public Quaternion getFinalObserverRotation(int index) { // Copied from OpenVRInput VREnvironment env = hardware.getEnvironment(); OculusViewManager vrvm = (OculusViewManager) hardware.getEnvironment().getVRViewManager(); Object obs = env.getObserver(); Quaternion tempq = new Quaternion(); // TODO move to class scope? if (obs instanceof Camera) { tempq.set(((Camera) obs).getRotation()); } else { tempq.set(((Spatial) obs).getWorldRotation()); } return tempq.multLocal(getOrientation(index)); }
@Override public Vector3f getFinalObserverPosition(int index) { OSVRViewManager vrvm = (OSVRViewManager) environment.getVRViewManager(); if( vrvm == null || isInputDeviceTracking(index) == false ) return null; Object obs = environment.getObserver(); Vector3f pos = getPosition(index); if( obs instanceof Camera ) { ((Camera)obs).getRotation().mult(pos, pos); return pos.addLocal(((Camera)obs).getLocation()); } else { ((Spatial)obs).getWorldRotation().mult(pos, pos); return pos.addLocal(((Spatial)obs).getWorldTranslation()); } }
/** * Get the observer final position within the scene. * @return the observer position. * @see #getFinalObserverRotation() */ public Vector3f getFinalObserverPosition() { if( viewmanager == null ) { if( observer == null ) { return getCamera().getLocation(); } else return observer.getWorldTranslation(); } Vector3f pos = VRhardware.getPosition(); if( observer == null ) { dummyCam.getRotation().mult(pos, pos); return pos.addLocal(dummyCam.getLocation()); } else { observer.getWorldRotation().mult(pos, pos); return pos.addLocal(observer.getWorldTranslation()); } }
@Override public Vector3f getFinalObserverPosition(int index) { // Copied from OpenVRInput VREnvironment env = hardware.getEnvironment(); OculusViewManager vrvm = (OculusViewManager) hardware.getEnvironment().getVRViewManager(); Object obs = env.getObserver(); Vector3f pos = getPosition(index); if (obs instanceof Camera) { ((Camera) obs).getRotation().mult(pos, pos); return pos.addLocal(((Camera) obs).getLocation()); } else { ((Spatial) obs).getWorldRotation().mult(pos, pos); return pos.addLocal(((Spatial) obs).getWorldTranslation()); } }
@Override public void simpleUpdate(float tpf) { if(forward){ model.move(model.getLocalRotation().multLocal(new Vector3f(0,0,1)).multLocal(tpf)); }else if(backward){ model.move(model.getLocalRotation().multLocal(new Vector3f(0,0,1)).multLocal(-tpf)); }else if(leftRotate){ model.rotate(0, tpf, 0); }else if(rightRotate){ model.rotate(0, -tpf, 0); } fpsText.setText(cam.getLocation() + "/" + cam.getRotation()); }
@Override public void render(RenderManager rm) { if (!isEnabled() || listener == null) { return; } Vector3f lastLocation = listener.getLocation(); Vector3f currentLocation = camera.getLocation(); Vector3f velocity = listener.getVelocity(); if (!lastLocation.equals(currentLocation)) { velocity.set(currentLocation).subtractLocal(lastLocation); velocity.multLocal(1f / lastTpf); listener.setLocation(currentLocation); listener.setVelocity(velocity); } else if (!velocity.equals(Vector3f.ZERO)) { listener.setVelocity(Vector3f.ZERO); } Quaternion lastRotation = listener.getRotation(); Quaternion currentRotation = camera.getRotation(); if (!lastRotation.equals(currentRotation)) { listener.setRotation(currentRotation); } }
public void postQueue(RenderQueue rq) { Camera sceneCam = rm.getCurrentCamera(); //update refraction cam refractionCam.setLocation(sceneCam.getLocation()); refractionCam.setRotation(sceneCam.getRotation()); refractionCam.setFrustum(sceneCam.getFrustumNear(), sceneCam.getFrustumFar(), sceneCam.getFrustumLeft(), sceneCam.getFrustumRight(), sceneCam.getFrustumTop(), sceneCam.getFrustumBottom()); refractionCam.setParallelProjection(sceneCam.isParallelProjection()); //update reflection cam WaterUtils.updateReflectionCam(reflectionCam, plane, sceneCam); //Rendering reflection and refraction rm.renderViewPort(reflectionView, savedTpf); rm.renderViewPort(refractionView, savedTpf); rm.getRenderer().setFrameBuffer(vp.getOutputFrameBuffer()); rm.setCamera(sceneCam, false); }
@Override protected void controlUpdate(float tpf) { if (spatial != null && camera != null) { switch (controlDir) { case SpatialToCamera: camera.setLocation(spatial.getWorldTranslation()); camera.setRotation(spatial.getWorldRotation()); break; case CameraToSpatial: // set the localtransform, so that the worldtransform would be equal to the camera's transform. // Location: TempVars vars = TempVars.get(); Vector3f vecDiff = vars.vect1.set(camera.getLocation()).subtractLocal(spatial.getWorldTranslation()); spatial.setLocalTranslation(vecDiff.addLocal(spatial.getLocalTranslation())); // Rotation: Quaternion worldDiff = vars.quat1.set(camera.getRotation()).subtractLocal(spatial.getWorldRotation()); spatial.setLocalRotation(worldDiff.addLocal(spatial.getLocalRotation())); vars.release(); break; } } }
/** * Get the observer final position within the scene. * @return the observer position. * @see #getFinalObserverRotation() */ public Vector3f getFinalObserverPosition() { if( environment.getVRViewManager() == null ) { if( environment.getObserver() == null ) { return environment.getCamera().getLocation(); } else{ return ((Spatial)environment.getObserver()).getWorldTranslation(); } } Vector3f pos = environment.getVRHardware().getPosition(); if( environment.getObserver() == null ) { environment.getDummyCamera().getRotation().mult(pos, pos); return pos.addLocal(environment.getDummyCamera().getLocation()); } else { ((Spatial)environment.getObserver()).getWorldRotation().mult(pos, pos); return pos.addLocal(((Spatial)environment.getObserver()).getWorldTranslation()); } }