使用盖莫游戏引擎做的天空面例子(当然可以使用天空盒,天空顶)
代码如下:
1 #include <cstdlib>
2 #include <iostream>
3 #include <GEngine/Main.hpp>
4
5 using namespace std;
6
7 core::RefPtr<core::Image> skyimage[1];
8 core::RefPtr<core::Texture> skytexture[1];
9 core::RefPtr<core::Image> terrainimage[2];
10 core::RefPtr<core::Texture> terraintexture[2];
11
12 int main(int argc, char *argv[])
13 {
14 core::Device* device = core::InitDevice("盖莫引擎场景测试");
15
16 //! 获取资源管理器
17 core::ResourceManager *resourcemanager = device->GetResourceManager();
18
19 //! 获取场景管理器
20 core::RefPtr<core::SceneManager> scenemanager = core::SceneManager::GetSceneManager();
21
22 //! 获取新的摄像机并设置为活动摄像机
23 core::RefPtr<core::Camera> camera = scenemanager->CreateCamera("mycamera",
24 Vector3f(500,20,400),
25 Vector3f(503,20,400),
26 Vector3f(0,1,0));
27
28 //! 设置当前活动摄像机
29 scenemanager->SetActiveCamera(camera);
30
31 //! 获取天空面图形和纹理
32 skyimage[0] = resourcemanager->GetImage("sky_image","..\\image//sky//top.jpg");
33 skytexture[0] = resourcemanager->GetTexture("sky_texture",skyimage[0]);
34 core::RefPtr<core::SkyPlane> skyplane = scenemanager->GetSkyPlane(32,500,900,skytexture[0]);
35 skyplane->SetRotationStep(0.03f);
36
37 //! 设置地形数据
38 terrainimage[0] = resourcemanager->GetImage("terrain_image","..\\terrain//terrain.bmp");
39 terrainimage[1] = resourcemanager->GetImage("terrain_detail","..\\terrain//terrainflat.jpg");
40 terraintexture[0] = resourcemanager->GetTexture("terrain_texture1",terrainimage[0]);
41 terraintexture[1] = resourcemanager->GetTexture("terrain_texture2",terrainimage[1]);
42
43 core::RefPtr<core::Terrain> terrain = scenemanager->GetTerrain("terrain1");
44 bool flag = terrain->Load("..\\terrain//terrain2.raw",1024);
45 terrain->SetStepSize(16);
46 terrain->SetTexture(terraintexture[1],terraintexture[0]);
47
48 //! 设置摄像机数据
49 camera->SetViewport(0,0,640,480);
50 camera->SetPerspective(45,640.0f/480.0f,0.1f,1000);
51
52 //! 获取输入系统指针
53 core::Input* input = device->GetInput();
54
55 //! 获取雾指针
56 core::RefPtr<core::Fog> fog = scenemanager->GetFog();
57 fog->SetColor(core::Color(0.3f,0.3f,0.2f));
58 fog->SetDensity(0.001f);
59 fog->SetQuality(0.003f);
60 fog->SetBound(0.1f,1000.0f);
61 fog->Render();
62
63 BEGIN_LOOP(device)
64 camera->SetPerspective(45,640.0f/480.0f,0.1f,1000);
65 camera->Render();
66 skyplane->Render();
67 terrain->Render();
68 END_LOOP(device)
69
70 terrain->Deinit();
71
72 device->Close();
73 device->Drop();
74
75 system("PAUSE");
76 return EXIT_SUCCESS;
77 }
78
79
贴图如下:
![](http://www.cppblog.com/images/cppblog_com/gaimor/006.JPG)
编译:devc++,vc2003
如果对盖莫引擎感兴趣可以通过邮件和我联系
ccsdu2009@sohu.com