- video::S3DVertex(0,0,0, 0,0,0, c, 0,1),
- video::S3DVertex(BS/2,0,0, 0,0,0, c, 1,1),
- video::S3DVertex(BS/2,BS/2,0, 0,0,0, c, 1,0),
- video::S3DVertex(0,BS/2,0, 0,0,0, c, 0,0),
- };
- u16 indices[] = {0,1,2,2,3,0};
- buf->append(vertices, 4, indices, 6);
- // Set material
- buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
- buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
- //buf->getMaterial().setTexture(0, NULL);
- buf->getMaterial().setTexture(0, tsrc->getTextureRaw("firefly.png"));
- buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
- buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
- buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
- // Add to mesh
- mesh->addMeshBuffer(buf);
- buf->drop();
- m_node = smgr->addMeshSceneNode(mesh, NULL);
- mesh->drop();
- // Set it to use the materials of the meshbuffers directly.
- // This is needed for changing the texture in the future
- m_node->setReadOnlyMaterials(true);
- updateNodePos();
-}
-
-void FireflyCAO::removeFromScene()
-{
- if(m_node == NULL)
- return;
-
- m_node->remove();
- m_node = NULL;
-}
-
-void FireflyCAO::updateLight(u8 light_at_pos)
-{
- if(m_node == NULL)
- return;
-
- u8 li = 255;
- video::SColor color(255,li,li,li);
- setMeshVerticesColor(m_node->getMesh(), color);
-}
-
-v3s16 FireflyCAO::getLightPosition()
-{
- return floatToInt(m_position+v3f(0,BS*0.5,0), BS);
-}
-
-void FireflyCAO::updateNodePos()
-{
- if(m_node == NULL)
- return;
-
- //m_node->setPosition(m_position);
- m_node->setPosition(pos_translator.vect_show);
-
- v3f rot = m_node->getRotation();
- rot.Y = 180.0 - m_yaw;
- m_node->setRotation(rot);
-}
-
-void FireflyCAO::step(float dtime, ClientEnvironment *env)
-{
- pos_translator.translate(dtime);
- updateNodePos();
-}
-
-void FireflyCAO::processMessage(const std::string &data)
-{
- //infostream<<"FireflyCAO: Got message"<<std::endl;
- std::istringstream is(data, std::ios::binary);
- // command
- u8 cmd = readU8(is);
- if(cmd == 0)
- {
- // pos
- m_position = readV3F1000(is);
- pos_translator.update(m_position);
- // yaw
- m_yaw = readF1000(is);
- updateNodePos();
- }
-}
-
-void FireflyCAO::initialize(const std::string &data)
-{
- //infostream<<"FireflyCAO: Got init data"<<std::endl;
-
- {
- std::istringstream is(data, std::ios::binary);
- // version
- u8 version = readU8(is);
- // check version
- if(version != 0)
- return;
- // pos
- m_position = readV3F1000(is);
- pos_translator.init(m_position);
- }
-
- updateNodePos();
-}
-
-/*
- MobV2CAO
-*/
-
-// Prototype
-MobV2CAO proto_MobV2CAO(NULL);
-
-MobV2CAO::MobV2CAO(IGameDef *gamedef):
- ClientActiveObject(0, gamedef),
- m_selection_box(-0.4*BS,-0.4*BS,-0.4*BS, 0.4*BS,0.8*BS,0.4*BS),
- m_node(NULL),
- m_position(v3f(0,10*BS,0)),
- m_yaw(0),
- m_walking(false),
- m_walking_unset_timer(0),
- m_walk_timer(0),
- m_walk_frame(0),
- m_damage_visual_timer(0),
- m_last_light(0),
- m_shooting(0),
- m_shooting_unset_timer(0),
- m_sprite_size(BS,BS),
- m_sprite_y(0),
- m_bright_shooting(false),
- m_lock_full_brightness(false),
- m_player_hit_timer(0)
-{
- ClientActiveObject::registerType(getType(), create);
-
- m_properties = new Settings;
-}
-
-MobV2CAO::~MobV2CAO()
-{
- delete m_properties;
-}
-
-ClientActiveObject* MobV2CAO::create(IGameDef *gamedef)
-{
- return new MobV2CAO(gamedef);
-}
-
-void MobV2CAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
-{
- if(m_node != NULL)
- return;
-
- /*infostream<<"MobV2CAO::addToScene using texture_name="<<
- m_texture_name<<std::endl;*/
- std::string texture_string = m_texture_name +
- "^[makealpha:128,0,0^[makealpha:128,128,0";
-
- scene::MyBillboardSceneNode *bill = new scene::MyBillboardSceneNode(
- smgr->getRootSceneNode(), smgr, -1, v3f(0,0,0), v2f(1,1));
- bill->setMaterialTexture(0, tsrc->getTextureRaw(texture_string));
- bill->setMaterialFlag(video::EMF_LIGHTING, false);
- bill->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
- bill->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
- bill->setMaterialFlag(video::EMF_FOG_ENABLE, true);
- bill->setColor(video::SColor(255,0,0,0));
- bill->setVisible(false); /* Set visible when brightness is known */
- bill->setSize(m_sprite_size);
- if(m_sprite_type == "humanoid_1"){
- const float txp = 1./192;
- const float txs = txp*32;
- const float typ = 1./240;
- const float tys = typ*48;
- bill->setTCoords(0, v2f(txs*1, tys*1));
- bill->setTCoords(1, v2f(txs*1, tys*0));
- bill->setTCoords(2, v2f(txs*0, tys*0));
- bill->setTCoords(3, v2f(txs*0, tys*1));
- } else if(m_sprite_type == "simple"){
- const float txs = 1.0;
- const float tys = 1.0 / m_simple_anim_frames;
- bill->setTCoords(0, v2f(txs*1, tys*1));
- bill->setTCoords(1, v2f(txs*1, tys*0));
- bill->setTCoords(2, v2f(txs*0, tys*0));
- bill->setTCoords(3, v2f(txs*0, tys*1));
- } else {
- infostream<<"MobV2CAO: Unknown sprite type \""<<m_sprite_type<<"\""
- <<std::endl;