Code: Select all
#include "irrlicht.h"
#include <cstdlib>
#include <iostream>
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);
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;
}
void init_points( int x, int y, int z)
{
video::SColor color( 0, 255, 0, 0);
Buffer.Vertices.push_back( video::S3DVertex( x, y, 10+z, 1,1,0, video::SColor(255,0,255,255), 0, 1));
Buffer.Vertices.push_back( video::S3DVertex( 10+x, y, z, 1,0,0,video::SColor(255,255,0,255), 1, 1));
Buffer.Vertices.push_back( video::S3DVertex( x, y+10, 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("ice2.jpg") );
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);
irr::scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS( 0, 60.0f, 0.001f, -1, 0, 0, false, 0.0f, false, true);
cam->setTarget( core::vector3df(0,0,0));
cam->setPosition( core::vector3df(0,0,-15));
device->getCursorControl()->setVisible( false);
init_points( 0, 0, 0);
irr::scene::ILightSceneNode* light1 =
smgr->addLightSceneNode(0, irr::core::vector3df(0,0,-5),
irr::video::SColorf(0.0f, 0.0f, 1.0f, 1.0f), 100.0f);
irr::video::SLight light1_data;
light1_data.Direction = irr::core::vector3df(0,0,0);
light1_data.Type = irr::video::ELT_SPOT;
light1_data.AmbientColor = irr::video::SColorf(0.0f,1.0f,0.0f,1);
light1_data.SpecularColor = irr::video::SColorf(1.0f,0.0f,0.0f,1);//this doesn't work
light1_data.DiffuseColor = irr::video::SColorf(0.0f,0.0f,1.0f,1);//this doesn't work
light1_data.InnerCone = 0.0f;
light1_data.OuterCone = 10.0f;
light1_data.Falloff = 10.0f;
light1_data.Attenuation = irr::core::vector3df( 0.0f, 0.5f, 0.0f);
light1_data.CastShadows = false;
light1->setLightData( light1_data);
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();
device->setWindowCaption(str.c_str());
frames=0;
}
}
device->drop();
return 0;
}
I also wanted to ask about the two lines
Code: Select all
light1_data.SpecularColor = irr::video::SColorf(1.0f,0.0f,0.0f,1);//this doesn't work
light1_data.DiffuseColor = irr::video::SColorf(0.0f,0.0f,1.0f,1);//this doesn't work
I set them on line 83-84.
Code: Select all
material.DiffuseColor = irr::video::SColor( 255, 0, 0, 255);
material.SpecularColor = irr::video::SColor( 255, 0, 0, 255);