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);
50 else if(type == ACTIVEOBJECT_TYPE_LUA)
52 dstream<<"ClientActiveObject::create(): passed "
53 <<"ACTIVEOBJECT_TYPE_LUA"<<std::endl;
58 dstream<<"ClientActiveObject::create(): passed "
59 <<"unknown type="<<type<<std::endl;
68 TestCAO::TestCAO(u16 id):
69 ClientActiveObject(id),
71 m_position(v3f(0,10*BS,0))
79 void TestCAO::addToScene(scene::ISceneManager *smgr)
84 video::IVideoDriver* driver = smgr->getVideoDriver();
86 scene::SMesh *mesh = new scene::SMesh();
87 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
88 video::SColor c(255,255,255,255);
89 video::S3DVertex vertices[4] =
91 video::S3DVertex(-BS/2,-BS/4,0, 0,0,0, c, 0,1),
92 video::S3DVertex(BS/2,-BS/4,0, 0,0,0, c, 1,1),
93 video::S3DVertex(BS/2,BS/4,0, 0,0,0, c, 1,0),
94 video::S3DVertex(-BS/2,BS/4,0, 0,0,0, c, 0,0),
96 u16 indices[] = {0,1,2,2,3,0};
97 buf->append(vertices, 4, indices, 6);
99 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
100 buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
101 buf->getMaterial().setTexture
102 (0, driver->getTexture(porting::getDataPath("rat.png").c_str()));
103 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
104 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
105 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
107 mesh->addMeshBuffer(buf);
109 m_node = smgr->addMeshSceneNode(mesh, NULL);
114 void TestCAO::removeFromScene()
123 void TestCAO::updateLight(u8 light_at_pos)
127 v3s16 TestCAO::getLightPosition()
129 return floatToInt(m_position, BS);
132 void TestCAO::updateNodePos()
137 m_node->setPosition(m_position);
138 //m_node->setRotation(v3f(0, 45, 0));
141 void TestCAO::step(float dtime)
145 v3f rot = m_node->getRotation();
146 //dstream<<"dtime="<<dtime<<", rot.Y="<<rot.Y<<std::endl;
147 rot.Y += dtime * 180;
148 m_node->setRotation(rot);
152 void TestCAO::processMessage(const std::string &data)
154 //dstream<<"TestCAO: Got data: "<<data<<std::endl;
155 std::istringstream is(data, std::ios::binary);