From: <au...@us...> - 2010-12-09 01:22:28
|
Revision: 6908 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=6908&view=rev Author: auria Date: 2010-12-09 01:22:22 +0000 (Thu, 09 Dec 2010) Log Message: ----------- Fixed rare crash with explosions, when m_remaining_time is exactly equal to explosion_time Modified Paths: -------------- main/trunk/src/graphics/explosion.cpp main/trunk/src/graphics/explosion.hpp Modified: main/trunk/src/graphics/explosion.cpp =================================================================== --- main/trunk/src/graphics/explosion.cpp 2010-12-09 01:22:01 UTC (rev 6907) +++ main/trunk/src/graphics/explosion.cpp 2010-12-09 01:22:22 UTC (rev 6908) @@ -30,7 +30,7 @@ const float burst_time = 0.1f; Explosion::Explosion(const Vec3& coord, const char* explosion_sound) -{ +{ m_remaining_time = burst_time; // short emision time, explosion, not constant flame m_node = irr_driver->addParticleNode(); #ifdef DEBUG @@ -137,6 +137,7 @@ { // Sound and animation finished --> remove node irr_driver->removeNode(m_node); + m_node = NULL; projectile_manager->FinishedExplosion(); return; } Modified: main/trunk/src/graphics/explosion.hpp =================================================================== --- main/trunk/src/graphics/explosion.hpp 2010-12-09 01:22:01 UTC (rev 6907) +++ main/trunk/src/graphics/explosion.hpp 2010-12-09 01:22:22 UTC (rev 6908) @@ -39,14 +39,14 @@ SFXBase* m_explode_sound; float m_remaining_time; scene::IParticleSystemSceneNode *m_node; - + public: Explosion(const Vec3& coord, const char* explosion_sound); ~Explosion(); void init (const Vec3& coord); void update (float delta_t); int inUse (); - bool hasEnded () { return m_remaining_time < -explosion_time; } + bool hasEnded () { return m_remaining_time <= -explosion_time; } } ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2010-12-15 22:53:06
|
Revision: 7030 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7030&view=rev Author: hikerstk Date: 2010-12-15 22:52:59 +0000 (Wed, 15 Dec 2010) Log Message: ----------- Fixed line endings. Modified Paths: -------------- main/trunk/src/graphics/CBatchingMesh.cpp main/trunk/src/graphics/CBatchingMesh.hpp Modified: main/trunk/src/graphics/CBatchingMesh.cpp =================================================================== --- main/trunk/src/graphics/CBatchingMesh.cpp 2010-12-15 22:50:17 UTC (rev 7029) +++ main/trunk/src/graphics/CBatchingMesh.cpp 2010-12-15 22:52:59 UTC (rev 7030) @@ -1,508 +1,508 @@ - -#include "graphics/CBatchingMesh.hpp" - -namespace irr -{ -namespace scene -{ - -CBatchingMesh::CBatchingMesh() - : Box(core::vector3df(0,0,0)), IsDirty(false), IsFinal(false) -{ - -} - -CBatchingMesh::~CBatchingMesh() -{ - u32 i; - for (i=0; i < DestBuffers.size(); ++i) - DestBuffers[i].Buffer->drop(); - - for (i=0; i < SourceBuffers.size(); ++i) - SourceBuffers[i]->drop(); -} - -bool CBatchingMesh::isDirty(s32 id) -{ - if ((u32)id > DestBuffers.size()) - return IsDirty; - else - return DestBuffers[id].IsDirty; -} - -//! refreshes the internal buffers from source -void CBatchingMesh::update() -{ - // allocate the index and vertex arrays - u32 i; - for (i=0; i<DestBuffers.size(); ++i) - { - if (DestBuffers[i].IndexCount != DestBuffers[i].Buffer->getIndexCount() || - DestBuffers[i].VertexCount != DestBuffers[i].Buffer->getVertexCount()) - { - DestBuffers[i].IsDirty = true; - - switch (DestBuffers[i].VertexType) - { - case video::EVT_STANDARD: - { - SMeshBuffer* mb = (SMeshBuffer*)DestBuffers[i].Buffer; - mb->Vertices.set_used(DestBuffers[i].VertexCount); - mb->Indices.set_used(DestBuffers[i].IndexCount); - break; - } - case video::EVT_2TCOORDS: - { - SMeshBufferLightMap* mb = (SMeshBufferLightMap*)DestBuffers[i].Buffer; - mb->Vertices.set_used(DestBuffers[i].VertexCount); - mb->Indices.set_used(DestBuffers[i].IndexCount); - break; - } - case video::EVT_TANGENTS: - { - SMeshBufferTangents* mb = (SMeshBufferTangents*)DestBuffers[i].Buffer; - mb->Vertices.set_used(DestBuffers[i].VertexCount); - mb->Indices.set_used(DestBuffers[i].IndexCount); - break; - } - default: // shouldn't ever happen - continue; - } - } - } - - // refresh dirty buffers from source - for (i=0; i<BufferReferences.size(); ++i) - { - if (DestBuffers[BufferReferences[i].DestReference].IsDirty) - { - updateDestFromSourceBuffer(i); - } - } - - // calculate bounding boxes - for (i=0; i< DestBuffers.size(); ++i) - { - if (DestBuffers[i].IsDirty) - { - recalculateDestBufferBoundingBox(i); - // reset dirty state too - DestBuffers[i].IsDirty = false; - } - } - - IsDirty = false; - recalculateBoundingBox(); -} - -//! adds a mesh to the buffers with the given offset -/** \Returns Returns an array of ID numbers */ -core::array<s32> CBatchingMesh::addMesh(IMesh* mesh, core::vector3df pos, core::vector3df rot, core::vector3df scale) -{ - core::matrix4 m; - m.setRotationDegrees(rot); - m.setTranslation(pos); - - core::matrix4 scalem; - scalem.setScale(scale); - m *= scalem; - - return addMesh(mesh, m); -} - -//! adds a mesh with the given transformation -core::array<s32> CBatchingMesh::addMesh(IMesh* mesh, const core::matrix4 &transform) -{ - core::array<s32> bufferNos; - - if (!mesh) - return bufferNos; - - u32 i; - for (i=0; i<mesh->getMeshBufferCount(); ++i) - bufferNos.push_back(addMeshBuffer(mesh->getMeshBuffer(i), transform)); - - return bufferNos; -} - -//! adds a mesh buffer with the given transformation -/** \Return Returns the ID of this mesh buffer */ -s32 CBatchingMesh::addMeshBuffer(IMeshBuffer* buffer, core::vector3df pos, core::vector3df rot, core::vector3df scale) -{ - core::matrix4 m; - m.setRotationDegrees(rot); - m.setTranslation(pos); - - core::matrix4 scalem; - scalem.setScale(scale); - m *= scalem; - - return addMeshBuffer(buffer, m); -} - -//! adds a mesh with the given transformation -/** \Return Returns the ID of this mesh buffer */ -s32 CBatchingMesh::addMeshBuffer(IMeshBuffer* buffer, const core::matrix4 &transform) -{ - if (!buffer || IsFinal) - return -1; - - u32 i; - video::SMaterial m = buffer->getMaterial(); - - // find material - bool found=false; - video::E_VERTEX_TYPE vt = buffer->getVertexType(); - for (i=0; i<MaterialReferences.size(); ++i) - { - if (MaterialReferences[i].VertexType == vt && - MaterialReferences[i].Material == m) - { - // will there be too many vertices in the buffer? - u32 newTotalI = buffer->getIndexCount() + DestBuffers[ MaterialReferences[i].BufferIndex ].IndexCount; - u32 newTotalV = buffer->getVertexCount() + DestBuffers[ MaterialReferences[i].BufferIndex ].VertexCount; - - if ( newTotalI < 65536*3 && newTotalV < 65536) - { - found = true; - DestBuffers[ MaterialReferences[i].BufferIndex ].IndexCount = newTotalI; - DestBuffers[ MaterialReferences[i].BufferIndex ].VertexCount = newTotalV; - break; - } - } - } - - if (!found) - { - // we need a new destination buffer and material reference - IMeshBuffer *mb=0; - - SMaterialReference r; - r.Material = m; - r.VertexType = vt; - r.BufferIndex = DestBuffers.size(); - switch (vt) - { - case video::EVT_STANDARD: - mb = (IMeshBuffer*)new SMeshBuffer(); - mb->getMaterial() = m; - break; - case video::EVT_2TCOORDS: - mb = (IMeshBuffer*)new SMeshBufferLightMap(); - mb->getMaterial() = m; - break; - case video::EVT_TANGENTS: - mb = (IMeshBuffer*)new SMeshBufferTangents(); - mb->getMaterial() = m; - break; - default: // unknown vertex type - return -1; - } - i = MaterialReferences.size(); - MaterialReferences.push_back(r); - - SDestBufferReference db; - db.Buffer = mb; - db.IndexCount = buffer->getIndexCount(); - db.VertexCount = buffer->getVertexCount(); - db.IsDirty = true; - db.VertexType = vt; - - DestBuffers.push_back(db); - } - // now we add the mesh reference - SBufferReference r; - r.DestReference = i; - r.SourceBuffer = buffer; - r.Transform = transform; - r.IndexCount = buffer->getIndexCount(); - r.VertexCount = buffer->getVertexCount(); - r.FirstIndex = DestBuffers[ MaterialReferences[i].BufferIndex ].IndexCount - r.IndexCount; - r.FirstVertex = DestBuffers[ MaterialReferences[i].BufferIndex ].VertexCount - r.VertexCount; - r.Initialized = false; - BufferReferences.push_back(r); - addSourceBuffer(buffer); - - IsDirty = true; - return BufferReferences.size()-1; -} - -//! updates bouding box from internal buffers -void CBatchingMesh::recalculateBoundingBox() -{ - if (DestBuffers.size() == 0) - Box.reset(0,0,0); - else - { - Box.reset(DestBuffers[0].Buffer->getBoundingBox().MinEdge); - - u32 i; - for (i=0; i < DestBuffers.size(); ++i) - Box.addInternalBox(DestBuffers[i].Buffer->getBoundingBox()); - } -} - - -/* Standard IMesh functions */ - -//! Returns the amount of mesh buffers. -/** \return Returns the amount of mesh buffers (IMeshBuffer) in this mesh. */ -u32 CBatchingMesh::getMeshBufferCount() const -{ - return DestBuffers.size(); -} - -//! Returns pointer to a mesh buffer. -/** \param nr: Zero based index of the mesh buffer. The maximum value is -getMeshBufferCount() - 1; -\return Returns the pointer to the mesh buffer or -NULL if there is no such mesh buffer. */ -IMeshBuffer* CBatchingMesh::getMeshBuffer(u32 nr) const -{ - if (nr < DestBuffers.size()) - return DestBuffers[nr].Buffer; - else - return 0; -} - -//! Returns pointer to a mesh buffer which fits a material -IMeshBuffer* CBatchingMesh::getMeshBuffer( const video::SMaterial &material) const -{ - return 0; -} - -//! Returns an axis aligned bounding box of the mesh. -/** \return A bounding box of this mesh is returned. */ -const core::aabbox3d<f32>& CBatchingMesh::getBoundingBox() const -{ - return Box; -} - -//! set user axis aligned bounding box -void CBatchingMesh::setBoundingBox( const core::aabbox3df& box) -{ - Box = box; -} - -//! Sets a flag of all contained materials to a new value. -/** \param flag: Flag to set in all materials. - \param newvalue: New value to set in all materials. */ -void CBatchingMesh::setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) -{ - for (u32 i=0; i<DestBuffers.size(); ++i) - DestBuffers[i].Buffer->getMaterial().setFlag(flag, newvalue); -} - -//! drops all buffers and clears internal states -void CBatchingMesh::clear() -{ - u32 i; - for (i=0; i < DestBuffers.size(); ++i) - DestBuffers[i].Buffer->drop(); - - for (i=0; i < SourceBuffers.size(); ++i) - SourceBuffers[i]->drop(); - - BufferReferences.clear(); - MaterialReferences.clear(); - DestBuffers.clear(); - SourceBuffers.clear(); - - IsDirty = false; - IsFinal = false; -} - -//! first updates the mesh, then drops all source buffers. -/** once this mesh has been finalized, it cannot be changed again! */ -void CBatchingMesh::finalize() -{ - update(); - - for (u32 i=0; i < SourceBuffers.size(); ++i) - SourceBuffers[i]->drop(); - - SourceBuffers.clear(); - - IsFinal = true; -} - -//! Moves a mesh -core::array<bool> CBatchingMesh::moveMesh(const core::array<s32>& bufferIDs, const core::matrix4 &newMatrix) -{ - core::array<bool> result; - result.reallocate(bufferIDs.size()); - for (u32 i=0; i<bufferIDs.size(); ++i) - result.push_back(moveMeshBuffer(bufferIDs[i], newMatrix)); - - return result; -} - - -//! Moves a mesh buffer -bool CBatchingMesh::moveMeshBuffer(const s32 id, const core::matrix4 &newMatrix) -{ - if ((u32)id > BufferReferences.size() || IsFinal ) - return false; - - BufferReferences[id].Transform = newMatrix; - - // is the source buffer dirty? - if (!DestBuffers[BufferReferences[id].DestReference].IsDirty) - { - // transform each vertex and normal - updateDestFromSourceBuffer(id); - recalculateDestBufferBoundingBox(BufferReferences[id].DestReference); - } - return true; -} - - -//! returns the source buffer, if available -IMeshBuffer* CBatchingMesh::getSourceBuffer(s32 id) -{ - if ((u32)id > BufferReferences.size() || IsFinal) - return 0; - else - return BufferReferences[id].SourceBuffer; -} - -//! returns the matrix of the source buffer -core::matrix4 CBatchingMesh::getSourceBufferMatrix(s32 id) -{ - core::matrix4 ret; - if ((u32)id > BufferReferences.size() || IsFinal) - ret.makeIdentity(); - else - ret = BufferReferences[id].Transform; - - return ret; -} - - -//! returns the number of source buffers -u32 CBatchingMesh::getSourceBufferCount() const -{ - return BufferReferences.size(); -} - -// private functions - -void CBatchingMesh::recalculateDestBufferBoundingBox(u32 i) -{ - switch (DestBuffers[i].VertexType) - { - case video::EVT_STANDARD: - ((SMeshBuffer*)DestBuffers[i].Buffer)->recalculateBoundingBox(); - break; - case video::EVT_2TCOORDS: - ((SMeshBufferLightMap*)DestBuffers[i].Buffer)->recalculateBoundingBox(); - break; - case video::EVT_TANGENTS: - ((SMeshBufferTangents*)DestBuffers[i].Buffer)->recalculateBoundingBox(); - break; - } -} - -void CBatchingMesh::updateDestFromSourceBuffer(u32 i) -{ - u16* ind = BufferReferences[i].SourceBuffer->getIndices(); - void*ver = BufferReferences[i].SourceBuffer->getVertices(); - core::matrix4 m = BufferReferences[i].Transform; - u32 fi = BufferReferences[i].FirstIndex; - u32 fv = BufferReferences[i].FirstVertex; - u32 ic = BufferReferences[i].IndexCount; - u32 vc = BufferReferences[i].VertexCount; - u32 x; - video::E_VERTEX_TYPE vt = DestBuffers[BufferReferences[i].DestReference].VertexType; - switch (vt) - { - case video::EVT_STANDARD: - { - SMeshBuffer* dest = (SMeshBuffer*) DestBuffers[BufferReferences[i].DestReference].Buffer; - - for (x=fi; x < fi+ic; ++x) - dest->Indices[x] = ind[x-fi]+fv; - - video::S3DVertex* vertices= (video::S3DVertex*) ver; - - for (x=fv; x < fv+vc; ++x) - { - dest->Vertices[x] = vertices[x-fv]; - m.transformVect(dest->Vertices[x].Pos); - m.rotateVect(dest->Vertices[x].Normal); - } - break; - } - case video::EVT_2TCOORDS: - { - SMeshBufferLightMap* dest = (SMeshBufferLightMap*) DestBuffers[BufferReferences[i].DestReference].Buffer; - - for (x=fi; x < fi+ic; ++x) - dest->Indices[x] = ind[x-fi]+fv; - - video::S3DVertex2TCoords* vertices= (video::S3DVertex2TCoords*) ver; - - for (x=fv; x < fv+vc; ++x) - { - dest->Vertices[x] = vertices[x-fv]; - m.transformVect(dest->Vertices[x].Pos); - m.rotateVect(dest->Vertices[x].Normal); - } - break; - } - case video::EVT_TANGENTS: - { - SMeshBufferTangents* dest = (SMeshBufferTangents*) DestBuffers[BufferReferences[i].DestReference].Buffer; - - for (x=fi; x < fi+ic; ++x) - dest->Indices[x] = ind[x-fi]+fv; - - video::S3DVertexTangents* vertices= (video::S3DVertexTangents*) ver; - - for (x=fv; x < fv+vc; ++x) - { - dest->Vertices[x] = vertices[x-fv]; - m.transformVect(dest->Vertices[x].Pos); - m.rotateVect(dest->Vertices[x].Normal); // are tangents/binormals in face space? - } - break; - } - default: - break; - } -} - -void CBatchingMesh::addSourceBuffer(IMeshBuffer *source) -{ - bool found = false; - for (u32 i=0; i<SourceBuffers.size(); ++i) - { - if (SourceBuffers[i] == source) - { - found = true; - break; - } - } - if (!found) - { - source->grab(); - SourceBuffers.push_back(source); - } -} - -void CBatchingMesh::setHardwareMappingHint(E_HARDWARE_MAPPING mapping, E_BUFFER_TYPE type) -{ - for (u32 i=0; i < DestBuffers.size(); ++i) - DestBuffers[i].Buffer->setHardwareMappingHint(mapping, type); -} - - -void CBatchingMesh::setDirty(E_BUFFER_TYPE type) -{ - for (u32 i=0; i < DestBuffers.size(); ++i) - DestBuffers[i].Buffer->setDirty(type); -} - -} // namespace scene -} // namespace irr - + +#include "graphics/CBatchingMesh.hpp" + +namespace irr +{ +namespace scene +{ + +CBatchingMesh::CBatchingMesh() + : Box(core::vector3df(0,0,0)), IsDirty(false), IsFinal(false) +{ + +} + +CBatchingMesh::~CBatchingMesh() +{ + u32 i; + for (i=0; i < DestBuffers.size(); ++i) + DestBuffers[i].Buffer->drop(); + + for (i=0; i < SourceBuffers.size(); ++i) + SourceBuffers[i]->drop(); +} + +bool CBatchingMesh::isDirty(s32 id) +{ + if ((u32)id > DestBuffers.size()) + return IsDirty; + else + return DestBuffers[id].IsDirty; +} + +//! refreshes the internal buffers from source +void CBatchingMesh::update() +{ + // allocate the index and vertex arrays + u32 i; + for (i=0; i<DestBuffers.size(); ++i) + { + if (DestBuffers[i].IndexCount != DestBuffers[i].Buffer->getIndexCount() || + DestBuffers[i].VertexCount != DestBuffers[i].Buffer->getVertexCount()) + { + DestBuffers[i].IsDirty = true; + + switch (DestBuffers[i].VertexType) + { + case video::EVT_STANDARD: + { + SMeshBuffer* mb = (SMeshBuffer*)DestBuffers[i].Buffer; + mb->Vertices.set_used(DestBuffers[i].VertexCount); + mb->Indices.set_used(DestBuffers[i].IndexCount); + break; + } + case video::EVT_2TCOORDS: + { + SMeshBufferLightMap* mb = (SMeshBufferLightMap*)DestBuffers[i].Buffer; + mb->Vertices.set_used(DestBuffers[i].VertexCount); + mb->Indices.set_used(DestBuffers[i].IndexCount); + break; + } + case video::EVT_TANGENTS: + { + SMeshBufferTangents* mb = (SMeshBufferTangents*)DestBuffers[i].Buffer; + mb->Vertices.set_used(DestBuffers[i].VertexCount); + mb->Indices.set_used(DestBuffers[i].IndexCount); + break; + } + default: // shouldn't ever happen + continue; + } + } + } + + // refresh dirty buffers from source + for (i=0; i<BufferReferences.size(); ++i) + { + if (DestBuffers[BufferReferences[i].DestReference].IsDirty) + { + updateDestFromSourceBuffer(i); + } + } + + // calculate bounding boxes + for (i=0; i< DestBuffers.size(); ++i) + { + if (DestBuffers[i].IsDirty) + { + recalculateDestBufferBoundingBox(i); + // reset dirty state too + DestBuffers[i].IsDirty = false; + } + } + + IsDirty = false; + recalculateBoundingBox(); +} + +//! adds a mesh to the buffers with the given offset +/** \Returns Returns an array of ID numbers */ +core::array<s32> CBatchingMesh::addMesh(IMesh* mesh, core::vector3df pos, core::vector3df rot, core::vector3df scale) +{ + core::matrix4 m; + m.setRotationDegrees(rot); + m.setTranslation(pos); + + core::matrix4 scalem; + scalem.setScale(scale); + m *= scalem; + + return addMesh(mesh, m); +} + +//! adds a mesh with the given transformation +core::array<s32> CBatchingMesh::addMesh(IMesh* mesh, const core::matrix4 &transform) +{ + core::array<s32> bufferNos; + + if (!mesh) + return bufferNos; + + u32 i; + for (i=0; i<mesh->getMeshBufferCount(); ++i) + bufferNos.push_back(addMeshBuffer(mesh->getMeshBuffer(i), transform)); + + return bufferNos; +} + +//! adds a mesh buffer with the given transformation +/** \Return Returns the ID of this mesh buffer */ +s32 CBatchingMesh::addMeshBuffer(IMeshBuffer* buffer, core::vector3df pos, core::vector3df rot, core::vector3df scale) +{ + core::matrix4 m; + m.setRotationDegrees(rot); + m.setTranslation(pos); + + core::matrix4 scalem; + scalem.setScale(scale); + m *= scalem; + + return addMeshBuffer(buffer, m); +} + +//! adds a mesh with the given transformation +/** \Return Returns the ID of this mesh buffer */ +s32 CBatchingMesh::addMeshBuffer(IMeshBuffer* buffer, const core::matrix4 &transform) +{ + if (!buffer || IsFinal) + return -1; + + u32 i; + video::SMaterial m = buffer->getMaterial(); + + // find material + bool found=false; + video::E_VERTEX_TYPE vt = buffer->getVertexType(); + for (i=0; i<MaterialReferences.size(); ++i) + { + if (MaterialReferences[i].VertexType == vt && + MaterialReferences[i].Material == m) + { + // will there be too many vertices in the buffer? + u32 newTotalI = buffer->getIndexCount() + DestBuffers[ MaterialReferences[i].BufferIndex ].IndexCount; + u32 newTotalV = buffer->getVertexCount() + DestBuffers[ MaterialReferences[i].BufferIndex ].VertexCount; + + if ( newTotalI < 65536*3 && newTotalV < 65536) + { + found = true; + DestBuffers[ MaterialReferences[i].BufferIndex ].IndexCount = newTotalI; + DestBuffers[ MaterialReferences[i].BufferIndex ].VertexCount = newTotalV; + break; + } + } + } + + if (!found) + { + // we need a new destination buffer and material reference + IMeshBuffer *mb=0; + + SMaterialReference r; + r.Material = m; + r.VertexType = vt; + r.BufferIndex = DestBuffers.size(); + switch (vt) + { + case video::EVT_STANDARD: + mb = (IMeshBuffer*)new SMeshBuffer(); + mb->getMaterial() = m; + break; + case video::EVT_2TCOORDS: + mb = (IMeshBuffer*)new SMeshBufferLightMap(); + mb->getMaterial() = m; + break; + case video::EVT_TANGENTS: + mb = (IMeshBuffer*)new SMeshBufferTangents(); + mb->getMaterial() = m; + break; + default: // unknown vertex type + return -1; + } + i = MaterialReferences.size(); + MaterialReferences.push_back(r); + + SDestBufferReference db; + db.Buffer = mb; + db.IndexCount = buffer->getIndexCount(); + db.VertexCount = buffer->getVertexCount(); + db.IsDirty = true; + db.VertexType = vt; + + DestBuffers.push_back(db); + } + // now we add the mesh reference + SBufferReference r; + r.DestReference = i; + r.SourceBuffer = buffer; + r.Transform = transform; + r.IndexCount = buffer->getIndexCount(); + r.VertexCount = buffer->getVertexCount(); + r.FirstIndex = DestBuffers[ MaterialReferences[i].BufferIndex ].IndexCount - r.IndexCount; + r.FirstVertex = DestBuffers[ MaterialReferences[i].BufferIndex ].VertexCount - r.VertexCount; + r.Initialized = false; + BufferReferences.push_back(r); + addSourceBuffer(buffer); + + IsDirty = true; + return BufferReferences.size()-1; +} + +//! updates bouding box from internal buffers +void CBatchingMesh::recalculateBoundingBox() +{ + if (DestBuffers.size() == 0) + Box.reset(0,0,0); + else + { + Box.reset(DestBuffers[0].Buffer->getBoundingBox().MinEdge); + + u32 i; + for (i=0; i < DestBuffers.size(); ++i) + Box.addInternalBox(DestBuffers[i].Buffer->getBoundingBox()); + } +} + + +/* Standard IMesh functions */ + +//! Returns the amount of mesh buffers. +/** \return Returns the amount of mesh buffers (IMeshBuffer) in this mesh. */ +u32 CBatchingMesh::getMeshBufferCount() const +{ + return DestBuffers.size(); +} + +//! Returns pointer to a mesh buffer. +/** \param nr: Zero based index of the mesh buffer. The maximum value is +getMeshBufferCount() - 1; +\return Returns the pointer to the mesh buffer or +NULL if there is no such mesh buffer. */ +IMeshBuffer* CBatchingMesh::getMeshBuffer(u32 nr) const +{ + if (nr < DestBuffers.size()) + return DestBuffers[nr].Buffer; + else + return 0; +} + +//! Returns pointer to a mesh buffer which fits a material +IMeshBuffer* CBatchingMesh::getMeshBuffer( const video::SMaterial &material) const +{ + return 0; +} + +//! Returns an axis aligned bounding box of the mesh. +/** \return A bounding box of this mesh is returned. */ +const core::aabbox3d<f32>& CBatchingMesh::getBoundingBox() const +{ + return Box; +} + +//! set user axis aligned bounding box +void CBatchingMesh::setBoundingBox( const core::aabbox3df& box) +{ + Box = box; +} + +//! Sets a flag of all contained materials to a new value. +/** \param flag: Flag to set in all materials. + \param newvalue: New value to set in all materials. */ +void CBatchingMesh::setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) +{ + for (u32 i=0; i<DestBuffers.size(); ++i) + DestBuffers[i].Buffer->getMaterial().setFlag(flag, newvalue); +} + +//! drops all buffers and clears internal states +void CBatchingMesh::clear() +{ + u32 i; + for (i=0; i < DestBuffers.size(); ++i) + DestBuffers[i].Buffer->drop(); + + for (i=0; i < SourceBuffers.size(); ++i) + SourceBuffers[i]->drop(); + + BufferReferences.clear(); + MaterialReferences.clear(); + DestBuffers.clear(); + SourceBuffers.clear(); + + IsDirty = false; + IsFinal = false; +} + +//! first updates the mesh, then drops all source buffers. +/** once this mesh has been finalized, it cannot be changed again! */ +void CBatchingMesh::finalize() +{ + update(); + + for (u32 i=0; i < SourceBuffers.size(); ++i) + SourceBuffers[i]->drop(); + + SourceBuffers.clear(); + + IsFinal = true; +} + +//! Moves a mesh +core::array<bool> CBatchingMesh::moveMesh(const core::array<s32>& bufferIDs, const core::matrix4 &newMatrix) +{ + core::array<bool> result; + result.reallocate(bufferIDs.size()); + for (u32 i=0; i<bufferIDs.size(); ++i) + result.push_back(moveMeshBuffer(bufferIDs[i], newMatrix)); + + return result; +} + + +//! Moves a mesh buffer +bool CBatchingMesh::moveMeshBuffer(const s32 id, const core::matrix4 &newMatrix) +{ + if ((u32)id > BufferReferences.size() || IsFinal ) + return false; + + BufferReferences[id].Transform = newMatrix; + + // is the source buffer dirty? + if (!DestBuffers[BufferReferences[id].DestReference].IsDirty) + { + // transform each vertex and normal + updateDestFromSourceBuffer(id); + recalculateDestBufferBoundingBox(BufferReferences[id].DestReference); + } + return true; +} + + +//! returns the source buffer, if available +IMeshBuffer* CBatchingMesh::getSourceBuffer(s32 id) +{ + if ((u32)id > BufferReferences.size() || IsFinal) + return 0; + else + return BufferReferences[id].SourceBuffer; +} + +//! returns the matrix of the source buffer +core::matrix4 CBatchingMesh::getSourceBufferMatrix(s32 id) +{ + core::matrix4 ret; + if ((u32)id > BufferReferences.size() || IsFinal) + ret.makeIdentity(); + else + ret = BufferReferences[id].Transform; + + return ret; +} + + +//! returns the number of source buffers +u32 CBatchingMesh::getSourceBufferCount() const +{ + return BufferReferences.size(); +} + +// private functions + +void CBatchingMesh::recalculateDestBufferBoundingBox(u32 i) +{ + switch (DestBuffers[i].VertexType) + { + case video::EVT_STANDARD: + ((SMeshBuffer*)DestBuffers[i].Buffer)->recalculateBoundingBox(); + break; + case video::EVT_2TCOORDS: + ((SMeshBufferLightMap*)DestBuffers[i].Buffer)->recalculateBoundingBox(); + break; + case video::EVT_TANGENTS: + ((SMeshBufferTangents*)DestBuffers[i].Buffer)->recalculateBoundingBox(); + break; + } +} + +void CBatchingMesh::updateDestFromSourceBuffer(u32 i) +{ + u16* ind = BufferReferences[i].SourceBuffer->getIndices(); + void*ver = BufferReferences[i].SourceBuffer->getVertices(); + core::matrix4 m = BufferReferences[i].Transform; + u32 fi = BufferReferences[i].FirstIndex; + u32 fv = BufferReferences[i].FirstVertex; + u32 ic = BufferReferences[i].IndexCount; + u32 vc = BufferReferences[i].VertexCount; + u32 x; + video::E_VERTEX_TYPE vt = DestBuffers[BufferReferences[i].DestReference].VertexType; + switch (vt) + { + case video::EVT_STANDARD: + { + SMeshBuffer* dest = (SMeshBuffer*) DestBuffers[BufferReferences[i].DestReference].Buffer; + + for (x=fi; x < fi+ic; ++x) + dest->Indices[x] = ind[x-fi]+fv; + + video::S3DVertex* vertices= (video::S3DVertex*) ver; + + for (x=fv; x < fv+vc; ++x) + { + dest->Vertices[x] = vertices[x-fv]; + m.transformVect(dest->Vertices[x].Pos); + m.rotateVect(dest->Vertices[x].Normal); + } + break; + } + case video::EVT_2TCOORDS: + { + SMeshBufferLightMap* dest = (SMeshBufferLightMap*) DestBuffers[BufferReferences[i].DestReference].Buffer; + + for (x=fi; x < fi+ic; ++x) + dest->Indices[x] = ind[x-fi]+fv; + + video::S3DVertex2TCoords* vertices= (video::S3DVertex2TCoords*) ver; + + for (x=fv; x < fv+vc; ++x) + { + dest->Vertices[x] = vertices[x-fv]; + m.transformVect(dest->Vertices[x].Pos); + m.rotateVect(dest->Vertices[x].Normal); + } + break; + } + case video::EVT_TANGENTS: + { + SMeshBufferTangents* dest = (SMeshBufferTangents*) DestBuffers[BufferReferences[i].DestReference].Buffer; + + for (x=fi; x < fi+ic; ++x) + dest->Indices[x] = ind[x-fi]+fv; + + video::S3DVertexTangents* vertices= (video::S3DVertexTangents*) ver; + + for (x=fv; x < fv+vc; ++x) + { + dest->Vertices[x] = vertices[x-fv]; + m.transformVect(dest->Vertices[x].Pos); + m.rotateVect(dest->Vertices[x].Normal); // are tangents/binormals in face space? + } + break; + } + default: + break; + } +} + +void CBatchingMesh::addSourceBuffer(IMeshBuffer *source) +{ + bool found = false; + for (u32 i=0; i<SourceBuffers.size(); ++i) + { + if (SourceBuffers[i] == source) + { + found = true; + break; + } + } + if (!found) + { + source->grab(); + SourceBuffers.push_back(source); + } +} + +void CBatchingMesh::setHardwareMappingHint(E_HARDWARE_MAPPING mapping, E_BUFFER_TYPE type) +{ + for (u32 i=0; i < DestBuffers.size(); ++i) + DestBuffers[i].Buffer->setHardwareMappingHint(mapping, type); +} + + +void CBatchingMesh::setDirty(E_BUFFER_TYPE type) +{ + for (u32 i=0; i < DestBuffers.size(); ++i) + DestBuffers[i].Buffer->setDirty(type); +} + +} // namespace scene +} // namespace irr + Modified: main/trunk/src/graphics/CBatchingMesh.hpp =================================================================== --- main/trunk/src/graphics/CBatchingMesh.hpp 2010-12-15 22:50:17 UTC (rev 7029) +++ main/trunk/src/graphics/CBatchingMesh.hpp 2010-12-15 22:52:59 UTC (rev 7030) @@ -1,174 +1,174 @@ -// A mesh used for batching many other meshes together, to reduce the number -// of draw calls. Simply add meshes into this one, with given transformations -// or positions, and then call update - -// TODO: Adapt the VBO interface and integrate setDirty with the current VBO updates. - -#include "IMesh.h" -#include "SMeshBuffer.h" - -namespace irr -{ -namespace scene -{ - -class CBatchingMesh : public IMesh -{ -public: - CBatchingMesh(); - - virtual ~CBatchingMesh(); - - //! returns true if new buffers have been added without updating the internal buffers - bool isDirty(s32 id=-1); - - //! refreshes the internal buffers from source - void update(); - - //! drops all buffers and clears internal states - void clear(); - - //! first updates the mesh, then drops all source buffers. - /** once this mesh has been finalized, it cannot be changed again! */ - void finalize(); - - //! adds a mesh to the buffers with the given offset - /** \Return: Returns an array of ID numbers */ - core::array<s32> addMesh(IMesh* mesh, - core::vector3df pos = core::vector3df(0,0,0), - core::vector3df rot = core::vector3df(0,0,0), - core::vector3df scale = core::vector3df(1,1,1)); - - //! adds a mesh with the given transformation - /** \Return: Returns an array of ID numbers */ - core::array<s32> addMesh(IMesh* mesh, const core::matrix4 &transform); - - //! adds a mesh buffer with the given transformation - /** \Return: Returns the ID of this mesh buffer */ - s32 addMeshBuffer(IMeshBuffer* buffer, - core::vector3df pos = core::vector3df(0,0,0), - core::vector3df rot = core::vector3df(0,0,0), - core::vector3df scale = core::vector3df(1,1,1)); - - //! adds a mesh with the given transformation - /** \Return Returns the ID of this mesh buffer */ - s32 addMeshBuffer(IMeshBuffer* buffer, const core::matrix4 &transform); - - //! updates bouding box from internal buffers - void recalculateBoundingBox(); - - //! Moves a mesh, - /** mesh buffers in clean destination buffers will be moved immediately, - ones in dirty buffers will be left until the next update */ - core::array<bool> moveMesh(const core::array<s32>& bufferIDs, const core::matrix4 &newMatrix); - - //! Moves a mesh buffer - /** if the destination buffer is clean it will be moved immediately, - if a member of a dirty buffer, it will be left until the next update */ - bool moveMeshBuffer(const s32 id, const core::matrix4 &newMatrix); - - //! returns the source buffer, if available - IMeshBuffer* getSourceBuffer(s32 id); - - //! returns the matrix of the source buffer - core::matrix4 getSourceBufferMatrix(s32 id); - - //! returns the number of source buffers - u32 getSourceBufferCount() const; - - /* Standard IMesh functions */ - - //! Returns the amount of mesh buffers. - /** \return Returns the amount of mesh buffers (IMeshBuffer) in this mesh. */ - virtual u32 getMeshBufferCount() const; - - //! Returns pointer to a mesh buffer. - /** \param nr: Zero based index of the mesh buffer. The maximum value is - getMeshBufferCount() - 1; - \return Returns the pointer to the mesh buffer or - NULL if there is no such mesh buffer. */ - virtual IMeshBuffer* getMeshBuffer(u32 nr) const; - - //! Returns pointer to a mesh buffer which fits a material - /** \param material: material to search for - \return Returns the pointer to the mesh buffer or - NULL if there is no such mesh buffer. */ - virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const; - - //! Returns an axis aligned bounding box of the mesh. - /** \return A bounding box of this mesh is returned. */ - virtual const core::aabbox3d<f32>& getBoundingBox() const; - - //! set user axis aligned bounding box - virtual void setBoundingBox( const core::aabbox3df& box); - - //! Sets a flag of all contained materials to a new value. - /** \param flag: Flag to set in all materials. - \param newvalue: New value to set in all materials. */ - virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue); - - virtual void setHardwareMappingHint(E_HARDWARE_MAPPING mapping, E_BUFFER_TYPE type); - - virtual void setDirty(E_BUFFER_TYPE type); - -private: - - // add a buffer to the source buffers array if it doesn't already exist - void addSourceBuffer(IMeshBuffer* source); - - // updates the vertices in dest buffer from the source one - void updateDestFromSourceBuffer(u32 id); - - // recalculates the bounding box for the given dest buffer - void recalculateDestBufferBoundingBox(u32 i); - - struct SBufferReference - { - SBufferReference() - : SourceBuffer(0), DestReference(0), FirstVertex(0), VertexCount(0), - FirstIndex(0), IndexCount(0), Initialized(false) { } - - IMeshBuffer* SourceBuffer; - u32 DestReference; - u32 FirstVertex, VertexCount, FirstIndex, IndexCount; - core::matrix4 Transform; - bool Initialized; - }; - - struct SMaterialReference - { - video::SMaterial Material; - video::E_VERTEX_TYPE VertexType; - u32 BufferIndex; - }; - - struct SDestBufferReference - { - IMeshBuffer* Buffer; - video::E_VERTEX_TYPE VertexType; - u32 VertexCount; - u32 IndexCount; - bool IsDirty; - }; - - //! Source mesh buffers, these are locked - core::array<IMeshBuffer*> SourceBuffers; - - core::array<SBufferReference> BufferReferences; - core::array<SMaterialReference> MaterialReferences; - core::array<SDestBufferReference> DestBuffers; - - //! bounding containing all destination buffers - core::aabbox3d<f32> Box; - - //! does it require an update? - bool IsDirty; - - //! can it be changed? - bool IsFinal; -}; - -} // namespace scene -} // namespace irr - -// #endif +// A mesh used for batching many other meshes together, to reduce the number +// of draw calls. Simply add meshes into this one, with given transformations +// or positions, and then call update + +// TODO: Adapt the VBO interface and integrate setDirty with the current VBO updates. + +#include "IMesh.h" +#include "SMeshBuffer.h" + +namespace irr +{ +namespace scene +{ + +class CBatchingMesh : public IMesh +{ +public: + CBatchingMesh(); + + virtual ~CBatchingMesh(); + + //! returns true if new buffers have been added without updating the internal buffers + bool isDirty(s32 id=-1); + + //! refreshes the internal buffers from source + void update(); + + //! drops all buffers and clears internal states + void clear(); + + //! first updates the mesh, then drops all source buffers. + /** once this mesh has been finalized, it cannot be changed again! */ + void finalize(); + + //! adds a mesh to the buffers with the given offset + /** \Return: Returns an array of ID numbers */ + core::array<s32> addMesh(IMesh* mesh, + core::vector3df pos = core::vector3df(0,0,0), + core::vector3df rot = core::vector3df(0,0,0), + core::vector3df scale = core::vector3df(1,1,1)); + + //! adds a mesh with the given transformation + /** \Return: Returns an array of ID numbers */ + core::array<s32> addMesh(IMesh* mesh, const core::matrix4 &transform); + + //! adds a mesh buffer with the given transformation + /** \Return: Returns the ID of this mesh buffer */ + s32 addMeshBuffer(IMeshBuffer* buffer, + core::vector3df pos = core::vector3df(0,0,0), + core::vector3df rot = core::vector3df(0,0,0), + core::vector3df scale = core::vector3df(1,1,1)); + + //! adds a mesh with the given transformation + /** \Return Returns the ID of this mesh buffer */ + s32 addMeshBuffer(IMeshBuffer* buffer, const core::matrix4 &transform); + + //! updates bouding box from internal buffers + void recalculateBoundingBox(); + + //! Moves a mesh, + /** mesh buffers in clean destination buffers will be moved immediately, + ones in dirty buffers will be left until the next update */ + core::array<bool> moveMesh(const core::array<s32>& bufferIDs, const core::matrix4 &newMatrix); + + //! Moves a mesh buffer + /** if the destination buffer is clean it will be moved immediately, + if a member of a dirty buffer, it will be left until the next update */ + bool moveMeshBuffer(const s32 id, const core::matrix4 &newMatrix); + + //! returns the source buffer, if available + IMeshBuffer* getSourceBuffer(s32 id); + + //! returns the matrix of the source buffer + core::matrix4 getSourceBufferMatrix(s32 id); + + //! returns the number of source buffers + u32 getSourceBufferCount() const; + + /* Standard IMesh functions */ + + //! Returns the amount of mesh buffers. + /** \return Returns the amount of mesh buffers (IMeshBuffer) in this mesh. */ + virtual u32 getMeshBufferCount() const; + + //! Returns pointer to a mesh buffer. + /** \param nr: Zero based index of the mesh buffer. The maximum value is + getMeshBufferCount() - 1; + \return Returns the pointer to the mesh buffer or + NULL if there is no such mesh buffer. */ + virtual IMeshBuffer* getMeshBuffer(u32 nr) const; + + //! Returns pointer to a mesh buffer which fits a material + /** \param material: material to search for + \return Returns the pointer to the mesh buffer or + NULL if there is no such mesh buffer. */ + virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const; + + //! Returns an axis aligned bounding box of the mesh. + /** \return A bounding box of this mesh is returned. */ + virtual const core::aabbox3d<f32>& getBoundingBox() const; + + //! set user axis aligned bounding box + virtual void setBoundingBox( const core::aabbox3df& box); + + //! Sets a flag of all contained materials to a new value. + /** \param flag: Flag to set in all materials. + \param newvalue: New value to set in all materials. */ + virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue); + + virtual void setHardwareMappingHint(E_HARDWARE_MAPPING mapping, E_BUFFER_TYPE type); + + virtual void setDirty(E_BUFFER_TYPE type); + +private: + + // add a buffer to the source buffers array if it doesn't already exist + void addSourceBuffer(IMeshBuffer* source); + + // updates the vertices in dest buffer from the source one + void updateDestFromSourceBuffer(u32 id); + + // recalculates the bounding box for the given dest buffer + void recalculateDestBufferBoundingBox(u32 i); + + struct SBufferReference + { + SBufferReference() + : SourceBuffer(0), DestReference(0), FirstVertex(0), VertexCount(0), + FirstIndex(0), IndexCount(0), Initialized(false) { } + + IMeshBuffer* SourceBuffer; + u32 DestReference; + u32 FirstVertex, VertexCount, FirstIndex, IndexCount; + core::matrix4 Transform; + bool Initialized; + }; + + struct SMaterialReference + { + video::SMaterial Material; + video::E_VERTEX_TYPE VertexType; + u32 BufferIndex; + }; + + struct SDestBufferReference + { + IMeshBuffer* Buffer; + video::E_VERTEX_TYPE VertexType; + u32 VertexCount; + u32 IndexCount; + bool IsDirty; + }; + + //! Source mesh buffers, these are locked + core::array<IMeshBuffer*> SourceBuffers; + + core::array<SBufferReference> BufferReferences; + core::array<SMaterialReference> MaterialReferences; + core::array<SDestBufferReference> DestBuffers; + + //! bounding containing all destination buffers + core::aabbox3d<f32> Box; + + //! does it require an update? + bool IsDirty; + + //! can it be changed? + bool IsFinal; +}; + +} // namespace scene +} // namespace irr + +// #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-01-06 21:11:38
|
Revision: 7316 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7316&view=rev Author: auria Date: 2011-01-06 21:11:32 +0000 (Thu, 06 Jan 2011) Log Message: ----------- Remove outdated FIXMES + fix possible crash if section is missing in XML file Modified Paths: -------------- main/trunk/src/graphics/particle_emitter.cpp main/trunk/src/graphics/particle_kind.cpp Modified: main/trunk/src/graphics/particle_emitter.cpp =================================================================== --- main/trunk/src/graphics/particle_emitter.cpp 2011-01-06 20:56:32 UTC (rev 7315) +++ main/trunk/src/graphics/particle_emitter.cpp 2011-01-06 21:11:32 UTC (rev 7316) @@ -66,8 +66,6 @@ { case EMITTER_POINT: { - // FIXME: does the maxAngle param work at all?? - // FIXME: the min and max color params don't appear to work m_emitter = m_node->createPointEmitter(core::vector3df(m_particle_type->getVelocityX(), m_particle_type->getVelocityY(), m_particle_type->getVelocityZ()), // velocity in m/ms @@ -81,8 +79,6 @@ case EMITTER_BOX: { - // FIXME: does the maxAngle param work at all?? - // FIXME: the min and max color params don't appear to work const float box_size_x = type->getBoxSizeX()/2.0f; const float box_size_y = type->getBoxSizeY()/2.0f; const float box_size_z = type->getBoxSizeZ()/2.0f; Modified: main/trunk/src/graphics/particle_kind.cpp =================================================================== --- main/trunk/src/graphics/particle_kind.cpp 2011-01-06 20:56:32 UTC (rev 7315) +++ main/trunk/src/graphics/particle_kind.cpp 2011-01-06 21:11:32 UTC (rev 7316) @@ -62,7 +62,7 @@ if (xml->getName() != "particles") { delete xml; - throw std::runtime_error("[ParticleKind] No <particles> main node in smoke.xml"); + throw std::runtime_error("[ParticleKind] No <particles> main node in " + file); } // ------------------------------------------------------------------------ @@ -105,6 +105,12 @@ // ------------------------------------------------------------------------ const XMLNode* material = xml->getNode("material"); + if (material == NULL) + { + delete xml; + throw std::runtime_error("[ParticleKind] No <material> node in " + file); + } + std::string materialFile; material->get("file", &materialFile); @@ -123,8 +129,11 @@ // ------------------------------------------------------------------------ const XMLNode* rate = xml->getNode("rate"); - rate->get("min", &m_min_rate); - rate->get("max", &m_max_rate); + if (rate != NULL) + { + rate->get("min", &m_min_rate); + rate->get("max", &m_max_rate); + } //std::cout << "m_min_rate = " << m_min_rate << "\n"; //std::cout << "m_max_rate = " << m_max_rate << "\n"; @@ -132,8 +141,11 @@ // ------------------------------------------------------------------------ const XMLNode* lifetime = xml->getNode("lifetime"); - lifetime->get("min", &m_lifetime_min); - lifetime->get("max", &m_lifetime_max); + if (lifetime != NULL) + { + lifetime->get("min", &m_lifetime_min); + lifetime->get("max", &m_lifetime_max); + } //std::cout << "m_lifetime_min = " << m_lifetime_min << "\n"; //std::cout << "m_lifetime_max = " << m_lifetime_max << "\n"; @@ -141,9 +153,11 @@ // ------------------------------------------------------------------------ const XMLNode* size = xml->getNode("size"); - //size->get("default", &m_particle_size); - size->get("min", &m_min_size); - size->get("max", &m_max_size); + if (size != NULL) + { + size->get("min", &m_min_size); + size->get("max", &m_max_size); + } //std::cout << "m_particle_size = " << m_particle_size << "\n"; //std::cout << "m_min_size = " << m_min_size << "\n"; @@ -152,16 +166,20 @@ // ------------------------------------------------------------------------ const XMLNode* color = xml->getNode("color"); - video::SColor minColor; - video::SColor maxColor; - color->get("min", &m_min_start_color); - color->get("max", &m_max_start_color); + if (color != NULL) + { + color->get("min", &m_min_start_color); + color->get("max", &m_max_start_color); + } // ------------------------------------------------------------------------ const XMLNode* fadeout = xml->getNode("fadeout"); - fadeout->get("time", &m_fadeout_time); - + if (fadeout != NULL) + { + fadeout->get("time", &m_fadeout_time); + } + //std::cout << "m_fadeout_time = " << m_fadeout_time << "\n"; // ------------------------------------------------------------------------ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-01-11 21:09:06
|
Revision: 7364 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7364&view=rev Author: auria Date: 2011-01-11 21:09:00 +0000 (Tue, 11 Jan 2011) Log Message: ----------- Add new option to materials.xml : disable z-buffer writes Modified Paths: -------------- main/trunk/src/graphics/material.cpp main/trunk/src/graphics/material.hpp Modified: main/trunk/src/graphics/material.cpp =================================================================== --- main/trunk/src/graphics/material.cpp 2011-01-11 21:06:19 UTC (rev 7363) +++ main/trunk/src/graphics/material.cpp 2011-01-11 21:09:00 UTC (rev 7364) @@ -67,6 +67,7 @@ node->get("slowdown-time", &m_slowdown_time ); node->get("anisotropic", &m_anisotropic ); node->get("backface-culling", &m_backface_culling ); + node->get("disable-z-write", &m_disable_z_write ); std::string s(""); node->get("graphical-effect", &s ); if(s=="water") @@ -149,6 +150,7 @@ m_ignore = false; m_resetter = false; m_add = false; + m_disable_z_write = false; m_max_speed_fraction = 1.0f; m_slowdown_time = 1.0f; m_sfx_name = ""; @@ -362,6 +364,11 @@ modes++; } + if (m_disable_z_write) + { + m->ZWriteEnable = false; + } + if (modes > 1) { std::cerr << "[Material::setMaterialProperties] More than one main mode set for " << m_texname.c_str() << "\n"; Modified: main/trunk/src/graphics/material.hpp =================================================================== --- main/trunk/src/graphics/material.hpp 2011-01-11 21:06:19 UTC (rev 7363) +++ main/trunk/src/graphics/material.hpp 2011-01-11 21:09:00 UTC (rev 7364) @@ -75,6 +75,9 @@ /** Whether to use anisotropic filtering for this texture */ bool m_anisotropic; + /** Set to true to disable writing to the Z buffer. Usually to be used with alpha blending */ + bool m_disable_z_write; + /** True if lightmapping is enabled for this material. */ bool m_lightmap; float m_friction; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-01-25 17:05:17
|
Revision: 7547 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7547&view=rev Author: auria Date: 2011-01-25 17:05:10 +0000 (Tue, 25 Jan 2011) Log Message: ----------- Name cameras in debug mode, useful to debug particle effects (which need to be camera-specific) Modified Paths: -------------- main/trunk/src/graphics/camera.cpp main/trunk/src/graphics/particle_emitter.cpp Modified: main/trunk/src/graphics/camera.cpp =================================================================== --- main/trunk/src/graphics/camera.cpp 2011-01-25 16:54:15 UTC (rev 7546) +++ main/trunk/src/graphics/camera.cpp 2011-01-25 17:05:10 UTC (rev 7547) @@ -43,6 +43,11 @@ m_mode = CM_NORMAL; m_index = camera_index; m_camera = irr_driver->addCameraSceneNode(); + +#ifdef DEBUG + m_camera->setName(core::stringc("Camera for ") + kart->getKartProperties()->getName()); +#endif + setupCamera(); m_distance = kart->getKartProperties()->getCameraDistance(); m_kart = kart; @@ -166,7 +171,6 @@ m_camera->setFOV(m_fov); m_camera->setAspectRatio(m_aspect); m_camera->setFarValue(World::getWorld()->getTrack()->getCameraFar()); - } // setupCamera // ---------------------------------------------------------------------------- Modified: main/trunk/src/graphics/particle_emitter.cpp =================================================================== --- main/trunk/src/graphics/particle_emitter.cpp 2011-01-25 16:54:15 UTC (rev 7546) +++ main/trunk/src/graphics/particle_emitter.cpp 2011-01-25 17:05:10 UTC (rev 7547) @@ -47,6 +47,8 @@ scene::ICameraSceneNode* curr_cam = irr_driver->getSceneManager()->getActiveCamera(); const core::vector3df& cam_pos = curr_cam->getPosition(); + // printf("Affect called with now=%u, camera=%s\n", now, curr_cam->getName()); + for (unsigned int n=0; n<count; n++) { scene::SParticle& curr = particlearray[n]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-02-03 02:23:10
|
Revision: 7593 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7593&view=rev Author: auria Date: 2011-02-03 02:23:04 +0000 (Thu, 03 Feb 2011) Log Message: ----------- Fixed crash when particles not found Modified Paths: -------------- main/trunk/src/graphics/particle_emitter.cpp main/trunk/src/graphics/particle_emitter.hpp Modified: main/trunk/src/graphics/particle_emitter.cpp =================================================================== --- main/trunk/src/graphics/particle_emitter.cpp 2011-02-03 00:52:42 UTC (rev 7592) +++ main/trunk/src/graphics/particle_emitter.cpp 2011-02-03 02:23:04 UTC (rev 7593) @@ -86,10 +86,13 @@ ParticleEmitter::ParticleEmitter(const ParticleKind* type, core::vector3df position, scene::ISceneNode* parent) : m_position(position) { + assert(type != NULL); + m_magic_number = 0x58781325; m_node = NULL; m_particle_type = NULL; m_parent = parent; setParticleType(type); + assert(m_node != NULL); } // KartParticleSystem @@ -98,12 +101,18 @@ */ ParticleEmitter::~ParticleEmitter() { + assert(m_magic_number == 0x58781325); + assert(m_node != NULL); irr_driver->removeNode(m_node); + + m_magic_number = 0xDEADBEEF; } // ~ParticleEmitter //----------------------------------------------------------------------------- void ParticleEmitter::update() { + assert(m_magic_number == 0x58781325); + // No particles to emit, nothing to do if (m_emitter->getMinParticlesPerSecond() == 0) return; @@ -164,6 +173,7 @@ void ParticleEmitter::setParticleType(const ParticleKind* type) { + assert(m_magic_number == 0x58781325); if (m_particle_type == type) return; // already the right type if (m_node != NULL) @@ -171,16 +181,15 @@ m_node->removeAll(); m_node->removeAllAffectors(); } - else + + m_node = irr_driver->addParticleNode(); + + if (m_parent != NULL) { - m_node = irr_driver->addParticleNode(); - - if (m_parent != NULL) - { - m_node->setParent(m_parent); - } + m_node->setParent(m_parent); } + m_particle_type = type; Material* material = type->getMaterial(); @@ -223,6 +232,9 @@ lifeTimeMin, lifeTimeMax, m_particle_type->getAngleSpread() /* angle */ ); + + irr_driver->getSceneManager()->addCubeSceneNode(0.1f, m_parent, -1, m_position); + break; } Modified: main/trunk/src/graphics/particle_emitter.hpp =================================================================== --- main/trunk/src/graphics/particle_emitter.hpp 2011-02-03 00:52:42 UTC (rev 7592) +++ main/trunk/src/graphics/particle_emitter.hpp 2011-02-03 02:23:04 UTC (rev 7593) @@ -49,6 +49,8 @@ const ParticleKind *m_particle_type; + unsigned int m_magic_number; + public: ParticleEmitter (const ParticleKind* type, core::vector3df position, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-02-03 22:39:37
|
Revision: 7603 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7603&view=rev Author: hikerstk Date: 2011-02-03 22:39:30 +0000 (Thu, 03 Feb 2011) Log Message: ----------- Used const & to avoid copying of vectors, minor cosmetic changes. Modified Paths: -------------- main/trunk/src/graphics/particle_emitter.cpp main/trunk/src/graphics/particle_emitter.hpp Modified: main/trunk/src/graphics/particle_emitter.cpp =================================================================== --- main/trunk/src/graphics/particle_emitter.cpp 2011-02-03 22:20:53 UTC (rev 7602) +++ main/trunk/src/graphics/particle_emitter.cpp 2011-02-03 22:39:30 UTC (rev 7603) @@ -40,11 +40,12 @@ m_start_fading = start; m_end_fading = end; assert(m_end_fading >= m_start_fading); - } - + } // FadeAwayAffector + // ------------------------------------------------------------------------ virtual void affect(u32 now, scene::SParticle* particlearray, u32 count) { - scene::ICameraSceneNode* curr_cam = irr_driver->getSceneManager()->getActiveCamera(); + scene::ICameraSceneNode* curr_cam = + irr_driver->getSceneManager()->getActiveCamera(); const core::vector3df& cam_pos = curr_cam->getPosition(); // printf("Affect called with now=%u, camera=%s\n", now, curr_cam->getName()); @@ -71,20 +72,23 @@ curr.color.setAlpha((int)((distance_squared - m_start_fading) / (m_end_fading - m_start_fading))); } - } - } - + } // for n<count + } // affect + + // ------------------------------------------------------------------------ virtual scene::E_PARTICLE_AFFECTOR_TYPE getType() const { // FIXME: this method seems to make sense only for built-in affectors return scene::EPAT_FADE_OUT; } -}; +}; // FadeAwayAffector - -ParticleEmitter::ParticleEmitter(const ParticleKind* type, core::vector3df position, - scene::ISceneNode* parent) : m_position(position) +// ============================================================================ +ParticleEmitter::ParticleEmitter(const ParticleKind* type, + const core::vector3df &position, + scene::ISceneNode* parent) + : m_position(position) { assert(type != NULL); m_magic_number = 0x58781325; @@ -164,7 +168,7 @@ //----------------------------------------------------------------------------- -void ParticleEmitter::setPosition(core::vector3df pos) +void ParticleEmitter::setPosition(const core::vector3df &pos) { m_node->setPosition(pos); } @@ -295,4 +299,4 @@ m_node->addAffector(faa); faa->drop(); } -} +} // setParticleType Modified: main/trunk/src/graphics/particle_emitter.hpp =================================================================== --- main/trunk/src/graphics/particle_emitter.hpp 2011-02-03 22:20:53 UTC (rev 7602) +++ main/trunk/src/graphics/particle_emitter.hpp 2011-02-03 22:39:30 UTC (rev 7603) @@ -53,13 +53,14 @@ public: - ParticleEmitter (const ParticleKind* type, core::vector3df position, + ParticleEmitter (const ParticleKind* type, + const core::vector3df &position, scene::ISceneNode* parent = NULL); virtual ~ParticleEmitter(); virtual void update (); void setCreationRate(float f); - void setPosition(core::vector3df pos); + void setPosition(const core::vector3df &pos); const ParticleKind* getParticlesInfo() const { return m_particle_type; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-02-06 15:30:50
|
Revision: 7639 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7639&view=rev Author: auria Date: 2011-02-06 15:30:43 +0000 (Sun, 06 Feb 2011) Log Message: ----------- Fix crash with particles on resolution change Modified Paths: -------------- main/trunk/src/graphics/irr_driver.cpp main/trunk/src/graphics/particle_kind_manager.cpp main/trunk/src/graphics/particle_kind_manager.hpp Modified: main/trunk/src/graphics/irr_driver.cpp =================================================================== --- main/trunk/src/graphics/irr_driver.cpp 2011-02-06 15:17:48 UTC (rev 7638) +++ main/trunk/src/graphics/irr_driver.cpp 2011-02-06 15:30:43 UTC (rev 7639) @@ -22,6 +22,7 @@ #include "config/user_config.hpp" #include "graphics/camera.hpp" #include "graphics/material_manager.hpp" +#include "graphics/particle_kind_manager.hpp" #include "guiengine/engine.hpp" #include "guiengine/modaldialog.hpp" #include "guiengine/scalable_font.hpp" @@ -339,21 +340,19 @@ UserConfigParams::m_prev_height) ); m_device->getVideoDriver()->endScene(); - // startScreen -> removeTextures(); attachment_manager -> removeTextures(); projectile_manager -> removeTextures(); item_manager -> removeTextures(); kart_properties_manager -> unloadAllKarts(); powerup_manager -> unloadPowerups(); + ParticleKindManager::get()->cleanup(); delete input_manager; GUIEngine::clear(); GUIEngine::cleanUp(); - //std::cout << "^^^^^^^^ Closing m_device ^^^^^^^^\n"; m_device->closeDevice(); m_device->clearSystemMessages(); m_device->run(); - //std::cout << "^^^^^^^^ Dropping m_device ^^^^^^^^\n"; // Clear the pointer stored in the file manager file_manager->dropFileSystem(); Modified: main/trunk/src/graphics/particle_kind_manager.cpp =================================================================== --- main/trunk/src/graphics/particle_kind_manager.cpp 2011-02-06 15:17:48 UTC (rev 7638) +++ main/trunk/src/graphics/particle_kind_manager.cpp 2011-02-06 15:30:43 UTC (rev 7639) @@ -43,6 +43,13 @@ ParticleKindManager::~ParticleKindManager() { + cleanup(); +} + +// ---------------------------------------------------------------------------- + +void ParticleKindManager::cleanup() +{ cleanUpTrackSpecificGfx(); std::map<std::string, ParticleKind*>::iterator it; Modified: main/trunk/src/graphics/particle_kind_manager.hpp =================================================================== --- main/trunk/src/graphics/particle_kind_manager.hpp 2011-02-06 15:17:48 UTC (rev 7638) +++ main/trunk/src/graphics/particle_kind_manager.hpp 2011-02-06 15:30:43 UTC (rev 7639) @@ -47,6 +47,7 @@ ParticleKind* getParticles(const std::string &name); void cleanUpTrackSpecificGfx(); + void cleanup(); static ParticleKindManager* get(); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mbj...@us...> - 2011-02-07 03:30:01
|
Revision: 7647 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7647&view=rev Author: mbjornstk Date: 2011-02-07 03:29:55 +0000 (Mon, 07 Feb 2011) Log Message: ----------- Raise rain cylinder from 3 to 5, so the kart and camera are under rain too. Things to do would be adding constant wheel splotches and maybe a fixed plane in front of the camera to darken/reduce contrast everywhere and give it a wet look (or change the materials to be darker & shinnier, but karts' textures...). Modified Paths: -------------- main/trunk/src/graphics/rain.cpp main/trunk/src/graphics/rain.hpp Modified: main/trunk/src/graphics/rain.cpp =================================================================== --- main/trunk/src/graphics/rain.cpp 2011-02-07 02:55:46 UTC (rev 7646) +++ main/trunk/src/graphics/rain.cpp 2011-02-07 03:29:55 UTC (rev 7647) @@ -22,13 +22,13 @@ #include "graphics/material.hpp" #include "graphics/rain.hpp" -const float RAIN_RADIUS[RAIN_RING_COUNT] = { 6.0f, 12.0f, 24.0f }; +const float RAIN_RADIUS[RAIN_RING_COUNT] = { 1.0f, 3.0f, 6.0f, 12.0f, 24.0f }; const float RAIN_Y_TO = 25.0f; const float RAIN_Y_FROM = -10.0f; const float RAIN_DY = 2.5f; -const float TEXTURE_X_TILES[RAIN_RING_COUNT] = { 3.5f, 5.0f, 8.0f }; -const float TEXTURE_Y_TILES[RAIN_RING_COUNT] = { 6.0f, 4.0f, 4.0f}; +const float TEXTURE_X_TILES[RAIN_RING_COUNT] = { 2.0f, 2.5f, 3.5f, 5.0f, 8.0f }; +const float TEXTURE_Y_TILES[RAIN_RING_COUNT] = { 8.0f, 7.0f, 6.0f, 4.0f, 4.0f }; Rain::Rain(irr::scene::ISceneNode* parent) Modified: main/trunk/src/graphics/rain.hpp =================================================================== --- main/trunk/src/graphics/rain.hpp 2011-02-07 02:55:46 UTC (rev 7646) +++ main/trunk/src/graphics/rain.hpp 2011-02-07 03:29:55 UTC (rev 7647) @@ -21,7 +21,7 @@ #define HEADER_RAIN_HPP #include <irrlicht.h> -const int RAIN_RING_COUNT = 3; +const int RAIN_RING_COUNT = 5; class Rain { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-02-10 02:48:32
|
Revision: 7669 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7669&view=rev Author: auria Date: 2011-02-10 02:48:25 +0000 (Thu, 10 Feb 2011) Log Message: ----------- PerCameraNode now works fine (wanring: evil dark magic in use) Modified Paths: -------------- main/trunk/src/graphics/per_camera_node.cpp main/trunk/src/graphics/rain.cpp Modified: main/trunk/src/graphics/per_camera_node.cpp =================================================================== --- main/trunk/src/graphics/per_camera_node.cpp 2011-02-10 01:56:52 UTC (rev 7668) +++ main/trunk/src/graphics/per_camera_node.cpp 2011-02-10 02:48:25 UTC (rev 7669) @@ -30,8 +30,10 @@ #endif m_camera = camera; - //m_child = mgr->addMeshSceneNode(mesh, this); - m_child = mgr->addCubeSceneNode(0.5f, this, -1); + m_child = mgr->addMeshSceneNode(mesh, this); + //m_child = mgr->addCubeSceneNode(0.5f, this, -1, core::vector3df(0,0,0), core::vector3df(0,0,0), core::vector3df(3.0f,0.2f,3.0f)); + //RelativeTransformationMatrix.setTranslation( core::vector3df(-0.5,-1,3) ); + setAutomaticCulling(scene::EAC_OFF); parent->addChild(this); @@ -41,22 +43,28 @@ { } +// How to show/hide a child node is not as easy as one might think. +// setVisible(false) is effective starting from the NEXT render so we +// can't easily use it; deciding which nodes go into the render list +// from OnRegisterSceneNode doesn't work either, presumably because +// this method is called before the active camera is set or for some +// other obscure reason (?). So my solution is to add no children +// nodes from OnRegisterSceneNode, but register the PerCameraNode to +// be "rendered" in the camera phase (which is very early in the render +// pipe). then, in the render callback, I can decide whether I add +// the children nodes to the render list. + void PerCameraNode::render() { - if (irr_driver->getSceneManager()->getSceneNodeRenderPass() != scene::ESNRP_SKY_BOX) - { - return; - } - scene::ICameraSceneNode* curr_cam = irr_driver->getSceneManager()->getActiveCamera(); - //printf("cam %s <--> %s\n", curr_cam->getName(), m_camera->getName()); - m_child->setVisible(curr_cam == m_camera); + + // Only register children nodes if the right camera is in use + if (curr_cam == m_camera) ISceneNode::OnRegisterSceneNode(); } void PerCameraNode::OnRegisterSceneNode() { - irr_driver->getSceneManager()->registerNodeForRendering(this, scene::ESNRP_SKY_BOX); - ISceneNode::OnRegisterSceneNode(); + irr_driver->getSceneManager()->registerNodeForRendering(this, scene::ESNRP_CAMERA); } void PerCameraNode::setCamera(scene::ICameraSceneNode* camera) @@ -65,6 +73,6 @@ #ifdef DEBUG if (camera) - setDebugName(camera->getDebugName()); + setName(camera->getName()); #endif } \ No newline at end of file Modified: main/trunk/src/graphics/rain.cpp =================================================================== --- main/trunk/src/graphics/rain.cpp 2011-02-10 01:56:52 UTC (rev 7668) +++ main/trunk/src/graphics/rain.cpp 2011-02-10 02:48:25 UTC (rev 7669) @@ -92,9 +92,7 @@ mesh->addMeshBuffer(buffer); mesh->recalculateBoundingBox(); - m_node[r] = irr_driver->addPerCameraMesh(mesh, camera); - - if (parent != NULL) m_node[r]->setParent(parent); + m_node[r] = irr_driver->addPerCameraMesh(mesh, camera, parent); mesh->drop(); buffer->drop(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mbj...@us...> - 2011-02-14 03:55:32
|
Revision: 7703 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7703&view=rev Author: mbjornstk Date: 2011-02-14 03:55:26 +0000 (Mon, 14 Feb 2011) Log Message: ----------- Displace rain texture also in X to make repetition hard/impossible to see. Modified Paths: -------------- main/trunk/src/graphics/rain.cpp main/trunk/src/graphics/rain.hpp Modified: main/trunk/src/graphics/rain.cpp =================================================================== --- main/trunk/src/graphics/rain.cpp 2011-02-14 02:50:38 UTC (rev 7702) +++ main/trunk/src/graphics/rain.cpp 2011-02-14 03:55:26 UTC (rev 7703) @@ -28,6 +28,7 @@ const float RAIN_Y_TO = 25.0f; const float RAIN_Y_FROM = -10.0f; const float RAIN_DY = 2.5f; +const float RAIN_DX = 0.2f; const float TEXTURE_X_TILES[RAIN_RING_COUNT] = { 2.0f, 2.5f, 3.5f, 5.0f, 8.0f }; const float TEXTURE_Y_TILES[RAIN_RING_COUNT] = { 8.0f, 7.0f, 6.0f, 4.0f, 4.0f }; @@ -113,7 +114,9 @@ void Rain::update(float dt) { + m_x = m_x + dt*RAIN_DX; m_y = m_y + dt*RAIN_DY; + if (m_x > 1.0f) m_x = fmod(m_x, 1.0f); if (m_y > 1.0f) m_y = fmod(m_y, 1.0f); //const int count = m_materials.size(); @@ -121,7 +124,7 @@ { core::matrix4& matrix = m_node[m]->getChild()->getMaterial(0).getTextureMatrix(0); - matrix.setTextureTranslate(0, m_y); + matrix.setTextureTranslate(m_x, m_y); } } // update Modified: main/trunk/src/graphics/rain.hpp =================================================================== --- main/trunk/src/graphics/rain.hpp 2011-02-14 02:50:38 UTC (rev 7702) +++ main/trunk/src/graphics/rain.hpp 2011-02-14 03:55:26 UTC (rev 7703) @@ -31,6 +31,7 @@ std::vector<irr::video::SMaterial*> m_materials; + float m_x; float m_y; public: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-02-16 06:07:44
|
Revision: 7712 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7712&view=rev Author: hikerstk Date: 2011-02-16 06:07:38 +0000 (Wed, 16 Feb 2011) Log Message: ----------- Applied and fixed MiniBjorn's support for pre-mul textures by setting adjust-image=premultiply or adjust-image=divide in material.xml But big question: can't we just modify the textures externally and use them, instead of doing this at runtime? Modified Paths: -------------- main/trunk/src/graphics/irr_driver.cpp main/trunk/src/graphics/irr_driver.hpp main/trunk/src/graphics/material.cpp main/trunk/src/graphics/material.hpp Modified: main/trunk/src/graphics/irr_driver.cpp =================================================================== --- main/trunk/src/graphics/irr_driver.cpp 2011-02-16 06:02:30 UTC (rev 7711) +++ main/trunk/src/graphics/irr_driver.cpp 2011-02-16 06:07:38 UTC (rev 7712) @@ -763,69 +763,77 @@ // ---------------------------------------------------------------------------- /** Loads a texture from a file and returns the texture object. * \param filename File name of the texture to load. + * \param is_premul If the alpha values needd to be multiplied for + * all pixels. + * \param is_prediv If the alpha value needs to be divided into + * each pixel. */ -video::ITexture *IrrDriver::getTexture(const std::string &filename) +video::ITexture *IrrDriver::getTexture(const std::string &filename, + bool is_premul, + bool is_prediv) { -#undef PREMULPNGS -#ifndef PREMULPNGS - video::ITexture* out = m_scene_manager->getVideoDriver()->getTexture(filename.c_str()); -#else - video::IImage* img = m_scene_manager->getVideoDriver()->createImageFromFile(filename.c_str()); - // PNGs are non premul, but some are used for premul tasks, so convert - // http://home.comcast.net/~tom_forsyth/blog.wiki.html#[[Premultiplied%20alpha]] - if(StringUtils::hasSuffix(filename.c_str(), ".png")) // FIXME check param, not name + video::ITexture* out; + if(!is_premul && !is_prediv) + out = m_scene_manager->getVideoDriver()->getTexture(filename.c_str()); + else { - if ((img->getColorFormat() == irr::video::ECF_A8R8G8B8) && img->lock()) + // FIXME: can't we just do this externally, and just use the + // modified textures?? + video::IImage* img = + m_scene_manager->getVideoDriver()->createImageFromFile(filename.c_str()); + // PNGs are non premul, but some are used for premul tasks, so convert + // http://home.comcast.net/~tom_forsyth/blog.wiki.html#[[Premultiplied%20alpha]] + // FIXME check param, not name + if(is_premul && + StringUtils::hasSuffix(filename.c_str(), ".png") && + (img->getColorFormat() == irr::video::ECF_A8R8G8B8) && + img->lock()) { core::dimension2d<u32> dim = img->getDimension(); - for(uint x = 0; x < dim.Width; x++) + for(unsigned int x = 0; x < dim.Width; x++) { - for(uint y = 0; y < dim.Height; y++) + for(unsigned int y = 0; y < dim.Height; y++) { video::SColor col = img->getPixel(x, y); - uint alpha = col.getAlpha(); - uint red = alpha * col.getRed() / 255; - uint blue = alpha * col.getBlue() / 255; - uint green = alpha * col.getGreen() / 255; + unsigned int alpha = col.getAlpha(); + unsigned int red = alpha * col.getRed() / 255; + unsigned int blue = alpha * col.getBlue() / 255; + unsigned int green = alpha * col.getGreen() / 255; col.set(alpha, red, green, blue); img->setPixel(x, y, col, false); - } - } + } // for y + } // for x img->unlock(); - } - } - /* - // Other formats can be premul, but the tasks can be non premul - // So divide to get the separate RGBA (only possible if alpha!=0) - else if() // FIXME, use param "DE-PREMUL requested" to match above - { - if ((img->getColorFormat() == irr::video::ECF_A8R8G8B8) && img->lock()) + } // if png and ColorFOrmat and lock + // Other formats can be premul, but the tasks can be non premul + // So divide to get the separate RGBA (only possible if alpha!=0) + else if(is_prediv && + (img->getColorFormat() == irr::video::ECF_A8R8G8B8) && + img->lock()) { core::dimension2d<u32> dim = img->getDimension(); - for(uint x = 0; x < dim.Width; x++) + for(unsigned int x = 0; x < dim.Width; x++) { - for(uint y = 0; y < dim.Height; y++) + for(unsigned int y = 0; y < dim.Height; y++) { video::SColor col = img->getPixel(x, y); - uint alpha = col.getAlpha(); + unsigned int alpha = col.getAlpha(); // Avoid divide by zero if (alpha) { - uint red = 255 * col.getRed() / alpha ; - uint blue = 255 * col.getBlue() / alpha; - uint green = 255 * col.getGreen() / alpha; + unsigned int red = 255 * col.getRed() / alpha ; + unsigned int blue = 255 * col.getBlue() / alpha; + unsigned int green = 255 * col.getGreen() / alpha; col.set(alpha, red, green, blue); img->setPixel(x, y, col, false); } - } - } + } // for y + } // for x img->unlock(); - } - } - */ - video::ITexture* out = m_scene_manager->getVideoDriver()->addTexture(filename.c_str(), - img, NULL); -#endif - + } // if premul && color format && lock + out = m_scene_manager->getVideoDriver()->addTexture(filename.c_str(), + img, NULL); + } // if is_premul or is_prediv + #ifndef NDEBUG if (out == NULL) { Modified: main/trunk/src/graphics/irr_driver.hpp =================================================================== --- main/trunk/src/graphics/irr_driver.hpp 2011-02-16 06:02:30 UTC (rev 7711) +++ main/trunk/src/graphics/irr_driver.hpp 2011-02-16 06:07:38 UTC (rev 7712) @@ -112,7 +112,9 @@ bool OnEvent(const irr::SEvent &event); void setAmbientLight(const video::SColor &light); - video::ITexture *getTexture(const std::string &filename); + video::ITexture *getTexture(const std::string &filename, + bool is_premul=false, + bool is_prediv=false); scene::IMesh *createQuadMesh(const video::SMaterial *material=NULL, bool create_one_quad=false); scene::IMesh *createTexturedQuadMesh(const video::SMaterial *material, const double w, const double h); Modified: main/trunk/src/graphics/material.cpp =================================================================== --- main/trunk/src/graphics/material.cpp 2011-02-16 06:02:30 UTC (rev 7711) +++ main/trunk/src/graphics/material.cpp 2011-02-16 06:07:38 UTC (rev 7712) @@ -56,6 +56,17 @@ node->get("clampV", &b); if (b) m_clamp_tex |= VCLAMP; node->get("transparency", &m_alpha_testing ); node->get("lightmap", &m_lightmap ); + std::string s; + node->get("adjust-image", &s ); + if(s=="premultiply") + m_adjust_image = ADJ_PREMUL; + else if (s=="divide") + m_adjust_image = ADJ_DIV; + else if (s=="" || s=="none") + m_adjust_image = ADJ_NONE; + else + printf("Incorrect adjust-image specification: '%s' - ignored.\n", + s.c_str()); node->get("alpha", &m_alpha_blending ); node->get("light", &m_lighting ); node->get("sphere", &m_sphere_map ); @@ -77,7 +88,8 @@ node->get("anisotropic", &m_anisotropic ); node->get("backface-culling", &m_backface_culling ); node->get("disable-z-write", &m_disable_z_write ); - std::string s(""); + + s=""; node->get("graphical-effect", &s ); if(s=="water") m_graphical_effect = GE_WATER; @@ -162,6 +174,7 @@ m_clamp_tex = 0; m_alpha_testing = false; m_lightmap = false; + m_adjust_image = ADJ_NONE; m_alpha_blending = false; m_lighting = true; m_anisotropic = false; @@ -201,7 +214,8 @@ const std::string &full_path = is_full_path ? m_texname : file_manager->getTextureFile(m_texname); - m_texture = irr_driver->getTexture(full_path); + m_texture = irr_driver->getTexture(full_path, + isPreMul(), isPreDiv()); // now set the name to the basename, so that all tests work as expected m_texname = StringUtils::getBasename(m_texname); Modified: main/trunk/src/graphics/material.hpp =================================================================== --- main/trunk/src/graphics/material.hpp 2011-02-16 06:02:30 UTC (rev 7711) +++ main/trunk/src/graphics/material.hpp 2011-02-16 06:07:38 UTC (rev 7712) @@ -96,7 +96,11 @@ /** Set to true to disable writing to the Z buffer. Usually to be used with alpha blending */ bool m_disable_z_write; - + + /** Some textures need to be pre-multiplied, some divided to give + * the intended effect. */ + enum {ADJ_NONE, ADJ_PREMUL, ADJ_DIV} + m_adjust_image; /** True if lightmapping is enabled for this material. */ bool m_lightmap; float m_friction; @@ -159,6 +163,12 @@ bool isTransparent () const { return m_alpha_testing || m_alpha_blending || m_add; } // ------------------------------------------------------------------------ + /** Returns true if this materials need pre-multiply of alpha. */ + bool isPreMul() const {return m_adjust_image==ADJ_PREMUL; } + // ------------------------------------------------------------------------ + /** Returns true if this materials need pre-division of alpha. */ + bool isPreDiv() const {return m_adjust_image==ADJ_DIV; } + // ------------------------------------------------------------------------ /** Returns the fraction of maximum speed on this material. */ float getMaxSpeedFraction() const { return m_max_speed_fraction; } // ------------------------------------------------------------------------ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-02-18 16:08:08
|
Revision: 7735 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7735&view=rev Author: auria Date: 2011-02-18 16:08:02 +0000 (Fri, 18 Feb 2011) Log Message: ----------- Enhance UnNamed's rotation effect, instead of rotating all cylinders toghether all the time make them receive an initial independent rotation each, IMHO this looks better Modified Paths: -------------- main/trunk/src/graphics/rain.cpp main/trunk/src/graphics/rain.hpp Modified: main/trunk/src/graphics/rain.cpp =================================================================== --- main/trunk/src/graphics/rain.cpp 2011-02-18 16:03:07 UTC (rev 7734) +++ main/trunk/src/graphics/rain.cpp 2011-02-18 16:08:02 UTC (rev 7735) @@ -28,7 +28,7 @@ const float RAIN_Y_TO = 25.0f; const float RAIN_Y_FROM = -10.0f; const float RAIN_DY = 2.5f; -const float RAIN_DX = 0.2f; +const float RAIN_DX = 0.0f; const float TEXTURE_X_TILES[RAIN_RING_COUNT] = { 2.0f, 2.5f, 3.5f, 5.0f, 8.0f }; const float TEXTURE_Y_TILES[RAIN_RING_COUNT] = { 8.0f, 7.0f, 6.0f, 4.0f, 4.0f }; @@ -36,13 +36,14 @@ Rain::Rain(irr::scene::ICameraSceneNode* camera, irr::scene::ISceneNode* parent) { - m_y = 0.0f; - m_x = 0.0f; Material* m = material_manager->getMaterial("rain.png"); assert(m != NULL); for (int r=0; r<RAIN_RING_COUNT; r++) { + m_x[r] = r/(float)RAIN_RING_COUNT; + m_y[r] = r/(float)RAIN_RING_COUNT; + scene::SMeshBuffer *buffer = new scene::SMeshBuffer(); buffer->Material.setTexture(0, m->getTexture()); @@ -114,17 +115,17 @@ void Rain::update(float dt) { - m_x = m_x + dt*RAIN_DX; - m_y = m_y + dt*RAIN_DY; - if (m_x > 1.0f) m_x = fmod(m_x, 1.0f); - if (m_y > 1.0f) m_y = fmod(m_y, 1.0f); - //const int count = m_materials.size(); for (int m=0; m<RAIN_RING_COUNT; m++) { + m_x[m] = m_x[m] + dt*RAIN_DX; + m_y[m] = m_y[m] + dt*RAIN_DY; + if (m_x[m] > 1.0f) m_x[m] = fmod(m_x[m], 1.0f); + if (m_y[m] > 1.0f) m_y[m] = fmod(m_y[m], 1.0f); + core::matrix4& matrix = m_node[m]->getChild()->getMaterial(0).getTextureMatrix(0); - matrix.setTextureTranslate(m_x, m_y); + matrix.setTextureTranslate(m_x[m], m_y[m]); } } // update Modified: main/trunk/src/graphics/rain.hpp =================================================================== --- main/trunk/src/graphics/rain.hpp 2011-02-18 16:03:07 UTC (rev 7734) +++ main/trunk/src/graphics/rain.hpp 2011-02-18 16:08:02 UTC (rev 7735) @@ -31,8 +31,8 @@ std::vector<irr::video::SMaterial*> m_materials; - float m_x; - float m_y; + float m_x[RAIN_RING_COUNT]; + float m_y[RAIN_RING_COUNT]; public: Rain(irr::scene::ICameraSceneNode* camera, irr::scene::ISceneNode* parent); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-02-28 22:35:36
|
Revision: 7773 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7773&view=rev Author: hikerstk Date: 2011-02-28 22:35:30 +0000 (Mon, 28 Feb 2011) Log Message: ----------- Simplified camera settings, fixed jump in camera when rescue is triggered. Modified Paths: -------------- main/trunk/src/graphics/camera.cpp main/trunk/src/graphics/camera.hpp Modified: main/trunk/src/graphics/camera.cpp =================================================================== --- main/trunk/src/graphics/camera.cpp 2011-02-28 21:43:13 UTC (rev 7772) +++ main/trunk/src/graphics/camera.cpp 2011-02-28 22:35:30 UTC (rev 7773) @@ -315,128 +315,177 @@ } // computeNormalCameraPosition //----------------------------------------------------------------------------- -/** Called once per time frame to move the camera to the right position. - * \param dt Time step. +/** Determine the camera settings for the current frame. + * \param above_kart How far above the camera should aim at. + * \param cam_angle Angle above the kart plane for the camera. + * \param sideway Sideway movement of the camera. + * \param distance Distance from kart. */ -void Camera::update(float dt) +void Camera::getCameraSettings(float *above_kart, float *cam_angle, + float *sideway, float *distance, + bool *smoothing) { - // The following settings give a debug camera which shows the track from - // high above the kart straight down. - if(UserConfigParams::m_camera_debug) - { - core::vector3df xyz = m_kart->getXYZ().toIrrVector(); - m_camera->setTarget(xyz); - xyz.Y = xyz.Y+30; - m_camera->setPosition(xyz); - m_camera->setNearValue(52.0); // To view inside tunnels (FIXME 52>30 why??? makes no sense) - return; - } + const KartProperties *kp = m_kart->getKartProperties(); - // If an explosion or rescue is happening, stop moving the camera, - // but keep it target on the kart. - if(m_kart->playingEmergencyAnimation()) + if( (m_mode==CM_NORMAL && m_camera_style==CS_MODERN) || + (m_mode==CM_FALLING) ) { - m_camera->setTarget(m_kart->getXYZ().toIrrVector()); + *above_kart = 0.75f; + float steering = m_kart->getSteerPercent() + * (1.0f + (m_kart->getSkidding() - 1.0f)/2.3f ); + // quadratically to dampen small variations (but keep sign) + float dampened_steer = fabsf(steering) * steering; + *cam_angle = kp->getCameraForwardUpAngle(); + *sideway = -m_rotation_range*dampened_steer*0.5f; + *distance = -m_distance; + *smoothing = true; return; } - - Vec3 wanted_position; - Vec3 wanted_target = m_kart->getXYZ(); - - - Vec3 relative_position; - const KartProperties *kp = m_kart->getKartProperties(); - const btTransform &trans = m_kart->getTrans(); - // Each case should set wanted_position and wanted_target according to - // what is needed for that mode. Yes, there is a lot of duplicate code - // but it is (IMHO) much easier to follow this way. switch(m_mode) { case CM_NORMAL: - { - switch (m_camera_style) - { - // 0.7 flexible link - case CS_MODERN: - { - computeNormalCameraPosition(&wanted_position, - &wanted_target); - smoothMoveCamera(dt, wanted_position, wanted_target); - break; - } + assert(m_camera_style==CS_CLASSIC); - // More like the 0.6 STK way - case CS_CLASSIC: - { - wanted_target.setY(wanted_target.getY()+ 0.3f); - float tan_up = tan(kp->getCameraBackwardUpAngle()); - relative_position.setValue(0, - 1.5f*m_distance*tan_up+0.3f, - -1.5f*m_distance ); - wanted_position = trans(relative_position); - smoothMoveCamera(dt, wanted_position, wanted_target); - break; - } - } + *above_kart = 0.3f; + *cam_angle = kp->getCameraBackwardUpAngle(); + *sideway = 0.0f; + *distance = -1.5f*m_distance; + *smoothing = true; break; - } case CM_FALLING: { - computeNormalCameraPosition(&wanted_position, &wanted_target); - wanted_position = m_camera->getPosition(); - smoothMoveCamera(dt, wanted_position, wanted_target); + *above_kart = 0.75f; + float steering = m_kart->getSteerPercent() + * (1.0f + (m_kart->getSkidding() - 1.0f)/2.3f ); + // quadratically to dampen small variations (but keep sign) + float dampened_steer = fabsf(steering) * steering; + *cam_angle = kp->getCameraForwardUpAngle(); + *sideway = -m_rotation_range*dampened_steer*0.5f; + *distance = m_distance; + *smoothing = true; break; - } - case CM_FINAL: - { - handleEndCamera(dt); - break; - } + } // CM_FALLING case CM_REVERSE: // Same as CM_NORMAL except it looks backwards { - wanted_target.setY(wanted_target.getY()+0.75f); - float tan_up = tan(kp->getCameraBackwardUpAngle()); - relative_position.setValue(0, - 2.0f*m_distance*tan_up+0.75f, - 2.0f*m_distance); - wanted_position = trans(relative_position); - smoothMoveCamera(dt, wanted_position, wanted_target); - m_camera->setPosition(wanted_position.toIrrVector()); - m_camera->setTarget(wanted_target.toIrrVector()); + *above_kart = 0.75f; + *cam_angle = kp->getCameraBackwardUpAngle(); + *sideway = 0; + *distance = 2.0f*m_distance; + *smoothing = false; break; } case CM_CLOSEUP: // Lower to the ground and closer to the kart { - wanted_target.setY(wanted_target.getY()+0.75f); - float tan_up = tan(20.0f*DEGREE_TO_RAD); - relative_position.setX( m_rotation_range - * m_kart->getSteerPercent() - * m_kart->getSkidding()); - relative_position.setY(0.5f*m_distance*tan_up+0.75f); - relative_position.setZ(0.5f*m_distance); - smoothMoveCamera(dt, wanted_position, wanted_target); + *above_kart = 0.75f; + *cam_angle = 20.0f*DEGREE_TO_RAD; + *sideway = m_rotation_range + * m_kart->getSteerPercent() + * m_kart->getSkidding(); + *distance = -0.5f*m_distance; + *smoothing = false; break; } case CM_LEADER_MODE: { - World *world = World::getWorld(); - Kart *kart = world->getKart(0); - wanted_target = kart->getXYZ().toIrrVector(); - float tan_up = tan(40.0f*DEGREE_TO_RAD); - wanted_position.setValue(0, - 2.0f*m_distance*tan_up, - 2.0f*m_distance); - smoothMoveCamera(dt, wanted_position, wanted_target); + *above_kart = 0.0f; + *cam_angle = 40*DEGREE_TO_RAD; + *sideway = 0; + *distance = 2.0f*m_distance; + *smoothing = true; break; } + case CM_FINAL: case CM_SIMPLE_REPLAY: // TODO: Implement break; } +} // get CameraPosition + +//----------------------------------------------------------------------------- +/** Called once per time frame to move the camera to the right position. + * \param dt Time step. + */ +void Camera::update(float dt) +{ + // The following settings give a debug camera which shows the track from + // high above the kart straight down. + if(UserConfigParams::m_camera_debug) + { + core::vector3df xyz = m_kart->getXYZ().toIrrVector(); + m_camera->setTarget(xyz); + xyz.Y = xyz.Y+30; + m_camera->setPosition(xyz); + m_camera->setNearValue(52.0); // To view inside tunnels (FIXME 52>30 why??? makes no sense) + return; + } + + if(m_mode==CM_FINAL) + { + handleEndCamera(dt); + return; + } + + float above_kart, cam_angle, side_way, distance; + bool smoothing; + getCameraSettings(&above_kart, &cam_angle, &side_way, &distance, + &smoothing); + + // If an explosion or rescue is happening, stop moving the camera, + // but keep it target on the kart. + if(m_kart->playingEmergencyAnimation()) + { + // The camera target needs to be 'smooth moved', otherwise + // there will be a noticable jump in the first frame + + // Aim at the usual same position of the kart (i.e. slightly + // above the kart). + core::vector3df wanted_target(m_kart->getXYZ().toIrrVector() + +core::vector3df(0, above_kart, 0) ); + core::vector3df current_target = m_camera->getTarget(); + // Note: this code is replicated from smoothMoveCamera so that + // the camera keeps on pointing to the same spot. + current_target += ((wanted_target-current_target)*m_target_speed)*dt; + + m_camera->setTarget(current_target); + return; + } + + positionCamera(dt, above_kart, cam_angle, side_way, distance, smoothing); } // update // ---------------------------------------------------------------------------- +/** Actually sets the camera based on the given parameter. + * \param above_kart How far above the camera should aim at. + * \param cam_angle Angle above the kart plane for the camera. + * \param sideway Sideway movement of the camera. + * \param distance Distance from kart. +*/ +void Camera::positionCamera(float dt, float above_kart, float cam_angle, + float side_way, float distance, float smoothing) +{ + Vec3 wanted_position; + Vec3 wanted_target = m_kart->getXYZ(); + + wanted_target.setY(wanted_target.getY()+above_kart); + + float tan_up = tan(cam_angle); + Vec3 relative_position(side_way, + fabsf(distance)*tan_up+above_kart, + distance); + const btTransform &trans=m_kart->getTrans(); + wanted_position = trans(relative_position); + if(smoothing) + smoothMoveCamera(dt, wanted_position, wanted_target); + else + { + m_camera->setPosition(wanted_position.toIrrVector()); + m_camera->setTarget(wanted_target.toIrrVector()); + } + +} // positionCamera + +// ---------------------------------------------------------------------------- /** This function handles the end camera. It adjusts the camera position * according to the current camera type, and checks if a switch to the * next camera should be made. @@ -469,23 +518,12 @@ } case EndCameraInformation::EC_AHEAD_OF_KART: { - Vec3 wanted_target = m_kart->getXYZ(); - wanted_target.setY(wanted_target.getY()+ 0.75f); - float angle_around = m_kart->getHeading() - //+ m_rotation_range * m_kart->getSteerPercent() - //* m_kart->getSkidding() - ; - float angle_up = m_kart->getKartProperties()->getCameraBackwardUpAngle() - - m_kart->getPitch() ; - Vec3 wanted_position; - wanted_position.setX( sin(angle_around)); - 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); - m_camera->setPosition(wanted_position.toIrrVector()); - m_camera->setTarget(wanted_target.toIrrVector()); + const KartProperties *kp=m_kart->getKartProperties(); + float cam_angle = kp->getCameraBackwardUpAngle(); + + positionCamera(dt, /*above_kart*/0.75f, + cam_angle, /*side_way*/0, + 2.0f*m_distance, /*smoothing*/false); break; } default: break; @@ -506,7 +544,7 @@ m_next_end_camera++; if(m_next_end_camera>=(unsigned)m_end_cameras.size()) m_next_end_camera = 0; } -} // handleEndCamera +} // checkForNextEndCamera // ---------------------------------------------------------------------------- /** Sets viewport etc. for this camera. Called from irr_driver just before Modified: main/trunk/src/graphics/camera.hpp =================================================================== --- main/trunk/src/graphics/camera.hpp 2011-02-28 21:43:13 UTC (rev 7772) +++ main/trunk/src/graphics/camera.hpp 2011-02-28 22:35:30 UTC (rev 7773) @@ -178,7 +178,11 @@ void computeNormalCameraPosition(Vec3 *wanted_position, Vec3 *wanted_target); void handleEndCamera(float dt); - + void getCameraSettings(float *above_kart, float *cam_angle, + float *side_way, float *distance, + bool *smoothing); + void positionCamera(float dt, float above_kart, float cam_angle, + float side_way, float distance, float smoothing); public: Camera (int camera_index, const Kart* kart); ~Camera (); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-03-03 03:15:33
|
Revision: 7797 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7797&view=rev Author: auria Date: 2011-03-03 03:15:27 +0000 (Thu, 03 Mar 2011) Log Message: ----------- Make slipstream fade in smoothly Modified Paths: -------------- main/trunk/src/graphics/slip_stream.cpp main/trunk/src/graphics/slip_stream.hpp Modified: main/trunk/src/graphics/slip_stream.cpp =================================================================== --- main/trunk/src/graphics/slip_stream.cpp 2011-03-02 23:15:07 UTC (rev 7796) +++ main/trunk/src/graphics/slip_stream.cpp 2011-03-03 03:15:27 UTC (rev 7797) @@ -252,6 +252,25 @@ // For real testing in game: this needs some tuning! m_node->setVisible(f!=0); MovingTexture::setSpeed(f, 0); + + + int c = f*255; + if (c > 255) c = 255; + + const unsigned int bcount = m_node->getMesh()->getMeshBufferCount(); + for (unsigned int b=0; b<bcount; b++) + { + scene::IMeshBuffer* mb = m_node->getMesh()->getMeshBuffer(b); + irr::video::S3DVertex* vertices = (video::S3DVertex*)mb->getVertices(); + for (unsigned int i=0; i<mb->getVertexCount(); i++) + { + const int color = c*(vertices[i].Color.getAlpha()/255.0f); + vertices[i].Color.setRed( color ); + vertices[i].Color.setGreen( color ); + vertices[i].Color.setBlue( color ); + } + } + return; // For debugging: make the slip stream effect visible all the time m_node->setVisible(true); Modified: main/trunk/src/graphics/slip_stream.hpp =================================================================== --- main/trunk/src/graphics/slip_stream.hpp 2011-03-02 23:15:07 UTC (rev 7796) +++ main/trunk/src/graphics/slip_stream.hpp 2011-03-03 03:15:27 UTC (rev 7797) @@ -39,7 +39,7 @@ Kart *m_kart; /** The scene node. */ - scene::ISceneNode *m_node; + scene::IMeshSceneNode *m_node; /** The actual mesh. */ scene::IMesh *m_mesh; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-03-05 23:04:32
|
Revision: 7823 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7823&view=rev Author: auria Date: 2011-03-05 23:04:26 +0000 (Sat, 05 Mar 2011) Log Message: ----------- Add support for parallax mapping Modified Paths: -------------- main/trunk/src/graphics/material.cpp main/trunk/src/graphics/material.hpp Modified: main/trunk/src/graphics/material.cpp =================================================================== --- main/trunk/src/graphics/material.cpp 2011-03-05 23:02:32 UTC (rev 7822) +++ main/trunk/src/graphics/material.cpp 2011-03-05 23:04:26 UTC (rev 7823) @@ -93,6 +93,12 @@ { m_normal_map = true; } + else if (node->get("parallax-map", &m_normal_map_tex)) + { + m_parallax_map = true; + m_parallax_height = 0.2f; + node->get("parallax-height", &m_parallax_height); + } s=""; node->get("graphical-effect", &s ); @@ -217,6 +223,7 @@ m_zipper_max_speed_increase = -1.0f; m_zipper_speed_gain = -1.0f; m_normal_map = false; + m_parallax_map = false; for (int n=0; n<EMIT_KINDS_COUNT; n++) { @@ -420,9 +427,16 @@ if (m_normal_map) { m->setTexture(1, irr_driver->getTexture(m_normal_map_tex)); - m->MaterialType = video::EMT_NORMAL_MAP_SOLID; // video::EMT_PARALLAX_MAP_SOLID + m->MaterialType = video::EMT_NORMAL_MAP_SOLID; modes++; } + if (m_parallax_map) + { + m->setTexture(1, irr_driver->getTexture(m_normal_map_tex)); + m->MaterialType = video::EMT_PARALLAX_MAP_SOLID; + m->MaterialTypeParam = m_parallax_height; + modes++; + } if (modes > 1) { Modified: main/trunk/src/graphics/material.hpp =================================================================== --- main/trunk/src/graphics/material.hpp 2011-03-05 23:02:32 UTC (rev 7822) +++ main/trunk/src/graphics/material.hpp 2011-03-05 23:04:26 UTC (rev 7823) @@ -85,6 +85,9 @@ bool m_normal_map; std::string m_normal_map_tex; + bool m_parallax_map; + float m_parallax_height; + /** Texture clamp bitmask */ unsigned int m_clamp_tex; bool m_lighting; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-03-06 01:13:10
|
Revision: 7824 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7824&view=rev Author: auria Date: 2011-03-06 01:13:02 +0000 (Sun, 06 Mar 2011) Log Message: ----------- Added support for heightmaps in parallax and normal mapping, since that seems to be irrlicht's preferred way to go Modified Paths: -------------- main/trunk/src/graphics/material.cpp main/trunk/src/graphics/material.hpp Modified: main/trunk/src/graphics/material.cpp =================================================================== --- main/trunk/src/graphics/material.cpp 2011-03-05 23:04:26 UTC (rev 7823) +++ main/trunk/src/graphics/material.cpp 2011-03-06 01:13:02 UTC (rev 7824) @@ -93,12 +93,24 @@ { m_normal_map = true; } + else if (node->get("normal-heightmap", &m_normal_map_tex)) + { + m_is_heightmap = true; + m_normal_map = true; + } else if (node->get("parallax-map", &m_normal_map_tex)) { m_parallax_map = true; m_parallax_height = 0.2f; node->get("parallax-height", &m_parallax_height); } + else if (node->get("parallax-heightmap", &m_normal_map_tex)) + { + m_is_heightmap = true; + m_parallax_map = true; + m_parallax_height = 0.2f; + node->get("parallax-height", &m_parallax_height); + } s=""; node->get("graphical-effect", &s ); @@ -224,6 +236,7 @@ m_zipper_speed_gain = -1.0f; m_normal_map = false; m_parallax_map = false; + m_is_heightmap = false; for (int n=0; n<EMIT_KINDS_COUNT; n++) { @@ -426,15 +439,26 @@ } if (m_normal_map) { - m->setTexture(1, irr_driver->getTexture(m_normal_map_tex)); + video::ITexture* tex = irr_driver->getTexture(m_normal_map_tex) ; + if (m_is_heightmap) + { + irr_driver->getVideoDriver()->makeNormalMapTexture( tex ); + } + m->setTexture(1, tex); m->MaterialType = video::EMT_NORMAL_MAP_SOLID; modes++; } if (m_parallax_map) { - m->setTexture(1, irr_driver->getTexture(m_normal_map_tex)); + video::ITexture* tex = irr_driver->getTexture(m_normal_map_tex); + if (m_is_heightmap) + { + irr_driver->getVideoDriver()->makeNormalMapTexture( tex ); + } + m->setTexture(1, tex); m->MaterialType = video::EMT_PARALLAX_MAP_SOLID; m->MaterialTypeParam = m_parallax_height; + m->SpecularColor.set(0,0,0,0); modes++; } Modified: main/trunk/src/graphics/material.hpp =================================================================== --- main/trunk/src/graphics/material.hpp 2011-03-05 23:04:26 UTC (rev 7823) +++ main/trunk/src/graphics/material.hpp 2011-03-06 01:13:02 UTC (rev 7824) @@ -84,7 +84,7 @@ /** For normal maps */ bool m_normal_map; std::string m_normal_map_tex; - + bool m_is_heightmap; bool m_parallax_map; float m_parallax_height; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-03-15 18:25:33
|
Revision: 7901 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7901&view=rev Author: auria Date: 2011-03-15 18:25:27 +0000 (Tue, 15 Mar 2011) Log Message: ----------- Improved error handling (don't crash when invalid particles are defined) Modified Paths: -------------- main/trunk/src/graphics/material.cpp main/trunk/src/graphics/particle_emitter.cpp main/trunk/src/graphics/particle_kind.cpp main/trunk/src/graphics/particle_kind.hpp Modified: main/trunk/src/graphics/material.cpp =================================================================== --- main/trunk/src/graphics/material.cpp 2011-03-14 22:20:10 UTC (rev 7900) +++ main/trunk/src/graphics/material.cpp 2011-03-15 18:25:27 UTC (rev 7901) @@ -333,7 +333,7 @@ if (count == 0) { - fprintf(stderr, "[Material::initParticlesEffect] WARNING: Particles '%s' for material '%s' are declared but not used\n", + fprintf(stderr, "[Material::initParticlesEffect] WARNING: Particles '%s' for material '%s' are declared but not used (no emission condition set)\n", base.c_str(), m_texname.c_str()); } Modified: main/trunk/src/graphics/particle_emitter.cpp =================================================================== --- main/trunk/src/graphics/particle_emitter.cpp 2011-03-14 22:20:10 UTC (rev 7900) +++ main/trunk/src/graphics/particle_emitter.cpp 2011-03-15 18:25:27 UTC (rev 7901) @@ -263,7 +263,7 @@ //----------------------------------------------------------------------------- void ParticleEmitter::setParticleType(const ParticleKind* type) -{ +{ assert(m_magic_number == 0x58781325); if (m_particle_type == type) return; // already the right type @@ -291,28 +291,39 @@ const int lifeTimeMin = type->getMinLifetime(); const int lifeTimeMax = type->getMaxLifetime(); - assert(material->getTexture() != NULL); assert(maxSize >= minSize); assert(lifeTimeMax >= lifeTimeMin); #ifdef DEBUG - video::ITexture* tex = material->getTexture(); - assert(tex != NULL); - const io::SNamedPath& name = tex->getName(); - const io::path& tpath = name.getPath(); - - std::string debug_name = std::string("particles(") + tpath.c_str() + ")"; - m_node->setName(debug_name.c_str()); + if (material != NULL) + { + video::ITexture* tex = material->getTexture(); + assert(tex != NULL); + const io::SNamedPath& name = tex->getName(); + const io::path& tpath = name.getPath(); + + std::string debug_name = std::string("particles(") + tpath.c_str() + ")"; + m_node->setName(debug_name.c_str()); + } #endif video::SMaterial& mat0 = m_node->getMaterial(0); m_node->setPosition(m_position.toIrrVector()); - material->setMaterialProperties(&mat0); - m_node->setMaterialTexture(0, material->getTexture()); - mat0.ZWriteEnable = !material->isTransparent(); // disable z-buffer writes if material is transparent + if (material != NULL) + { + assert(material->getTexture() != NULL); + material->setMaterialProperties(&mat0); + m_node->setMaterialTexture(0, material->getTexture()); + mat0.ZWriteEnable = !material->isTransparent(); // disable z-buffer writes if material is transparent + } + else + { + m_node->setMaterialTexture(0, irr_driver->getTexture((file_manager->getDataDir() + "/gui/main_help.png").c_str())); + } + switch (type->getShape()) { case EMITTER_POINT: @@ -320,7 +331,7 @@ m_emitter = m_node->createPointEmitter(core::vector3df(m_particle_type->getVelocityX(), m_particle_type->getVelocityY(), m_particle_type->getVelocityZ()), // velocity in m/ms - type->getMinRate(), type->getMaxRate(), + type->getMinRate(), type->getMaxRate(), type->getMinColor(), type->getMaxColor(), lifeTimeMin, lifeTimeMax, m_particle_type->getAngleSpread() /* angle */ @@ -338,7 +349,7 @@ core::vector3df(m_particle_type->getVelocityX(), m_particle_type->getVelocityY(), m_particle_type->getVelocityZ()), // velocity in m/ms - type->getMinRate(), type->getMaxRate(), + type->getMinRate(), type->getMaxRate(), type->getMinColor(), type->getMaxColor(), lifeTimeMin, lifeTimeMax, m_particle_type->getAngleSpread() /* angle */ Modified: main/trunk/src/graphics/particle_kind.cpp =================================================================== --- main/trunk/src/graphics/particle_kind.cpp 2011-03-14 22:20:10 UTC (rev 7900) +++ main/trunk/src/graphics/particle_kind.cpp 2011-03-15 18:25:27 UTC (rev 7901) @@ -28,7 +28,8 @@ #include <stdexcept> -ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,255,255), m_max_start_color(255,255,255,255) +ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,255,255), + m_max_start_color(255,255,255,255), m_name(file) { // ---- Initial values to prevent readin uninitialized values m_max_size = 0.5f; @@ -135,7 +136,7 @@ } else { - fprintf(stderr, "[ParticleKind] WARNING: particle image '%s' does not appear in the list of currently known materials, it will be opaque", materialFile.c_str()); + fprintf(stderr, "[ParticleKind] WARNING: particle image '%s' does not appear in the list of currently known materials\n", materialFile.c_str()); } // ------------------------------------------------------------------------ Modified: main/trunk/src/graphics/particle_kind.hpp =================================================================== --- main/trunk/src/graphics/particle_kind.hpp 2011-03-14 22:20:10 UTC (rev 7900) +++ main/trunk/src/graphics/particle_kind.hpp 2011-03-15 18:25:27 UTC (rev 7901) @@ -83,6 +83,8 @@ /** Distance from camera at which particles start fading out, or negative if disabled */ float m_fade_away_start, m_fade_away_end; + std::string m_name; + public: /** @@ -134,6 +136,8 @@ void setBoxSizeX (float newVal) { m_box_x = newVal; } void setBoxSizeY (float newVal) { m_box_y = newVal; } void setBoxSizeZ (float newVal) { m_box_z = newVal; } + + std::string getName() const { return m_name; } }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-04-20 13:04:28
|
Revision: 8391 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=8391&view=rev Author: hikerstk Date: 2011-04-20 13:04:21 +0000 (Wed, 20 Apr 2011) Log Message: ----------- Cosmetic changes, use m_video_driver instead of calling a function to get it. Modified Paths: -------------- main/trunk/src/graphics/irr_driver.cpp main/trunk/src/graphics/irr_driver.hpp Modified: main/trunk/src/graphics/irr_driver.cpp =================================================================== --- main/trunk/src/graphics/irr_driver.cpp 2011-04-20 01:53:25 UTC (rev 8390) +++ main/trunk/src/graphics/irr_driver.cpp 2011-04-20 13:04:21 UTC (rev 8391) @@ -52,7 +52,7 @@ /** singleton */ IrrDriver *irr_driver = NULL; -const int MIN_SUPPORTED_HEIGHT = 600; //TODO: do some tests, 600 might be too small without a special menu +const int MIN_SUPPORTED_HEIGHT = 600; const int MIN_SUPPORTED_WIDTH = 800; // ---------------------------------------------------------------------------- @@ -88,11 +88,7 @@ video::IVideoModeList* modes = m_device->getVideoModeList(); const int count = modes->getVideoModeCount(); - //std::cout << "--------------\n allowed modes \n--------------\n"; - //std::cout << "Desktop depth : " << modes->getDesktopDepth() << std::endl; - //std::cout << "Desktop resolution : " << modes->getDesktopResolution().Width << "," << modes->getDesktopResolution().Height << std::endl; - - //std::cout << "Found " << count << " valid modes\n"; + for(int i=0; i<count; i++) { // only consider 32-bit resolutions for now @@ -100,7 +96,8 @@ { const int w = modes->getVideoModeResolution(i).Width; const int h = modes->getVideoModeResolution(i).Height; - if (h < MIN_SUPPORTED_HEIGHT || w < MIN_SUPPORTED_WIDTH) continue; + if (h < MIN_SUPPORTED_HEIGHT || w < MIN_SUPPORTED_WIDTH) + continue; VideoMode mode; mode.width = w; @@ -224,21 +221,11 @@ // Force creation of mipmaps even if the mipmaps flag in a b3d file // does not set the 'enable mipmap' flag. - m_scene_manager->getParameters()->setAttribute(scene::B3D_LOADER_IGNORE_MIPMAP_FLAG, true); - m_device->getVideoDriver()->setTextureCreationFlag( - video::ETCF_CREATE_MIP_MAPS, - true); - //m_device->getVideoDriver()->setTextureCreationFlag( - // video::ETCF_OPTIMIZED_FOR_SPEED , - // true); - //m_device->getVideoDriver()->setTextureCreationFlag( - // video::ETCF_ALWAYS_16_BIT , - // true); + m_scene_manager->getParameters() + ->setAttribute(scene::B3D_LOADER_IGNORE_MIPMAP_FLAG, true); + m_device->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS,true); m_gui_env = m_device->getGUIEnvironment(); - m_video_driver = m_device->getVideoDriver(); - //const std::string &font = file_manager->getFontFile("DomesticManners.xml"); - //m_race_font = m_gui_env->getFont(font.c_str()); - + m_video_driver = m_device->getVideoDriver(); video::SMaterial& material2D = m_video_driver->getMaterial2D(); material2D.setFlag(video::EMF_ANTI_ALIASING, true); @@ -259,9 +246,8 @@ // so let's decide ourselves...) m_device->getCursorControl()->setVisible(true); m_pointer_shown = true; -} +} // initDevice - //----------------------------------------------------------------------------- video::E_DRIVER_TYPE IrrDriver::getEngineDriverType( int index ) { @@ -356,13 +342,12 @@ { // show black before resolution switch so we don't see OpenGL's buffer // garbage during switch - m_device->getVideoDriver()->beginScene(true, true, - video::SColor(255,100,101,140)); - m_device->getVideoDriver()->draw2DRectangle( SColor(255, 0, 0, 0), - core::rect<s32>(0, 0, - UserConfigParams::m_prev_width, - UserConfigParams::m_prev_height) ); - m_device->getVideoDriver()->endScene(); + m_video_driver->beginScene(true, true, video::SColor(255,100,101,140)); + m_video_driver->draw2DRectangle( SColor(255, 0, 0, 0), + core::rect<s32>(0, 0, + UserConfigParams::m_prev_width, + UserConfigParams::m_prev_height) ); + m_video_driver->endScene(); attachment_manager -> removeTextures(); projectile_manager -> removeTextures(); @@ -567,26 +552,34 @@ // ---------------------------------------------------------------------------- -PerCameraNode *IrrDriver::addPerCameraMesh(scene::IMesh* mesh, scene::ICameraSceneNode* camera, +PerCameraNode *IrrDriver::addPerCameraMesh(scene::IMesh* mesh, + scene::ICameraSceneNode* camera, scene::ISceneNode *parent) { - return new PerCameraNode((parent != NULL ? parent : m_scene_manager->getRootSceneNode()), m_scene_manager, -1, camera, mesh); + return new PerCameraNode((parent ? parent + : m_scene_manager->getRootSceneNode()), + m_scene_manager, -1, camera, mesh); } // addMesh // ---------------------------------------------------------------------------- /** Adds a billboard node to scene. */ -scene::ISceneNode *IrrDriver::addBillboard(const core::dimension2d< f32 > size, video::ITexture *texture, scene::ISceneNode* parent) +scene::ISceneNode *IrrDriver::addBillboard(const core::dimension2d< f32 > size, + video::ITexture *texture, + scene::ISceneNode* parent) { - scene::IBillboardSceneNode* node = m_scene_manager->addBillboardSceneNode(parent, size); + scene::IBillboardSceneNode* node = + m_scene_manager->addBillboardSceneNode(parent, size); assert(node->getMaterialCount() > 0); node->setMaterialTexture(0, texture); return node; } // addMesh // ---------------------------------------------------------------------------- -/** Creates a quad mesh buffer and adds it to the scene graph. (FIXME: wrong docs? I don't think it does) +/** Creates a quad mesh with a given material. + * \param material The material to use (NULL if no material). + * \param create_one_quad If true creates one quad in the mesh. */ scene::IMesh *IrrDriver::createQuadMesh(const video::SMaterial *material, bool create_one_quad) @@ -624,7 +617,12 @@ return mesh; } // createQuadMesh -/** Creates a quad mesh buffer +// ---------------------------------------------------------------------------- +/** Creates a quad mesh buffer with a given width and height (z coordinate is + * 0). + * \param material The material to use for this quad. + * \param w Width of the quad. + * \param h Height of the quad. */ scene::IMesh *IrrDriver::createTexturedQuadMesh(const video::SMaterial *material, const double w, const double h) @@ -797,13 +795,13 @@ { video::ITexture* out; if(!is_premul && !is_prediv) - out = m_scene_manager->getVideoDriver()->getTexture(filename.c_str()); + out = m_video_driver->getTexture(filename.c_str()); else { // FIXME: can't we just do this externally, and just use the // modified textures?? video::IImage* img = - m_scene_manager->getVideoDriver()->createImageFromFile(filename.c_str()); + m_video_driver->createImageFromFile(filename.c_str()); // PNGs are non premul, but some are used for premul tasks, so convert // http://home.comcast.net/~tom_forsyth/blog.wiki.html#[[Premultiplied%20alpha]] // FIXME check param, not name @@ -853,8 +851,7 @@ } // for x img->unlock(); } // if premul && color format && lock - out = m_scene_manager->getVideoDriver()->addTexture(filename.c_str(), - img, NULL); + out = m_video_driver->addTexture(filename.c_str(), img, NULL); } // if is_premul or is_prediv #ifndef NDEBUG @@ -869,14 +866,15 @@ } // getTexture // ---------------------------------------------------------------------------- - -ITexture* IrrDriver::applyMask(video::ITexture* texture, const std::string& mask_path) +ITexture* IrrDriver::applyMask(video::ITexture* texture, + const std::string& mask_path) { video::IImage* img = - m_scene_manager->getVideoDriver()->createImage(texture, core::position2d<s32>(0,0), texture->getSize()); + m_video_driver->createImage(texture, core::position2d<s32>(0,0), + texture->getSize()); video::IImage* mask = - m_scene_manager->getVideoDriver()->createImageFromFile(mask_path.c_str()); + m_video_driver->createImageFromFile(mask_path.c_str()); if (img == NULL || mask == NULL) return NULL; @@ -902,7 +900,8 @@ return NULL; } - ITexture *t = m_scene_manager->getVideoDriver()->addTexture(texture->getName().getPath().c_str(), img, NULL); + ITexture *t = m_video_driver->addTexture(texture->getName().getPath().c_str(), + img, NULL); img->drop(); mask->drop(); return t; @@ -934,18 +933,21 @@ no_trust--; static video::SColor fpsColor = video::SColor(255, 255, 0, 0); - font->draw( L"FPS: ...", core::rect< s32 >(100,0,400,50), fpsColor, false ); + font->draw( L"FPS: ...", core::rect< s32 >(100,0,400,50), fpsColor, + false ); return; } - // Ask for current frames per second and last number of triangles processed (trimed to thousands) - const int fps = m_device->getVideoDriver()->getFPS(); - const float kilotris = m_device->getVideoDriver()->getPrimitiveCountDrawn(0) + // Ask for current frames per second and last number of triangles + // processed (trimed to thousands) + const int fps = m_video_driver->getFPS(); + const float kilotris = m_video_driver->getPrimitiveCountDrawn(0) * (1.f / 1000.f); // Min and max info tracking, per mode, so user can check game vs menus - bool current_state = StateManager::get()->getGameState() == GUIEngine::GAME; + bool current_state = StateManager::get()->getGameState() + == GUIEngine::GAME; static bool prev_state = false; static int min = 999; // Absurd values for start will print first time static int max = 0; // but no big issue, maybe even "invisible" @@ -1008,17 +1010,18 @@ // With bullet debug view we have to clear the back buffer, but // that's not necessary for non-debug - bool back_buffer_clear = inRace && (world->getPhysics()->isDebug() || world->clearBackBuffer()); + bool back_buffer_clear = inRace && (world->getPhysics()->isDebug() || + world->clearBackBuffer() ); if (world != NULL) { - m_device->getVideoDriver()->beginScene(back_buffer_clear, + m_video_driver->beginScene(back_buffer_clear, true, world->getClearColor()); } else { - m_device->getVideoDriver()->beginScene(back_buffer_clear, - true, video::SColor(255,100,101,140)); + m_video_driver->beginScene(back_buffer_clear, + true, video::SColor(255,100,101,140)); } { // Just to mark the begin/end scene block @@ -1079,7 +1082,7 @@ } } // just to mark the begin/end scene block - m_device->getVideoDriver()->endScene(); + m_video_driver->endScene(); // Enable this next print statement to get render information printed // E.g. number of triangles rendered, culled etc. The stats is only // printed while the race is running and not while the in-game menu @@ -1093,8 +1096,9 @@ // Irrlicht Event handler. bool IrrDriver::OnEvent(const irr::SEvent &event) { - //TODO: ideally we wouldn't use this object to STFU irrlicht's chatty debugging, we'd - // just create the EventHandler earlier so it can act upon it + //TODO: ideally we wouldn't use this object to STFU irrlicht's chatty + // debugging, we'd just create the EventHandler earlier so it + // can act upon it switch (event.EventType) { case irr::EET_LOG_TEXT_EVENT: @@ -1128,12 +1132,12 @@ */ IrrDriver::RTTProvider::RTTProvider(const core::dimension2du &dimension, const std::string &name) -{ +{ m_video_driver = irr_driver->getVideoDriver(); - - m_render_target_texture = m_video_driver->addRenderTargetTexture(dimension, - name.c_str(), - video::ECF_A8R8G8B8); + m_render_target_texture = + m_video_driver->addRenderTargetTexture(dimension, + name.c_str(), + video::ECF_A8R8G8B8); if (m_render_target_texture != NULL) { m_video_driver->setRenderTarget(m_render_target_texture); @@ -1152,9 +1156,9 @@ // ---------------------------------------------------------------------------- /** Sets up a given vector of meshes for render-to-texture. Ideal to embed a 3D - * object inside the GUI. If there are multiple meshes, the first mesh is considered - * to be the root, and all following meshes will have their locations relative to - * the location of the first mesh. + * object inside the GUI. If there are multiple meshes, the first mesh is + * considered to be the root, and all following meshes will have their + * locations relative to the location of the first mesh. */ void IrrDriver::RTTProvider::setupRTTScene(PtrVector<scene::IMesh, REF>& mesh, AlignedArray<Vec3>& mesh_location, @@ -1163,14 +1167,17 @@ { if (model_frames[0] == -1) { - scene::ISceneNode* node = irr_driver->getSceneManager()->addMeshSceneNode(mesh.get(0), NULL); + scene::ISceneNode* node = + irr_driver->getSceneManager()->addMeshSceneNode(mesh.get(0), NULL); node->setPosition( mesh_location[0].toIrrVector() ); node->setScale( mesh_scale[0].toIrrVector() ); m_rtt_main_node = node; } else { - scene::IAnimatedMeshSceneNode* node = irr_driver->getSceneManager()->addAnimatedMeshSceneNode((IAnimatedMesh*)mesh.get(0), NULL); + scene::IAnimatedMeshSceneNode* node = + irr_driver->getSceneManager()->addAnimatedMeshSceneNode( + (IAnimatedMesh*)mesh.get(0), NULL ); node->setPosition( mesh_location[0].toIrrVector() ); node->setFrameLoop(model_frames[0], model_frames[0]); node->setAnimationSpeed(0); @@ -1188,14 +1195,19 @@ { if (model_frames[n] == -1) { - scene::ISceneNode* node = irr_driver->getSceneManager()->addMeshSceneNode(mesh.get(n), m_rtt_main_node); + scene::ISceneNode* node = + irr_driver->getSceneManager()->addMeshSceneNode(mesh.get(n), + m_rtt_main_node); node->setPosition( mesh_location[n].toIrrVector() ); node->updateAbsolutePosition(); node->setScale( mesh_scale[n].toIrrVector() ); } else { - scene::IAnimatedMeshSceneNode* node = irr_driver->getSceneManager()->addAnimatedMeshSceneNode((IAnimatedMesh*)mesh.get(n), m_rtt_main_node); + scene::IAnimatedMeshSceneNode* node = + irr_driver->getSceneManager() + ->addAnimatedMeshSceneNode((IAnimatedMesh*)mesh.get(n), + m_rtt_main_node ); node->setPosition( mesh_location[n].toIrrVector() ); node->setFrameLoop(model_frames[n], model_frames[n]); node->setAnimationSpeed(0); @@ -1205,12 +1217,17 @@ } } - irr_driver->getSceneManager()->setAmbientLight(video::SColor(255, 120, 120, 120)); + irr_driver->getSceneManager()->setAmbientLight(video::SColor(255, 120, + 120, 120) ); const core::vector3df &sun_pos = core::vector3df( 0, 200, 100.0f ); - m_light = irr_driver->getSceneManager()->addLightSceneNode(NULL, sun_pos, video::SColorf(1.0f,1.0f,1.0f), 10000.0f /* radius */); - m_light->getLightData().DiffuseColor = irr::video::SColorf(0.5f, 0.5f, 0.5f, 0.5f); - m_light->getLightData().SpecularColor = irr::video::SColorf(1.0f, 1.0f, 1.0f, 1.0f); + m_light = irr_driver->getSceneManager() + ->addLightSceneNode(NULL, sun_pos, video::SColorf(1.0f,1.0f,1.0f), + 10000.0f /* radius */); + m_light->getLightData().DiffuseColor + = irr::video::SColorf(0.5f, 0.5f, 0.5f, 0.5f); + m_light->getLightData().SpecularColor + = irr::video::SColorf(1.0f, 1.0f, 1.0f, 1.0f); m_rtt_main_node->setMaterialFlag(EMF_GOURAUD_SHADING , true); m_rtt_main_node->setMaterialFlag(EMF_LIGHTING, true); @@ -1220,7 +1237,8 @@ { m_rtt_main_node->getMaterial(n).setFlag(EMF_LIGHTING, true); - m_rtt_main_node->getMaterial(n).Shininess = 100.0f; // set size of specular highlights + // set size of specular highlights + m_rtt_main_node->getMaterial(n).Shininess = 100.0f; m_rtt_main_node->getMaterial(n).SpecularColor.set(255,50,50,50); m_rtt_main_node->getMaterial(n).DiffuseColor.set(255,150,150,150); @@ -1273,7 +1291,8 @@ if(!is_2d_render) m_video_driver->setRenderTarget(m_render_target_texture); - if (angle != -1 && m_rtt_main_node != NULL) m_rtt_main_node->setRotation( core::vector3df(0, angle, 0) ); + if (angle != -1 && m_rtt_main_node != NULL) + m_rtt_main_node->setRotation( core::vector3df(0, angle, 0) ); if (m_rtt_main_node == NULL) { Modified: main/trunk/src/graphics/irr_driver.hpp =================================================================== --- main/trunk/src/graphics/irr_driver.hpp 2011-04-20 01:53:25 UTC (rev 8390) +++ main/trunk/src/graphics/irr_driver.hpp 2011-04-20 13:04:21 UTC (rev 8391) @@ -46,7 +46,8 @@ }; /** - * \brief class that creates the irrLicht device and offers higher-level ways to manage the 3D scene + * \brief class that creates the irrLicht device and offers higher-level + * ways to manage the 3D scene * \ingroup graphics */ class IrrDriver : public IEventReceiver, public NoCopy @@ -105,7 +106,8 @@ gui::IGUIEnvironment *getGUI() const { return m_gui_env; } //irr::gui::IGUIFont *getRaceFont() const { return m_race_font; } - video::ITexture *applyMask(video::ITexture* texture, const std::string& mask_path); + video::ITexture *applyMask(video::ITexture* texture, + const std::string& mask_path); void displayFPS(); /** this is not really used to process events, it's only used to shut down irrLicht's @@ -119,14 +121,19 @@ bool is_prediv=false); scene::IMesh *createQuadMesh(const video::SMaterial *material=NULL, bool create_one_quad=false); - scene::IMesh *createTexturedQuadMesh(const video::SMaterial *material, const double w, const double h); + scene::IMesh *createTexturedQuadMesh(const video::SMaterial *material, + const double w, const double h); scene::ISceneNode *addWaterNode(scene::IMesh *mesh, float wave_height, float wave_speed, float wave_length); scene::IMeshSceneNode*addOctTree(scene::IMesh *mesh); scene::IMeshSceneNode*addMesh(scene::IMesh *mesh, scene::ISceneNode *parent=NULL); - PerCameraNode *addPerCameraMesh(scene::IMesh* mesh, scene::ICameraSceneNode* node, scene::ISceneNode *parent = NULL); - scene::ISceneNode *addBillboard(const core::dimension2d< f32 > size, video::ITexture *texture, scene::ISceneNode* parent=NULL); + PerCameraNode *addPerCameraMesh(scene::IMesh* mesh, + scene::ICameraSceneNode* node, + scene::ISceneNode *parent = NULL); + scene::ISceneNode *addBillboard(const core::dimension2d< f32 > size, + video::ITexture *texture, + scene::ISceneNode* parent=NULL); scene::IParticleSystemSceneNode *addParticleNode(bool default_emitter=true); @@ -164,16 +171,19 @@ void draw2dTriangle(const core::vector2df &a, const core::vector2df &b, const core::vector2df &c, const video::ITexture *texture = NULL, - const video::SColor *ca=NULL, const video::SColor *cb=NULL, + const video::SColor *ca=NULL, + const video::SColor *cb=NULL, const video::SColor *cc=NULL); // --------------------- RTT -------------------- /** - * Class that provides RTT (currently, only when no other 3D rendering in the main scene is required) - * Provides an optional 'setupRTTScene' method to make it quick and easy to prepare rendering of 3D objects - * but you can also manually set the scene/camera. If you use the factory 'setupRTTScene', cleanup can be - * done through 'tearDownRTTScene' (destructor will also do this). If you set it up manually, you need - * to clean it up manually. + * Class that provides RTT (currently, only when no other 3D rendering + * in the main scene is required) + * Provides an optional 'setupRTTScene' method to make it quick and easy + * to prepare rendering of 3D objects but you can also manually set the + * scene/camera. If you use the factory 'setupRTTScene', cleanup can be + * done through 'tearDownRTTScene' (destructor will also do this). If + * you set it up manually, you need to clean it up manually. */ class RTTProvider { @@ -198,17 +208,21 @@ ~RTTProvider(); /** - * \brief Quick utility method to setup a scene from a plain list of models + * \brief Quick utility method to setup a scene from a plain list + * of models * - * Sets up a given vector of meshes for render-to-texture. Ideal to embed a 3D - * object inside the GUI. If there are multiple meshes, the first mesh is considered - * to be the root, and all following meshes will have their locations relative to - * the location of the first mesh. + * Sets up a given vector of meshes for render-to-texture. Ideal to + * embed a 3D object inside the GUI. If there are multiple meshes, + * the first mesh is considered to be the root, and all following + * meshes will have their locations relative to the location of the + * first mesh. * * \param mesh The list of meshes to add to the scene * \param mesh_location Location of each fo these meshes - * \param model_frames For animated meshes, which frame to use (value can be -1 to set none) - * When frame is not -1, the corresponding IMesh must be an IAnimatedMesh. + * \param model_frames For animated meshes, which frame to use + * (value can be -1 to set none) + * When frame is not -1, the corresponding + * IMesh must be an IAnimatedMesh. * \pre The 3 vectors have the same size. */ void setupRTTScene(PtrVector<scene::IMesh, REF>& mesh, @@ -216,7 +230,8 @@ AlignedArray<Vec3>& mesh_scale, const std::vector<int>& model_frames); - /** Optional 'angle' parameter will rotate the object added *through setupRTTScene* */ + /** Optional 'angle' parameter will rotate the object added + * *through setupRTTScene* */ video::ITexture* renderToTexture(float angle=-1, bool is_2d_render=false); @@ -230,4 +245,3 @@ extern IrrDriver *irr_driver; #endif // HEADER_IRR_DRIVER_HPP - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-04-20 20:40:16
|
Revision: 8397 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=8397&view=rev Author: auria Date: 2011-04-20 20:40:10 +0000 (Wed, 20 Apr 2011) Log Message: ----------- Hopefully fixed bug with masked textures Modified Paths: -------------- main/trunk/src/graphics/irr_driver.cpp main/trunk/src/graphics/material.cpp Modified: main/trunk/src/graphics/irr_driver.cpp =================================================================== --- main/trunk/src/graphics/irr_driver.cpp 2011-04-20 20:05:42 UTC (rev 8396) +++ main/trunk/src/graphics/irr_driver.cpp 2011-04-20 20:40:10 UTC (rev 8397) @@ -900,7 +900,8 @@ return NULL; } - ITexture *t = m_video_driver->addTexture(texture->getName().getPath().c_str(), + //printf("* Adding '%s'\n", texture->getName().getPath().c_str()); + ITexture *t = m_video_driver->addTexture(StringUtils::getBasename(texture->getName().getPath().c_str()).c_str(), img, NULL); img->drop(); mask->drop(); Modified: main/trunk/src/graphics/material.cpp =================================================================== --- main/trunk/src/graphics/material.cpp 2011-04-20 20:05:42 UTC (rev 8396) +++ main/trunk/src/graphics/material.cpp 2011-04-20 20:40:10 UTC (rev 8397) @@ -256,13 +256,16 @@ m_texture = irr_driver->getTexture(full_path, isPreMul(), isPreDiv()); + // now set the name to the basename, so that all tests work as expected + m_texname = StringUtils::getBasename(m_texname); + if (m_mask.size() > 0) { - m_texture = irr_driver->applyMask(m_texture, m_mask); + video::ITexture* tex = irr_driver->applyMask(m_texture, m_mask); + if (tex) m_texture = tex; + else fprintf(stderr, "Applying mask failed for '%s'!\n", m_texname.c_str()); } - // now set the name to the basename, so that all tests work as expected - m_texname = StringUtils::getBasename(m_texname); } // install //----------------------------------------------------------------------------- Material::~Material() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-04-24 17:43:34
|
Revision: 8439 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=8439&view=rev Author: auria Date: 2011-04-24 17:43:28 +0000 (Sun, 24 Apr 2011) Log Message: ----------- remove anisotropic from material.xml code Modified Paths: -------------- main/trunk/src/graphics/material.cpp main/trunk/src/graphics/material.hpp Modified: main/trunk/src/graphics/material.cpp =================================================================== --- main/trunk/src/graphics/material.cpp 2011-04-24 17:33:21 UTC (rev 8438) +++ main/trunk/src/graphics/material.cpp 2011-04-24 17:43:28 UTC (rev 8439) @@ -87,7 +87,6 @@ node->get("additive", &m_add ); node->get("max-speed", &m_max_speed_fraction); node->get("slowdown-time", &m_slowdown_time ); - node->get("anisotropic", &m_anisotropic ); node->get("backface-culling", &m_backface_culling ); node->get("disable-z-write", &m_disable_z_write ); @@ -213,7 +212,6 @@ m_adjust_image = ADJ_NONE; m_alpha_blending = false; m_lighting = true; - m_anisotropic = false; m_backface_culling = true; m_sphere_map = false; m_friction = 1.0f; Modified: main/trunk/src/graphics/material.hpp =================================================================== --- main/trunk/src/graphics/material.hpp 2011-04-24 17:33:21 UTC (rev 8438) +++ main/trunk/src/graphics/material.hpp 2011-04-24 17:43:28 UTC (rev 8439) @@ -99,9 +99,6 @@ /** True if backface culliing should be enabled. */ bool m_backface_culling; - - /** Whether to use anisotropic filtering for this texture */ - bool m_anisotropic; /** Set to true to disable writing to the Z buffer. Usually to be used with alpha blending */ bool m_disable_z_write; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mbj...@us...> - 2011-07-14 02:45:31
|
Revision: 9254 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=9254&view=rev Author: mbjornstk Date: 2011-07-14 02:45:24 +0000 (Thu, 14 Jul 2011) Log Message: ----------- Add svn props. Property Changed: ---------------- main/trunk/src/graphics/hardware_skinning.cpp main/trunk/src/graphics/hardware_skinning.hpp Property changes on: main/trunk/src/graphics/hardware_skinning.cpp ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Property changes on: main/trunk/src/graphics/hardware_skinning.hpp ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mbj...@us...> - 2011-07-22 00:52:48
|
Revision: 9320 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=9320&view=rev Author: mbjornstk Date: 2011-07-22 00:52:42 +0000 (Fri, 22 Jul 2011) Log Message: ----------- Set props as per SVN-CONFIG file. Property Changed: ---------------- main/trunk/src/graphics/post_processing.cpp main/trunk/src/graphics/post_processing.hpp Property changes on: main/trunk/src/graphics/post_processing.cpp ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Property changes on: main/trunk/src/graphics/post_processing.hpp ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-08-21 21:57:34
|
Revision: 9599 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=9599&view=rev Author: hikerstk Date: 2011-08-21 21:57:28 +0000 (Sun, 21 Aug 2011) Log Message: ----------- Cleaned up explosion code (only cosmetic changes). Modified Paths: -------------- main/trunk/src/graphics/explosion.cpp main/trunk/src/graphics/explosion.hpp Modified: main/trunk/src/graphics/explosion.cpp =================================================================== --- main/trunk/src/graphics/explosion.cpp 2011-08-21 21:56:49 UTC (rev 9598) +++ main/trunk/src/graphics/explosion.cpp 2011-08-21 21:57:28 UTC (rev 9599) @@ -32,10 +32,13 @@ const float burst_time = 0.1f; -Explosion::Explosion(const Vec3& coord, const char* explosion_sound, bool player_kart_hit) +/** Creates an explosion effect. */ +Explosion::Explosion(const Vec3& coord, const char* explosion_sound, + bool player_kart_hit) { - m_remaining_time = burst_time; // short emision time, explosion, not constant flame - m_node = irr_driver->addParticleNode(); + // short emision time, explosion, not constant flame + m_remaining_time = burst_time; + m_node = irr_driver->addParticleNode(); m_player_kart_hit = player_kart_hit; #ifdef DEBUG @@ -47,40 +50,44 @@ m->setMaterialProperties(&(m_node->getMaterial(0))); m_node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR ); - scene::IParticleEmitter* em = m_node->createSphereEmitter(core::vector3df(0.0f,0.0f,0.0f), 0.5f, - core::vector3df(0.0f,0.005f,0.0f), // velocity in m/ms - 600, 900, // min max particles per sec - video::SColor(0, 0, 0, 0), video::SColor(0, 0, 0, 0), // min max colour - (int)((burst_time + explosion_time)*1000.0f), - (int)((burst_time + explosion_time)*1000.0f), // min max life ms - 90, // max angle - core::dimension2df(0.3f, 0.3f), core::dimension2df(0.75f, 0.75f) // min max start size - ); + scene::IParticleEmitter* em = + m_node->createSphereEmitter(core::vector3df(0.0f,0.0f,0.0f), 0.5f, + /* velocity in m/ms */core::vector3df(0.0f,0.005f,0.0f), + 600, 900, // min max particles per sec + video::SColor(0, 0, 0, 0), // min colour + video::SColor(0, 0, 0, 0), // max colour + (int)((burst_time + explosion_time) + *1000.0f), // min life ms + (int)((burst_time + explosion_time) + *1000.0f), // max max life ms + 90, // max angle + // min and max start size + core::dimension2df(0.3f, 0.3f), + core::dimension2df(0.75f, 0.75f) + ); m_node->setEmitter(em); // this grabs the emitter em->drop(); // so we can drop it here without deleting it - /* - // doesn't work; instead we'll be doing it by hand below - scene::IParticleAffector* fade_out_affector = m_node->createFadeOutParticleAffector(video::SColor(0, 0, 0, 0), 10000); - m_node->addAffector(fade_out_affector); // same goes for the affector - fade_out_affector->drop(); - */ - - scene::IParticleAffector* scale_affector = m_node->createScaleParticleAffector(core::dimension2df(3.0f, 3.0f)); + scene::IParticleAffector* scale_affector = + m_node->createScaleParticleAffector(core::dimension2df(3.0f, 3.0f)); m_node->addAffector(scale_affector); // same goes for the affector scale_affector->drop(); - //scene::IParticleAffector *paf = - // m_node->createGravityAffector(Vec3(0, 0, -5).toIrrVector()); - //m_node->addAffector(paf); - //paf->drop(); - - m_explode_sound = sfx_manager->createSoundSource( explosion_sound ); - init(coord); + m_explode_sound->position(coord); + + // in multiplayer mode, sounds are NOT positional (because we have multiple listeners) + // so the sounds of all AIs are constantly heard. So reduce volume of sounds. + if (race_manager->getNumLocalPlayers() > 1) + m_explode_sound->volume(m_player_kart_hit ? 1.0f : 0.5f); + else + m_explode_sound->volume(1.0f); + m_explode_sound->play(); } // Explosion //----------------------------------------------------------------------------- +/** Destructor stops the explosion sfx from being played and frees its memory. + */ Explosion::~Explosion() { if (m_explode_sound->getStatus() == SFXManager::SFX_PLAYING) @@ -89,26 +96,12 @@ } sfx_manager->deleteSFX(m_explode_sound); -} -//----------------------------------------------------------------------------- -void Explosion::init(const Vec3& coord) -{ - m_explode_sound->position(coord); - - // in multiplayer mode, sounds are NOT positional (because we have multiple listeners) - // so the sounds of all AIs are constantly heard. So reduce volume of sounds. - if (race_manager->getNumLocalPlayers() > 1) - { - m_explode_sound->volume(m_player_kart_hit ? 1.0f : 0.5f); - } - else - { - m_explode_sound->volume(1.0f); - } - m_explode_sound->play(); -} // init +} // ~Explosion //----------------------------------------------------------------------------- +/** Updates the explosion, called one per time step. + * \param dt Time step size. + */ void Explosion::update(float dt) { m_remaining_time -= dt; @@ -157,4 +150,4 @@ projectile_manager->FinishedExplosion(); return; } -} +} // update Modified: main/trunk/src/graphics/explosion.hpp =================================================================== --- main/trunk/src/graphics/explosion.hpp 2011-08-21 21:56:49 UTC (rev 9598) +++ main/trunk/src/graphics/explosion.hpp 2011-08-21 21:57:28 UTC (rev 9599) @@ -47,7 +47,6 @@ public: Explosion(const Vec3& coord, const char* explosion_sound, bool player_hit); ~Explosion(); - void init (const Vec3& coord); void update (float delta_t); int inUse (); bool hasEnded () { return m_remaining_time <= -explosion_time; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-08-29 01:05:08
|
Revision: 9653 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=9653&view=rev Author: auria Date: 2011-08-29 01:05:02 +0000 (Mon, 29 Aug 2011) Log Message: ----------- Improve anti-aliasing : remove my attempts at configuring it and just use the defaults, it's much nicer-looking this way ^^ Modified Paths: -------------- main/trunk/src/graphics/material.cpp main/trunk/src/graphics/material_manager.cpp Modified: main/trunk/src/graphics/material.cpp =================================================================== --- main/trunk/src/graphics/material.cpp 2011-08-29 00:55:47 UTC (rev 9652) +++ main/trunk/src/graphics/material.cpp 2011-08-29 01:05:02 UTC (rev 9653) @@ -613,8 +613,8 @@ } #endif - if (UserConfigParams::m_fullscreen_antialiasing) - m->AntiAliasing = video::EAAM_LINE_SMOOTH; + //if (UserConfigParams::m_fullscreen_antialiasing) + // m->AntiAliasing = video::EAAM_LINE_SMOOTH; } // setMaterialProperties Modified: main/trunk/src/graphics/material_manager.cpp =================================================================== --- main/trunk/src/graphics/material_manager.cpp 2011-08-29 00:55:47 UTC (rev 9652) +++ main/trunk/src/graphics/material_manager.cpp 2011-08-29 01:05:02 UTC (rev 9653) @@ -90,8 +90,8 @@ mb->getMaterial().ColorMaterial = video::ECM_DIFFUSE_AND_AMBIENT; - if (UserConfigParams::m_fullscreen_antialiasing) - mb->getMaterial().AntiAliasing = video::EAAM_LINE_SMOOTH; + //if (UserConfigParams::m_fullscreen_antialiasing) + // mb->getMaterial().AntiAliasing = video::EAAM_LINE_SMOOTH; } // setAllMaterialFlags This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |