游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2685|回复: 0

[转载]ReferenceAppLayer笔记(一)

[复制链接]

14

主题

96

帖子

124

积分

注册会员

Rank: 2

积分
124
QQ
发表于 2007-2-6 09:42:00 | 显示全部楼层 |阅读模式
来源:http://www.blog.edu.cn/user1/4750/archives/2004/8635.shtml

首先说明一下ReferenceAppLayer的用途,它在Sample中被用于BSPCollision,用于连接物理引擎(ODE)。它是以一个动态连接库的方式工作
的。
首先进入ReferenceApplication目录中打开其中的.sln文件,为了分析方便,首先打开ReferenceAppLayer.h文件,发现里面只是include了本
工程中其他的.h文件,所以转向分析其他的文件,那个球的文件中包含了两个头文件,一个是OGRERefApplicationObject.h,另一个是OGRERefA
ppPrerequisites.h。而OGRERefApplicationObject.h又包含了OGRERefAppPrerequisites.h,所以先从OGRERefAppPrerequisites.h入手。

程序源码如下:
//OGRERefAppPrerequisites.h
#ifndef __REFAPP_PREREQUISITES_H__
#define __REFAPP_PREREQUISITES_H__

// 包含ODE标准C头文件
#i nclude <ode/ode.h>
// 包含ODE C++头文件
#i nclude <ode/odecpp.h>
#i nclude <ode/odecpp_collision.h>

// 包含主面向应用的OGRE头文件
#i nclude <Ogre.h>


// To save us some typing
using namespace Ogre;

namespace OgreRefApp {

    #if OGRE_PLATFORM == PLATFORM_WIN32
    // 导出控制
    #   if defined( REFERENCEAPPLAYER_EXPORTS )
    #       define _OgreRefAppExport __declspec( dllexport )
    #   else
    #       define _OgreRefAppExport __declspec( dllimport )
    #   endif
    #else // Linux / Mac OSX etc
    #   define _OgreRefAppExport
    #endif

    // Quick conversions
    inline void OgreToOde(const Matrix3& ogre, dMatrix3& ode)
    {
        ode[0] = ogre[0][0];
        ode[1] = ogre[0][1];
        ode[2] = ogre[0][2];
        ode[3] = ogre[0][3];
        ode[4] = ogre[1][0];
        ode[5] = ogre[1][1];
        ode[6] = ogre[1][2];
        ode[7] = ogre[1][3];
        ode[8] = ogre[2][0];
        ode[9] = ogre[2][1];
        ode[10] = ogre[2][2];
        ode[11] = ogre[2][3];
    }


    // 向前定义类来减少依赖
    class ApplicationObject;
    class OgreHead;
    class FinitePlane;
    class Ball;
    class Box;
    class CollideCamera;

}



#endif

可以看出,这个头文件的作用就是做一些基本的连接工作和设置,自己实际应用的时候需要修改的也就是下面的镶嵌定义类部分。现在基本明
白了怎么样用OGRE引用ODE了,而且基本明白了一些DLL的使用。
感觉OGRERefApplicationObject.h没有太多看的必要,里面涉及了很多物理方面的东西,看起来很累,且把它当作封装好的模块来用吧。
下面来看一下OGRERefAppBall.h,应该比较有代表性。

#ifndef __REFAPP_BALL_H__
#define __REFAPP_BALL_H__

#i nclude "OgreRefAppPrerequisites.h"
#i nclude "OgreRefAppApplicationObject.h"

namespace OgreRefApp {

    class _OgreRefAppExport Ball : public ApplicationObject
    {
    protected:
        Real mRadius;
        void setUp(const String& name);
    public:
        Ball(const String& name, Real radius);
        ~Ball();

    };


}

#endif

这里只给出了一个结构,主要的直径、柔软度等内容都是在.CPP中设定的。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2026-1-26 10:40

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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