Simplistic wielded tool lighting, added setMeshVerticesColor to utility.h and refactored some other code into calls of that

This commit is contained in:
Kahrl 2011-09-21 18:37:29 +02:00
parent a4a2c34831
commit 3e012122d1
8 changed files with 66 additions and 145 deletions

@ -249,6 +249,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize)
} }
m_wieldnode->setPosition(wield_position); m_wieldnode->setPosition(wield_position);
m_wieldnode->setRotation(wield_rotation); m_wieldnode->setRotation(wield_rotation);
m_wieldnode->updateLight(player->light);
// Render distance feedback loop // Render distance feedback loop
updateViewingRange(frametime); updateViewingRange(frametime);
@ -472,6 +473,7 @@ ExtrudedSpriteSceneNode::ExtrudedSpriteSceneNode(
m_thickness = 0.1; m_thickness = 0.1;
m_cubemesh = NULL; m_cubemesh = NULL;
m_is_cube = false; m_is_cube = false;
m_light = LIGHT_MAX;
} }
ExtrudedSpriteSceneNode::~ExtrudedSpriteSceneNode() ExtrudedSpriteSceneNode::~ExtrudedSpriteSceneNode()
@ -519,6 +521,7 @@ void ExtrudedSpriteSceneNode::setSprite(video::ITexture* texture)
m_meshnode->getMaterial(0).MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; m_meshnode->getMaterial(0).MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
m_meshnode->setVisible(true); m_meshnode->setVisible(true);
m_is_cube = false; m_is_cube = false;
updateLight(m_light);
} }
void ExtrudedSpriteSceneNode::setCube(const TileSpec tiles[6]) void ExtrudedSpriteSceneNode::setCube(const TileSpec tiles[6])
@ -546,6 +549,16 @@ void ExtrudedSpriteSceneNode::setCube(const TileSpec tiles[6])
} }
m_meshnode->setVisible(true); m_meshnode->setVisible(true);
m_is_cube = true; m_is_cube = true;
updateLight(m_light);
}
void ExtrudedSpriteSceneNode::updateLight(u8 light)
{
m_light = light;
u8 li = decode_light(light);
video::SColor color(255,li,li,li);
setMeshVerticesColor(m_meshnode->getMesh(), color);
} }
void ExtrudedSpriteSceneNode::removeSpriteFromCache(video::ITexture* texture) void ExtrudedSpriteSceneNode::removeSpriteFromCache(video::ITexture* texture)

@ -205,6 +205,8 @@ public:
f32 getSpriteThickness() const { return m_thickness; } f32 getSpriteThickness() const { return m_thickness; }
void setSpriteThickness(f32 thickness); void setSpriteThickness(f32 thickness);
void updateLight(u8 light);
void removeSpriteFromCache(video::ITexture* texture); void removeSpriteFromCache(video::ITexture* texture);
virtual const core::aabbox3d<f32>& getBoundingBox() const; virtual const core::aabbox3d<f32>& getBoundingBox() const;
@ -216,6 +218,7 @@ private:
f32 m_thickness; f32 m_thickness;
scene::IMesh* m_cubemesh; scene::IMesh* m_cubemesh;
bool m_is_cube; bool m_is_cube;
u8 m_light;
// internal extrusion helper methods // internal extrusion helper methods
io::path getExtrudedName(video::ITexture* texture); io::path getExtrudedName(video::ITexture* texture);

