I'm trying to use this http://irrlicht.sourceforge.net/docu/example008.html tutorial on FX in the following code which does work with
Code: Select all
anim = smgr->createRotationAnimator ( irr::core::vector3df(0.0f, 1.0f, 0.0f) );
Here's the complete code
Code: Select all
#include "irrlicht.h"
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace irr;
class EventReceiver : public irr::IEventReceiver
{
public:
virtual bool OnEvent(const irr::SEvent& event);
virtual bool IsKeyDown( irr::EKEY_CODE keyCode) const;
EventReceiver();
private:
bool KeyIsDown[ irr::KEY_KEY_CODES_COUNT];
};
bool EventReceiver::OnEvent(const irr::SEvent& event)
{
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
bool EventReceiver::IsKeyDown( irr::EKEY_CODE keyCode) const
{
return KeyIsDown[keyCode];
}
EventReceiver::EventReceiver()
{
for ( irr::u32 i = 0; i < irr::KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
}
scene::SMeshBuffer Buffer;
video::IVideoDriver* driver;
void init_indices()//this is supposed to create a triangle polygon. The indices represent the points of the vertices and the point zero is the beginning and endpoint.
{
int index = Buffer.Indices.size();
Buffer.Indices.push_back( index/3);
Buffer.Indices.push_back( 2+index/3);
Buffer.Indices.push_back( 3+index/3);
Buffer.Indices.push_back( 2+index/3);
Buffer.Indices.push_back( 1+index/3);
Buffer.Indices.push_back( 3+index/3);
Buffer.Indices.push_back( 1+index/3);
Buffer.Indices.push_back( index/3);
Buffer.Indices.push_back( 3+index/3);
Buffer.Indices.push_back( 2+index/3);
Buffer.Indices.push_back( index/3);
Buffer.Indices.push_back( 1+index/3);
}
void init_points( float x, float y, float z)
{
//video::SColor color( 0, 255, 0, 0);
Buffer.Vertices.push_back( video::S3DVertex( x, y, .1+z, 1,1,0, video::SColor(255, 0,255,255), 0, 1));
Buffer.Vertices.push_back( video::S3DVertex( .1+x, y, z, 1,0,0, video::SColor(255,255, 0,255), 1, 1));
Buffer.Vertices.push_back( video::S3DVertex( x, y+.1, z, 0,1,1, video::SColor(255,255,255, 0), 1, 0));
Buffer.Vertices.push_back(video::S3DVertex( x, y, z, 0,0,1, video::SColor(255, 0,255, 0), 0, 0));
init_indices();
}
void render()
{
video::SMaterial material;
material.Wireframe = false;
material.Lighting = true;
material.BackfaceCulling = true;
material.DiffuseColor = irr::video::SColor( 255, 0, 0, 255);
material.SpecularColor = irr::video::SColor( 255, 0, 0, 255);
material.setTexture( 0, driver->getTexture("../../media/particlewhite.bmp") );
material.setFlag( irr::video::EMF_FOG_ENABLE, true);
material.NormalizeNormals = true;
driver->setMaterial( material);
driver->drawVertexPrimitiveList
(
Buffer.getVertices(),
Buffer.getVertexCount(),
Buffer.getIndices(),
Buffer.Indices.size()/3,
video::EVT_STANDARD,
irr::scene::EPT_TRIANGLES,
video::EIT_16BIT
);
}
int main()
{
EventReceiver receiver;
IrrlichtDevice *device = createDevice( irr::video::EDT_OPENGL,
irr::core::dimension2d< irr::u32>( 1024, 768),
16,
false,
false,
false,
&receiver);
if (device == 0)
return 1;
device->setWindowCaption(L"IRRLICHT");
driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
driver->setTextureCreationFlag( irr::video::ETCF_CREATE_MIP_MAPS, true);
for( float x = -5; x < 5; x+= .1)
for( float y = -5; y < 5; y+= .1)
init_points( x, y, 0);
std::cout<<"Buffer.getVertices(). "<<Buffer.getVertices();
std::cout<<", Buffer.getVertexCount(). "<<Buffer.getVertexCount();
std::cout<<", Buffer.getIndices(). "<<Buffer.getIndices();
std::cout<<", Buffer.Indices.size()/3. "<<Buffer.Indices.size()/3<<std::endl;
//
irr::scene::ISceneNode* node = 0;
irr::scene::ILightSceneNode* light_node = 0;
node = smgr->addEmptySceneNode( 0,-1);
light_node = smgr->addLightSceneNode();
light_node->setPosition( irr::core::vector3df(0,0,1));
irr::video::SLight & slight = light_node->getLightData();
slight.Type = irr::video::ELT_DIRECTIONAL;
//node->addChild( light_node);
light_node->setParent( node);
irr::scene::ISceneNodeAnimator* anim = 0;
///*
anim = smgr->createFlyCircleAnimator
(
irr::core::vector3df(0.0f, 0.0f, 0.0f),//center
15.f,//radius
0.001f,//speed
irr::core::vector3df(0.0f, 1.0f, 0.0f),//direction
0.0f,//start position
0.0f //radius ellipsoid
);
//*/
//anim = smgr->createRotationAnimator ( irr::core::vector3df(0.0f, 1.0f, 0.0f) );
node->addAnimator(anim);
anim->drop();
// attach billboard to light\
node = smgr->addBillboardSceneNode( node, irr::core::dimension2d<irr::f32>(1, 1));
node->setMaterialFlag( irr::video::EMF_LIGHTING, false);
node->setMaterialType( irr::video::EMT_TRANSPARENT_ADD_COLOR);
node->setMaterialTexture(0, driver->getTexture("../../media/particlewhite.bmp"));
//
irr::scene::ICameraSceneNode* cam = smgr->addCameraSceneNode();
cam->setTarget( core::vector3df(0,0,0));
cam->setPosition( core::vector3df(0,0,-25));
device->getCursorControl()->setVisible( false);
u32 frames=0;
while(device->run())
{
driver->beginScene( true, true, video::SColor( 0, 0, 0, 0));
render();
smgr->drawAll();
driver->endScene();
if (++frames==100)
{
core::stringw str = L"Irrlicht Engine [";
str += driver->getName();
str += L"] FPS: ";
str += (s32)driver->getFPS();
//pLight->setRotation( irr::core::vector3df( x_rot, 0, 0));
device->setWindowCaption(str.c_str());
frames=0;
}
//x_rot += 0.05f;
}
device->drop();
return 0;
}
Code: Select all
node->addChild( light_node);
light_node->setParent( node);