Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿

以前早就看过了如何使用opengl绘制3ds静态对象的材料
现在总把这个加入到引擎里面了
具体代码如下:

 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 int main(int argc, char *argv[])
13 {   
14     Device *device = InitDevice("盖莫引擎天空盒测试");
15     device->SetClearColor(core::Color(80,90,255));
16    
17     //! 获取场景管理器 
18     RefPtr<SceneManager> scenemanager = SceneManager::GetSceneManager(); 
19                                                                  
20     //! 获取资源管理器 
21     ResourceManager* resourcemanager = device->GetResourceManager();
22     //! 获取天空图片资源
23     //! 获取天空图形指针 
24     skyimage[0= resourcemanager->GetImage("sky_front","..\\image//sky//front.jpg");
25     skyimage[1= resourcemanager->GetImage("sky_back","..\\image//sky//back.jpg");
26     skyimage[2= resourcemanager->GetImage("sky_left","..\\image//sky//left.jpg");
27     skyimage[3= resourcemanager->GetImage("sky_right","..\\image//sky//right.jpg");
28     skyimage[4= resourcemanager->GetImage("sky_top","..\\image//sky//top.bmp");
29   
30     skytexture[0= resourcemanager->GetTexture("sky_front",skyimage[0]);
31     skytexture[1= resourcemanager->GetTexture("sky_back",skyimage[1]);        
32     skytexture[2= resourcemanager->GetTexture("sky_left",skyimage[2]);
33     skytexture[3= resourcemanager->GetTexture("sky_right",skyimage[3]);   
34     skytexture[4= resourcemanager->GetTexture("sky_top",skyimage[4]); 
35     //! 获取天空盒指针
36     RefPtr<SceneNode> skybox = scenemanager->GetSkyBox(NULL,skytexture[0],skytexture[1],skytexture[2],skytexture[3],skytexture[4],500,500,600);  
37     
38     //! 设置地形数据
39     terrainimage[0= resourcemanager->GetImage("terrain_image","..\\terrain//terrain.bmp");
40     terrainimage[1= resourcemanager->GetImage("terrain_detail","..\\terrain//detail.bmp");
41     terraintexture[0= resourcemanager->GetTexture("terrain_texture1",terrainimage[0]);
42     terraintexture[1= resourcemanager->GetTexture("terrain_texture2",terrainimage[1]);
43     RefPtr<Terrain>  terrain = scenemanager->GetTerrain(NULL,"..\\terrain//terrain.raw",1024,terraintexture[0],terraintexture[1]); 
44   
45     int height = terrain->GetHeight(440,370);
46     height += 20;
47     //! 获取新的摄像机并设置为活动摄像机
48     RefPtr<Camera> camera = scenemanager->CreateCamera("mycamera", Vector3f(10,height,10),
49                                                                    Vector3f(440,height - 40,370),
50                                                                    Vector3f(0,1,0));
51     //! 设置当前活动摄像机 
52     scenemanager->SetActiveCamera(camera);
53     camera->SetViewport(0,0,640,480);  
54     
55     //! 雾设置
56     RefPtr<Fog> fog = scenemanager->GetFog();
57     fog->SetColor(core::Color(0.5f,0.5f,0.1f));
58     fog->SetDensity(0.001f);
59     fog->SetQuality(0.003f);
60     fog->SetBound(0.5f,1000.0f);
61     fog->Render();
62     
63     RefPtr<Model3D> model = scenemanager->GetStaticModel("3dsmodel");
64     model->Load("digger.3ds");
65     //model->SetScale(Vector3f(125,125,125));
66     model->SetTranslate(Vector3f(512,terrain->GetHeight(512,512),512));
67     
68     BEGIN_LOOP(device);
69         camera->SetPerspective(45,640.0f/480.0f,6.0f,1000);
70         camera->Render();
71         skybox->Render();
72         model->Render();
73         static float angle = 0.0f;      
74         skybox->SetRotate(core::AXIS_Z,angle);
75         terrain->Render();
76         angle+=0.000001;
77         if(angle>360)
78            angle-=360;
79     END_LOOP(device);
80     
81     device->Close();
82     device->Drop();
83     
84     system("PAUSE");
85     return EXIT_SUCCESS;
86 }
87 
88 
这里设计的操作静态模型的相关主要函数有
加载模型,模型平移旋转缩放处理
具体的贴图如下:

只是模型的颜色不太对,看来需要调整下其rbg次序
再换一个人物模型:
代码:
 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 int main(int argc, char *argv[])
13 {   
14     Device *device = InitDevice("盖莫引擎天空盒测试");
15     device->SetClearColor(core::Color(80,90,255));
16    
17     //! 获取场景管理器 
18     RefPtr<SceneManager> scenemanager = SceneManager::GetSceneManager(); 
19                                                                  
20     //! 获取资源管理器 
21     ResourceManager* resourcemanager = device->GetResourceManager();
22     //! 获取天空图片资源
23     //! 获取天空图形指针 
24     skyimage[0= resourcemanager->GetImage("sky_front","..\\image//sky//front.jpg");
25     skyimage[1= resourcemanager->GetImage("sky_back","..\\image//sky//back.jpg");
26     skyimage[2= resourcemanager->GetImage("sky_left","..\\image//sky//left.jpg");
27     skyimage[3= resourcemanager->GetImage("sky_right","..\\image//sky//right.jpg");
28     skyimage[4= resourcemanager->GetImage("sky_top","..\\image//sky//top.bmp");
29   
30     skytexture[0= resourcemanager->GetTexture("sky_front",skyimage[0]);
31     skytexture[1= resourcemanager->GetTexture("sky_back",skyimage[1]);        
32     skytexture[2= resourcemanager->GetTexture("sky_left",skyimage[2]);
33     skytexture[3= resourcemanager->GetTexture("sky_right",skyimage[3]);   
34     skytexture[4= resourcemanager->GetTexture("sky_top",skyimage[4]); 
35     //! 获取天空盒指针
36     RefPtr<SceneNode> skybox = scenemanager->GetSkyBox(NULL,skytexture[0],skytexture[1],skytexture[2],skytexture[3],skytexture[4],500,500,600);  
37     
38     //! 设置地形数据
39     terrainimage[0= resourcemanager->GetImage("terrain_image","..\\terrain//terrain.bmp");
40     terrainimage[1= resourcemanager->GetImage("terrain_detail","..\\terrain//detail.bmp");
41     terraintexture[0= resourcemanager->GetTexture("terrain_texture1",terrainimage[0]);
42     terraintexture[1= resourcemanager->GetTexture("terrain_texture2",terrainimage[1]);
43     RefPtr<Terrain>  terrain = scenemanager->GetTerrain(NULL,"..\\terrain//terrain.raw",1024,terraintexture[0],terraintexture[1]); 
44   
45     int height = terrain->GetHeight(440,370);
46     height += 40;
47     //! 获取新的摄像机并设置为活动摄像机
48     RefPtr<Camera> camera = scenemanager->CreateCamera("mycamera", Vector3f(10,height,10),
49                                                                    Vector3f(440,height - 30,370),
50                                                                    Vector3f(0,1,0));
51     //! 设置当前活动摄像机 
52     scenemanager->SetActiveCamera(camera);
53     camera->SetViewport(0,0,640,480);  
54     
55     //! 雾设置
56     RefPtr<Fog> fog = scenemanager->GetFog();
57     fog->SetColor(core::Color(0.3f,0.5f,0.2f));
58     fog->SetDensity(0.0012f);
59     fog->SetQuality(0.004f);
60     fog->SetBound(0.2f,1000.0f);
61     fog->Render();
62     
63     RefPtr<Model3D> model = scenemanager->GetStaticModel("3dsmodel");
64     model->Load("model.3ds");
65     model->SetScale(Vector3f(125,125,125));
66     model->SetTranslate(Vector3f(510,terrain->GetHeight(512,512),512));
67     
68     BEGIN_LOOP(device);
69         camera->SetPerspective(45,640.0f/480.0f,6.0f,1000);
70         camera->Render();
71         skybox->Render();
72         model->Render();
73         static float angle = 0.0f;      
74         skybox->SetRotate(core::AXIS_Z,angle);
75         terrain->Render();
76         angle+=0.000003;
77         if(angle>360)
78            angle-=360;
79     END_LOOP(device);
80     
81     device->Close();
82     device->Drop();
83     
84     system("PAUSE");
85     return EXIT_SUCCESS;
86 }
87 
88 

贴图:

需要注意的是由于模型大小不一致故需要调整模型大小
 
posted on 2010-02-09 17:27 ccsdu2009 阅读(1193) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理