@ -224,22 +224,7 @@ void ItemCAO::updateLight(u8 light_at_pos)
u8 li = decode_light(light_at_pos); u8 li = decode_light(light_at_pos);
video::SColor color(255,li,li,li); video::SColor color(255,li,li,li);
setMeshVerticesColor(m_node->getMesh(), color);
scene::IMesh *mesh = m_node->getMesh();
if(mesh == NULL)
return;
u16 mc = mesh->getMeshBufferCount();
for(u16 j=0; j<mc; j++)
{
scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
u16 vc = buf->getVertexCount();
for(u16 i=0; i<vc; i++)
{
vertices[i].Color = color;
}
}
} }
v3s16 ItemCAO::getLightPosition() v3s16 ItemCAO::getLightPosition()
@ -430,22 +415,7 @@ void RatCAO::updateLight(u8 light_at_pos)
u8 li = decode_light(light_at_pos); u8 li = decode_light(light_at_pos);
video::SColor color(255,li,li,li); video::SColor color(255,li,li,li);
setMeshVerticesColor(m_node->getMesh(), color);
scene::IMesh *mesh = m_node->getMesh();
if(mesh == NULL)
return;
u16 mc = mesh->getMeshBufferCount();
for(u16 j=0; j<mc; j++)
{
scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
u16 vc = buf->getVertexCount();
for(u16 i=0; i<vc; i++)
{
vertices[i].Color = color;
}
}
} }
v3s16 RatCAO::getLightPosition() v3s16 RatCAO::getLightPosition()
@ -601,22 +571,7 @@ void Oerkki1CAO::updateLight(u8 light_at_pos)
u8 li = decode_light(light_at_pos); u8 li = decode_light(light_at_pos);
video::SColor color(255,li,li,li); video::SColor color(255,li,li,li);
setMeshVerticesColor(m_node->getMesh(), color);
scene::IMesh *mesh = m_node->getMesh();
if(mesh == NULL)
return;
u16 mc = mesh->getMeshBufferCount();
for(u16 j=0; j<mc; j++)
{
scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
u16 vc = buf->getVertexCount();
for(u16 i=0; i<vc; i++)
{
vertices[i].Color = color;
}
}
} }
v3s16 Oerkki1CAO::getLightPosition() v3s16 Oerkki1CAO::getLightPosition()
@ -833,22 +788,7 @@ void FireflyCAO::updateLight(u8 light_at_pos)
u8 li = 255; u8 li = 255;
video::SColor color(255,li,li,li); video::SColor color(255,li,li,li);
setMeshVerticesColor(m_node->getMesh(), color);
scene::IMesh *mesh = m_node->getMesh();
if(mesh == NULL)
return;
u16 mc = mesh->getMeshBufferCount();
for(u16 j=0; j<mc; j++)
{
scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
u16 vc = buf->getVertexCount();
for(u16 i=0; i<vc; i++)
{
vertices[i].Color = color;
}
}
} }
v3s16 FireflyCAO::getLightPosition() v3s16 FireflyCAO::getLightPosition()

