Very first changes. Doesn't really work yet and will most likely crash - not recommended to use :)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/switch_coordinate_system@4813 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
2f8411c364
commit
092a59a7d2
@ -2,11 +2,32 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<config>
|
||||
|
||||
<!-- Minimum and maximum kart versions that can be used by this binary.
|
||||
Older version will be ignored. -->
|
||||
<kart-version min="1" max="1"/>
|
||||
<!-- Minimum and maxium track versions that be be read by this binary.
|
||||
Older versions will be ignored. -->
|
||||
<track-version min="1" max="1"/>
|
||||
<!-- Maximum number of karts to be used at the same time. This limit
|
||||
can easily be increased, but some tracks might not have valid start
|
||||
positions for those additional karts. -->
|
||||
<max-karts value="8"/>
|
||||
<!--
|
||||
<Scores =point="10 8 6 5 4 3 2 1"''>
|
||||
grid-order="1"
|
||||
title-music="main_theme.music"
|
||||
mainmenu-background="st_title_screen.rgb st_title_screen2.rgb"
|
||||
menu-background="menu_background.rgb menu_background2.rgb"
|
||||
max-history="10000"
|
||||
max-skidmarks="100"
|
||||
skid-fadeout-time="60"
|
||||
near-ground="2"
|
||||
delay-finish-time="4"
|
||||
music-credit-time="10"
|
||||
final-camera-time="1.5"
|
||||
-->
|
||||
<!-- STK PARAMETERS
|
||||
|
||||
min-kart-version and max-kart-version are the the minimum and maximum .kart
|
||||
files supported. Older/newer files are ignored.
|
||||
|
||||
min-track-version and max-track-version are the minimum and maximum .track
|
||||
files supported, older/newer files are ignored.
|
||||
@ -189,7 +210,7 @@ rubber-band-duration is the duration a rubber band acts.
|
||||
time-full-steer-ai="0.1"
|
||||
corn-f ="4"
|
||||
corn-r="4"
|
||||
gravity-center-shift="0 0 0.3"
|
||||
gravity-center-shift="0 0.3 0"
|
||||
nitro-power-boost="3"
|
||||
|
||||
skid-increase="1.05"
|
||||
@ -224,10 +245,10 @@ rubber-band-duration is the duration a rubber band acts.
|
||||
jump-velocity="3.0"
|
||||
collision-side-impulse="0"
|
||||
z-rescue-offset="0.0"
|
||||
wheel-front-right="0.38 0.6 0"
|
||||
wheel-front-left="-0.38 0.6 0"
|
||||
wheel-rear-right="0.38 -0.6 0"
|
||||
wheel-rear-left="-0.38 -0.6 0"
|
||||
wheel-front-right="0.38 0 0.6"
|
||||
wheel-front-left="-0.38 0 0.6"
|
||||
wheel-rear-right="0.38 0 -0.6"
|
||||
wheel-rear-left="-0.38 0 -0.6"
|
||||
gear-switch-ratio="0.25 0.7 1.0"
|
||||
gear-power-increase="2.2 1.7 1.3"
|
||||
upright-tolerance="0.2"
|
||||
|
@ -164,7 +164,7 @@ void Camera::setMode(Mode mode)
|
||||
core::vector3df curr_hpr = m_camera->getRotation();
|
||||
m_target_velocity = (target - m_camera->getTarget())
|
||||
/ stk_config->m_final_camera_time;
|
||||
m_final_time = 0.0f;
|
||||
m_final_time = 0.0f;
|
||||
}
|
||||
|
||||
// If the camera is set to final mode but there is no camera
|
||||
@ -199,7 +199,8 @@ void Camera::reset()
|
||||
*/
|
||||
void Camera::setInitialTransform()
|
||||
{
|
||||
m_camera->setPosition( m_kart->getXYZ().toIrrVector() - core::vector3df(0, -25, 50) );
|
||||
m_camera->setPosition( m_kart->getXYZ().toIrrVector()
|
||||
- core::vector3df(0, 50, -25) );
|
||||
} // setInitialTransform
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -246,16 +247,16 @@ void Camera::computeNormalCameraPosition(Vec3 *wanted_position,
|
||||
Vec3 *wanted_target)
|
||||
{
|
||||
*wanted_target = m_kart->getXYZ();
|
||||
wanted_target->setZ(wanted_target->getZ()+ 0.75f);
|
||||
wanted_target->setY(wanted_target->getY()+ 0.75f);
|
||||
// This first line moves the camera around behind the kart, pointing it
|
||||
// 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().getX() + m_rotation_range * dampened_steer * 0.5f;
|
||||
float angle_up = m_kart->getHPR().getY() - 30.0f*DEGREE_TO_RAD;
|
||||
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));
|
||||
wanted_position->setY(-cos(angle_around));
|
||||
wanted_position->setZ(-sin(angle_up) );
|
||||
wanted_position->setY(-sin(angle_up) );
|
||||
wanted_position->setZ(-cos(angle_around));
|
||||
*wanted_position *= m_distance;
|
||||
*wanted_position += *wanted_target;
|
||||
} // computeNormalCameraPosition
|
||||
@ -283,11 +284,14 @@ void Camera::update(float dt)
|
||||
case CM_REVERSE: // Same as CM_NORMAL except it looks backwards
|
||||
{
|
||||
wanted_target.setZ(wanted_target.getZ()+ 0.75f);
|
||||
float angle_around = m_kart->getHPR().getX() - m_rotation_range * m_kart->getSteerPercent() * m_kart->getSkidding();
|
||||
float angle_up = m_kart->getHPR().getY() + 30.0f*DEGREE_TO_RAD;
|
||||
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.setY( cos(angle_around));
|
||||
wanted_position.setZ( sin(angle_up) );
|
||||
wanted_position.setY( sin(angle_up) );
|
||||
wanted_position.setZ( cos(angle_around));
|
||||
wanted_position *= m_distance * 2.0f;
|
||||
wanted_position += wanted_target;
|
||||
smoothMoveCamera(dt, wanted_position, wanted_target);
|
||||
@ -297,12 +301,15 @@ void Camera::update(float dt)
|
||||
}
|
||||
case CM_CLOSEUP: // Lower to the ground and closer to the kart
|
||||
{
|
||||
wanted_target.setZ(wanted_target.getZ()+0.75f);
|
||||
float angle_around = m_kart->getHPR().getX() + m_rotation_range * m_kart->getSteerPercent() * m_kart->getSkidding();
|
||||
float angle_up = m_kart->getHPR().getY() - 20.0f*DEGREE_TO_RAD;
|
||||
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()
|
||||
- 20.0f*DEGREE_TO_RAD;
|
||||
wanted_position.setX( sin(angle_around));
|
||||
wanted_position.setY(-cos(angle_around));
|
||||
wanted_position.setZ(-sin(angle_up) );
|
||||
wanted_position.setY(-sin(angle_up) );
|
||||
wanted_position.setZ(-cos(angle_around));
|
||||
wanted_position *= m_distance * 0.5f;
|
||||
wanted_position += wanted_target;
|
||||
smoothMoveCamera(dt, wanted_position, wanted_target);
|
||||
@ -315,11 +322,11 @@ void Camera::update(float dt)
|
||||
wanted_target = kart->getXYZ().toIrrVector();
|
||||
// Follows the leader kart, higher off of the ground, further from the kart,
|
||||
// and turns in the opposite direction from the kart for a nice effect. :)
|
||||
float angle_around = kart->getHPR().getX();
|
||||
float angle_up = kart->getHPR().getY() + 40.0f*DEGREE_TO_RAD;
|
||||
float angle_around = kart->getHPR().getHeading();
|
||||
float angle_up = kart->getHPR().getPitch() + 40.0f*DEGREE_TO_RAD;
|
||||
wanted_position.setX(sin(angle_around));
|
||||
wanted_position.setY(cos(angle_around));
|
||||
wanted_position.setZ(sin(angle_up) );
|
||||
wanted_position.setY(sin(angle_up) );
|
||||
wanted_position.setZ(cos(angle_around));
|
||||
wanted_position *= m_distance * 2.0f;
|
||||
wanted_position += wanted_target;
|
||||
smoothMoveCamera(dt, wanted_position, wanted_target);
|
||||
|
@ -36,8 +36,8 @@ void MeshTools::minMax3D(scene::IMesh* mesh, Vec3 *min, Vec3 *max) {
|
||||
for(unsigned int j=0; j<mb->getIndexCount(); j+=1) {
|
||||
int indx=mbIndices[j];
|
||||
Vec3 c(mbVertices[indx].Pos.X,
|
||||
mbVertices[indx].Pos.Z,
|
||||
mbVertices[indx].Pos.Y );
|
||||
mbVertices[indx].Pos.Y,
|
||||
mbVertices[indx].Pos.Z );
|
||||
min->min(c);
|
||||
max->max(c);
|
||||
} // for j
|
||||
|
@ -155,7 +155,7 @@ void Item::update(float dt)
|
||||
|
||||
if(!m_rotate) return;
|
||||
// have it rotate
|
||||
Vec3 rotation(dt*M_PI, 0, 0);
|
||||
Vec3 rotation(0, dt*M_PI, 0);
|
||||
m_coord.setHPR(m_coord.getHPR()+rotation);
|
||||
m_node->setRotation(m_coord.getHPR().toIrrHPR());
|
||||
m_node->setPosition(m_coord.getXYZ().toIrrVector());
|
||||
|
@ -191,8 +191,8 @@ void Kart::createPhysics()
|
||||
float kart_height = km->getHeight();
|
||||
|
||||
btBoxShape *shape = new btBoxShape(btVector3(0.5f*kart_width,
|
||||
0.5f*kart_length,
|
||||
0.5f*kart_height));
|
||||
0.5f*kart_height,
|
||||
0.5f*kart_length));
|
||||
btTransform shiftCenterOfGravity;
|
||||
shiftCenterOfGravity.setIdentity();
|
||||
// Shift center of gravity downwards, so that the kart
|
||||
@ -229,15 +229,15 @@ void Kart::createPhysics()
|
||||
|
||||
// never deactivate the vehicle
|
||||
m_body->setActivationState(DISABLE_DEACTIVATION);
|
||||
m_vehicle->setCoordinateSystem(/*right: */ 0, /*up: */ 2, /*forward: */ 1);
|
||||
m_vehicle->setCoordinateSystem(/*right: */ 0, /*up: */ 1, /*forward: */ 2);
|
||||
|
||||
// Add wheels
|
||||
// ----------
|
||||
float wheel_radius = m_kart_properties->getWheelRadius();
|
||||
float suspension_rest = m_kart_properties->getSuspensionRest();
|
||||
|
||||
btVector3 wheel_direction(0.0f, 0.0f, -1.0f);
|
||||
btVector3 wheel_axle(1.0f,0.0f,0.0f);
|
||||
btVector3 wheel_direction(0.0f, -1.0f, 0.0f);
|
||||
btVector3 wheel_axle(-1.0f,0.0f,0.0f);
|
||||
|
||||
for(unsigned int i=0; i<4; i++)
|
||||
{
|
||||
@ -1027,7 +1027,7 @@ bool Kart::playCustomSFX(unsigned int type)
|
||||
*/
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void Kart::updatePhysics (float dt)
|
||||
void Kart::updatePhysics(float dt)
|
||||
{
|
||||
|
||||
m_bounce_back_time-=dt;
|
||||
@ -1171,8 +1171,8 @@ void Kart::updatePhysics (float dt)
|
||||
}
|
||||
float steering = getMaxSteerAngle() * m_controls.m_steer*m_skidding;
|
||||
|
||||
m_vehicle->setSteeringValue(steering, 0);
|
||||
m_vehicle->setSteeringValue(steering, 1);
|
||||
m_vehicle->setSteeringValue(-steering, 0);
|
||||
m_vehicle->setSteeringValue(-steering, 1);
|
||||
|
||||
// Only compute the current speed if this is not the client. On a client the
|
||||
// speed is actually received from the server.
|
||||
@ -1320,12 +1320,12 @@ void Kart::setSuspensionLength()
|
||||
//-----------------------------------------------------------------------------
|
||||
void Kart::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr)
|
||||
{
|
||||
float wheel_z_axis[4];
|
||||
float wheel_y_axis[4];
|
||||
KartModel *kart_model = m_kart_properties->getKartModel();
|
||||
for(unsigned int i=0; i<4; i++)
|
||||
{
|
||||
// Set the suspension length
|
||||
wheel_z_axis[i] = m_default_suspension_length[i]
|
||||
wheel_y_axis[i] = m_default_suspension_length[i]
|
||||
- m_vehicle->getWheelInfo(i).m_raycastInfo.m_suspensionLength;
|
||||
}
|
||||
#define AUTO_SKID_VISUAL 1.7f
|
||||
@ -1335,15 +1335,15 @@ void Kart::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr)
|
||||
else
|
||||
auto_skid = m_controls.m_steer*30.0f;
|
||||
kart_model->update(m_wheel_rotation, auto_skid,
|
||||
getSteerPercent(), wheel_z_axis);
|
||||
getSteerPercent(), wheel_y_axis);
|
||||
|
||||
Vec3 center_shift = getGravityCenterShift();
|
||||
float X = m_vehicle->getWheelInfo(0).m_chassisConnectionPointCS.getZ()
|
||||
float y = m_vehicle->getWheelInfo(0).m_chassisConnectionPointCS.getY()
|
||||
- m_default_suspension_length[0]
|
||||
- m_vehicle->getWheelInfo(0).m_wheelsRadius
|
||||
- (kart_model->getWheelGraphicsRadius(0)
|
||||
-kart_model->getWheelGraphicsPosition(0).getZ() );
|
||||
center_shift.setZ(X);
|
||||
-kart_model->getWheelGraphicsPosition(0).getY() );
|
||||
center_shift.setY(y);
|
||||
|
||||
if(m_smoke_system)
|
||||
{
|
||||
|
@ -109,8 +109,8 @@ void KartModel::loadModels(const KartProperties &kart_properties)
|
||||
Vec3 size = max-min;
|
||||
m_z_offset = min.getZ();
|
||||
m_kart_width = size.getX();
|
||||
m_kart_height = size.getZ();
|
||||
m_kart_length = size.getY();
|
||||
m_kart_height = size.getY();
|
||||
m_kart_length = size.getZ();
|
||||
// FIXME: How do we handle this? it's a mesh only, so we can't
|
||||
// simply move it in a transform (unless we turn it into a scene
|
||||
// node). m_z_offset should probably be made available to kart.
|
||||
@ -127,9 +127,9 @@ void KartModel::loadModels(const KartProperties &kart_properties)
|
||||
m_wheel_graphics_position[i].setX( ( i==1||i==3)
|
||||
? -0.5f*m_kart_width
|
||||
: 0.5f*m_kart_width );
|
||||
m_wheel_graphics_position[i].setY( (i<2) ? 0.5f*m_kart_length
|
||||
m_wheel_graphics_position[i].setY(0);
|
||||
m_wheel_graphics_position[i].setZ( (i<2) ? 0.5f*m_kart_length
|
||||
: -0.5f*m_kart_length);
|
||||
m_wheel_graphics_position[i].setZ(0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,13 +198,13 @@ void KartModel::setDefaultPhysicsPosition(const Vec3 ¢er_shift,
|
||||
? -0.5f*m_kart_width
|
||||
: 0.5f*m_kart_width
|
||||
+center_shift.getX( ));
|
||||
m_wheel_physics_position[i].setY( (0.5f*m_kart_length-wheel_radius)
|
||||
* ( (i<2) ? 1 : -1)
|
||||
+center_shift.getY());
|
||||
// Set the connection point so that a maximum compressed wheel
|
||||
// (susp. length=0) will still poke a little bit out under the
|
||||
// kart
|
||||
m_wheel_physics_position[i].setZ(wheel_radius-0.05f);
|
||||
m_wheel_physics_position[i].setY(wheel_radius-0.05f);
|
||||
m_wheel_physics_position[i].setZ( (0.5f*m_kart_length-wheel_radius)
|
||||
* ( (i<2) ? 1 : -1)
|
||||
+center_shift.getZ());
|
||||
} // if physics position is not defined
|
||||
}
|
||||
|
||||
@ -263,7 +263,6 @@ void KartModel::update(float rotation, float visual_steer,
|
||||
clamped_suspension[i] = ratio*suspension_length;
|
||||
} // for i<4
|
||||
|
||||
// core::vector3df wheel_rear (RAD_TO_DEGREE(-rotation), 0, 0);
|
||||
core::vector3df wheel_rear (-rotation, 0, 0);
|
||||
core::vector3df wheel_steer(0, -visual_steer, 0);
|
||||
core::vector3df wheel_front = wheel_rear+wheel_steer;
|
||||
|
@ -175,14 +175,14 @@ void KartProperties::load(const std::string &filename, const std::string &node)
|
||||
if(m_gravity_center_shift.getX()==UNDEFINED)
|
||||
{
|
||||
m_gravity_center_shift.setX(0);
|
||||
m_gravity_center_shift.setY(0);
|
||||
// Default: center at the very bottom of the kart.
|
||||
m_gravity_center_shift.setZ(m_kart_model.getHeight()*0.5f);
|
||||
m_gravity_center_shift.setY(m_kart_model.getHeight()*0.5f);
|
||||
m_gravity_center_shift.setZ(0);
|
||||
}
|
||||
m_kart_model.setDefaultPhysicsPosition(m_gravity_center_shift,
|
||||
m_wheel_radius);
|
||||
m_wheel_base = fabsf( m_kart_model.getWheelPhysicsPosition(0).getY()
|
||||
-m_kart_model.getWheelPhysicsPosition(2).getY());
|
||||
m_wheel_radius );
|
||||
m_wheel_base = fabsf( m_kart_model.getWheelPhysicsPosition(0).getZ()
|
||||
-m_kart_model.getWheelPhysicsPosition(2).getZ());
|
||||
m_angle_at_min = asinf(m_wheel_base/m_min_radius);
|
||||
m_angle_at_max = asinf(m_wheel_base/m_max_radius);
|
||||
if(m_max_speed_turn == m_min_speed_turn)
|
||||
|
@ -128,14 +128,14 @@ void Moveable::update(float dt)
|
||||
//m_hpr.setZ(-r.Z);
|
||||
|
||||
|
||||
m_hpr.setHPR(m_transform.getBasis());
|
||||
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,0,1);
|
||||
Vec3 roll_vec = m_transform.getBasis()*up;
|
||||
float roll = atan2(roll_vec.getX(), roll_vec.getZ());
|
||||
m_hpr.setRoll(roll);
|
||||
//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);
|
||||
|
||||
updateGraphics(Vec3(0,0,0), Vec3(0,0,0));
|
||||
m_first_time = false ;
|
||||
@ -161,8 +161,7 @@ void Moveable::createBody(float mass, btTransform& trans,
|
||||
// functions are not called correctly. So only init the pointer to zero.
|
||||
m_user_pointer.zero();
|
||||
m_body->setUserPointer(&m_user_pointer);
|
||||
const btMatrix3x3& basis=m_body->getWorldTransform().getBasis();
|
||||
m_hpr.setHPR(basis);
|
||||
m_hpr.setHPR(m_body->getWorldTransform().getRotation());
|
||||
} // createBody
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -280,12 +280,20 @@ int LinearWorld::getSectorForKart(const int kart_id) const
|
||||
} // getSectorForKart
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Returns the distance the kart has travelled along the track since
|
||||
* crossing the start line..
|
||||
* \param kart_id Index of the kart.
|
||||
*/
|
||||
float LinearWorld::getDistanceDownTrackForKart(const int kart_id) const
|
||||
{
|
||||
return m_kart_info[kart_id].m_curr_track_coords.getY();
|
||||
return m_kart_info[kart_id].m_curr_track_coords.getZ();
|
||||
} // getDistanceDownTrackForKart
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Gets the distance of the kart from the center of the driveline. Positive
|
||||
* is to the right of the center, negative values to the left.
|
||||
* \param kart_id Index of kart.
|
||||
*/
|
||||
float LinearWorld::getDistanceToCenterForKart(const int kart_id) const
|
||||
{
|
||||
return m_kart_info[kart_id].m_curr_track_coords.getX();
|
||||
|
@ -103,7 +103,7 @@ btUprightConstraint::btUprightConstraint(btRigidBody& rbA, const btTransform& fr
|
||||
m_limit[0].m_accumulatedImpulse = 0.0f;
|
||||
m_limit[1].m_accumulatedImpulse = 0.0f;
|
||||
m_limit[ 0 ].m_axis = btVector3( 1, 0, 0 );
|
||||
m_limit[ 1 ].m_axis = btVector3( 0, 1, 0 );
|
||||
m_limit[ 1 ].m_axis = btVector3( 0, 0, 1 );
|
||||
setLimit( SIMD_PI * 0.4f );
|
||||
}
|
||||
|
||||
@ -114,9 +114,9 @@ btUprightConstraint::btUprightConstraint(btRigidBody& rbA, const btTransform& fr
|
||||
void btUprightConstraint::buildJacobian()
|
||||
{
|
||||
btTransform worldTransform = m_rbA.getCenterOfMassTransform() * m_frameInA;
|
||||
btVector3 upAxis = worldTransform.getBasis().getColumn(2);
|
||||
m_limit[ 0 ].m_angle = btAtan2( upAxis.getZ(), upAxis.getY() )-SIMD_PI/2.0f;
|
||||
m_limit[ 1 ].m_angle = -btAtan2( upAxis.getZ(), upAxis.getX() )+SIMD_PI/2.0f;
|
||||
btVector3 upAxis = worldTransform.getBasis().getColumn(1);
|
||||
m_limit[ 0 ].m_angle = btAtan2( upAxis.getY(), upAxis.getZ() )-SIMD_PI/2.0f;
|
||||
m_limit[ 1 ].m_angle = -btAtan2( upAxis.getY(), upAxis.getX() )+SIMD_PI/2.0f;
|
||||
|
||||
for ( int i = 0; i < 2; i++ )
|
||||
{
|
||||
|
@ -59,12 +59,10 @@ void IrrDebugDrawer::deactivate()
|
||||
void IrrDebugDrawer::drawLine(const btVector3& from, const btVector3& to,
|
||||
const btVector3& color)
|
||||
{
|
||||
Vec3 f(from);
|
||||
Vec3 t(to);
|
||||
video::SColor c(255, (int)(color.getX()*255), (int)(color.getY()*255),
|
||||
(int)(color.getZ()*255) );
|
||||
irr_driver->getVideoDriver()->draw3DLine(f.toIrrVector(),
|
||||
t.toIrrVector(), c);
|
||||
irr_driver->getVideoDriver()->draw3DLine((const core::vector3df&)from,
|
||||
(const core::vector3df&)to, c);
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
@ -45,11 +45,12 @@ void Physics::init(const Vec3 &world_min, const Vec3 &world_max)
|
||||
{
|
||||
m_axis_sweep = new btAxisSweep3(world_min, world_max);
|
||||
m_dynamics_world = new btDiscreteDynamicsWorld(m_dispatcher,
|
||||
m_axis_sweep,
|
||||
m_axis_sweep,
|
||||
this,
|
||||
m_collision_conf);
|
||||
m_dynamics_world->setGravity(btVector3(0.0f, 0.0f,
|
||||
-World::getWorld()->getTrack()->getGravity()));
|
||||
m_dynamics_world->setGravity(btVector3(0.0f,
|
||||
-World::getWorld()->getTrack()->getGravity(),
|
||||
0.0f));
|
||||
m_debug_drawer = new IrrDebugDrawer();
|
||||
m_debug_drawer->setDebugMode(btIDebugDraw::DBG_DrawWireframe);
|
||||
m_dynamics_world->setDebugDrawer(m_debug_drawer);
|
||||
|
@ -52,10 +52,10 @@ GraphNode::GraphNode(unsigned int index)
|
||||
+ (quad[3]-quad[2]).length() ) * 0.5f;
|
||||
Vec3 lower = (quad[0]+quad[1]) * 0.5f;
|
||||
Vec3 upper = (quad[2]+quad[3]) * 0.5f;
|
||||
m_line = core::line2df(lower.getX(), lower.getY(),
|
||||
upper.getX(), upper.getY() );
|
||||
m_line = core::line2df(lower.getX(), lower.getZ(),
|
||||
upper.getX(), upper.getZ() );
|
||||
// Only this 2d point is needed later
|
||||
m_lower_center = core::vector2df(lower.getX(), lower.getY());
|
||||
m_lower_center = core::vector2df(lower.getX(), lower.getZ());
|
||||
} // GraphNode
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -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.getY());
|
||||
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
|
||||
@ -103,7 +103,7 @@ void GraphNode::addSuccessor(unsigned int to)
|
||||
* is it. All these computations are done in 2D only.
|
||||
* \param xyz The coordinates of the point.
|
||||
* \param result The X coordinate contains the sidewards distance, the
|
||||
* y coordinate the forward distance.
|
||||
* Z coordinate the forward distance.
|
||||
*/
|
||||
void GraphNode::getDistances(const Vec3 &xyz, Vec3 *result)
|
||||
{
|
||||
@ -113,5 +113,5 @@ void GraphNode::getDistances(const Vec3 &xyz, Vec3 *result)
|
||||
result->setX( (closest-xyz2d).getLength()); // to the right
|
||||
else
|
||||
result->setX(-(closest-xyz2d).getLength()); // to the left
|
||||
result->setY( m_distance_from_start + (closest-m_lower_center).getLength());
|
||||
result->setZ( m_distance_from_start + (closest-m_lower_center).getLength());
|
||||
} // getDistances
|
||||
|
@ -41,8 +41,8 @@ Quad::Quad(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2, const Vec3 &p3,
|
||||
m_p[0]=p0; m_p[1]=p1; m_p[2]=p2; m_p[3]=p3;
|
||||
}
|
||||
m_center = 0.25f*(p0+p1+p2+p3);
|
||||
m_min_height = std::min ( std::min(p0.getZ(), p1.getZ()),
|
||||
std::min(p0.getZ(), p1.getZ()) );
|
||||
m_min_height = std::min ( std::min(p0.getY(), p1.getY()),
|
||||
std::min(p0.getY(), p1.getY()) );
|
||||
m_invisible = invisible;
|
||||
} // Quad
|
||||
|
||||
@ -87,8 +87,8 @@ void Quad::getVertices(video::S3DVertex *v, const video::SColor &color) const
|
||||
*/
|
||||
float Quad::sideOfLine2D(const Vec3& l1, const Vec3& l2, const Vec3& p) const
|
||||
{
|
||||
return (l2.getX()-l1.getX())*(p.getY()-l1.getY()) -
|
||||
(l2.getY()-l1.getY())*(p.getX()-l1.getX());
|
||||
return (l2.getX()-l1.getX())*(p.getZ()-l1.getZ()) -
|
||||
(l2.getZ()-l1.getZ())*(p.getX()-l1.getX());
|
||||
} // sideOfLine
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -102,6 +102,7 @@ bool Quad::pointInQuad(const Vec3& p) const
|
||||
sideOfLine2D(m_p[3], m_p[0], p) >= 0.0;
|
||||
}
|
||||
} // pointInQuad
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Transforms a quad by a given transform (i.e. translation+rotation). This
|
||||
* function does not modify this quad, the results are stored in the quad
|
||||
|
@ -79,7 +79,7 @@ void QuadGraph::setStartCoordinate(const CheckLine &cl)
|
||||
}
|
||||
Vec3 xyz;
|
||||
spatialToTrack(&xyz, start_point, sector);
|
||||
m_offset_for_startline = xyz.getY();
|
||||
m_offset_for_startline = xyz.getZ();
|
||||
} // setStartCoordinate
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -311,7 +311,7 @@ void QuadGraph::getSuccessors(int node_number, std::vector<unsigned int>& succ)
|
||||
* of the returned vector is how much of the track the point has gone
|
||||
* through, the x-axis is on which side of the road it is. The Z axis
|
||||
* is not changed.
|
||||
* \param dst Returns the results in the X and Y coordinates.
|
||||
* \param dst Returns the results in the X and Z coordinates.
|
||||
* \param xyz The position of the kart.
|
||||
* \param sector The graph node the position is on.
|
||||
*/
|
||||
@ -325,10 +325,10 @@ void QuadGraph::spatialToTrack(Vec3 *dst, const Vec3& xyz,
|
||||
}
|
||||
|
||||
getNode(sector).getDistances(xyz, dst);
|
||||
float y=dst->getY();
|
||||
y=y-m_offset_for_startline;
|
||||
if(y<0) y+=m_lap_length;
|
||||
dst->setY(y);
|
||||
float z=dst->getZ();
|
||||
z=z-m_offset_for_startline;
|
||||
if(z<0) z+=m_lap_length;
|
||||
dst->setZ(z);
|
||||
} // spatialToTrack
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -167,7 +167,7 @@ btTransform Track::getStartTransform(unsigned int pos) const
|
||||
|
||||
Vec3 orig = pos<m_start_positions.size()
|
||||
? m_start_positions[pos]
|
||||
: Vec3( (pos%2==0)?1.5f:-1.5f, -1.5f*pos-1.5f, 1.0f);
|
||||
: Vec3( (pos%2==0)?1.5f:-1.5f, 1.0f, -1.5f*pos-1.5f);
|
||||
btTransform start;
|
||||
start.setOrigin(orig);
|
||||
start.setRotation(btQuaternion(btVector3(0, 0, 1),
|
||||
@ -392,7 +392,7 @@ void Track::convertTrackToBullet(const scene::IMesh *mesh,
|
||||
int indx=mbIndices[j+k];
|
||||
core::vector3df v = mbVertices[indx].Pos;
|
||||
mat.transformVect(v);
|
||||
vertices[k] = Vec3(v);
|
||||
vertices[k]=v;
|
||||
} // for k
|
||||
if(tmesh) tmesh->addTriangle(vertices[0], vertices[1],
|
||||
vertices[2], material );
|
||||
@ -909,7 +909,7 @@ void Track::itemCommand(const Vec3 &xyz, Item::ItemType type,
|
||||
// i.e. the items will not rotate around the normal, but 'wobble'
|
||||
// around.
|
||||
//Vec3 normal(0.7071f, 0, 0.7071f);
|
||||
Vec3 normal(0, 0, 1);
|
||||
Vec3 normal(0, 1, 0);
|
||||
item_manager->newItem(type, loc, normal);
|
||||
} // itemCommand
|
||||
|
||||
|
@ -56,7 +56,7 @@ public:
|
||||
Coord(const btTransform& t)
|
||||
{
|
||||
m_xyz = t.getOrigin();
|
||||
m_hpr.setHPR(t.getBasis());
|
||||
m_hpr.setHPR(t.getRotation());
|
||||
//setSgCoord();
|
||||
} // Coord
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -21,59 +21,22 @@
|
||||
|
||||
#include "utils/constants.hpp"
|
||||
|
||||
void Vec3::setHPR(const btMatrix3x3& m)
|
||||
|
||||
void Vec3::setHPR(const btQuaternion& q)
|
||||
{
|
||||
float f[4][4];
|
||||
m.getOpenGLSubMatrix((float*)f);
|
||||
float W = q.getW();
|
||||
float X = q.getX();
|
||||
float Y = q.getY();
|
||||
float Z = q.getZ();
|
||||
float WSquared = W * W;
|
||||
float XSquared = X * X;
|
||||
float YSquared = Y * Y;
|
||||
float ZSquared = Z * Z;
|
||||
|
||||
float s = m.getColumn(0).length();
|
||||
|
||||
if ( s <= 0.00001 )
|
||||
{
|
||||
fprintf(stderr,"setHPR: bad matrix\n");
|
||||
setValue(0,0,0);
|
||||
return ;
|
||||
}
|
||||
s=1/s;
|
||||
|
||||
#define CLAMPTO1(x) x<-1 ? -1 : (x>1 ? 1 : x)
|
||||
|
||||
setY(asin(CLAMPTO1(m.getRow(2).getY())));
|
||||
|
||||
float cp = cos(getY());
|
||||
|
||||
/* If pointing nearly vertically up - then heading is ill-defined */
|
||||
|
||||
|
||||
if ( cp > -0.00001 && cp < 0.00001 )
|
||||
{
|
||||
float cr = CLAMPTO1( m.getRow(1).getX()*s);
|
||||
float sr = CLAMPTO1(-m.getRow(1).getZ()*s);
|
||||
|
||||
setX(0.0f);
|
||||
setZ(atan2(sr, cr ));
|
||||
}
|
||||
else
|
||||
{
|
||||
cp = s / cp ; // includes the scaling factor
|
||||
float sr = CLAMPTO1( -m.getRow(2).getX() * cp );
|
||||
float cr = CLAMPTO1( m.getRow(2).getZ() * cp );
|
||||
float sh = CLAMPTO1( -m.getRow(0).getY() * cp );
|
||||
float ch = CLAMPTO1( m.getRow(1).getY() * cp );
|
||||
|
||||
if ( (sh == 0.0f && ch == 0.0f) || (sr == 0.0f && cr == 0.0f) )
|
||||
{
|
||||
cr = CLAMPTO1( m.getRow(1).getX()*s);
|
||||
sr = CLAMPTO1(-m.getRow(1).getZ()*s) ;
|
||||
|
||||
setX(0.0f);
|
||||
}
|
||||
else
|
||||
setX(atan2(sh, ch ));
|
||||
|
||||
setZ(atan2(sr, cr ));
|
||||
}
|
||||
} // setHPR
|
||||
setX(atan2f(2.0f * (Y * Z + X * W), -XSquared - YSquared + ZSquared + WSquared));
|
||||
setY(asinf(-2.0f * (X * Z - Y * W)));
|
||||
setZ(atan2f(2.0f * (X * Y + Z * W), XSquared - YSquared - ZSquared + WSquared));
|
||||
} // setHPR(btQuaternion)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Vec3::degreeToRad()
|
||||
@ -95,8 +58,8 @@ void Vec3::setPitchRoll(const Vec3 &normal)
|
||||
// Compute the angle between the normal of the plane and the line to
|
||||
// (x,y,0). (x,y,0) is normalised, so are the coordinates of the plane,
|
||||
// simplifying the computation of the scalar product.
|
||||
float pitch = ( normal.getX()*X + normal.getY()*Y ); // use ( x,y,0)
|
||||
float roll = (-normal.getX()*Y + normal.getY()*X ); // use (-y,x,0)
|
||||
float pitch = ( normal.getX()*X + normal.getZ()*Y ); // use ( x,y,0)
|
||||
float roll = (-normal.getX()*Y + normal.getZ()*X ); // use (-y,x,0)
|
||||
|
||||
// The actual angle computed above is between the normal and the (x,y,0)
|
||||
// line, so to compute the actual angles 90 degrees must be subtracted.
|
||||
@ -111,18 +74,20 @@ void Vec3::setPitchRoll(const Vec3 &normal)
|
||||
*/
|
||||
const core::vector3df Vec3::toIrrHPR() const
|
||||
{
|
||||
core::vector3df r(RAD_TO_DEGREE*(-getY()), // pitch
|
||||
RAD_TO_DEGREE*(-getX()), // heading
|
||||
RAD_TO_DEGREE*(-getZ()) ); // roll
|
||||
core::vector3df r(RAD_TO_DEGREE*(getX()), // pitch
|
||||
RAD_TO_DEGREE*(getY()), // heading
|
||||
RAD_TO_DEGREE*(getZ()) ); // roll
|
||||
return r;
|
||||
|
||||
} // toIrrHPR
|
||||
// ----------------------------------------------------------------------------
|
||||
const core::vector3df Vec3::toIrrVector() const
|
||||
/** Converts a vec3 into an irrlicht vector (which is a simple type cast).
|
||||
*/
|
||||
const core::vector3df& Vec3::toIrrVector() const
|
||||
{
|
||||
core::vector3df v(m_x, m_z, m_y);
|
||||
return v;
|
||||
return (const core::vector3df&)*this;
|
||||
} // toIrrVector
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns the X and Y component as an irrlicht 2d vector. */
|
||||
const core::vector2df Vec3::toIrrVector2d() const
|
||||
|
@ -40,8 +40,7 @@ public:
|
||||
* axis as well (so a vector3df can be stored in and restored from
|
||||
* a vec3).
|
||||
*/
|
||||
inline Vec3(const core::vector3df &v) : btVector3(v.X, v.Z, v.Y) {}
|
||||
//inline Vec3(sgVec3 a) : btVector3(a[0], a[1], a[2]) {}
|
||||
inline Vec3(const core::vector3df &v) : btVector3(v.X, v.Y, v.Z) {}
|
||||
inline Vec3(const btVector3& a) : btVector3(a) {}
|
||||
inline Vec3() : btVector3() {}
|
||||
inline Vec3(float x, float y, float z) : btVector3(x,y,z) {}
|
||||
@ -54,22 +53,21 @@ public:
|
||||
{m_x=heading;
|
||||
setPitchRoll(normal);}
|
||||
|
||||
void setHPR(const btMatrix3x3& m);
|
||||
inline const float operator[](int n) const {return *(&m_x+n); }
|
||||
inline const float getHeading() const {return m_x; }
|
||||
inline const float getPitch() const {return m_y; }
|
||||
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 setRoll(float f) {m_z = f;}
|
||||
float* toFloat() const {return (float*)this; }
|
||||
void setHPR(const btQuaternion& q);
|
||||
inline const float operator[](int n) const { return *(&m_x+n); }
|
||||
inline const float getHeading() const { return m_x; }
|
||||
inline const float getPitch() const { return m_y; }
|
||||
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 setRoll(float f) { m_z = f; }
|
||||
/** Converts a Vec3 to an irrlicht 3d floating point vector. */
|
||||
const core::vector3df toIrrVector() const;
|
||||
const core::vector3df toIrrHPR() const;
|
||||
const core::vector2df toIrrVector2d() const;
|
||||
void degreeToRad();
|
||||
const core::vector3df& toIrrVector() const;
|
||||
const core::vector3df toIrrHPR() const;
|
||||
const core::vector2df toIrrVector2d() const;
|
||||
void degreeToRad();
|
||||
Vec3& operator=(const btVector3& a) {*(btVector3*)this=a; return *this;}
|
||||
Vec3& operator=(const btMatrix3x3& m) {setHPR(m); return *this;}
|
||||
Vec3& operator=(const btQuaternion& q){setHPR(q); return *this;}
|
||||
Vec3 operator-(const Vec3& v1) const {return (Vec3)(*(btVector3*)this-(btVector3)v1);}
|
||||
/** Helper functions to treat this vec3 as a 2d vector. This returns the
|
||||
* square of the length of the first 2 dimensions. */
|
||||
|
Loading…
Reference in New Issue
Block a user