3 Copyright (C) 2012 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "content_cso.h"
21 #include <IBillboardSceneNode.h>
23 #include "environment.h"
28 static void setBillboardTextureMatrix(scene::IBillboardSceneNode *bill,
29 float txs, float tys, int col, int row)
31 video::SMaterial& material = bill->getMaterial(0);
32 core::matrix4& matrix = material.getTextureMatrix(0);
33 matrix.setTextureTranslate(txs*col, tys*row);
34 matrix.setTextureScale(txs, tys);
37 class SmokePuffCSO: public ClientSimpleObject
40 scene::IBillboardSceneNode *m_spritenode;
42 SmokePuffCSO(scene::ISceneManager *smgr,
43 ClientEnvironment *env, v3f pos, v2f size):
47 infostream<<"SmokePuffCSO: constructing"<<std::endl;
48 m_spritenode = smgr->addBillboardSceneNode(
49 NULL, v2f(1,1), pos, -1);
50 m_spritenode->setMaterialTexture(0,
51 env->getGameDef()->tsrc()->getTextureRaw("smoke_puff.png"));
52 m_spritenode->setMaterialFlag(video::EMF_LIGHTING, false);
53 m_spritenode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
54 //m_spritenode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
55 m_spritenode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
56 m_spritenode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
57 m_spritenode->setColor(video::SColor(255,0,0,0));
58 m_spritenode->setVisible(true);
59 m_spritenode->setSize(size);
60 /* Update brightness */
63 MapNode n = env->getMap().getNode(floatToInt(pos, BS));
64 light = decode_light(n.getLightBlend(env->getDayNightRatio(),
65 env->getGameDef()->ndef()));
67 catch(InvalidPositionException &e){}
68 video::SColor color(255,light,light,light);
69 m_spritenode->setColor(color);
71 virtual ~SmokePuffCSO()
73 infostream<<"SmokePuffCSO: destructing"<<std::endl;
74 m_spritenode->remove();
76 void step(float dtime)
80 m_to_be_removed = true;
85 ClientSimpleObject* createSmokePuff(scene::ISceneManager *smgr,
86 ClientEnvironment *env, v3f pos, v2f size)
88 return new SmokePuffCSO(smgr, env, pos, size);