Fixed incorrect heading and pitch in vec3, fixed rescue (again),
fixed checklines, improved camera (still not fully working), fixed incorrect 'wrong heading' messages. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/switch_coordinate_system@4844 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -212,6 +212,10 @@ void Camera::setInitialTransform()
|
||||
void Camera::smoothMoveCamera(float dt, const Vec3 &wanted_position,
|
||||
const Vec3 &wanted_target)
|
||||
{
|
||||
//FIXME: m_camera->setPosition(wanted_position.toIrrVector());
|
||||
//m_camera->setTarget(wanted_target.toIrrVector());
|
||||
//return;
|
||||
|
||||
// Smoothly interpolate towards the position and target
|
||||
core::vector3df current_position = m_camera->getPosition();
|
||||
core::vector3df current_target = m_camera->getTarget();
|
||||
@@ -252,9 +256,9 @@ void Camera::computeNormalCameraPosition(Vec3 *wanted_position,
|
||||
// towards where the kart is turning (and turning even more while skidding).
|
||||
float steering = m_kart->getSteerPercent() * (1.0f + (m_kart->getSkidding() - 1.0f)/2.3f ); // dampen skidding effect
|
||||
float dampened_steer = fabsf(steering) * steering; // quadratically to dampen small variations (but keep sign)
|
||||
float angle_around = m_kart->getHPR().getHeading() + m_rotation_range * dampened_steer * 0.5f;
|
||||
float angle_up = m_kart->getHPR().getPitch() - 30.0f*DEGREE_TO_RAD;
|
||||
wanted_position->setX( sin(angle_around));
|
||||
float angle_around = m_kart->getHeading() + m_rotation_range * dampened_steer * 0.5f;
|
||||
float angle_up = m_kart->getHPR().getPitch() - DEGREE_TO_RAD * 30;
|
||||
wanted_position->setX(-sin(angle_around));
|
||||
wanted_position->setY(-sin(angle_up) );
|
||||
wanted_position->setZ(-cos(angle_around));
|
||||
*wanted_position *= m_distance;
|
||||
@@ -269,11 +273,6 @@ void Camera::update(float dt)
|
||||
{
|
||||
Vec3 wanted_position;
|
||||
Vec3 wanted_target = m_kart->getXYZ();
|
||||
Vec3 rotated_forw=m_kart->getTrans().getBasis()*Vec3(0,0,1);
|
||||
float heading=atan2f(-rotated_forw.getX(), rotated_forw.getZ());
|
||||
printf("kart hpr %f (%f) %f %f\n",
|
||||
m_kart->getHPR().getX(),heading, m_kart->getHPR().getY(),
|
||||
m_kart->getHPR().getZ());
|
||||
// Each case should set wanted_position and wanted_target according to
|
||||
// what is needed for that mode. Yes, there is a lot of duplicate code
|
||||
// but it is (IMHO) much easier to follow this way.
|
||||
@@ -287,13 +286,13 @@ void Camera::update(float dt)
|
||||
}
|
||||
case CM_REVERSE: // Same as CM_NORMAL except it looks backwards
|
||||
{
|
||||
wanted_target.setZ(wanted_target.getZ()+ 0.75f);
|
||||
wanted_target.setY(wanted_target.getY()+ 0.75f);
|
||||
float angle_around = m_kart->getHPR().getHeading()
|
||||
- m_rotation_range * m_kart->getSteerPercent()
|
||||
* m_kart->getSkidding();
|
||||
float angle_up = m_kart->getHPR().getPitch()
|
||||
+ 30.0f*DEGREE_TO_RAD;
|
||||
wanted_position.setX(-sin(angle_around));
|
||||
wanted_position.setX( sin(angle_around));
|
||||
wanted_position.setY( sin(angle_up) );
|
||||
wanted_position.setZ( cos(angle_around));
|
||||
wanted_position *= m_distance * 2.0f;
|
||||
|
||||
@@ -644,6 +644,9 @@ void Kart::update(float dt)
|
||||
m_uprightConstraint->setLimit(M_PI);
|
||||
else
|
||||
m_uprightConstraint->setLimit(m_kart_properties->getUprightTolerance());
|
||||
// FIXXXXXXXXXXXXXXXXXMMMMMMMMMMEEEEEEEEEEEEEEE fixme
|
||||
m_uprightConstraint->setLimit(M_PI);
|
||||
// FIXXXXXXXXXXXXXXXXXMMMMMMMMMMEEEEEEEEEEEEEEE fixme
|
||||
m_zipper_time_left = m_zipper_time_left>0.0f ? m_zipper_time_left-dt : 0.0f;
|
||||
|
||||
//m_wheel_rotation gives the rotation around the X-axis, and since velocity's
|
||||
|
||||
@@ -64,7 +64,7 @@ KartProperties::KartProperties(const std::string &filename) : m_icon_material(0)
|
||||
m_wheel_radius = m_chassis_linear_damping =
|
||||
m_chassis_angular_damping = m_suspension_rest =
|
||||
m_max_speed_reverse_ratio = m_jump_velocity =
|
||||
m_z_rescue_offset = m_upright_tolerance = m_collision_side_impulse =
|
||||
m_vert_rescue_offset = m_upright_tolerance = m_collision_side_impulse =
|
||||
m_upright_max_force = m_suspension_travel_cm =
|
||||
m_track_connection_accel = m_min_speed_turn = m_angle_at_min =
|
||||
m_max_speed_turn = m_angle_at_max =
|
||||
@@ -313,14 +313,14 @@ void KartProperties::getAllData(const XMLNode * root)
|
||||
|
||||
//TODO: wheel width is not loaded, yet is listed as an attribute in the xml file after wheel-radius?
|
||||
|
||||
root->get("chassis-linear-damping", &m_chassis_linear_damping);
|
||||
root->get("chassis-linear-damping", &m_chassis_linear_damping);
|
||||
root->get("chassis-angular-damping", &m_chassis_angular_damping);
|
||||
root->get("max-speed-reverse-ratio", &m_max_speed_reverse_ratio);
|
||||
root->get("suspension-rest", &m_suspension_rest);
|
||||
root->get("suspension-travel-cm", &m_suspension_travel_cm);
|
||||
root->get("jump-velocity", &m_jump_velocity);
|
||||
root->get("collision-side-impulse", &m_collision_side_impulse);
|
||||
root->get("z-rescue-offset", &m_z_rescue_offset);
|
||||
root->get("suspension-rest", &m_suspension_rest);
|
||||
root->get("suspension-travel-cm", &m_suspension_travel_cm);
|
||||
root->get("jump-velocity", &m_jump_velocity);
|
||||
root->get("collision-side-impulse", &m_collision_side_impulse);
|
||||
root->get("vert-rescue-offset", &m_vert_rescue_offset);
|
||||
|
||||
//TODO: wheel front right and wheel front left is not loaded, yet is listed as an attribute in the xml file after wheel-radius
|
||||
//TODO: same goes for their rear equivalents
|
||||
@@ -443,7 +443,7 @@ void KartProperties::getAllData(const lisp::Lisp* lisp)
|
||||
lisp->get("suspension-travel-cm", m_suspension_travel_cm );
|
||||
lisp->get("collision-side-impulse", m_collision_side_impulse );
|
||||
lisp->get("jump-velocity", m_jump_velocity );
|
||||
lisp->get("z-rescue-offset", m_z_rescue_offset );
|
||||
lisp->get("vert-rescue-offset", m_vert_rescue_offset );
|
||||
lisp->get("upright-tolerance", m_upright_tolerance );
|
||||
lisp->get("upright-max-force", m_upright_max_force );
|
||||
lisp->get("track-connection-accel", m_track_connection_accel );
|
||||
@@ -540,7 +540,7 @@ void KartProperties::checkAllSet(const std::string &filename)
|
||||
CHECK_NEG(m_suspension_travel_cm, "suspension-travel-cm" );
|
||||
CHECK_NEG(m_collision_side_impulse, "collision-side-impulse" );
|
||||
CHECK_NEG(m_jump_velocity, "jump-velocity" );
|
||||
CHECK_NEG(m_z_rescue_offset, "z-rescue-offset" );
|
||||
CHECK_NEG(m_vert_rescue_offset, "vert-rescue-offset" );
|
||||
CHECK_NEG(m_upright_tolerance, "upright-tolerance" );
|
||||
CHECK_NEG(m_upright_max_force, "upright-max-force" );
|
||||
CHECK_NEG(m_track_connection_accel, "track-connection-accel" );
|
||||
|
||||
@@ -130,8 +130,8 @@ private:
|
||||
/** An additional artifical side-impulse that pushes the slower kart
|
||||
* out of the way of the faster kart in case of a collision. */
|
||||
float m_collision_side_impulse;
|
||||
float m_jump_velocity; // z velocity set when jumping
|
||||
float m_z_rescue_offset; // z offset after rescue
|
||||
float m_jump_velocity; /**< Vertical velocity set when jumping. */
|
||||
float m_vert_rescue_offset; /**< Vertical offset after rescue. */
|
||||
float m_upright_tolerance;
|
||||
float m_upright_max_force;
|
||||
|
||||
@@ -230,7 +230,9 @@ public:
|
||||
/** Returns the (artificial) collision side impulse this kart will apply
|
||||
* to a slower kart in case of a collision. */
|
||||
float getCollisionSideImpulse () const {return m_collision_side_impulse; }
|
||||
float getZRescueOffset () const {return m_z_rescue_offset; }
|
||||
/** Returns the vertical offset when rescuing karts to avoid karts being
|
||||
* rescued in (or under) the track. */
|
||||
float getVertRescueOffset () const {return m_vert_rescue_offset; }
|
||||
float getUprightTolerance () const {return m_upright_tolerance; }
|
||||
float getUprightMaxForce () const {return m_upright_max_force; }
|
||||
float getTrackConnectionAccel () const {return m_track_connection_accel; }
|
||||
|
||||
@@ -129,24 +129,9 @@ void Moveable::update(float dt)
|
||||
|
||||
|
||||
m_hpr.setHPR(m_transform.getRotation());
|
||||
// roll is not set correctly, I assume due to a different HPR order.
|
||||
// So we compute the proper roll (by taking the angle between the up
|
||||
// vector and the rotated up vector).
|
||||
//Vec3 up(0, 1, 0);
|
||||
//Vec3 roll_vec = m_transform.getBasis()*up;
|
||||
//float roll = atan2(roll_vec.getX(), roll_vec.getY());
|
||||
//m_hpr.setRoll(roll);
|
||||
Vec3 up(0, 1, 0);
|
||||
Vec3 pitch_vec = m_transform.getBasis()*up;
|
||||
float p = atan2f(pitch_vec.getZ(), pitch_vec.getY());
|
||||
float r = atan2f(pitch_vec.getX(), pitch_vec.getY());
|
||||
Vec3 forw(0,0,1);
|
||||
Vec3 forw_vec = m_transform.getBasis()*forw;
|
||||
float h = atan2f(forw_vec.getX(), forw_vec.getZ());
|
||||
printf("orig: %f %f %f now %f %f %f\n",
|
||||
m_hpr.getX(), m_hpr.getY(), m_hpr.getZ(), h, p, r);
|
||||
//m_hpr = Vec3(h, p, r);
|
||||
//m_hpr.setPitch(p);
|
||||
Vec3 forw(1, 0, 0);
|
||||
Vec3 forw_vec = m_transform.getBasis().getColumn(0);
|
||||
m_heading = -atan2f(forw_vec.getZ(), forw_vec.getX());
|
||||
|
||||
updateGraphics(Vec3(0,0,0), Vec3(0,0,0));
|
||||
m_first_time = false ;
|
||||
|
||||
@@ -40,9 +40,12 @@ class Material;
|
||||
class Moveable
|
||||
{
|
||||
private:
|
||||
btVector3 m_velocityLC; /**<Velocity in kart coordinates */
|
||||
btTransform m_transform;
|
||||
Vec3 m_hpr;
|
||||
btVector3 m_velocityLC; /**<Velocity in kart coordinates. */
|
||||
btTransform m_transform;
|
||||
Vec3 m_hpr;
|
||||
/** The heading in m_hpr is between -90 and 90 degrees only. The 'real'
|
||||
* heading between -180 to 180 degrees is stored in this variable. */
|
||||
float m_heading;
|
||||
|
||||
protected:
|
||||
UserPointer m_user_pointer;
|
||||
@@ -68,7 +71,10 @@ public:
|
||||
&getVelocityLC() const {return m_velocityLC; }
|
||||
virtual void setVelocity(const btVector3& v) {m_body->setLinearVelocity(v); }
|
||||
const Vec3& getXYZ() const {return (Vec3&)m_transform.getOrigin();}
|
||||
/** Return the rotation, but heading is restricted to -90 and 90 degrees. */
|
||||
const Vec3& getHPR() const {return m_hpr; }
|
||||
/** Returns the heading between -180 and 180 degrees. */
|
||||
float getHeading() const {return m_heading; }
|
||||
const btQuaternion
|
||||
getRotation() const {return m_transform.getRotation(); }
|
||||
|
||||
|
||||
@@ -480,7 +480,7 @@ void LinearWorld::moveKartAfterRescue(Kart* kart, btRigidBody* body)
|
||||
|
||||
kart->setXYZ( m_track->trackToSpatial(info.m_track_sector) );
|
||||
|
||||
btQuaternion heading(btVector3(0.0f, 0.0f, 1.0f),
|
||||
btQuaternion heading(btVector3(0.0f, 1.0f, 0.0f),
|
||||
m_track->getAngle(info.m_track_sector) );
|
||||
kart->setRotation(heading);
|
||||
|
||||
@@ -491,8 +491,8 @@ void LinearWorld::moveKartAfterRescue(Kart* kart, btRigidBody* body)
|
||||
float epsilon = 0.5f * kart->getKartHeight();
|
||||
|
||||
btTransform pos;
|
||||
pos.setOrigin(kart->getXYZ()+btVector3(0, 0, kart->getKartHeight() + epsilon));
|
||||
pos.setRotation(btQuaternion(btVector3(0.0f, 0.0f, 1.0f),
|
||||
pos.setOrigin(kart->getXYZ()+btVector3(0, kart->getKartHeight() + epsilon, 0));
|
||||
pos.setRotation(btQuaternion(btVector3(0.0f, 1.0f, 0.0f),
|
||||
m_track->getAngle(info.m_track_sector)));
|
||||
|
||||
body->setCenterOfMassTransform(pos);
|
||||
@@ -503,9 +503,9 @@ void LinearWorld::moveKartAfterRescue(Kart* kart, btRigidBody* body)
|
||||
if (kart_over_ground)
|
||||
{
|
||||
//add vertical offset so that the kart starts off above the track
|
||||
float vertical_offset = kart->getKartProperties()->getZRescueOffset() *
|
||||
float vertical_offset = kart->getKartProperties()->getVertRescueOffset() *
|
||||
kart->getKartHeight();
|
||||
body->translate(btVector3(0, 0, vertical_offset));
|
||||
body->translate(btVector3(0, vertical_offset, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -593,7 +593,7 @@ void LinearWorld::checkForWrongDirection(unsigned int i)
|
||||
return;
|
||||
|
||||
// check if the player is going in the wrong direction
|
||||
float angle_diff = kart->getHPR().getHeading() -
|
||||
float angle_diff = kart->getHeading() -
|
||||
m_track->getAngle(m_kart_info[i].m_track_sector);
|
||||
if(angle_diff > M_PI) angle_diff -= 2*M_PI;
|
||||
else if (angle_diff < -M_PI) angle_diff += 2*M_PI;
|
||||
|
||||
@@ -240,18 +240,19 @@ void ThreeStrikesBattle::moveKartAfterRescue(Kart* kart, btRigidBody* body)
|
||||
const int start_spots_amount = world->getTrack()->getNumberOfStartPositions();
|
||||
assert(start_spots_amount > 0);
|
||||
|
||||
int smallest_distance_found = -1, closest_id_found = -1;
|
||||
float smallest_distance_found = -1;
|
||||
int closest_id_found = -1;
|
||||
|
||||
const int kart_x = (int)(kart->getXYZ()[0]);
|
||||
const int kart_y = (int)(kart->getXYZ()[1]);
|
||||
const float kart_x = kart->getXYZ().getX();
|
||||
const float kart_z = kart->getXYZ().getZ();
|
||||
|
||||
for(int n=0; n<start_spots_amount; n++)
|
||||
{
|
||||
// no need for the overhead to compute exact distance with sqrt(), so using the
|
||||
// 'manhattan' heuristic which will do fine enough.
|
||||
const Vec3 &v=world->getTrack()->getStartPosition(n);
|
||||
const int dist_n = abs((int)(kart_x - v.getX())) +
|
||||
abs((int)(kart_y - v.getY()));
|
||||
const float dist_n= fabs(kart_x - v.getX()) +
|
||||
fabs(kart_z - v.getZ());
|
||||
if(dist_n < smallest_distance_found || closest_id_found == -1)
|
||||
{
|
||||
closest_id_found = n;
|
||||
@@ -264,14 +265,14 @@ void ThreeStrikesBattle::moveKartAfterRescue(Kart* kart, btRigidBody* body)
|
||||
kart->setXYZ( Vec3(v) );
|
||||
|
||||
// FIXME - implement correct heading
|
||||
btQuaternion heading(btVector3(0.0f, 0.0f, 1.0f),
|
||||
btQuaternion heading(btVector3(0.0f, 1.0f, 0.0f),
|
||||
world->getTrack()->getStartHeading(closest_id_found));
|
||||
kart->setRotation(heading);
|
||||
|
||||
//position kart from same height as in World::resetAllKarts
|
||||
btTransform pos;
|
||||
pos.setOrigin(kart->getXYZ()+btVector3(0, 0, 0.5f*kart->getKartHeight()));
|
||||
pos.setRotation( btQuaternion(btVector3(0.0f, 0.0f, 1.0f), 0 /* angle */) );
|
||||
pos.setOrigin(kart->getXYZ()+btVector3(0, 0.5f*kart->getKartHeight(), 0.0f));
|
||||
pos.setRotation( btQuaternion(btVector3(0.0f, 1.0f, 0.0f), 0 /* angle */) );
|
||||
|
||||
body->setCenterOfMassTransform(pos);
|
||||
|
||||
@@ -281,9 +282,9 @@ void ThreeStrikesBattle::moveKartAfterRescue(Kart* kart, btRigidBody* body)
|
||||
if (kart_over_ground)
|
||||
{
|
||||
//add vertical offset so that the kart starts off above the track
|
||||
float vertical_offset = kart->getKartProperties()->getZRescueOffset() *
|
||||
float vertical_offset = kart->getKartProperties()->getVertRescueOffset() *
|
||||
kart->getKartHeight();
|
||||
body->translate(btVector3(0, 0, vertical_offset));
|
||||
body->translate(btVector3(0, vertical_offset, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -60,7 +60,7 @@ void CheckLine::reset(const Track &track)
|
||||
Vec3 CheckLine::getCenterPoint() const
|
||||
{
|
||||
core::vector2df c=m_line.getMiddle();
|
||||
Vec3 xyz(c.X, c.Y, m_min_height);
|
||||
Vec3 xyz(c.X, m_min_height, c.Y);
|
||||
return xyz;
|
||||
} // getCenterPoint
|
||||
|
||||
@@ -89,8 +89,8 @@ bool CheckLine::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx)
|
||||
// between -1 and 4 units (negative numbers are unlikely, but help
|
||||
// in case that there is 'somewhat' inside of the track, or the
|
||||
// checklines are a bit off in Z direction.
|
||||
result = new_pos.getZ()-m_min_height<4.0f &&
|
||||
new_pos.getZ()-m_min_height>-1.0f;
|
||||
result = new_pos.getY()-m_min_height<4.0f &&
|
||||
new_pos.getY()-m_min_height>-1.0f;
|
||||
}
|
||||
else
|
||||
result = false;
|
||||
|
||||
@@ -76,7 +76,7 @@ void GraphNode::addSuccessor(unsigned int to)
|
||||
Vec3 diff = next_quad.getCenter() - this_quad.getCenter();
|
||||
m_distance_to_next.push_back(d2.getLength());
|
||||
|
||||
float theta = -atan2(diff.getX(), diff.getZ());
|
||||
float theta = atan2(diff.getX(), diff.getZ());
|
||||
m_angle_to_next.push_back(theta);
|
||||
|
||||
// The length of this quad is the average of the left and right side
|
||||
|
||||
@@ -92,6 +92,6 @@ const core::vector3df& Vec3::toIrrVector() const
|
||||
/** Returns the X and Y component as an irrlicht 2d vector. */
|
||||
const core::vector2df Vec3::toIrrVector2d() const
|
||||
{
|
||||
core::vector2df v(m_x, m_y);
|
||||
core::vector2df v(m_x, m_z);
|
||||
return v;
|
||||
} // toIrrVector2d
|
||||
|
||||
@@ -56,10 +56,10 @@ public:
|
||||
void setHPR(const btQuaternion& q);
|
||||
inline const float operator[](int n) const { return *(&m_x+n); }
|
||||
inline const float getHeading() const { return m_y; }
|
||||
inline const float getPitch() const { return m_z; }
|
||||
inline const float getPitch() const { return m_x; }
|
||||
inline const float getRoll() const { return m_z; }
|
||||
inline const void setHeading(float f) { m_x = f; }
|
||||
inline const void setPitch(float f) { m_y = f; }
|
||||
inline const void setHeading(float f) { m_y = f; }
|
||||
inline const void setPitch(float f) { m_x = f; }
|
||||
inline const void setRoll(float f) { m_z = f; }
|
||||
/** Converts a Vec3 to an irrlicht 3d floating point vector. */
|
||||
const core::vector3df& toIrrVector() const;
|
||||
|
||||
Reference in New Issue
Block a user