I created a simple crosshair for my project, but I decided to make it into a scene node. As a scene node I need to add it to the scene manager, but I'm not sure what I should add it as. Now that it's a scene node, how do I keep it flat to the screen?
Before I was simply drawing it manually after the scene manager was done drawing.
Thanks.
Crosshairs flat to the screen
-
- Posts: 101
- Joined: Wed Dec 03, 2008 5:33 pm
- Location: ger
just load an ITexture and then add an gui image
(don't forget the guienv->drawAll() in the mainloop.)
this is how i do it.
i think this is what you mean...(?!)
(don't forget the guienv->drawAll() in the mainloop.)
this is how i do it.
Code: Select all
video::ITexture* CrosshairTex = driver->getTexture("../../media/Crosshair.png");
guienv->addImage(CrosshairTex, core::position2d<s32>(driver->getScreenSize().Width / 2 - (CrosshairTex->getSize().Width/2), driver->getScreenSize().Height / 2 - (CrosshairTex->getSize().Height/2)) , true);
i love skateboarding!
Code: Select all
class CCrossHair : public irr::gui::IGUIElement
{
public:
CCrossHair(irr::gui::IGUIEnvironment * environment, irr::u32 id = -1) : irr::gui::IGUIElement ( irr::gui::EGUIET_ELEMENT, environment, environment->getRootGUIElement(), id, irr::core::rect< irr::s32 >(0,0,0,0))
{
Texture = 0;
Color = irr::video::SColor(255,255,255,0);
Size = 10;
}
virtual ~CCrossHair(void)
{
if (Texture)
Texture->drop();
}
void draw(void)
{
irr::video::IVideoDriver* driver = Environment->getVideoDriver();
irr::u32 screenW = driver->getScreenSize().Width;
irr::u32 screenH = driver->getScreenSize().Height;
irr::u32 cenW = screenW / 2;
irr::u32 cenH = screenH / 2;
if (!Texture)
{
//Draw crosshair
driver->draw2DRectangle( Color, irr::core::rect<irr::s32>(cenW-1,cenH-Size,cenW+1,cenH-4) ); //above
driver->draw2DRectangle( Color, irr::core::rect<irr::s32>(cenW+4,cenH-1,cenW+Size,cenH+1) ); //right
driver->draw2DRectangle( Color, irr::core::rect<irr::s32>(cenW-1,cenH+4,cenW+1,cenH+Size) ); //down
driver->draw2DRectangle( Color, irr::core::rect<irr::s32>(cenW-Size,cenH-1,cenW-4,cenH+1) ); //left
driver->draw2DRectangle( Color, irr::core::rect<irr::s32>(cenW-1,cenH-1,cenW+1,cenH+1) ); //center of screen
}
else
{
irr::video::SColor Colors [] = {Color, Color, Color, Color};
driver->draw2DImage(Texture, irr::core::rect< irr::s32 >(cenW-Size, cenH-Size, cenW+Size, cenH+Size), irr::core::rect< irr::s32 >(0, 0, Texture->getOriginalSize().Width, Texture->getOriginalSize().Height), 0, Colors, true);
}
}
void setTexture(irr::video::ITexture* texture)
{
if (Texture)
Texture->drop();
Texture = texture;
if (Texture)
Texture->grab();
}
void setSize(irr::u32 size)
{
Size = size;
}
void setColor(irr::video::SColor color)
{
Color = color;
}
protected:
irr::video::ITexture* Texture;
irr::u32 Size;
irr::video::SColor Color;
};
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
-
- Posts: 1186
- Joined: Fri Dec 29, 2006 12:04 am
Code: Select all
crosshair = smgr->addBillboardSceneNode(camera, irr::core::dimension2df(4, 4), irr::core::vector3df(0.0f, 0.0f, 50.0f));
crosshair->setMaterialType(irr::video::EMT_TRANSPARENT_ADD_COLOR);
crosshair->setMaterialTexture(0, videoDriver->getTexture("media/images/crosshair/cross.bmp"));
crosshair->setMaterialFlag(irr::video::EMF_LIGHTING, false);
crosshair->setMaterialFlag(irr::video::EMF_ZBUFFER, false);
Last edited by randomMesh on Sun Jan 11, 2009 12:40 am, edited 1 time in total.
So you have your own scene node that you've written? i.e., you wrote a class that inherits from ISceneNode.isfk wrote:I am rendering it in the render method as an inherited ISceneNode.
I'm not sure what you mean. Are you trying to figure out how to add a function to the ISceneManager interface for creating your new scene node (like smgr->addCrosshairSceneNode()), or are you just trying to figure out how to put one of the nodes into the scene so it will render?I have the scene node ready, but I don't know how to add it to the scene manager.
Now i'm even more confused. Are you just saying that you tried to use a IBillboardSceneNode but didn't like it because it wouldn't automatically stay in the right place?I tried adding it as a bill board, but I can't keep it stick to the front of the camera no matter how I move the camera.
Travis
That is what I was after, I needed to use the camera as the node to attach it to. Thanks for your help.randomMesh wrote:Code: Select all
crosshair = smgr->addBillboardSceneNode(camera, irr::core::dimension2df(4, 4), irr::core::vector3df(0.0f, 0.0f, 50.0f)); crosshair->setMaterialType(irr::video::EMT_TRANSPARENT_ADD_COLOR); crosshair->setMaterialTexture(0, videoDriver()->getTexture("media/images/crosshair/cross.bmp")); crosshair->setMaterialFlag(irr::video::EMF_LIGHTING, false); crosshair->setMaterialFlag(irr::video::EMF_ZBUFFER, false);