鬼火(irrlicht)的复燃

    点此领取楼主。

    我说的“鬼火(irrlicht)“是一个开源的3D渲染引擎,基于C++开发。

    大概3年多以前第一次接触到irrlicht,那时候还有一个“食人魔(OGRE)”,也是基于C++的开源3D渲染引擎,二者之间我选择了前者。虽然OGRE拥有更强大的社区支持,并且拥有更加流畅的结构,但是对于初学者而言整个系统国语复杂(除非你坚持钻研下去直到豁然开朗的那一天,而我则只是浅尝辄止),所以我选择了相对简洁的鬼火引擎。

    大概有半个月的时间零散的学习了irrlicht的一些demo,最后自己仿照官方例程改写了一个完整的3d演示程序,所有数据未做更改。

    期间还附带地学习了irrklang音频处理引擎,与irrlicht啊呸使用相得益彰,irrlicht用于video渲染,irrklang用于audio输出,完美!

    之后诸多杂事(或者只是懒惰的借口?)以至于将此学习搁置一旁,如今重拾,似乎又找回了当初的那种感觉。






























程序结构

App.cpp:

WinMain()

{

new Game();  //SimpleGame.cpp

Game->Run(); //

return;

}


SimpleGame的声明

//
#ifndef __SIMPLEGAME_H_INCLUDED__
#define __SIMPLEGAME_H_INCLUDED__

#include <windows.h>

// Irrlicht dependencies
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib,"irrlicht.lib")

// IrrKlang audio support
#include <irrKlang.h>	
using namespace irrklang;
#pragma comment (lib, "irrKlang.lib")

typedef struct particleImpact
{
	u32 when;
	vector3df pos;
	vector3df outVector;
} SParticleImpact;

namespace Parameters
{
	namespace FullScreen
	{
		enum State
		{
			On = 1,
			Off = 2
		};
	}

	namespace BufferedShadow
	{
		enum State
		{
			On = 1,
			Off = 2
		};
	}

	namespace VerticalSync
	{
		enum State
		{
			On = 1,
			Off = 2
		};
	}

	namespace AntiAlias
	{
		enum State
		{
			On = 1,
			Off = 2
		};
	}

	namespace PlayMusic
	{
		enum State
		{
			On = 1,
			Off = 2
		};
	}
}

using namespace Parameters;

class Size
{
public:
	Size(int w, int h);
	int Width();
	int Height();
private:
	int width;
	int height;
};

class Game :public IEventReceiver
{
public:
	const int CAMERA_COUNT=7;
	Game(E_DRIVER_TYPE driverType, Size resolution,  FullScreen::State full, BufferedShadow::State shadow, 
	             VerticalSync::State vsync, AntiAlias::State anti, PlayMusic::State music);
	void SetBkMusic(char* pszMusicFile);
	~Game();
	void Run();
	virtual bool OnEvent(const SEvent& evt);
private:
	void CreateLoadingScreen();
	void LoadSceneData();
	void SwitchToNextScene();
	void Shoot();
	void CreateParticleImpacts();

	SIrrlichtCreationParameters params;
	IrrlichtDevice* irrDevice;
	IVideoDriver*  videoDriver;
	ISceneManager* sceneMgr;
	IGUIEnvironment* guiEnv;
	IFileSystem* fileSys;
	ITimer*  timer;

	PlayMusic::State playMusic;
	ISoundEngine* sndEngine;
	ISound* bkMusic;
	ISoundSource* ballSound;
	ISoundSource* impactSound;

	int currentScene;
	SColor bgColor;

	IGUIStaticText* statusText;
	IGUIInOutFader* inOutFader;

	IQ3LevelMesh* quakeLevelMesh;
	ISceneNode* quakeLevelNode;
	ISceneNode* skyboxNode;
	IAnimatedMeshSceneNode* model1;
	IAnimatedMeshSceneNode* model2;
	IParticleSystemSceneNode* campFire;

	IMetaTriangleSelector* metaSelector;
	ITriangleSelector* mapSelector;

	s32 sceneStartTime;
	s32 timeForThisScene;

	array<SParticleImpact> Impacts;
};

#endif


SimpleGame的实现

#include "SimpleGame.h"

Size::Size(int w, int h)
{
	width = w;
	height = h;
}

int Size::Width()
{
	return width;
}

int Size::Height()
{
	return height;
}

Game::Game(E_DRIVER_TYPE driverType, Size resolution, FullScreen::State full,
                            BufferedShadow::State shadow, VerticalSync::State vsync, 
							 AntiAlias::State anti, PlayMusic::State music)
{
	params.DriverType = driverType;
	u32 w = resolution.Width();
	u32 h = resolution.Height();
	if (driverType == EDT_SOF
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值