newbie question:
I have a general question regarding model animation. Let's say I have a box that has two animations, 1. it rotates, and 2. it changes color.
What model file type should I use, will md2 do that.
How do I independently control those two animations in the code to:
Hit the 'A' to make it rotate.
Hit the 'B' to make it change color.
In other words, how can you get to separate animations for the same model.
I'm sorry if I'm not asking this right, I did get a little familiar with the blender game engine, but just starting out with irrlicht.
Thanks for any suggestions.
Animation and the engine
Frames of animation have its index numbers. Irrlicht lets you choose which frames you play. You animate your model so taht one animation follows another. For example:
animation: frame 0-100
-walk animation: frame 0-50
-run animation: frame 50-100
when user hit A you play frames 0-50, when B frames 50-100.
However while this kind of animation lets you rotate your model, it don't let you change color of your model since it works only with position of vertices.
What you need is to use one of the ISceneNodeAnimator types. There is rotation animator which you can create via ISceneManager::createRotationAnimator function but I don't know any "change color" animator so you probably have to create one yourself. Look at SpecialFX example for some example code.
animation: frame 0-100
-walk animation: frame 0-50
-run animation: frame 50-100
when user hit A you play frames 0-50, when B frames 50-100.
However while this kind of animation lets you rotate your model, it don't let you change color of your model since it works only with position of vertices.
What you need is to use one of the ISceneNodeAnimator types. There is rotation animator which you can create via ISceneManager::createRotationAnimator function but I don't know any "change color" animator so you probably have to create one yourself. Look at SpecialFX example for some example code.
Exactly what I needed to know, thanks
Thanks... that's exactly what I was looking for. Too bad about the color animation though. I just used IPO curves in blender engine.
Darien
Darien
It wont be so dificult to implement, depends howe well zou know Irrlicht already.
Here is code which will "burn" texture of cube. You can find some inspiration there.
Of course you can alter color of vertices instead of texture pixels but that would work only if lighting is off for object.
It was made for some older Irrlicht version so you may want to do some changes to code.
Here is code which will "burn" texture of cube. You can find some inspiration there.
Of course you can alter color of vertices instead of texture pixels but that would work only if lighting is off for object.
Code: Select all
#include <irrlicht.h>
using namespace irr;
// this code will work only if texture is in default 32 bit color format (ECF_A8R8G8B8)
void burn(scene::ISceneNode* node, u32 amouth)
{
// get texture of node
// note that depending on type node may have more than one material with seweral textures each
video::ITexture* texture = node->getMaterial(0).Texture1;
// find size of texture
core::dimension2d<s32> size = texture->getSize();
// get pointer to texture data
s32* p = (s32*)texture->lock();
for(s32 i=0; i<size.Width*size.Height; i++)
{
// get color of pixel
video::SColor color = p[i];
// darken color until black
if(color.getRed() > amouth) color.setRed(color.getRed() - amouth);
else color.setRed(0);
if(color.getGreen() > amouth) color.setGreen(color.getGreen() - amouth);
else color.setGreen(0);
if(color.getBlue() > amouth) color.setBlue(color.getBlue() - amouth);
else color.setBlue(0);
// set new color to pixel
p[i] = color.color;
}
texture->unlock();
}
int main()
{
IrrlichtDevice *device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480), 16, false, false, false, 0);
device->setWindowCaption(L"Burn Cube");
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
scene::ISceneNode* node = smgr->addCubeSceneNode();
node->setMaterialTexture(0, driver->getTexture("texture.bmp") );
node->setMaterialFlag(video::EMF_LIGHTING, false);
scene::ISceneNode* node2 = smgr->addCubeSceneNode();
node2->setMaterialTexture(0, driver->getTexture("texture.bmp") );
node2->setMaterialFlag(video::EMF_LIGHTING, false);
node2->setPosition(core::vector3df(-10,0,0));
smgr->addCameraSceneNode(0, core::vector3df(7,10,-15), core::vector3df(0,0,0));
// howe much to burn
s32 n = 150;
// since color RGB components are stored as u32 we can nott decrement with
// lower number than 1. To make burning proces bit slower we burn cube only
// once per 100 frames
s32 frames = 0;
while(device->run())
{
driver->beginScene(true, true, video::SColor(255,100,101,140));
if(frames > 0)
frames--;
else
{
if(n > 0)
{
burn(node, 1);
n--;
}
frames = 100;
}
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}