stuff you can(and need) to change is dot0.tga and the basesize
decalscenenode.h
Code: Select all
#include <irrlicht.h>
using namespace irr;
class DecalSceneNode : public scene::ISceneNode
{
protected:
core::aabbox3d<f32> Box;
video::S3DVertex Vertices[4];
video::SMaterial Material;
public:
DecalSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, core::triangle3df tri, core::vector3df intersection);
core::vector3df pointA;
core::vector3df pointB;
core::vector3df pointC;
float posA;
float posB;
float posC;
core::vector3df trinormal;
float basesize;
float dotcorrection;
video::IVideoDriver* driver;
video::ITexture* image;
core::line3d<f32> line1;
core::vector3df v1;
core::vector3df v2;
core::line3d<f32> line2;
core::vector3df v3;
core::vector3df squarepA;
core::vector3df squarepB;
core::vector3df squarepC;
core::vector3df squarepD;
void OnPreRender();
void render();
const core::aabbox3d<f32>& getBoundingBox() const;
virtual s32 getMaterialCount();
virtual video::SMaterial& getMaterial(s32 i);
};
Code: Select all
#include <irrlicht.h>
#include "decalscenenode.h"
using namespace irr;
DecalSceneNode::DotSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, core::triangle3df tri, core::vector3df intersection): scene::ISceneNode(parent, mgr, 0)
{
pointA=tri.pointA;
pointB=tri.pointB;
pointC=tri.pointC;
posA=intersection.X;
posB=intersection.Y;
posC=intersection.Z;
trinormal=tri.getNormal();
float basesize;
dotcorrection=1;
video::IVideoDriver* driver = SceneManager->getVideoDriver();
Material.Wireframe = false;
Material.Lighting = false;
video::ITexture* image = driver->getTexture("dot0.tga");
this->setMaterialType( video::EMT_TRANSPARENT_ALPHA_CHANNEL );
this->setMaterialFlag(video::EMF_LIGHTING, true);
this->setMaterialTexture(0, image );
basesize=0.5;
trinormal=trinormal.normalize();
core::line3d<f32> line1(pointA, pointB);
core::vector3df v1 = line1.getVector().normalize();
core::vector3df v2 = line1.getClosestPoint( pointC );
core::line3d<f32> line2(v2,pointC);
core::vector3df v3 = line2.getVector().normalize();
core::vector3df squarepA=(v1*-basesize)+trinormal*dotcorrection+(v3*-basesize);
core::vector3df squarepB=squarepA+(v1*basesize*2);
core::vector3df squarepC=squarepA+(v1*basesize*2)+(v3*basesize*2);
core::vector3df squarepD=squarepA+(v3*basesize*2);
squarepA=squarepA+core::vector3df(posA,posB,posC);
squarepB=squarepB+core::vector3df(posA,posB,posC);
squarepC=squarepC+core::vector3df(posA,posB,posC);
squarepD=squarepD+core::vector3df(posA,posB,posC);
Vertices[0] = video::S3DVertex(squarepA.X,squarepA.Y,squarepA.Z, 1,0,0,video::SColor(255,255,255,255),1,0);
Vertices[1] = video::S3DVertex(squarepB.X,squarepB.Y,squarepB.Z, 1,0,0,video::SColor(255,255,255,255),1,1);
Vertices[2] = video::S3DVertex(squarepC.X,squarepC.Y,squarepC.Z, 1,0,0,video::SColor(255,255,255,255),0,1);
Vertices[3] = video::S3DVertex(squarepD.X,squarepD.Y,squarepD.Z, 1,0,0,video::SColor(255,255,255,255),0,0);
Box.reset(Vertices[0].Pos);
for (s32 i=1; i<4; ++i)
Box.addInternalPoint(Vertices[i].Pos);
}
void DecalSceneNode::OnPreRender()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnPreRender();
}
void DecalSceneNode::render()
{
u16 indices[] = { 0,1,2, 0,2,3};
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setMaterial(Material);
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 2);
}
const core::aabbox3d<f32>& DecalSceneNode::getBoundingBox() const
{
return Box;
}
s32 DecalSceneNode::getMaterialCount()
{
return 1;
}
video::SMaterial& DecalSceneNode::getMaterial(s32 i)
{
return Material;
}