Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
当然是使用盖莫游戏引擎啦。
代码如下:
 
 1 代码如下:
 2 
 3 #include <GEngine/Gaimo.hpp>
 4 #include <iostream>
 5 using namespace std;
 6 
 7 int main(int argc, char **argv)
 8 {
 9     //! 初始化引擎设备并得到设备指针
10     core::Device* device = core::InitDevice("盖莫引擎室外场景测试1");
11     //! 得到引擎场景指针
12     core::RefPtr<core::SceneManager> scenemanager = device->GetSceneManager();
13     //! 得到引擎资源指针
14     core::ResourceManager* resourcemanager = device->GetResourceManager();
15 
16     //! 获取lua指针
17     LuaPlus::LuaStateOwner *lua = device->GetLuaStateOwner();
18     //! 载入lua脚本
19     (*lua)->DoFile("..\\script//skybox.lua");
20     //! 获取天空盒表对象
21     LuaPlus::LuaObject skyboxtable = (*lua)->GetGlobal("skybox");
22    
23     //! 得到天空盒图形和其纹理
24     core::RefPtr<core::Image>   skyimage0 = resourcemanager->GetImage("sky1",skyboxtable["front"].GetString());
25     core::RefPtr<core::Image>   skyimage1 = resourcemanager->GetImage("sky2",skyboxtable["back"].GetString());
26     core::RefPtr<core::Image>   skyimage2 = resourcemanager->GetImage("sky3",skyboxtable["left"].GetString());
27     core::RefPtr<core::Image>   skyimage3 = resourcemanager->GetImage("sky4",skyboxtable["right"].GetString());
28     core::RefPtr<core::Image>   skyimage4 = resourcemanager->GetImage("sky5",skyboxtable["top"].GetString());   
29     core::RefPtr<core::Texture> sky0 = resourcemanager->GetTexture("front",skyimage0);
30     core::RefPtr<core::Texture> sky1 = resourcemanager->GetTexture("back",skyimage1);
31     core::RefPtr<core::Texture> sky2 = resourcemanager->GetTexture("left",skyimage2);
32     core::RefPtr<core::Texture> sky3 = resourcemanager->GetTexture("right",skyimage3);
33     core::RefPtr<core::Texture> sky4 = resourcemanager->GetTexture("top",skyimage4);
34 
35     //! 得到天空盒指针
36     core::RefPtr<core::Renderable> skybox = scenemanager->GetSkyBox(sky0,sky1,sky2,sky3,sky4,
37                                                                     skyboxtable["width"].GetFloat(),
38                                                                     skyboxtable["length"].GetFloat(),
39                                                                     skyboxtable["heigth"].GetFloat()
40                                                                     ,skyboxtable["rotstep"].GetFloat());     
41     //! 载入lua脚本
42     (*lua)->DoFile("..\\script//terrain.lua");  
43     //! 获取地形表对象
44     LuaPlus::LuaObject terraintable = (*lua)->GetGlobal("terrain");
45 
46     //! 得到地形图形和其纹理
47     core::RefPtr<core::Image>   terrainimage0 = resourcemanager->GetImage("terrain0",terraintable["image1"].GetString());
48     core::RefPtr<core::Image>   terrainimage1 = resourcemanager->GetImage("terrain1",terraintable["image2"].GetString());
49     core::RefPtr<core::Texture> terraintexture0 = resourcemanager->GetTexture("terraim0",terrainimage0);
50     core::RefPtr<core::Texture> terraintexture1 = resourcemanager->GetTexture("terraim1",terrainimage1);     
51    
52     //! 创建地形描述符
53     core::TerrainDesc desc;
54     desc.main_texture = terraintexture0;
55     desc.detail_texture = terraintexture1;
56     desc.use_detail = terraintable["usedetail"].GetInteger();
57    
58     //! 获取地形指针
59     core::RefPtr<core::Terrain> terrain = scenemanager->GetTerrain(desc);
60     terrain->LoadHeigthMap(terraintable["rawfile"].GetString(),terraintable["mapsize"].GetInteger(),terraintable["cell"].GetInteger());
61 
62     //! 获取全局摄像机
63     core::RefPtr<core::Camera> camera = scenemanager->GetGlobalCamera(Vector3f(250,terrain->GetHeight(250,215)+10,215),
64                                                                       Vector3f(251,terrain->GetHeight(251,216)+10,216),
65                                                                       Vector3f(0,1,0));
66     camera->SetViewport(0,0,640,480);  
67     camera->SetPerspective(50.0f,640.0f/480.0f,0.1f,1000.0f);                                                                  
68     glClearDepth(1.0f);                                            
69     glDepthFunc(GL_LEQUAL);                                       
70     glEnable(GL_DEPTH_TEST);
71     glEnable(GL_CULL_FACE);   
72     glShadeModel(GL_SMOOTH);                                    
73     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);     
74     BEGIN_LOOP(device)
75        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);            
76        glLoadIdentity();
77        camera->SetPerspective(45.0f,640.0f/480.0f,0.1f,1000.0f);
78        camera->Render();   
79        skybox->Render();
80        terrain->Render();
81     END_LOOP(device)
82    
83     device->Close();
84     device->Drop();
85 
86     return 0;
87 }
2个lua配置文件
1.
-- 这是盖莫引擎中使用lua脚本配置天空盒的脚本
 1 -- 定义天空盒数据
 2 skybox =
 3 {
 4    front  = "..\\image//sky//front.jpg";
 5    back   = "..\\image//sky//back.jpg";
 6    left   = "..\\image//sky//left.jpg";
 7    right  = "..\\image//sky//right.jpg";
 8    top    = "..\\image//sky//top.jpg";   
 9    width  = 600;
10    length = 600;
11    heigth = 600;
12    rotstep= 0.003;   
13 }
2.
 1 -- 这是盖莫引擎中使用lua脚本配置地形的脚本
 2 
 3 -- 定义地形数据
 4 terrain =
 5 {
 6    rawfile   = "..\\terrain//terrain.raw";
 7    image1    = "..\\terrain//terrain.bmp";
 8    image2    = "..\\terrain//detail.bmp";
 9    usedetail = 1;
10    mapsize   = 1024;
11    cell      = 16
12 }
这里使用了简单的lua表数据结构
当然这个还会不断改进的
posted on 2010-03-03 09:09 ccsdu2009 阅读(211) 评论(2)  编辑 收藏 引用 所属分类: Game引擎
Comments

只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理