Some redesign of split screen to enable proper handling of

ambient light changes.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@4229 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-11-29 13:04:57 +00:00
parent a7e32c44d0
commit ed9bd38402
15 changed files with 265 additions and 263 deletions

View File

@ -35,6 +35,7 @@ Camera::Camera(int camera_index, const Kart* kart)
m_mode = CM_NORMAL;
m_index = camera_index;
m_camera = irr_driver->addCameraSceneNode();
setupCamera();
m_distance = kart->getKartProperties()->getCameraDistance() * 0.5f;
m_kart = kart;
m_angle_up = 0.0f;
@ -56,10 +57,80 @@ Camera::Camera(int camera_index, const Kart* kart)
*/
Camera::~Camera()
{
irr_driver->removeCamera(this);
irr_driver->removeCameraSceneNode(m_camera);
} // ~Camera
//-----------------------------------------------------------------------------
/** Sets up the viewport, aspect ratio, field of view, and scaling for this
* camera.
*/
void Camera::setupCamera()
{
m_aspect = (float)(UserConfigParams::m_width)/UserConfigParams::m_height;
switch(race_manager->getNumLocalPlayers())
{
case 1: m_viewport = core::recti(0, 0,
UserConfigParams::m_width,
UserConfigParams::m_height);
m_scaling = core::vector2df(1.0f, 1.0f);
m_fov = DEGREE_TO_RAD*75.0f;
break;
case 2: m_viewport = core::recti(0,
m_index==0 ? 0
: UserConfigParams::m_height>>1,
UserConfigParams::m_width,
m_index==0 ? UserConfigParams::m_height>>1
: UserConfigParams::m_height);
m_scaling = core::vector2df(1.0f, 0.5f);
m_aspect *= 2.0f;
m_fov = DEGREE_TO_RAD*85.0f;
break;
case 3: if(m_index<2)
{
m_viewport = core::recti(m_index==0 ? 0
: UserConfigParams::m_width>>1,
0,
m_index==0 ? UserConfigParams::m_width>>1
: UserConfigParams::m_width,
UserConfigParams::m_height>>1);
m_scaling = core::vector2df(0.5f, 0.5f);
m_fov = DEGREE_TO_RAD*50.0f;
}
else
{
m_viewport = core::recti(0, UserConfigParams::m_height>>1,
UserConfigParams::m_width,
UserConfigParams::m_height);
m_scaling = core::vector2df(1.0f, 0.5f);
m_fov = DEGREE_TO_RAD*85.0f;
m_aspect *= 2.0f;
}
break;
case 4: m_viewport = core::recti(m_index%2==0 ? 0
: UserConfigParams::m_width>>1,
m_index<2 ? 0
: UserConfigParams::m_width>>1,
m_index%2==0 ? UserConfigParams::m_width>>1
: UserConfigParams::m_width,
m_index<2 ? UserConfigParams::m_height>>1
: UserConfigParams::m_height);
m_scaling = core::vector2df(0.5f, 0.5f);
m_fov = DEGREE_TO_RAD*50.0f;
break;
default:fprintf(stderr, "Incorrect number of players: '%d' - assuming 1.\n",
race_manager->getNumLocalPlayers());
m_viewport = core::recti(0, 0,
UserConfigParams::m_width,
UserConfigParams::m_height);
m_scaling = core::vector2df(1.0f, 1.0f);
m_fov = DEGREE_TO_RAD*75.0f;
break;
} // switch
m_camera->setFOV(m_fov);
m_camera->setAspectRatio(m_aspect);
} // setupCamera
// ----------------------------------------------------------------------------
void Camera::setMode(Mode mode)
{
m_mode = mode;
@ -205,3 +276,15 @@ void Camera::update(float dt)
} // update
// ----------------------------------------------------------------------------
/** Sets viewport etc. for this camera. Called from irr_driver just before
* rendering the view for this kart.
*/
void Camera::activate()
{
irr::scene::ISceneManager *sm = irr_driver->getSceneManager();
sm->setActiveCamera(m_camera);
sm->setAmbientLight(m_ambient_light);
irr_driver->getVideoDriver()->setViewPort(m_viewport);
} // activate

View File

@ -41,35 +41,92 @@ public:
};
private:
scene::ICameraSceneNode
*m_camera;
Mode m_mode; // Camera's mode
Vec3 m_position; // The ultimate position which the camera wants to obtain
Vec3 m_temp_position; // The position the camera currently has
Vec3 m_target; // The ultimate target which the camera wants to obtain
Vec3 m_temp_target; // The target the camera currently has
/** The camera scene node. */
scene::ICameraSceneNode *m_camera;
int m_index;
/** Camera's mode. */
Mode m_mode;
float m_distance; // Distance between the camera and the kart
float m_angle_up; // Angle between the ground and the camera (with the kart as the vertex of the angle)
float m_angle_around; // Angle around the kart (should actually match the rotation of the kart)
float m_position_speed; // The speed at which the camera changes position
float m_target_speed; // The speed at which the camera changes targets
float m_rotation_range; // Factor of the effects of steering in camera aim
/** The index of this camera which is the index of the kart it is
* attached to. */
unsigned int m_index;
const Kart *m_kart; // The kart that the camera follows
/** The ultimate position which the camera wants to obtain. */
Vec3 m_position;
/** The position the camera currently has. */
Vec3 m_temp_position;
/** The ultimate target which the camera wants to obtain. */
Vec3 m_target;
/** The target the camera currently has. */
Vec3 m_temp_target;
/** Current ambient light for this camera. */
video::SColor m_ambient_light;
/** Distance between the camera and the kart. */
float m_distance;
/** Angle between the ground and the camera (with the kart as the
* vertex of the angle). */
float m_angle_up;
/** Angle around the kart (should actually match the rotation of the kart). */
float m_angle_around;
/** The speed at which the camera changes position. */
float m_position_speed;
/** The speed at which the camera changes targets. */
float m_target_speed;
/** Factor of the effects of steering in camera aim. */
float m_rotation_range;
/** The kart that the camera follows. */
const Kart *m_kart;
/** The list of viewports for this cameras. */
core::recti m_viewport;
/** The scaling necessary for each axis. */
core::vector2df m_scaling;
/** Field of view for the camera. */
float m_fov;
/** Aspect ratio for camera. */
float m_aspect;
void setupCamera();
private:
public:
Camera (int camera_index, const Kart* kart);
~Camera ();
void setMode (Mode mode_); /** Set the camera to the given mode */
Mode getMode();
/** Returns the camera index (or player kart index, which is the same). */
int getIndex() const {return m_index;}
void reset ();
void setInitialTransform();
void activate();
void update (float dt);
/** Sets the ambient light for this camera. */
void setAmbientLight(const video::SColor &color) { m_ambient_light=color; }
/** Returns the current ambient light. */
const video::SColor &getAmbientLight() const {return m_ambient_light; }
/** Returns the viewport of this camera. */
const core::recti& getViewport() const {return m_viewport; }
/** Returns the scaling in x/y direction for this camera. */
const core::vector2df& getScaling() const {return m_scaling; }
/** Returns the camera scene node. */
scene::ICameraSceneNode *getCameraSceneNode()
{
return m_camera;

View File

@ -495,39 +495,6 @@ scene::ICameraSceneNode *IrrDriver::addCameraSceneNode()
return m_scene_manager->addCameraSceneNode();
} // addCameraSceneNode
//-----------------------------------------------------------------------------
/** Adds a camera (as in STK Camera object, not an irrlicht camera). The number
* of cameras determines e.g. if split screen is used.
*/
Camera *IrrDriver::addCamera(unsigned int index, Kart *kart)
{
Camera *camera = new Camera(index, kart);
m_stk_cameras.push_back(camera);
m_viewports.push_back(core::recti());
m_scaling.push_back(core::vector2df());
m_fov.push_back(DEGREE_TO_RAD*75.0f);
m_aspect.push_back(((float)UserConfigParams::m_width)/UserConfigParams::m_height);
setupViewports();
return camera;
} // addCamera
// ----------------------------------------------------------------------------
void IrrDriver::removeCamera(Camera *camera)
{
unsigned index;
for(index=0; index<m_stk_cameras.size(); index++)
{
if(m_stk_cameras[index]==camera) break;
}
assert(index!=m_stk_cameras.size());
m_stk_cameras.erase(m_stk_cameras.begin()+index);
m_viewports.erase(m_viewports.begin()+index);
m_scaling.erase(m_scaling.begin()+index);
m_fov.erase(m_fov.begin()+index);
m_aspect.erase(m_aspect.begin()+index);
removeCameraSceneNode(camera->getCameraSceneNode());
} // removeCamera
// ----------------------------------------------------------------------------
/** Removes a camera. This can't be done with removeNode() since the camera
* can be marked as active, meaning a drop will not delete it. While this
@ -551,88 +518,6 @@ video::ITexture *IrrDriver::getTexture(const std::string &filename)
return m_scene_manager->getVideoDriver()->getTexture(filename.c_str());
} // getTexture
// ----------------------------------------------------------------------------
/** Determines the viewports and scaling for the cameras.
*/
void IrrDriver::setupViewports()
{
assert(m_stk_cameras.size()==m_viewports.size());
switch(m_stk_cameras.size())
{
case 1: m_viewports[0] = core::recti(0, 0,
UserConfigParams::m_width,
UserConfigParams::m_height);
m_scaling[0] = core::vector2df(1.0f, 1.0f);
break;
case 2: m_viewports[0] = core::recti(0, 0,
UserConfigParams::m_width,
UserConfigParams::m_height>>1);
m_scaling[0] = core::vector2df(1.0f, 0.5f);
m_aspect[0] *= 2.0f;
m_fov[0] = DEGREE_TO_RAD*85.0f;
m_viewports[1] = core::recti(0, UserConfigParams::m_height>>1,
UserConfigParams::m_width,
UserConfigParams::m_height);
m_scaling[1] = core::vector2df(1.0f, 0.5f);
m_aspect[1] *= 2.0f;
m_fov[1] = DEGREE_TO_RAD*85.0f;
break;
case 3: m_viewports[0] = core::recti(0, 0,
UserConfigParams::m_width>>1,
UserConfigParams::m_height>>1);
m_scaling[0] = core::vector2df(0.5f, 0.5f);
m_fov[1] = DEGREE_TO_RAD*50.0f;
m_viewports[1] = core::recti(UserConfigParams::m_width>>1,
0,
UserConfigParams::m_width,
UserConfigParams::m_height>>1);
m_scaling[1] = core::vector2df(0.5f, 0.5f);
m_fov[1] = DEGREE_TO_RAD*50.0f;
m_viewports[2] = core::recti(0, UserConfigParams::m_height>>1,
UserConfigParams::m_width,
UserConfigParams::m_height);
m_scaling[2] = core::vector2df(1.0f, 0.5f);
m_fov[1] = DEGREE_TO_RAD*85.0f;
m_aspect[2] *= 2.0f;
break;
case 4: m_viewports[0] = core::recti(0, 0,
UserConfigParams::m_width>>1,
UserConfigParams::m_height>>1);
m_scaling[0] = core::vector2df(0.5f, 0.5f);
m_fov[0] = DEGREE_TO_RAD*50.0f;
m_viewports[1] = core::recti(UserConfigParams::m_width>>1,
0,
UserConfigParams::m_width,
UserConfigParams::m_height>>1);
m_scaling[1] = core::vector2df(0.5f, 0.5f);
m_fov[1] = DEGREE_TO_RAD*50.0f;
m_viewports[2] = core::recti(0, UserConfigParams::m_height>>1,
UserConfigParams::m_width>>1,
UserConfigParams::m_height);
m_scaling[2] = core::vector2df(0.5f, 0.5f);
m_fov[2] = DEGREE_TO_RAD*50.0f;
m_viewports[3] = core::recti(UserConfigParams::m_width>>1,
UserConfigParams::m_height>>1,
UserConfigParams::m_width,
UserConfigParams::m_height);
m_scaling[3] = core::vector2df(0.5f, 0.5f);
m_fov[3] = DEGREE_TO_RAD*50.0f;
break;
default:fprintf(stderr, "Incorrect number of players: '%d' - assuming 1.\n",
m_stk_cameras.size());
m_viewports[0] = core::recti(0, 0,
UserConfigParams::m_width,
UserConfigParams::m_height);
m_scaling[0] = core::vector2df(1.0f, 1.0f);
break;
} // switch
for(unsigned int i=0; i<m_stk_cameras.size(); i++)
{
m_stk_cameras[i]->getCameraSceneNode()->setFOV(m_fov[i]);
m_stk_cameras[i]->getCameraSceneNode()->setAspectRatio(m_aspect[i]);
}
} // setupViewports
// ----------------------------------------------------------------------------
/** Sets the ambient light.
* \param light The colour of the light to set.
@ -742,11 +627,6 @@ void IrrDriver::displayFPS()
*/
void IrrDriver::update(float dt)
{
// First update all cameras
std::vector<Camera*>::iterator i;
for(i=m_stk_cameras.begin(); i!=m_stk_cameras.end(); i++)
(*i)->update(dt);
if(!m_device->run()) return;
m_device->getVideoDriver()->beginScene(false, true, video::SColor(255,100,101,140));
@ -774,21 +654,22 @@ void IrrDriver::update(float dt)
else
{
RaceGUI *rg = RaceManager::getWorld()->getRaceGUI();
for(unsigned int i=0; i<m_stk_cameras.size(); i++)
for(unsigned int i=0; i<race_manager->getNumLocalPlayers(); i++)
{
m_scene_manager->setActiveCamera(m_stk_cameras[i]->getCameraSceneNode());
m_video_driver->setViewPort(m_viewports[i]);
PlayerKart *pk=RaceManager::getWorld()->getLocalPlayerKart(i);
pk->activateCamera();
m_scene_manager->drawAll();
}
// To draw the race gui we set the viewport back to the full
// screen.
m_video_driver->setViewPort(core::recti(0, 0,
UserConfigParams::m_width,
UserConfigParams::m_height));
for(unsigned int i=0; i<m_stk_cameras.size(); i++)
for(unsigned int i=0; i<race_manager->getNumLocalPlayers(); i++)
{
rg->renderPlayerView(i, m_viewports[i], m_scaling[i]);
} // for i <m_stk_cameras.size()
rg->renderPlayerView(i);
} // for i<getNumLocalPlayers
} // !bullet_debug
}
else

View File

@ -50,21 +50,6 @@ private:
video::IVideoDriver *m_video_driver;
/** Irrlicht race font. */
irr::gui::IGUIFont *m_race_font;
/** The list of all cameras. */
std::vector<Camera*> m_stk_cameras;
/** The list of viewports for all cameras. */
std::vector<core::recti> m_viewports;
/** The scaling necessary for each axis for each camera. */
std::vector<core::vector2df> m_scaling;
/** Field of view for camera. */
std::vector<float> m_fov;
/** Aspect ratio for camera. */
std::vector<float> m_aspect;
void setAllMaterialFlags(scene::IAnimatedMesh *mesh) const;
std::vector<VideoMode> m_modes;

View File

@ -33,6 +33,13 @@
#include "utils/constants.hpp"
#include "utils/translation.hpp"
/** The constructor for a player kart.
* \param kart_name Name of the kart.
* \param position The starting position (1 to n).
* \param player The player to which this kart belongs.
* \param init_pos The start coordinates and heading of the kart.
* \param player_index Index of the player akrt.
*/
PlayerKart::PlayerKart(const std::string& kart_name, int position,
ActivePlayer *player, const btTransform& init_pos,
unsigned int player_index) :
@ -40,7 +47,7 @@ PlayerKart::PlayerKart(const std::string& kart_name, int position,
{
m_player = player;
m_penalty_time = 0.0f;
m_camera = irr_driver->addCamera(player_index, this);
m_camera = new Camera(player_index, this);
m_camera->setMode(Camera::CM_NORMAL);
m_bzzt_sound = sfx_manager->newSFX(SFXManager::SOUND_BZZT );
@ -53,9 +60,11 @@ PlayerKart::PlayerKart(const std::string& kart_name, int position,
} // PlayerKart
//-----------------------------------------------------------------------------
/** Destructor for a player kart.
*/
PlayerKart::~PlayerKart()
{
irr_driver->removeCamera(m_camera);
delete m_camera;
sfx_manager->deleteSFX(m_bzzt_sound);
sfx_manager->deleteSFX(m_wee_sound );
sfx_manager->deleteSFX(m_ugh_sound );
@ -64,6 +73,8 @@ PlayerKart::~PlayerKart()
} // ~PlayerKart
//-----------------------------------------------------------------------------
/** Resets the player kart for a new or restarted race.
*/
void PlayerKart::reset()
{
m_steer_val_l = 0;
@ -170,6 +181,8 @@ void PlayerKart::action(PlayerAction action, int value)
} // action
//-----------------------------------------------------------------------------
/** Handles steering for a player kart.
*/
void PlayerKart::steer(float dt, int steer_val)
{
if(UserConfigParams::m_gamepad_debug)
@ -216,8 +229,11 @@ void PlayerKart::steer(float dt, int steer_val)
} // steer
//-----------------------------------------------------------------------------
/** Updates the player kart, called once each timestep.
*/
void PlayerKart::update(float dt)
{
m_camera->update(dt);
// Don't do steering if it's replay. In position only replay it doesn't
// matter, but if it's physics replay the gradual steering causes
// incorrect results, since the stored values are already adjusted.
@ -232,10 +248,15 @@ void PlayerKart::update(float dt)
if(m_penalty_time == 0.0)//eliminates machine-gun-effect for SOUND_BZZT
{
m_penalty_time=1.0;
RaceGUI* m=RaceManager::getWorld()->getRaceGUI();
if(m)
{
m->addMessage(_("Penalty time!!"),
this, 2.0f, 60);
}
m_bzzt_sound->play();
}
// A warning gets displayed in RaceGUI
}
} // if penalty_time = 0
} // if key pressed
else
{
// The call to update is necessary here (even though the kart
@ -243,9 +264,9 @@ void PlayerKart::update(float dt)
// the camera gets the wrong position.
Kart::update(dt);
}
return;
}
} // if isStartPhase
if(m_penalty_time>0.0)
{
m_penalty_time-=dt;
@ -258,27 +279,17 @@ void PlayerKart::update(float dt)
Kart::beep();
}
if(m_controls.m_look_back)
{
m_camera->setMode(Camera::CM_REVERSE);
}
else
{
m_camera->setMode(Camera::CM_NORMAL);
}
m_camera->setMode(m_controls.m_look_back ? Camera::CM_REVERSE
: Camera::CM_NORMAL);
// We can't restrict rescue to fulfil isOnGround() (which would be more like
// MK), since e.g. in the City track it is possible for the kart to end
// up sitting on a brick wall, with all wheels in the air :((
if ( m_controls.m_rescue )
{
//m_beep_sound->play();
forceRescue();
m_controls.m_rescue=false;
}
// FIXME: This is the code previously done in Kart::update (for player
// karts). Does this mean that there are actually two sounds played
// when rescue? beep above and bzzt her???
if (isRescue() && m_attachment.getType() != ATTACH_TINYTUX)
{
m_bzzt_sound->play();
@ -287,6 +298,8 @@ void PlayerKart::update(float dt)
} // update
//-----------------------------------------------------------------------------
/** Marks the kart as having had a crash.
*/
void PlayerKart::crashed(Kart *kart)
{
Kart::crashed(kart);

View File

@ -23,6 +23,7 @@
#define HEADER_PLAYERKART_HPP
#include "config/player.hpp"
#include "graphics/camera.hpp"
#include "karts/kart.hpp"
class SFXBase;
@ -34,19 +35,19 @@ class Camera;
class PlayerKart : public Kart
{
private:
int m_steer_val, m_steer_val_l, m_steer_val_r;
int m_prev_accel;
bool m_prev_brake;
int m_steer_val, m_steer_val_l, m_steer_val_r;
int m_prev_accel;
bool m_prev_brake;
ActivePlayer *m_player;
float m_penalty_time;
Camera *m_camera;
SFXBase *m_bzzt_sound;
SFXBase *m_wee_sound;
SFXBase *m_ugh_sound;
SFXBase *m_grab_sound;
SFXBase *m_full_sound;
SFXBase *m_bzzt_sound;
SFXBase *m_wee_sound;
SFXBase *m_ugh_sound;
SFXBase *m_grab_sound;
SFXBase *m_full_sound;
void steer(float, int);
public:
@ -55,7 +56,6 @@ public:
const btTransform& init_pos,
unsigned int player_index);
~PlayerKart ();
int earlyStartPenalty () { return m_penalty_time>0; }
ActivePlayer *getPlayer () { return m_player; }
PlayerProfile *getPlayerProfile () { return m_player->getProfile(); }
void update (float);
@ -69,6 +69,12 @@ public:
Camera* getCamera () {return m_camera;}
void reset ();
void resetInputState ();
/** Sets viewport etc. for the camera of this kart. */
void activateCamera () {m_camera->activate(); }
/** Returns the viewport of the camera of this kart. */
const core::recti& getViewport() const {return m_camera->getViewport(); }
/** Returns the scaling in x/y direction for the camera of this kart. */
const core::vector2df& getScaling() const {return m_camera->getScaling(); }
};
#endif

View File

@ -87,7 +87,9 @@ Kart *ProfileWorld::createKart(const std::string &kart_ident, int index,
{
// The pointer to the camera does not have to be stored, since it
// the camera for robots is not modified.
irr_driver->addCamera(index, newkart);
// FIXME: this is broken now, where do we store the camera in case
// of profile mode???
new Camera(index, newkart);
}
//m_local_player_karts[index] = static_cast<PlayerKart*>(newkart);
//m_player_karts[index] = static_cast<PlayerKart*>(newkart);

View File

@ -118,7 +118,7 @@ void World::init()
const std::string& kart_ident = race_manager->getKartIdent(i);
int local_player_id = race_manager->getKartLocalPlayerId(i);
int global_player_id = race_manager->getKartGlobalPlayerId(i);
Kart* newkart = this->createKart(kart_ident, i, local_player_id,
Kart* newkart = createKart(kart_ident, i, local_player_id,
global_player_id, init_pos);
m_kart.push_back(newkart);
newkart->setWorldKartId(m_kart.size()-1);
@ -142,7 +142,7 @@ void World::init()
* \param index Index of the kart.
* \param local_player_id If the kart is a player kart this is the index of
* this player on the local machine.
* \param global_player_id If the akrt is a player kart this is the index of
* \param global_player_id If the kart is a player kart this is the index of
* this player globally (i.e. including network players).
* \param init_pos The start XYZ coordinates.
*/

View File

@ -52,7 +52,7 @@ Track* RaceManager::getTrack()
{
return m_world->getTrack();
}
Kart* RaceManager::getPlayerKart(const unsigned int n)
PlayerKart* RaceManager::getPlayerKart(const unsigned int n)
{
return m_world->getPlayerKart(n);
}

View File

@ -27,9 +27,10 @@
#include "network/remote_kart_info.hpp"
#include "race/grand_prix_data.hpp"
class World;
class Track;
class Kart;
class PlayerKart;
class Track;
class World;
/** The race manager has two functions:
* 1) it stores information about the race the user selected (e.g. number
@ -178,7 +179,7 @@ public:
static World* getWorld() {return m_world;}
static void setWorld(World* world);
static Track* getTrack();
static Kart* getPlayerKart(const unsigned int n);
static PlayerKart* getPlayerKart(const unsigned int n);
static Kart* getKart(const unsigned int n);
public:

View File

@ -172,14 +172,6 @@ void RaceGUI::renderGlobal(float dt)
drawGlobalReadySetGo();
}
// The penalty message needs to be displayed for up to one second
// after the start of the race, otherwise it disappears if
// "Go" is displayed and the race starts
if(RaceManager::getWorld()->isStartPhase() ||
RaceManager::getWorld()->getTime()<1.0f)
{
displayPenaltyMessages();
}
// Timer etc. are not displayed unless the game is actually started.
if(!RaceManager::getWorld()->isRacePhase()) return;
@ -202,20 +194,21 @@ void RaceGUI::renderGlobal(float dt)
* \param viewport Viewport to use (already set in the camera).
* \param scaling Scaling to use.
*/
void RaceGUI::renderPlayerView(unsigned int player_id,
const core::recti &viewport,
const core::vector2df &scaling)
void RaceGUI::renderPlayerView(unsigned int player_id)
{
PlayerKart* player_kart = RaceManager::getWorld()->getLocalPlayerKart(player_id);
const core::recti &viewport = player_kart->getViewport();
const core::vector2df &scaling = player_kart->getScaling();
drawAllMessages (player_kart, viewport, scaling);
if(!RaceManager::getWorld()->isRacePhase()) return;
RaceGUI::KartIconDisplayInfo* info = RaceManager::getWorld()->getKartsDisplayInfo();
Kart* player_kart = RaceManager::getWorld()->getLocalPlayerKart(player_id);
drawPowerupIcons (player_kart, viewport, scaling);
drawEnergyMeter (player_kart, viewport, scaling);
drawSpeed (player_kart, viewport, scaling);
drawLap (info, player_kart, viewport, scaling);
drawAllMessages (player_kart, viewport, scaling);
if(player_kart->hasViewBlockedByPlunger())
{
int offset_x = viewport.UpperLeftCorner.X;
@ -369,15 +362,18 @@ void RaceGUI::drawPowerupIcons(Kart* player_kart,
int nSize=(int)(64.0f*std::min(scaling.X, scaling.Y));
int x1 = (int)((UserConfigParams::m_width/2-32) * scaling.X)
+ viewport.UpperLeftCorner.X;
int y1 = UserConfigParams::m_height - viewport.LowerRightCorner.Y
+ (int)(20 * scaling.Y)+nSize;
//int y1 = UserConfigParams::m_height - viewport.LowerRightCorner.Y
// + (int)(20 * scaling.Y)+nSize;
int y1 = viewport.UpperLeftCorner.Y
+ (int)(20 * scaling.Y);
video::ITexture *t=powerup->getIcon()->getTexture();
core::rect<s32> rect(core::position2di(0, 0), t->getOriginalSize());
for ( int i = 0 ; i < n ; i++ )
{
core::rect<s32> pos(x1+i*30, y1-nSize, x1+i*30+nSize, y1);
int x2=(int)(x1+i*std::min(scaling.X, scaling.Y)*30);
core::rect<s32> pos(x2, y1, x2+nSize, y1+nSize);
irr_driver->getVideoDriver()->draw2DImage(t, pos, rect, NULL,
NULL, true);
} // for i
@ -392,7 +388,7 @@ void RaceGUI::drawEnergyMeter (Kart *player_kart,
float state = (float)(player_kart->getEnergy()) / MAX_ITEMS_COLLECTED;
int x = (int)((UserConfigParams::m_width-24) * scaling.X) + viewport.UpperLeftCorner.X;
//int y = (int)(250 * scaling.Y) + viewport.UpperLeftCorner.Y;
int y = UserConfigParams::m_height - (int)(250 * scaling.Y) - viewport.UpperLeftCorner.Y;
int y = viewport.LowerRightCorner.Y - (int)(250 * scaling.Y);
int w = (int)(16 * scaling.X);
int h = (int)(UserConfigParams::m_height/4 * scaling.Y);
float coin_target = (float)race_manager->getCoinTarget();
@ -456,15 +452,15 @@ void RaceGUI::drawSpeed(Kart* kart, const core::recti &viewport,
int meter_height = (int)(SPEEDWIDTH*minRatio);
core::vector2di offset = viewport.UpperLeftCorner;
offset.X += (int)((UserConfigParams::m_width-10)*scaling.X) - meter_width;
offset.Y += (int)(10*scaling.Y);
offset.Y = viewport.LowerRightCorner.Y-(int)(10*scaling.Y);
// First draw the meter (i.e. the background which contains the numbers etc.
// -------------------------------------------------------------------------
video::IVideoDriver *video = irr_driver->getVideoDriver();
const core::rect<s32> meter_pos(offset.X,
UserConfigParams::m_height-offset.Y-meter_height,
offset.Y-meter_height,
offset.X+meter_width,
UserConfigParams::m_height-offset.Y);
offset.Y);
video::ITexture *meter_texture = m_speed_meter_icon->getTexture();
const core::rect<s32> meter_texture_coords(core::position2d<s32>(0,0),
meter_texture->getOriginalSize());
@ -476,9 +472,9 @@ void RaceGUI::drawSpeed(Kart* kart, const core::recti &viewport,
{
static video::SColor color = video::SColor(255, 255, 255, 255);
core::rect<s32> pos(offset.X-(int)(30*minRatio),
UserConfigParams::m_height-(offset.Y-(int)(10*minRatio)),
offset.Y-(int)(10*minRatio),
offset.X-(int)(30*minRatio),
UserConfigParams::m_height-(offset.Y-(int)(10*minRatio)) );
offset.Y-(int)(10*minRatio) );
irr_driver->getRaceFont()->draw(core::stringw("!").c_str(), pos, color);
}
@ -519,11 +515,11 @@ void RaceGUI::drawSpeed(Kart* kart, const core::recti &viewport,
count = 4;
vertices[2].TCoords = core::vector2df(0,0);
vertices[2].Pos = core::vector3df((float)offset.X,
(float)(UserConfigParams::m_height-offset.Y-meter_height),
(float)(offset.Y-meter_height),
0);
vertices[3].TCoords = core::vector2df(2*speed_ratio-1.0f, 0);
vertices[3].Pos = core::vector3df(offset.X+2*(speed_ratio-0.5f)*meter_width,
(float)(UserConfigParams::m_height-offset.Y-meter_height),
(float)(offset.Y-meter_height),
0);
}
short int index[4];
@ -557,28 +553,30 @@ void RaceGUI::drawLap(const KartIconDisplayInfo* info, Kart* kart,
core::recti pos;
pos.UpperLeftCorner.X = viewport.UpperLeftCorner.X
+ (int)(0.15f*UserConfigParams::m_width*scaling.X);
pos.UpperLeftCorner.Y = UserConfigParams::m_height - viewport.LowerRightCorner.Y;
//pos.UpperLeftCorner.Y += (int)(UserConfigParams::m_height*5/6*minRatio);
pos.UpperLeftCorner.Y += (int)(40*minRatio);
pos.LowerRightCorner = pos.UpperLeftCorner;
pos.UpperLeftCorner.Y = viewport.LowerRightCorner.Y;
gui::IGUIFont* font = irr_driver->getRaceFont();
int font_height = (int)(60*scaling.Y);
if(kart->hasFinishedRace())
{
static video::SColor color = video::SColor(255, 255, 255, 255);
//I18N: Shown at the end of a race
core::stringw s=_("Finished");
pos.UpperLeftCorner.Y -= 2*font_height;
pos.LowerRightCorner = pos.UpperLeftCorner;
font->draw(s.c_str(), pos, color);
}
else
{
static video::SColor color = video::SColor(255, 255, 255, 255);
core::stringw s = _("Lap");
pos.UpperLeftCorner.Y -= 3*font_height;
pos.LowerRightCorner = pos.UpperLeftCorner;
font->draw(core::stringw(_("Lap")).c_str(), pos, color);
char str[256];
sprintf(str, "%d/%d", lap+1, race_manager->getNumLaps());
pos.UpperLeftCorner.Y += (int)(40*scaling.Y);
pos.LowerRightCorner.Y += (int)(40*scaling.Y);
pos.UpperLeftCorner.Y += font_height;
pos.LowerRightCorner.Y += font_height;
font->draw(core::stringw(str).c_str(), pos, color);
}
} // drawLap
@ -612,10 +610,11 @@ void RaceGUI::drawAllMessages(Kart* player_kart,
const core::recti &viewport,
const core::vector2df &scaling)
{
int y;
// First line of text somewhat under the top of the screen. For now
// start just under the timer display
y = (int)(scaling.Y*164+viewport.UpperLeftCorner.Y);
int y = (int)(scaling.Y*164 + UserConfigParams::m_height
- viewport.LowerRightCorner.Y );
int x = (viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X)>>1;
// The message are displayed in reverse order, so that a multi-line
// message (addMessage("1", ...); addMessage("2",...) is displayed
// in the right order: "1" on top of "2"
@ -626,8 +625,7 @@ void RaceGUI::drawAllMessages(Kart* player_kart,
// Display only messages for all karts, or messages for this kart
if( msg.m_kart && msg.m_kart!=player_kart) continue;
core::rect<s32> pos(UserConfigParams::m_width>>1, y,
UserConfigParams::m_width>>1, y);
core::rect<s32> pos(x, y, x, y);
irr_driver->getRaceFont()->draw(core::stringw(msg.m_message.c_str()).c_str(),
pos, msg.m_color, true, true);
y+=40;
@ -767,28 +765,3 @@ void RaceGUI::drawGlobalReadySetGo()
break;
} // switch
} // drawGlobalReadySetGo
// ----------------------------------------------------------------------------
void RaceGUI::displayPenaltyMessages()
{
// The penalty message needs to be displayed for up to one second
// after the start of the race, otherwise it disappears if
// "Go" is displayed and the race starts
const unsigned int num_players = race_manager->getNumLocalPlayers();
if(RaceManager::getWorld()->isStartPhase() || RaceManager::getWorld()->getTime()<1.0f)
{
for(unsigned int i=0; i<num_players; i++)
{
if(RaceManager::getWorld()->getLocalPlayerKart(i)->earlyStartPenalty())
{
static video::SColor color = video::SColor(255, 179, 6, 6);
// FIXME: the position should take split screen into account!
core::rect<s32> pos(UserConfigParams::m_width>>1, (UserConfigParams::m_height>>1)-40,
UserConfigParams::m_width>>1, (UserConfigParams::m_height>>1)-40);
gui::IGUIFont* font = irr_driver->getRaceFont();
core::stringw s=_("Penalty time!!");
font->draw(s.c_str(), pos, color, true, true);
} // if penalty
} // for i < getNum_players
} // if not RACE_PHASE
} // displayPenaltyMessage

View File

@ -157,14 +157,12 @@ private:
void drawGlobalMusicDescription();
void cleanupMessages (const float dt);
void drawGlobalReadySetGo ();
void displayPenaltyMessages();
public:
RaceGUI();
~RaceGUI();
void renderGlobal(float dt);
void renderPlayerView(unsigned int player_id, const core::recti &viewport,
const core::vector2df &scaling);
void renderPlayerView(unsigned int player_id);
void addMessage(const irr::core::stringw &m, const Kart *kart, float time,
int fonst_size,

View File

@ -22,6 +22,7 @@
#include <string>
#include <stdio.h>
#include "graphics/camera.hpp"
#include "io/xml_node.hpp"
#include "modes/world.hpp"
#include "race/race_manager.hpp"
@ -47,8 +48,12 @@ AmbientLightSphere::AmbientLightSphere(CheckManager *check_manager,
void AmbientLightSphere::update(float dt)
{
CheckStructure::update(dt);
race_manager->getNumLocalPlayers();
for(unsigned int i=0; i<race_manager->getNumKarts(); i++)
{
Kart *kart=race_manager->getKart(i);
if(!kart->isPlayerKart()) continue;
if(isInside(i))
{
float d2=getDistance2ForKart(i);
@ -64,7 +69,7 @@ void AmbientLightSphere::update(float dt)
const video::SColor &def = track->getDefaultAmbientColor();
color = m_ambient_color.getInterpolated(def, f);
}
track->setAmbientColor(color);
((PlayerKart*)kart)->getCamera()->setAmbientLight(color);
} // if active
} // for i<num_karts
} // update

View File

@ -192,7 +192,6 @@ void Track::loadTrackInfo(const std::string &filename)
/* ARGB */
m_fog_color = video::SColor(255, 77, 179, 230);
m_default_ambient_color = video::SColor(255, 120, 120, 120);
//m_sun_ambient_color = video::SColor(255, 255, 255, 255);
m_sun_specular_color = video::SColor(255, 255, 255, 255);
m_sun_diffuse_color = video::SColor(255, 255, 255, 255);
XMLNode *root = file_manager->createXMLTree(m_filename);
@ -530,7 +529,6 @@ void Track::handleAnimatedTextures(scene::ISceneNode *node, const XMLNode &xml)
void Track::update(float dt)
{
irr_driver->getSceneManager()->setAmbientLight(m_ambient_color);
//m_sun->getLightData().AmbientColor = m_ambient_color;
for(unsigned int i=0; i<m_animated_textures.size(); i++)
{

View File

@ -134,9 +134,9 @@ private:
float m_fog_start;
float m_fog_end;
core::vector3df m_sun_position;
/** The current ambient color for each kart. */
video::SColor m_ambient_color;
video::SColor m_default_ambient_color;
//video::SColor m_sun_ambient_color;
video::SColor m_sun_specular_color;
video::SColor m_sun_diffuse_color;
video::SColor m_fog_color;
@ -253,9 +253,9 @@ public:
/** Returns the default ambient color. */
const video::SColor &getDefaultAmbientColor() const
{ return m_default_ambient_color;}
/** Sets the current ambient color. */
void setAmbientColor(const video::SColor &color)
{ m_ambient_color = color; }
/** Sets the current ambient color for a kart with index k. */
void setAmbientColor(const video::SColor &color,
unsigned int k);
/** Get the number of start positions defined in the scene file. */
unsigned int getNumberOfStartPositions() const
{ return m_start_positions.size(); }