• MMORPG大型游戏设计与开发(客户端架构 part3 of vegine)


    无论在何处在什么地方,我们都或多或少的接触到数学知识。特别是在客户端中,从打开界面的那一刻起就有太多与数学扯上的关联,如打开窗口的大小,窗口的位置,窗口里面的元件对象,以及UI的坐标等等。而在进入游戏之后,不仅有这些坐标,还有了世界的坐标,以及场景坐标,还有粒子对象的各种属性值。但为什么要扩展ogre的数学库呢?就让我们看看有哪些类型的吧。

    CODE

      文件math/base.h

    /**
     * PAP Engine ( -- )
     * $Id math.h
     * @link -- for the canonical source repository
     * @copyright Copyright (c) 2013-2014 viticm( viticm@126.com )
     * @license
     * @user viticm<viticm@126.com/viticm.ti@gmail.com>
     * @date 2014-3-12 11:15:08
     * @uses the base config macros and defines, also with system include
     */
    #ifndef VENGINE_MATH_BASE_H_
    #define VENGINE_MATH_BASE_H_
    
    #include "vengine/config.h"
    
    namespace vengine_math {
    
    namespace base {
    
    struct VENGINE_API twofloat_vector_t {
     public:
       inline twofloat_vector_t& operator = (const twofloat_vector_t& vector) {
         x = vector.x;
         y = vector.y;
         return *this;
       }
    
       inline bool operator == (const twofloat_vector_t& vector) const {
         return (x == vector.x && y == vector.y);
       }
    
       inline bool operator != (const twofloat_vector_t& vector) const {
         return ( x != vector.x || y != vector.y );
       }
    
       inline twofloat_vector_t operator + 
         (const twofloat_vector_t& vector) const {
         twofloat_vector_t sum;
         sum.x = x + vector.x;
         sum.y = y + vector.y;
         return sum;
       }
    
       inline twofloat_vector_t operator - 
         (const twofloat_vector_t& vector) const {
         twofloat_vector_t diff;
         diff.x = x - vector.x;
         diff.y = y - vector.y;
         return diff;
       }
    
       inline twofloat_vector_t operator * (float scalar ) const {
         twofloat_vector_t prod;
         prod.x = scalar * x;
         prod.y = scalar * y;
         return prod;
       }
    
       inline friend twofloat_vector_t operator * 
         (float scalar, const twofloat_vector_t& vector) {
         twofloat_vector_t prod;
         prod.x = scalar * vector.x;
         prod.y = scalar * vector.y;
         return prod;
       }
    
       inline float length() const;
       float normalise(float aimlength = 1.0f);
     public:
       twofloat_vector_t() : x(0.0f), y(0.0f) {}
       twofloat_vector_t(float _x, float _y) : x(_x), y(_y) {}
     public:
       float x; 
       float y;
    };
    
    //tow int32_t vector struct
    struct VENGINE_API twoint_vector_t {
     public:
       twoint_vector_t() : x(0), y(0) {}
       twoint_vector_t(int32_t _x, int32_t _y) : x(_x), y(_y) {}
     public:
       int32_t x; 
       int32_t y;
    };
    
    struct VENGINE_API threefloat_vector_t {
     public:
       inline threefloat_vector_t& operator = 
         (const threefloat_vector_t& vector) {
         x = vector.x;
         y = vector.y;
         z = vector.z;            
         return *this;
       }
    
       inline bool operator == ( const threefloat_vector_t& vector) const {
         return (x == vector.x && y == vector.y && z == vector.z);
       }
    
       inline bool operator != ( const threefloat_vector_t& vector ) const {
         return (x != vector.x || y != vector.y || z != vector.z);
       }
    
       inline threefloat_vector_t operator + 
         (const threefloat_vector_t& vector) const {
         threefloat_vector_t sum;
         sum.x = x + vector.x;
         sum.y = y + vector.y;
         sum.z = z + vector.z;
         return sum;
       }
    
       inline threefloat_vector_t operator - 
         (const threefloat_vector_t& vector) const {
         threefloat_vector_t diff;
         diff.x = x - vector.x;
         diff.y = y - vector.y;
         diff.z = z - vector.z;
         return diff;
       }
    
       inline threefloat_vector_t operator * (const float& mult) const {
         threefloat_vector_t vector;
         vector.x = x * mult;
         vector.y = y * mult;
         vector.z = z * mult;
         return vector;
       }
    
       inline float length() const;
    
       float normalise(float aimlength = 1.0f);
    
     public:
       threefloat_vector_t() : x(0.0f), y(0.0f), z(0.0f) {}
       threefloat_vector_t(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
     public:
       float x; 
       float y; 
       float z;
    };
    
    struct VENGINE_API threeint_vector_t {
     public:
       threeint_vector_t() : x(0), y(0), z(0) {}
       threeint_vector_t(int32_t _x, int32_t _y, int32_t _z) : 
         x(_x), y(_y), z(_z) {}
     public:
       int32_t x; 
       int32_t y; 
       int32_t z;
    };
    
    
    struct VENGINE_API floatray {
     public:
       threefloat_vector_t origin;
       threefloat_vector_t direction;
    };
    
    }; //namespace base
    
    }; //namespace vengine_math
    
    #endif //VENGINE_MATH_BASE_H_

    总结

      从上面的代码中不难看出,扩展的数学库将二维坐标、三维坐标,以整型与浮点的形式进行了结构体的封装,而这些正是在3D游戏中经常用到的各种坐标数据类型。floatray为最后一个封装,是屏幕射线的结构,一个是起点坐标,一个是方向的坐标,两个坐标组成了一条线。学习过立体几何的都应该知道,在点与点之间这条直线自然就确定了一个方向。

      这两节都讲的比较简单,接下来会讲一下客户端的性能接口模块,其实性能接口就是在引擎接口中实现了的,我们下节再说。

    作者:viticm 出处: http://www.cnblogs.com/lianyue/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。如果觉得还有帮助的话,可以点一下右下角的【推荐】,希望能够持续的为大家带来好的技术文章!想跟我一起进步么?那就【关注】我吧。
  • 相关阅读:
    tcp_wrapper过滤
    cobbler无人值守批量安装Linux系统
    PXE+kickstart无人值守安装CentOS 7
    kickstart文件详解
    SHELL脚本--shell数组基础
    SHELL脚本--管道和重定向基础
    第4章 DHCP服务
    第3章 NFS基本应用
    man sm-notify(sm-notify命令中文手册)
    man statd(rpc.statd中文手册)
  • 原文地址:https://www.cnblogs.com/lianyue/p/3884537.html
Copyright © 2020-2023  润新知