The default start positions are now transformed/rotated if the lap

counting line is not centered around 0,0,0 or not parallel to the
X axis.
Note that this requires all lap counting line in the scene.xml files
to be 'oriented', i.e. the first point must be the left point, and
the second one the right point (r5488 updated this for all current
tracks, and r5487 updated the track exporter to do this automatically).
As a result of this the start positions might now be a bit too close
to the starting line (depending on where the chess-pattern is on the
track), and that might need some additional adjustments.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5490 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2010-06-08 23:30:45 +00:00
parent b9a63ebb0d
commit 744d9dd0fb
5 changed files with 65 additions and 10 deletions

View File

@@ -448,8 +448,8 @@ void World::update(float dt)
// the order of karts will be incorrect, since this kart will not
// have started the next lap. While this will only last for one
// frame (since in the next frame the check manager will detect
// the new lap), it causes an unwanted display of icons in the
// icon display.
// the new lap), it causes an incorrect display of icons in the
// icon display for this one frame.
m_track->update(dt);
projectile_manager->update(dt);

View File

@@ -59,6 +59,8 @@ public:
virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx);
virtual void reset(const Track &track);
virtual Vec3 getCenterPoint() const;
/** Returns the actual line data for this checkpoint. */
const core::line2df &getLine2D() const {return m_line;}
}; // CheckLine
#endif

View File

@@ -40,6 +40,7 @@ CheckManager::CheckManager(const XMLNode &node, Track *track)
if(cl->getType()==CheckStructure::CT_NEW_LAP)
{
track->getQuadGraph().setStartCoordinate(*cl);
track->setStartCoordinates(cl->getLine2D());
}
} // checkline
else if(type=="check-sphere")

View File

@@ -55,14 +55,14 @@ using namespace irr;
const float Track::NOHIT = -99999.9f;
btTransform global_start;
// ----------------------------------------------------------------------------
Track::Track(std::string filename)
{
m_filename = filename;
m_root = StringUtils::getPath(StringUtils::removeExtension(m_filename));
m_ident = StringUtils::getBasename(m_root);
m_item_style = "";
//m_description = "";
m_designer = "";
m_screenshot = "";
m_version = 0;
@@ -75,6 +75,8 @@ Track::Track(std::string filename)
m_quad_graph = NULL;
m_animation_manager = NULL;
m_check_manager = NULL;
m_start_angle = 0;
m_start_transform.setIdentity();
loadTrackInfo();
} // Track
@@ -157,22 +159,60 @@ const Vec3& Track::trackToSpatial(const int sector) const
return m_quad_graph->getQuad(sector).getCenter();
} // trackToSpatial
//-----------------------------------------------------------------------------
/** This function determines the linear transform and rotation for the start
* coordinates in order to line up propery behind the specified start line.
* The transform and rotation is saved in a matrix and applied to all
* start coordinates later on, see getStartTransform().
* \param line The start line.
*/
void Track::setStartCoordinates(const core::line2df& line)
{
core::vector2df start = line.start;
core::vector2df end = line.end;
m_start_angle = -atan2(end.Y - start.Y,
end.X - start.X);
core::vector2df mid = (start+end)*0.5f;
btQuaternion q(Vec3(0, 1, 0), m_start_angle);
global_start.setRotation(q);
global_start.setOrigin(Vec3(mid.X, 0, mid.Y));
} // setStartCoordinates
//-----------------------------------------------------------------------------
/** Returns the start coordinates for a kart on a given position pos
(with pos ranging from 0 to kart_num-1).
*/
btTransform Track::getStartTransform(unsigned int pos) const
{
Vec3 orig;
float angle;
if(pos<m_start_positions.size())
{
orig = m_start_positions[pos];
angle = 0;
}
else
{
// Distance from middle of start line in X direction.
// +-X_DIST is used to place the karts left/right
const float X_DIST = 1.5f;
// Distance from start line in Z direction.
const float Z_DIST_FROM_START = 1.5f;
const float Z_DIST = 1.5f;
orig = Vec3( X_DIST * (pos%2==0) ? 1.0f : -1.0f,
1.0f,
-Z_DIST*pos-Z_DIST_FROM_START);
orig = global_start(orig);
angle = m_start_angle;
}
Vec3 orig = pos<m_start_positions.size()
? m_start_positions[pos]
: 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, 1, 0),
pos<m_start_heading.size()
? DEGREE_TO_RAD*m_start_heading[pos]
: 0.0f ));
: angle ));
return start;
} // getStartTransform
@@ -208,7 +248,6 @@ void Track::loadTrackInfo()
std::vector<std::string> filenames;
root->get("music", &filenames);
getMusicInformation(filenames, m_music);
root->get("item", &m_item_style);
root->get("screenshot", &m_screenshot);
root->get("gravity", &m_gravity);
root->get("arena", &m_is_arena);

View File

@@ -65,8 +65,21 @@ private:
std::vector<MusicInformation*> m_music;
/** Start heading of karts (if specified in the scene file). */
std::vector<float> m_start_heading;
/** Start positions of karts (if specified in the scene file). */
std::vector<Vec3> m_start_positions;
/** A transform which is applied to the default start coordinates
* (i.e. only if no start coordinates are defined for the track).
* This is used to position the karts in case that the lap counting
* line is not centered around (0,0,0), or rotated. */
btTransform m_start_transform;
/** The explicit angle of the lap counting line. This angle can
* not be easily deduced from m_start_transform (problem with the
* sign), so it is saved additionally so that karts can be rotated
* properly if no explicit start positions are given. */
float m_start_angle;
std::string m_item_style;
std::string m_description;
std::string m_designer;
@@ -223,7 +236,6 @@ public:
/** Returns an absolute path to the screenshot file of this track */
const std::string& getScreenshotFile () const {return m_screenshot; }
const std::string& getItemStyle () const {return m_item_style; }
btTransform getStartTransform (unsigned int pos) const;
void getTerrainInfo(const Vec3 &pos, float *hot, Vec3* normal,
const Material **material) const;
@@ -232,6 +244,7 @@ public:
void update(float dt);
void reset();
void adjustForFog(scene::ISceneNode *node);
void setStartCoordinates(const core::line2df& line);
void handleExplosion(const Vec3 &pos, const PhysicalObject *mp) const;
/** Sets pointer to the aabb of this track. */
void getAABB(const Vec3 **min, const Vec3 **max) const