How to put a bitmap in a 3D world

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
MedievalMagic13

How to put a bitmap in a 3D world

Post by MedievalMagic13 »

Hello everybody. I want to make a 3D game, but for the enemies I want to use bitmaps (like in Duke Nukem 3D). I've used the code from the 2D tutorial to load a bitmap , but this puts the bitmap on the screen (so it stays on the same place on the screen and you'll see it wherever you go). I need to know how you can get it in a fixed position in the 3D world (like in Duke Nukem 3D or Doom).

I hope somebody can answer this question.

Thanks in advance.
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

what you're talking about is billboarding.

you want a Quad to always face the camera, from inside the 3D space.

what you have to do (not neccesarily in terms of irrlicht) is to calculate the vector from the camera's position to the image's center. Then find the plane perpendicular to that vector. this will be the plane the texture should be aligned to.

IrrLicht already has a particle system though, and those typically use billboarding-- so perhaps its already got something built in? Can anyone confirm or deny this suspicion? (id go read the API reference now, but my brain is fried and im going to sleep.)
a screen cap is worth 0x100000 DWORDS
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

Billboards always face the camera automatically, yes. One thing you will have to do is calculate the angle of the billboard in relation to the angle the enemy is actually facing, and use that angle to determine which texture to put on the billboard at any given time (eg if the enemy is facing you use a frontal enemy texture, if it is facing 90 degrees to you, use a side enemy texture, etc).
MedievalMagic13

Post by MedievalMagic13 »

Thanks for the answer. I looked in the SpecialFX example and found the code to let the bitmap face the camera. This works fine now, but the lighting still doesn't work. I want to have a bitmap that's fully transparent and give some light like in the SpecialFX example, but the light effect isn't there when I load the level. It sometimes come after a while, but most of the time, it doesn't.

This is my code: (I've already loaded a Quake 3 bsp file before this code)

q3node = smgr->addLightSceneNode(0, core::vector3df(-50,80,0),
video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 200.0f);


// attach billboard to light

q3node = smgr->addBillboardSceneNode(q3node, core::dimension2d<f32>(40, 40));
q3node->setMaterialFlag(video::EMF_LIGHTING, false);
q3node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
q3node->setMaterialTexture(0,driver->getTexture("data/textures/enemies/boss1.bmp"));

Would somebody know what the problem is?

Thanks.
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

I dont know why its not working for you-- but the engine isnt called the "Erring Light" engine for nothing. HAH! ahahahaha. aaah. ::sigh:: I'm funny.
a screen cap is worth 0x100000 DWORDS
MedievalMagic13

Post by MedievalMagic13 »

Thanks for the answers guys, but I've found the problem myself. I have to use EMT_TRANSPARENT_VERTEX_ALPHA instead of EMT_TRANSPARENT_ADD_COLOR.
Post Reply