RigsofRods
Soft-body Physics Simulation
CameraManager.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2017-2020 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include "CameraManager.h"
23 
24 #include "AppContext.h"
25 #include "ApproxMath.h"
26 #include "Actor.h"
27 #include "ActorManager.h"
28 #include "Character.h"
29 #include "Collisions.h"
30 #include "Console.h"
31 #include "GameContext.h"
32 #include "GfxScene.h"
33 #include "InputEngine.h"
34 #include "Language.h"
35 #include "OverlayWrapper.h"
36 #include "Replay.h"
37 #include "Terrain.h"
38 #include "GUIManager.h"
40 #include "Water.h"
41 
42 using namespace Ogre;
43 using namespace RoR;
44 
45 static const Ogre::Vector3 CHARACTERCAM_OFFSET_1ST_PERSON(0.0f, 1.82f, 0.0f);
46 static const Ogre::Vector3 CHARACTERCAM_OFFSET_3RD_PERSON(0.0f, 1.1f, 0.0f);
47 static const int SPLINECAM_DRAW_RESOLUTION = 200;
48 static const int DEFAULT_INTERNAL_CAM_PITCH = -15;
49 static const float TRANS_SPEED = 50.f;
50 static const float ROTATE_SPEED = 100.f;
51 
52 bool intersectsTerrain(Vector3 a, Vector3 b) // internal helper
53 {
54  b.y = std::max(b.y, App::GetGameContext()->GetTerrain()->GetHeightAt(b.x, b.z) + 1.0f);
55 
56  int steps = std::max(3.0f, a.distance(b) * 2.0f);
57  for (int i = 1; i < steps; i++)
58  {
59  Vector3 pos = a + (b - a) * (float)i / steps;
60  float h = App::GetGameContext()->GetTerrain()->GetHeightAt(pos.x, pos.z);
61  if (h > pos.y)
62  {
63  return true;
64  }
65  }
66  return App::GetGameContext()->GetTerrain()->GetCollisions()->intersectsTris(Ray(a, b - a)).first;
67 }
68 
69 bool intersectsTerrain(Vector3 a, Vector3 start, Vector3 end, float interval) // internal helper
70 {
71  int steps = std::max(3.0f, start.distance(end) * (6.0f / interval));
72  for (int i = 0; i <= steps; i++)
73  {
74  Vector3 b = start + (end - start) * (float)i / steps;
75  if (intersectsTerrain(a, b))
76  {
77  return true;
78  }
79  }
80  return false;
81 }
82 
83 CameraManager::CameraManager() :
84  m_current_behavior(CAMERA_BEHAVIOR_INVALID)
85  , m_cct_dt(0.0f)
86  , m_cct_trans_scale(1.0f)
87  , m_cct_sim_speed(1.0f)
88  , m_cam_before_toggled(CAMERA_BEHAVIOR_INVALID)
89  , m_prev_toggled_cam(CAMERA_BEHAVIOR_INVALID)
90  , m_charactercam_is_3rdperson(true)
91  , m_splinecam_num_linked_beams(0)
92  , m_splinecam_auto_tracking(false)
93  , m_splinecam_spline(new SimpleSpline())
94  , m_splinecam_spline_closed(false)
95  , m_splinecam_spline_len(1.0f)
96  , m_splinecam_mo(0)
97  , m_splinecam_spline_pos(0.5f)
98  , m_staticcam_force_update(false)
99  , m_staticcam_fov_exponent(1.0f)
100  , m_cam_rot_x(0.0f)
101  , m_cam_rot_y(0.3f)
102  , m_cam_dist(5.f)
103  , m_cam_dist_min(0.f)
104  , m_cam_dist_max(0.f)
105  , m_cam_target_direction(0.f)
106  , m_cam_target_pitch(0.f)
107  , m_cam_ratio (11.f)
108  , m_cam_look_at(Ogre::Vector3::ZERO)
109  , m_cam_look_at_last(Ogre::Vector3::ZERO)
110  , m_cam_look_at_smooth(Ogre::Vector3::ZERO)
111  , m_cam_look_at_smooth_last(Ogre::Vector3::ZERO)
112  , m_cam_limit_movement(true)
113  , m_camera_node(nullptr)
114 {
115  m_cct_player_actor = nullptr;
116  m_staticcam_update_timer.reset();
117 
118  m_camera = App::GetGfxScene()->GetSceneManager()->createCamera("PlayerCam");
119  m_camera->setNearClipDistance(0.5);
120  m_camera->setAutoAspectRatio(true);
121  this->CreateCameraNode();
122 
123  App::GetAppContext()->GetViewport()->setCamera(m_camera);
124 }
125 
127 {
128  if (m_splinecam_spline)
129  delete m_splinecam_spline;
130  if (m_splinecam_mo)
131  delete m_splinecam_mo;
132 }
133 
135 {
137  m_camera_node = App::GetGfxScene()->GetSceneManager()->getRootSceneNode()->createChildSceneNode("PlayerCamNode");
138  m_camera_node->setFixedYawAxis(true);
139  m_camera_node->attachObject(m_camera);
140 }
141 
143 {
144  m_camera_node = nullptr; // after call to `Ogre::SceneManager::ClearScene()`, the node pointer is invalid.
145  this->CreateCameraNode();
146 }
147 
149 {
150  switch(m_current_behavior)
151  {
154  {
156  this->ResetCurrentBehavior();
157  return false;
158  }
159  else // first person
160  {
162  return true;
163  }
164  }
165  case CAMERA_BEHAVIOR_STATIC: return true;
166  case CAMERA_BEHAVIOR_VEHICLE: return true;
167  case CAMERA_BEHAVIOR_VEHICLE_SPLINE: return true;
169  if ( (m_cct_player_actor != nullptr)
171  {
174  return false;
175  }
176  return true;
177  }
178  case CAMERA_BEHAVIOR_FREE: return true;
179  case CAMERA_BEHAVIOR_FIXED: return true;
180  case CAMERA_BEHAVIOR_ISOMETRIC: return true;
181  case CAMERA_BEHAVIOR_INVALID: return true;
182  default: return false;
183  }
184 }
185 
187 {
188  switch(m_current_behavior)
189  {
191  if (!App::GetGameContext()->GetPlayerCharacter())
192  return;
196 
198  return;
199  }
200 
204  return;
205 
210 
214 
215  Vector3 dir = (m_cct_player_actor->ar_nodes[pos_node].AbsPosition
216  - m_cct_player_actor->ar_nodes[dir_node].AbsPosition).normalisedCopy();
217  Vector3 roll = (m_cct_player_actor->ar_nodes[pos_node].AbsPosition
218  - m_cct_player_actor->ar_nodes[roll_node].AbsPosition).normalisedCopy();
219 
221  {
222  roll = -roll;
223  }
224 
225  Vector3 up = dir.crossProduct(roll);
226  roll = up.crossProduct(dir);
227 
228  Quaternion orientation = Quaternion(m_cam_rot_x, up) * Quaternion(Degree(180.0) + m_cam_rot_y, roll) * Quaternion(roll, up, dir);
229 
231  this->GetCameraNode()->setOrientation(orientation);
232  return;
233  }
234  case CAMERA_BEHAVIOR_FREE: this->UpdateCameraBehaviorFree(); return;
235  case CAMERA_BEHAVIOR_FIXED: this->UpdateCameraBehaviorFixed(); return;
236  case CAMERA_BEHAVIOR_ISOMETRIC: return;
237  case CAMERA_BEHAVIOR_INVALID: return;
238  default: return;
239  }
240 }
241 
242 void CameraManager::UpdateInputEvents(float dt) // Called every frame
243 {
244  if (App::sim_state->getEnum<SimState>() != SimState::RUNNING &&
245  App::sim_state->getEnum<SimState>() != SimState::EDITOR_MODE)
246  {
247  return;
248  }
249 
252  m_cct_dt = dt;
253  m_cct_rot_scale = Degree(TRANS_SPEED * dt);
255 
256  if ( m_current_behavior < CAMERA_BEHAVIOR_END && App::GetInputEngine()->getEventBoolValueBounce(EV_CAMERA_CHANGE) )
257  {
259  {
260  this->switchToNextBehavior();
261  }
262  }
263 
264  if (App::GetInputEngine()->getEventBoolValueBounce(EV_CAMERA_FREE_MODE_FIX))
265  {
267  }
268 
269  if (App::GetInputEngine()->getEventBoolValueBounce(EV_CAMERA_FREE_MODE))
270  {
272  }
273 
275  {
276  this->UpdateCurrentBehavior();
277  }
278  else
279  {
281  }
282 
283  // camera FOV settings
284  if (this->GetCurrentBehavior() != CameraManager::CAMERA_BEHAVIOR_STATIC) // the static camera has its own fov logic
285  {
288 
289  int modifier = 0;
290  modifier = (App::GetInputEngine()->getEventBoolValueBounce(EV_COMMON_FOV_LESS, 0.1f)) ? -1 : 0;
291  modifier += (App::GetInputEngine()->getEventBoolValueBounce(EV_COMMON_FOV_MORE, 0.1f)) ? 1 : 0;
292  int fov = -1;
293  if (modifier != 0)
294  {
295  fov = cvar_fov->getInt() + modifier;
296  if (fov >= 10 && fov <= 160)
297  {
298  cvar_fov->setVal(fov);
299  }
300  else
301  {
303  }
304  }
305  if (App::GetInputEngine()->getEventBoolValueBounce(EV_COMMON_FOV_RESET))
306  {
309  cvar_fov->setVal(cvar_fov_default->getInt());
310  }
311 
312  if (fov != -1)
313  {
314  Str<100> msg; msg << _L("FOV: ") << fov;
316  }
317  }
318 }
319 
321 {
322  int i = (static_cast<int>(m_current_behavior) + 1) % CAMERA_BEHAVIOR_END;
323  this->switchBehavior(static_cast<CameraBehaviors>(i));
324 }
325 
327 {
328  switch(m_current_behavior)
329  {
332 
333  // Vars from CameraBehaviorOrbit
335  {
336  m_cam_rot_y = 0.1f;
337  m_cam_dist = 0.1f;
338  m_cam_ratio = 0.0f;
339  }
340  else
341  {
342  m_cam_rot_y = 0.3f;
343  m_cam_dist = 5.0f;
344  m_cam_ratio = 11.0f;
345  }
346  m_cam_dist_min = 0;
347  m_cam_target_pitch = 0.0f;
348  return;
349  }
350 
354  return;
355 
358  return;
359 
364  App::GetCameraManager()->GetCamera()->setFOVy(Degree(App::gfx_fov_internal->getInt()));
365  return;
366 
367  case CAMERA_BEHAVIOR_FREE: return;
368  case CAMERA_BEHAVIOR_FIXED: return;
369  case CAMERA_BEHAVIOR_ISOMETRIC: return;
370  case CAMERA_BEHAVIOR_INVALID: return;
371  default: return;
372  }
373 }
374 
376 {
377  // Assign new behavior
378  m_current_behavior = new_behavior;
379 
380  // Resolve per-behavior constraints and actions
381  switch (new_behavior)
382  {
385  break;
386 
390  break;
391 
394  break;
395 
397  if ( (m_cct_player_actor == nullptr) || m_cct_player_actor->ar_num_camera_rails <= 0)
398  {
399  this->switchToNextBehavior();
400  return;
401  }
402  else if (reset)
403  {
406  }
408  break;
409 
411  if ((m_cct_player_actor == nullptr) || (m_cct_player_actor->ar_num_cinecams <= 0))
412  {
413  this->switchToNextBehavior();
414  return;
415  }
416  else if ( reset )
417  {
418  this->ResetCurrentBehavior();
419  }
420 
421  App::GetCameraManager()->GetCamera()->setFOVy(Degree(App::gfx_fov_internal->getInt()));
422 
424 
425  if ( RoR::App::GetOverlayWrapper() != nullptr )
426  {
429  }
430 
433 
435  break;
436 
438  if ( m_cct_player_actor == nullptr )
439  {
440  this->switchToNextBehavior();
441  return;
442  }
443  else if ( reset )
444  {
445  this->ResetCurrentBehavior();
446  }
448  break;
449 
451  if (m_cct_player_actor != nullptr)
452  {
453  this->switchToNextBehavior();
454  return;
455  }
456  else if (reset)
457  {
458  this->ResetCurrentBehavior();
459  }
460  break;
461 
463  this->CameraBehaviorOrbitReset();
464  break;
465  }
466 }
467 
469 {
471  {
473  }
475  {
476  if ( m_cct_player_actor != nullptr )
477  {
478  App::GetCameraManager()->GetCamera()->setFOVy(Degree(App::gfx_fov_external->getInt()));
481  }
482  }
483 }
484 
486 {
487  if (new_behavior == m_current_behavior)
488  {
489  return;
490  }
491 
493 
494  if (m_cct_player_actor != nullptr)
495  {
497  if (!App::GetGuiManager()->IsGuiHidden())
498  {
500  }
502  {
504  }
505  }
506 
507  this->ActivateNewBehavior(new_behavior, true);
508 }
509 
511 {
512  if (new_behavior == m_current_behavior)
513  {
514  this->NotifyContextChange();
515  }
516 
518 
519  m_cct_player_actor = new_vehicle;
520 
521  this->ActivateNewBehavior(new_behavior, new_behavior != m_current_behavior);
522 }
523 
525 {
527 }
528 
530 {
532 }
533 
535 {
536 
537  if (App::sim_state->getEnum<SimState>() == SimState::PAUSED)
538  {
539  return true; // Do nothing when paused
540  }
541 
542  // IMPORTANT: get mouse button state from InputEngine, not from OIS directly
543  // - that state may be dirty, see commentary in `InputEngine::getMouseState()`
544  const OIS::MouseState ms = App::GetInputEngine()->getMouseState();
545 
546  switch(m_current_behavior)
547  {
549  if (!App::GetGameContext()->GetPlayerCharacter())
550  return false;
552  {
553  Radian angle = App::GetGameContext()->GetPlayerCharacter()->getRotation();
554 
555  m_cam_rot_y += Degree(ms.Y.rel * 0.13f);
556  angle += Degree(ms.X.rel * 0.13f);
557 
558  m_cam_rot_y = Radian(std::min(+Math::HALF_PI * 0.65f, m_cam_rot_y.valueRadians()));
559  m_cam_rot_y = Radian(std::max(m_cam_rot_y.valueRadians(), -Math::HALF_PI * 0.9f));
560 
562 
564 
565  return true;
566  }
567 
569  }
574  case CAMERA_BEHAVIOR_FREE: {
575 
576  App::GetCameraManager()->GetCameraNode()->yaw(Degree(-ms.X.rel * 0.13f), Ogre::Node::TS_WORLD);
577  App::GetCameraManager()->GetCameraNode()->pitch(Degree(-ms.Y.rel * 0.13f));
578 
580 
581  return true;
582  }
583 
584  case CAMERA_BEHAVIOR_FIXED: return false;
585  case CAMERA_BEHAVIOR_ISOMETRIC: return false;
586  case CAMERA_BEHAVIOR_INVALID: return false;
587  default: return false;
588  }
589 }
590 
592 {
593  // IMPORTANT: get mouse button state from InputEngine, not from OIS directly
594  // - that state may be dirty, see commentary in `InputEngine::getMouseState()`
595  const OIS::MouseState ms = App::GetInputEngine()->getMouseState();
596 
597  if (ms.buttonDown(OIS::MB_Right) && ms.buttonDown(OIS::MB_Middle))
598  {
600  }
601 
602  switch(m_current_behavior)
603  {
604  case CAMERA_BEHAVIOR_CHARACTER: return false;
605  case CAMERA_BEHAVIOR_STATIC: return false;
609  case CAMERA_BEHAVIOR_FREE: return false;
610  case CAMERA_BEHAVIOR_FIXED: return false;
611  case CAMERA_BEHAVIOR_ISOMETRIC: return false;
612  case CAMERA_BEHAVIOR_INVALID: return false;
613  default: return false;
614  }
615 }
616 
618 {
619  switch(m_current_behavior)
620  {
625  m_cam_look_at_last = Vector3::ZERO;
626  return;
627 
628  default:
629  return;
630  }
631 }
632 
634 {
635  // Getting out of vehicle
636  if (new_vehicle == nullptr)
637  {
638  m_cct_player_actor = nullptr;
641  {
643  }
644  return;
645  }
646 
647  // Getting in vehicle
650  {
651  // Change camera
652  switch (new_vehicle->GetCameraContext()->behavior)
653  {
656  break;
657 
660  break;
661 
664  break;
665 
666  default:
668  }
669  }
670 }
671 
672 void CameraManager::ToggleCameraBehavior(CameraBehaviors new_behavior) // Only accepts FREE and FREEFIX modes
673 {
674  ROR_ASSERT(new_behavior == CAMERA_BEHAVIOR_FIXED || new_behavior == CAMERA_BEHAVIOR_FREE);
675 
676  if (m_current_behavior == new_behavior) // Leaving toggled mode?
677  {
679  {
682  }
684  {
687  }
688  }
689  else // Entering toggled mode
690  {
692  {
694  }
695  else
696  {
698  }
699  this->switchBehavior(new_behavior);
700  }
701 }
702 
704 {
705  Vector3 velocity = Vector3::ZERO;
706  Radian angle = Degree(90);
707  float radius = 3.0f;
708  float speed = 0.0f;
709 
710  if (m_cct_player_actor)
711  {
713  {
715  }
718  if (App::GetGameContext()->GetPlayerActor()->ar_driveable != AIRPLANE)
719  {
721  }
722  angle = (m_staticcam_look_at - m_staticcam_position).angleBetween(velocity);
723  speed = velocity.normalise();
724 
726  {
728  }
729  }
730  else
731  {
733  }
734 
736 
737  if (m_staticcam_force_update || m_staticcam_update_timer.getMilliseconds() > 1000)
738  {
739  Vector3 lookAt = m_staticcam_look_at;
740  Vector3 lookAtPrediction = lookAt + velocity * speed;
741  float distance = m_staticcam_position.distance(lookAt);
742  float interval = std::max(radius, speed);
743  float cmradius = std::max(radius, App::gfx_camera_height->getFloat() / 7.0f);
744 
746  (distance > cmradius * 8.0f && angle < Degree(30)) ||
747  (distance < cmradius * 2.0f && angle > Degree(150)) ||
748  distance > cmradius * std::max(25.0f, speed * 1.15f) ||
749  intersectsTerrain(m_staticcam_position, lookAt, lookAtPrediction, interval))
750  {
751  const auto water = App::GetGameContext()->GetTerrain()->getWater();
752  float water_height = (water && !water->IsUnderWater(lookAt)) ? water->GetStaticWaterHeight() : 0.0f;
753  float desired_offset = std::max(std::sqrt(radius) * 2.89f, App::gfx_camera_height->getFloat());
754 
755  std::vector<std::pair<float, Vector3>> viable_positions;
756  for (int i = 0; i < 10; i++)
757  {
758  Vector3 pos = lookAt;
759  if (speed < 2.5f)
760  {
761  float angle = Math::TWO_PI * frand();
762  pos += Vector3(cos(angle), 0, sin(angle)) * cmradius * 2.5f;
763  }
764  else
765  {
766  float dist = std::max(cmradius * 2.5f, std::sqrt(cmradius) * speed);
767  float mrnd = Math::Clamp(0.6f * cmradius / dist, 0.0f, 0.3f);
768  float arnd = mrnd + frand() * (1.0f - mrnd);
769  float rnd = frand() > 0.5f ? arnd : -arnd;
770  pos += (velocity + velocity.crossProduct(Vector3::UNIT_Y) * rnd) * dist;
771  }
772  pos.y = std::max(pos.y, water_height);
773  pos.y = std::max(pos.y, App::GetGameContext()->GetTerrain()->GetHeightAt(pos.x, pos.z));
774  pos.y += desired_offset * (i < 7 ? 1.0f : frand());
775  if (!intersectsTerrain(pos, lookAt, lookAtPrediction, interval))
776  {
777  float hdiff = std::abs(pos.y - lookAt.y - desired_offset);
778  viable_positions.push_back({hdiff, pos});
779  if (hdiff < 1.0f || viable_positions.size() > 2)
780  break;
781  }
782  }
783  if (!viable_positions.empty())
784  {
785  std::sort(viable_positions.begin(), viable_positions.end());
786  m_staticcam_update_timer.reset();
787  m_staticcam_position = viable_positions.front().second;
788  m_staticcam_force_update = false;
789  }
790  }
791  }
792 
793  static float fovExp = m_staticcam_fov_exponent;
794  fovExp = (1.0f / (m_cam_ratio + 1.0f)) * m_staticcam_fov_exponent + (m_cam_ratio / (m_cam_ratio + 1.0f)) * fovExp;
795 
796  float camDist = m_staticcam_position.distance(m_staticcam_look_at);
797  float fov = atan2(20.0f, std::pow(camDist, fovExp));
798 
799  this->GetCameraNode()->setPosition(m_staticcam_position);
800  App::GetCameraManager()->GetCameraNode()->lookAt(m_staticcam_look_at, Ogre::Node::TS_WORLD);
801  App::GetCameraManager()->GetCamera()->setFOVy(Radian(fov));
802 }
803 
805 {
806  // IMPORTANT: get mouse button state from InputEngine, not from OIS directly
807  // - that state may be dirty, see commentary in `InputEngine::getMouseState()`
808  const OIS::MouseState ms = App::GetInputEngine()->getMouseState();
809 
810  if (ms.buttonDown(OIS::MB_Right))
811  {
812  float scale = RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU) ? 0.00002f : 0.0002f;
813  m_staticcam_fov_exponent += ms.Z.rel * scale;
814  m_staticcam_fov_exponent = Math::Clamp(m_staticcam_fov_exponent, 0.8f, 1.50f);
816  return true;
817  }
818 
819  return false;
820 }
821 
823 {
824  if (RoR::App::GetInputEngine()->getEventBoolValueBounce(EV_CAMERA_LOOKBACK))
825  {
826  if (m_cam_rot_x > Degree(0))
827  {
828  m_cam_rot_x = Degree(0);
829  }
830  else
831  {
832  m_cam_rot_x = Degree(180);
833  }
834  }
835 
837  {
840  }
841  else
842  {
845  }
846  m_cam_rot_y = std::max((Radian)Degree(-80), m_cam_rot_y);
847  m_cam_rot_y = std::min(m_cam_rot_y, (Radian)Degree(88));
848 
849  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CAMERA_ZOOM_IN) && m_cam_dist > 1)
850  {
852  }
853  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CAMERA_ZOOM_IN_FAST) && m_cam_dist > 1)
854  {
856  }
857  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CAMERA_ZOOM_OUT))
858  {
860  }
861  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CAMERA_ZOOM_OUT_FAST))
862  {
864  }
865 
866  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CAMERA_RESET))
867  {
869  }
870 
871  if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_RSHIFT) && RoR::App::GetInputEngine()->isKeyDownValueBounce(OIS::KC_SPACE))
872  {
875  {
876  RoR::App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE, _L("Limited camera movement enabled"), "camera_go.png");
877  }
878  else
879  {
880  RoR::App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE, _L("Limited camera movement disabled"), "camera_go.png");
881  }
882  }
883 
884  if (m_cam_limit_movement && m_cam_dist_min > 0.0f)
885  {
886  m_cam_dist = std::max(m_cam_dist_min, m_cam_dist);
887  }
888  if (m_cam_limit_movement && m_cam_dist_max > 0.0f)
889  {
890  m_cam_dist = std::min(m_cam_dist, m_cam_dist_max);
891  }
892 
893  m_cam_dist = std::max(0.0f, m_cam_dist);
894 
895  Vector3 desiredPosition = m_cam_look_at + m_cam_dist * 0.5f * Vector3(
896  sin(m_cam_target_direction.valueRadians() + m_cam_rot_x.valueRadians()) * cos(m_cam_target_pitch.valueRadians() + m_cam_rot_y.valueRadians())
897  , sin(m_cam_target_pitch.valueRadians() + m_cam_rot_y.valueRadians())
898  , cos(m_cam_target_direction.valueRadians() + m_cam_rot_x.valueRadians()) * cos(m_cam_target_pitch.valueRadians() + m_cam_rot_y.valueRadians())
899  );
900 
902  {
903  float h = App::GetGameContext()->GetTerrain()->GetHeightAt(desiredPosition.x, desiredPosition.z) + 1.0f;
904 
905  desiredPosition.y = std::max(h, desiredPosition.y);
906  }
907 
908  if (m_cam_look_at_last == Vector3::ZERO)
909  {
911  }
912  if (m_cam_look_at_smooth == Vector3::ZERO)
913  {
915  }
916  if (m_cam_look_at_smooth_last == Vector3::ZERO)
917  {
919  }
920 
921  Vector3 camDisplacement = m_cam_look_at - m_cam_look_at_last;
922  Vector3 precedingLookAt = m_cam_look_at_smooth_last + camDisplacement;
923  Vector3 precedingPosition = this->GetCameraNode()->getPosition() + camDisplacement;
924 
925  Vector3 camPosition = (1.0f / (m_cam_ratio + 1.0f)) * desiredPosition + (m_cam_ratio / (m_cam_ratio + 1.0f)) * precedingPosition;
926 
928  {
929  this->GetCameraNode()->setPosition(App::GetGameContext()->GetTerrain()->GetCollisions()->forcecampos);
931  }
932  else
933  {
934  if (m_cct_player_actor && m_cct_player_actor->ar_state == ActorState::LOCAL_REPLAY && camDisplacement != Vector3::ZERO)
935  this->GetCameraNode()->setPosition(desiredPosition);
936  else
937  this->GetCameraNode()->setPosition(camPosition);
938  }
939 
940  m_cam_look_at_smooth = (1.0f / (m_cam_ratio + 1.0f)) * m_cam_look_at + (m_cam_ratio / (m_cam_ratio + 1.0f)) * precedingLookAt;
941 
944  App::GetCameraManager()->GetCameraNode()->lookAt(m_cam_look_at_smooth, Ogre::Node::TS_WORLD);
945 }
946 
948 {
949  // IMPORTANT: get mouse button state from InputEngine, not from OIS directly
950  // - that state may be dirty, see commentary in `InputEngine::getMouseState()`
951  const OIS::MouseState ms = App::GetInputEngine()->getMouseState();
952 
953  if (ms.buttonDown(OIS::MB_Right))
954  {
956  float scale = RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU) ? 0.002f : 0.02f;
958  {
959  m_cam_rot_x += Degree(ms.X.rel * -0.13f);
960  m_cam_rot_y += Degree(-ms.Y.rel * -0.13f);
961  }
962  else
963  {
964  m_cam_rot_x += Degree(ms.X.rel * 0.13f);
965  m_cam_rot_y += Degree(-ms.Y.rel * 0.13f);
966  }
967  m_cam_dist += -ms.Z.rel * scale;
968  return true;
969  }
970 
971  return false;
972 }
973 
975 {
976  m_cam_rot_x = 0.0f;
977  m_cam_rot_y = 0.3f;
978  m_cam_look_at_last = Vector3::ZERO;
979  m_cam_look_at_smooth = Vector3::ZERO;
980  m_cam_look_at_smooth_last = Vector3::ZERO;
981  App::GetCameraManager()->GetCamera()->setFOVy(Degree(App::gfx_fov_external->getInt()));
982 }
983 
985 {
986  Degree mRotX(0.0f);
987  Degree mRotY(0.0f);
988  Degree cct_rot_scale(m_cct_rot_scale * 5.0f * m_cct_dt);
989  Vector3 mTrans(Vector3::ZERO);
990  Real cct_trans_scale(m_cct_trans_scale * 5.0f * m_cct_dt);
991 
993  {
994  cct_rot_scale *= 3.0f;
995  cct_trans_scale *= 5.0f;
996  }
997  if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LCONTROL))
998  {
999  cct_rot_scale *= 6.0f;
1000  cct_trans_scale *= 10.0f;
1001  }
1002  if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU))
1003  {
1004  cct_rot_scale *= 0.2f;
1005  cct_trans_scale *= 0.2f;
1006  }
1007 
1008  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_SIDESTEP_LEFT))
1009  {
1010  mTrans.x -= cct_trans_scale;
1011  }
1012  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_SIDESTEP_RIGHT))
1013  {
1014  mTrans.x += cct_trans_scale;
1015  }
1016  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_FORWARD))
1017  {
1018  mTrans.z -= cct_trans_scale;
1019  }
1020  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_BACKWARDS))
1021  {
1022  mTrans.z += cct_trans_scale;
1023  }
1024  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CAMERA_UP))
1025  {
1026  mTrans.y += cct_trans_scale;
1027  }
1028  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CAMERA_DOWN))
1029  {
1030  mTrans.y -= cct_trans_scale;
1031  }
1032 
1033  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_RIGHT))
1034  {
1035  mRotX -= cct_rot_scale;
1036  }
1037  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_LEFT))
1038  {
1039  mRotX += cct_rot_scale;
1040  }
1041  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_ROT_UP))
1042  {
1043  mRotY += cct_rot_scale;
1044  }
1045  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_ROT_DOWN))
1046  {
1047  mRotY -= cct_rot_scale;
1048  }
1049 
1050  App::GetCameraManager()->GetCameraNode()->yaw(mRotX, Ogre::Node::TS_WORLD);
1051  App::GetCameraManager()->GetCameraNode()->pitch(mRotY);
1052 
1053  Vector3 camPosition = this->GetCameraNode()->getPosition() + this->GetCameraNode()->getOrientation() * mTrans.normalisedCopy() * cct_trans_scale;
1054 
1055  this->GetCameraNode()->setPosition(camPosition);
1056 }
1057 
1059 {
1060  if (App::gfx_fixed_cam_tracking->getBool())
1061  {
1063  App::GetCameraManager()->GetCameraNode()->lookAt(look_at, Ogre::Node::TS_WORLD);
1064  }
1065 }
1066 
1068 {
1069  Vector3 dir = m_cct_player_actor->getDirection();
1070 
1071  m_cam_target_direction = -atan2(dir.dotProduct(Vector3::UNIT_X), dir.dotProduct(-Vector3::UNIT_Z));
1072  m_cam_target_pitch = 0.0f;
1073 
1074  if ( RoR::App::gfx_extcam_mode->getEnum<GfxExtCamMode>() == RoR::GfxExtCamMode::PITCHING)
1075  {
1076  m_cam_target_pitch = -asin(dir.dotProduct(Vector3::UNIT_Y));
1077  }
1078 
1079  m_cam_ratio = 1.0f / (m_cct_dt * 4.0f);
1080 
1081  m_cam_dist_min = std::min(m_cct_player_actor->getMinimalCameraRadius() * 2.0f, 33.0f);
1082 
1084 
1086 }
1087 
1089 {
1091  m_cam_rot_y = 0.35f;
1092  m_cam_dist_min = std::min(m_cct_player_actor->getMinimalCameraRadius() * 2.0f, 33.0f);
1093  m_cam_dist = m_cam_dist_min * 1.5f + 2.0f;
1094 }
1095 
1097 {
1098  // IMPORTANT: get mouse button state from InputEngine, not from OIS directly
1099  // - that state may be dirty, see commentary in `InputEngine::getMouseState()`
1100  const OIS::MouseState ms = App::GetInputEngine()->getMouseState();
1101 
1102  if ( ms.buttonDown(OIS::MB_Middle) && RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) )
1103  {
1105  {
1106  // Calculate new camera distance
1108  m_cam_dist = 2.0f * this->GetCameraNode()->getPosition().distance(lookAt);
1109 
1110  // Calculate new camera pitch
1111  Vector3 camDir = (this->GetCameraNode()->getPosition() - lookAt).normalisedCopy();
1112  m_cam_rot_y = asin(camDir.y);
1113 
1114  // Calculate new camera yaw
1115  Vector3 dir = -m_cct_player_actor->getDirection();
1116  Quaternion rotX = dir.getRotationTo(camDir, Vector3::UNIT_Y);
1117  m_cam_rot_x = rotX.getYaw();
1118 
1119  // Corner case handling
1120  Radian angle = dir.angleBetween(camDir);
1121  if ( angle > Radian(Math::HALF_PI) )
1122  {
1123  if ( std::abs(Radian(m_cam_rot_x).valueRadians()) < Math::HALF_PI )
1124  {
1125  if ( m_cam_rot_x < Radian(0.0f) )
1126  m_cam_rot_x -= Radian(Math::HALF_PI);
1127  else
1128  m_cam_rot_x += Radian(Math::HALF_PI);
1129  }
1130  }
1131  }
1132  }
1133 
1134  return false;
1135 }
1136 
1138 {
1140  {
1141  this->switchToNextBehavior();
1142  return;
1143  }
1144 
1145  Vector3 dir = m_cct_player_actor->getDirection();
1146 
1147  m_cam_target_pitch = 0.0f;
1148 
1149  if (App::gfx_extcam_mode->getEnum<GfxExtCamMode>() == GfxExtCamMode::PITCHING)
1150  {
1151  m_cam_target_pitch = -asin(dir.dotProduct(Vector3::UNIT_Y));
1152  }
1153 
1155  {
1157  }
1160 
1162 
1163  if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) && RoR::App::GetInputEngine()->isKeyDownValueBounce(OIS::KC_SPACE))
1164  {
1167  {
1168  RoR::App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE, _L("Auto tracking enabled"), "camera_go.png");
1169  }
1170  else
1171  {
1172  RoR::App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE, _L("Auto tracking disabled"), "camera_go.png");
1173  }
1174  }
1175 
1177  {
1178  Vector3 centerDir = m_cct_player_actor->getPosition() - m_cam_look_at;
1179  if (centerDir.length() > 1.0f)
1180  {
1181  centerDir.normalise();
1182  Radian oldTargetDirection = m_cam_target_direction;
1183  m_cam_target_direction = -atan2(centerDir.dotProduct(Vector3::UNIT_X), centerDir.dotProduct(-Vector3::UNIT_Z));
1184  if (m_cam_target_direction.valueRadians() * oldTargetDirection.valueRadians() < 0.0f && centerDir.length() < m_cam_dist_min)
1185  {
1187  }
1188  }
1189  }
1190 
1192 }
1193 
1195 {
1196  // IMPORTANT: get mouse button state from InputEngine, not from OIS directly
1197  // - that state may be dirty, see commentary in `InputEngine::getMouseState()`
1198  const OIS::MouseState ms = App::GetInputEngine()->getMouseState();
1199 
1200  m_cam_ratio = 1.0f / (m_cct_dt * 4.0f);
1201 
1202  if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LCONTROL) && ms.buttonDown(OIS::MB_Right))
1203  {
1204  Real splinePosDiff = ms.X.rel * std::max(0.00005f, m_splinecam_spline_len * 0.0000001f);
1205 
1207  {
1208  splinePosDiff *= 3.0f;
1209  }
1210 
1211  if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU))
1212  {
1213  splinePosDiff *= 0.1f;
1214  }
1215 
1216  m_splinecam_spline_pos += splinePosDiff;
1217 
1218  if (ms.X.rel > 0 && m_splinecam_spline_pos > 0.99f)
1219  {
1221  {
1222  m_splinecam_spline_pos -= 1.0f;
1223  }
1224  else
1225  {
1226  // u - turn
1227  }
1228  }
1229  else if (ms.X.rel < 0 && m_splinecam_spline_pos < 0.01f)
1230  {
1232  {
1233  m_splinecam_spline_pos += 1.0f;
1234  }
1235  else
1236  {
1237  // u - turn
1238  }
1239  }
1240 
1243 
1244  return true;
1245  }
1246  else
1247  {
1249  }
1250 }
1251 
1253 {
1255 
1256  m_cam_dist = std::min(m_cct_player_actor->getMinimalCameraRadius() * 2.0f, 33.0f);
1257 
1258  m_splinecam_spline_pos = 0.5f;
1259 }
1260 
1262 {
1263  m_splinecam_spline_closed = false;
1264  m_splinecam_spline_len = 1.0f;
1265 
1266  m_splinecam_spline->clear();
1267  m_splinecam_spline_nodes.clear();
1268 
1269  for (int i = 0; i < m_cct_player_actor->ar_num_camera_rails; i++)
1270  {
1272  }
1273 
1274  auto linkedBeams = m_cct_player_actor->ar_linked_actors;
1275 
1276  m_splinecam_num_linked_beams = static_cast<int>(linkedBeams.size());
1277 
1279  {
1280  for (ActorPtr& actor : linkedBeams)
1281  {
1282  if (actor->ar_num_camera_rails <= 0)
1283  continue;
1284 
1285  Vector3 curSplineFront = m_splinecam_spline_nodes.front()->AbsPosition;
1286  Vector3 curSplineBack = m_splinecam_spline_nodes.back()->AbsPosition;
1287 
1288  Vector3 linkedSplineFront = actor->ar_nodes[actor->ar_camera_rail[0]].AbsPosition;
1289  Vector3 linkedSplineBack = actor->ar_nodes[actor->ar_camera_rail[actor->ar_num_camera_rails - 1]].AbsPosition;
1290 
1291  if (curSplineBack.distance(linkedSplineFront) < 5.0f)
1292  {
1293  for (int i = 1; i < actor->ar_num_camera_rails; i++)
1294  {
1295  m_splinecam_spline_nodes.push_back(&actor->ar_nodes[actor->ar_camera_rail[i]]);
1296  }
1297  }
1298  else if (curSplineFront.distance(linkedSplineFront) < 5.0f)
1299  {
1300  for (int i = 1; i < actor->ar_num_camera_rails; i++)
1301  {
1302  m_splinecam_spline_nodes.push_front(&actor->ar_nodes[actor->ar_camera_rail[i]]);
1303  }
1304  }
1305  else if (curSplineBack.distance(linkedSplineBack) < 5.0f)
1306  {
1307  for (int i = actor->ar_num_camera_rails - 2; i >= 0; i--)
1308  {
1309  m_splinecam_spline_nodes.push_back(&actor->ar_nodes[actor->ar_camera_rail[i]]);
1310  }
1311  }
1312  else if (curSplineFront.distance(linkedSplineBack) < 5.0f)
1313  {
1314  for (int i = actor->ar_num_camera_rails - 2; i >= 0; i--)
1315  {
1316  m_splinecam_spline_nodes.push_front(&actor->ar_nodes[actor->ar_camera_rail[i]]);
1317  }
1318  }
1319  }
1320  }
1321 
1322  for (unsigned int i = 0; i < m_splinecam_spline_nodes.size(); i++)
1323  {
1324  m_splinecam_spline->addPoint(m_splinecam_spline_nodes[i]->AbsPosition);
1325  }
1326 
1327  Vector3 firstPoint = m_splinecam_spline->getPoint(0);
1328  Vector3 lastPoint = m_splinecam_spline->getPoint(m_splinecam_spline->getNumPoints() - 1);
1329 
1330  if (firstPoint.distance(lastPoint) < 1.0f)
1331  {
1333  }
1334 
1335  for (int i = 1; i < m_splinecam_spline->getNumPoints(); i++)
1336  {
1337  m_splinecam_spline_len += m_splinecam_spline->getPoint(i - 1).distance(m_splinecam_spline->getPoint(i));
1338  }
1339 
1340  m_splinecam_spline_len /= 2.0f;
1341 
1342  if (!m_splinecam_mo && RoR::App::diag_camera->getBool())
1343  {
1344  m_splinecam_mo = App::GetGfxScene()->GetSceneManager()->createManualObject();
1345  SceneNode* splineNode = App::GetGfxScene()->GetSceneManager()->getRootSceneNode()->createChildSceneNode();
1346 
1347  m_splinecam_mo->begin("tracks/transred", Ogre::RenderOperation::OT_LINE_STRIP);
1348  for (int i = 0; i < SPLINECAM_DRAW_RESOLUTION; i++)
1349  {
1350  m_splinecam_mo->position(0, 0, 0);
1351  }
1352  m_splinecam_mo->end();
1353 
1354  splineNode->attachObject(m_splinecam_mo);
1355  }
1356 }
1357 
1359 {
1360  for (int i = 0; i < m_splinecam_spline->getNumPoints(); i++)
1361  {
1362  m_splinecam_spline->updatePoint(i, m_splinecam_spline_nodes[i]->AbsPosition);
1363  }
1364 }
1365 
1367 {
1368  if (!m_splinecam_mo)
1369  return;
1370 
1371  m_splinecam_mo->beginUpdate(0);
1372  for (int i = 0; i < SPLINECAM_DRAW_RESOLUTION; i++)
1373  {
1374  Real parametricDist = i / (float)SPLINECAM_DRAW_RESOLUTION;
1375  Vector3 position = m_splinecam_spline->interpolate(parametricDist);
1376  m_splinecam_mo->position(position);
1377  }
1378  m_splinecam_mo->end();
1379 }
ROR_ASSERT
#define ROR_ASSERT(_EXPR)
Definition: Application.h:40
GameContext.h
Game state manager and message-queue provider.
RoR::CameraManager::UpdateInputEvents
void UpdateInputEvents(float dt)
Definition: CameraManager.cpp:242
RoR::App::io_invert_orbitcam
CVar * io_invert_orbitcam
Definition: Application.cpp:206
RoR::CameraManager::CAMERA_BEHAVIOR_INVALID
@ CAMERA_BEHAVIOR_INVALID
Definition: CameraManager.h:55
RoR::CameraManager::hasActiveBehavior
bool hasActiveBehavior()
Definition: CameraManager.cpp:524
RoR::Character::getRotation
Ogre::Radian getRotation() const
Definition: Character.h:54
RoR::CameraManager::UpdateCameraBehaviorVehicle
void UpdateCameraBehaviorVehicle()
Definition: CameraManager.cpp:1067
RoR::IWater::GetStaticWaterHeight
virtual float GetStaticWaterHeight()=0
Returns static water level configured in 'terrn2'.
RoR::ActorManager::GetSimulationSpeed
float GetSimulationSpeed() const
Definition: ActorManager.h:93
RoR::EV_CAMERA_ZOOM_OUT_FAST
@ EV_CAMERA_ZOOM_OUT_FAST
zoom camera out faster
Definition: InputEngine.h:128
RoR::CameraManager::m_cam_target_direction
Ogre::Radian m_cam_target_direction
Definition: CameraManager.h:121
RoR::CameraManager::m_cam_look_at_smooth_last
Ogre::Vector3 m_cam_look_at_smooth_last
Definition: CameraManager.h:131
RoR::Actor::getMinCameraRadius
float getMinCameraRadius()
Definition: Actor.h:254
RoR::App::gfx_fov_internal
CVar * gfx_fov_internal
Definition: Application.cpp:240
RoR::Actor::ar_camera_node_dir
NodeNum_t ar_camera_node_dir[MAX_CAMERAS]
Physics attr; 'camera' = frame of reference; back node.
Definition: Actor.h:392
RoR::node_t::Velocity
Ogre::Vector3 Velocity
Definition: SimData.h:295
RoR::CameraManager::m_staticcam_update_timer
Ogre::Timer m_staticcam_update_timer
Definition: CameraManager.h:138
RoR::PerVehicleCameraContext::CAMCTX_BEHAVIOR_VEHICLE_3rdPERSON
@ CAMCTX_BEHAVIOR_VEHICLE_3rdPERSON
Definition: PerVehicleCameraContext.h:19
PerVehicleCameraContext.h
OverlayWrapper.h
RoR::CameraManager::m_cam_dist_min
float m_cam_dist_min
Definition: CameraManager.h:124
RoR::App::GetCameraManager
CameraManager * GetCameraManager()
Definition: Application.cpp:275
RoR::node_t::AbsPosition
Ogre::Vector3 AbsPosition
absolute position in the world (shaky)
Definition: SimData.h:294
RoR::App::GetGuiManager
GUIManager * GetGuiManager()
Definition: Application.cpp:269
RoR::CameraManager::UpdateCameraBehaviorFree
void UpdateCameraBehaviorFree()
Definition: CameraManager.cpp:984
RoR::EV_CAMERA_ROTATE_UP
@ EV_CAMERA_ROTATE_UP
rotate camera up
Definition: InputEngine.h:123
RoR::Actor::ar_linked_actors
ActorPtrVec ar_linked_actors
BEWARE: Includes indirect links, see DetermineLinkedActors(); Other actors linked using 'hooks/ties/r...
Definition: Actor.h:447
RoR::GfxExtCamMode::PITCHING
@ PITCHING
RoR::CameraManager::m_cam_look_at_last
Ogre::Vector3 m_cam_look_at_last
Definition: CameraManager.h:129
RoR::App::gfx_fixed_cam_tracking
CVar * gfx_fixed_cam_tracking
Definition: Application.cpp:243
RoR::InputEngine::getMouseState
OIS::MouseState getMouseState()
Definition: InputEngine.cpp:603
RoR::App::GetAppContext
AppContext * GetAppContext()
Definition: Application.cpp:266
RoR::NODENUM_INVALID
static const NodeNum_t NODENUM_INVALID
Definition: ForwardDeclarations.h:53
RoR::ActorState::LOCAL_REPLAY
@ LOCAL_REPLAY
RoR::CameraManager::CameraBehaviorOrbitMouseMoved
bool CameraBehaviorOrbitMouseMoved()
Definition: CameraManager.cpp:947
RoR::EV_CAMERA_ZOOM_IN
@ EV_CAMERA_ZOOM_IN
zoom camera in
Definition: InputEngine.h:125
RoR::EV_CHARACTER_ROT_DOWN
@ EV_CHARACTER_ROT_DOWN
Definition: InputEngine.h:134
RoR::CameraManager::m_current_behavior
CameraBehaviors m_current_behavior
Definition: CameraManager.h:109
RoR::CameraManager::m_staticcam_look_at
Ogre::Vector3 m_staticcam_look_at
Definition: CameraManager.h:136
RoR::CameraManager::CAMERA_BEHAVIOR_FREE
@ CAMERA_BEHAVIOR_FREE
Definition: CameraManager.h:52
RoR::GameContext::GetPlayerCharacter
Character * GetPlayerCharacter()
Definition: GameContext.cpp:872
RoR::CameraManager::NotifyVehicleChanged
void NotifyVehicleChanged(ActorPtr new_vehicle)
Definition: CameraManager.cpp:633
RoR::CameraManager::CAMERA_BEHAVIOR_ISOMETRIC
@ CAMERA_BEHAVIOR_ISOMETRIC
Definition: CameraManager.h:54
RoR::App::gfx_extcam_mode
CVar * gfx_extcam_mode
Definition: Application.cpp:218
RoR::SimState::EDITOR_MODE
@ EDITOR_MODE
Hacky, but whatever... added by Ulteq, 2016.
RoR::CameraManager::DeactivateCurrentBehavior
void DeactivateCurrentBehavior()
Definition: CameraManager.cpp:468
RoR::App::GetOverlayWrapper
OverlayWrapper * GetOverlayWrapper()
Definition: Application.cpp:268
RoR::CameraManager::CameraBehaviors
CameraBehaviors
Definition: CameraManager.h:44
RoR::EV_CHARACTER_BACKWARDS
@ EV_CHARACTER_BACKWARDS
step backwards with the character
Definition: InputEngine.h:129
CameraManager.h
RoR::PerVehicleCameraContext::CAMCTX_BEHAVIOR_EXTERNAL
@ CAMCTX_BEHAVIOR_EXTERNAL
Definition: PerVehicleCameraContext.h:18
RoR::GUIManager::IsGuiHidden
bool IsGuiHidden() const
Definition: GUIManager.h:142
AppContext.h
System integration layer; inspired by OgreBites::ApplicationContext.
Console.h
RoR::App::gfx_fov_external_default
CVar * gfx_fov_external_default
Definition: Application.cpp:239
RoR::Console::putMessage
void putMessage(MessageArea area, MessageType type, std::string const &msg, std::string icon="")
Definition: Console.cpp:97
RoR::CameraManager::ActivateNewBehavior
void ActivateNewBehavior(CameraBehaviors new_behavior, bool reset)
Definition: CameraManager.cpp:375
intersectsTerrain
bool intersectsTerrain(Vector3 a, Vector3 b)
Definition: CameraManager.cpp:52
RoR::Actor::ar_current_cinecam
int ar_current_cinecam
Sim state; index of current CineCam (-1 if using 3rd-person camera)
Definition: Actor.h:423
RoR::CameraManager::UpdateCurrentBehavior
void UpdateCurrentBehavior()
Definition: CameraManager.cpp:186
CHARACTERCAM_OFFSET_1ST_PERSON
static const Ogre::Vector3 CHARACTERCAM_OFFSET_1ST_PERSON(0.0f, 1.82f, 0.0f)
RoR::CameraManager::CAMERA_BEHAVIOR_END
@ CAMERA_BEHAVIOR_END
Definition: CameraManager.h:51
RoR::PerVehicleCameraContext::behavior
CameraCtxBehavior behavior
Definition: PerVehicleCameraContext.h:28
RoR::AppContext::GetViewport
Ogre::Viewport * GetViewport()
Definition: AppContext.h:66
RoR::App::gfx_static_cam_fov_exp
CVar * gfx_static_cam_fov_exp
Definition: Application.cpp:242
RoR::EV_COMMON_FOV_LESS
@ EV_COMMON_FOV_LESS
decreases the current FOV value
Definition: InputEngine.h:234
RoR::CameraManager::m_cct_player_actor
ActorPtr m_cct_player_actor
Definition: CameraManager.h:113
RoR::App::sim_state
CVar * sim_state
Definition: Application.cpp:96
RoR::CameraManager::GetCameraNode
Ogre::SceneNode * GetCameraNode()
Definition: CameraManager.h:63
RoR::CameraManager::UpdateCameraBehaviorFixed
void UpdateCameraBehaviorFixed()
Definition: CameraManager.cpp:1058
Language.h
RoR::EV_CHARACTER_ROT_UP
@ EV_CHARACTER_ROT_UP
Definition: InputEngine.h:135
RoR::InputEngine::getEventBoolValueBounce
bool getEventBoolValueBounce(int eventID, float time=0.2f)
Definition: InputEngine.cpp:762
RoR::CameraManager::m_cam_dist_max
float m_cam_dist_max
Definition: CameraManager.h:125
RefCountingObjectPtr< Actor >
RoR::InputEngine::getEventValue
float getEventValue(int eventID, bool pure=false, InputSourceType valueSource=InputSourceType::IST_ANY)
valueSource: IST_ANY=digital and analog devices, IST_DIGITAL=only digital, IST_ANALOG=only analog
Definition: InputEngine.cpp:958
RoR::EV_CHARACTER_RIGHT
@ EV_CHARACTER_RIGHT
rotate character right
Definition: InputEngine.h:133
RoR::CameraManager::m_cam_before_toggled
CameraBehaviors m_cam_before_toggled
Toggled modes (FREE, FREEFIX) remember original state.
Definition: CameraManager.h:110
RoR::CameraManager::m_splinecam_spline_pos
Ogre::Real m_splinecam_spline_pos
Definition: CameraManager.h:145
GUIManager.h
RoR::CameraManager::m_cam_look_at
Ogre::Vector3 m_cam_look_at
Definition: CameraManager.h:127
ActorManager.h
Actor.h
RoR::InputEngine::isKeyDown
bool isKeyDown(OIS::KeyCode mod)
Asks OIS directly.
Definition: InputEngine.cpp:1170
RoR::GfxScene::GetSceneManager
Ogre::SceneManager * GetSceneManager()
Definition: GfxScene.h:64
RoR::Console::CONSOLE_SYSTEM_NOTICE
@ CONSOLE_SYSTEM_NOTICE
Definition: Console.h:51
RoR::CameraManager::CameraBehaviorOrbitUpdate
void CameraBehaviorOrbitUpdate()
Definition: CameraManager.cpp:822
RoR::CameraManager::m_staticcam_fov_exponent
float m_staticcam_fov_exponent
Definition: CameraManager.h:134
RoR::CameraManager::NotifyContextChange
void NotifyContextChange()
Definition: CameraManager.cpp:617
RoR::CameraManager::m_splinecam_spline_nodes
std::deque< node_t * > m_splinecam_spline_nodes
Definition: CameraManager.h:148
RoR::Terrain::GetHeightAt
float GetHeightAt(float x, float z)
Definition: Terrain.cpp:503
Replay.h
RoR::Actor::getReplay
Replay * getReplay()
Definition: Actor.cpp:4566
RoR::CameraManager::m_cct_trans_scale
Ogre::Real m_cct_trans_scale
Definition: CameraManager.h:116
RoR::CameraManager::GetCurrentBehavior
CameraBehaviors GetCurrentBehavior() const
Definition: CameraManager.h:62
RoR::App::gfx_camera_height
CVar * gfx_camera_height
Definition: Application.cpp:237
RoR::CameraManager::CAMERA_BEHAVIOR_STATIC
@ CAMERA_BEHAVIOR_STATIC
Definition: CameraManager.h:47
RoR::Replay::getPrecision
float getPrecision() const
Definition: Replay.h:51
Script2Game::KC_LSHIFT
enum Script2Game::inputEvents KC_LSHIFT
RoR::CameraManager::m_staticcam_force_update
bool m_staticcam_force_update
Definition: CameraManager.h:133
RoR::EV_CAMERA_ZOOM_OUT
@ EV_CAMERA_ZOOM_OUT
zoom camera out
Definition: InputEngine.h:127
RoR::EV_CAMERA_FREE_MODE
@ EV_CAMERA_FREE_MODE
Definition: InputEngine.h:116
RoR::CameraManager::GetCamera
Ogre::Camera * GetCamera()
Definition: CameraManager.h:64
RoR::CameraManager::~CameraManager
~CameraManager()
Definition: CameraManager.cpp:126
RoR::EV_CAMERA_ZOOM_IN_FAST
@ EV_CAMERA_ZOOM_IN_FAST
zoom camera in faster
Definition: InputEngine.h:126
RoR::Collisions::intersectsTris
std::pair< bool, Ogre::Real > intersectsTris(Ogre::Ray ray)
Definition: Collisions.cpp:628
RoR::NodeNum_t
uint16_t NodeNum_t
Node position within Actor::ar_nodes; use RoR::NODENUM_INVALID as empty value.
Definition: ForwardDeclarations.h:52
RoR::Str
Wrapper for classic c-string (local buffer) Refresher: strlen() excludes '\0' terminator; strncat() A...
Definition: Str.h:35
RoR::Actor::ar_camera_node_roll
NodeNum_t ar_camera_node_roll[MAX_CAMERAS]
Physics attr; 'camera' = frame of reference; left node.
Definition: Actor.h:393
RoR::CameraManager::ReCreateCameraNode
void ReCreateCameraNode()
Needed since we call Ogre::SceneManager::ClearScene() after end of sim. session.
Definition: CameraManager.cpp:142
RoR::CameraManager::m_cct_dt
Ogre::Real m_cct_dt
Definition: CameraManager.h:115
DEFAULT_INTERNAL_CAM_PITCH
static const int DEFAULT_INTERNAL_CAM_PITCH
Definition: CameraManager.cpp:48
RoR::EV_CAMERA_ROTATE_LEFT
@ EV_CAMERA_ROTATE_LEFT
rotate camera left
Definition: InputEngine.h:121
RoR::CameraManager::m_staticcam_position
Ogre::Vector3 m_staticcam_position
Definition: CameraManager.h:137
RoR::CameraManager::CameraBehaviorVehicleMousePressed
bool CameraBehaviorVehicleMousePressed()
Definition: CameraManager.cpp:1096
RoR::EV_CHARACTER_SIDESTEP_RIGHT
@ EV_CHARACTER_SIDESTEP_RIGHT
sidestep to the right
Definition: InputEngine.h:138
RoR::CameraManager::CAMERA_BEHAVIOR_VEHICLE_SPLINE
@ CAMERA_BEHAVIOR_VEHICLE_SPLINE
Definition: CameraManager.h:49
RoR::EV_CAMERA_ROTATE_DOWN
@ EV_CAMERA_ROTATE_DOWN
rotate camera down
Definition: InputEngine.h:120
RoR::CameraManager::CAMERA_BEHAVIOR_CHARACTER
@ CAMERA_BEHAVIOR_CHARACTER
Definition: CameraManager.h:46
RoR::CameraManager::m_splinecam_num_linked_beams
unsigned int m_splinecam_num_linked_beams
Definition: CameraManager.h:149
RoR::Str::ToCStr
const char * ToCStr() const
Definition: Str.h:46
RoR::CameraManager::ResetAllBehaviors
void ResetAllBehaviors()
Definition: CameraManager.cpp:529
RoR::Terrain::GetCollisions
Collisions * GetCollisions()
Definition: Terrain.h:83
RoR::Actor::getPosition
Ogre::Vector3 getPosition()
Definition: Actor.cpp:424
GfxScene.h
RoR::Actor::NotifyActorCameraChanged
void NotifyActorCameraChanged()
Logic: sound, display; Notify this vehicle that camera changed;.
Definition: Actor.cpp:3844
Character.h
RoR::CameraManager::m_splinecam_spline
Ogre::SimpleSpline * m_splinecam_spline
Definition: CameraManager.h:143
Script2Game::KC_SPACE
enum Script2Game::inputEvents KC_SPACE
RoR::CameraManager::CAMERA_BEHAVIOR_VEHICLE
@ CAMERA_BEHAVIOR_VEHICLE
Definition: CameraManager.h:48
RoR::OverlayWrapper::showDashboardOverlays
void showDashboardOverlays(bool show, ActorPtr actor)
Definition: OverlayWrapper.cpp:375
RoR::SimState::PAUSED
@ PAUSED
RoR::App::GetConsole
Console * GetConsole()
Definition: Application.cpp:270
RoR::CameraManager::CAMERA_BEHAVIOR_FIXED
@ CAMERA_BEHAVIOR_FIXED
Definition: CameraManager.h:53
RoR::App::GetGameContext
GameContext * GetGameContext()
Definition: Application.cpp:280
RoR::PerVehicleCameraContext::CAMCTX_BEHAVIOR_VEHICLE_SPLINE
@ CAMCTX_BEHAVIOR_VEHICLE_SPLINE
Definition: PerVehicleCameraContext.h:20
RoR::Character::getPosition
Ogre::Vector3 getPosition()
Definition: Character.cpp:92
RoR::App::gfx_fov_internal_default
CVar * gfx_fov_internal_default
Definition: Application.cpp:241
RoR::AIRPLANE
@ AIRPLANE
its an airplane
Definition: SimData.h:94
RoR::EV_CHARACTER_FORWARD
@ EV_CHARACTER_FORWARD
step forward with the character
Definition: InputEngine.h:130
RoR::EV_COMMON_FOV_MORE
@ EV_COMMON_FOV_MORE
increases the current FOV value
Definition: InputEngine.h:235
RoR::EV_CAMERA_LOOKBACK
@ EV_CAMERA_LOOKBACK
look back (toggles between normal and lookback)
Definition: InputEngine.h:118
RoR::CameraManager::CameraBehaviorStaticMouseMoved
bool CameraBehaviorStaticMouseMoved()
Definition: CameraManager.cpp:804
RoR::EV_CAMERA_FREE_MODE_FIX
@ EV_CAMERA_FREE_MODE_FIX
Definition: InputEngine.h:117
RoR::CameraManager::m_camera
Ogre::Camera * m_camera
Definition: CameraManager.h:106
RoR::Actor::getDirection
Ogre::Vector3 getDirection()
average actor velocity, calculated using the actor positions of the last two frames
Definition: Actor.cpp:419
RoR::Actor::ar_camera_node_roll_inv
bool ar_camera_node_roll_inv[MAX_CAMERAS]
Physics attr; 'camera' = frame of reference; indicates roll node is right instead of left.
Definition: Actor.h:394
RoR::CameraManager::CameraBehaviorVehicleReset
void CameraBehaviorVehicleReset()
Definition: CameraManager.cpp:1088
frand
float frand()
Definition: ApproxMath.h:31
RoR::CameraManager::ResetCurrentBehavior
void ResetCurrentBehavior()
Definition: CameraManager.cpp:326
RoR::CameraManager::m_splinecam_mo
Ogre::ManualObject * m_splinecam_mo
Definition: CameraManager.h:142
RoR::CameraManager::m_cam_rot_y
Ogre::Radian m_cam_rot_y
Definition: CameraManager.h:120
TRANS_SPEED
static const float TRANS_SPEED
Definition: CameraManager.cpp:49
ApproxMath.h
RoR::CameraManager::m_cct_sim_speed
float m_cct_sim_speed
Definition: CameraManager.h:117
RoR::CameraManager::m_charactercam_is_3rdperson
bool m_charactercam_is_3rdperson
Definition: CameraManager.h:140
RoR::GUIManager::SetMouseCursorVisibility
void SetMouseCursorVisibility(MouseCursorVisibility visi)
Definition: GUIManager.cpp:265
RoR::Actor::ar_num_cinecams
int ar_num_cinecams
Sim attr;.
Definition: Actor.h:381
RoR::CVar
Quake-style console variable, defined in RoR.cfg or crated via Console UI and scripts.
Definition: CVar.h:52
RoR::CameraManager::m_camera_node
Ogre::SceneNode * m_camera_node
Definition: CameraManager.h:107
RoR::Actor::GetCameraContext
PerVehicleCameraContext * GetCameraContext()
Definition: Actor.h:265
RoR::CameraManager::handleMouseMoved
bool handleMouseMoved()
Definition: CameraManager.cpp:534
RoR::Collisions::forcecam
bool forcecam
Definition: Collisions.h:172
RoR::EV_CAMERA_RESET
@ EV_CAMERA_RESET
reset the camera position
Definition: InputEngine.h:119
RoR::CameraManager::CameraBehaviorVehicleSplineMouseMoved
bool CameraBehaviorVehicleSplineMouseMoved()
Definition: CameraManager.cpp:1194
RoR::Actor::ar_nodes
node_t * ar_nodes
Definition: Actor.h:279
Script2Game::KC_RSHIFT
enum Script2Game::inputEvents KC_RSHIFT
RoR::Actor::getMinimalCameraRadius
Ogre::Real getMinimalCameraRadius()
Definition: Actor.cpp:4561
RoR::EV_CAMERA_CHANGE
@ EV_CAMERA_CHANGE
change camera mode
Definition: InputEngine.h:114
RoR::CameraManager::switchBehavior
void switchBehavior(CameraBehaviors new_behavior)
Definition: CameraManager.cpp:485
RoR::CameraManager::m_cam_limit_movement
bool m_cam_limit_movement
Definition: CameraManager.h:128
RoR::CameraManager::m_cam_ratio
float m_cam_ratio
Definition: CameraManager.h:126
SPLINECAM_DRAW_RESOLUTION
static const int SPLINECAM_DRAW_RESOLUTION
Definition: CameraManager.cpp:47
RoR::CameraManager::m_staticcam_previous_fov
Ogre::Radian m_staticcam_previous_fov
Definition: CameraManager.h:135
RoR::Actor::ar_driveable
ActorType ar_driveable
Sim attr; marks vehicle type and features.
Definition: Actor.h:378
RoR::CVar::setVal
void setVal(T val)
Definition: CVar.h:72
_L
#define _L
Definition: ErrorUtils.cpp:34
RoR::CameraManager::CameraBehaviorVehicleSplineUpdate
void CameraBehaviorVehicleSplineUpdate()
Definition: CameraManager.cpp:1137
RoR::App::diag_camera
CVar * diag_camera
Definition: Application.cpp:134
RoR::Actor::ar_custom_camera_node
NodeNum_t ar_custom_camera_node
Sim state; custom tracking node for 3rd-person camera.
Definition: Actor.h:424
RoR::CameraManager::m_cam_target_pitch
Ogre::Radian m_cam_target_pitch
Definition: CameraManager.h:122
RoR::CameraManager::SwitchBehaviorOnVehicleChange
void SwitchBehaviorOnVehicleChange(CameraBehaviors new_behavior, ActorPtr new_vehicle)
Definition: CameraManager.cpp:510
RoR::CameraManager::m_cam_rot_x
Ogre::Radian m_cam_rot_x
Definition: CameraManager.h:119
RoR::App::GetInputEngine
InputEngine * GetInputEngine()
Definition: Application.cpp:271
CHARACTERCAM_OFFSET_3RD_PERSON
static const Ogre::Vector3 CHARACTERCAM_OFFSET_3RD_PERSON(0.0f, 1.1f, 0.0f)
RoR::CameraManager::ToggleCameraBehavior
void ToggleCameraBehavior(CameraBehaviors new_behavior)
Only accepts FREE and FREEFIX modes.
Definition: CameraManager.cpp:672
RoR::Actor::ar_num_camera_rails
int ar_num_camera_rails
Definition: Actor.h:344
RoR::App::gfx_fov_external
CVar * gfx_fov_external
Definition: Application.cpp:238
RoR::CameraManager::m_cam_look_at_smooth
Ogre::Vector3 m_cam_look_at_smooth
Definition: CameraManager.h:130
RoR::EV_CHARACTER_SIDESTEP_LEFT
@ EV_CHARACTER_SIDESTEP_LEFT
sidestep to the left
Definition: InputEngine.h:137
Terrain.h
RoR::SimState::RUNNING
@ RUNNING
InputEngine.h
Handles controller inputs from player. Defines input events and binding mechanism,...
RoR::CVar::getFloat
float getFloat() const
Definition: CVar.h:96
ROTATE_SPEED
static const float ROTATE_SPEED
Definition: CameraManager.cpp:50
Ogre
Definition: ExtinguishableFireAffector.cpp:35
RoR::CameraManager::CameraBehaviorVehicleSplineUpdateSpline
void CameraBehaviorVehicleSplineUpdateSpline()
Definition: CameraManager.cpp:1358
RoR::CameraManager::UpdateCameraBehaviorStatic
void UpdateCameraBehaviorStatic()
Definition: CameraManager.cpp:703
RoR::CVar::getInt
int getInt() const
Definition: CVar.h:97
RoR::Console::CONSOLE_MSGTYPE_INFO
@ CONSOLE_MSGTYPE_INFO
Generic message.
Definition: Console.h:60
RoR::CameraManager::EvaluateSwitchBehavior
bool EvaluateSwitchBehavior()
Definition: CameraManager.cpp:148
RoR::EV_CAMERA_UP
@ EV_CAMERA_UP
Definition: InputEngine.h:124
RoR::Actor::ar_camera_node_pos
NodeNum_t ar_camera_node_pos[MAX_CAMERAS]
Physics attr; 'camera' = frame of reference; origin node.
Definition: Actor.h:391
Collisions.h
RoR::CameraManager::m_cam_dist
float m_cam_dist
Definition: CameraManager.h:123
RoR::CameraManager::m_splinecam_spline_len
Ogre::Real m_splinecam_spline_len
Definition: CameraManager.h:144
RoR::CameraManager::CreateCameraNode
void CreateCameraNode()
Definition: CameraManager.cpp:134
RoR::CameraManager::m_prev_toggled_cam
CameraBehaviors m_prev_toggled_cam
Switching toggled modes (FREE, FREEFIX) keeps 1-slot history.
Definition: CameraManager.h:111
RoR::EV_CHARACTER_LEFT
@ EV_CHARACTER_LEFT
rotate character left
Definition: InputEngine.h:132
RoR::Actor::ar_state
ActorState ar_state
Definition: Actor.h:446
RoR::CameraManager::CameraBehaviorVehicleSplineCreateSpline
void CameraBehaviorVehicleSplineCreateSpline()
Definition: CameraManager.cpp:1261
RoR::GUIManager::MouseCursorVisibility::HIDDEN
@ HIDDEN
Hidden as inactive, will re-appear the moment user moves mouse.
RoR::GameContext::GetPlayerActor
const ActorPtr & GetPlayerActor()
Definition: GameContext.h:134
RoR::CameraManager::CameraBehaviorVehicleSplineUpdateSplineDisplay
void CameraBehaviorVehicleSplineUpdateSplineDisplay()
Definition: CameraManager.cpp:1366
RoR::Actor::prepareInside
void prepareInside(bool inside)
Prepares vehicle for in-cabin camera use.
Definition: Actor.cpp:2955
RoR::EV_COMMON_FOV_RESET
@ EV_COMMON_FOV_RESET
reset the FOV value
Definition: InputEngine.h:236
RoR::CameraManager::CameraBehaviorVehicleSplineReset
void CameraBehaviorVehicleSplineReset()
Definition: CameraManager.cpp:1252
RoR::EV_CAMERA_DOWN
@ EV_CAMERA_DOWN
Definition: InputEngine.h:115
RoR::Actor::ar_camera_rail
NodeNum_t ar_camera_rail[MAX_CAMERARAIL]
Nodes defining camera-movement spline.
Definition: Actor.h:343
RoR::CameraManager::CAMERA_BEHAVIOR_VEHICLE_CINECAM
@ CAMERA_BEHAVIOR_VEHICLE_CINECAM
Definition: CameraManager.h:50
RoR
Definition: AppContext.h:36
RoR::EV_CAMERA_ROTATE_RIGHT
@ EV_CAMERA_ROTATE_RIGHT
rotate camera right
Definition: InputEngine.h:122
Water.h
RoR::App::GetGfxScene
GfxScene * GetGfxScene()
Definition: Application.cpp:276
RoR::GameContext::GetActorManager
ActorManager * GetActorManager()
Definition: GameContext.h:127
RoR::CameraManager::handleMousePressed
bool handleMousePressed()
Definition: CameraManager.cpp:591
RoR::CameraManager::m_splinecam_spline_closed
bool m_splinecam_spline_closed
Definition: CameraManager.h:146
RoR::Terrain::getWater
IWater * getWater()
Definition: Terrain.h:84
RoR::Character::setRotation
void setRotation(Ogre::Radian rotation)
Definition: Character.cpp:98
RoR::CameraManager::m_splinecam_auto_tracking
bool m_splinecam_auto_tracking
Definition: CameraManager.h:147
RoR::Actor::ar_cinecam_node
NodeNum_t ar_cinecam_node[MAX_CAMERAS]
Sim attr; Cine-camera node indexes.
Definition: Actor.h:380
RoR::PerVehicleCameraContext::CAMCTX_BEHAVIOR_VEHICLE_CINECAM
@ CAMCTX_BEHAVIOR_VEHICLE_CINECAM
Definition: PerVehicleCameraContext.h:21
RoR::CameraManager::m_cct_rot_scale
Ogre::Degree m_cct_rot_scale
Definition: CameraManager.h:114
RoR::CameraManager::switchToNextBehavior
void switchToNextBehavior()
Definition: CameraManager.cpp:320
RoR::CameraManager::CameraBehaviorOrbitReset
void CameraBehaviorOrbitReset()
Definition: CameraManager.cpp:974
RoR::Actor::isBeingReset
bool isBeingReset() const
Definition: Actor.h:273
RoR::GameContext::GetTerrain
const TerrainPtr & GetTerrain()
Definition: GameContext.h:117