I want to draw a dynamic scene node in per-pixel lighting. I referred the tutorials and tried this.
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace video;
using namespace scene;
using namespace gui;
using namespace io;
class CSceneNode : public ISceneNode {
public:
CSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id) : ISceneNode(parent, mgr, id), meshBuffer(new SMeshBuffer()) {
meshBuffer->Material.Wireframe = false;
//meshBuffer->Material.Lighting = false;
meshBuffer->Material.MaterialType = EMT_PARALLAX_MAP_SOLID;
meshBuffer->Vertices.set_used(6);
meshBuffer->Vertices[0] = S3DVertex(0, 0, 10, 1, 1, 0, SColor(255, 0, 255, 255), 0, 1);
meshBuffer->Vertices[1] = S3DVertex(10, 0, -10, 1, 0, 0, SColor(255, 255, 0, 255), 0.5f, 0);
meshBuffer->Vertices[2] = S3DVertex(0, 20, 0, 0, 1, 1, SColor(255, 255, 255, 0), 0, 0);
meshBuffer->Vertices[3] = S3DVertex(-10, 0, -10, 0, 0, 1, SColor(255, 0, 255, 0), 0.5f, 1);
meshBuffer->Vertices[4] = S3DVertex(0, 0, 10, 1, 1, 0, SColor(255, 0, 255, 255), 1, 1);
meshBuffer->Vertices[5] = S3DVertex(0, 20, 0, 0, 1, 1, SColor(255, 255, 255, 0), 1, 0);
meshBuffer->Indices.set_used(12);
u16 indices[] = { 2,3,0, 1,3,2, 1,4,3, 5,4,1 };
for (s32 i = 0; i < 12; i++) {
meshBuffer->Indices[i] = indices[i];
}
meshBuffer->BoundingBox.reset(meshBuffer->Vertices[0].Pos);
for (s32 i = 1; i < 4; ++i) {
meshBuffer->BoundingBox.addInternalPoint(meshBuffer->Vertices[i].Pos);
}
}
virtual void OnRegisterSceneNode() {
if (IsVisible) {
SceneManager->registerNodeForRendering(this);
}
ISceneNode::OnRegisterSceneNode();
}
virtual void render() {
IVideoDriver* drv = SceneManager->getVideoDriver();
drv->setMaterial(meshBuffer->Material);
drv->setTransform(ETS_WORLD, AbsoluteTransformation);
drv->drawMeshBuffer(meshBuffer);
}
virtual const aabbox3d<f32>& getBoundingBox() const
{
return meshBuffer->BoundingBox;
}
virtual u32 getMaterialCount() const
{
return 1;
}
virtual SMaterial& getMaterial(u32 i)
{
return meshBuffer->Material;
}
private:
SMeshBuffer* meshBuffer;
};
int main() {
IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<u32>(640, 480), 16, false);
if (device == 0) {
return 1;
}
IVideoDriver* drv = device->getVideoDriver();
ISceneManager* mgr = device->getSceneManager();
drv->setTextureCreationFlag(ETCF_ALWAYS_32_BIT, true);
mgr->addCameraSceneNode(0, vector3df(0, 0, -40), vector3df(0, 0, 0));
//mgr->addCameraSceneNodeFPS()->setPosition(vector3df(0, 0, -40));
mgr->addLightSceneNode(0, vector3df(20, 0, -20));
mgr->addSphereSceneNode(5.0f, 16, 0, 777, vector3df(20, 0, -20))->setMaterialFlag(EMF_LIGHTING, false);
CSceneNode *node = new CSceneNode(mgr->getRootSceneNode(), mgr, 666);
node->setMaterialTexture(0, drv->getTexture("a.png"));
ITexture* HTM = drv->getTexture("ah.png");
drv->makeNormalMapTexture(HTM);
node->setMaterialTexture(1, HTM);
ISceneNodeAnimator* animation = mgr->createRotationAnimator(vector3df(0.8f, 0, 0.3f));
if (animation) {
node->addAnimator(animation);
animation->drop();
}
node->drop();
while (device->run()) {
drv->beginScene();
//drv->beginScene(true, true, SColor(0, 100, 100, 100));
mgr->drawAll();
drv->endScene();
}
device->drop();
return 0;
}
Please tell me how to draw like tutorial 11.
ah.png is a grayscale of a.png
Thank you.