/** Example 001 HelloWorld
This Tutorial shows how to set up the IDE for using the Irrlicht Engine and how
to write a simple HelloWorld program with it. The program will show how to use
the basics of the VideoDriver, the GUIEnvironment, and the SceneManager.
Microsoft Visual Studio is used as an IDE, but you will also be able to
understand everything if you are using a different one or even another
operating system than windows.
You have to include the header file <irrlicht.h> in order to use the engine. The
header file can be found in the Irrlicht Engine SDK directory \c include. To let
the compiler find this header file, the directory where it is located has to be
specified. This is different for every IDE and compiler you use. Let's explain
shortly how to do this in Microsoft Visual Studio:
- If you use Version 6.0, select the Menu Extras -> Options.
Select the directories tab, and select the 'Include' Item in the combo box.
Add the \c include directory of the irrlicht engine folder to the list of
directories. Now the compiler will find the Irrlicht.h header file. We also
need the irrlicht.lib to be found, so stay in that dialog, select 'Libraries'
in the combo box and add the \c lib/VisualStudio directory.
\image html "vc6optionsdir.jpg"
\image latex "vc6optionsdir.jpg"
\image html "vc6include.jpg"
\image latex "vc6include.jpg"
- If your IDE is Visual Studio .NET, select Tools -> Options.
Select the projects entry and then select VC++ directories. Select 'show
directories for include files' in the combo box, and add the \c include
directory of the irrlicht engine folder to the list of directories. Now the
compiler will find the Irrlicht.h header file. We also need the irrlicht.lib
to be found, so stay in that dialog, select 'show directories for Library
files' and add the \c lib/VisualStudio directory.
\image html "vcnetinclude.jpg"
\image latex "vcnetinclude.jpg"
That's it. With your IDE set up like this, you will now be able to develop
applications with the Irrlicht Engine.
Lets start!
After we have set up the IDE, the compiler will know where to find the Irrlicht
Engine header files so we can include it now in our code.
*/
#include <irrlicht.h>
/*
In the Irrlicht Engine, everything can be found in the namespace 'irr'. So if
you want to use a class of the engine, you have to write irr:: before the name
of the class. For example to use the IrrlichtDevice write: irr::IrrlichtDevice.
To get rid of the irr:: in front of the name of every class, we tell the
compiler that we use that namespace from now on, and we will not have to write
irr:: anymore.
*/
using namespace irr;
/*
There are 5 sub namespaces in the Irrlicht Engine. Take a look at them, you can
read a detailed description of them in the documentation by clicking on the top
menu item 'Namespace List' or by using this link:
http://irrlicht.sourceforge.net/docu/namespaces.html
Like the irr namespace, we do not want these 5 sub namespaces now, to keep this
example simple. Hence, we tell the compiler again that we do not want always to
write their names.
*/
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
/*
To be able to use the Irrlicht.DLL file, we need to link with the Irrlicht.lib.
We could set this option in the project settings, but to make it easy, we use a
pragma comment lib for VisualStudio. On Windows platforms, we have to get rid
of the console window, which pops up when starting a program with main(). This
is done by the second pragma. We could also use the WinMain method, though
losing platform independence then.
*/
#ifdef _IRR_WINDOWS_
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
enum
{
// I use this ISceneNode ID to indicate a scene node that is
// not pickable by getSceneNodeAndCollisionPointFromRay()
ID_IsNotPickable = 0,
// I use this flag in ISceneNode IDs to indicate that the
// scene node can be picked by ray selection.
IDFlag_IsPickable = 1 << 0,
// I use this flag in ISceneNode IDs to indicate that the
// scene node can be highlighted. In this example, the
// homonids can be highlighted, but the level mesh can't.
IDFlag_IsHighlightable = 1 << 1
};
//事件接受类
class MyEventReceiver : public IEventReceiver
{
public:
// This is the one method that we have to implement
virtual bool OnEvent(const SEvent& event)
{
// Remember whether each key is down or up
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
// This is used to check whether a key is being held down
//这个方法是用来检验哪一个键被按下
virtual bool IsKeyDown(EKEY_CODE keyCode) const
{
return KeyIsDown[keyCode];
}
virtual bool
MyEventReceiver()
{
for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
}
private:
// We use this array to store the current state of each key
//利用此数组来存储每个键的当前状态
bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
//主函数main()
int main()
{
//创建一个设备
IrrlichtDevice *device=createDevice(video::EDT_OPENGL,core::dimension2d<u32>(640,480),32,false,false,false,0);
//如果创建不成功
if(!device)
{
return 1;
}
//获取食品设备,场景管理器,用户环境指针并存储起来
IVideoDriver *driver=device->getVideoDriver();
ISceneManager *smgr=device->getSceneManager();
IGUIEnvironment *guienv=device->getGUIEnvironment();
//读取模型并显示它
ITexture *image=driver->getTexture("../../media/detailmap3.jpg");
ITexture *imp1=driver->getTexture("../../media/imp1.jpg");
ITexture *imp2=driver->getTexture("../../media/imp2.jpg");
//IAnimatedMesh *mesh=smgr->getMesh("../../media/detailmap3.jpg");
//如果读取不成功
//if (!mesh)
//{
// device->drop();
// return 1;
// }
//IAnimatedMeshSceneNode *node=smgr->addAnimatedMeshSceneNode(mesh);
//对模型图片进行属性设置,贴纹理等操作
// if(node)
// {
// node->setMaterialFlag(EMF_LIGHTING,false);
// // node->setMD2Animation(scene::EMAT_STAND);
// // node->setMaterialTexture(0,driver->getTexture("../../media/sydney.bmp"));
// }
// smgr->addCameraSceneNode(0,vector3df(50,20,50),vector3df(10,10,10));
scene::IAnimatedMeshSceneNode* node = 0;
scene::IAnimatedMeshSceneNode* anms =
smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/ninja.b3d"));
if (anms)
{
scene::ISceneNodeAnimator* anim =
smgr->createFlyStraightAnimator(core::vector3df(100,0,60),
core::vector3df(-100,0,60), 3500, true);
if (anim)
{
anms->addAnimator(anim);
anim->drop();
}
/*
To make the model look right we disable lighting, set the
frames between which the animation should loop, rotate the
model around 180 degrees, and adjust the animation speed and
the texture. To set the right animation (frames and speed), we
would also be able to just call
"anms->setMD2Animation(scene::EMAT_RUN)" for the 'run'
animation instead of "setFrameLoop" and "setAnimationSpeed",
but this only works with MD2 animations, and so you know how to
start other animations. But a good advice is to not use
hardcoded frame-numbers...
*/
anms->setMaterialFlag(video::EMF_LIGHTING, false);
anms->setFrameLoop(0, 13);
anms->setAnimationSpeed(15);
// anms->setMD2Animation(scene::EMAT_RUN);
anms->setScale(core::vector3df(2.f,2.f,2.f));
anms->setRotation(core::vector3df(0,-90,0));
// anms->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp"));
}
smgr->addCameraSceneNodeFPS();
device->getCursorControl()->setVisible(false);
//添加一个2D场景节点
//IAnimatedMesh *m=smgr->getMesh("../../media/imp1.jpg");
//IAnimatedM
没有合适的资源?快使用搜索试试~ 我知道了~
irrlicht的helloworld
共29个文件
vcproj:3个
pdb:2个
gif:2个
3星 · 超过75%的资源 需积分: 10 9 下载量 146 浏览量
2011-09-29
17:41:52
上传
评论
收藏 2.07MB RAR 举报
温馨提示
irrlicht的2D操作,只是很简单的载入一个2D图片,然后利用wsad四个键进行操作,简单的使用键盘输入方法
资源推荐
资源详情
资源评论
收起资源包目录
01.HelloWorld.rar (29个子文件)
01.HelloWorld
HelloWorld_vc9.vcproj 5KB
HelloWorld_vc9.ncb 6.5MB
HelloWorld.dev 991B
HelloWorld_vc8.vcproj.8.00.old 5KB
UpgradeLog.XML 2KB
HelloWorld_vc9.vcproj.MICROSOF-C8E151.Administrator.user 1KB
_UpgradeReport_Files
UpgradeReport.xslt 12KB
UpgradeReport_Minus.gif 69B
UpgradeReport.css 3KB
UpgradeReport_Plus.gif 71B
HelloWorld_vc8.ncb 1.09MB
tutorial.html 23KB
ve-191.tmp 8KB
HelloWorld_vc9.suo 24KB
main.cpp 10KB
HelloWorld_vc8.vcproj 5KB
Makefile 2KB
HelloWorld.sln 909B
HelloWorld.layout 137B
HelloWorld.vcproj 4KB
Debug
BuildLog.htm 7KB
01.HelloWorld.exe.intermediate.manifest 381B
vc90.pdb 460KB
main.obj 98KB
vc90.idb 275KB
mt.dep 67B
HelloWorld.pdb 2.25MB
HelloWorld.cbp 2KB
HelloWorld_vc9.sln 896B
共 29 条
- 1
资源评论
- AirSup2012-12-15代码如果更简单一点就好了!!
linxiangpeng2008
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功