/** Sets the mode of the camera. * \param mode Mode the camera should be switched to. */ void Camera::setMode(Mode mode) { // If we switch from reverse view, move the camera immediately to the // correct position. if(m_mode==CM_REVERSE && mode==CM_NORMAL) { Vec3 wanted_position, wanted_target; computeNormalCameraPosition(&wanted_position, &wanted_target); m_camera->setPosition(wanted_position.toIrrVector()); m_camera->setTarget(wanted_target.toIrrVector()); assert(!isnan(m_camera->getPosition().X)); assert(!isnan(m_camera->getPosition().Y)); assert(!isnan(m_camera->getPosition().Z)); } if(mode==CM_FINAL) { if(m_end_cameras.size()>0) m_camera->setPosition(m_end_cameras[0].m_position.toIrrVector()); m_next_end_camera = m_end_cameras.size()>1 ? 1 : 0; m_current_end_camera = 0; m_camera->setFOV(m_fov); handleEndCamera(0); } // mode==CM_FINAL m_mode = mode; } // setMode
/** Called once per time frame to move the camera to the right position. * \param dt Time step. */ 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; // The following settings give a debug camera which shows the track from // high above the kart straight down. if (UserConfigParams::m_camera_debug==1) { core::vector3df xyz = m_kart->getXYZ().toIrrVector(); m_camera->setTarget(xyz); xyz.Y = xyz.Y+55; xyz.Z -= 5.0f; m_camera->setPosition(xyz); // To view inside tunnels (FIXME 27>15 why??? makes no sense // - the kart should not be visible, but it works) m_camera->setNearValue(27.0); } else if (m_mode==CM_FINAL) { handleEndCamera(dt); } // If an explosion is happening, stop moving the camera, // but keep it target on the kart. else if (dynamic_cast<ExplosionAnimation*>(m_kart->getKartAnimation())) { getCameraSettings(&above_kart, &cam_angle, &side_way, &distance, &smoothing); // The camera target needs to be 'smooth moved', otherwise // there will be a noticable jump in the first frame // Aim at the usual same position of the kart (i.e. slightly // above the kart). core::vector3df wanted_target(m_kart->getXYZ().toIrrVector() +core::vector3df(0, above_kart, 0) ); core::vector3df current_target = m_camera->getTarget(); // Note: this code is replicated from smoothMoveCamera so that // the camera keeps on pointing to the same spot. current_target += ((wanted_target-current_target)*m_target_speed)*dt; m_camera->setTarget(current_target); } else { getCameraSettings(&above_kart, &cam_angle, &side_way, &distance, &smoothing); positionCamera(dt, above_kart, cam_angle, side_way, distance, smoothing); } if (UserConfigParams::m_graphical_effects && m_rain) { m_rain->setPosition( getCameraSceneNode()->getPosition() ); m_rain->update(dt); } // UserConfigParams::m_graphical_effects } // update
/** Sets the mode of the camera. * \param mode Mode the camera should be switched to. */ void Camera::setMode(Mode mode) { // If we switch from reverse view, move the camera immediately to the // correct position. if((m_mode==CM_REVERSE && mode==CM_NORMAL) || (m_mode==CM_FALLING && mode==CM_NORMAL)) { Vec3 start_offset(0, 1.6f, -3); Vec3 current_position = m_kart->getTrans()(start_offset); m_camera->setPosition( current_position.toIrrVector()); m_camera->setTarget(m_camera->getPosition()); } if(mode==CM_FINAL) { if(m_end_cameras.size()>0) m_camera->setPosition(m_end_cameras[0].m_position.toIrrVector()); m_next_end_camera = m_end_cameras.size()>1 ? 1 : 0; m_current_end_camera = 0; m_camera->setFOV(m_fov); handleEndCamera(0); } // mode==CM_FINAL m_mode = mode; } // setMode