Mmorgp large-scale game design and development (client architecture Part3 of vegine)

Source: Internet
Author: User

Wherever we are, we are more or less exposed to mathematical knowledge. Especially on the client, there are too many associations with mathematics from the moment the interface is opened, such as the size of the window opened, the position of the window, and the component objects in the window, and UI coordinates. After entering the game, there are not only these coordinates, but also the coordinates of the world, as well as the scene coordinates, as well as various attribute values of particle objects. But why do we need to expand the Ogre Math Library? Let's see what types are available.

Code

File math/base. h

/** * PAP Engine ( -- ) * $Id math.h * @link -- for the canonical source repository * @copyright Copyright (c) 2013-2014 viticm( [email protected] ) * @license * @user viticm<[email protected]/[email protected]> * @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 structstruct 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_

 

Summary

From the code above, it is not difficult to see that the extended Math Library encapsulates two-dimensional and three-dimensional coordinates in the form of integer and floating point structures, these are the various coordinate data types that are often used in 3D games. Floatray is the last encapsulation of the screen ray structure. One is the starting point coordinate, the other is the direction coordinate, and the two coordinates form a line. If you have learned ry, you should know that the straight line between a point naturally determines a direction.

The two sections are simple. Next we will talk about the performance interface module of the client. In fact, the performance interface is implemented in the engine interface. Let's talk about it in the next section.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.