viewport camera lockdown
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				studiorailgun/Renderer/pipeline/head This commit looks good
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	studiorailgun/Renderer/pipeline/head This commit looks good
				
			This commit is contained in:
		
							parent
							
								
									f78c8b6633
								
							
						
					
					
						commit
						d2a8acf027
					
				| @ -41,6 +41,9 @@ public class CameraHandler { | ||||
|     //if set to true, the camera will track the player's entity | ||||
|     boolean trackPlayerEntity = true; | ||||
| 
 | ||||
|     //sets whether the camera handler should update the player's camera or not | ||||
|     boolean update = true; | ||||
| 
 | ||||
|     /** | ||||
|      * Handles a mouse event | ||||
|      * @param event The mouse event | ||||
| @ -75,88 +78,90 @@ public class CameraHandler { | ||||
|      */ | ||||
|     public void updateGlobalCamera(){ | ||||
|         Globals.profiler.beginCpuSample("updateGlobalCamera"); | ||||
|         if(Globals.playerCamera != null){ | ||||
|             cameraSpeed = 2.5f * (float)Globals.timekeeper.getMostRecentRawFrametime(); | ||||
|         if(update){ | ||||
|             if(Globals.playerCamera != null){ | ||||
|                 cameraSpeed = 2.5f * (float)Globals.timekeeper.getMostRecentRawFrametime(); | ||||
| 
 | ||||
|             if(Crosshair.getCrosshairActive()){ | ||||
|                  | ||||
|                 // if(Globals.playerCharacter != null){ | ||||
|                 //     Vector3d charPos = EntityUtils.getPosition(Globals.playerCharacter); | ||||
|                 //     CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)charPos.x,(float)charPos.y,(float)charPos.z)); | ||||
|                 // } | ||||
|                  | ||||
|                 Vector3d characterPos = EntityUtils.getPosition(Globals.playerEntity); | ||||
|                 Vector3d targetPos = Crosshair.getTargetPosition(); | ||||
|                 Vector3d diffed = new Vector3d(targetPos).sub(characterPos).mul(-1).normalize(); | ||||
|                 cameraRotationVector.set((float)diffed.x, 0.5f, (float)diffed.z).normalize(); | ||||
|                  | ||||
|                 yaw = (float)Math.toDegrees(Math.atan2(diffed.z, diffed.x)); | ||||
|                  | ||||
|                 CameraEntityUtils.setCameraPitch(Globals.playerCamera, pitch); | ||||
|                 CameraEntityUtils.setCameraYaw(Globals.playerCamera, yaw); | ||||
|                  | ||||
|             } else { | ||||
|                 CameraEntityUtils.setCameraPitch(Globals.playerCamera, pitch); | ||||
|                 CameraEntityUtils.setCameraYaw(Globals.playerCamera, yaw); | ||||
|                 if(Crosshair.getCrosshairActive()){ | ||||
|                      | ||||
|                     // if(Globals.playerCharacter != null){ | ||||
|                     //     Vector3d charPos = EntityUtils.getPosition(Globals.playerCharacter); | ||||
|                     //     CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)charPos.x,(float)charPos.y,(float)charPos.z)); | ||||
|                     // } | ||||
|                      | ||||
|                     Vector3d characterPos = EntityUtils.getPosition(Globals.playerEntity); | ||||
|                     Vector3d targetPos = Crosshair.getTargetPosition(); | ||||
|                     Vector3d diffed = new Vector3d(targetPos).sub(characterPos).mul(-1).normalize(); | ||||
|                     cameraRotationVector.set((float)diffed.x, 0.5f, (float)diffed.z).normalize(); | ||||
|                      | ||||
|                     yaw = (float)Math.toDegrees(Math.atan2(diffed.z, diffed.x)); | ||||
|                      | ||||
|                     CameraEntityUtils.setCameraPitch(Globals.playerCamera, pitch); | ||||
|                     CameraEntityUtils.setCameraYaw(Globals.playerCamera, yaw); | ||||
|                      | ||||
|                 } else { | ||||
|                     CameraEntityUtils.setCameraPitch(Globals.playerCamera, pitch); | ||||
|                     CameraEntityUtils.setCameraYaw(Globals.playerCamera, yaw); | ||||
| 
 | ||||
|                 // System.out.println(pitch); | ||||
|                 // if(Globals.playerCharacter != null){ | ||||
|                 //     Vector3d charPos = EntityUtils.getPosition(Globals.playerCharacter); | ||||
|                 //     CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)charPos.x,(float)charPos.y,(float)charPos.z)); | ||||
|                 // } | ||||
|                     // System.out.println(pitch); | ||||
|                     // if(Globals.playerCharacter != null){ | ||||
|                     //     Vector3d charPos = EntityUtils.getPosition(Globals.playerCharacter); | ||||
|                     //     CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)charPos.x,(float)charPos.y,(float)charPos.z)); | ||||
|                     // } | ||||
| 
 | ||||
|                 Quaternionf pitchQuat = new Quaternionf().fromAxisAngleDeg(MathUtils.getLeftVectorf(), -pitch); | ||||
|                 Quaternionf yawQuat = new Quaternionf().fromAxisAngleDeg(MathUtils.getUpVectorf(), -yaw); | ||||
|                 // float yawRad = yaw / 180.0f * (float)Math.PI; | ||||
|                 // float pitchRad = pitch / 180.0f * (float)Math.PI; | ||||
|                 // float rollRad = 0.0f; | ||||
|                 // pitchQuat.mul(yawQuat); | ||||
|                 cameraRotationVector = pitchQuat.transform(MathUtils.getOriginVectorf()); | ||||
|                 cameraRotationVector = yawQuat.transform(cameraRotationVector); | ||||
|                 cameraRotationVector.normalize(); | ||||
|                     Quaternionf pitchQuat = new Quaternionf().fromAxisAngleDeg(MathUtils.getLeftVectorf(), -pitch); | ||||
|                     Quaternionf yawQuat = new Quaternionf().fromAxisAngleDeg(MathUtils.getUpVectorf(), -yaw); | ||||
|                     // float yawRad = yaw / 180.0f * (float)Math.PI; | ||||
|                     // float pitchRad = pitch / 180.0f * (float)Math.PI; | ||||
|                     // float rollRad = 0.0f; | ||||
|                     // pitchQuat.mul(yawQuat); | ||||
|                     cameraRotationVector = pitchQuat.transform(MathUtils.getOriginVectorf()); | ||||
|                     cameraRotationVector = yawQuat.transform(cameraRotationVector); | ||||
|                     cameraRotationVector.normalize(); | ||||
| 
 | ||||
| 
 | ||||
|                 // cameraRotationVector.x = 0 + (float) Math.cos(yaw / 180.0f * Math.PI) * 1; | ||||
|                 // cameraRotationVector.y = 0 + (float) Math.sin(pitch / 180.0f * Math.PI) * 1; | ||||
|                 // cameraRotationVector.z = 0 + (float) Math.sin(yaw / 180.0f * Math.PI) * 1; | ||||
|                 // cameraRotationVector.normalize(); | ||||
|                 // System.out.println(yaw + " " + pitch); | ||||
|                     // cameraRotationVector.x = 0 + (float) Math.cos(yaw / 180.0f * Math.PI) * 1; | ||||
|                     // cameraRotationVector.y = 0 + (float) Math.sin(pitch / 180.0f * Math.PI) * 1; | ||||
|                     // cameraRotationVector.z = 0 + (float) Math.sin(yaw / 180.0f * Math.PI) * 1; | ||||
|                     // cameraRotationVector.normalize(); | ||||
|                     // System.out.println(yaw + " " + pitch); | ||||
|                 } | ||||
|                 if(trackPlayerEntity && Globals.playerEntity != null){ | ||||
|                     Vector3d entityPos = EntityUtils.getPosition(Globals.playerEntity); | ||||
|                     CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)entityPos.x,(float)entityPos.y,(float)entityPos.z).add(CameraEntityUtils.getOrbitalCameraRadialOffset(Globals.playerCamera))); | ||||
|                 } | ||||
|                 //update view matrix offset | ||||
|                 float xFactor = (float)Math.cos(yaw / 180.0f * Math.PI); | ||||
|                 float yFactor = (float)Math.sin(yaw / 180.0f * Math.PI); | ||||
|                 Vector3f radialOffset = CameraEntityUtils.getOrbitalCameraRadialOffset(Globals.playerCamera); | ||||
|                 Vector3f trueOffset = new Vector3f(radialOffset).mul(xFactor,1.0f,yFactor); | ||||
|                 CameraEntityUtils.setOrbitalCameraRadialOffset(Globals.playerCamera, trueOffset); | ||||
|                 cameraRotationVector.mul(CameraEntityUtils.getOrbitalCameraDistance(Globals.playerCamera)); | ||||
|                 CameraEntityUtils.setCameraEye(Globals.playerCamera, cameraRotationVector); | ||||
| 
 | ||||
|                 //tell the server that we changed where we're looking, if we're in first person | ||||
|                 int perspectiveVal = CameraHandler.CAMERA_PERSPECTIVE_FIRST; | ||||
|                 if(Globals.controlHandler.cameraIsThirdPerson()){ | ||||
|                     perspectiveVal = CameraHandler.CAMERA_PERSPECTIVE_THIRD; | ||||
|                 } | ||||
|                 if(Globals.cameraHandler.getTrackPlayerEntity() && Globals.playerEntity != null){ | ||||
|                     Globals.clientConnection.queueOutgoingMessage( | ||||
|                         EntityMessage.constructupdateEntityViewDirMessage( | ||||
|                             Globals.clientSceneWrapper.mapClientToServerId(Globals.playerEntity.getId()), | ||||
|                             Globals.timekeeper.getNumberOfSimFramesElapsed(), | ||||
|                             perspectiveVal, | ||||
|                             yaw, | ||||
|                             pitch | ||||
|                         ) | ||||
|                     ); | ||||
|                 } | ||||
| 
 | ||||
|                 //the view matrix | ||||
|                 Globals.viewMatrix = CameraEntityUtils.getCameraViewMatrix(Globals.playerCamera); | ||||
| 
 | ||||
|                 //update the cursor on client side | ||||
|                 updatePlayerCursor(); | ||||
|             } | ||||
|             if(trackPlayerEntity && Globals.playerEntity != null){ | ||||
|                 Vector3d entityPos = EntityUtils.getPosition(Globals.playerEntity); | ||||
|                 CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)entityPos.x,(float)entityPos.y,(float)entityPos.z).add(CameraEntityUtils.getOrbitalCameraRadialOffset(Globals.playerCamera))); | ||||
|             } | ||||
|             //update view matrix offset | ||||
|             float xFactor = (float)Math.cos(yaw / 180.0f * Math.PI); | ||||
|             float yFactor = (float)Math.sin(yaw / 180.0f * Math.PI); | ||||
|             Vector3f radialOffset = CameraEntityUtils.getOrbitalCameraRadialOffset(Globals.playerCamera); | ||||
|             Vector3f trueOffset = new Vector3f(radialOffset).mul(xFactor,1.0f,yFactor); | ||||
|             CameraEntityUtils.setOrbitalCameraRadialOffset(Globals.playerCamera, trueOffset); | ||||
|             cameraRotationVector.mul(CameraEntityUtils.getOrbitalCameraDistance(Globals.playerCamera)); | ||||
|             CameraEntityUtils.setCameraEye(Globals.playerCamera, cameraRotationVector); | ||||
| 
 | ||||
