From 75a0ca6bd67aa9ca87668bc27d36399b5028c2b1 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 12 Nov 2011 15:14:24 +0200 Subject: Scripting WIP --- src/content_cao.cpp | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) (limited to 'src/content_cao.cpp') diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 1f4f6fbe8..e007c5f37 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -1275,7 +1275,7 @@ LuaEntityCAO proto_LuaEntityCAO; LuaEntityCAO::LuaEntityCAO(): ClientActiveObject(0), - m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.), + m_selection_box(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.), m_meshnode(NULL), m_spritenode(NULL), m_position(v3f(0,10*BS,0)), @@ -1303,9 +1303,114 @@ void LuaEntityCAO::addToScene(scene::ISceneManager *smgr) //video::IVideoDriver* driver = smgr->getVideoDriver(); if(m_prop->visual == "single_sprite"){ + infostream<<"LuaEntityCAO::addToScene(): single_sprite"<getRootSceneNode(), smgr, -1, v3f(0,0,0), v2f(1,1)); + std::string texturestring = "unknown_block.png"; + if(m_prop->textures.size() >= 1) + texturestring = m_prop->textures[0]; + m_spritenode->setMaterialTexture(0, + g_texturesource->getTextureRaw(texturestring)); + m_spritenode->setMaterialFlag(video::EMF_LIGHTING, false); + m_spritenode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false); + m_spritenode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF); + m_spritenode->setMaterialFlag(video::EMF_FOG_ENABLE, true); + m_spritenode->setColor(video::SColor(255,0,0,0)); + m_spritenode->setVisible(false); /* Set visible when brightness is known */ + m_spritenode->setSize(v2f(1,1)*1.0*BS); + { + 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)); + } } else if(m_prop->visual == "cube"){ + infostream<<"LuaEntityCAO::addToScene(): cube"<append(vertices + 4 * i, 4, indices, 6); + buf->recalculateBoundingBox(); + mesh->addMeshBuffer(buf); + buf->drop(); + } + mesh->recalculateBoundingBox(); + + m_meshnode = smgr->addMeshSceneNode(mesh, NULL); + + m_meshnode->setMesh(mesh); + m_meshnode->setScale(v3f(1)); + for (u32 i = 0; i < 6; ++i) + { + std::string texturestring = "unknown_block.png"; + if(m_prop->textures.size() > i) + texturestring = m_prop->textures[i]; + AtlasPointer ap = g_texturesource->getTexture(texturestring); + + // Get the tile texture and atlas transformation + video::ITexture* atlas = ap.atlas; + v2f pos = ap.pos; + v2f size = ap.size; + + // Set material flags and texture + video::SMaterial& material = m_meshnode->getMaterial(i); + material.setFlag(video::EMF_LIGHTING, false); + material.setFlag(video::EMF_BILINEAR_FILTER, false); + material.setTexture(0, atlas); + material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y); + material.getTextureMatrix(0).setTextureScale(size.X, size.Y); + } + // Will be shown when we know the brightness + m_meshnode->setVisible(false); } else { + infostream<<"LuaEntityCAO::addToScene(): \""<visual + <<"\" not supported"<getMesh(), color); + m_meshnode->setVisible(true); } if(m_spritenode){ m_spritenode->setColor(color); + m_spritenode->setVisible(true); } } @@ -1350,6 +1457,7 @@ void LuaEntityCAO::updateNodePos() void LuaEntityCAO::step(float dtime, ClientEnvironment *env) { pos_translator.translate(dtime); + updateNodePos(); } void LuaEntityCAO::processMessage(const std::string &data) @@ -1398,6 +1506,10 @@ void LuaEntityCAO::initialize(const std::string &data) m_prop->deSerialize(prop_is); infostream<<"m_prop: "<dump()<collisionbox; + m_selection_box.MinEdge *= BS; + m_selection_box.MaxEdge *= BS; pos_translator.init(m_position); -- cgit v1.2.3