Jetson Inference
DNN Vision Library
glCamera.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef __GL_CAMERA_H__
24 #define __GL_CAMERA_H__
25 
26 
27 #include <stdint.h>
28 #include <stdio.h>
29 
30 
35 class glCamera
36 {
37 public:
42  {
46  };
47 
56  static glCamera* Create( CameraMode mode, int registerEvents=0 );
57 
66  static glCamera* Create( int registerEvents=0 );
67 
71  ~glCamera();
72 
76  void Activate();
77 
81  void Activate( CameraMode mode );
82 
86  void Deactivate();
87 
91  inline CameraMode GetCameraMode() const { return mMode; }
92 
96  inline void SetCameraMode( CameraMode mode ) { mMode = mode; }
97 
101  inline void SetFOV( float fov ) { mFoV = fov; }
102 
106  inline void SetClippingPlane( float near, float far ) { mNear = near; mFar = far; }
107 
111  inline void SetNear( float near ) { mNear = near; }
112 
116  inline void SetFar( float far ) { mFar = far; }
117 
121  inline void SetEye( float x, float y, float z ) { mEye[0] = x; mEye[1] = y; mEye[2] = z; }
122 
126  inline void SetLookAt( float x, float y, float z ) { mLookAt[0] = x; mLookAt[1] = y; mLookAt[2] = z; }
127 
131  inline void SetRotation( float yaw, float pitch, float roll ) { mRotation[0] = pitch; mRotation[1] = yaw; mRotation[2] = roll; }
132 
136  inline void SetYaw( float yaw ) { mRotation[1] = yaw; }
137 
141  inline void SetPitch( float pitch ) { mRotation[0] = pitch; }
142 
146  inline void SetRoll( float roll ) { mRotation[2] = roll; }
147 
151  inline void SetMovementSpeed( float speed ) { mMovementSpeed = speed; }
152 
156  inline void SetMovementEnabled( bool enabled ) { mMovementEnabled = enabled; }
157 
161  void StoreDefaults();
162 
166  void Reset();
167 
171  void RegisterEvents( uint32_t display=0 );
172 
173 private:
174  glCamera( CameraMode mode );
175 
176  bool mouseInViewport() const;
177 
178  bool onEventLookAt( uint16_t msg, int a, int b );
179  bool onEventYawPitchRoll( uint16_t msg, int a, int b );
180 
181  static bool onEvent( uint16_t msg, int a, int b, void* user );
182 
183  CameraMode mMode;
184 
185  float mNear;
186  float mFar;
187  float mFoV;
188 
189  float mEye[3]; // camera location
190  float mRotation[3]; // pitch/yaw/roll euler angles
191  float mLookAt[3]; // look-at point
192  float mUp[3]; // up direction
193 
194  float mDefaultEye[3];
195  float mDefaultRotation[3];
196  float mDefaultLookAt[3];
197 
198  float mPrevModelView[16];
199  float mPrevProjection[16];
200 
201  float mMovementSpeed;
202  bool mMovementEnabled;
203 
204  void* mDisplay;
205  int mViewport[4];
206  bool mMouseActive;
207 };
208 
209 #endif
210 
glCamera::CameraMode
CameraMode
Enum specifying the camera mode.
Definition: glCamera.h:41
glCamera::SetRoll
void SetRoll(float roll)
Set the roll angle, in radians.
Definition: glCamera.h:146
glCamera::SetNear
void SetNear(float near)
Set the distance to the near clipping plane.
Definition: glCamera.h:111
glCamera::Create
static glCamera * Create(CameraMode mode, int registerEvents=0)
Create OpenGL camera object with the specified CameraMode.
glCamera::~glCamera
~glCamera()
Free the camera.
glCamera::Ortho
@ Ortho
Ortho (2D)
Definition: glCamera.h:45
glCamera::SetPitch
void SetPitch(float pitch)
Set the pitch angle, in radians.
Definition: glCamera.h:141
glCamera::SetRotation
void SetRotation(float yaw, float pitch, float roll)
Set the yaw/pitch/roll angles, in radians.
Definition: glCamera.h:131
glCamera::SetMovementSpeed
void SetMovementSpeed(float speed)
Set the movement speed (in world units)
Definition: glCamera.h:151
glCamera::SetFar
void SetFar(float far)
Set the distance to the far clipping plane.
Definition: glCamera.h:116
glCamera::SetFOV
void SetFOV(float fov)
Set the field of view (FOV), in degrees.
Definition: glCamera.h:101
glCamera::SetYaw
void SetYaw(float yaw)
Set the yaw angle, in radians.
Definition: glCamera.h:136
glCamera::SetLookAt
void SetLookAt(float x, float y, float z)
Set the look-at point.
Definition: glCamera.h:126
glCamera::Reset
void Reset()
Reset camera orientation to defaults.
glCamera::YawPitchRoll
@ YawPitchRoll
YawPitchRoll (first person.
Definition: glCamera.h:44
glCamera
OpenGL perspective camera supporting Look-At, Yaw/Pitch/Roll, and Ortho modes.
Definition: glCamera.h:35
glCamera::Deactivate
void Deactivate()
Restore previous GL_PROJECTION and GL_MODELVIEW matrices.
glCamera::GetCameraMode
CameraMode GetCameraMode() const
Get the camera mode.
Definition: glCamera.h:91
glCamera::StoreDefaults
void StoreDefaults()
Store the current configuration as defaults.
glCamera::SetMovementEnabled
void SetMovementEnabled(bool enabled)
Enable or disable movement from user input.
Definition: glCamera.h:156
glCamera::Activate
void Activate()
Activate GL_PROJECTION and GL_MODELVIEW matrices.
glCamera::RegisterEvents
void RegisterEvents(uint32_t display=0)
Register to recieve input events (enable movement)
glCamera::SetEye
void SetEye(float x, float y, float z)
Set the eye position.
Definition: glCamera.h:121
glCamera::SetClippingPlane
void SetClippingPlane(float near, float far)
Set the near/far z-clipping plane.
Definition: glCamera.h:106
glCamera::SetCameraMode
void SetCameraMode(CameraMode mode)
Set the camera mode.
Definition: glCamera.h:96
glCamera::LookAt
@ LookAt
LookAt (orbit)
Definition: glCamera.h:43