@ -1686,7 +1686,9 @@ void ClientEnvironment::step(float dtime)
// Move // Move
player->move(dtime, *m_map, 100*BS); player->move(dtime, *m_map, 100*BS);
// Update lighting on remote players on client }
// Update lighting on all players on client
u8 light = LIGHT_MAX; u8 light = LIGHT_MAX;
try{ try{
// Get node at head // Get node at head
@ -1696,7 +1698,6 @@ void ClientEnvironment::step(float dtime)
} }
catch(InvalidPositionException &e) {} catch(InvalidPositionException &e) {}
player->updateLight(light); player->updateLight(light);
}
/* /*
Add footsteps to grass Add footsteps to grass

@ -484,20 +484,7 @@ public:
u8 li = decode_light(light_at_pos); u8 li = decode_light(light_at_pos);
video::SColor color(255,li,li,li); video::SColor color(255,li,li,li);
setMeshVerticesColor(m_node->getMesh(), color);
scene::IMesh *mesh = m_node->getMesh();
u16 mc = mesh->getMeshBufferCount();
for(u16 j=0; j<mc; j++)
{
scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
u16 vc = buf->getVertexCount();
for(u16 i=0; i<vc; i++)
{
vertices[i].Color = color;
}
}
} }
#endif #endif
@ -676,20 +663,7 @@ public:
u8 li = decode_light(light_at_pos); u8 li = decode_light(light_at_pos);
video::SColor color(255,li,li,li); video::SColor color(255,li,li,li);
setMeshVerticesColor(m_node->getMesh(), color);
scene::IMesh *mesh = m_node->getMesh();
u16 mc = mesh->getMeshBufferCount();
for(u16 j=0; j<mc; j++)
{
scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
u16 vc = buf->getVertexCount();
for(u16 i=0; i<vc; i++)
{
vertices[i].Color = color;
}
}
} }
#endif #endif
@ -836,20 +810,7 @@ public:
u8 li = decode_light(light_at_pos); u8 li = decode_light(light_at_pos);
video::SColor color(255,li,li,li); video::SColor color(255,li,li,li);
setMeshVerticesColor(m_node->getMesh(), color);
scene::IMesh *mesh = m_node->getMesh();
u16 mc = mesh->getMeshBufferCount();
for(u16 j=0; j<mc; j++)
{
scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
u16 vc = buf->getVertexCount();
for(u16 i=0; i<vc; i++)
{
vertices[i].Color = color;
}
}
} }
#endif #endif
@ -982,20 +943,7 @@ public:
u8 li = decode_light(light_at_pos); u8 li = decode_light(light_at_pos);
video::SColor color(255,li,li,li); video::SColor color(255,li,li,li);
setMeshVerticesColor(m_node->getMesh(), color);
scene::IMesh *mesh = m_node->getMesh();
u16 mc = mesh->getMeshBufferCount();
for(u16 j=0; j<mc; j++)
{
scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
u16 vc = buf->getVertexCount();
for(u16 i=0; i<vc; i++)
{
vertices[i].Color = color;
}
}
} }
#endif #endif

@ -126,7 +126,10 @@ public:
virtual bool isLocal() const = 0; virtual bool isLocal() const = 0;
virtual void updateLight(u8 light_at_pos) {}; virtual void updateLight(u8 light_at_pos)
{
light = light_at_pos;
}
// NOTE: Use peer_id == 0 for disconnected // NOTE: Use peer_id == 0 for disconnected
/*virtual bool isClientConnected() { return false; } /*virtual bool isClientConnected() { return false; }
@ -149,6 +152,8 @@ public:
bool swimming_up; bool swimming_up;
bool is_frozen; bool is_frozen;
u8 light;
Inventory inventory; Inventory inventory;
// Actual inventory is backed up here when creative mode is used // Actual inventory is backed up here when creative mode is used
Inventory *inventory_backup; Inventory *inventory_backup;
@ -266,25 +271,14 @@ public:
virtual void updateLight(u8 light_at_pos) virtual void updateLight(u8 light_at_pos)
{ {
Player::updateLight(light_at_pos);
if(m_node == NULL) if(m_node == NULL)
return; return;
u8 li = decode_light(light_at_pos); u8 li = decode_light(light_at_pos);
video::SColor color(255,li,li,li); video::SColor color(255,li,li,li);
setMeshVerticesColor(m_node->getMesh(), color);
scene::IMesh *mesh = m_node->getMesh();
u16 mc = mesh->getMeshBufferCount();
for(u16 j=0; j<mc; j++)
{
scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
u16 vc = buf->getVertexCount();
for(u16 i=0; i<vc; i++)
{
vertices[i].Color = color;
}
}
} }
void move(f32 dtime, Map &map, f32 pos_max_d); void move(f32 dtime, Map &map, f32 pos_max_d);

@ -156,6 +156,25 @@ void mysrand(unsigned seed)
next = seed; next = seed;
} }
// Sets the color of all vertices in the mesh
void setMeshVerticesColor(scene::IMesh* mesh, video::SColor& color)
{
if(mesh == NULL)
return;
u16 mc = mesh->getMeshBufferCount();
for(u16 j=0; j<mc; j++)
{
scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
u16 vc = buf->getVertexCount();
for(u16 i=0; i<vc; i++)
{
vertices[i].Color = color;
}
}
}
/* /*
blockpos: position of block in block coordinates blockpos: position of block in block coordinates
camera_pos: position of camera in nodes camera_pos: position of camera in nodes

@ -553,6 +553,9 @@ private:
u32 *m_result; u32 *m_result;
}; };
// Sets the color of all vertices in the mesh
void setMeshVerticesColor(scene::IMesh* mesh, video::SColor& color);
// Calculates the borders of a "d-radius" cube // Calculates the borders of a "d-radius" cube
inline void getFacePositions(core::list<v3s16> &list, u16 d) inline void getFacePositions(core::list<v3s16> &list, u16 d)
{ {