+++ /dev/null
-// Copyright (C) 2002-2010 Nikolaus Gebhardt\r
-// This file is part of the "Irrlicht Engine".\r
-// For conditions of distribution and use, see copyright notice in irrlicht.h\r
-\r
-#include "MyBillboardSceneNode.h"\r
-#include "IVideoDriver.h"\r
-#include "ISceneManager.h"\r
-#include "ICameraSceneNode.h"\r
-\r
-namespace irr\r
-{\r
-namespace scene\r
-{\r
-\r
-//! constructor\r
-MyBillboardSceneNode::MyBillboardSceneNode(ISceneNode* parent,\r
- ISceneManager* mgr, s32 id,\r
- const core::vector3df& position, const core::dimension2d<f32>& size)\r
- : IBillboardSceneNode(parent, mgr, id, position)\r
-{\r
- #ifdef _DEBUG\r
- setDebugName("MyBillboardSceneNode");\r
- #endif\r
-\r
- setSize(size);\r
-\r
- indices[0] = 0;\r
- indices[1] = 2;\r
- indices[2] = 1;\r
- indices[3] = 0;\r
- indices[4] = 3;\r
- indices[5] = 2;\r
-\r
- video::SColor colorTop = video::SColor(0xFFFFFFFF);\r
- video::SColor colorBottom = video::SColor(0xFFFFFFFF);\r
-\r
- vertices[0].TCoords.set(1.0f, 1.0f);\r
- vertices[0].Color = colorBottom;\r
-\r
- vertices[1].TCoords.set(1.0f, 0.0f);\r
- vertices[1].Color = colorTop;\r
-\r
- vertices[2].TCoords.set(0.0f, 0.0f);\r
- vertices[2].Color = colorTop;\r
-\r
- vertices[3].TCoords.set(0.0f, 1.0f);\r
- vertices[3].Color = colorBottom;\r
-}\r
-\r
-\r
-//! pre render event\r
-void MyBillboardSceneNode::OnRegisterSceneNode()\r
-{\r
- if (IsVisible)\r
- SceneManager->registerNodeForRendering(this);\r
-\r
- ISceneNode::OnRegisterSceneNode();\r
-}\r
-\r
-\r
-//! render\r
-void MyBillboardSceneNode::render()\r
-{\r
- video::IVideoDriver* driver = SceneManager->getVideoDriver();\r
- ICameraSceneNode* camera = SceneManager->getActiveCamera();\r
-\r
- if (!camera || !driver)\r
- return;\r
-\r
- // make billboard look to camera\r
-\r
- core::vector3df pos = getAbsolutePosition();\r
-\r
- core::vector3df campos = camera->getAbsolutePosition();\r
- core::vector3df target = camera->getTarget();\r
- core::vector3df up = camera->getUpVector();\r
- core::vector3df view = target - campos;\r
- view.normalize();\r
-\r
- core::vector3df horizontal = up.crossProduct(view);\r
- if ( horizontal.getLength() == 0 )\r
- {\r
- horizontal.set(up.Y,up.X,up.Z);\r
- }\r
- horizontal.normalize();\r
- horizontal *= 0.5f * Size.Width;\r
-\r
- core::vector3df vertical = horizontal.crossProduct(view);\r
- vertical.normalize();\r
- vertical *= 0.5f * Size.Height;\r
-\r
- view *= -1.0f;\r
-\r
- for (s32 i=0; i<4; ++i)\r
- vertices[i].Normal = view;\r
-\r
- vertices[0].Pos = pos + horizontal + vertical;\r
- vertices[1].Pos = pos + horizontal - vertical;\r
- vertices[2].Pos = pos - horizontal - vertical;\r
- vertices[3].Pos = pos - horizontal + vertical;\r
-\r
- // draw\r
-\r
- if ( DebugDataVisible & scene::EDS_BBOX )\r
- {\r
- driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);\r
- video::SMaterial m;\r
- m.Lighting = false;\r
- driver->setMaterial(m);\r
- driver->draw3DBox(BBox, video::SColor(0,208,195,152));\r
- }\r
-\r
- driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);\r
-\r
- driver->setMaterial(Material);\r
-\r
- driver->drawIndexedTriangleList(vertices, 4, indices, 2);\r
-}\r
-\r
-\r
-//! returns the axis aligned bounding box of this node\r
-const core::aabbox3d<f32>& MyBillboardSceneNode::getBoundingBox() const\r
-{\r
- return BBox;\r
-}\r
-\r
-\r
-//! sets the size of the billboard\r
-void MyBillboardSceneNode::setSize(const core::dimension2d<f32>& size)\r
-{\r
- Size = size;\r
-\r
- if (Size.Width == 0.0f)\r
- Size.Width = 1.0f;\r
-\r
- if (Size.Height == 0.0f )\r
- Size.Height = 1.0f;\r
-\r
- f32 avg = (size.Width + size.Height)/6;\r
- BBox.MinEdge.set(-avg,-avg,-avg);\r
- BBox.MaxEdge.set(avg,avg,avg);\r
-}\r
-\r
-\r
-video::SMaterial& MyBillboardSceneNode::getMaterial(u32 i)\r
-{\r
- return Material;\r
-}\r
-\r
-\r
-//! returns amount of materials used by this scene node.\r
-u32 MyBillboardSceneNode::getMaterialCount() const\r
-{\r
- return 1;\r
-}\r
-\r
-\r
-//! gets the size of the billboard\r
-const core::dimension2d<f32>& MyBillboardSceneNode::getSize() const\r
-{\r
- return Size;\r
-}\r
-\r
-\r
-//! Set the color of all vertices of the billboard\r
-//! \param overallColor: the color to set\r
-void MyBillboardSceneNode::setColor(const video::SColor & overallColor)\r
-{\r
- for(u32 vertex = 0; vertex < 4; ++vertex)\r
- vertices[vertex].Color = overallColor;\r
-}\r
-\r
-\r
-//! Set the color of the top and bottom vertices of the billboard\r
-//! \param topColor: the color to set the top vertices\r
-//! \param bottomColor: the color to set the bottom vertices\r
-void MyBillboardSceneNode::setColor(const video::SColor & topColor, const video::SColor & bottomColor)\r
-{\r
- vertices[0].Color = bottomColor;\r
- vertices[1].Color = topColor;\r
- vertices[2].Color = topColor;\r
- vertices[3].Color = bottomColor;\r
-}\r
-\r
-\r
-//! Gets the color of the top and bottom vertices of the billboard\r
-//! \param[out] topColor: stores the color of the top vertices\r
-//! \param[out] bottomColor: stores the color of the bottom vertices\r
-void MyBillboardSceneNode::getColor(video::SColor & topColor, video::SColor & bottomColor) const\r
-{\r
- bottomColor = vertices[0].Color;\r
- topColor = vertices[1].Color;\r
-}\r
- \r
-void MyBillboardSceneNode::setTCoords(u32 i, core::vector2d<f32> c)\r
-{\r
- vertices[i].TCoords = c;\r
-}\r
-\r
-} // end namespace scene\r
-} // end namespace irr\r
-\r
#include "settings.h"
#include <ICameraSceneNode.h>
#include <ITextSceneNode.h>
+#include <IBillboardSceneNode.h>
#include "serialization.h" // For decompressZlib
#include "gamedef.h"
#include "clientobject.h"
#include "mesh.h"
#include "utility.h" // For IntervalLimiter
class Settings;
-#include "MyBillboardSceneNode.h"
core::map<u16, ClientActiveObject::Factory> ClientActiveObject::m_types;
SmoothTranslator pos_translator;
};
+static void setBillboardTextureMatrix(scene::IBillboardSceneNode *bill,
+ float txs, float tys, int col, int row)
+{
+ video::SMaterial& material = bill->getMaterial(0);
+ core::matrix4& matrix = material.getTextureMatrix(0);
+ matrix.setTextureTranslate(txs*col, tys*row);
+ matrix.setTextureScale(txs, tys);
+}
+
/*
MobV2CAO
*/
IntervalLimiter m_attack_interval;
core::aabbox3d<f32> m_selection_box;
- scene::MyBillboardSceneNode *m_node;
+ scene::IBillboardSceneNode *m_node;
v3f m_position;
std::string m_texture_name;
float m_yaw;
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));
+ scene::IBillboardSceneNode *bill = smgr->addBillboardSceneNode(
+ NULL, v2f(1, 1), v3f(0,0,0), -1);
bill->setMaterialTexture(0, tsrc->getTextureRaw(texture_string));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
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));
+ setBillboardTextureMatrix(bill, txs, tys, 0, 0);
} 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));
+ setBillboardTextureMatrix(bill, txs, tys, 0, 0);
} else {
infostream<<"MobV2CAO: Unknown sprite type \""<<m_sprite_type<<"\""
<<std::endl;
if(m_node == NULL)
return;
- m_node->drop();
m_node->remove();
m_node = NULL;
}
void MobV2CAO::step(float dtime, ClientEnvironment *env)
{
- scene::MyBillboardSceneNode *bill = m_node;
+ scene::IBillboardSceneNode *bill = m_node;
if(!bill)
return;
const float txs = txp*32;
const float typ = 1./240;
const float tys = typ*48;
- bill->setTCoords(0, v2f(txs*(1+col), tys*(1+row)));
- bill->setTCoords(1, v2f(txs*(1+col), tys*(0+row)));
- bill->setTCoords(2, v2f(txs*(0+col), tys*(0+row)));
- bill->setTCoords(3, v2f(txs*(0+col), tys*(1+row)));
+ setBillboardTextureMatrix(bill, txs, tys, col, row);
} else if(m_sprite_type == "simple"){
m_walk_timer += dtime;
if(m_walk_timer >= m_simple_anim_frametime){
int row = m_walk_frame;
const float txs = 1.0;
const float tys = 1.0 / m_simple_anim_frames;
- bill->setTCoords(0, v2f(txs*(1+col), tys*(1+row)));
- bill->setTCoords(1, v2f(txs*(1+col), tys*(0+row)));
- bill->setTCoords(2, v2f(txs*(0+col), tys*(0+row)));
- bill->setTCoords(3, v2f(txs*(0+col), tys*(1+row)));
+ setBillboardTextureMatrix(bill, txs, tys, col, row);
} else {
infostream<<"MobV2CAO::step(): Unknown sprite type \""
<<m_sprite_type<<"\""<<std::endl;
private:
core::aabbox3d<f32> m_selection_box;
scene::IMeshSceneNode *m_meshnode;
- scene::MyBillboardSceneNode *m_spritenode;
+ scene::IBillboardSceneNode *m_spritenode;
v3f m_position;
v3f m_velocity;
v3f m_acceleration;
if(m_prop->visual == "sprite"){
infostream<<"LuaEntityCAO::addToScene(): single_sprite"<<std::endl;
- m_spritenode = new scene::MyBillboardSceneNode(
- smgr->getRootSceneNode(), smgr, -1, v3f(0,0,0), v2f(1,1));
+ m_spritenode = smgr->addBillboardSceneNode(
+ NULL, v2f(1, 1), v3f(0,0,0), -1);
m_spritenode->setMaterialTexture(0,
tsrc->getTextureRaw("unknown_block.png"));
m_spritenode->setMaterialFlag(video::EMF_LIGHTING, false);
{
const float txs = 1.0 / 1;
const float tys = 1.0 / 1;
- m_spritenode->setTCoords(0, v2f(txs*1, tys*1));
- m_spritenode->setTCoords(1, v2f(txs*1, tys*0));
- m_spritenode->setTCoords(2, v2f(txs*0, tys*0));
- m_spritenode->setTCoords(3, v2f(txs*0, tys*1));
+ setBillboardTextureMatrix(m_spritenode,
+ txs, tys, 0, 0);
}
} else if(m_prop->visual == "cube"){
infostream<<"LuaEntityCAO::addToScene(): cube"<<std::endl;
- video::SColor c(255,255,255,255);
- video::S3DVertex vertices[24] =
- {
- // Up
- video::S3DVertex(-0.5,+0.5,-0.5, 0,1,0, c, 0,1),
- video::S3DVertex(-0.5,+0.5,+0.5, 0,1,0, c, 0,0),
- video::S3DVertex(+0.5,+0.5,+0.5, 0,1,0, c, 1,0),
- video::S3DVertex(+0.5,+0.5,-0.5, 0,1,0, c, 1,1),
- // Down
- video::S3DVertex(-0.5,-0.5,-0.5, 0,-1,0, c, 0,0),
- video::S3DVertex(+0.5,-0.5,-0.5, 0,-1,0, c, 1,0),
- video::S3DVertex(+0.5,-0.5,+0.5, 0,-1,0, c, 1,1),
- video::S3DVertex(-0.5,-0.5,+0.5, 0,-1,0, c, 0,1),
- // Right
- video::S3DVertex(+0.5,-0.5,-0.5, 1,0,0, c, 0,1),
- video::S3DVertex(+0.5,+0.5,-0.5, 1,0,0, c, 0,0),
- video::S3DVertex(+0.5,+0.5,+0.5, 1,0,0, c, 1,0),
- video::S3DVertex(+0.5,-0.5,+0.5, 1,0,0, c, 1,1),
- // Left
- video::S3DVertex(-0.5,-0.5,-0.5, -1,0,0, c, 1,1),
- video::S3DVertex(-0.5,-0.5,+0.5, -1,0,0, c, 0,1),
- video::S3DVertex(-0.5,+0.5,+0.5, -1,0,0, c, 0,0),
- video::S3DVertex(-0.5,+0.5,-0.5, -1,0,0, c, 1,0),
- // Back
- video::S3DVertex(-0.5,-0.5,+0.5, 0,0,1, c, 1,1),
- video::S3DVertex(+0.5,-0.5,+0.5, 0,0,1, c, 0,1),
- video::S3DVertex(+0.5,+0.5,+0.5, 0,0,1, c, 0,0),
- video::S3DVertex(-0.5,+0.5,+0.5, 0,0,1, c, 1,0),
- // Front
- video::S3DVertex(-0.5,-0.5,-0.5, 0,0,-1, c, 0,1),
- video::S3DVertex(-0.5,+0.5,-0.5, 0,0,-1, c, 0,0),
- video::S3DVertex(+0.5,+0.5,-0.5, 0,0,-1, c, 1,0),
- video::S3DVertex(+0.5,-0.5,-0.5, 0,0,-1, c, 1,1),
- };
-
- for(u32 i=0; i<24; ++i){
- vertices[i].Pos *= BS;
- vertices[i].Pos.Y *= m_prop->visual_size.Y;
- vertices[i].Pos.X *= m_prop->visual_size.X;
- vertices[i].Pos.Z *= m_prop->visual_size.X;
- }
-
- u16 indices[6] = {0,1,2,2,3,0};
-
- scene::SMesh* mesh = new scene::SMesh();
- for (u32 i=0; i<6; ++i)
- {
- scene::IMeshBuffer* buf = new scene::SMeshBuffer();
- buf->append(vertices + 4 * i, 4, indices, 6);
- buf->recalculateBoundingBox();
- mesh->addMeshBuffer(buf);
- buf->drop();
- }
- mesh->recalculateBoundingBox();
-
+ scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS));
m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
+ mesh->drop();
- m_meshnode->setMesh(mesh);
m_meshnode->setScale(v3f(1));
// Will be shown when we know the brightness
m_meshnode->setVisible(false);
float txs = m_tx_size.X;
float tys = m_tx_size.Y;
- m_spritenode->setTCoords(0, v2f(txs*(1+col), tys*(1+row)));
- m_spritenode->setTCoords(1, v2f(txs*(1+col), tys*(0+row)));
- m_spritenode->setTCoords(2, v2f(txs*(0+col), tys*(0+row)));
- m_spritenode->setTCoords(3, v2f(txs*(0+col), tys*(1+row)));
+ setBillboardTextureMatrix(m_spritenode,
+ txs, tys, col, row);
}
}