Added initial support for bezier curves to be exported from blender

and imported into stk (though they are not used for anything atm).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3641 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-06-24 01:27:05 +00:00
parent 09ce7366c8
commit 238b401cc2
6 changed files with 159 additions and 12 deletions

View File

@ -220,6 +220,8 @@ supertuxkart_SOURCES = \
replay/replay_recorder.hpp \
robots/default_robot.cpp \
robots/default_robot.hpp \
tracks/bezier_curve.cpp \
tracks/bezier_curve.hpp \
tracks/graph_node.cpp\
tracks/graph_node.hpp\
tracks/quad.cpp \

View File

@ -576,6 +576,10 @@
<Filter
Name="tracks"
>
<File
RelativePath="..\..\tracks\bezier_curve.cpp"
>
</File>
<File
RelativePath="..\..\tracks\graph_node.cpp"
>
@ -1158,6 +1162,10 @@
<Filter
Name="tracks"
>
<File
RelativePath="..\..\tracks\bezier_curve.hpp"
>
</File>
<File
RelativePath="..\..\tracks\graph_node.hpp"
>

View File

@ -0,0 +1,61 @@
// $Id: bezier.cpp 3606 2009-06-11 10:00:43Z hikerstk $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "tracks/bezier_curve.hpp"
#include "io/xml_node.hpp"
BezierCurve::BezierCurve(const XMLNode &node)
{
for(unsigned int i=0; i<node.getNumNodes(); i++)
{
const XMLNode *p = node.getNode(i);
BezierData b;
p->get("c", &b.m_control_point);
p->get("h1", &b.m_handle1);
p->get("h2", &b.m_handle2);
m_all_data.push_back(b);
} // for i<node.getNumNodes()
} // BezierCurve
// ----------------------------------------------------------------------------
Vec3 BezierCurve::getXYZ(float t) const
{
unsigned int i=int(t); // FIXME: have to figure out which point we want here
if(i>=m_all_data.size()-1) return m_all_data[i].m_control_point;
const BezierData &p0 = m_all_data[i];
const BezierData &p1 = m_all_data[i+1];
Vec3 c = 3*(p0.m_handle2-p0.m_control_point);
Vec3 b = 3*(p1.m_handle1-p0.m_handle2)-c;
Vec3 a = p1.m_control_point - p0.m_control_point - c - b;
t = t-i;
Vec3 r = a*t*t*t + b*t*t + c*t + p0.m_control_point;
return r;
} // getXYZ
// ----------------------------------------------------------------------------
Vec3 BezierCurve::getHPR(float t) const
{
// FIXME: not yet implemented
Vec3 hpr;
return hpr;
} // getHPR

View File

@ -0,0 +1,59 @@
// $Id: bezier.hpp 3527 2009-05-22 03:23:48Z hikerstk $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_BEZIER_HPP
#define HEADER_BEZIER_HPP
#include <vector>
#include "utils/vec3.hpp"
class XMLNode;
/** A class to manage bezier curves and interpolation.
*/
class BezierCurve
{
private:
/** A data structure to store one bezier control point and
* the two handles. */
struct BezierData
{
/** The control point. */
Vec3 m_control_point;
/** First handle, i.e. the one towards the previous point. */
Vec3 m_handle1;
/** Second handle, i.e. the one towards the next point. */
Vec3 m_handle2;
}; // BezierData
/** Overall duration. */
float m_time;
/** Vector with all control points and handles. */
std::vector<BezierData> m_all_data;
public:
BezierCurve(const XMLNode &node);
Vec3 getXYZ(float t) const;
Vec3 getHPR(float t) const;
/** Returns the number of points in this bezier curve. */
unsigned int getNumPoints() const {return m_all_data.size(); }
}; // BezierCurve
#endif

View File

@ -44,6 +44,7 @@ using namespace irr;
#include "physics/physical_object.hpp"
#include "physics/triangle_mesh.hpp"
#include "race/race_manager.hpp"
#include "tracks/bezier_curve.hpp"
#include "tracks/quad_graph.hpp"
#include "tracks/quad_set.hpp"
#include "utils/string_utils.hpp"
@ -515,12 +516,34 @@ void Track::loadTrack(const std::string &filename)
}
} // if sky-box
// Set the correct paths
xml_node = root->getNode("curves");
if(xml_node)
loadCurves(*xml_node);
// Set the correct paths
m_screenshot = file_manager->getTrackFile(m_screenshot, getIdent());
delete root;
} // loadTrack
//-----------------------------------------------------------------------------
void Track::loadCurves(const XMLNode &node)
{
for(unsigned int i=0; i<node.getNumNodes(); i++)
{
const XMLNode *curve = node.getNode(i);
m_all_curves.push_back(new BezierCurve(*curve));
float t=0;
const BezierCurve &c=*m_all_curves[m_all_curves.size()-1];
while(t<=c.getNumPoints()-0.9998) // allow for some rounding errors
{
Vec3 xyz = c.getXYZ(t);
printf("t %f xyz %f %f %f\n", t, xyz.getX(),xyz.getY(),xyz.getZ());
t=t+0.1f;
}
} // for i<node.getNumNodes
} // loadCurves
//-----------------------------------------------------------------------------
void Track::getMusicInformation(std::vector<std::string>& filenames,
std::vector<MusicInformation*>& music )

View File

@ -45,6 +45,7 @@ class TriangleMesh;
class MovingTexture;
class XMLNode;
class PhysicalObject;
class BezierCurve;
class Track
{
@ -97,20 +98,13 @@ private:
/** If a sky dome is used, percentage of the texture to be used. */
float m_sky_texture_percent;
/** List of all bezier curves in the track - for e.g. camera, ... */
std::vector<BezierCurve*> m_all_curves;
void loadCurves(const XMLNode &node);
void handleAnimatedTextures(scene::ISceneNode *node, const XMLNode &xml);
public:
struct SegmentTriangle
{
int segment;
int triangle;
SegmentTriangle
(
int _segment,
int _triangle
) : segment(_segment), triangle(_triangle) {};
};
std::string m_name;
bool m_use_fog;