Now, first of all, if anyone has an easier way of doing 2d scaling and rotation I would be very happy to hear about it. I'm not committed to this class, I just need a way to do scaling/rotation for something I'm working on. Also, if anyone has a class or a link to a class that does something similar I'd love to hear it.
This code has several problems. (any solutions or suggestions would be much appreciated)
1) I can't make 'bill' draw by itself, if I use its render method directly it draws from the point of view of the FPS camera for some reason. If I can't make it draw by itself then in future when I have other scene nodes its going to get unpleasant. 'drawAll' draws from the proper camera though.
2) the output is upside down, (this is noted in the documentation for setRenderTarget, but the provided solution seems to only apply when using the output as a texture on a 3d object.
3) can't rotate the image.
4) the background is black on the image, though I can probably nut out a straight forward solution to this.
5) I can't seem to see the billboard when I use
ortho.buildProjectionMatrixOrthoLH(1.0f, 1.0f, 0.0f, 10.0f);
when I tried it, even when poking around with the FPS camera set to orthogonal I couldn't see the billboard..
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
int main()
{
IrrlichtDevice * device = createDevice(video::EDT_OPENGL, dimension2d<s32>(1024, 768), 32, false, false, false, 0);
video::IVideoDriver * video = device->getVideoDriver();
gui::IGUIEnvironment * env = device->getGUIEnvironment();
scene::ISceneManager * man = device->getSceneManager();
video::ITexture * original = video->getTexture("centered.png");
video::ITexture * output = video->createRenderTargetTexture(dimension2di(128, 128));
scene::IBillboardSceneNode * bill =
man->addBillboardSceneNode
(man->getRootSceneNode(),
dimension2df(1.0f, 1.0f),
vector3df(0.0f, 0.0f, 1.0f),
-1,
video::SColor(255, 0, 0, 0),
video::SColor(255, 0, 0, 0));
bill->setMaterialTexture(0, original);
bill->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
matrix4 ortho;
ortho.buildProjectionMatrixOrthoLH(1.0f, 1.0f, 0.0f, 10.0f);
// can't seem to make a RH matrix work...
scene::ICameraSceneNode * cam =
man->addCameraSceneNode
(man->getRootSceneNode(),
vector3df(0.0f, 0.0f, 0.0f),
vector3df(0.0f, 0.0f, 1.0f));
cam->setProjectionMatrix(ortho);
cam->setIsOrthogonal(true);
scene::ICameraSceneNode * fpsCam =
man->addCameraSceneNodeFPS(man->getRootSceneNode(), 100.0f, 50.0f);
env->addImage(output, position2di(0, 0), true, env->getRootGUIElement(), -1);
// display
while(device->run())
{
video->beginScene(true, true, video::SColor(0, 122, 65, 171));
video->setRenderTarget(output);
man->setActiveCamera(cam);
bill->setVisible(true);
bill->render();
//man->drawAll(); // this works
bill->setVisible(false);
video->setRenderTarget(NULL, false);
man->setActiveCamera(fpsCam);
man->drawAll();
env->drawAll();
video->endScene();
device->yield();
}
output->drop();
device->drop();
return 0;
}