Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
这是使用盖莫游戏引擎2.1.1做的简单球面映射
比较简单的不说什么
献上贴图:

再上代码
 1 using namespace std;
 2 using namespace core;
 3 
 4 int main(int argc, char **argv)
 5 {
 6     //! 初始化引擎设备并得到设备指针
 7     RefPtr<Device> device = core::InitDevice("球面映射");
 8     //! 得到引擎场景指针
 9     RefPtr<SceneManager> scenemanager = device->GetSceneManager();
10     //! 得到引擎资源指针
11     RefPtr<ResourceManager> resourcemanager = device->GetResourceManager();
12     //! 获取引擎纹理管理器指针
13     RefPtr<TextureManager> texturemanager = resourcemanager->GetTextureManager(); 
14     //! 获取引擎图形管理器
15     RefPtr<ImageManager>   imagemanager = resourcemanager->GetImageManager();
16     //! 获取引擎视频驱动器
17     RefPtr<VideoDriver>    videodriver = device->GetVideoDriver();
18     
19     //! 得到图形和其纹理
20     core::RefPtr<Image>   image1 = imagemanager->CreateObject("background","..\\image//spheremap//tree.jpg");
21     core::RefPtr<Texture> background = texturemanager->CreateObject("background",image1);
22      
23     core::RefPtr<Image>   image2 = imagemanager->CreateObject("reflect","..\\image//spheremap//tree1.jpg");
24     core::RefPtr<Texture> reflect = texturemanager->CreateSphereMap("reflect",image2);
25  
26     background->Generate(); 
27     reflect->Generate();
28 
29     //! 获取全局摄像机,设置摄像机参数 
30     core::RefPtr<core::Camera> camera = scenemanager->GetActiveCamera();
31     camera->SetPosition(Vector3f(0,0,30));
32     camera->SetView(Vector3f(0,0,0));
33     camera->SetDirection(Vector3f(0,1,0));
34     camera->SetViewPort(Recti(0,0,640,480));
35     camera->SetPerspective(50.0f,640.0f/480.0f,0.1f,1000.0f);
36     videodriver->EnableCulling();
37  
38     BEGIN_LOOP(device)
39        videodriver->SetClearBuffer(ENGINE_CLEAR_COLOR | ENGINE_CLEAR_DEPTH);
40        videodriver->SetClearColor(core::Color::Blue);
41        camera->Render();
42   
43        background->AttachRenderTarget();
44        glBegin(GL_QUADS);
45           glNormal3f( 0.0f0.0f1.0f);
46           glTexCoord2f(0.0f0.0f); glVertex3f(-13.0f-12.0f,  10.0f);
47           glTexCoord2f(1.0f0.0f); glVertex3f( 13.0f-12.0f,  10.0f);
48           glTexCoord2f(1.0f1.0f); glVertex3f( 13.0f,  12.0f,  10.0f);
49           glTexCoord2f(0.0f1.0f); glVertex3f(-13.0f,  12.0f,  10.0f);
50        glEnd();
51        
52        reflect->AttachRenderTarget();
53        videodriver->RenderSphere(12,32,32);
54        videodriver->RenderSphere(9,32,32);
55        videodriver->RenderSphere(6,32,32);
56        reflect->Destroy();
57     END_LOOP(device)
58 
59     return 0;
60 }

题外话:截止目前引擎支持2d纹理,球面映射和立方体纹理
其它相关的映射和纹理会陆续加入
posted on 2010-04-07 17:28 ccsdu2009 阅读(206) 评论(0)  编辑 收藏 引用 所属分类: Game引擎

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