|             //tell the server that we changed where we're looking, if we're in first person | ||||
|             int perspectiveVal = CameraHandler.CAMERA_PERSPECTIVE_FIRST; | ||||
|             if(Globals.controlHandler.cameraIsThirdPerson()){ | ||||
|                 perspectiveVal = CameraHandler.CAMERA_PERSPECTIVE_THIRD; | ||||
|             } | ||||
|             if(Globals.cameraHandler.getTrackPlayerEntity() && Globals.playerEntity != null){ | ||||
|                 Globals.clientConnection.queueOutgoingMessage( | ||||
|                     EntityMessage.constructupdateEntityViewDirMessage( | ||||
|                         Globals.clientSceneWrapper.mapClientToServerId(Globals.playerEntity.getId()), | ||||
|                         Globals.timekeeper.getNumberOfSimFramesElapsed(), | ||||
|                         perspectiveVal, | ||||
|                         yaw, | ||||
|                         pitch | ||||
|                     ) | ||||
|                 ); | ||||
|             } | ||||
| 
 | ||||
|             //the view matrix | ||||
|             Globals.viewMatrix = CameraEntityUtils.getCameraViewMatrix(Globals.playerCamera); | ||||
| 
 | ||||
|             //update the cursor on client side | ||||
|             updatePlayerCursor(); | ||||
|         } | ||||
|         Globals.profiler.endCpuSample(); | ||||
|     } | ||||
| @ -208,6 +213,14 @@ public class CameraHandler { | ||||
|     public boolean getTrackPlayerEntity(){ | ||||
|         return trackPlayerEntity; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Sets whether the camera should update with player input or not | ||||
|      * @param update true to update with input, false otherwise | ||||
|      */ | ||||
|     public void setUpdate(boolean update){ | ||||
|         this.update = update; | ||||
|     } | ||||
|      | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -112,6 +112,7 @@ public class ClientLoading { | ||||
|         //init camera | ||||
|         Globals.playerCamera = CameraEntityUtils.spawnBasicCameraEntity(new Vector3f(0,0,0), new Vector3f(-1,0,0)); | ||||
|         Globals.cameraHandler.setTrackPlayerEntity(false); | ||||
|         Globals.cameraHandler.setUpdate(false); | ||||
|         //initialize the "real" objects simulation | ||||
|         initClientSimulation(); | ||||
|         //init foliage manager | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user