Line data Source code
1 : /*
2 : Minetest
3 : Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 :
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.
9 :
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.
14 :
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.
18 : */
19 :
20 : #include "content_cso.h"
21 : #include <IBillboardSceneNode.h>
22 : #include "client/tile.h"
23 : #include "environment.h"
24 : #include "gamedef.h"
25 : #include "log.h"
26 : #include "map.h"
27 :
28 : /*
29 : static void setBillboardTextureMatrix(scene::IBillboardSceneNode *bill,
30 : float txs, float tys, int col, int row)
31 : {
32 : video::SMaterial& material = bill->getMaterial(0);
33 : core::matrix4& matrix = material.getTextureMatrix(0);
34 : matrix.setTextureTranslate(txs*col, tys*row);
35 : matrix.setTextureScale(txs, tys);
36 : }
37 : */
38 :
39 : class SmokePuffCSO: public ClientSimpleObject
40 : {
41 : float m_age;
42 : scene::IBillboardSceneNode *m_spritenode;
43 : public:
44 0 : SmokePuffCSO(scene::ISceneManager *smgr,
45 : ClientEnvironment *env, v3f pos, v2f size):
46 : m_age(0),
47 0 : m_spritenode(NULL)
48 : {
49 0 : infostream<<"SmokePuffCSO: constructing"<<std::endl;
50 0 : m_spritenode = smgr->addBillboardSceneNode(
51 0 : NULL, v2f(1,1), pos, -1);
52 0 : m_spritenode->setMaterialTexture(0,
53 0 : env->getGameDef()->tsrc()->getTextureForMesh("smoke_puff.png"));
54 0 : m_spritenode->setMaterialFlag(video::EMF_LIGHTING, false);
55 0 : m_spritenode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
56 : //m_spritenode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
57 0 : m_spritenode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
58 0 : m_spritenode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
59 0 : m_spritenode->setColor(video::SColor(255,0,0,0));
60 0 : m_spritenode->setVisible(true);
61 0 : m_spritenode->setSize(size);
62 : /* Update brightness */
63 : u8 light;
64 : bool pos_ok;
65 0 : MapNode n = env->getMap().getNodeNoEx(floatToInt(pos, BS), &pos_ok);
66 0 : light = pos_ok ? decode_light(n.getLightBlend(env->getDayNightRatio(),
67 : env->getGameDef()->ndef()))
68 0 : : 64;
69 0 : video::SColor color(255,light,light,light);
70 0 : m_spritenode->setColor(color);
71 0 : }
72 0 : virtual ~SmokePuffCSO()
73 0 : {
74 0 : infostream<<"SmokePuffCSO: destructing"<<std::endl;
75 0 : m_spritenode->remove();
76 0 : }
77 0 : void step(float dtime)
78 : {
79 0 : m_age += dtime;
80 0 : if(m_age > 1.0){
81 0 : m_to_be_removed = true;
82 : }
83 0 : }
84 : };
85 :
86 0 : ClientSimpleObject* createSmokePuff(scene::ISceneManager *smgr,
87 : ClientEnvironment *env, v3f pos, v2f size)
88 : {
89 0 : return new SmokePuffCSO(smgr, env, pos, size);
90 3 : }
91 :
|