1) Quad meshes are now easier to use generally

(though still backwards compatible with e.g.
   rubber band and shadow)
2) More scene cleanups.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3756 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2009-07-17 00:22:58 +00:00
parent 5f4b474e77
commit 6706e72311
9 changed files with 72 additions and 46 deletions

View File

@@ -359,36 +359,33 @@ void IrrDriver::renderToTexture(ptr_vector<scene::IMesh, REF>& mesh,
// ----------------------------------------------------------------------------
/** Creates a quad mesh buffer and adds it to the scene graph.
*/
scene::IMesh *IrrDriver::createQuadMesh(const video::SMaterial *material)
scene::IMesh *IrrDriver::createQuadMesh(const video::SMaterial *material,
bool create_one_quad)
{
scene::SMeshBuffer *buffer = new scene::SMeshBuffer();
video::S3DVertex v;
v.Pos = core::vector3df(0,0,0);
// Add the vertices
// ----------------
buffer->Vertices.push_back(v);
buffer->Vertices.push_back(v);
buffer->Vertices.push_back(v);
buffer->Vertices.push_back(v);
if(create_one_quad)
{
video::S3DVertex v;
v.Pos = core::vector3df(0,0,0);
v.Normal = core::vector3df(1/sqrt(2.0f), 1/sqrt(2.0f), 0);
// Define the indices for the triangles
// ------------------------------------
buffer->Indices.push_back(0);
buffer->Indices.push_back(1);
buffer->Indices.push_back(2);
// Add the vertices
// ----------------
buffer->Vertices.push_back(v);
buffer->Vertices.push_back(v);
buffer->Vertices.push_back(v);
buffer->Vertices.push_back(v);
buffer->Indices.push_back(0);
buffer->Indices.push_back(2);
buffer->Indices.push_back(3);
// Define the indices for the triangles
// ------------------------------------
buffer->Indices.push_back(0);
buffer->Indices.push_back(1);
buffer->Indices.push_back(2);
// Set the normals
// ---------------
core::vector3df n(1/sqrt(2.0f), 1/sqrt(2.0f), 0);
buffer->Vertices[0].Normal = n;
buffer->Vertices[1].Normal = n;
buffer->Vertices[2].Normal = n;
buffer->Vertices[3].Normal = n;
buffer->Indices.push_back(0);
buffer->Indices.push_back(2);
buffer->Indices.push_back(3);
}
if(material)
buffer->Material = *material;
SMesh *mesh = new SMesh();

View File

@@ -77,7 +77,8 @@ public:
bool OnEvent(const irr::SEvent &event);
void setAmbientLight(const video::SColor &light);
video::ITexture *getTexture(const std::string &filename);
scene::IMesh *createQuadMesh(const video::SMaterial *material=NULL);
scene::IMesh *createQuadMesh(const video::SMaterial *material=NULL,
bool create_one_quad=false);
scene::ISceneNode *addWaterNode(scene::IMesh *mesh, float wave_height,
float wave_speed, float wave_length);
scene::ISceneNode *addOctTree(scene::IMesh *mesh);

View File

@@ -30,7 +30,7 @@ Shadow::Shadow(const std::string &name)
m.setTexture(0, texture);
m.BackfaceCulling = false;
m.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
m_mesh = irr_driver->createQuadMesh(&m);
m_mesh = irr_driver->createQuadMesh(&m, /*create_one_quad*/true);
m_buffer = m_mesh->getMeshBuffer(0);
irr::video::S3DVertex* v=(video::S3DVertex*)m_buffer->getVertices();
v[0].Pos.X = -1.0f; v[0].Pos.Z = 1.0f; v[0].Pos.Y = 0.01f;

View File

@@ -116,7 +116,15 @@ void RaceGUI::drawMap ()
{
// arenas currently don't have a map.
if(RaceManager::getTrack()->isArena()) return;
const video::ITexture *t=RaceManager::getTrack()->getMiniMap();
core::rect<s32> dest(10, UserConfigParams::m_height-60,
60, UserConfigParams::m_height-10);
core::rect<s32> source(core::position2di(0, 0), t->getOriginalSize());
irr_driver->getVideoDriver()->draw2DImage(t, dest, source, 0, 0, true);
return;
glDisable ( GL_TEXTURE_2D ) ;
assert(RaceManager::getWorld() != NULL);
int xLeft = 10;

View File

@@ -46,7 +46,7 @@ RubberBand::RubberBand(Plunger *plunger, const Kart &kart) :
m.DiffuseColor = color;
m.EmissiveColor = color;
m.BackfaceCulling = false;
m_mesh = irr_driver->createQuadMesh(&m);
m_mesh = irr_driver->createQuadMesh(&m, /*create_one_quad*/ true);
m_buffer = m_mesh->getMeshBuffer(0);
m_attached_state = RB_TO_PLUNGER;
assert(m_buffer->getVertexType()==video::EVT_STANDARD);

View File

@@ -163,40 +163,35 @@ void QuadGraph::createDebugMesh()
m_mesh_buffer = m_mesh->getMeshBuffer(0);
assert(m_mesh_buffer->getVertexType()==video::EVT_STANDARD);
video::S3DVertex* v=(video::S3DVertex*)m_mesh_buffer->getVertices();
// The mesh buffer already contains one quad, so set the coordinates
// of the first quad in there.
video::SColor c(255, 255, 0, 0);
m_all_quads->getQuad(0).setVertices(v, c);
video::SColor c(255, 255, 0, 0);
unsigned int n = m_all_quads->getNumberOfQuads();
// Four vertices for each of the n-1 remaining quads
video::S3DVertex *new_v = new video::S3DVertex[(n-1)*4];
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-1)*6];
irr::u16 *ind = new irr::u16[n*6];
// Now add all other quads
for(unsigned int i=1; i<n; i++)
for(unsigned int i=0; i<n; i++)
{
// Swap the colours from red to blue and back
c.setRed (i%2 ? 255 : 0);
c.setBlue(i%2 ? 0 : 255);
// Transfer the 4 points of the current quad to the list of vertices
m_all_quads->getQuad(i).setVertices(new_v+(4*i-4), c);
m_all_quads->getQuad(i).setVertices(new_v+4*i, c);
// Set up the indices for the triangles
// (note, afaik with opengl we could use quads directly, but the code
// would not be portable to directx anymore).
ind[6*i-6] = 4*i-4; // First triangle: vertex 0, 1, 2
ind[6*i-5] = 4*i-3;
ind[6*i-4] = 4*i-2;
ind[6*i-3] = 4*i-4; // second triangle: vertex 0, 1, 3
ind[6*i-2] = 4*i-2;
ind[6*i-1] = 4*i-1;
ind[6*i ] = 4*i; // First triangle: vertex 0, 1, 2
ind[6*i+1] = 4*i+1;
ind[6*i+2] = 4*i+2;
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;
} // for i=1; i<m_all_quads
m_mesh_buffer->append(new_v, (n-1)*4, ind, (n-1)*6);
m_mesh_buffer->append(new_v, n*4, ind, n*6);
// Instead of setting the bounding boxes, we could just disable culling,
// since the debug track should always be drawn.
//m_node->setAutomaticCulling(scene::EAC_OFF);
@@ -205,6 +200,15 @@ void QuadGraph::createDebugMesh()
m_node = irr_driver->addMesh(m_mesh);
} // createDebugMesh
// -----------------------------------------------------------------------------
/** Removes the debug mesh from the scene.
*/
void QuadGraph::cleanupDebugMesh()
{
irr_driver->removeNode(m_node);
irr_driver->removeMesh(m_mesh);
} // cleanupDebugMesh
// -----------------------------------------------------------------------------
/** Returns the list of successors or a node.
* \param node_number The number of the node.
@@ -382,11 +386,21 @@ video::ITexture *QuadGraph::makeMiniMap(const core::dimension2di &dimension,
video::ITexture *texture =
irr_driver->getVideoDriver()->addTexture(dimension, name.c_str());
// FIXME: all very much work in progress, only committed as a backup
// (and to include the debug cleanup)
createDebugMesh();
scene::IMesh *mesh = irr_driver->createQuadMesh();
for(unsigned int i=0; i<m_all_nodes.size(); i++)
scene::IMeshBuffer *buffer = mesh->getMeshBuffer(0);
unsigned int n = m_all_nodes.size();
for(unsigned int i=0; i<n; i++)
{
const Quad &q=m_all_quads->getQuad(m_all_nodes[i]->getIndex());
}
irr_driver->removeMesh(mesh);
const std::string f=file_manager->getTrackFile("waterfall.png", "beach");
return irr_driver->getTexture(f);
return texture;
} // drawMiniMap

View File

@@ -50,6 +50,7 @@ public:
const std::string graph_file_name);
~QuadGraph ();
void createDebugMesh();
void cleanupDebugMesh();
void getSuccessors(int quadNumber,
std::vector<unsigned int>& succ) const;
void spatialToTrack(Vec3 *dst, const Vec3& xyz,

View File

@@ -106,6 +106,9 @@ void Track::reset()
*/
void Track::cleanup()
{
if(UserConfigParams::m_track_debug)
m_quad_graph->cleanupDebugMesh();
item_manager->cleanup();
for(unsigned int i=0; i<m_animated_textures.size(); i++)
{

View File

@@ -161,6 +161,8 @@ public:
~Track ();
bool isArena () const { return m_is_arena; }
void cleanup ();
/** Returns the texture with the mini map for this track. */
const video::ITexture*getMiniMap () const { return m_mini_map; }
void draw2Dview (float x_offset,
float y_offset ) const;
void drawScaled2D (float x, float y, float w,