From e993add76d124414028e98857127206609128670 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Tue, 29 Apr 2008 03:29:28 +0000 Subject: [PATCH] 1) Made some of the upright constraint parameter configureable. 2) Made some camera parameters configureable. 3) Some code cleanup for karts. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1772 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/camera.cpp | 24 +++++++++--------- src/camera.hpp | 13 +++++----- src/kart.cpp | 56 +++++++++++++---------------------------- src/kart.hpp | 6 ++--- src/kart_properties.cpp | 38 +++++++++++++++++++++++----- src/kart_properties.hpp | 37 +++++++++++++++++++-------- src/physics.cpp | 6 ++--- src/stk_config.cpp | 26 ++++++++++++------- 8 files changed, 118 insertions(+), 88 deletions(-) diff --git a/src/camera.cpp b/src/camera.cpp index 60ef1ceab..1d1dc726f 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -76,7 +76,7 @@ void Camera::setScreenPosition ( int numPlayers, int pos ) break; } } - m_LastPitch = 0.0f; + m_last_pitch = 0.0f; } // setScreenPosition //----------------------------------------------------------------------------- @@ -103,8 +103,8 @@ Camera::Camera(int numPlayers, int which) //----------------------------------------------------------------------------- void Camera::setMode(Mode mode) { - m_mode = mode; - m_LastPitch = 0.0f; + m_mode = mode; + m_last_pitch = 0.0f; if(m_mode==CM_LEADER_MODE) setReverseHeading(true); } // setMode @@ -121,7 +121,7 @@ void Camera::setReverseHeading(bool b) */ void Camera::reset() { - m_LastPitch = 0.0f; + m_last_pitch = 0.0f; } // reset //----------------------------------------------------------------------------- @@ -155,15 +155,15 @@ void Camera::update (float dt) // If the terrain pitch is 'significantly' different from the camera angle, // start adjusting the camera. This helps with steep declines, where // otherwise the track is not visible anymore. - if(fabsf(kartcoord.hpr[1]-m_LastPitch)>1.0f) { - kartcoord.hpr[1] = m_LastPitch + (kartcoord.hpr[1]-m_LastPitch)*2.0f*dt; + if(fabsf(kartcoord.hpr[1]-m_last_pitch)>1.0f) { + kartcoord.hpr[1] = m_last_pitch + (kartcoord.hpr[1]-m_last_pitch)*2.0f*dt; } else { - kartcoord.hpr[1]=m_LastPitch; + kartcoord.hpr[1]=m_last_pitch; } } // dt>0.0 - m_LastPitch = kartcoord.hpr[1]; + m_last_pitch = kartcoord.hpr[1]; } // m_mode!=CM_LEADER_MODE if (m_mode == CM_SIMPLE_REPLAY) @@ -183,7 +183,8 @@ void Camera::update (float dt) if (m_mode == CM_CLOSEUP) sgMakeTransMat4(cam_pos, 0.f, -2.5f, 1.5f); else - sgMakeTransMat4(cam_pos, 0.f, -3.5f, 1.5f); + sgMakeTransMat4(cam_pos, 0.f, + -kart->getKartProperties()->getCameraDistance(), 1.5f); if (m_reverse) { @@ -221,10 +222,9 @@ void Camera::update (float dt) sgMat4 result; sgMultMat4(result, tokart, relative); - sgCoord cam; - sgSetCoord(&cam, result); + sgSetCoord(&m_current_pos, result); - m_context -> setCamera (&cam) ; + m_context -> setCamera (&m_current_pos) ; } // update //----------------------------------------------------------------------------- diff --git a/src/camera.hpp b/src/camera.hpp index 231a82d82..8ea5964f5 100644 --- a/src/camera.hpp +++ b/src/camera.hpp @@ -37,12 +37,13 @@ public: }; protected: ssgContext *m_context ; - - int m_which_kart; - Mode m_mode; - float m_last_steer_offset; - float m_x, m_y, m_w, m_h ; - float m_LastPitch; + sgCoord m_current_pos; + int m_which_kart; + Mode m_mode; + float m_last_steer_offset; + float m_x, m_y, m_w, m_h; + float m_current_speed; // current speed of camera + float m_last_pitch; bool m_reverse; diff --git a/src/kart.cpp b/src/kart.cpp index 873c764ba..356a1e129 100644 --- a/src/kart.cpp +++ b/src/kart.cpp @@ -102,41 +102,21 @@ void Kart::createPhysics(ssgEntity *obj) { // First: Create the chassis of the kart // ------------------------------------- - // The size for bullet must be specified in half extends! - // ssgEntity *model = getModel(); - float x_min, x_max, y_min, y_max, z_min, z_max; - MinMax(obj, &x_min, &x_max, &y_min, &y_max, &z_min, &z_max); - if(getName()=="Hexley" || getName()=="Wilber") - { - // These kart models are too small, so we get problems with stability. - // Till we find either better (bigger) models or improve their physics - // parameters to become playable, we just adjust the size of their - // physical models to be the same as the tuxkart model - x_min=-0.473799f; - x_max= 0.486361f; - y_min=-0.772244f; - y_max= 0.739075f; - z_min= 0.002806f; - z_max= 0.701095f; - } - float kart_width = x_max-x_min; - m_kart_length = y_max-y_min; - if(m_kart_length<1.2) m_kart_length=1.5f; - // The kart height is needed later to reset the physics to the correct - // position. - m_kart_height = z_max-z_min; + float kart_width = m_kart_properties->getKartWidth(); + float kart_length = m_kart_properties->getKartLength(); + float kart_height = m_kart_properties->getKartHeight(); btBoxShape *shape = new btBoxShape(btVector3(0.5f*kart_width, - 0.5f*m_kart_length, - 0.5f*m_kart_height)); + 0.5f*kart_length, + 0.5f*kart_height)); btTransform shiftCenterOfGravity; shiftCenterOfGravity.setIdentity(); // Shift center of gravity downwards, so that the kart // won't topple over too easy. This must be between 0 and 0.5 // (it's in units of kart_height) const float CENTER_SHIFT = getGravityCenterShift(); - shiftCenterOfGravity.setOrigin(btVector3(0.0f,0.0f,CENTER_SHIFT*m_kart_height)); + shiftCenterOfGravity.setOrigin(btVector3(0.0f,0.0f,CENTER_SHIFT*kart_height)); m_kart_chassis.addChildShape(shiftCenterOfGravity, shape); @@ -174,13 +154,13 @@ void Kart::createPhysics(ssgEntity *obj) float wheel_width = m_kart_properties->getWheelWidth(); float wheel_radius = m_kart_properties->getWheelRadius(); float suspension_rest = m_kart_properties->getSuspensionRest(); - float connection_height = -(0.5f-CENTER_SHIFT)*m_kart_height; + float connection_height = -(0.5f-CENTER_SHIFT)*kart_height; btVector3 wheel_direction(0.0f, 0.0f, -1.0f); btVector3 wheel_axle(1.0f,0.0f,0.0f); // right front wheel btVector3 wheel_coord(0.5f*kart_width-0.3f*wheel_width, - 0.5f*m_kart_length-wheel_radius, + 0.5f*kart_length-wheel_radius, connection_height); m_vehicle->addWheel(wheel_coord, wheel_direction, wheel_axle, suspension_rest, wheel_radius, *m_tuning, @@ -188,7 +168,7 @@ void Kart::createPhysics(ssgEntity *obj) // left front wheel wheel_coord = btVector3(-0.5f*kart_width+0.3f*wheel_width, - 0.5f*m_kart_length-wheel_radius, + 0.5f*kart_length-wheel_radius, connection_height); m_vehicle->addWheel(wheel_coord, wheel_direction, wheel_axle, suspension_rest, wheel_radius, *m_tuning, @@ -196,7 +176,7 @@ void Kart::createPhysics(ssgEntity *obj) // right rear wheel wheel_coord = btVector3(0.5f*kart_width-0.3f*wheel_width, - -0.5f*m_kart_length+wheel_radius, + -0.5f*kart_length+wheel_radius, connection_height); m_vehicle->addWheel(wheel_coord, wheel_direction, wheel_axle, suspension_rest, wheel_radius, *m_tuning, @@ -204,7 +184,7 @@ void Kart::createPhysics(ssgEntity *obj) // right rear wheel wheel_coord = btVector3(-0.5f*kart_width+0.3f*wheel_width, - -0.5f*m_kart_length+wheel_radius, + -0.5f*kart_length+wheel_radius, connection_height); m_vehicle->addWheel(wheel_coord, wheel_direction, wheel_axle, suspension_rest, wheel_radius, *m_tuning, @@ -223,9 +203,9 @@ void Kart::createPhysics(ssgEntity *obj) btTransform *t=new btTransform(); t->setIdentity(); m_uprightConstraint=new btUprightConstraint(*m_body, *t); - m_uprightConstraint->setLimit(M_PI/8.0f); + m_uprightConstraint->setLimit(m_kart_properties->getUprightTolerance()); m_uprightConstraint->setBounce(0.0f); - m_uprightConstraint->setMaxLimitForce(300.0f); + m_uprightConstraint->setMaxLimitForce(m_kart_properties->getUprightMaxForce()); m_uprightConstraint->setErp(1.0f); m_uprightConstraint->setLimitSoftness(1.0f); m_uprightConstraint->setDamping(0.0f); @@ -360,7 +340,7 @@ void Kart::reset() // Set position m_transform.setOrigin(btVector3(m_reset_pos.xyz[0], m_reset_pos.xyz[1], - m_reset_pos.xyz[2]+0.5f*m_kart_height)); + 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)); @@ -732,7 +712,7 @@ float Kart::handleWheelie(float dt) { // Disable the upright constraint, since it will otherwise // work against the wheelie - m_uprightConstraint->setLimit(2.0f*M_PI); + m_uprightConstraint->setLimit(m_kart_properties->getUprightTolerance()); if ( m_wheelie_angle < getWheelieMaxPitch() ) m_wheelie_angle += getWheeliePitchRate() * dt; @@ -746,7 +726,7 @@ float Kart::handleWheelie(float dt) } if(m_wheelie_angle <=0.0f) { - m_uprightConstraint->setLimit(M_PI/8.0f); + m_uprightConstraint->setLimit(m_kart_properties->getUprightTolerance()); return 0.0f; } @@ -909,7 +889,7 @@ void Kart::endRescue() // 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*m_kart_height+0.1f)); + m_curr_pos.xyz[2]+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); @@ -1084,7 +1064,7 @@ void Kart::placeModel () // c.hpr[1] += m_wheelie_angle ; // c.xyz[2] += 0.3f*fabs(sin(m_wheelie_angle*SG_DEGREES_TO_RADIANS)); const float CENTER_SHIFT = getGravityCenterShift(); - c.xyz[2] -= (0.5f-CENTER_SHIFT)*m_kart_height; // adjust for center of gravity + c.xyz[2] -= (0.5f-CENTER_SHIFT)*getKartHeight(); // adjust for center of gravity m_model_transform->setTransform(&c); Moveable::placeModel(); diff --git a/src/kart.hpp b/src/kart.hpp index bb701dca1..dc1316668 100644 --- a/src/kart.hpp +++ b/src/kart.hpp @@ -69,7 +69,6 @@ protected: float m_wheelie_angle; float m_zipper_time_left; // zipper time left float m_lap_start_time; // Time at start of a new lap - float m_kart_length; // length of kart char m_fastest_lap_message[255]; int m_shortcut_sector; // segment on which the shortcut was started @@ -80,7 +79,6 @@ protected: btVehicleRaycaster *m_vehicle_raycaster; btRaycastVehicle *m_vehicle; btUprightConstraint *m_uprightConstraint; - float m_kart_height; private: int m_num_herrings_gobbled; @@ -187,9 +185,9 @@ public: float getMaxSpeed () const {return m_max_speed; } void setTimeAtLap (float t){m_time_at_last_lap=t; } float getTimeAtLap () const {return m_time_at_last_lap; } - float getKartLength () const {return m_kart_length; } void createPhysics (ssgEntity *obj); - float getKartHeight () const {return m_kart_height; } + float getKartLength () const {return m_kart_properties->getKartLength();} + float getKartHeight () const {return m_kart_properties->getKartHeight();} float getWheelieAngle () const {return m_wheelie_angle; } btRaycastVehicle *getVehicle () const {return m_vehicle; } btUprightConstraint *getUprightConstraint() const {return m_uprightConstraint;} diff --git a/src/kart_properties.cpp b/src/kart_properties.cpp index d704b7981..58231c303 100644 --- a/src/kart_properties.cpp +++ b/src/kart_properties.cpp @@ -95,16 +95,31 @@ void KartProperties::load(const std::string filename, const std::string node, m_model = loader->load(m_model_file, CB_KART, false); if(!m_model) { - fprintf(stderr, "Can't find kart model '%s'.\n",m_model_file.c_str()); - file_manager->popTextureSearchPath(); - file_manager->popModelSearchPath(); + fprintf(stderr, "Can't find kart model '%s'.\n",m_model_file.c_str()); + file_manager->popTextureSearchPath(); + file_manager->popModelSearchPath(); return; } ssgStripify(m_model); float x_min, x_max, y_min, y_max, z_min, z_max; MinMax(m_model, &x_min, &x_max, &y_min, &y_max, &z_min, &z_max); - m_kart_width = x_max-x_min; - m_kart_length = y_max-y_min; + if(getName()=="Hexley" || getName()=="Wilber") + { + // These kart models are too small, so we get problems with stability. + // Till we find either better (bigger) models or improve their physics + // parameters to become playable, we just adjust the size of their + // physical models to be the same as the tuxkart model + x_min=-0.473799f; + x_max= 0.486361f; + y_min=-0.772244f; + y_max= 0.739075f; + z_min= 0.002806f; + z_max= 0.701095f; + } + m_kart_width = x_max - x_min; + m_kart_length = y_max - y_min; + m_kart_height = z_max - z_min; + if(m_kart_length<1.2) m_kart_length=1.5f; m_model->ref(); } // if if(!dont_load_materials) @@ -164,6 +179,8 @@ void KartProperties::getAllData(const lisp::Lisp* lisp) lisp->get("gravity-center-shift", m_gravity_center_shift ); lisp->get("suspension-rest", m_suspension_rest ); lisp->get("jump-velocity", m_jump_velocity ); + lisp->get("upright-tolerance", m_upright_tolerance ); + lisp->get("upright-max-force", m_upright_max_force ); // getVector appends to existing vectors, so a new one must be used to load std::vector temp; lisp->getVector("gear-switch-ratio", temp); @@ -171,6 +188,11 @@ void KartProperties::getAllData(const lisp::Lisp* lisp) temp.clear(); lisp->getVector("gear-power-increase", temp); if(temp.size()>0) m_gear_power_increase = temp; + + // Camera + lisp->get("camera-max-accel", m_camera_max_accel); + lisp->get("camera-max-brake", m_camera_max_brake); + lisp->get("camera-distance", m_camera_distance ); } // getAllData @@ -222,7 +244,11 @@ void KartProperties::init_defaults() m_jump_velocity = stk_config->m_jump_velocity; m_gear_switch_ratio = stk_config->m_gear_switch_ratio; m_gear_power_increase = stk_config->m_gear_power_increase; - + m_upright_tolerance = stk_config->getUprightTolerance(); + m_upright_max_force = stk_config->getUprightMaxForce(); + m_camera_max_accel = stk_config->getCameraMaxAccel(); + m_camera_max_brake = stk_config->getCameraMaxBrake(); + m_camera_distance = stk_config->getCameraDistance(); } // init_defaults /* EOF */ diff --git a/src/kart_properties.hpp b/src/kart_properties.hpp index 6ea95c29a..45360c26d 100644 --- a/src/kart_properties.hpp +++ b/src/kart_properties.hpp @@ -36,22 +36,23 @@ private: ssgEntity* m_model; protected: - /* Display and gui */ - /* --------------- */ + // Display and gui + // --------------- std::string m_name; // The human readable Name of the karts driver std::string m_ident; // The computer readable-name of the karts driver std::string m_model_file; // Filename of 3d model that is used for kart std::string m_icon_file; // Filename of icon that represents the kart in - // the statusbar and the character select screen + // the statusbar and the character select screen std::string m_shadow_file; // Filename of the image file that contains the - // shadow for this kart + // shadow for this kart float m_color[3]; // Color the represents the kart in the status - // bar and on the track-view + // bar and on the track-view - /* Physic properties */ - /* ----------------- */ + // Physic properties + // ----------------- float m_kart_width; // width of kart float m_kart_length; // length of kart + float m_kart_height; // height of kart float m_mass; // weight of kart float m_wheel_base; // distance between front and read wheels float m_height_cog; // height of center of gravity @@ -69,7 +70,8 @@ protected: float m_wheelie_step; float m_wheelie_power_boost; // increase in engine power - //bullet physics data + // bullet physics data + // ------------------- float m_suspension_stiffness; float m_wheel_damping_relaxation; float m_wheel_damping_compression; @@ -84,6 +86,15 @@ protected: float m_gravity_center_shift; float m_suspension_rest; float m_jump_velocity; // z velocity set when jumping + float m_upright_tolerance; + float m_upright_max_force; + + // Camera related setting + // ---------------------- + float m_camera_max_accel; // maximum acceleration of camera + float m_camera_max_brake; // maximum braking of camera + float m_camera_distance; // distance of normal camera from kart + // // The following two vectors define at what ratio of the maximum speed what // gear is selected, e.g. 0.25 means: if speed <=0.25*maxSpeed --> gear 1, // 0.5 means: if speed <=0.5 *maxSpeed --> gear 2 @@ -112,6 +123,9 @@ public: const char* getIconFile () const {return m_icon_file.c_str(); } const sgVec3* getColor () const {return &m_color; } float getMass () const {return m_mass; } + float getKartLength () const {return m_kart_length; } + float getKartWidth () const {return m_kart_width; } + float getKartHeight () const {return m_kart_height; } float getMaxPower () const {return m_engine_power; } float getTimeFullSteer () const {return m_time_full_steer; } float getBrakeFactor () const {return m_brake_factor; } @@ -128,8 +142,6 @@ public: float getWheelieBalanceRecovery()const{return m_wheelie_balance_recovery;} float getWheelieStep () const {return m_wheelie_step; } float getWheeliePowerBoost () const {return m_wheelie_power_boost; } - float getKartLength () const {return m_kart_length; } - float getKartWidth () const {return m_kart_width; } //bullet physics get functions float getSuspensionStiffness () const {return m_suspension_stiffness; } @@ -145,10 +157,15 @@ public: float getGravityCenterShift () const {return m_gravity_center_shift; } float getSuspensionRest () const {return m_suspension_rest; } float getJumpVelocity () const {return m_jump_velocity; } + float getUprightTolerance () const {return m_upright_tolerance; } + float getUprightMaxForce () const {return m_upright_max_force; } const std::vector& getGearSwitchRatio () const {return m_gear_switch_ratio; } const std::vector& getGearPowerIncrease () const {return m_gear_power_increase; } + float getCameraMaxAccel () const {return m_camera_max_accel; } + float getCameraMaxBrake () const {return m_camera_max_brake; } + float getCameraDistance () const {return m_camera_distance; } }; #endif diff --git a/src/physics.cpp b/src/physics.cpp index 2d9ef1b67..85b66bb66 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -202,10 +202,10 @@ btScalar Physics::solveGroup(btCollisionObject** bodies, int numBodies, UserPointer *upA = (UserPointer*)(objA->getUserPointer()); UserPointer *upB = (UserPointer*)(objB->getUserPointer()); - // FIXME: Must be a moving physics object - // FIXME: A rocket should explode here! + // FIXME: Must be a moving physics object + // FIXME: A rocket should explode here! - if(!upA || !upB) continue; + if(!upA || !upB) continue; // 1) object A is a track // ======================= if(upA->is(UserPointer::UP_TRACK)) diff --git a/src/stk_config.cpp b/src/stk_config.cpp index 36f514c67..5a176c8a3 100644 --- a/src/stk_config.cpp +++ b/src/stk_config.cpp @@ -32,8 +32,8 @@ void STKConfig::load(const std::string filename) /*dont_load_models */ true, /*dont_load_materials*/ true ); - // Check that all necessary values are indeed set physics.data file - + // Check that all necessary values are indeed set + // ----------------------------------------------- #define CHECK_NEG( a,strA) if(a<-99) { \ fprintf(stderr,"Missing default value for '%s' in '%s'.\n", \ @@ -120,6 +120,11 @@ void STKConfig::load(const std::string filename) CHECK_NEG(m_jump_velocity, "jump-velocity" ); CHECK_NEG(m_explosion_impulse, "explosion-impulse" ); CHECK_NEG(m_explosion_impulse_objects, "explosion-impulse-objects" ); + CHECK_NEG(m_upright_tolerance, "upright-tolerance" ); + CHECK_NEG(m_upright_max_force, "upright-max-force" ); + CHECK_NEG(m_camera_max_accel, "camera-max-accel" ); + CHECK_NEG(m_camera_max_brake, "camera-max-brake" ); + CHECK_NEG(m_camera_distance, "camera-distance" ); } // load @@ -135,19 +140,22 @@ void STKConfig::init_defaults() m_parachute_time = m_parachute_done_fraction = m_parachute_time_other = m_engine_power = m_jump_impulse = m_brake_factor = m_anvil_speed_factor = m_time_full_steer = m_wheelie_max_pitch = - m_wheelie_max_speed_ratio = m_wheelie_pitch_rate = m_wheelie_restore_rate = - m_wheelie_speed_boost = + m_wheelie_max_speed_ratio = m_wheelie_pitch_rate = + m_wheelie_restore_rate = m_wheelie_speed_boost = m_bomb_time = m_bomb_time_increase= m_anvil_time = m_zipper_time = m_zipper_force = m_zipper_speed_gain = m_shortcut_segments = //bullet physics data - m_suspension_stiffness = m_wheel_damping_relaxation = m_wheel_damping_compression = - m_friction_slip = m_roll_influence = m_wheel_radius = m_wheel_width = - m_wheelie_lean_recovery = m_wheelie_step = m_wheelie_balance_recovery = - m_wheelie_power_boost = m_chassis_linear_damping = m_chassis_angular_damping = + m_suspension_stiffness = m_wheel_damping_relaxation = + m_wheel_damping_compression = m_friction_slip = m_roll_influence = + m_wheel_radius = m_wheel_width = m_wheelie_lean_recovery = + m_wheelie_step = m_wheelie_balance_recovery =m_wheelie_power_boost = + m_chassis_linear_damping = m_chassis_angular_damping = m_maximum_speed = m_gravity_center_shift = m_suspension_rest = m_max_speed_reverse_ratio = m_explosion_impulse = m_jump_velocity = - m_explosion_impulse_objects = -99.9f; + m_explosion_impulse_objects = m_upright_tolerance = m_upright_max_force = + // Camera + m_camera_max_accel = m_camera_max_brake = m_camera_distance = -99.9f; m_max_karts = -100; m_grid_order = -100;