Bullet marks on wall

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Armen138
Posts: 298
Joined: Mon Feb 23, 2004 3:38 am

decalscenenode

Post by Armen138 »

here's the code, its not documented at all so i hope you can make some sense out of it...
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);

};
decalscenenode.cpp

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;
   }
if you're looking for me, start looking on irc, i'm probably there.
Armen138
Posts: 298
Joined: Mon Feb 23, 2004 3:38 am

Post by Armen138 »

heh maybe i should post a little code how to call this thing...
if you're looking for me, start looking on irc, i'm probably there.
Armen138
Posts: 298
Joined: Mon Feb 23, 2004 3:38 am

Post by Armen138 »

Code: Select all

		if (smgr->getSceneCollisionManager()->getCollisionPoint(
			line, selector, intersection, tri))
		{
DecalSceneNode* dot= new DecalSceneNode(smgr->getRootSceneNode(), smgr,tri,intersection);
}
i hope all of this makes sense to you...
if you're looking for me, start looking on irc, i'm probably there.
Captain_Kill
Posts: 124
Joined: Sun Jun 27, 2004 11:02 am
Contact:

Post by Captain_Kill »

Nice :shock: Thanks for that m8 8)
2.8GHz P4 with HT - 512MB DDR - ATI Radeon 9600XT 256MB - Windows XP - VC++ 6 and VC++ 2003

Dark Reign 3 Home Page: http://darkreign3.notwhatyouthink.org/
Dark Reign 3 Forums: http://notwhatyouthink.org/darkreign3bb/
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

very nice
Armen138
Posts: 298
Joined: Mon Feb 23, 2004 3:38 am

update

Post by Armen138 »

here's a little more complete version, without the typo's :)

decalscenenode.h

Code: Select all

#include <irrlicht.h>
#include <time.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, video::ITexture* image);
   	   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;
	
       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;
	     
	   time_t c_time;
	   time_t d_time;
	   double lifeSpan;

void setLifeSpan(double seconds);
float getSize();
void OnPreRender();

void render();
   

const core::aabbox3d<f32>& getBoundingBox() const;

   virtual s32 getMaterialCount();
   
   virtual video::SMaterial& getMaterial(s32 i);

};
decalscenenode.cpp

Code: Select all

/* 
bullethole/decal class
by Armen138

before creating an instance of this class, i assume you got:
1. the triangle you hit with your weapon
2. the coordinates(intersection point) you hit the triangle at
3. the texture you want to display on the decal
4. the size you want the bullethole to be(you'll have to experiment a little with this one)

these are the last 4 arguments for the constructor.

this will create a square decal displaying your texture on the wall you hit
with a weapon shooting in a straight line.
*/

#include <irrlicht.h>
#include "decalscenenode.h"
#include "time.h"
using namespace irr;
DecalSceneNode::DecalSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, core::triangle3df tri, core::vector3df intersection, video::ITexture* image, float size): scene::ISceneNode(parent, mgr, 0)
{	  	   
	   time(&c_time);	 
	   lifeSpan=0;
	   pointA=tri.pointA;
	   pointB=tri.pointB;
	   pointC=tri.pointC;
	   posA=intersection.X;
	   posB=intersection.Y;
	   posC=intersection.Z;
       trinormal=tri.getNormal();	   
	   dotcorrection=1;
       video::IVideoDriver* driver = SceneManager->getVideoDriver();
           
       Material.Wireframe = false;
       Material.Lighting = false;
       
       this->setMaterialType( video::EMT_TRANSPARENT_ALPHA_CHANNEL  );
       this->setMaterialFlag(video::EMF_LIGHTING, true);
       this->setMaterialTexture(0, image );
	   basesize=size/2;


       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::setLifeSpan(double seconds){
	lifeSpan=seconds;
}

float DecalSceneNode::getSize(){
	return basesize*2;
}
void DecalSceneNode::OnPreRender()
   {			     	   
	   if(lifeSpan>0){if(difftime(time(NULL),c_time) > lifeSpan)SceneManager->addToDeletionQueue(this);}
       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;
   }
if you're looking for me, start looking on irc, i'm probably there.
Armen138
Posts: 298
Joined: Mon Feb 23, 2004 3:38 am

example

Post by Armen138 »

i posted an example on how to use all this stuff here:
http://www.irrlichtnx.mmdevel.de/phpBB2 ... ?p=556#556
if you're looking for me, start looking on irc, i'm probably there.
Armen138
Posts: 298
Joined: Mon Feb 23, 2004 3:38 am

Post by Armen138 »

for the transparancy part to work correctly, you should use irrlichtNX and OpenGL for now....
if you're looking for me, start looking on irc, i'm probably there.
arnir
Competition winner
Posts: 154
Joined: Sat Jan 20, 2007 4:36 pm
Location: Czech Republic

Re: example

Post by arnir »

Armen138 wrote:i posted an example on how to use all this stuff here:
http://www.irrlichtnx.mmdevel.de/phpBB2 ... ?p=556#556
link dont work...
please send here an example of use
thanks
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Re: example

Post by rogerborg »

Armen138 wrote:Posted: Wed Sep 01, 2004 3:44 pm

yea, and i did verily post ye example onneth how ye useth all this stuffeth over in yonder place:
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
arnir
Competition winner
Posts: 154
Joined: Sat Jan 20, 2007 4:36 pm
Location: Czech Republic

Re: example

Post by arnir »

rogerborg wrote:
Armen138 wrote:Posted: Wed Sep 01, 2004 3:44 pm

yea, and i did verily post ye example onneth how ye useth all this stuffeth over in yonder place:
i dont understand :oops:
arnir
Competition winner
Posts: 154
Joined: Sat Jan 20, 2007 4:36 pm
Location: Czech Republic

Post by arnir »

i solved my problem
programmer is bad designer
designer is bad programmer
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Cool.. I looked for this a while back for IrrExt but couldn't find it, tidying this up is much better than writing a new one :)
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Is it usable? It looks like it'll happily hang out in space, so it'll look vile when applied near edges.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
arnir
Competition winner
Posts: 154
Joined: Sat Jan 20, 2007 4:36 pm
Location: Czech Republic

Post by arnir »

in 1,41 version of irrlicht, dont working alpha channel right.

I disscus this also here: http://irrlicht.sourceforge.net/phpBB2/ ... p?p=171140
programmer is bad designer
designer is bad programmer
Post Reply