Merge branch 'walldriving' of https://github.com/lurk26/stk-code into walldriving
This commit is contained in:
@@ -390,6 +390,10 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void crashed(const Material *m, const Vec3 &normal) = 0;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the normal of the terrain the kart is over atm. This is
|
||||
* defined even if the kart is flying. */
|
||||
virtual const Vec3& getNormal() const = 0;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the height of the terrain. we're currently above */
|
||||
virtual float getHoT() const = 0;
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@@ -374,7 +374,7 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true if the kart is close to the ground, used to dis/enable
|
||||
* the upright constraint to allow for more realistic explosions. */
|
||||
bool isNearGround () const;
|
||||
bool isNearGround() const;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true if the kart is eliminated. */
|
||||
virtual bool isEliminated() const { return m_eliminated; }
|
||||
@@ -419,6 +419,10 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void setOnScreenText(const wchar_t *text);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the normal of the terrain the kart is over atm. This is
|
||||
* defined even if the kart is flying. */
|
||||
virtual const Vec3& getNormal() const {return m_terrain_info->getNormal();}
|
||||
// ------------------------------------------------------------------------
|
||||
/** For debugging only: check if a kart is flying. */
|
||||
bool isFlying() const { return m_flying; }
|
||||
}; // Kart
|
||||
|
||||
@@ -129,8 +129,8 @@ void Moveable::update(float dt)
|
||||
if(m_body->getInvMass()!=0)
|
||||
m_motion_state->getWorldTransform(m_transform);
|
||||
m_velocityLC = getVelocity()*m_transform.getBasis();
|
||||
Vec3 forw_vec = m_transform.getBasis().getColumn(0);
|
||||
m_heading = -atan2f(forw_vec.getZ(), forw_vec.getX());
|
||||
Vec3 forw_vec = m_transform.getBasis().getColumn(2);
|
||||
m_heading = atan2f(forw_vec.getX(), forw_vec.getZ());
|
||||
|
||||
// The pitch in hpr is in between -pi and pi. But for the camera it
|
||||
// must be restricted to -pi/2 and pi/2 - so recompute it by restricting
|
||||
|
||||
@@ -90,15 +90,23 @@ public:
|
||||
m_transform.setOrigin(a);
|
||||
if(m_motion_state)
|
||||
m_motion_state->setWorldTransform(m_transform);
|
||||
}
|
||||
} // setXYZ
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the rotation of this moveable. */
|
||||
void setRotation(const btQuaternion&a)
|
||||
/** Sets the rotation of the physical body this moveable. */
|
||||
void setRotation(const btMatrix3x3 &m)
|
||||
{
|
||||
m_transform.setRotation(a);
|
||||
m_transform.setBasis(m);
|
||||
if(m_motion_state)
|
||||
m_motion_state->setWorldTransform(m_transform);
|
||||
}
|
||||
} // setRotation(btMatrix3x3)
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the rotation of the physical body this moveable. */
|
||||
void setRotation(const btQuaternion &q)
|
||||
{
|
||||
m_transform.setRotation(q);
|
||||
if(m_motion_state)
|
||||
m_motion_state->setWorldTransform(m_transform);
|
||||
} // setRotation(btQuaternion)
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void updateGraphics(float dt, const Vec3& off_xyz,
|
||||
const btQuaternion& off_rotation);
|
||||
|
||||
@@ -45,27 +45,20 @@ RescueAnimation::RescueAnimation(AbstractKart *kart, bool is_auto_rescue)
|
||||
|
||||
m_kart->getAttachment()->clear();
|
||||
|
||||
// We get the final transform of the kart so that it is rotated
|
||||
// accordingly during the rescue animation
|
||||
World * world = World::getWorld();
|
||||
unsigned int index = world->getRescuePositionIndex(m_kart);
|
||||
btTransform t = world->getRescueTransform(index);
|
||||
Vec3 up = t.getBasis().getColumn(1);
|
||||
float target_pitch = atan2(up.getZ(), fabsf(up.getY()));
|
||||
float target_roll = atan2(up.getX(), up.getY());
|
||||
// Get the current rotation of the kart
|
||||
m_curr_rotation = m_kart->getNode()->getRotation() * DEGREE_TO_RAD;
|
||||
|
||||
|
||||
m_curr_rotation.setPitch(m_kart->getPitch());
|
||||
m_curr_rotation.setRoll(m_kart->getRoll());
|
||||
m_curr_rotation.setHeading(0);
|
||||
|
||||
Vec3 required_rotation;
|
||||
required_rotation.setPitch(target_pitch - m_kart->getPitch());
|
||||
required_rotation.setRoll(target_roll - m_kart->getRoll());
|
||||
required_rotation.setHeading(0);
|
||||
m_add_rotation = -required_rotation/m_timer;
|
||||
|
||||
m_curr_rotation.setHeading(m_kart->getHeading());
|
||||
// Determine the rotation that will rotate the kart from the current
|
||||
// up direction to the right up direction it should have according to
|
||||
// the normal at the kart's location
|
||||
Vec3 up = m_kart->getTrans().getBasis().getColumn(1);
|
||||
btQuaternion q = shortestArcQuat(up, m_kart->getNormal());
|
||||
|
||||
// Store this rotation as 'delta HPR', which is added over time to the
|
||||
// current rotation to end up (after m_timer seconds) with the right up
|
||||
// rotation
|
||||
m_add_rotation.setHPR(q);
|
||||
m_add_rotation /= m_timer;
|
||||
|
||||
// Add a hit unless it was auto-rescue
|
||||
if(race_manager->getMinorMode()==RaceManager::MINOR_MODE_3_STRIKES &&
|
||||
@@ -112,15 +105,13 @@ RescueAnimation::~RescueAnimation()
|
||||
*/
|
||||
void RescueAnimation::update(float dt)
|
||||
{
|
||||
|
||||
//m_xyz.setY(m_xyz.getY() + dt*m_velocity);
|
||||
btQuaternion q1 = m_kart->getTrans().getRotation();
|
||||
m_xyz = m_xyz + dt*m_velocity*(Vec3(0, 1, 0).rotate(q1.getAxis(), q1.getAngle()));
|
||||
m_xyz += dt*m_velocity * m_kart->getNormal();
|
||||
m_kart->setXYZ(m_xyz);
|
||||
m_curr_rotation += dt*m_add_rotation;
|
||||
btQuaternion q(m_curr_rotation.getHeading(), m_curr_rotation.getPitch(),
|
||||
btMatrix3x3 m;
|
||||
m.setEulerZYX(m_curr_rotation.getPitch(), m_curr_rotation.getHeading(),
|
||||
m_curr_rotation.getRoll());
|
||||
m_kart->setRotation(q);
|
||||
m_kart->setRotation(m);
|
||||
|
||||
AbstractKartAnimation::update(dt);
|
||||
|
||||
|
||||
@@ -636,6 +636,7 @@ btTransform LinearWorld::getRescueTransform(unsigned int index) const
|
||||
const Vec3 &xyz = QuadGraph::get()->getQuadOfNode(index).getCenter();
|
||||
const Vec3 &normal = QuadGraph::get()->getQuadOfNode(index).getNormal();
|
||||
btTransform pos;
|
||||
pos.setOrigin(xyz);
|
||||
|
||||
// First rotate into the quad's plane (q1), then rotate so that the kart points in the
|
||||
// right direction (q2).
|
||||
@@ -646,9 +647,18 @@ btTransform LinearWorld::getRescueTransform(unsigned int index) const
|
||||
}
|
||||
else q1 = btQuaternion(Vec3(0,1,0),0);
|
||||
|
||||
btQuaternion q2(btVector3(normal), m_track->getAngle(index));
|
||||
pos.setOrigin(xyz);
|
||||
pos.setRotation(q2*q1);
|
||||
btQuaternion q2(btVector3(0,1,0), m_track->getAngle(index));
|
||||
|
||||
// First apply the heading change, than the 'parallelisation' to the plane
|
||||
pos.setRotation(q1*q2);
|
||||
#ifdef DEBUG
|
||||
btQuaternion r = q1*q2;
|
||||
btVector3 axis = r.getAxis();
|
||||
float angle = r.getAngle();
|
||||
Log::verbose("rescue", "%d angle %f axis %f %f %f pos %f %f %f",
|
||||
index, angle, axis.getX(),axis.getY(),axis.getZ(),
|
||||
xyz.getX(),xyz.getY(),xyz.getZ());
|
||||
#endif
|
||||
return pos;
|
||||
} // getRescueTransform
|
||||
|
||||
|
||||
@@ -715,9 +715,7 @@ void World::moveKartTo(AbstractKart* kart, const btTransform &transform)
|
||||
btQuaternion rot = pos.getRotation();
|
||||
|
||||
// Move the kart
|
||||
Vec3 xyz = pos.getOrigin() + btVector3(0, 0.5f*kart->getKartHeight(),0.0f).
|
||||
rotate(rot.getAxis(),rot.getAngle());
|
||||
|
||||
Vec3 xyz = pos.getOrigin() + 0.5f*kart->getKartHeight() * kart->getNormal();
|
||||
pos.setOrigin(xyz);
|
||||
kart->setXYZ(xyz);
|
||||
kart->setRotation(pos.getRotation());
|
||||
|
||||
@@ -2453,7 +2453,7 @@ bool Track::findGround(AbstractKart *kart)
|
||||
// - so I'll leave it in for now.
|
||||
float offset = kart->getKartProperties()->getSuspensionRest() +
|
||||
kart->getKartProperties()->getWheelRadius();
|
||||
t.setOrigin(hit_point+ (btVector3(0, offset, 0).rotate(q.getAxis(),q.getAngle()) ) );
|
||||
t.setOrigin(hit_point+ quadNormal * offset);
|
||||
kart->getBody()->setCenterOfMassTransform(t);
|
||||
kart->setTrans(t);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user