Hi,
I'm trying to port my DecalSceneNode to v1.4 and I think I have the same problem, but can't solve it !?!?!
I do exactly the same and getting the same result !!!
if I set the texture, the quad gets black, if I don't set the texture the quad uses the vertex color...
I also have no const behind getMaterialCount, but I thought this doesn't matter, because I set the material directly and not with the setMaterial functions...
after I found this thread I decided to give this const a try, as far as it seems to be exactly my problem...
but if I declare getMaterialCount as const the test program crashes !?!?!
IDecalSceneNode.h:
Code: Select all
#ifndef __I_DECAL_SCENE_NODE_H_INCLUDED__
#define __I_DECAL_SCENE_NODE_H_INCLUDED__
#include "ISceneNode.h"
namespace irr{
namespace scene{
class IDecalSceneNode : public ISceneNode{
public:
IDecalSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, core::triangle3df tri,
core::vector3df intersection, video::ITexture* image, float size):ISceneNode(parent, mgr) {}
virtual void setLifeSpan(double seconds) = 0;
virtual const core::dimension2d<f32>& getSize() = 0;
};
} // namespace scene
} // namespace irr
#endif
CDecalSceneNode.h:
Code: Select all
#ifndef __C_DECAL_SCENE_NODE_H_INCLUDED__
#define __C_DECAL_SCENE_NODE_H_INCLUDED__
#include "time.h"
#include "IDecalSceneNode.h"
#include "S3DVertex.h"
namespace irr{
namespace scene{
class CDecalSceneNode : public IDecalSceneNode{
public:
CDecalSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, core::triangle3df tri, core::vector3df intersection, video::ITexture* image, float size);
virtual void setLifeSpan(double seconds);
virtual void OnRegisterSceneNode();
virtual void render();
virtual const core::aabbox3d<f32>& getBoundingBox() const;
virtual const core::dimension2d<f32>& getSize();
virtual video::SMaterial& getMaterial(s32 i);
// virtual u32 getMaterialCount()const; // <<< program crash
virtual u32 getMaterialCount();
virtual ESCENE_NODE_TYPE getType() { return ESNT_BILLBOARD; }
private:
time_t c_time;
double lifeSpan;
core::dimension2d<f32> Size;
core::aabbox3d<f32> BBox;
video::SMaterial Material;
video::S3DVertex vertices[4];
u16 indices[6];
};
} // namespace scene
} // namespace irr
#endif
CDecalSceneNode.cpp:
Code: Select all
#include "CDecalSceneNode.h"
#include "time.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "ICameraSceneNode.h"
#include "os.h"
namespace irr{
namespace scene{
CDecalSceneNode::CDecalSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, core::triangle3df tri, core::vector3df intersection, video::ITexture* image, float size):IDecalSceneNode(parent, mgr, tri, intersection, image, size){
#ifdef _DEBUG
setDebugName("CDecalSceneNode");
#endif
time(&c_time);
lifeSpan=0;
// create quad
core::vector3df pointA=tri.pointA;
core::vector3df pointB=tri.pointB;
core::vector3df pointC=tri.pointC;
float posA=intersection.X;
float posB=intersection.Y;
float posC=intersection.Z;
core::vector3df trinormal=tri.getNormal();
float dotcorrection=1;
float 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);
BBox.reset(vertices[0].Pos);
for(s32 i=1; i<4; ++i) BBox.addInternalPoint(vertices[i].Pos);
indices[0] = 0;
indices[1] = 1;
indices[2] = 2;
indices[3] = 0;
indices[4] = 2;
indices[5] = 3;
setAutomaticCulling(scene::EAC_BOX);
// set material
Material.Lighting = false;
Material.ZBuffer = true;
Material.ZWriteEnable = true;
Material.BackfaceCulling = false;
Material.Wireframe = false;
Material.setTexture(0,image);
//Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
//this->setMaterialFlag(video::EMF_LIGHTING, false);
//this->setMaterialFlag(video::EMF_ZBUFFER, true);
//this->setMaterialFlag(video::EMF_ZWRITE_ENABLE, true);
//this->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
//this->setMaterialTexture(0, image );
}
void CDecalSceneNode::setLifeSpan(double seconds){
lifeSpan = seconds;
}
void CDecalSceneNode::OnRegisterSceneNode(){
if(lifeSpan>0){
if(difftime(time(NULL),c_time) > lifeSpan)
SceneManager->addToDeletionQueue(this);
}
if(IsVisible){
SceneManager->registerNodeForRendering(this);
ISceneNode::OnRegisterSceneNode();
}
}
const core::dimension2d<f32>& CDecalSceneNode::getSize(){
return Size;
}
void CDecalSceneNode::render(){
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>& CDecalSceneNode::getBoundingBox() const{
return BBox;
}
video::SMaterial& CDecalSceneNode::getMaterial(s32 i){
return Material;
}
//u32 CDecalSceneNode::getMaterialCount()const{ // <<< program crash
u32 CDecalSceneNode::getMaterialCount(){
return 1;
}
} // namespace scene
} // namespace irr