diff options
Diffstat (limited to 'src/content_cao.cpp')
-rw-r--r-- | src/content_cao.cpp | 116 |
1 files changed, 27 insertions, 89 deletions
diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 7563cfcc6..d581b35dc 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "settings.h" #include <ICameraSceneNode.h> #include <ITextSceneNode.h> +#include <IBillboardSceneNode.h> #include "serialization.h" // For decompressZlib #include "gamedef.h" #include "clientobject.h" @@ -30,7 +31,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mesh.h" #include "utility.h" // For IntervalLimiter class Settings; -#include "MyBillboardSceneNode.h" core::map<u16, ClientActiveObject::Factory> ClientActiveObject::m_types; @@ -332,6 +332,15 @@ private: SmoothTranslator pos_translator; }; +static void setBillboardTextureMatrix(scene::IBillboardSceneNode *bill, + float txs, float tys, int col, int row) +{ + video::SMaterial& material = bill->getMaterial(0); + core::matrix4& matrix = material.getTextureMatrix(0); + matrix.setTextureTranslate(txs*col, tys*row); + matrix.setTextureScale(txs, tys); +} + /* MobV2CAO */ @@ -377,7 +386,7 @@ private: IntervalLimiter m_attack_interval; core::aabbox3d<f32> m_selection_box; - scene::MyBillboardSceneNode *m_node; + scene::IBillboardSceneNode *m_node; v3f m_position; std::string m_texture_name; float m_yaw; @@ -1305,8 +1314,8 @@ void MobV2CAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc, std::string texture_string = m_texture_name + "^[makealpha:128,0,0^[makealpha:128,128,0"; - scene::MyBillboardSceneNode *bill = new scene::MyBillboardSceneNode( - smgr->getRootSceneNode(), smgr, -1, v3f(0,0,0), v2f(1,1)); + scene::IBillboardSceneNode *bill = smgr->addBillboardSceneNode( + NULL, v2f(1, 1), v3f(0,0,0), -1); bill->setMaterialTexture(0, tsrc->getTextureRaw(texture_string)); bill->setMaterialFlag(video::EMF_LIGHTING, false); bill->setMaterialFlag(video::EMF_BILINEAR_FILTER, false); @@ -1320,17 +1329,11 @@ void MobV2CAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc, const float txs = txp*32; const float typ = 1./240; const float tys = typ*48; - bill->setTCoords(0, v2f(txs*1, tys*1)); - bill->setTCoords(1, v2f(txs*1, tys*0)); - bill->setTCoords(2, v2f(txs*0, tys*0)); - bill->setTCoords(3, v2f(txs*0, tys*1)); + setBillboardTextureMatrix(bill, txs, tys, 0, 0); } else if(m_sprite_type == "simple"){ const float txs = 1.0; const float tys = 1.0 / m_simple_anim_frames; - bill->setTCoords(0, v2f(txs*1, tys*1)); - bill->setTCoords(1, v2f(txs*1, tys*0)); - bill->setTCoords(2, v2f(txs*0, tys*0)); - bill->setTCoords(3, v2f(txs*0, tys*1)); + setBillboardTextureMatrix(bill, txs, tys, 0, 0); } else { infostream<<"MobV2CAO: Unknown sprite type \""<<m_sprite_type<<"\"" <<std::endl; @@ -1346,7 +1349,6 @@ void MobV2CAO::removeFromScene() if(m_node == NULL) return; - m_node->drop(); m_node->remove(); m_node = NULL; } @@ -1394,7 +1396,7 @@ void MobV2CAO::updateNodePos() void MobV2CAO::step(float dtime, ClientEnvironment *env) { - scene::MyBillboardSceneNode *bill = m_node; + scene::IBillboardSceneNode *bill = m_node; if(!bill) return; @@ -1447,10 +1449,7 @@ void MobV2CAO::step(float dtime, ClientEnvironment *env) const float txs = txp*32; const float typ = 1./240; const float tys = typ*48; - bill->setTCoords(0, v2f(txs*(1+col), tys*(1+row))); - bill->setTCoords(1, v2f(txs*(1+col), tys*(0+row))); - bill->setTCoords(2, v2f(txs*(0+col), tys*(0+row))); - bill->setTCoords(3, v2f(txs*(0+col), tys*(1+row))); + setBillboardTextureMatrix(bill, txs, tys, col, row); } else if(m_sprite_type == "simple"){ m_walk_timer += dtime; if(m_walk_timer >= m_simple_anim_frametime){ @@ -1461,10 +1460,7 @@ void MobV2CAO::step(float dtime, ClientEnvironment *env) int row = m_walk_frame; const float txs = 1.0; const float tys = 1.0 / m_simple_anim_frames; - bill->setTCoords(0, v2f(txs*(1+col), tys*(1+row))); - bill->setTCoords(1, v2f(txs*(1+col), tys*(0+row))); - bill->setTCoords(2, v2f(txs*(0+col), tys*(0+row))); - bill->setTCoords(3, v2f(txs*(0+col), tys*(1+row))); + setBillboardTextureMatrix(bill, txs, tys, col, row); } else { infostream<<"MobV2CAO::step(): Unknown sprite type \"" <<m_sprite_type<<"\""<<std::endl; @@ -1677,7 +1673,7 @@ class LuaEntityCAO : public ClientActiveObject private: core::aabbox3d<f32> m_selection_box; scene::IMeshSceneNode *m_meshnode; - scene::MyBillboardSceneNode *m_spritenode; + scene::IBillboardSceneNode *m_spritenode; v3f m_position; v3f m_velocity; v3f m_acceleration; @@ -1783,8 +1779,8 @@ public: if(m_prop->visual == "sprite"){ infostream<<"LuaEntityCAO::addToScene(): single_sprite"<<std::endl; - m_spritenode = new scene::MyBillboardSceneNode( - smgr->getRootSceneNode(), smgr, -1, v3f(0,0,0), v2f(1,1)); + m_spritenode = smgr->addBillboardSceneNode( + NULL, v2f(1, 1), v3f(0,0,0), -1); m_spritenode->setMaterialTexture(0, tsrc->getTextureRaw("unknown_block.png")); m_spritenode->setMaterialFlag(video::EMF_LIGHTING, false); @@ -1797,71 +1793,15 @@ public: { const float txs = 1.0 / 1; const float tys = 1.0 / 1; - m_spritenode->setTCoords(0, v2f(txs*1, tys*1)); - m_spritenode->setTCoords(1, v2f(txs*1, tys*0)); - m_spritenode->setTCoords(2, v2f(txs*0, tys*0)); - m_spritenode->setTCoords(3, v2f(txs*0, tys*1)); + setBillboardTextureMatrix(m_spritenode, + txs, tys, 0, 0); } } else if(m_prop->visual == "cube"){ infostream<<"LuaEntityCAO::addToScene(): cube"<<std::endl; - video::SColor c(255,255,255,255); - video::S3DVertex vertices[24] = - { - // Up - video::S3DVertex(-0.5,+0.5,-0.5, 0,1,0, c, 0,1), - video::S3DVertex(-0.5,+0.5,+0.5, 0,1,0, c, 0,0), - video::S3DVertex(+0.5,+0.5,+0.5, 0,1,0, c, 1,0), - video::S3DVertex(+0.5,+0.5,-0.5, 0,1,0, c, 1,1), - // Down - video::S3DVertex(-0.5,-0.5,-0.5, 0,-1,0, c, 0,0), - video::S3DVertex(+0.5,-0.5,-0.5, 0,-1,0, c, 1,0), - video::S3DVertex(+0.5,-0.5,+0.5, 0,-1,0, c, 1,1), - video::S3DVertex(-0.5,-0.5,+0.5, 0,-1,0, c, 0,1), - // Right - video::S3DVertex(+0.5,-0.5,-0.5, 1,0,0, c, 0,1), - video::S3DVertex(+0.5,+0.5,-0.5, 1,0,0, c, 0,0), - video::S3DVertex(+0.5,+0.5,+0.5, 1,0,0, c, 1,0), - video::S3DVertex(+0.5,-0.5,+0.5, 1,0,0, c, 1,1), - // Left - video::S3DVertex(-0.5,-0.5,-0.5, -1,0,0, c, 1,1), - video::S3DVertex(-0.5,-0.5,+0.5, -1,0,0, c, 0,1), - video::S3DVertex(-0.5,+0.5,+0.5, -1,0,0, c, 0,0), - video::S3DVertex(-0.5,+0.5,-0.5, -1,0,0, c, 1,0), - // Back - video::S3DVertex(-0.5,-0.5,+0.5, 0,0,1, c, 1,1), - video::S3DVertex(+0.5,-0.5,+0.5, 0,0,1, c, 0,1), - video::S3DVertex(+0.5,+0.5,+0.5, 0,0,1, c, 0,0), - video::S3DVertex(-0.5,+0.5,+0.5, 0,0,1, c, 1,0), - // Front - video::S3DVertex(-0.5,-0.5,-0.5, 0,0,-1, c, 0,1), - video::S3DVertex(-0.5,+0.5,-0.5, 0,0,-1, c, 0,0), - video::S3DVertex(+0.5,+0.5,-0.5, 0,0,-1, c, 1,0), - video::S3DVertex(+0.5,-0.5,-0.5, 0,0,-1, c, 1,1), - }; - - for(u32 i=0; i<24; ++i){ - vertices[i].Pos *= BS; - vertices[i].Pos.Y *= m_prop->visual_size.Y; - vertices[i].Pos.X *= m_prop->visual_size.X; - vertices[i].Pos.Z *= m_prop->visual_size.X; - } - - u16 indices[6] = {0,1,2,2,3,0}; - - scene::SMesh* mesh = new scene::SMesh(); - for (u32 i=0; i<6; ++i) - { - scene::IMeshBuffer* buf = new scene::SMeshBuffer(); - buf->append(vertices + 4 * i, 4, indices, 6); - buf->recalculateBoundingBox(); - mesh->addMeshBuffer(buf); - buf->drop(); - } - mesh->recalculateBoundingBox(); - + scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS)); m_meshnode = smgr->addMeshSceneNode(mesh, NULL); + mesh->drop(); - m_meshnode->setMesh(mesh); m_meshnode->setScale(v3f(1)); // Will be shown when we know the brightness m_meshnode->setVisible(false); @@ -1999,10 +1939,8 @@ public: float txs = m_tx_size.X; float tys = m_tx_size.Y; - m_spritenode->setTCoords(0, v2f(txs*(1+col), tys*(1+row))); - m_spritenode->setTCoords(1, v2f(txs*(1+col), tys*(0+row))); - m_spritenode->setTCoords(2, v2f(txs*(0+col), tys*(0+row))); - m_spritenode->setTCoords(3, v2f(txs*(0+col), tys*(1+row))); + setBillboardTextureMatrix(m_spritenode, + txs, tys, col, row); } } |