刚改造了以前做的盖莫游戏引擎渲染md2的代码.
对于md2模型来说
一个模型由若干动画组成
一个动画由若干帧构成
每个动画都有自己的名字
具体渲染的时候是对帧做插值的
具体测试例子如下:
1 #include <cstdlib>
2 #include <iostream>
3 #include <GEngine/Main.hpp>
4
5 using namespace std;
6 using namespace core;
7 core::RefPtr<core::Image> skyimage[5];
8 core::RefPtr<core::Texture> skytexture[5];
9 core::RefPtr<core::Image> terrainimage[2];
10 core::RefPtr<core::Texture> terraintexture[2];
11
12
13 int main(int argc, char *argv[])
14 {
15 Device *device = InitDevice("盖莫引擎md2模型测试");
16 device->SetClearColor(core::Color(80,90,255));
17
18 //! 获取场景管理器
19 RefPtr<SceneManager> scenemanager = SceneManager::GetSceneManager();
20
21 //! 获取资源管理器
22 ResourceManager* resourcemanager = device->GetResourceManager();
23 //! 获取天空图片资源
24 //! 获取天空图形指针
25 skyimage[0] = resourcemanager->GetImage("sky_front","..\\image//sky//front.jpg");
26 skyimage[1] = resourcemanager->GetImage("sky_back","..\\image//sky//back.jpg");
27 skyimage[2] = resourcemanager->GetImage("sky_left","..\\image//sky//left.jpg");
28 skyimage[3] = resourcemanager->GetImage("sky_right","..\\image//sky//right.jpg");
29 skyimage[4] = resourcemanager->GetImage("sky_top","..\\image//sky//top.bmp");
30
31 skytexture[0] = resourcemanager->GetTexture("sky_front",skyimage[0]);
32 skytexture[1] = resourcemanager->GetTexture("sky_back",skyimage[1]);
33 skytexture[2] = resourcemanager->GetTexture("sky_left",skyimage[2]);
34 skytexture[3] = resourcemanager->GetTexture("sky_right",skyimage[3]);
35 skytexture[4] = resourcemanager->GetTexture("sky_top",skyimage[4]);
36 //! 获取天空盒指针
37 RefPtr<SceneNode> skybox = scenemanager->GetSkyBox(NULL,skytexture[0],skytexture[1],skytexture[2],skytexture[3],skytexture[4],500,500,600);
38
39 //! 设置地形数据
40 terrainimage[0] = resourcemanager->GetImage("terrain_image","..\\terrain//terrain.bmp");
41 terrainimage[1] = resourcemanager->GetImage("terrain_detail","..\\terrain//detail.bmp");
42 terraintexture[0] = resourcemanager->GetTexture("terrain_texture1",terrainimage[0]);
43 terraintexture[1] = resourcemanager->GetTexture("terrain_texture2",terrainimage[1]);
44 RefPtr<Terrain> terrain = scenemanager->GetTerrain(NULL,"..\\terrain//terrain.raw",1024,terraintexture[0],terraintexture[1]);
45
46 int height = terrain->GetHeight(440,370);
47 height += 40;
48 //! 获取新的摄像机并设置为活动摄像机
49 RefPtr<Camera> camera = scenemanager->CreateCamera("mycamera", Vector3f(10,height,10),
50 Vector3f(512,height - 30,512),
51 Vector3f(0,1,0));
52 //! 设置当前活动摄像机
53 scenemanager->SetActiveCamera(camera);
54 camera->SetViewport(0,0,640,480);
55
56 //! 雾设置
57 RefPtr<Fog> fog = scenemanager->GetFog();
58 fog->SetColor(core::Color(0.3f,0.5f,0.2f));
59 fog->SetDensity(0.0012f);
60 fog->SetQuality(0.004f);
61 fog->SetBound(0.2f,1000.0f);
62 fog->Render();
63
64 RefPtr<ActiveModel3D> model = scenemanager->GetActiveModel("md2model");
65 model->Load("..\\model\\hobgoblin.md2");
66 RefPtr<Image> md2image = resourcemanager->GetImage("md2image","..\\model//hobgoblin.bmp");
67 RefPtr<Texture> md2texture = resourcemanager->GetTexture("md2texture",md2image);
68 model->LoadTexture(md2texture);
69 model->SetTranslate(Vector3f(180,10+terrain->GetHeight(112,512),180));
70
71 std::vector<AnimationFrame> frames;
72 model->GetFrameList(frames);
73
74 BEGIN_LOOP(device);
75 camera->SetPerspective(45,640.0f/480.0f,6.0f,1000);
76 camera->Render();
77 skybox->Render();
78 terrain->Render();
79 model->Render();
80 static int begin_frame = 0;
81 static int end_frame = begin_frame+1;;
82 static float t = 0.0f;
83 t+=0.02;
84 if(t>1)
85 {
86 t = 0;
87 end_frame++;
88 begin_frame++;
89 }
90 if(begin_frame == frames.back().frame_end)
91 end_frame = begin_frame = 0;
92 model->SetCurrentFrame(begin_frame,end_frame,t);
93
94 static float angle = 0.0f;
95 skybox->SetRotate(core::AXIS_Z,angle);
96
97 angle+=0.000003;
98 if(angle>360)
99 angle-=360;
100 END_LOOP(device);
101
102 device->Close();
103 device->Drop();
104
105 system("PAUSE");
106 return EXIT_SUCCESS;
107 }
108
109
贴图如下:这里的模型是源于opengl游戏开发一书
再来一个Opengl3d游戏开发中士兵的模型例子如下(当然我拿走了他的枪):
我会先让引擎具备常见的功能
之后我就会考虑加入引擎自己的亮点和消除引擎存在的Bug
当然了各类编辑器的设计也是迟早的了
再来一个机器人的md2模型