无论在何处在什么地方,我们都或多或少的接触到数学知识。特别是在客户端中,从打开界面的那一刻起就有太多与数学扯上的关联,如打开窗口的大小,窗口的位置,窗口里面的元件对象,以及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(), y() {}
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(), y(), z() {}
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为最后一个封装,是屏幕射线的结构,一个是起点坐标,一个是方向的坐标,两个坐标组成了一条线。学习过立体几何的都应该知道,在点与点之间这条直线自然就确定了一个方向。

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

MMORPG大型游戏设计与开发(客户端架构 part3 of vegine)的更多相关文章

  1. MMORPG大型游戏设计与开发(客户端架构 part8 of vegine)

    脚本模块是游戏设计中争论比较多的话题,那是因为作为脚本本身所带来的利弊.其实这都无关紧要,取舍是人必须学会的一项技能,如果你不会取舍那么就让趋势给你一个满意的答复.自从魔兽世界以及传奇(世界)问世以来 ...

  2. MMORPG大型游戏设计与开发(概述)updated

    1.定义 MMORPG,是英文Massive(或Massively)Multiplayer Online Role-PlayingGame的缩写,即大型多人在线角色扮演游戏. 2.技术与知识 在这系列 ...

  3. MMORPG大型游戏设计与开发(UI SYSTEM SHOW)

    接下来一段时间,这些文件可能不再更新,期间我会学习和掌握一些前端知识.虽然我非常欣赏剑侠网络版叁和九阴真经的画面,但是那是一个庞大的游戏引擎,一般人是无法窥伺的,除非你是天才而且要拥有机器毫无中断的毅 ...

  4. MMORPG大型游戏设计与开发(服务器 游戏场景 核心详述)

    核心这个词来的是多么的高深,可能我们也因为这个字眼望而却步,也就很难去掌握这部分的知识.之所以将核心放在最前面讲解,也可以看出它真的很重要,希望朋友们不会错过这个一直以来让大家不熟悉的知识,同我一起进 ...

  5. MMORPG大型游戏设计与开发(游戏服务器 游戏场景 概述 updated)

    我们在玩游戏的时候,我们进入游戏后第一眼往往都是看到游戏世界中的场景,当然除了个别例外,因为那些游戏将游戏场景隐藏了起来,如文字游戏中的地点一样.既然我们接触了游戏世界的核心,那么作为核心的场景又包括 ...

  6. MMORPG大型游戏设计与开发(客户端架构 part12 of vegine)

    在游戏中的交互过程中输入是一个必不可少的过程,比如登陆的时候需要用户输入用户名与密码,就算是单机游戏很多时候也要求用户输入一个用户名作为存档的依据.网络游戏中没有了输入,只用鼠标来交互是不切实际的,因 ...

  7. MMORPG大型游戏设计与开发(客户端架构 part2 of vgui)

    这一节我将讲解vgui的基础系统部分,也是该库提供给外部使用的一些重要接口.作为UI部分比较重要的部分,该节有着至关重要的部分,如果没有看到上一节内容,请留意下面的连接.我们现在可以猜想一下在客户端U ...

  8. MMORPG大型游戏设计与开发(客户端架构 part16 of vegine)

    由于近来比较忙碌和有些困倦的原因,所以关于这部分的文章没有及时更新,一句话:让朋友们久等了!今天所讲的是客户端vengine(微引擎)中最后一个部分,就像上节所说,这一部分的内容比较多.可能有些朋友看 ...

  9. MMORPG大型游戏设计与开发(客户端架构 part9 of vegine)

    时间在人们的生活中是多么重要的东西,如果打乱了时间,不知道这个时间会成什么样子.在客户端中,自然也有时间模块,因为不同的时间可能会处理不同的事情,特别是在追求高度自由化的同时,时间也成为了一个很重要的 ...

  10. MMORPG大型游戏设计与开发(客户端架构)

    首先为所有等待的朋友说一声歉意,实在让大家等的太久.客户端的设计本来就是一个大的工程,而且工作的关系,也没有太多时间在这方面做研究.不过在私下有空的时间,我还是继续着这方面的研究,很遗憾没有用期望的o ...

随机推荐

  1. sql搜索数据库中具有某列的表

    在接口中明明有某个节点,但在数据库中却找不到,为此本人写了一个sql,以供快速查找. Select distinct syscolumns.name,sysobjects.name from sysc ...

  2. swift学习笔记之-方法部分

    //方法部分 import UIKit //方法(Methods) /*方法是与某些特定类型相关联的函数,类.结构体.枚举都可以定义实例方法 实例方法(Instance Methods): 1.属于某 ...

  3. 移动端图片滚动加载-lazyload实现的要点总结

    最近在做移动端的营销页面时,遇到了页面有大量图片的情况,于是很自然的想到了要使用图片lazyload,PC端用着jQuery,也有现成的插件.但是在移动端,基本不用jQuery,于是就试着自己去造一下 ...

  4. SAP查询事务、表属于哪个模块

    这个功能主要是在汇报SAP的产品问题时,让你知道该选择你所汇报的问题所哪个子模块的.它可以依据事务代码.表.程序名.域.数据元素来查找.     方法:SE38,执行报表程序:RSSTATUS .

  5. ArcCatalog中连接SDE数据库

    描述 在ArcCatalog采用直接的方式连接SDE数据库时,无论怎样填写连接参数,都连接不上(数据库管理工具和代码都可以连).主要报两类错误: Error:ORA-12154:TNS:无法解析指定的 ...

  6. 用SVG绕过浏览器XSS审计

    [Translated From]:http://insert-script.blogspot.com/2014/02/svg-fun-time-firefox-svg-vector.html === ...

  7. Hadoop出现 native snappy library not available: SnappyCompressor has not been loaded的解决办法

    我目前测试环境是Hadoop 2.7.1, 搭建群集之后经常出现错误“native snappy library not available: SnappyCompressor has not bee ...

  8. 【C语言】C语言外部变量和内部变量

    目录: [外部变量] · 定义 · 用extern修饰变量 [内部变量] · 定义 · 用static修饰变量 1.外部变量 · 定义 定义的变量能被本文件和其它文件访问的变量,称为外部变量. 注: ...

  9. socket编程中客户端常用函数 以及简单实现

    1 常用函数 1.1   connect() int connect(int sockfd, const struct sockaddr *servaddr, socklen_taddrlen); 客 ...

  10. GitHub Top 100 的项目(iOS)

    主要对当前 GitHub 排名前 100 的项目做一个简单的简介, 方便初学者快速了解到当前 Objective-C 在 GitHub 的情况. Android 版本的在此: https://gith ...