Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cinecam improvements #3010

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions source/main/gfx/camera/CameraManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,19 +813,26 @@ bool CameraManager::CameraBehaviorStaticMouseMoved(const OIS::MouseEvent& _arg)
return false;
}

void CameraManager::CameraBehaviorOrbitUpdate()
void CameraManager::CameraBehaviorOrbitToggleAngle(events ev, Ogre::Degree angle)
{
if (RoR::App::GetInputEngine()->getEventBoolValueBounce(EV_CAMERA_LOOKBACK))
if (RoR::App::GetInputEngine()->getEventBoolValueBounce(ev))
{
if (m_cam_rot_x > Degree(0))
if (m_cam_rot_x != angle)
{
m_cam_rot_x = Degree(0);
m_cam_rot_x = angle;
}
else
{
m_cam_rot_x = Degree(180);
m_cam_rot_x = Degree(0);
}
}
}

void CameraManager::CameraBehaviorOrbitUpdate()
{
this->CameraBehaviorOrbitToggleAngle(EV_CAMERA_LOOK_BACK, Degree(180));
this->CameraBehaviorOrbitToggleAngle(EV_CAMERA_LOOK_LEFT, Degree(270));
this->CameraBehaviorOrbitToggleAngle(EV_CAMERA_LOOK_RIGHT, Degree(90));

if (App::io_invert_orbitcam->getBool() && this->GetCurrentBehavior() != CameraManager::CAMERA_BEHAVIOR_VEHICLE_CINECAM)
{
Expand Down Expand Up @@ -940,23 +947,34 @@ void CameraManager::CameraBehaviorOrbitUpdate()

bool CameraManager::CameraBehaviorOrbitMouseMoved(const OIS::MouseEvent& _arg)
{
const OIS::MouseState ms = _arg.state;
const Ogre::Vector2 ROT_SPEED(550.f, 330.f);

if (ms.buttonDown(OIS::MB_Right))
if (_arg.state.buttonDown(OIS::MB_Right))
{
App::GetGuiManager()->SetMouseCursorVisibility(GUIManager::MouseCursorVisibility::HIDDEN);
// Recalculate mouse motion relative to screen size
const Ogre::Vector2 mouse_nrel(
static_cast<float>(_arg.state.X.rel) / static_cast<float>(_arg.state.width),
static_cast<float>(_arg.state.Y.rel) / static_cast<float>(_arg.state.height));

// Calculate camera rotation
m_cam_rot_x += Degree(mouse_nrel.x * ROT_SPEED.x);
m_cam_rot_y += Degree(-mouse_nrel.y * ROT_SPEED.y);

// Calculate camera zoom
float scale = RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU) ? 0.002f : 0.02f;
m_cam_dist += -_arg.state.Z.rel * scale;

if (App::io_invert_orbitcam->getBool() && this->GetCurrentBehavior() != CameraManager::CAMERA_BEHAVIOR_VEHICLE_CINECAM)
{
m_cam_rot_x += Degree(ms.X.rel * -0.13f);
m_cam_rot_y += Degree(-ms.Y.rel * -0.13f);
m_cam_rot_x += Degree(_arg.state.X.rel * -0.13f);
m_cam_rot_y += Degree(-_arg.state.Y.rel * -0.13f);
}
else
{
m_cam_rot_x += Degree(ms.X.rel * 0.13f);
m_cam_rot_y += Degree(-ms.Y.rel * 0.13f);
m_cam_rot_x += Degree(_arg.state.X.rel * 0.13f);
m_cam_rot_y += Degree(-_arg.state.Y.rel * 0.13f);
}
m_cam_dist += -ms.Z.rel * scale;
return true;
}

Expand Down
9 changes: 5 additions & 4 deletions source/main/gfx/camera/CameraManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#pragma once

#include "Application.h"
#include "InputEngine.h"

#include <OIS.h>
#include <Ogre.h>
Expand Down Expand Up @@ -66,10 +67,6 @@ class CameraManager
void NotifyContextChange();
void NotifyVehicleChanged(ActorPtr new_vehicle);

void CameraBehaviorOrbitReset();
bool CameraBehaviorOrbitMouseMoved(const OIS::MouseEvent& _arg);
void CameraBehaviorOrbitUpdate();

bool mouseMoved(const OIS::MouseEvent& _arg);
bool mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id);

Expand Down Expand Up @@ -102,6 +99,10 @@ class CameraManager
void CameraBehaviorVehicleSplineUpdateSpline();
void CameraBehaviorVehicleSplineUpdateSplineDisplay();
void CreateCameraNode();
void CameraBehaviorOrbitReset();
bool CameraBehaviorOrbitMouseMoved(const OIS::MouseEvent& _arg);
void CameraBehaviorOrbitUpdate();
void CameraBehaviorOrbitToggleAngle(RoR::events ev, Ogre::Degree angle);

Ogre::Camera* m_camera;
Ogre::SceneNode* m_camera_node;
Expand Down
4 changes: 3 additions & 1 deletion source/main/scripting/bindings/InputEngineAngelscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ void registerEventTypeEnum(asIScriptEngine* engine)
result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_DOWN", EV_CAMERA_DOWN ); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_FREE_MODE", EV_CAMERA_FREE_MODE ); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_FREE_MODE_FIX", EV_CAMERA_FREE_MODE_FIX ); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_LOOKBACK", EV_CAMERA_LOOKBACK ); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_LOOK_BACK", EV_CAMERA_LOOK_BACK ); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_LOOK_LEFT", EV_CAMERA_LOOK_LEFT ); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_LOOK_RIGHT", EV_CAMERA_LOOK_RIGHT ); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_RESET", EV_CAMERA_RESET ); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_ROTATE_DOWN", EV_CAMERA_ROTATE_DOWN ); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_ROTATE_LEFT", EV_CAMERA_ROTATE_LEFT ); ROR_ASSERT(result >= 0);
Expand Down
4 changes: 3 additions & 1 deletion source/main/utils/InputEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ InputEvent eventInfo[] = {

// Camera
{"CAMERA_CHANGE", EV_CAMERA_CHANGE, "Keyboard EXPL+C", _LC("InputEvent", "change camera mode")},
{"CAMERA_LOOKBACK", EV_CAMERA_LOOKBACK, "Keyboard NUMPAD1", _LC("InputEvent", "look back (toggles between normal and lookback)")},
{"CAMERA_LOOK_BACK", EV_CAMERA_LOOK_BACK, "Keyboard NUMPAD1", _LC("InputEvent", "look back (toggles between normal and lookback)")},
{"CAMERA_LOOK_LEFT", EV_CAMERA_LOOK_LEFT, "", _LC("InputEvent", "look left (toggles between normal and lookleft)")},
{"CAMERA_LOOK_RIGHT", EV_CAMERA_LOOK_RIGHT, "", _LC("InputEvent", "look right (toggles between normal and lookright)")},
{"CAMERA_RESET", EV_CAMERA_RESET, "Keyboard NUMPAD5", _LC("InputEvent", "reset the camera position")},
{"CAMERA_ROTATE_DOWN", EV_CAMERA_ROTATE_DOWN, "Keyboard NUMPAD2", _LC("InputEvent", "rotate camera down")},
{"CAMERA_ROTATE_LEFT", EV_CAMERA_ROTATE_LEFT, "Keyboard NUMPAD4", _LC("InputEvent", "rotate camera left")},
Expand Down
6 changes: 4 additions & 2 deletions source/main/utils/InputEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ enum events
EV_CAMERA_DOWN,
EV_CAMERA_FREE_MODE,
EV_CAMERA_FREE_MODE_FIX,
EV_CAMERA_LOOKBACK, //!< look back (toggles between normal and lookback)
EV_CAMERA_RESET, //!< reset the camera position
EV_CAMERA_LOOK_BACK, //!< look back (toggles between normal and lookback)
EV_CAMERA_LOOK_LEFT, //!< look left (toggles between normal and lookleft)
EV_CAMERA_LOOK_RIGHT, //!< look right (toggles between normal and lookright)
EV_CAMERA_RESET, //!< reset the camera position/rotation
EV_CAMERA_ROTATE_DOWN, //!< rotate camera down
EV_CAMERA_ROTATE_LEFT, //!< rotate camera left
EV_CAMERA_ROTATE_RIGHT, //!< rotate camera right
Expand Down