This is your class applied in the basic CostumSceneNode example.
I tweak your Vertices a little-bit, but if it is still not working you have to give more information.
Code: Select all
#include <irrlicht.h>
#include <iostream>
using namespace irr;
using namespace scene;
using namespace video;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
class CrosshairSceneNode : public scene::ISceneNode
{
protected:
core::aabbox3d<f32> Box;
video::S3DVertex Vertices[4];
video::SMaterial Material;
public:
CrosshairSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id) : ISceneNode(parent, mgr, id) {
Material.Wireframe = false;
Material.Lighting = false;
SColor col(0,255,255,255);
Vertices[0] = S3DVertex(0,0,0, 0,0,0, col, 0, 1);
Vertices[1] = S3DVertex(0,10,0, 0,1,0, col, 0, 0);
Vertices[2] = S3DVertex(15,10,0, 1,1,0, col, 1, 0);
Vertices[3] = S3DVertex(15,0,0, 1,0,0, col, 1, 1);
this->setAutomaticCulling(EAC_OFF);
Box.reset(Vertices[0].Pos);
for (s32 i=1; i<4; ++i)
Box.addInternalPoint(Vertices[i].Pos);
}
virtual void OnRegisterSceneNode()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnRegisterSceneNode();
}
virtual void render()
{
u16 indices[] = {0,1,3, 1,2,3};
IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setMaterial(Material);
driver->setTransform(ETS_WORLD, AbsoluteTransformation);
driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 2);
}
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return Box;
}
virtual u32 getMaterialCount() const
{
return 1;
}
virtual video::SMaterial& getMaterial(u32 i)
{
return Material;
}
void setMaterialTexture(u32 textureLayer, video::ITexture* texture) {
if (textureLayer >= video::MATERIAL_MAX_TEXTURES)
return;
for (u32 i=0; i<getMaterialCount(); ++i)
getMaterial(i).setTexture(textureLayer, texture);
}
};
int main()
{
// let user select driver type
video::E_DRIVER_TYPE driverType;
printf("Please select the driver you want for this example:\n"\
" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
" (d) Software Renderer\n (e) Burning's Software Renderer\n"\
" (f) NullDevice\n (otherKey) exit\n\n");
char i;
std::cin >> i;
switch(i)
{
case 'a': driverType = video::EDT_DIRECT3D9;break;
case 'b': driverType = video::EDT_DIRECT3D8;break;
case 'c': driverType = video::EDT_OPENGL; break;
case 'd': driverType = video::EDT_SOFTWARE; break;
case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
case 'f': driverType = video::EDT_NULL; break;
default: return 0;
}
// create device
IrrlichtDevice *device = createDevice(driverType,
core::dimension2d<u32>(640, 480), 16, false);
if (device == 0)
return 1; // could not create selected driver.
// create engine and camera
device->setWindowCaption(L"Custom Scene Node - Irrlicht Engine Demo");
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
ICameraSceneNode* camera =smgr->addCameraSceneNodeFPS(0,50, 0.1, -1, 0, 1,false);
camera->setPosition(core::vector3df(0,0,-40));
//YOUR CLASS IS ABOUT TO FIRE HERE
CrosshairSceneNode *myNode =
new CrosshairSceneNode(smgr->getRootSceneNode(), smgr, 666);
video::ITexture *Tex1;
Tex1=driver->getTexture("../../media/detailmap3.jpg");
myNode->setMaterialTexture(0,Tex1);
myNode->drop();
myNode = 0;
//WOW that was amazing
u32 frames=0;
while(device->run())
{
driver->beginScene(true, true, video::SColor(0,100,100,100));
smgr->drawAll();
driver->endScene();
if (++frames==100)
{
core::stringw str = L"Irrlicht Engine [";
str += driver->getName();
str += L"] FPS: ";
str += (s32)driver->getFPS();
device->setWindowCaption(str.c_str());
frames=0;
}
}
device->drop();
return 0;
}