Code: Select all
ILightSceneNode* mySpotLight = smgr->addLightSceneNode();
mySpotLight->setPosition(vector3df(0.0f, 10.0f, 0.0f));
SLight spotLightData;
spotLightData.Type = ELT_SPOT;
spotLightData.DiffuseColor = SColor(255, 255, 0, 0);
spotLightData.OuterCone = 100;
spotLightData.InnerCone = 10;
mySpotLight->setLightData(spotLightData);
while(device->run())
{
mySpotLight->setRotation(vector3df(0.0f, 0.0f, 0.0f));
}
My code:
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(const SEvent& event)
{
if (event.EventType == EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
virtual bool IsKeyDown(EKEY_CODE keyCode) const
{
return KeyIsDown[keyCode];
}
MyEventReceiver()
{
for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
}
private:
bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
int main()
{
MyEventReceiver receiver;
IrrlichtDevice *device =
createDevice( EDT_OPENGL, dimension2d<u32>(640, 480), 16,
false, false, false, &receiver);
if (!device)
return 1;
device->setWindowCaption(L"CI2511 Assignment Part 1");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
camera->setPosition(vector3df(15.0,8.4,-59.6));
device->getCursorControl()->setVisible(false);
ISceneNode* node1=smgr ->addCubeSceneNode();
ISceneNode* node2=smgr ->addCubeSceneNode();
ISceneNode* node3=smgr ->addSphereSceneNode();
ISceneNode* node4=smgr ->addSphereSceneNode();
if(node1)
{
node1->setMaterialFlag(EMF_LIGHTING, true);
node1->setMaterialTexture(0, driver->getTexture("Bgtext.png"));
}
node1->setPosition(core::vector3df(0,0,0));
if(node2)
{
node2->setMaterialFlag(EMF_LIGHTING, true);
node2->setMaterialTexture(0, driver->getTexture("Bgtext.png"));
}
node2->setPosition(vector3df(20,20,0));
if(node3)
{
node3->setMaterialFlag(EMF_LIGHTING, true);
node3->setMaterialTexture(0, driver->getTexture("BgBtext.png"));
}
node3->setPosition(core::vector3df(0,15,0));
if(node4)
{
node4->setMaterialFlag(EMF_LIGHTING, true);
node4->setMaterialTexture(0, driver->getTexture("BgBtext.png"));
}
node4->setPosition(vector3df(20,35,0));
IAnimatedMeshSceneNode* anms =
smgr->addAnimatedMeshSceneNode(smgr->getMesh("ninja.b3d"));
if (anms)
{
ISceneNodeAnimator* anim =
smgr->createFlyStraightAnimator(vector3df(100,0,60),
vector3df(-100,0,60), 3500, true);
if (anim)
{
anms->addAnimator(anim);
anim->drop();
}
anms->setMaterialFlag(EMF_LIGHTING, true);
anms->setFrameLoop(0, 13);
anms->setAnimationSpeed(15);
anms->setScale(vector3df(2.f,2.f,2.f));
anms->setRotation(vector3df(0,-90,0));
anms->setMaterialTexture(0, driver->getTexture("sydney.bmp"));
}
IAnimatedMeshSceneNode* anms2 =
smgr->addAnimatedMeshSceneNode(smgr->getMesh("faerie.md2"));
if (anms2)
{
ISceneNodeAnimator* anim =
smgr->createFlyStraightAnimator(vector3df(0,0,130),
vector3df(200,100,130), 3500, true);
if (anim)
{
anms2->addAnimator(anim);
anim->drop();
}
anms2->setMaterialFlag(EMF_LIGHTING, true);
anms2->setFrameLoop(0, 13);
anms2->setAnimationSpeed(10);
anms2->setMD2Animation(EMAT_JUMP);
anms2->setScale(vector3df(2.f,2.f,2.f));
anms2->setRotation(vector3df(0,0,0));
anms2->setMaterialTexture(0, driver->getTexture("Faerie5.bmp"));
}
IAnimatedMeshSceneNode* anms3 =
smgr->addAnimatedMeshSceneNode(smgr->getMesh("dwarf.x"));
if (anms3)
{
ISceneNodeAnimator* anim =
smgr->createFlyStraightAnimator(vector3df(0,0,290),
vector3df(0,0,180), 3500, true);
if (anim)
{
anms3->addAnimator(anim);
anim->drop();
}
anms3->setMaterialFlag(EMF_LIGHTING, true);
anms3->setFrameLoop(0, 13);
anms3->setAnimationSpeed(8);
anms3->setMD2Animation(EMAT_STAND);
anms3->addShadowVolumeSceneNode();
anms3->setScale(vector3df(2.f,2.f,2.f));
anms3->setRotation(vector3df(0,0,0));
anms3->setMaterialTexture(0, driver->getTexture("dwarf.jpg"));
}
smgr->setShadowColor(SColor(150, 0, 0, 0));
smgr->setAmbientLight(SColor(100, 100, 100, 100));
ILightSceneNode* mySpotLight = smgr->addLightSceneNode();
mySpotLight->setPosition(vector3df(0.0f, 10.0f, 0.0f));
SLight spotLightData;
spotLightData.Type = ELT_SPOT;
spotLightData.DiffuseColor = SColor(255, 255, 0, 0);
spotLightData.OuterCone = 100;
spotLightData.InnerCone = 10;
mySpotLight->setLightData(spotLightData);
while(device->run())
{
mySpotLight->setRotation(vector3df(0.0f, 0.0f, 0.0f));
}
//ILightSceneNode* light1 = smgr->addLightSceneNode( 0, vector3df(0,400,-200), SColorf(0.3f,0.3f,0.3f), 1.0f, 1 );
wchar_t tmp[1000];
int lastFPS = -1;
u32 then = device->getTimer()->getTime();
const f32 MOVEMENT_SPEED = 5.f;
double i=0.5;
while(device->run())
{
const u32 now = device->getTimer()->getTime();
const f32 frameDeltaTime = (f32)(now - then) / 1000.f;
then = now;
vector3df nodePosition = node3->getPosition();
if(receiver.IsKeyDown(KEY_KEY_W))
nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(KEY_KEY_S))
nodePosition.Y -= MOVEMENT_SPEED * frameDeltaTime;
if(receiver.IsKeyDown(KEY_KEY_A))
nodePosition.X -= MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(KEY_KEY_D))
nodePosition.X += MOVEMENT_SPEED * frameDeltaTime;
node3->setPosition(nodePosition);
vector3df nodePosition2 = node4->getPosition();
if(receiver.IsKeyDown(KEY_KEY_1))
nodePosition2.Y += MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(KEY_KEY_2))
nodePosition2.Y -= MOVEMENT_SPEED * frameDeltaTime;
if(receiver.IsKeyDown(KEY_KEY_3))
nodePosition2.X -= MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(KEY_KEY_4))
nodePosition2.X += MOVEMENT_SPEED * frameDeltaTime;
node4->setPosition(nodePosition2);
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll();
/*int fps = driver->getFPS();
if (lastFPS != fps)
{
swprintf(tmp, 1000, L"(%3.1f,%3.1f,%3.1f)", camera->getTarget().X,
camera->getTarget().Y, camera->getTarget().Z);
device->setWindowCaption(tmp);
lastFPS = fps;
}
*/
node3->setRotation(vector3df(0,0,i));
node4->setRotation(vector3df(0,0,i));
i+= 0.2;
driver->endScene();
}
device->drop();
return 0;
}