游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2649|回复: 1

使用盖莫游戏引擎绘制立方体

[复制链接]

50

主题

69

帖子

69

积分

注册会员

Rank: 2

积分
69
发表于 2010-3-3 15:15:00 | 显示全部楼层 |阅读模式
使用盖莫游戏引擎绘制立方体
这不是正式测试的demo例子
其存在的必要是为物理引擎Demo做准备的O(∩_∩)O~

//! 2010.03.03
/////////////////////////////////////////////////////
/// 盖莫游戏引擎的立方体绘制
/////////////////////////////////////////////////////  
//! 测试立方体绘制函数,矩阵,输入输出
//! 按键f1,f2,f3旋转立方体
#include <GEngine/Gaimo.hpp>
using namespace std;

Matrix4f mat;  

//! 处理鼠标响应
void MouseCheck(core::Input* input);   

int main(int argc, char **argv)
{
    //! 初始化引擎设备并得到设备指针
    core:evice* device = core::InitDevice("盖莫引擎立方体测试");
    //! 得到引擎场景指针
    core::RefPtr<core::SceneManager> scenemanager = device->GetSceneManager();
    //! 得到引擎资源指针
    core::ResourceManager* resourcemanager = device->GetResourceManager();

    //! 获取lua指针
    LuaPlus:uaStateOwner *lua = device->GetLuaStateOwner();
   
    //! 得到logo图形和其纹理
    core::RefPtr<core::Image>   logo = resourcemanager->GetImage("logo","..\\image//logo.jpg");
    core::RefPtr<core::Texture> logotexture = resourcemanager->GetTexture("logo",logo);
    logotexture->Bind();
   
    //! 获取全局摄像机
    core::RefPtr<core::Camera> camera = scenemanager->GetGlobalCamera(Vector3f(30,30,30),
                                                                      Vector3f(0,0,0),
                                                                      Vector3f(0,1,0));
    camera->SetViewport(0,0,640,480);  
    camera->SetPerspective(50.0f,640.0f/480.0f,0.1f,1000.0f);                                                                  
    glClearDepth(1.0f);                                            
    glDepthFunc(GL_LEQUAL);                                       
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);   
    glShadeModel(GL_SMOOTH);                                    
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);   

    float sides[] = {16,16,16};
    float pos[] = {0,0,0};
  
    BEGIN_LOOP(device)
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);            
       glLoadIdentity();
       core::Render::SetClearColor(core::Color::Blue);
       camera->SetPerspective(45.0f,640.0f/480.0f,0.1f,1000.0f);
       camera->Render();  
       MouseCheck(device->GetInput());               
       core::Render::RenderCube((int)logotexture->GetTextureId(),pos,mat.ptr(),sides);
    END_LOOP(device)
   
    device->Close();
    device->Drop();

    return 0;
}

//! 处理鼠标响应
void MouseCheck(core::Input* input)
{
    if(input->IsPressedKey(KEY_F1))
    {
        mat*=mat.Rotate((rand()%200)/900.0f,1,0,0);                     
    }
    else if(input->IsPressedKey(KEY_F2))
    {
        mat*=mat.Rotate((rand()%200)/900.0f,0,1,0);            
    }
    else if(input->IsPressedKey(KEY_F3))
    {
        mat*=mat.Rotate((rand()%200)/900.0f,0,0,1);           
    }  
}

显示如下:



50

主题

69

帖子

69

积分

注册会员

Rank: 2

积分
69
 楼主| 发表于 2010-3-3 15:17:00 | 显示全部楼层

Re:使用盖莫游戏引擎绘制立方体

在盖莫游戏引擎中我们大量使用了智能指针来避免内存的泄露
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-7-1 18:49

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表