mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-10-31 15:56:42 +00:00 
			
		
		
		
	Add pitch constraint for first person camera.
This commit is contained in:
		
							parent
							
								
									e07687ee01
								
							
						
					
					
						commit
						b111febfc9
					
				
					 1 changed files with 20 additions and 0 deletions
				
			
		|  | @ -1,5 +1,7 @@ | |||
| #include "cameracontroller.hpp" | ||||
| 
 | ||||
| #include <cmath> | ||||
| 
 | ||||
| #include <QKeyEvent> | ||||
| 
 | ||||
| #include <osg/BoundingBox> | ||||
|  | @ -314,6 +316,24 @@ namespace CSVRender | |||
| 
 | ||||
|     void FreeCameraController::pitch(double value) | ||||
|     { | ||||
|         const double Constraint = osg::PI / 2 - 0.1; | ||||
| 
 | ||||
|         if (mLockUpright) | ||||
|         { | ||||
|             osg::Vec3d eye, center, up; | ||||
|             getCamera()->getViewMatrixAsLookAt(eye, center, up); | ||||
| 
 | ||||
|             osg::Vec3d forward = center - eye; | ||||
|             osg::Vec3d left = up ^ forward; | ||||
| 
 | ||||
|             double pitchAngle = std::acos(up * mUp); | ||||
|             if ((mUp ^ up) * left < 0) | ||||
|                 pitchAngle *= -1; | ||||
| 
 | ||||
|             if (std::abs(pitchAngle + value) > Constraint) | ||||
|                 value = (pitchAngle > 0 ? 1 : -1) * Constraint - pitchAngle; | ||||
|         } | ||||
| 
 | ||||
|         getCamera()->getViewMatrix() *= osg::Matrixd::rotate(value, LocalLeft); | ||||
|         mModified = true; | ||||
|     } | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue