From: <hik...@us...> - 2008-06-20 09:34:37
|
Revision: 2132 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=2132&view=rev Author: hikerstk Date: 2008-06-20 02:34:35 -0700 (Fri, 20 Jun 2008) Log Message: ----------- 1) Removed the old m_curr_pos sg* data structure from kart. 2) Replaced several sg* data structures and function parameters with plib independent data structures. 3) Some code cleanup, updated gpl license to 3 in a file or two. Modified Paths: -------------- trunk/supertuxkart/src/attachment.cpp trunk/supertuxkart/src/auto_kart.hpp trunk/supertuxkart/src/camera.cpp trunk/supertuxkart/src/coord.hpp trunk/supertuxkart/src/flyable.cpp trunk/supertuxkart/src/flyable.hpp trunk/supertuxkart/src/gui/race_gui.cpp trunk/supertuxkart/src/herring.cpp trunk/supertuxkart/src/herring.hpp trunk/supertuxkart/src/herring_manager.cpp trunk/supertuxkart/src/herring_manager.hpp trunk/supertuxkart/src/kart.cpp trunk/supertuxkart/src/kart.hpp trunk/supertuxkart/src/material.cpp trunk/supertuxkart/src/moveable.cpp trunk/supertuxkart/src/moveable.hpp trunk/supertuxkart/src/player_kart.cpp trunk/supertuxkart/src/player_kart.hpp trunk/supertuxkart/src/projectile_manager.cpp trunk/supertuxkart/src/robots/default_robot.cpp trunk/supertuxkart/src/robots/default_robot.hpp trunk/supertuxkart/src/scene.cpp trunk/supertuxkart/src/track.cpp trunk/supertuxkart/src/track.hpp trunk/supertuxkart/src/vec3.hpp trunk/supertuxkart/src/world.cpp trunk/supertuxkart/src/world.hpp Modified: trunk/supertuxkart/src/attachment.cpp =================================================================== --- trunk/supertuxkart/src/attachment.cpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/attachment.cpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -69,8 +69,8 @@ float leftover_time = 0.0f; switch(getType()) // If there already is an attachment, make it worse :) { - case ATTACH_BOMB: projectile_manager->newExplosion(m_kart->getPos()); - m_kart->handleExplosion(m_kart->getPos(), /*direct_hit*/ true); + case ATTACH_BOMB: projectile_manager->newExplosion(m_kart->getXYZ()); + m_kart->handleExplosion(m_kart->getXYZ(), /*direct_hit*/ true); clear(); random_attachment = rand()%3; break; @@ -139,8 +139,8 @@ case ATTACH_MAX: break; case ATTACH_BOMB: if(m_time_left<=0.0) { - projectile_manager->newExplosion(m_kart->getPos()); - m_kart->handleExplosion(m_kart->getPos(), + projectile_manager->newExplosion(m_kart->getXYZ()); + m_kart->handleExplosion(m_kart->getXYZ(), /*direct_hit*/ true); } break; Modified: trunk/supertuxkart/src/auto_kart.hpp =================================================================== --- trunk/supertuxkart/src/auto_kart.hpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/auto_kart.hpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -28,8 +28,8 @@ { public: AutoKart(const std::string& kart_name, int position, - sgCoord init_pos) : - Kart(kart_name, position, init_pos) { Kart::reset(); } + const btTransform& init_pos) : + Kart(kart_name, position, init_pos) {} int isPlayerKart() const {return 0;} }; Modified: trunk/supertuxkart/src/camera.cpp =================================================================== --- trunk/supertuxkart/src/camera.cpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/camera.cpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -34,7 +34,7 @@ m_context = new ssgContext ; m_distance = kart->getKartProperties()->getCameraDistance(); m_kart = kart; - m_xyz = kart->getPos(); + m_xyz = kart->getXYZ(); m_hpr = Vec3(0,0,0); // FIXME: clipping should be configurable for slower machines @@ -121,7 +121,7 @@ { setMode(CM_NORMAL); m_last_pitch = 0.0f; - m_xyz = m_kart->getPos(); + m_xyz = m_kart->getXYZ(); m_hpr = Vec3(0,0,0); } // reset @@ -142,7 +142,7 @@ else { kart = m_kart; - kart_hpr = kart->getRotation(); + kart_hpr = kart->getHPR(); // Use the terrain pitch to avoid the camera following a wheelie the kart is doing kart_hpr.setPitch( m_kart->getTerrainPitch(kart_hpr.getHeading()) ); kart_hpr.setRoll(0.0f); @@ -159,7 +159,7 @@ kart_hpr.setPitch(m_last_pitch); } // dt>0.0 } // m_mode!=CM_LEADER_MODE - kart_xyz = kart->getPos(); + kart_xyz = kart->getXYZ(); if(m_mode==CM_SIMPLE_REPLAY) kart_hpr.setHeading(0.0f); // Set the camera position relative to the kart Modified: trunk/supertuxkart/src/coord.hpp =================================================================== --- trunk/supertuxkart/src/coord.hpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/coord.hpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -5,7 +5,7 @@ // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 +// as published by the Free Software Foundation; either version 3 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, @@ -58,9 +58,11 @@ setSgCoord(); } // Coord // ------------------------------------------------------------------------ - const sgCoord& toSgCoord() const { return m_coord; } - const Vec3& getXYZ() const { return m_xyz; } - const Vec3& getHPR() const { return m_hpr; } + const sgCoord& toSgCoord() const { return m_coord; } + const Vec3& getXYZ() const { return m_xyz; } + const Vec3& getHPR() const { return m_hpr; } + void setHPR(const Vec3& a) { m_hpr = a; setSgCoord(); } + void setXYZ(const Vec3& a) { m_xyz = a; setSgCoord(); } }; // Coord #endif Modified: trunk/supertuxkart/src/flyable.cpp =================================================================== --- trunk/supertuxkart/src/flyable.cpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/flyable.cpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -76,7 +76,7 @@ trans.getBasis()[2][1]); float heading=atan2(-direction.getX(), direction.getY()); - TerrainInfo::update(m_owner->getPos()); + TerrainInfo::update(m_owner->getXYZ()); float pitch = getTerrainPitch(heading); btMatrix3x3 m; @@ -187,15 +187,6 @@ Moveable::update(dt); } // update -// ----------------------------------------------------------------------------- -void Flyable::placeModel() -{ - btTransform t=getTrans(); - float m[4][4]; - t.getOpenGLMatrix((float*)&m); - sgSetCoord(&m_curr_pos, m); - Moveable::placeModel(); -} // placeModel // ----------------------------------------------------------------------------- void Flyable::explode(Kart *kart_hit, MovingPhysics* moving_physics) @@ -213,7 +204,7 @@ scene->remove(m); // The explosion is a bit higher in the air - btVector3 pos_explosion=getPos(); + Vec3 pos_explosion=getXYZ(); pos_explosion.setZ(pos_explosion.getZ()+1.2f); world->getPhysics()->removeBody(getBody()); m_exploded=true; @@ -227,7 +218,7 @@ if(m_owner!=kart || m_owner==kart_hit) { // Set a flag it if was a direct hit. - kart->handleExplosion(getPos(), kart==kart_hit); + kart->handleExplosion(getXYZ(), kart==kart_hit); } } callback_manager->handleExplosion(pos_explosion, moving_physics); Modified: trunk/supertuxkart/src/flyable.hpp =================================================================== --- trunk/supertuxkart/src/flyable.hpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/flyable.hpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -66,12 +66,10 @@ CollectableType type); virtual void update (float); - void placeModel (); virtual void hitTrack () {}; void explode (Kart* kart, MovingPhysics* moving_physics=NULL); bool hasHit () { return m_has_hit_something; } - void reset () { Moveable::reset(); - sgCopyCoord(&m_last_pos,&m_reset_pos ); } + void reset () { Moveable::reset(); } }; // Flyable #endif Modified: trunk/supertuxkart/src/gui/race_gui.cpp =================================================================== --- trunk/supertuxkart/src/gui/race_gui.cpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/gui/race_gui.cpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -292,27 +292,25 @@ for ( unsigned int i = 0 ; i < race_manager->getNumKarts() ; i++ ) { - sgCoord *c ; - Kart* kart = world->getKart(i); if(kart->isEliminated()) continue; // don't draw eliminated kart glColor3fv ( kart->getColor().toFloat()); - c = kart->getCoord () ; + const Vec3& xyz = kart->getXYZ(); /* If it's a player, draw a bigger sign */ if (kart -> isPlayerKart ()) { - world -> m_track->glVtx ( c->xyz, (float)xLeft+3, (float)yTop+3); - world -> m_track->glVtx ( c->xyz, (float)xLeft-2, (float)yTop+3); - world -> m_track->glVtx ( c->xyz, (float)xLeft-2, (float)yTop-2); - world -> m_track->glVtx ( c->xyz, (float)xLeft+3, (float)yTop-2); + world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft+3, (float)yTop+3); + world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft-2, (float)yTop+3); + world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft-2, (float)yTop-2); + world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft+3, (float)yTop-2); } else { - world -> m_track->glVtx ( c->xyz, (float)xLeft+2, (float)yTop+2); - world -> m_track->glVtx ( c->xyz, (float)xLeft-1, (float)yTop+2); - world -> m_track->glVtx ( c->xyz, (float)xLeft-1, (float)yTop-1); - world -> m_track->glVtx ( c->xyz, (float)xLeft+2, (float)yTop-1); + world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft+2, (float)yTop+2); + world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft-1, (float)yTop+2); + world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft-1, (float)yTop-1); + world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft+2, (float)yTop-1); } } Modified: trunk/supertuxkart/src/herring.cpp =================================================================== --- trunk/supertuxkart/src/herring.cpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/herring.cpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -17,37 +17,31 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include "vec3.hpp" #include "world.hpp" #include "herring.hpp" #include "kart.hpp" #include "scene.hpp" +#include "coord.hpp" -Herring::Herring(herringType _type, sgVec3* xyz, ssgEntity* model) +Herring::Herring(herringType type, const Vec3& xyz, ssgEntity* model) + : m_coord(xyz, Vec3(0, 0, 0)) { - sgSetVec3(m_coord.hpr, 0.0f, 0.0f, 0.0f); - - sgCopyVec3(m_coord.xyz, *xyz); - m_root = new ssgTransform(); + m_type = type; + m_eaten = false; + m_time_to_return = 0.0f; // not strictly necessary, see isEaten() + m_root = new ssgTransform(); m_root->ref(); - m_root->setTransform(&m_coord); - - m_rotate = new ssgTransform(); - m_rotate->ref(); - m_rotate->addKid(model); - m_root->addKid(m_rotate); + m_root->setTransform(const_cast<sgCoord*>(&m_coord.toSgCoord())); + m_root->addKid(model); scene->add(m_root); - m_type = _type; - m_eaten = false; - m_rotation = 0.0f; - m_time_to_return = 0.0f; // not strictly necessary, see isEaten() } // Herring //----------------------------------------------------------------------------- Herring::~Herring() { ssgDeRefDelete(m_root); - ssgDeRefDelete(m_rotate); } // ~Herring //----------------------------------------------------------------------------- @@ -55,13 +49,13 @@ { m_eaten = false; m_time_to_return = 0.0f; - m_root->setTransform(&m_coord); + m_root->setTransform(const_cast<sgCoord*>(&m_coord.toSgCoord())); } // reset //----------------------------------------------------------------------------- int Herring::hitKart(Kart* kart) { - return sgDistanceSquaredVec3 ( kart->getCoord()->xyz, m_coord.xyz ) < 0.8f; + return (kart->getXYZ()-m_coord.getXYZ()).length2()<0.8f; } // hitKart //----------------------------------------------------------------------------- @@ -72,26 +66,24 @@ const float T = m_time_to_return - world->getTime(); if ( T > 0 ) { - sgVec3 hell; - sgCopyVec3(hell, m_coord.xyz); + Vec3 hell(m_coord.getXYZ()); - hell[2] = ( T > 1.0f ) ? -1000000.0f : m_coord.xyz[2] - T / 2.0f; - m_root -> setTransform(hell); + hell.setZ( (T>1.0f) ? -1000000.0f : m_coord.getXYZ().getZ() - T / 2.0f); + m_root->setTransform(hell.toFloat()); } else { - m_eaten = false; - m_rotation = 0.0f; - m_root -> setTransform(&m_coord); + m_eaten = false; + m_coord.setHPR(Vec3(0.0f)); + m_root->setTransform(const_cast<sgCoord*>(&m_coord.toSgCoord())); } // T>0 } else { // not m_eaten - sgCoord c = { { 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 } } ; - c.hpr[0] = m_rotation; - m_rotation += 180.0f*delta; - m_rotate -> setTransform ( &c ) ; + Vec3 rotation(delta*M_PI, 0, 0); + m_coord.setHPR(m_coord.getHPR()+rotation); + m_root->setTransform(const_cast<sgCoord*>(&m_coord.toSgCoord())); } } // update Modified: trunk/supertuxkart/src/herring.hpp =================================================================== --- trunk/supertuxkart/src/herring.hpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/herring.hpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -21,6 +21,7 @@ #define HEADER_HERRING_H #include <plib/sg.h> +#include "coord.hpp" class Kart; class ssgTransform; @@ -34,24 +35,22 @@ { private: herringType m_type; // Herring type - bool m_eaten; // true if herring was eaten & is not displayed + bool m_eaten; // true if herring was eaten & is not displayed float m_time_to_return; // world->clock when an eaten herring reappears - sgCoord m_coord; // Original coordinates, used mainly when - // eaten herrings reappear. + Coord m_coord; // Original coordinates, used mainly when + // eaten herrings reappear. ssgTransform* m_root; // The actual root of the herring - ssgTransform* m_rotate; // Just below root is a node only rotating - float m_rotation; // Amount of rotation public: - Herring (herringType type, sgVec3* xyz, ssgEntity* model); - ~Herring (); - void update (float delta); - bool wasEaten () {return m_eaten;} - void isEaten (); - herringType getType () {return m_type;} - int hitKart (Kart* kart ); - void reset (); + Herring (herringType type, const Vec3& xyz, ssgEntity* model); + ~Herring (); + void update (float delta); + void isEaten (); + int hitKart (Kart* kart ); + void reset (); ssgTransform* getRoot () const {return m_root;} + herringType getType () const {return m_type;} + bool wasEaten() const {return m_eaten;} } ; // class Herring Modified: trunk/supertuxkart/src/herring_manager.cpp =================================================================== --- trunk/supertuxkart/src/herring_manager.cpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/herring_manager.cpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -195,7 +195,7 @@ } // setDefaultHerringStyle //----------------------------------------------------------------------------- -Herring* HerringManager::newHerring(herringType type, sgVec3* xyz) +Herring* HerringManager::newHerring(herringType type, const Vec3& xyz) { Herring* h = new Herring(type, xyz, m_herring_model[type]); m_all_herrings.push_back(h); Modified: trunk/supertuxkart/src/herring_manager.hpp =================================================================== --- trunk/supertuxkart/src/herring_manager.hpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/herring_manager.hpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -57,7 +57,7 @@ ~HerringManager(); void loadDefaultHerrings(); void loadHerringStyle(const std::string filename); - Herring* newHerring (herringType type, sgVec3* xyz); + Herring* newHerring (herringType type, const Vec3& xyz); void update (float delta); void hitHerring (Kart* kart); void cleanup (); Modified: trunk/supertuxkart/src/kart.cpp =================================================================== --- trunk/supertuxkart/src/kart.cpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/kart.cpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -48,8 +48,8 @@ #endif -Kart::Kart (const std::string& kart_name, int position_ , - sgCoord init_pos) +Kart::Kart (const std::string& kart_name, int position, + const btTransform& init_transform) : TerrainInfo(1), #if defined(WIN32) && !defined(__CYGWIN__) // Disable warning for using 'this' in base member initializer list @@ -61,8 +61,8 @@ #endif { m_kart_properties = kart_properties_manager->getKart(kart_name); - m_grid_position = position_; - m_initial_position = position_; + m_grid_position = position; + m_initial_position = position; m_num_herrings_gobbled = 0; m_eliminated = false; m_finished_race = false; @@ -74,8 +74,10 @@ m_skidmark_left = NULL; m_skidmark_right = NULL; m_track_sector = Track::UNKNOWN_SECTOR; - sgCopyCoord(&m_reset_pos, &init_pos); + // Set position and heading: + m_reset_transform = init_transform; + // Neglecting the roll resistance (which is small for high speeds compared // to the air resistance), maximum speed is reached when the engine // power equals the air resistance force, resulting in this formula: @@ -97,6 +99,7 @@ m_wheel_rear_r = NULL; m_lap_start_time = -1.0f; loadData(); + reset(); } // Kart // -----------------------------------------------------------------------------v @@ -288,7 +291,6 @@ { world->getPhysics()->addKart(this, m_vehicle); } - Moveable::reset(); m_attachment.clear(); m_collectable.reset(); @@ -306,47 +308,40 @@ m_wheel_rotation = 0; m_wheelie_angle = 0.0f; - m_controls.lr = 0.0f; - m_controls.accel = 0.0f; - m_controls.brake = false; - m_controls.wheelie = false; - m_controls.jump = false; - m_controls.fire = false; + m_controls.lr = 0.0f; + m_controls.accel = 0.0f; + m_controls.brake = false; + m_controls.wheelie = false; + m_controls.jump = false; + m_controls.fire = false; // Set the brakes so that karts don't slide downhill for(int i=0; i<4; i++) m_vehicle->setBrake(5.0f, i); - world->m_track->findRoadSector(m_curr_pos.xyz, &m_track_sector); + m_transform = m_reset_transform; + world->m_track->findRoadSector(getXYZ(), &m_track_sector); + //If m_track_sector == UNKNOWN_SECTOR, then the kart is not on top of //the road, so we have to use another function to find the sector. if (m_track_sector == Track::UNKNOWN_SECTOR ) { m_on_road = false; m_track_sector = world->m_track->findOutOfRoadSector( - m_curr_pos.xyz, Track::RS_DONT_KNOW, Track::UNKNOWN_SECTOR ); + getXYZ(), Track::RS_DONT_KNOW, Track::UNKNOWN_SECTOR ); } else { m_on_road = true; } - world->m_track->spatialToTrack( m_curr_track_coords, m_curr_pos.xyz, - m_track_sector ); + world->m_track->spatialToTrack(m_curr_track_coords, getXYZ(), + m_track_sector ); m_vehicle->applyEngineForce (0.0f, 2); m_vehicle->applyEngineForce (0.0f, 3); - // Set heading: - m_transform.setRotation(btQuaternion(btVector3(0.0f, 0.0f, 1.0f), - DEGREE_TO_RAD(m_reset_pos.hpr[0])) ); - // Set position - m_transform.setOrigin(btVector3(m_reset_pos.xyz[0], - m_reset_pos.xyz[1], - m_reset_pos.xyz[2]+0.5f*getKartHeight())); - m_body->setCenterOfMassTransform(m_transform); - m_body->setLinearVelocity (btVector3(0.0f,0.0f,0.0f)); - m_body->setAngularVelocity(btVector3(0.0f,0.0f,0.0f)); - m_motion_state->setWorldTransform(m_transform); + + Moveable::reset(); for(int j=0; j<m_vehicle->getNumWheels(); j++) { m_vehicle->updateWheelTransform(j, true); @@ -359,15 +354,13 @@ world->getPhysics()->addKart(this, m_vehicle); } m_rescue = false; - - placeModel(); - TerrainInfo::update(getPos()); + TerrainInfo::update(getXYZ()); } // reset //----------------------------------------------------------------------------- void Kart::doLapCounting () { - bool newLap = m_last_track_coords[1] > 300.0f && m_curr_track_coords[1] < 20.0f; + bool newLap = m_last_track_coords[1] > 300.0f && m_curr_track_coords.getY() < 20.0f; if ( newLap ) { // Only increase the lap counter and set the new time if the @@ -423,7 +416,7 @@ } m_lap_start_time = world->getTime(); } - else if ( m_curr_track_coords[1] > 300.0f && m_last_track_coords[1] < 20.0f) + else if ( m_curr_track_coords.getY() > 300.0f && m_last_track_coords[1] < 20.0f) { m_race_lap-- ; // Prevent cheating by setting time to a negative number, indicating @@ -496,7 +489,7 @@ m_vehicle->getWheelInfo(3).m_raycastInfo.m_isInContact; } // isOnGround //----------------------------------------------------------------------------- -void Kart::handleExplosion(const btVector3& pos, bool direct_hit) +void Kart::handleExplosion(const Vec3& pos, bool direct_hit) { if(direct_hit) { @@ -511,7 +504,7 @@ } else // only affected by a distant explosion { - btVector3 diff=getPos()-pos; + btVector3 diff=getXYZ()-pos; //if the z component is negative, the resulting impulse could push the // kart through the floor. So in this case ignore z. if(diff.getZ()<0) diff.setZ(0.0f); @@ -548,20 +541,16 @@ { if(isPlayerKart()) sound_manager -> playSfx ( SOUND_BZZT ); m_attachment.set( ATTACH_TINYTUX, rescue_time ) ; - m_rescue_pitch = m_curr_pos.hpr[1]; - m_rescue_roll = m_curr_pos.hpr[2]; + m_rescue_pitch = getHPR().getPitch(); + m_rescue_roll = getHPR().getRoll(); world->getPhysics()->removeKart(this); } - m_curr_pos.xyz[2] += rescue_height*dt/rescue_time; - - m_transform.setOrigin(btVector3(m_curr_pos.xyz[0],m_curr_pos.xyz[1], - m_curr_pos.xyz[2])); btQuaternion q_roll (btVector3(0.f, 1.f, 0.f), -m_rescue_roll*dt/rescue_time*M_PI/180.0f); btQuaternion q_pitch(btVector3(1.f, 0.f, 0.f), -m_rescue_pitch*dt/rescue_time*M_PI/180.0f); - m_transform.setRotation(m_transform.getRotation()*q_roll*q_pitch); - m_motion_state->setWorldTransform(m_transform); + setXYZRotation(getXYZ()+Vec3(0, 0, rescue_height*dt/rescue_time), + getRotation()*q_roll*q_pitch); } // if m_rescue m_attachment.update(dt); @@ -573,12 +562,12 @@ } // user_config->smoke updatePhysics(dt); - sgCopyVec2 ( m_last_track_coords, m_curr_track_coords ); - + m_last_track_coords = m_curr_track_coords; + Moveable::update(dt); // Check if a kart is (nearly) upside down and not moving much --> automatic rescue - if((fabs(m_curr_pos.hpr[2])>60 && fabs(getSpeed())<3.0f) ) + if((fabs(getHPR().getRoll())>60 && fabs(getSpeed())<3.0f) ) { forceRescue(); } @@ -634,7 +623,7 @@ int prev_sector = m_track_sector; if(!m_rescue) - world->m_track->findRoadSector(m_curr_pos.xyz, &m_track_sector); + world->m_track->findRoadSector(getXYZ(), &m_track_sector); // Check if the kart is taking a shortcut (if it's not already doing one): if(!m_rescue && world->m_track->isShortcut(prev_sector, m_track_sector)) @@ -655,10 +644,10 @@ m_on_road = false; if( m_curr_track_coords[0] > 0.0 ) m_track_sector = world->m_track->findOutOfRoadSector( - m_curr_pos.xyz, Track::RS_RIGHT, prev_sector ); + getXYZ(), Track::RS_RIGHT, prev_sector ); else m_track_sector = world->m_track->findOutOfRoadSector( - m_curr_pos.xyz, Track::RS_LEFT, prev_sector ); + getXYZ(), Track::RS_LEFT, prev_sector ); } else { @@ -666,7 +655,7 @@ } world->m_track->spatialToTrack( m_curr_track_coords, - m_curr_pos.xyz, + getXYZ(), m_track_sector ); if(!m_finished_race) doLapCounting(); @@ -881,8 +870,10 @@ void Kart::endRescue() { if ( m_track_sector > 0 ) m_track_sector-- ; - world ->m_track -> trackToSpatial ( m_curr_pos.xyz, m_track_sector ) ; - m_curr_pos.hpr[0] = world->m_track->m_angle[m_track_sector] ; + setXYZ( world->m_track->trackToSpatial(m_track_sector) ); + btQuaternion heading(btVector3(0.0f, 0.0f, 1.0f), + DEGREE_TO_RAD(world->m_track->m_angle[m_track_sector]) ); + setRotation(heading); m_rescue = false ; m_body->setLinearVelocity (btVector3(0.0f,0.0f,0.0f)); @@ -897,8 +888,7 @@ // that the drivelines are somewhat under the track. Otherwise, the // kart will be placed a little bit under the track, triggering // a rescue, ... - pos.setOrigin(btVector3(m_curr_pos.xyz[0],m_curr_pos.xyz[1], - m_curr_pos.xyz[2]+0.5f*getKartHeight()+0.1f)); + pos.setOrigin(getXYZ()+btVector3(0, 0, 0.5f*getKartHeight()+0.1f)); pos.setRotation(btQuaternion(btVector3(0.0f, 0.0f, 1.0f), DEGREE_TO_RAD(world->m_track->m_angle[m_track_sector]))); m_body->setCenterOfMassTransform(pos); @@ -925,22 +915,22 @@ { if(isOnGround()) { - m_skidmark_left ->add(*getCoord(), ANGLE, LENGTH); - m_skidmark_right->add(*getCoord(), ANGLE, LENGTH); + //FIXME: no getCoord anymore m_skidmark_left ->add(*getCoord(), ANGLE, LENGTH); + //FIXME m_skidmark_right->add(*getCoord(), ANGLE, LENGTH); } else { // not on ground - m_skidmark_left->addBreak(*getCoord(), ANGLE, LENGTH); - m_skidmark_right->addBreak(*getCoord(), ANGLE, LENGTH); + //FIXME m_skidmark_left->addBreak(*getCoord(), ANGLE, LENGTH); + //FIRME m_skidmark_right->addBreak(*getCoord(), ANGLE, LENGTH); } // on ground } else { // !skid_rear && !skid_front - if(m_skidmark_left->wasSkidMarking()) - m_skidmark_left->addBreak(*getCoord(), ANGLE, LENGTH); + //FIXME if(m_skidmark_left->wasSkidMarking()) + //FIXME m_skidmark_left->addBreak(*getCoord(), ANGLE, LENGTH); - if(m_skidmark_right->wasSkidMarking()) - m_skidmark_right->addBreak(*getCoord(), ANGLE, LENGTH); + //FIXME if(m_skidmark_right->wasSkidMarking()) + //FIXME m_skidmark_right->addBreak(*getCoord(), ANGLE, LENGTH); } } // processSkidMarks @@ -1039,7 +1029,7 @@ } // loadData //----------------------------------------------------------------------------- -void Kart::placeModel () +void Kart::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr) { sgMat4 wheel_front; sgMat4 wheel_steer; @@ -1056,30 +1046,14 @@ if (m_wheel_rear_l) m_wheel_rear_l->setTransform(wheel_rot); if (m_wheel_rear_r) m_wheel_rear_r->setTransform(wheel_rot); - // Only transfer the bullet data to the plib tree if no history is being - // replayed. - if(!user_config->m_replay_history) - { - //float m[4][4]; - //getTrans().getOpenGLMatrix((float*)&m); - //sgSetCoord(&m_curr_pos, m); - Coord coord(getTrans()); - // Transfer the new position and hpr to m_curr_pos - sgCopyCoord(&m_curr_pos, &(coord.toSgCoord())); - } - sgCoord c ; - sgCopyCoord ( &c, &m_curr_pos ); const float CENTER_SHIFT = getGravityCenterShift(); - const float offset_pitch = m_wheelie_angle; + const float offset_pitch = DEGREE_TO_RAD(m_wheelie_angle); const float offset_z = 0.3f*fabs(sin(m_wheelie_angle*SG_DEGREES_TO_RADIANS)) - (0.5f-CENTER_SHIFT)*getKartHeight(); - m_curr_pos.xyz[2] += offset_z; - m_curr_pos.hpr[1] += offset_pitch; - Moveable::placeModel(); - m_curr_pos.xyz[2] -= offset_z; - m_curr_pos.hpr[1] -= offset_pitch; -} // placeModel + Moveable::updateGraphics(Vec3(0, 0, offset_z), Vec3(0, offset_pitch, 0)); +} // updateGraphics + //----------------------------------------------------------------------------- float Kart::estimateFinishTime () { Modified: trunk/supertuxkart/src/kart.hpp =================================================================== --- trunk/supertuxkart/src/kart.hpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/kart.hpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -62,8 +62,9 @@ KartControl m_controls; // The position of the karts controls int m_track_sector; // index in driveline, special values // e.g. UNKNOWN_SECTOR can be negative! - sgVec2 m_last_track_coords; - sgVec3 m_curr_track_coords; + btTransform m_reset_transform; // reset position + Vec3 m_curr_track_coords; + Vec3 m_last_track_coords; float m_max_speed; // maximum speed of the kart, computed from float m_max_speed_reverse_ratio; float m_wheelie_angle; @@ -114,11 +115,11 @@ void load_wheels (ssgBranch* obj); public: - Kart(const std::string& kart_name, int position_, - sgCoord init_pos); + Kart(const std::string& kart_name, int position, + const btTransform& init_transform); virtual ~Kart(); void loadData(); - void placeModel (); + virtual void updateGraphics (const Vec3& off_xyz, const Vec3& off_hpr); const KartProperties* getKartProperties () const { return m_kart_properties; } void setKartProperties (const KartProperties *kp) @@ -130,8 +131,8 @@ virtual void setPosition (int p) { m_race_position = p; } int getSector () const { return m_track_sector; } - float getDistanceDownTrack() const { return m_curr_track_coords[1]; } - float getDistanceToCenter () const { return m_curr_track_coords[0]; } + float getDistanceDownTrack() const { return m_curr_track_coords.getY(); } + float getDistanceToCenter () const { return m_curr_track_coords.getX(); } Attachment *getAttachment () { return &m_attachment; } void setAttachmentType (attachmentType t, float time_left=0.0f, Kart*k=NULL) @@ -204,7 +205,7 @@ void resetBrakes (); void adjustSpeedWeight(float f); void forceRescue (bool is_rescue=false); - void handleExplosion (const btVector3& pos, bool direct_hit); + void handleExplosion (const Vec3& pos, bool direct_hit); const std::string& getName () const {return m_kart_properties->getName();} const std::string& getIdent () const {return m_kart_properties->getIdent();} virtual int isPlayerKart () const {return 0; } Modified: trunk/supertuxkart/src/material.cpp =================================================================== --- trunk/supertuxkart/src/material.cpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/material.cpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -5,7 +5,7 @@ // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 +// as published by the Free Software Foundation; either version 3 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, Modified: trunk/supertuxkart/src/moveable.cpp =================================================================== --- trunk/supertuxkart/src/moveable.cpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/moveable.cpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -35,9 +35,6 @@ m_model_transform->ref(); - sgZeroVec3 ( m_reset_pos.xyz ) ; sgZeroVec3 ( m_reset_pos.hpr ) ; - - reset (); if(bHasHistory) { m_history_velocity = new sgCoord[history->GetSize()]; @@ -65,16 +62,21 @@ } // ~Moveable //----------------------------------------------------------------------------- +// The reset position must be set before calling reset void Moveable::reset () { m_collided = false; m_crashed = false; m_material_hot = NULL; m_normal_hot = NULL; - if(m_body) m_body->setLinearVelocity(btVector3(0.0, 0.0, 0.0)); - sgCopyCoord( &m_curr_pos, &m_reset_pos ); - m_hpr = Vec3(m_curr_pos.hpr); - m_hpr.degreeToRad(); + if(m_body) + { + m_body->setLinearVelocity(btVector3(0.0, 0.0, 0.0)); + m_body->setAngularVelocity(btVector3(0, 0, 0)); + m_body->setCenterOfMassTransform(m_transform); + } + Coord c(m_transform); + m_hpr = c.getHPR(); } // reset //----------------------------------------------------------------------------- @@ -103,18 +105,16 @@ //----------------------------------------------------------------------------- void Moveable::update (float dt) { + m_motion_state->getWorldTransform(m_transform); + m_velocityLC = getVelocity()*getTrans().getBasis(); + m_hpr.setHPR(m_transform.getBasis()); + if(m_history_velocity) { if(user_config->m_replay_history) { sgCoord tmp; sgCopyCoord(&tmp, &(m_history_velocity[history->GetCurrentIndex()])); - //printf("m_velocity=%f,%f,%f,%f,%f,%f\n", - // m_velocity.xyz[0],m_velocity.xyz[1],m_velocity.xyz[2], - // m_velocity.hpr[0],m_velocity.hpr[1],m_velocity.hpr[2]); - //printf("tmp =%f,%f,%f,%f,%f,%f\n", - // tmp.xyz[0],tmp.xyz[1],tmp.xyz[2], - // tmp.hpr[0],tmp.hpr[1],tmp.hpr[2]); #undef IGNORE_Z_IN_HISTORY #ifdef IGNORE_Z_IN_HISTORY @@ -139,42 +139,35 @@ { sgCoord tmp; sgCopyCoord(&tmp, &(m_history_position[history->GetCurrentIndex()])); - //printf("m_curr_pos=%f,%f,%f,%f,%f,%f\n", - // m_curr_pos.xyz[0],m_curr_pos.xyz[1],m_curr_pos.xyz[2], - // m_curr_pos.hpr[0],m_curr_pos.hpr[1],m_curr_pos.hpr[2]); - //printf("tmp =%f,%f,%f,%f,%f,%f --> %d\n", - // tmp.xyz[0],tmp.xyz[1],tmp.xyz[2], - // tmp.hpr[0],tmp.hpr[1],tmp.hpr[2], - // history->GetCurrentIndex()); + Vec3 hpr(tmp.hpr); + hpr.degreeToRad(); + btMatrix3x3 rotation; + rotation.setEulerZYX(hpr.getPitch(), hpr.getRoll(), hpr.getHeading()); + m_transform.setBasis(rotation); + m_transform.setOrigin(Vec3(tmp.xyz)); -#ifdef IGNORE_Z_IN_HISTORY - const float DUMMY=m_curr_pos.xyz[2]; - sgCopyCoord(&m_curr_pos, &tmp); - m_curr_pos.xyz[2]=DUMMY; -#else - sgCopyCoord(&m_curr_pos, &tmp); -#endif - } else { - sgCopyCoord(&(m_history_position[history->GetCurrentIndex()]), &m_curr_pos); + Coord c(m_transform); + sgCopyCoord(&(m_history_position[history->GetCurrentIndex()]), &c.toSgCoord()); } } // if m_history_position - m_velocityLC = getVelocity()*getTrans().getBasis(); - m_motion_state->getWorldTransform(m_transform); - m_hpr.setHPR(m_transform.getBasis()); - placeModel(); + updateGraphics(Vec3(0,0,0), Vec3(0,0,0)); m_first_time = false ; } // update //----------------------------------------------------------------------------- -void Moveable::placeModel() +void Moveable::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr) { - m_model_transform->setTransform(&m_curr_pos); -} // placeModel + Vec3 xyz=getXYZ()+off_xyz; + Vec3 hpr=getHPR()+off_hpr; + sgCoord c=Coord(xyz, hpr).toSgCoord(); + + m_model_transform->setTransform(&c); +} // updateGraphics //----------------------------------------------------------------------------- void Moveable::WriteHistory(char* s, int kartNumber, int indx) Modified: trunk/supertuxkart/src/moveable.hpp =================================================================== --- trunk/supertuxkart/src/moveable.hpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/moveable.hpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -39,8 +39,6 @@ btVector3 m_velocityLC; /* velocity in kart coordinates */ protected: UserPointer m_user_pointer; - sgCoord m_reset_pos; /* Where to start in case of a reset */ - sgCoord m_curr_pos; /* current position */ sgVec4* m_normal_hot; /* plane on which HOT was computed */ Material* m_material_hot; /* Material at HOT */ ssgTransform* m_model_transform; // The transform where the model is under @@ -64,14 +62,19 @@ virtual const btVector3 &getVelocity() const {return m_body->getLinearVelocity();} const btVector3 &getVelocityLC() const {return m_velocityLC; } virtual void setVelocity(const btVector3& v) {m_body->setLinearVelocity(v); } - sgCoord* getCoord () {return &m_curr_pos; } - const Vec3& getPos () const {return (Vec3&)m_transform.getOrigin();} - const Vec3& getRotation() const {return m_hpr; } - const sgCoord* getCoord () const {return &m_curr_pos; } - const sgVec4* getNormalHOT () const {return m_normal_hot; } - const sgCoord* getResetPos () const {return &m_reset_pos; } - void setCoord (sgCoord* pos) {sgCopyCoord ( &m_curr_pos,pos); } - virtual void placeModel (); + const Vec3& getXYZ () const {return (Vec3&)m_transform.getOrigin();} + const Vec3& getHPR () const {return m_hpr; } + const btQuaternion getRotation() const {return m_transform.getRotation(); } + void setXYZ (const Vec3& a) {m_transform.setOrigin(a); + m_motion_state->setWorldTransform(m_transform);} + void setRotation (const btQuaternion&a){m_transform.setRotation(a); + m_motion_state->setWorldTransform(m_transform);} + void setXYZRotation(const Vec3& xyz, const btQuaternion& a) + {m_transform.setRotation(a); + m_transform.setOrigin(xyz); + m_motion_state->setWorldTransform(m_transform);} + const sgVec4* getNormalHOT () const {return m_normal_hot; } + virtual void updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr); virtual void handleZipper () {}; virtual void reset (); virtual void update (float dt) ; Modified: trunk/supertuxkart/src/player_kart.cpp =================================================================== --- trunk/supertuxkart/src/player_kart.cpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/player_kart.cpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -32,7 +32,7 @@ #include "camera.hpp" PlayerKart::PlayerKart(const std::string& kart_name, int position, Player *player, - sgCoord init_pos, int player_index) : + const btTransform& init_pos, int player_index) : Kart(kart_name, position, init_pos) { m_player = player; @@ -166,7 +166,6 @@ // The call to update is necessary here (even though the kart // shouldn't actually change) to update m_transform. Otherwise // the camera gets the wrong position. - // FIXME: that might not necessary anymore once m_curr_pos is removed! Kart::update(dt); } @@ -273,7 +272,7 @@ // ------------------------------------------------------ if(race_manager->getDifficulty()==RaceManager::RD_EASY) { - float angle_diff = getCoord()->hpr[0] - world->m_track->m_angle[getSector()]; + float angle_diff = RAD_TO_DEGREE(getHPR().getHeading()) - world->m_track->m_angle[getSector()]; if(angle_diff > 180.0f) angle_diff -= 360.0f; else if (angle_diff < -180.0f) angle_diff += 360.0f; // Display a warning message if the kart is going back way (unless Modified: trunk/supertuxkart/src/player_kart.hpp =================================================================== --- trunk/supertuxkart/src/player_kart.hpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/player_kart.hpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -44,7 +44,7 @@ public: PlayerKart(const std::string& kart_name, int position, Player *_player, - sgCoord init_pos, int player_index); + const btTransform& init_pos, int player_index); int earlyStartPenalty () {return m_penalty_time>0; } Player* getPlayer () {return m_player; } Modified: trunk/supertuxkart/src/projectile_manager.cpp =================================================================== --- trunk/supertuxkart/src/projectile_manager.cpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/projectile_manager.cpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -94,7 +94,7 @@ while(p!=m_active_projectiles.end()) { if(! (*p)->hasHit()) { p++; continue; } - newExplosion((const Vec3&)(*p)->getPos()); + newExplosion((*p)->getXYZ()); Flyable *f=*p; Projectiles::iterator pNext=m_active_projectiles.erase(p); // returns the next element delete f; Modified: trunk/supertuxkart/src/robots/default_robot.cpp =================================================================== --- trunk/supertuxkart/src/robots/default_robot.cpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/robots/default_robot.cpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -43,7 +43,7 @@ #include "default_robot.hpp" DefaultRobot::DefaultRobot(const std::string& kart_name, - int position, sgCoord init_pos ) : + int position, const btTransform& init_pos ) : AutoKart( kart_name, position, init_pos ) { reset(); @@ -98,25 +98,25 @@ /*Get information that is needed by more than 1 of the handling funcs*/ //Detect if we are going to crash with the track and/or kart - int steps = 0; - - // This should not happen (anymore :) ), but it keeps the game running - // in case that m_future_sector becomes undefined. - if(m_future_sector == Track::UNKNOWN_SECTOR ) - { -#ifdef DEBUG - fprintf(stderr,"DefaultRobot: m_future_sector is undefined.\n"); - fprintf(stderr,"This shouldn't happen, but can be ignored.\n"); -#endif - forceRescue(); - m_future_sector = 0; - } - else - { - steps = calc_steps(); - } - - check_crashes( steps, m_curr_pos.xyz ); + int steps = 0; + + // This should not happen (anymore :) ), but it keeps the game running + // in case that m_future_sector becomes undefined. + if(m_future_sector == Track::UNKNOWN_SECTOR ) + { +#ifdef DEBUG + fprintf(stderr,"DefaultRobot: m_future_sector is undefined.\n"); + fprintf(stderr,"This shouldn't happen, but can be ignored.\n"); +#endif + forceRescue(); + m_future_sector = 0; + } + else + { + steps = calc_steps(); + } + + check_crashes( steps, getXYZ() ); find_curve(); /*Response handling functions*/ @@ -161,7 +161,7 @@ if ( m_crashes.m_road && m_on_road && getVelocityLC().getY() > MIN_SPEED) { float kart_ang_diff = world->m_track->m_angle[m_track_sector] - - m_curr_pos.hpr[0]; + RAD_TO_DEGREE(getHPR().getHeading()); kart_ang_diff = normalize_angle(kart_ang_diff); kart_ang_diff = fabsf(kart_ang_diff); @@ -341,7 +341,7 @@ { const float ANGLE_DIFF = fabsf( normalize_angle( world->m_track->m_angle[m_track_sector]- - m_curr_pos.hpr[0] ) ); + RAD_TO_DEGREE(getHPR().getHeading()) ) ); if( m_time_since_last_shot > 10.0f && ANGLE_DIFF < 15.0f && !m_crashes.m_road && STEPS > 8 ) @@ -356,9 +356,8 @@ case COLLECT_HOMING: if( m_time_since_last_shot > 5.0f && m_crashes.m_kart != -1 ) { - if( sgDistanceVec2( m_curr_pos.xyz, - world->getKart(m_crashes.m_kart)->getCoord()->xyz ) > - m_kart_properties->getKartLength() * 2.5f ) + if( (getXYZ()-world->getKart(m_crashes.m_kart)->getXYZ() ).length_2d() > + m_kart_properties->getKartLength() * 2.5f ) { m_controls.fire = true; m_time_since_last_shot = 0.0f; @@ -435,15 +434,15 @@ //We have to be careful with normalizing, because if the source argument //has both the X and Y axis set to 0, it returns nan to the destiny. - const btVector3 &VEL=getVelocity(); - btVector3 vel_normal(VEL.getX(), VEL.getY(), 0.0); - float len=vel_normal.length(); + const Vec3 &VEL = getVelocity(); + Vec3 vel_normal(VEL.getX(), VEL.getY(), 0.0); + float len = vel_normal.length(); // Too slow for wheelies, and it avoids normalisation problems. if(len<getMaxSpeed()*getWheelieMaxSpeedRatio()) return false; vel_normal/=len; - sgVec2 step_coord; - sgVec3 step_track_coord; + Vec3 step_coord; + Vec3 step_track_coord; float distance; //FIXME: instead of using 1.5, it should find out how much time it @@ -458,11 +457,10 @@ for( int i = WHEELIE_STEPS; i > STEPS - 1; --i ) { - sgAddScaledVec2( step_coord, m_curr_pos.xyz, vel_normal, - m_kart_properties->getKartLength() * i ); + step_coord = getXYZ()+vel_normal* m_kart_properties->getKartLength() * i ; - world->m_track->spatialToTrack( step_track_coord, step_coord, - m_future_sector ); + world->m_track->spatialToTrack(step_track_coord, step_coord, + m_future_sector ); distance = step_track_coord[0] > 0.0f ? step_track_coord[0] : -step_track_coord[0]; @@ -533,7 +531,7 @@ float angle = world->m_track->m_angle[SECTOR]; //Desired angle minus current angle equals how many angles to turn - float steer_angle = angle - m_curr_pos.hpr[0]; + float steer_angle = angle - RAD_TO_DEGREE(getHPR().getHeading()); steer_angle += ANGLE; steer_angle = normalize_angle( steer_angle ); @@ -545,8 +543,8 @@ //----------------------------------------------------------------------------- float DefaultRobot::steer_to_point( const sgVec2 POINT ) { - const SGfloat ADJACENT_LINE = POINT[0] - m_curr_pos.xyz[0]; - const SGfloat OPPOSITE_LINE = POINT[1] - m_curr_pos.xyz[1]; + const SGfloat ADJACENT_LINE = POINT[0] - getXYZ().getX(); + const SGfloat OPPOSITE_LINE = POINT[1] - getXYZ().getY(); SGfloat theta; //Protection from division by zero @@ -559,14 +557,14 @@ //The real value depends on the side of the track that the kart is theta += ADJACENT_LINE < 0.0f ? 90.0f : -90.0f; - float steer_angle = theta - getCoord()->hpr[0]; + float steer_angle = theta - RAD_TO_DEGREE(getHPR().getHeading()); steer_angle = normalize_angle( steer_angle ); return steer_angle; } //----------------------------------------------------------------------------- -void DefaultRobot::check_crashes( const int STEPS, sgVec3 const pos ) +void DefaultRobot::check_crashes( const int STEPS, const Vec3& pos ) { //Right now there are 2 kind of 'crashes': with other karts and another //with the track. The sight line is used to find if the karts crash with @@ -574,21 +572,21 @@ //having karts too close in any direction. The crash with the track can //tell when a kart is going to get out of the track so it steers. - btVector3 vel_normal; + Vec3 vel_normal; //in this func we use it as a 2d-vector, but later on it is passed //to world->m_track->findRoadSector, there it is used as a 3d-vector //to find distance to plane, so z must be initialized to zero - sgVec3 step_coord; + Vec3 step_coord; SGfloat kart_distance; - step_coord[2] = 0.0; + step_coord.setZ(0.0); m_crashes.clear(); const size_t NUM_KARTS = race_manager->getNumKarts(); //Protection against having vel_normal with nan values - const btVector3 &VEL = getVelocity(); + const Vec3 &VEL = getVelocity(); vel_normal.setValue(VEL.getX(), VEL.getY(), 0.0); float len=vel_normal.length(); if(len>0.0f) @@ -602,7 +600,7 @@ for(int i = 1; STEPS > i; ++i) { - sgAddScaledVec3( step_coord, pos, vel_normal, m_kart_properties->getKartLength() * i ); + step_coord = pos + vel_normal* m_kart_properties->getKartLength() * i; /* Find if we crash with any kart, as long as we haven't found one * yet @@ -614,8 +612,7 @@ const Kart* kart=world->getKart(j); if(kart==this||kart->isEliminated()) continue; // ignore eliminated karts - kart_distance = sgDistanceVec2( step_coord, - world->getKart(j)->getCoord()->xyz ); + kart_distance = (step_coord-world->getKart(j)->getXYZ()).length_2d(); if( kart_distance < m_kart_properties->getKartLength() + 0.125f * i ) if( getVelocityLC().getY() > world->getKart(j)-> @@ -694,8 +691,8 @@ m_track_sector + 1 : 0; int target_sector; - sgVec2 direction; - sgVec3 step_track_coord; + Vec3 direction; + Vec3 step_track_coord; SGfloat distance; int steps; @@ -707,24 +704,22 @@ target_sector = sector + 1 < DRIVELINE_SIZE ? sector + 1 : 0; //direction is a vector from our kart to the sectors we are testing - sgSubVec2( direction, world->m_track->m_driveline[target_sector], - m_curr_pos.xyz ); + direction = world->m_track->m_driveline[target_sector] - getXYZ(); - float len=sgLengthVec2(direction); + float len=direction.length_2d(); steps = int( len / m_kart_properties->getKartLength() ); if( steps < 3 ) steps = 3; //Protection against having vel_normal with nan values if(len>0.0f) { - sgScaleVec2(direction, 1.0f/len); + direction*= 1.0f/len; } - sgVec2 step_coord; + Vec3 step_coord; //Test if we crash if we drive towards the target sector for( int i = 2; i < steps; ++i ) { - sgAddScaledVec2( step_coord, m_curr_pos.xyz, direction, - m_kart_properties->getKartLength() * i ); + step_coord = getXYZ()+direction*m_kart_properties->getKartLength() * i ; world->m_track->spatialToTrack( step_track_coord, step_coord, sector ); Modified: trunk/supertuxkart/src/robots/default_robot.hpp =================================================================== --- trunk/supertuxkart/src/robots/default_robot.hpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/robots/default_robot.hpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -115,7 +115,7 @@ float steer_to_point(const sgVec2 POINT); bool do_wheelie(const int STEPS); - void check_crashes(const int STEPS, sgVec3 const pos); + void check_crashes(const int STEPS, const Vec3& pos); void find_non_crashing_point(sgVec2 result); float normalize_angle (float angle); @@ -128,11 +128,10 @@ public: DefaultRobot(const std::string& kart_name, int position, - sgCoord init_pos); + const btTransform& init_pos); void update (float delta) ; void reset (); - int isPlayerKart() const {return 0;} }; #endif Modified: trunk/supertuxkart/src/scene.cpp =================================================================== --- trunk/supertuxkart/src/scene.cpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/scene.cpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -177,10 +177,9 @@ float f=2.0f; glFrustum(-f, f, -f, f, 1.0, 1000.0); - btVector3 pos; - sgCoord *c = world->getKart(race_manager->getNumKarts()-1)->getCoord(); - gluLookAt(c->xyz[0], c->xyz[1]-5.f, c->xyz[2]+4, - c->xyz[0], c->xyz[1], c->xyz[2], + Vec3 xyz = world->getKart(race_manager->getNumKarts()-1)->getXYZ(); + gluLookAt(xyz.getX(), xyz.getY()-5.f, xyz.getZ()+4, + xyz.getX(), xyz.getY(), xyz.getZ(), 0.0f, 0.0f, 1.0f); glMatrixMode(GL_MODELVIEW); Modified: trunk/supertuxkart/src/track.cpp =================================================================== --- trunk/supertuxkart/src/track.cpp 2008-06-20 01:16:53 UTC (rev 2131) +++ trunk/supertuxkart/src/track.cpp 2008-06-20 09:34:35 UTC (rev 2132) @@ -90,10 +90,10 @@ //----------------------------------------------------------------------------- /** Finds on which side of the line segment a given point is. */ -inline float Track::pointSideToLine( const sgVec2 L1, const sgVec2 L2, - const sgVec2 P ) const +inline float Track::pointSideToLine( const Vec3& L1, const Vec3& L2, + const Vec3& P ) const { - return ( L2[0]-L1[0] )*( P[1]-L1[1] )-( L2[1]-L1[1] )*( P[0]-L1[0] ); + return ( L2.getX()-L1.getX() )*( P.getY()-L1.getY() )-( L2.getY()-L1.getY() )*( P.getX()-L1.getX() ); } // pointSideToLine //----------------------------------------------------------------------------- @@ -107,11 +107,11 @@ */ int Track::pointInQuad ( - const sgVec2 A, - const sgVec2 B, - const sgVec2 C, - const sgVec2 D, - const sgVec2 POINT + const Vec3& A, + const Vec3& B, + const Vec3& C, + const Vec3& D, + const Vec3& POINT ) const { if(pointSideToLine( C, A, POINT ) >= 0.0 ) @@ -139,7 +139,7 @@ * The 'sector' could be defined as the number of the closest track * segment to XYZ. */ -void Track::findRoadSector( const sgVec3 XYZ, int *sector )const +void Track::findRoadSector(const Vec3& XYZ, int *sector )const { if(*sector!=UNKNOWN_SECTOR) { @@ -166,7 +166,7 @@ m_right_driveline[next], m_left_driveline[next], XYZ ); - if (triangle != QUAD_TRI_NONE && ((XYZ[2]-m_left_driveline[i][2]) < 1.0f)) + if (triangle != QUAD_TRI_NONE && ((XYZ.getZ()-m_left_driveline[i].getZ()) < 1.0f)) { possible_segment_tris.push_back(SegmentTriangle((int)i, triangle)); } @@ -201,16 +201,18 @@ if( possible_segment_tris[i].triangle == QUAD_TRI_FIRST ) { - sgMakePlane( plane, m_left_driveline[segment], - m_right_driveline[segment], m_right_driveline[next] ); + sgMakePlane( plane, m_left_driveline[segment].toFloat(), + m_right_driveline[segment].toFloat(), + m_right_driveline[next].toFloat() ); } else //possible_segment_tris[i].triangle == QUAD_TRI_SECOND { - sgMakePlane( plane, m_right_driveline[next], - m_left_driveline[next], m_left_driveline[segment] ); + sgMakePlane( plane, m_right_driveline[next].toFloat(), + m_left_driveline[next].toFloat(), + m_left_driveline[segment].toFloat() ); } - dist = sgHeightAbovePlaneVec3( plane, XYZ ); + dist = sgHeightAbovePlaneVec3( plane, XYZ.toFloat() ); /* sgHeightAbovePlaneVec3 gives a negative dist if the plane is on top, so we have to rule it out. @@ -264,7 +266,7 @@ */ int Track::findOutOfRoadSector ( - const sgVec3 XYZ, + const Vec3& XYZ, const RoadSide SIDE, const int CURR_SECTOR ) const @@ -309,10 +311,10 @@ if( SIDE != RS_RIGHT) { - sgCopyVec3( line_seg.a, m_left_driveline[i] ); - sgCopyVec3( line_seg.b, m_left_driveline[next_sector] ); + sgCopyVec3( line_seg.a, m_left_driveline[i].toFloat() ); + sgCopyVec3( line_seg.b, m_left_driveline[next_sector].toFloat() ); - dist = sgDistSquaredToLineSegmentVec3( line_seg, XYZ ); + dist = sgDistSquaredToLineSegmentVec3( line_seg, XYZ.toFloat() ); if ( dist < nearest_dist ) { @@ -323,10 +325,10 @@ if( SIDE != RS_LEFT ) { - sgCopyVec3( line_seg.a, m_right_driveline[i] ); - sgCopyVec3( line_seg.b, m_right_driveline[next_sector] ); + sgCopyVec3( line_seg.a, m_right_driveline[i].toFloat() ); + sgCopyVec3( line_seg.b, m_right_driveline[next_sector].toFloat() ); - dist = sgDistSquaredToLineSegmentVec3( line_seg, XYZ ); + dist = sgDistSquaredToLineSegmentVec3( line_seg, XYZ.toFloat() ); if ( dist < nearest_dist ) { @@ -355,8 +357,8 @@ */ int Track::spatial... [truncated message content] |