From a063d23b3701fa74db81a02e845ba34d11117a07 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Mon, 3 Mar 2014 18:57:10 -0500 Subject: [PATCH] Fix intro cutscene --- src/graphics/camera.cpp | 25 ++++++++++++++++++++----- src/graphics/camera.hpp | 4 +++- src/graphics/glwrap.cpp | 2 +- src/graphics/irr_driver.cpp | 17 +++-------------- src/modes/cutscene_world.cpp | 9 ++++++--- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 57e128ca3..610cd1d15 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -54,12 +54,22 @@ Camera::Camera(int camera_index, AbstractKart* kart) : m_kart(NULL) m_camera = irr_driver->addCameraSceneNode(); #ifdef DEBUG - m_camera->setName(core::stringc("Camera for ") + kart->getKartProperties()->getName()); + if (kart != NULL) + m_camera->setName(core::stringc("Camera for ") + kart->getKartProperties()->getName()); + else + m_camera->setName("Camera"); #endif setupCamera(); - m_distance = kart->getKartProperties()->getCameraDistance(); - setKart(kart); + if (kart != NULL) + { + m_distance = kart->getKartProperties()->getCameraDistance(); + setKart(kart); + } + else + { + m_distance = 1000.0f; + } m_ambient_light = World::getWorld()->getTrack()->getDefaultAmbientColor(); // TODO: Put these values into a config file @@ -264,7 +274,9 @@ void Camera::reset() { m_kart = m_original_kart; setMode(CM_NORMAL); - setInitialTransform(); + + if (m_kart != NULL) + setInitialTransform(); } // reset //----------------------------------------------------------------------------- @@ -273,6 +285,8 @@ void Camera::reset() */ void Camera::setInitialTransform() { + if (m_kart == NULL) return; + Vec3 start_offset(0, 25, -50); Vec3 xx = m_kart->getTrans()(start_offset); m_camera->setPosition( xx.toIrrVector()); @@ -431,6 +445,8 @@ void Camera::getCameraSettings(float *above_kart, float *cam_angle, */ void Camera::update(float dt) { + if (m_kart == NULL) return; // cameras not attached to kart must be positioned manually + float above_kart, cam_angle, side_way, distance; bool smoothing; @@ -472,7 +488,6 @@ void Camera::update(float dt) m_camera->setTarget(current_target); } - else { getCameraSettings(&above_kart, &cam_angle, &side_way, &distance, &smoothing); diff --git a/src/graphics/camera.hpp b/src/graphics/camera.hpp index 07ac34865..6b7e01fcf 100644 --- a/src/graphics/camera.hpp +++ b/src/graphics/camera.hpp @@ -86,7 +86,9 @@ private: float m_rotation_range; /** The kart that the camera follows. It can't be const, - * since in profile mode the camera might change its owner. */ + * since in profile mode the camera might change its owner. + * May be NULL (example: cutscene camera) + */ AbstractKart *m_kart; /** A pointer to the original kart the camera was pointing at when it diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 3ec8beaa3..bb94be63a 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -211,7 +211,7 @@ GLuint LoadShader(const char * file, unsigned type) { } GLint Result = GL_FALSE; int InfoLogLength; - printf("Compiling shader : %s\n", file); + Log::info("GLWrap", "Compiling shader : %s", file); char const * SourcePointer = Code.c_str(); int length = strlen(SourcePointer); glShaderSource(Id, 1, &SourcePointer, &length); diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 7b9b302ba..b31eb9a20 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -1803,18 +1803,7 @@ void IrrDriver::update(float dt) World *world = World::getWorld(); - // Handle cut scenes (which do not have any karts in it) - // ===================================================== - if (world && world->getNumKarts() == 0) - { - m_video_driver->beginScene(/*backBuffer clear*/true, /*zBuffer*/true, - world->getClearColor()); - m_scene_manager->drawAll(); - GUIEngine::render(dt); - m_video_driver->endScene(); - return; - } - else if (GUIEngine::getCurrentScreen() != NULL && + if (GUIEngine::getCurrentScreen() != NULL && GUIEngine::getCurrentScreen()->needs3D()) { //printf("Screen that needs 3D\n"); @@ -1827,10 +1816,10 @@ void IrrDriver::update(float dt) } else if (!world) { - m_video_driver->beginScene(/*backBuffer clear*/ true, /*zBuffer*/ true, + m_video_driver->beginScene(/*backBuffer clear*/ true, /*zBuffer*/ true, video::SColor(255,100,101,140)); - GUIEngine::render(dt); + GUIEngine::render(dt); m_video_driver->endScene(); return; diff --git a/src/modes/cutscene_world.cpp b/src/modes/cutscene_world.cpp index d3f50a01c..b95ed070b 100644 --- a/src/modes/cutscene_world.cpp +++ b/src/modes/cutscene_world.cpp @@ -22,6 +22,7 @@ #include "audio/music_manager.hpp" #include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" +#include "graphics/camera.hpp" #include "graphics/irr_driver.hpp" #include "io/file_manager.hpp" #include "karts/abstract_kart.hpp" @@ -73,9 +74,11 @@ void CutsceneWorld::init() //const btTransform &s = getTrack()->getStartTransform(0); //const Vec3 &v = s.getOrigin(); - m_camera = irr_driver->getSceneManager() - ->addCameraSceneNode(NULL, core::vector3df(0.0f, 0.0f, 0.0f), - core::vector3df(0.0f, 0.0f, 0.0f)); + Camera* stk_cam = Camera::createCamera(NULL); + m_camera = stk_cam->getCameraSceneNode(); + //m_camera = irr_driver->getSceneManager() + // ->addCameraSceneNode(NULL, core::vector3df(0.0f, 0.0f, 0.0f), + // core::vector3df(0.0f, 0.0f, 0.0f)); m_camera->setFOV(0.61f); m_camera->bindTargetAndRotation(true); // no "look-at"