Added support for invisible driveline-segments.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@4011 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -24,12 +24,14 @@
|
||||
#include "LinearMath/btTransform.h"
|
||||
|
||||
/** Constructor, takes 4 points. */
|
||||
Quad::Quad(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2, const Vec3 &p3)
|
||||
Quad::Quad(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2, const Vec3 &p3,
|
||||
bool invisible)
|
||||
{
|
||||
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_invisible = invisible;
|
||||
} // Quad
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -40,10 +40,14 @@ private:
|
||||
/** The minimum height of the quad, used in case that several quads
|
||||
* are on top of each other when determining the sector a kart is on. */
|
||||
float m_min_height;
|
||||
float sideOfLine2D(const Vec3& l1, const Vec3& l2, const Vec3& p) const;
|
||||
|
||||
/** Set to true if this quad should not be shown in the minimap. */
|
||||
bool m_invisible;
|
||||
|
||||
float sideOfLine2D(const Vec3& l1, const Vec3& l2, const Vec3& p) const;
|
||||
public:
|
||||
Quad(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2, const Vec3 &p3);
|
||||
Quad(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2, const Vec3 &p3,
|
||||
bool invis=false);
|
||||
void getVertices(video::S3DVertex *v, const video::SColor &color) const;
|
||||
bool pointInQuad(const Vec3& p) const;
|
||||
void transform(const btTransform &t, Quad *result) const;
|
||||
@@ -56,5 +60,9 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the minimum height of a quad. */
|
||||
float getMinHeight() const { return m_min_height; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true of this quad is invisible, i.e. not to be shown in
|
||||
* the minimap. */
|
||||
bool isInvisible() const { return m_invisible; }
|
||||
}; // class Quad
|
||||
#endif
|
||||
|
||||
@@ -162,7 +162,7 @@ void QuadGraph::setDefaultSuccessors()
|
||||
/** Creates a mesh for this graph. The mesh is not added to a scene node and
|
||||
* is stored in m_mesh.
|
||||
*/
|
||||
void QuadGraph::createMesh()
|
||||
void QuadGraph::createMesh(bool show_invisible)
|
||||
{
|
||||
// The debug track will not be lighted or culled.
|
||||
video::SMaterial m;
|
||||
@@ -172,17 +172,26 @@ void QuadGraph::createMesh()
|
||||
m_mesh_buffer = m_mesh->getMeshBuffer(0);
|
||||
assert(m_mesh_buffer->getVertexType()==video::EVT_STANDARD);
|
||||
|
||||
video::SColor c(255, 255, 0, 0);
|
||||
unsigned int n = m_all_quads->getNumberOfQuads();
|
||||
// Count the number of quads to display (some quads might be invisible
|
||||
unsigned int n = 0;
|
||||
for(unsigned int i=0; i<m_all_quads->getNumberOfQuads(); i++)
|
||||
if(show_invisible || !m_all_quads->getQuad(i).isInvisible())
|
||||
n++;
|
||||
|
||||
// Four vertices for each of the n-1 remaining quads
|
||||
video::S3DVertex *new_v = new video::S3DVertex[n*4];
|
||||
// Each quad consists of 2 triangles with 3 elements, so
|
||||
// we need 2*3 indices for each quad.
|
||||
irr::u16 *ind = new irr::u16[n*6];
|
||||
video::SColor c(255, 255, 0, 0);
|
||||
|
||||
// Now add all quads
|
||||
for(unsigned int i=0; i<n; i++)
|
||||
int i=0;
|
||||
for(unsigned int count=0; count<m_all_quads->getNumberOfQuads(); count++)
|
||||
{
|
||||
// Ignore invisible quads
|
||||
if(!show_invisible && m_all_quads->getQuad(count).isInvisible())
|
||||
continue;
|
||||
// Swap the colours from red to blue and back
|
||||
c.setRed (i%2 ? 255 : 0);
|
||||
c.setBlue(i%2 ? 0 : 255);
|
||||
@@ -198,6 +207,7 @@ void QuadGraph::createMesh()
|
||||
ind[6*i+3] = 4*i; // second triangle: vertex 0, 1, 3
|
||||
ind[6*i+4] = 4*i+2;
|
||||
ind[6*i+5] = 4*i+3;
|
||||
i++;
|
||||
} // for i=1; i<m_all_quads
|
||||
|
||||
m_mesh_buffer->append(new_v, n*4, ind, n*6);
|
||||
@@ -455,8 +465,8 @@ video::ITexture *QuadGraph::makeMiniMap(const core::dimension2di &dimension,
|
||||
m_scaling.setX(dimension.Width/(bb_max.getX()-bb_min.getX()));
|
||||
m_scaling.setY(dimension.Width/(bb_max.getY()-bb_min.getY()));
|
||||
return texture;
|
||||
|
||||
} // drawMiniMap
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Returns the 2d coordinates of a point when drawn on the mini map
|
||||
* texture.
|
||||
|
||||
@@ -52,7 +52,7 @@ private:
|
||||
|
||||
void setDefaultSuccessors();
|
||||
void load (const std::string &filename);
|
||||
void createMesh();
|
||||
void createMesh(bool show_invisible=true);
|
||||
public:
|
||||
static const int UNKNOWN_SECTOR;
|
||||
|
||||
|
||||
@@ -83,7 +83,9 @@ void QuadSet::load(const std::string &filename) {
|
||||
getPoint(xml_node, "p1", &p1);
|
||||
getPoint(xml_node, "p2", &p2);
|
||||
getPoint(xml_node, "p3", &p3);
|
||||
Quad* q=new Quad(p0,p1,p2,p3);
|
||||
bool invisible=false;
|
||||
xml_node->get("invisible", &invisible);
|
||||
Quad* q=new Quad(p0,p1,p2,p3, invisible);
|
||||
m_all_quads.push_back(q);
|
||||
m_max.max(p0);m_max.max(p1);m_max.max(p2);m_max.max(p3);
|
||||
m_min.min(p0);m_min.min(p1);m_min.min(p2);m_min.min(p3);
|
||||
|
||||
Reference in New Issue
Block a user