3 Copyright (C) 2010-2011 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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
15 You should have received a copy of the GNU 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 "clientobject.h"
23 #include "constants.h"
26 ClientActiveObject::ClientActiveObject(u16 id):
31 ClientActiveObject::~ClientActiveObject()
36 ClientActiveObject* ClientActiveObject::create(u8 type)
38 if(type == ACTIVEOBJECT_TYPE_INVALID)
40 dstream<<"ClientActiveObject::create(): passed "
41 <<"ACTIVEOBJECT_TYPE_INVALID"<<std::endl;
44 else if(type == ACTIVEOBJECT_TYPE_TEST)
46 dstream<<"ClientActiveObject::create(): passed "
47 <<"ACTIVEOBJECT_TYPE_TEST"<<std::endl;
48 return new TestCAO(0);
52 dstream<<"ClientActiveObject::create(): passed "
53 <<"unknown type="<<type<<std::endl;
62 TestCAO::TestCAO(u16 id):
63 ClientActiveObject(id),
65 m_position(v3f(0,10*BS,0))
73 void TestCAO::addToScene(scene::ISceneManager *smgr)
78 video::IVideoDriver* driver = smgr->getVideoDriver();
80 scene::SMesh *mesh = new scene::SMesh();
81 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
82 video::SColor c(255,255,255,255);
83 video::S3DVertex vertices[4] =
85 video::S3DVertex(-BS/2,-BS/4,0, 0,0,0, c, 0,1),
86 video::S3DVertex(BS/2,-BS/4,0, 0,0,0, c, 1,1),
87 video::S3DVertex(BS/2,BS/4,0, 0,0,0, c, 1,0),
88 video::S3DVertex(-BS/2,BS/4,0, 0,0,0, c, 0,0),
90 u16 indices[] = {0,1,2,2,3,0};
91 buf->append(vertices, 4, indices, 6);
93 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
94 buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
95 buf->getMaterial().setTexture
96 (0, driver->getTexture(porting::getDataPath("rat.png").c_str()));
97 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
98 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
99 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
101 mesh->addMeshBuffer(buf);
103 m_node = smgr->addMeshSceneNode(mesh, NULL);
108 void TestCAO::removeFromScene()
117 void TestCAO::updateLight(u8 light_at_pos)
121 v3s16 TestCAO::getLightPosition()
123 return floatToInt(m_position, BS);
126 void TestCAO::updateNodePos()
131 m_node->setPosition(m_position);
132 //m_node->setRotation(v3f(0, 45, 0));
135 void TestCAO::step(float dtime)
139 v3f rot = m_node->getRotation();
140 //dstream<<"dtime="<<dtime<<", rot.Y="<<rot.Y<<std::endl;
141 rot.Y += dtime * 180;
142 m_node->setRotation(rot);
146 void TestCAO::processMessage(const std::string &data)
148 dstream<<"TestCAO: Got data: "<<data<<std::endl;
149 std::istringstream is(data, std::ios::binary);