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 
534 bool CameraManager::mouseMoved(const OIS::MouseEvent& _arg)
535 {
536 
537  if (App::sim_state->getEnum<SimState>() == SimState::PAUSED)
538  {
539  return true; // Do nothing when paused
540  }
541 
542  switch(m_current_behavior)
543  {
545  if (!App::GetGameContext()->GetPlayerCharacter())
546  return false;
548  {
549  const OIS::MouseState ms = _arg.state;
550  Radian angle = App::GetGameContext()->GetPlayerCharacter()->getRotation();
551 
552  m_cam_rot_y += Degree(ms.Y.rel * 0.13f);
553  angle += Degree(ms.X.rel * 0.13f);
554 
555  m_cam_rot_y = Radian(std::min(+Math::HALF_PI * 0.65f, m_cam_rot_y.valueRadians()));
556  m_cam_rot_y = Radian(std::max(m_cam_rot_y.valueRadians(), -Math::HALF_PI * 0.9f));
557 
559 
561 
562  return true;
563  }
564 
566  }
571  case CAMERA_BEHAVIOR_FREE: {
572  const OIS::MouseState ms = _arg.state;
573 
574  App::GetCameraManager()->GetCameraNode()->yaw(Degree(-ms.X.rel * 0.13f), Ogre::Node::TS_WORLD);
575  App::GetCameraManager()->GetCameraNode()->pitch(Degree(-ms.Y.rel * 0.13f));
576 
578 
579  return true;
580  }
581 
582  case CAMERA_BEHAVIOR_FIXED: return false;
583  case CAMERA_BEHAVIOR_ISOMETRIC: return false;
584  case CAMERA_BEHAVIOR_INVALID: return false;
585  default: return false;
586  }
587 }
588 
589 bool CameraManager::mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id)
590 {
591  const OIS::MouseState ms = _arg.state;
592 
593  if (ms.buttonDown(OIS::MB_Right) && _id == OIS::MB_Middle)
594  {
596  }
597 
598  switch(m_current_behavior)
599  {
600  case CAMERA_BEHAVIOR_CHARACTER: return false;
601  case CAMERA_BEHAVIOR_STATIC: return false;
602  case CAMERA_BEHAVIOR_VEHICLE: return this->CameraBehaviorVehicleMousePressed(_arg, _id);
605  case CAMERA_BEHAVIOR_FREE: return false;
606  case CAMERA_BEHAVIOR_FIXED: return false;
607  case CAMERA_BEHAVIOR_ISOMETRIC: return false;
608  case CAMERA_BEHAVIOR_INVALID: return false;
609  default: return false;
610  }
611 }
612 
614 {
615  switch(m_current_behavior)
616  {
621  m_cam_look_at_last = Vector3::ZERO;
622  return;
623 
624  default:
625  return;
626  }
627 }
628 
630 {
631  // Getting out of vehicle
632  if (new_vehicle == nullptr)
633  {
634  m_cct_player_actor = nullptr;
637  {
639  }
640  return;
641  }
642 
643  // Getting in vehicle
646  {
647  // Change camera
648  switch (new_vehicle->GetCameraContext()->behavior)
649  {
652  break;
653 
656  break;
657 
660  break;
661 
662  default:
664  }
665  }
666 }
667 
668 void CameraManager::ToggleCameraBehavior(CameraBehaviors new_behavior) // Only accepts FREE and FREEFIX modes
669 {
670  ROR_ASSERT(new_behavior == CAMERA_BEHAVIOR_FIXED || new_behavior == CAMERA_BEHAVIOR_FREE);
671 
672  if (m_current_behavior == new_behavior) // Leaving toggled mode?
673  {
675  {
678  }
680  {
683  }
684  }
685  else // Entering toggled mode
686  {
688  {
690  }
691  else
692  {
694  }
695  this->switchBehavior(new_behavior);
696  }
697 }
698 
700 {
701  Vector3 velocity = Vector3::ZERO;
702  Radian angle = Degree(90);
703  float radius = 3.0f;
704  float speed = 0.0f;
705 
706  if (m_cct_player_actor)
707  {
709  {
711  }
714  if (App::GetGameContext()->GetPlayerActor()->ar_driveable != AIRPLANE)
715  {
717  }
718  angle = (m_staticcam_look_at - m_staticcam_position).angleBetween(velocity);
719  speed = velocity.normalise();
720 
722  {
724  }
725  }
726  else
727  {
729  }
730 
732 
733  if (m_staticcam_force_update || m_staticcam_update_timer.getMilliseconds() > 1000)
734  {
735  Vector3 lookAt = m_staticcam_look_at;
736  Vector3 lookAtPrediction = lookAt + velocity * speed;
737  float distance = m_staticcam_position.distance(lookAt);
738  float interval = std::max(radius, speed);
739  float cmradius = std::max(radius, App::gfx_camera_height->getFloat() / 7.0f);
740 
742  (distance > cmradius * 8.0f && angle < Degree(30)) ||
743  (distance < cmradius * 2.0f && angle > Degree(150)) ||
744  distance > cmradius * std::max(25.0f, speed * 1.15f) ||
745  intersectsTerrain(m_staticcam_position, lookAt, lookAtPrediction, interval))
746  {
747  const auto water = App::GetGameContext()->GetTerrain()->getWater();
748  float water_height = (water && !water->IsUnderWater(lookAt)) ? water->GetStaticWaterHeight() : 0.0f;
749  float desired_offset = std::max(std::sqrt(radius) * 2.89f, App::gfx_camera_height->getFloat());
750 
751  std::vector<std::pair<float, Vector3>> viable_positions;
752  for (int i = 0; i < 10; i++)
753  {
754  Vector3 pos = lookAt;
755  if (speed < 2.5f)
756  {
757  float angle = Math::TWO_PI * frand();
758  pos += Vector3(cos(angle), 0, sin(angle)) * cmradius * 2.5f;
759  }
760  else
761  {
762  float dist = std::max(cmradius * 2.5f, std::sqrt(cmradius) * speed);
763  float mrnd = Math::Clamp(0.6f * cmradius / dist, 0.0f, 0.3f);
764  float arnd = mrnd + frand() * (1.0f - mrnd);
765  float rnd = frand() > 0.5f ? arnd : -arnd;
766  pos += (velocity + velocity.crossProduct(Vector3::UNIT_Y) * rnd) * dist;
767  }
768  pos.y = std::max(pos.y, water_height);
769  pos.y = std::max(pos.y, App::GetGameContext()->GetTerrain()->GetHeightAt(pos.x, pos.z));
770  pos.y += desired_offset * (i < 7 ? 1.0f : frand());
771  if (!intersectsTerrain(pos, lookAt, lookAtPrediction, interval))
772  {
773  float hdiff = std::abs(pos.y - lookAt.y - desired_offset);
774  viable_positions.push_back({hdiff, pos});
775  if (hdiff < 1.0f || viable_positions.size() > 2)
776  break;
777  }
778  }
779  if (!viable_positions.empty())
780  {
781  std::sort(viable_positions.begin(), viable_positions.end());
782  m_staticcam_update_timer.reset();
783  m_staticcam_position = viable_positions.front().second;
784  m_staticcam_force_update = false;
785  }
786  }
787  }
788 
789  static float fovExp = m_staticcam_fov_exponent;
790  fovExp = (1.0f / (m_cam_ratio + 1.0f)) * m_staticcam_fov_exponent + (m_cam_ratio / (m_cam_ratio + 1.0f)) * fovExp;
791 
792  float camDist = m_staticcam_position.distance(m_staticcam_look_at);
793  float fov = atan2(20.0f, std::pow(camDist, fovExp));
794 
795  this->GetCameraNode()->setPosition(m_staticcam_position);
796  App::GetCameraManager()->GetCameraNode()->lookAt(m_staticcam_look_at, Ogre::Node::TS_WORLD);
797  App::GetCameraManager()->GetCamera()->setFOVy(Radian(fov));
798 }
799 
800 bool CameraManager::CameraBehaviorStaticMouseMoved(const OIS::MouseEvent& _arg)
801 {
802  const OIS::MouseState ms = _arg.state;
803 
804  if (ms.buttonDown(OIS::MB_Right))
805  {
806  float scale = RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU) ? 0.00002f : 0.0002f;
807  m_staticcam_fov_exponent += ms.Z.rel * scale;
808  m_staticcam_fov_exponent = Math::Clamp(m_staticcam_fov_exponent, 0.8f, 1.50f);
810  return true;
811  }
812 
813  return false;
814 }
815 
817 {
818  if (RoR::App::GetInputEngine()->getEventBoolValueBounce(EV_CAMERA_LOOKBACK))
819  {
820  if (m_cam_rot_x > Degree(0))
821  {
822  m_cam_rot_x = Degree(0);
823  }
824  else
825  {
826  m_cam_rot_x = Degree(180);
827  }
828  }
829 
831  {
834  }
835  else
836  {
839  }
840  m_cam_rot_y = std::max((Radian)Degree(-80), m_cam_rot_y);
841  m_cam_rot_y = std::min(m_cam_rot_y, (Radian)Degree(88));
842 
843  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CAMERA_ZOOM_IN) && m_cam_dist > 1)
844  {
846  }
847  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CAMERA_ZOOM_IN_FAST) && m_cam_dist > 1)
848  {
850  }
851  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CAMERA_ZOOM_OUT))
852  {
854  }
855  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CAMERA_ZOOM_OUT_FAST))
856  {
858  }
859 
860  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CAMERA_RESET))
861  {
863  }
864 
865  if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_RSHIFT) && RoR::App::GetInputEngine()->isKeyDownValueBounce(OIS::KC_SPACE))
866  {
869  {
870  RoR::App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE, _L("Limited camera movement enabled"), "camera_go.png");
871  }
872  else
873  {
874  RoR::App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE, _L("Limited camera movement disabled"), "camera_go.png");
875  }
876  }
877 
878  if (m_cam_limit_movement && m_cam_dist_min > 0.0f)
879  {
880  m_cam_dist = std::max(m_cam_dist_min, m_cam_dist);
881  }
882  if (m_cam_limit_movement && m_cam_dist_max > 0.0f)
883  {
884  m_cam_dist = std::min(m_cam_dist, m_cam_dist_max);
885  }
886 
887  m_cam_dist = std::max(0.0f, m_cam_dist);
888 
889  Vector3 desiredPosition = m_cam_look_at + m_cam_dist * 0.5f * Vector3(
890  sin(m_cam_target_direction.valueRadians() + m_cam_rot_x.valueRadians()) * cos(m_cam_target_pitch.valueRadians() + m_cam_rot_y.valueRadians())
891  , sin(m_cam_target_pitch.valueRadians() + m_cam_rot_y.valueRadians())
892  , cos(m_cam_target_direction.valueRadians() + m_cam_rot_x.valueRadians()) * cos(m_cam_target_pitch.valueRadians() + m_cam_rot_y.valueRadians())
893  );
894 
896  {
897  float h = App::GetGameContext()->GetTerrain()->GetHeightAt(desiredPosition.x, desiredPosition.z) + 1.0f;
898 
899  desiredPosition.y = std::max(h, desiredPosition.y);
900  }
901 
902  if (m_cam_look_at_last == Vector3::ZERO)
903  {
905  }
906  if (m_cam_look_at_smooth == Vector3::ZERO)
907  {
909  }
910  if (m_cam_look_at_smooth_last == Vector3::ZERO)
911  {
913  }
914 
915  Vector3 camDisplacement = m_cam_look_at - m_cam_look_at_last;
916  Vector3 precedingLookAt = m_cam_look_at_smooth_last + camDisplacement;
917  Vector3 precedingPosition = this->GetCameraNode()->getPosition() + camDisplacement;
918 
919  Vector3 camPosition = (1.0f / (m_cam_ratio + 1.0f)) * desiredPosition + (m_cam_ratio / (m_cam_ratio + 1.0f)) * precedingPosition;
920 
922  {
923  this->GetCameraNode()->setPosition(App::GetGameContext()->GetTerrain()->GetCollisions()->forcecampos);
925  }
926  else
927  {
928  if (m_cct_player_actor && m_cct_player_actor->ar_state == ActorState::LOCAL_REPLAY && camDisplacement != Vector3::ZERO)
929  this->GetCameraNode()->setPosition(desiredPosition);
930  else
931  this->GetCameraNode()->setPosition(camPosition);
932  }
933 
934  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;
935 
938  App::GetCameraManager()->GetCameraNode()->lookAt(m_cam_look_at_smooth, Ogre::Node::TS_WORLD);
939 }
940 
941 bool CameraManager::CameraBehaviorOrbitMouseMoved(const OIS::MouseEvent& _arg)
942 {
943  const OIS::MouseState ms = _arg.state;
944 
945  if (ms.buttonDown(OIS::MB_Right))
946  {
948  float scale = RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU) ? 0.002f : 0.02f;
950  {
951  m_cam_rot_x += Degree(ms.X.rel * -0.13f);
952  m_cam_rot_y += Degree(-ms.Y.rel * -0.13f);
953  }
954  else
955  {
956  m_cam_rot_x += Degree(ms.X.rel * 0.13f);
957  m_cam_rot_y += Degree(-ms.Y.rel * 0.13f);
958  }
959  m_cam_dist += -ms.Z.rel * scale;
960  return true;
961  }
962 
963  return false;
964 }
965 
967 {
968  m_cam_rot_x = 0.0f;
969  m_cam_rot_y = 0.3f;
970  m_cam_look_at_last = Vector3::ZERO;
971  m_cam_look_at_smooth = Vector3::ZERO;
972  m_cam_look_at_smooth_last = Vector3::ZERO;
973  App::GetCameraManager()->GetCamera()->setFOVy(Degree(App::gfx_fov_external->getInt()));
974 }
975 
977 {
978  Degree mRotX(0.0f);
979  Degree mRotY(0.0f);
980  Degree cct_rot_scale(m_cct_rot_scale * 5.0f * m_cct_dt);
981  Vector3 mTrans(Vector3::ZERO);
982  Real cct_trans_scale(m_cct_trans_scale * 5.0f * m_cct_dt);
983 
985  {
986  cct_rot_scale *= 3.0f;
987  cct_trans_scale *= 5.0f;
988  }
989  if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LCONTROL))
990  {
991  cct_rot_scale *= 6.0f;
992  cct_trans_scale *= 10.0f;
993  }
994  if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU))
995  {
996  cct_rot_scale *= 0.2f;
997  cct_trans_scale *= 0.2f;
998  }
999 
1000  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_SIDESTEP_LEFT))
1001  {
1002  mTrans.x -= cct_trans_scale;
1003  }
1004  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_SIDESTEP_RIGHT))
1005  {
1006  mTrans.x += cct_trans_scale;
1007  }
1008  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_FORWARD))
1009  {
1010  mTrans.z -= cct_trans_scale;
1011  }
1012  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_BACKWARDS))
1013  {
1014  mTrans.z += cct_trans_scale;
1015  }
1016  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CAMERA_UP))
1017  {
1018  mTrans.y += cct_trans_scale;
1019  }
1020  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CAMERA_DOWN))
1021  {
1022  mTrans.y -= cct_trans_scale;
1023  }
1024 
1025  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_RIGHT))
1026  {
1027  mRotX -= cct_rot_scale;
1028  }
1029  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_LEFT))
1030  {
1031  mRotX += cct_rot_scale;
1032  }
1033  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_ROT_UP))
1034  {
1035  mRotY += cct_rot_scale;
1036  }
1037  if (RoR::App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_ROT_DOWN))
1038  {
1039  mRotY -= cct_rot_scale;
1040  }
1041 
1042  App::GetCameraManager()->GetCameraNode()->yaw(mRotX, Ogre::Node::TS_WORLD);
1043  App::GetCameraManager()->GetCameraNode()->pitch(mRotY);
1044 
1045  Vector3 camPosition = this->GetCameraNode()->getPosition() + this->GetCameraNode()->getOrientation() * mTrans.normalisedCopy() * cct_trans_scale;
1046 
1047  this->GetCameraNode()->setPosition(camPosition);
1048 }
1049 
1051 {
1052  if (App::gfx_fixed_cam_tracking->getBool())
1053  {
1055  App::GetCameraManager()->GetCameraNode()->lookAt(look_at, Ogre::Node::TS_WORLD);
1056  }
1057 }
1058 
1060 {
1061  Vector3 dir = m_cct_player_actor->getDirection();
1062 
1063  m_cam_target_direction = -atan2(dir.dotProduct(Vector3::UNIT_X), dir.dotProduct(-Vector3::UNIT_Z));
1064  m_cam_target_pitch = 0.0f;
1065 
1066  if ( RoR::App::gfx_extcam_mode->getEnum<GfxExtCamMode>() == RoR::GfxExtCamMode::PITCHING)
1067  {
1068  m_cam_target_pitch = -asin(dir.dotProduct(Vector3::UNIT_Y));
1069  }
1070 
1071  m_cam_ratio = 1.0f / (m_cct_dt * 4.0f);
1072 
1073  m_cam_dist_min = std::min(m_cct_player_actor->getMinimalCameraRadius() * 2.0f, 33.0f);
1074 
1076 
1078 }
1079 
1081 {
1083  m_cam_rot_y = 0.35f;
1084  m_cam_dist_min = std::min(m_cct_player_actor->getMinimalCameraRadius() * 2.0f, 33.0f);
1085  m_cam_dist = m_cam_dist_min * 1.5f + 2.0f;
1086 }
1087 
1088 bool CameraManager::CameraBehaviorVehicleMousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id)
1089 {
1090  const OIS::MouseState ms = _arg.state;
1091 
1092  if ( ms.buttonDown(OIS::MB_Middle) && RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) )
1093  {
1095  {
1096  // Calculate new camera distance
1098  m_cam_dist = 2.0f * this->GetCameraNode()->getPosition().distance(lookAt);
1099 
1100  // Calculate new camera pitch
1101  Vector3 camDir = (this->GetCameraNode()->getPosition() - lookAt).normalisedCopy();
1102  m_cam_rot_y = asin(camDir.y);
1103 
1104  // Calculate new camera yaw
1105  Vector3 dir = -m_cct_player_actor->getDirection();
1106  Quaternion rotX = dir.getRotationTo(camDir, Vector3::UNIT_Y);
1107  m_cam_rot_x = rotX.getYaw();
1108 
1109  // Corner case handling
1110  Radian angle = dir.angleBetween(camDir);
1111  if ( angle > Radian(Math::HALF_PI) )
1112  {
1113  if ( std::abs(Radian(m_cam_rot_x).valueRadians()) < Math::HALF_PI )
1114  {
1115  if ( m_cam_rot_x < Radian(0.0f) )
1116  m_cam_rot_x -= Radian(Math::HALF_PI);
1117  else
1118  m_cam_rot_x += Radian(Math::HALF_PI);
1119  }
1120  }
1121  }
1122  }
1123 
1124  return false;
1125 }
1126 
1128 {
1130  {
1131  this->switchToNextBehavior();
1132  return;
1133  }
1134 
1135  Vector3 dir = m_cct_player_actor->getDirection();
1136 
1137  m_cam_target_pitch = 0.0f;
1138 
1139  if (App::gfx_extcam_mode->getEnum<GfxExtCamMode>() == GfxExtCamMode::PITCHING)
1140  {
1141  m_cam_target_pitch = -asin(dir.dotProduct(Vector3::UNIT_Y));
1142  }
1143 
1145  {
1147  }
1150 
1152 
1153  if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) && RoR::App::GetInputEngine()->isKeyDownValueBounce(OIS::KC_SPACE))
1154  {
1157  {
1158  RoR::App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE, _L("Auto tracking enabled"), "camera_go.png");
1159  }
1160  else
1161  {
1162  RoR::App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE, _L("Auto tracking disabled"), "camera_go.png");
1163  }
1164  }
1165 
1167  {
1168  Vector3 centerDir = m_cct_player_actor->getPosition() - m_cam_look_at;
1169  if (centerDir.length() > 1.0f)
1170  {
1171  centerDir.normalise();
1172  Radian oldTargetDirection = m_cam_target_direction;
1173  m_cam_target_direction = -atan2(centerDir.dotProduct(Vector3::UNIT_X), centerDir.dotProduct(-Vector3::UNIT_Z));
1174  if (m_cam_target_direction.valueRadians() * oldTargetDirection.valueRadians() < 0.0f && centerDir.length() < m_cam_dist_min)
1175  {
1177  }
1178  }
1179  }
1180 
1182 }
1183 
1185 {
1186  const OIS::MouseState ms = _arg.state;
1187 
1188  m_cam_ratio = 1.0f / (m_cct_dt * 4.0f);
1189 
1190  if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LCONTROL) && ms.buttonDown(OIS::MB_Right))
1191  {
1192  Real splinePosDiff = ms.X.rel * std::max(0.00005f, m_splinecam_spline_len * 0.0000001f);
1193 
1195  {
1196  splinePosDiff *= 3.0f;
1197  }
1198 
1199  if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU))
1200  {
1201  splinePosDiff *= 0.1f;
1202  }
1203 
1204  m_splinecam_spline_pos += splinePosDiff;
1205 
1206  if (ms.X.rel > 0 && m_splinecam_spline_pos > 0.99f)
1207  {
1209  {
1210  m_splinecam_spline_pos -= 1.0f;
1211  }
1212  else
1213  {
1214  // u - turn
1215  }
1216  }
1217  else if (ms.X.rel < 0 && m_splinecam_spline_pos < 0.01f)
1218  {
1220  {
1221  m_splinecam_spline_pos += 1.0f;
1222  }
1223  else
1224  {
1225  // u - turn
1226  }
1227  }
1228 
1231 
1232  return true;
1233  }
1234  else
1235  {
1237  }
1238 }
1239 
1241 {
1243 
1244  m_cam_dist = std::min(m_cct_player_actor->getMinimalCameraRadius() * 2.0f, 33.0f);
1245 
1246  m_splinecam_spline_pos = 0.5f;
1247 }
1248 
1250 {
1251  m_splinecam_spline_closed = false;
1252  m_splinecam_spline_len = 1.0f;
1253 
1254  m_splinecam_spline->clear();
1255  m_splinecam_spline_nodes.clear();
1256 
1257  for (int i = 0; i < m_cct_player_actor->ar_num_camera_rails; i++)
1258  {
1260  }
1261 
1262  auto linkedBeams = m_cct_player_actor->ar_linked_actors;
1263 
1264  m_splinecam_num_linked_beams = static_cast<int>(linkedBeams.size());
1265 
1267  {
1268  for (ActorPtr& actor : linkedBeams)
1269  {
1270  if (actor->ar_num_camera_rails <= 0)
1271  continue;
1272 
1273  Vector3 curSplineFront = m_splinecam_spline_nodes.front()->AbsPosition;
1274  Vector3 curSplineBack = m_splinecam_spline_nodes.back()->AbsPosition;
1275 
1276  Vector3 linkedSplineFront = actor->ar_nodes[actor->ar_camera_rail[0]].AbsPosition;
1277  Vector3 linkedSplineBack = actor->ar_nodes[actor->ar_camera_rail[actor->ar_num_camera_rails - 1]].AbsPosition;
1278 
1279  if (curSplineBack.distance(linkedSplineFront) < 5.0f)
1280  {
1281  for (int i = 1; i < actor->ar_num_camera_rails; i++)
1282  {
1283  m_splinecam_spline_nodes.push_back(&actor->ar_nodes[actor->ar_camera_rail[i]]);
1284  }
1285  }
1286  else if (curSplineFront.distance(linkedSplineFront) < 5.0f)
1287  {
1288  for (int i = 1; i < actor->ar_num_camera_rails; i++)
1289  {
1290  m_splinecam_spline_nodes.push_front(&actor->ar_nodes[actor->ar_camera_rail[i]]);
1291  }
1292  }
1293  else if (curSplineBack.distance(linkedSplineBack) < 5.0f)
1294  {
1295  for (int i = actor->ar_num_camera_rails - 2; i >= 0; i--)
1296  {
1297  m_splinecam_spline_nodes.push_back(&actor->ar_nodes[actor->ar_camera_rail[i]]);
1298  }
1299  }
1300  else if (curSplineFront.distance(linkedSplineBack) < 5.0f)
1301  {
1302  for (int i = actor->ar_num_camera_rails - 2; i >= 0; i--)
1303  {
1304  m_splinecam_spline_nodes.push_front(&actor->ar_nodes[actor->ar_camera_rail[i]]);
1305  }
1306  }
1307  }
1308  }
1309 
1310  for (unsigned int i = 0; i < m_splinecam_spline_nodes.size(); i++)
1311  {
1312  m_splinecam_spline->addPoint(m_splinecam_spline_nodes[i]->AbsPosition);
1313  }
1314 
1315  Vector3 firstPoint = m_splinecam_spline->getPoint(0);
1316  Vector3 lastPoint = m_splinecam_spline->getPoint(m_splinecam_spline->getNumPoints() - 1);
1317 
1318  if (firstPoint.distance(lastPoint) < 1.0f)
1319  {
1321  }
1322 
1323  for (int i = 1; i < m_splinecam_spline->getNumPoints(); i++)
1324  {
1325  m_splinecam_spline_len += m_splinecam_spline->getPoint(i - 1).distance(m_splinecam_spline->getPoint(i));
1326  }
1327 
1328  m_splinecam_spline_len /= 2.0f;
1329 
1330  if (!m_splinecam_mo && RoR::App::diag_camera->getBool())
1331  {
1332  m_splinecam_mo = App::GetGfxScene()->GetSceneManager()->createManualObject();
1333  SceneNode* splineNode = App::GetGfxScene()->GetSceneManager()->getRootSceneNode()->createChildSceneNode();
1334 
1335  m_splinecam_mo->begin("tracks/transred", Ogre::RenderOperation::OT_LINE_STRIP);
1336  for (int i = 0; i < SPLINECAM_DRAW_RESOLUTION; i++)
1337  {
1338  m_splinecam_mo->position(0, 0, 0);
1339  }
1340  m_splinecam_mo->end();
1341 
1342  splineNode->attachObject(m_splinecam_mo);
1343  }
1344 }
1345 
1347 {
1348  for (int i = 0; i < m_splinecam_spline->getNumPoints(); i++)
1349  {
1350  m_splinecam_spline->updatePoint(i, m_splinecam_spline_nodes[i]->AbsPosition);
1351  }
1352 }
1353 
1355 {
1356  if (!m_splinecam_mo)
1357  return;
1358 
1359  m_splinecam_mo->beginUpdate(0);
1360  for (int i = 0; i < SPLINECAM_DRAW_RESOLUTION; i++)
1361  {
1362  Real parametricDist = i / (float)SPLINECAM_DRAW_RESOLUTION;
1363  Vector3 position = m_splinecam_spline->interpolate(parametricDist);
1364  m_splinecam_mo->position(position);
1365  }
1366  m_splinecam_mo->end();
1367 }
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:1059
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:248
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:386
RoR::node_t::Velocity
Ogre::Vector3 Velocity
Definition: SimData.h:294
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:293
RoR::App::GetGuiManager
GUIManager * GetGuiManager()
Definition: Application.cpp:269
RoR::CameraManager::UpdateCameraBehaviorFree
void UpdateCameraBehaviorFree()
Definition: CameraManager.cpp:976
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:441
RoR::GfxExtCamMode::PITCHING
@ PITCHING
RoR::CameraManager::m_cam_look_at_last
Ogre::Vector3 m_cam_look_at_last
Definition: CameraManager.h:129
RoR::CameraManager::mouseMoved
bool mouseMoved(const OIS::MouseEvent &_arg)
Definition: CameraManager.cpp:534
RoR::App::gfx_fixed_cam_tracking
CVar * gfx_fixed_cam_tracking
Definition: Application.cpp:243
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::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:874
RoR::CameraManager::NotifyVehicleChanged
void NotifyVehicleChanged(ActorPtr new_vehicle)
Definition: CameraManager.cpp:629
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:146
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:417
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::CameraManager::CameraBehaviorVehicleMousePressed
bool CameraBehaviorVehicleMousePressed(const OIS::MouseEvent &_arg, OIS::MouseButtonID _id)
Definition: CameraManager.cpp:1088
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:1050
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:719
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:915
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:1127
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:816
RoR::CameraManager::m_staticcam_fov_exponent
float m_staticcam_fov_exponent
Definition: CameraManager.h:134
RoR::CameraManager::NotifyContextChange
void NotifyContextChange()
Definition: CameraManager.cpp:613
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:4561
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:387
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::CameraManager::CameraBehaviorVehicleSplineMouseMoved
bool CameraBehaviorVehicleSplineMouseMoved(const OIS::MouseEvent &_arg)
Definition: CameraManager.cpp:1184
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::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:423
GfxScene.h
RoR::Actor::NotifyActorCameraChanged
void NotifyActorCameraChanged()
Logic: sound, display; Notify this vehicle that camera changed;.
Definition: Actor.cpp:3839
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::CameraManager::mousePressed
bool mousePressed(const OIS::MouseEvent &_arg, OIS::MouseButtonID _id)
Definition: CameraManager.cpp:589
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:93
RoR::CameraManager::CameraBehaviorStaticMouseMoved
bool CameraBehaviorStaticMouseMoved(const OIS::MouseEvent &_arg)
Definition: CameraManager.cpp:800
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::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:418
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:388
RoR::CameraManager::CameraBehaviorVehicleReset
void CameraBehaviorVehicleReset()
Definition: CameraManager.cpp:1080
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:276
RoR::Actor::ar_num_cinecams
int ar_num_cinecams
Sim attr;.
Definition: Actor.h:375
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:259
RoR::CameraManager::CameraBehaviorOrbitMouseMoved
bool CameraBehaviorOrbitMouseMoved(const OIS::MouseEvent &_arg)
Definition: CameraManager.cpp:941
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::Actor::ar_nodes
node_t * ar_nodes
Definition: Actor.h:273
Script2Game::KC_RSHIFT
enum Script2Game::inputEvents KC_RSHIFT
RoR::Actor::getMinimalCameraRadius
Ogre::Real getMinimalCameraRadius()
Definition: Actor.cpp:4556
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:372
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:1127
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:418
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:668
RoR::Actor::ar_num_camera_rails
int ar_num_camera_rails
Definition: Actor.h:338
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:1346
RoR::CameraManager::UpdateCameraBehaviorStatic
void UpdateCameraBehaviorStatic()
Definition: CameraManager.cpp:699
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:385
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:440
RoR::CameraManager::CameraBehaviorVehicleSplineCreateSpline
void CameraBehaviorVehicleSplineCreateSpline()
Definition: CameraManager.cpp:1249
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:1354
RoR::Actor::prepareInside
void prepareInside(bool inside)
Prepares vehicle for in-cabin camera use.
Definition: Actor.cpp:2950
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:1240
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:337
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::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:374
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:966
RoR::Actor::isBeingReset
bool isBeingReset() const
Definition: Actor.h:267
RoR::GameContext::GetTerrain
const TerrainPtr & GetTerrain()
Definition: GameContext.h:117