@Franck and Mike: in case you may need any extra stuff: (ps. be careful if you get compiling errors, they will be due to the fact I'm using "My3d" files so you would need the "My3d" source and header as well. Just check the part of the bool keys (for esc):
Code: Select all
//Afecelis-Irrlicht SplitScreen-Example compiling with MSVC toolkit 2003 + the Relo IDE
//Copyright © 2004 Alvaro F. Celis "afecelis"
//Based on Max Winkel's splitscreen tutorial
//Using Zdimitor's My3d format and loader
//Music from the Gasoline demo by RECREATION : 'GASOLINE 2' : 2001, composed by Spector
/* The Irrlicht Engine License
Copyright © 2002-2003 Nikolaus Gebhardt
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications,
and to alter it and redistribute it freely, subject to the following restrictions:
1.The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2.Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3.This notice may not be removed or altered from any source distribution.*/
//-----------------------------------------------------------------------------------------------//
//headers
#include <irrlicht.h>
#include <audiere.h>
#include <iostream>
#include <stdio.h>
#include <wchar.h>
#include <windows.h>
#include "CMY3DMeshFileLoader.h"
//-----------------------------------------------------------------------------------------------//
//Namespaces for the engine
using namespace irr;
using namespace audiere;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
#pragma comment (lib, "audiere.lib")
ILogger* logger=NULL;
ICameraSceneNode *MayaCam, *NormalCam;
//-----------------------------------------------------------------------------------------------//
//Resolution
#define ResX 800
#define ResY 600
#define fullScreen false
//-----------------------------------------------------------------------------------------------//
//Use SplitScreen-cameras-wireframe?
//bool fullScreen = false;
bool SplitScreen = true;
bool Mayacam = false;
bool Normalcam = false;
bool WireFrame = false;
bool progDeath = false;
bool dark = false;
bool fog = false;
bool particles = false;
//-----------------------------------------------------------------------------------------------//
//cameras
ICameraSceneNode *camera[4] = {0,0,0,0};
//-----------------------------------------------------------------------------------------------//
//added by jox: to make it available in the event receiver
IrrlichtDevice *device;
//-----------------------------------------------------------------------------------------------//
//Eventreceiver
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
//Esc to quit
if (event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown){
switch(event.KeyInput.Key){
case KEY_ESCAPE:{
return progDeath = true;
}break;
}
return false;
}
//Key P enables/disables Particles
if (event.KeyInput.Key == KEY_KEY_P && event.KeyInput.PressedDown)
{
particles = !particles;
return true;
}
//Key S enables/disables SplitScreen
if (event.KeyInput.Key == KEY_KEY_S && event.KeyInput.PressedDown)
{
SplitScreen = !SplitScreen;
return true;
}
//Key M enables Maya camera
if (event.KeyInput.Key == KEY_KEY_M && event.KeyInput.PressedDown)
{
camera[3] = MayaCam;
// jox: make cursor visible
device->getCursorControl()->setVisible(true);
return true;
}
//Key N enables fps cam
if (event.KeyInput.Key == KEY_KEY_N && event.KeyInput.PressedDown)
{
camera[3] = NormalCam;
// jox: make cursor invisible
device->getCursorControl()->setVisible(false);
return true;
}
//Key W enables WireFrame
if (event.KeyInput.Key == KEY_KEY_W && event.KeyInput.PressedDown)
{
WireFrame = !WireFrame;
return true;
}
//Key L enables light
if (event.KeyInput.Key == KEY_KEY_L && event.KeyInput.PressedDown)
{
dark = !dark;
return true;
}
//Key F enables fog
if (event.KeyInput.Key == KEY_KEY_F && event.KeyInput.PressedDown)
{
fog = !fog;
return true;
}
//Send all other events to camera4
if (camera[3])
camera[3]->OnEvent(event);
return false;
}
};
//-----------------------------------------------------------------------------------------------//
//main function
int main()
{
//Instance of the EventReceiver
MyEventReceiver receiver;
//-----------------------------------------------------------------------------------------------//
//Initialize the engine
device = createDevice(EDT_OPENGL,dimension2d<s32>(ResX,ResY),32,fullScreen,true,false,&receiver);
ISceneManager* smgr = device->getSceneManager();
IVideoDriver* driver = device->getVideoDriver();
io::IFileSystem* fs = device->getFileSystem();
logger = device->getLogger();
driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
//-----------------------------------------------------------------------------------------------//
//initialize audio
AudioDevicePtr audiereDevice;
OutputStreamPtr stream;
audiereDevice = OpenDevice();
if (!audiereDevice)
return 1;
stream = OpenSound(audiereDevice.get(), "./data/murikka.mp3", true);
if (!stream)
return 2;
stream->setRepeat(true);
stream->setVolume(1.0f); // 50% volume
stream->play();
//-----------------------------------------------------------------------------------------------//
//add 3d model
scene::IAnimatedMesh* sydneymesh = 0;
sydneymesh = smgr->getMesh("./data/sydney.md2");
smgr->getMeshManipulator()->makePlanarTextureMapping(sydneymesh->getMesh(0), 0.008f);
scene::IAnimatedMeshSceneNode* sydneynode = 0;
sydneynode = smgr->addAnimatedMeshSceneNode(sydneymesh);
sydneynode->setScale(vector3df(8,8,8));
sydneynode->setPosition(core::vector3df(0,200,0));//1st=pos in x2nd=pos in y 3rd=pos in z
sydneynode->setRotation(core::vector3df(0,0,0));
sydneynode->setMaterialTexture(0, driver->getTexture("./data/sydney.bmp"));
sydneynode->setMaterialFlag(video::EMF_LIGHTING, true);
sydneynode->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR); //makes it transparent
sydneynode->getMaterial(0).EmissiveColor.set(0,0,255,0); //makes it emissive
sydneynode->addShadowVolumeSceneNode();
smgr->setShadowColor(video::SColor(220,0,0,0));
//-----------------------------------------------------------------------------------------------//
//rotate animator for sydney
scene::ISceneNodeAnimator* sydneyanim = 0;
sydneyanim = smgr->createRotationAnimator(core::vector3df(0, -1, 0));
sydneynode->addAnimator(sydneyanim);
sydneyanim->drop();
//-----------------------------------------------------------------------------------------------//
//load room model using Zdimitor's My3d format and loader
scene::IMeshLoader* my3dloader = 0;
my3dloader = new scene::CMY3DMeshFileLoader(fs,driver,smgr);
smgr->addExternalMeshLoader(my3dloader);
scene::IAnimatedMesh* mesh3d = 0;
mesh3d = smgr->getMesh("./data/ind.my3d");
scene::ISceneNode* meshnode = 0;
meshnode = smgr->addOctTreeSceneNode(mesh3d->getMesh(0));
meshnode->setMaterialFlag(video::EMF_LIGHTING, false);
//meshnode->setMaterialFlag(video::EMF_WIREFRAME,true);
//meshnode->setMaterialType(video::EMT_SPHERE_MAP);
//meshnode->setMaterialType(video::EMT_LIGHTMAP_LIGHTING); //bsp affected by dynamic lights
//meshnode->setMaterialType(video::EMT_SOLID); //shows only bsp
meshnode->setScale( irr::core::vector3df(5,5,5));
meshnode->setRotation( irr::core::vector3df(0,0,0));
//meshnode->setMaterialFlag(EMF_FOG_ENABLE,true); //enables fog
//driver->setFog(SColor(0,0,125,0),true, 0,4000); //fog color-final values= amount of fog, distance
//-----------------------------------------------------------------------------------------------//
// create particle system
scene::IParticleSystemSceneNode* ps = 0;
ps = smgr->addParticleSystemSceneNode(false);
ps->setMaterialFlag(video::EMF_LIGHTING, false);
ps->setPosition(core::vector3df(-100,550,250));
ps->setScale(core::vector3df(5,5,5));
ps->setParticleSize(core::dimension2d<f32>(20,20));
ps->setMaterialTexture(0, driver->getTexture("./sprites/particle_white.bmp"));
ps->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
scene::IParticleEmitter* emb = 0;
emb = ps->createBoxEmitter(core::aabbox3d<f32>(-7.00f,0.00f,-7.00f,7.00f,1.00f,7.00f),
core::vector3df(0.00f,0.03f,0.00f),100,250,
video::SColor(0,0,255,100),
video::SColor(0,255,255,100),1000,2000,0);
ps->setEmitter(emb);
emb->drop();
scene::IParticleAffector* paf = 0;
paf = ps->createFadeOutParticleAffector(video::SColor(0,0,0,0),1000);
ps->addAffector(paf);
paf->drop();
scene::IParticleAffector* pgaf = 0;
pgaf = ps->createGravityAffector(core::vector3df(0.15f,0.11f,0.00f),1000);
ps->addAffector(pgaf);
pgaf->drop();
//___________________________________________________________________________________________________//
// create light with animator
scene::ILightSceneNode* lightnode = 0;
lightnode = smgr->addLightSceneNode(0, core::vector3df(0,0,0),
video::SColorf(1.0f, 0.6f, 0.7f, 1.0f), 700.0f);
scene::ISceneNodeAnimator* lightanim = 0;
lightanim = smgr->createFlyCircleAnimator (core::vector3df(0,450,0),250.0f);//sets position as well
lightnode->addAnimator(lightanim);
lightanim->drop();
//___________________________________________________________________________________________________//
// attach billboard to light
scene::IBillboardSceneNode* lightbill = 0;
lightbill = smgr->addBillboardSceneNode(lightnode, core::dimension2d<f32>(150, 150));
lightbill->setMaterialFlag(video::EMF_LIGHTING, false);
lightbill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
lightbill->setMaterialTexture(0, driver->getTexture("./sprites/23.bmp"));
//lightbill->setPosition(core::vector3df(-200,70,-70));
//-----------------------------------------------------------------------------------------------//
//Create 3 fixed and one user-controlled cameras
//Front
camera[0] = smgr->addCameraSceneNode(0,vector3df(500,200,0),vector3df(0,0,0));
camera[0]->setTarget(core::vector3df(0,200,0));
//Top
camera[1] = smgr->addCameraSceneNode(0,vector3df(0,700,0),vector3df(0,0,0));
//Left
camera[2] = smgr->addCameraSceneNode(0,vector3df(0,250,500),vector3df(0,0,0));
//User-controlled
camera[3] = smgr->addCameraSceneNodeFPS();
camera[3]->setPosition(core::vector3df(-2000,200,0));
camera[3]->setRotation(core::vector3df(0,90,0));
camera[3]->setFarValue (50000.0f) ;
camera[3]->setFOV(1.1f);
camera[3]->setTarget(core::vector3df(-2000,200,0));
//-----------------------------------------------------------------------------------------------//
//Hide mouse
device->getCursorControl()->setVisible(false);
//-----------------------------------------------------------------------------------------------//
//select image-color for transparency
video::ITexture* images = driver->getTexture("./data/2dbkg.bmp");
driver->makeColorKeyTexture(images, core::position2d<s32>(0,0));
//-----------------------------------------------------------------------------------------------//
//We want to count the fps
int lastFPS = -1;
// jox: adjusted the settings a bit:
MayaCam = smgr->addCameraSceneNodeMaya(0, -500.0f, 2000.0f, 1000.0f);
MayaCam->setFarValue (50000.0f) ;
NormalCam = smgr->addCameraSceneNodeFPS();
NormalCam->setPosition(core::vector3df(-2000,200,0));
NormalCam->setRotation(core::vector3df(0,90,0));
NormalCam->setFarValue (50000.0f);
NormalCam->setFOV(1.1f);
NormalCam->setTarget(core::vector3df(-2000,200,0));
progDeath = false;
dark = false;
fog = true;
particles = true;
//While....
while(device->run())
{
//Set the viewpoint to the whole screen and begin scene
driver->setViewPort(rect<s32>(0,0,ResX,ResY));
driver->beginScene(true,true,SColor(0,90,90,90));//0,r,g,b
//-----------------------------------------------------------------------------------------------//
//If SplitScreen is used
if (SplitScreen)
{
//-----------------------------------------------------------------------------------------------//
//Activate camera1
smgr->setActiveCamera(camera[0]);
//Set viewpoint to the first quarter (left top)
driver->setViewPort(rect<s32>(0,0,ResX/2,ResY/2));
//Draw scene
smgr->drawAll();
//-----------------------------------------------------------------------------------------------//
// draw logo
driver->draw2DImage(images, core::position2d<s32>(650,550),
core::rect<s32>(323,87,442,118));
//-----------------------------------------------------------------------------------------------//
//Activate camera2
smgr->setActiveCamera(camera[1]);
//Set viewpoint to the second quarter (right top)
driver->setViewPort(rect<s32>(ResX/2,0,ResX,ResY/2));
//Draw scene
smgr->drawAll();
//-----------------------------------------------------------------------------------------------//
// draw logo
driver->draw2DImage(images, core::position2d<s32>(650,550),
core::rect<s32>(323,87,442,118));
//-----------------------------------------------------------------------------------------------//
//Activate camera3
smgr->setActiveCamera(camera[2]);
//Set viewpoint to the third quarter (left bottom)
driver->setViewPort(rect<s32>(0,ResY/2,ResX/2,ResY));
//Draw scene
smgr->drawAll();
//-----------------------------------------------------------------------------------------------//
// draw logo
driver->draw2DImage(images, core::position2d<s32>(650,550),
core::rect<s32>(323,87,442,118));
//-----------------------------------------------------------------------------------------------//
//Set viewport the last quarter (right bottom)
driver->setViewPort(rect<s32>(ResX/2,ResY/2,ResX,ResY));
}
//-----------------------------------------------------------------------------------------------//
//Activate camera4
smgr->setActiveCamera(camera[3]);
//Draw scene
smgr->drawAll();
//-----------------------------------------------------------------------------------------------//
// draw logo
driver->draw2DImage(images, core::position2d<s32>(650,550),
core::rect<s32>(323,87,442,118));
//-----------------------------------------------------------------------------------------------//
// end scene
driver->endScene();
//-----------------------------------------------------------------------------------------------//
//If Maya is used
if (Mayacam)
//maya cam
camera[3] = MayaCam;
//-----------------------------------------------------------------------------------------------//
//If Normalcam is used
if (Normalcam)
//Normalcam
camera[3] = NormalCam;
//-----------------------------------------------------------------------------------------------//
//Render in wireframe
meshnode->setMaterialFlag(video::EMF_WIREFRAME,WireFrame);
sydneynode->setMaterialFlag(video::EMF_WIREFRAME,WireFrame);
//-----------------------------------------------------------------------------------------------//
// Light on/off
meshnode->setMaterialFlag(video::EMF_LIGHTING, dark);
//-----------------------------------------------------------------------------------------------//
// fog on/off
meshnode->setMaterialFlag(video::EMF_FOG_ENABLE, fog);
driver->setFog(SColor(0,0,125,0),true, 0,4000);
//-----------------------------------------------------------------------------------------------//
// particles on/off
ps->setVisible(particles);
//-----------------------------------------------------------------------------------------------//
// If Esc is used
if(progDeath)
{
device->closeDevice();
}
//-----------------------------------------------------------------------------------------------//
//Get and show fps
if (driver->getFPS() != lastFPS)
{
lastFPS = driver->getFPS();
wchar_t tmp[1024];
swprintf(tmp,1024,L"Afecelis-Splitscreen Demo (FPS: %d)",lastFPS);
device->setWindowCaption(tmp);
}
}
//-----------------------------------------------------------------------------------------------//
//Delete device
device->drop();
return 0;
}