From b8a0ab32b4a27fc256d968a4a57da2c1d36cbc51 Mon Sep 17 00:00:00 2001 From: mbjornstk Date: Sun, 20 Feb 2011 05:11:26 +0000 Subject: [PATCH] Apply camera changes provided by Jesse Smith to have v0.6 camera option. Feel free to fix any C++ style issues, this saves you fighting with patch or can be undone quickly by reverting this single commit. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7739 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/config/user_config.hpp | 3 +++ src/graphics/camera.cpp | 39 ++++++++++++++++++++++++++++++++++++-- src/graphics/camera.hpp | 9 +++++++++ src/main.cpp | 6 ++++++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index 8900dd929..318713f7c 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -360,6 +360,9 @@ namespace UserConfigParams PARAM_DEFAULT( IntUserConfigParam(0, "reverse_look_threshold", "If the kart is driving backwards faster than this value,\n" "switch automatically to reverse camera (set to 0 to disable).") ); + PARAM_PREFIX IntUserConfigParam m_camera_style + PARAM_DEFAULT( IntUserConfigParam(1, "camera_style", "Camera Style") ); + PARAM_PREFIX StringUserConfigParam m_item_style PARAM_DEFAULT( StringUserConfigParam("items", "item_style", "Name of the .items file to use.") ); diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index f1b80be81..64c598c34 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -62,6 +62,13 @@ Camera::Camera(int camera_index, const Kart* kart) m_position_speed = 8.0f; m_target_speed = 10.0f; m_rotation_range = 0.4f; + // TODO: Make this per user too if the one above goes that way. + switch(UserConfigParams::m_camera_style) + { + case 1: m_camera_style = CS_CLASSIC; break; + case 0: + default: m_camera_style = CS_MODERN; break; + } reset(); } // Camera @@ -339,8 +346,36 @@ void Camera::update(float dt) { case CM_NORMAL: { - computeNormalCameraPosition(&wanted_position, &wanted_target); - smoothMoveCamera(dt, wanted_position, wanted_target); + switch (m_camera_style) + { + // 0.7 flexible link + case CS_MODERN: + { + computeNormalCameraPosition(&wanted_position, &wanted_target); + smoothMoveCamera(dt, wanted_position, wanted_target); + break; + } + + // More like the 0.6 STK way + case CS_CLASSIC: + { + // wanted_target.setY(wanted_target.getY()+ 0.75f); + wanted_target.setY(wanted_target.getY()+ 0.30f); + float angle_around = m_kart->getHeading(); + float angle_up = m_kart->getKartProperties()->getCameraBackwardUpAngle() + - m_kart->getPitch() ; + angle_around += 3.14; // face forward + wanted_position.setX( sin(angle_around)); + wanted_position.setY( sin(angle_up) ); + wanted_position.setZ( cos(angle_around)); + wanted_position *= m_distance * 1.5f; + wanted_position += wanted_target; + smoothMoveCamera(dt, wanted_position, wanted_target); + m_camera->setPosition(wanted_position.toIrrVector()); + m_camera->setTarget(wanted_target.toIrrVector()); + break; + } + } break; } case CM_FALLING: diff --git a/src/graphics/camera.hpp b/src/graphics/camera.hpp index d4ade77f8..5890cb142 100644 --- a/src/graphics/camera.hpp +++ b/src/graphics/camera.hpp @@ -51,6 +51,11 @@ public: CM_FALLING }; + enum Style { + CS_MODERN, //!< Flexible link between kart and camera + CS_CLASSIC, //!< Fixed position style, like STK v0.6 + }; + private: /** The camera scene node. */ scene::ICameraSceneNode *m_camera; @@ -97,6 +102,10 @@ private: /** Velocity of the target of the camera, only used for end camera. */ core::vector3df m_target_velocity; + + /* Whether we should use the pre-0.7 camera style or the + * modern style. Should default to modern. */ + Style m_camera_style; /** A class that stores information about the different end cameras * which can be specified in the scene.xml file. */ diff --git a/src/main.cpp b/src/main.cpp index 20dc2fd27..54e2f935d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -247,6 +247,7 @@ void cmdLineHelp (char* invocation) " --gfx=n Play other graphical effects like impact stars dance,\n" " water animations or explosions (Enable: 1, Disable: 0).\n" " --weather=n Show weather effects like rain or snow (0 or 1 as --gfx).\n" + " --camera-style=n Flexible (0) or hard like v0.6 (1) kart-camera link.\n" // should not be used by unaware users:u // " --profile Enable automatic driven profile mode for 20 seconds.\n" // " --profile=n Enable automatic driven profile mode for n seconds.\n" @@ -489,6 +490,11 @@ int handleCmdLine(int argc, char **argv) { UserConfigParams::m_show_steering_animations = n; } + + else if ( sscanf(argv[i], "--camera-style=%d", &n) ) + { + UserConfigParams::m_camera_style = n; + } else if( (!strcmp(argv[i], "--kart") && i+1getKart(argv[i+1]);