cs sdk v 1.14 released

Home  |  Product  |  Documents  |  Tutorials  |  FAQ |   Download  |   Forum |   Contacts  |   Link  


  Cross Suit

 Cross Suit SDK

 Documents
      classes
 Starting...
           Tutorials

 LUA tutorials

   Support

  Forum
  q&a

 Product parts

 Virtual File system

 Virtual Render
 Virtual Machine
   

  Demo Games

   

 3D Engine

  gvSystem(dx9)

 Link

 

 

gv_types.h

Go to the documentation of this file.
00001 #pragma once
00002 //
00003 //
00004 #ifndef __GV_TYPES_H__
00005 #define __GV_TYPES_H__
00006 
00007 #define true 1
00008 #define false 0
00009 #define g_PI    ((float)  3.141592654f)
00010 #define g_2_PI  g_PI*2.0f
00011 #define max(a,b)    (((a) > (b)) ? (a) : (b))
00012 #define min(a,b)    (((a) < (b)) ? (a) : (b))
00013 #define DEGREE(v)       (float)(v*180.0f/g_PI)
00014 #define RADIAN(v)       (float)((float)v*g_PI/180.0f)
00015 #undef NULL
00016 #define NULL            0x00
00017 //--------------------------------------------------------------------------*/
00018 
00023 
00024 typedef unsigned char           u8;
00025 typedef signed char                     s8;
00026 typedef char                            c8;
00027 typedef unsigned short          u16;
00028 typedef signed short            s16;
00029 //#ifndef u32
00030 //typedef unsigned int          u32;
00031 //#endif
00032 typedef signed int                      s32;
00033 typedef float                           f32;
00034 typedef double                          f64;
00035 
00036 typedef unsigned long           ULONG;
00037 typedef unsigned short          WORD;
00038 typedef unsigned int            UINT;
00039 
00040 //#ifndef max
00041 //inline bool max(float a,float b) {  return          (((a) > (b)) ? (a) : (b)); };
00042 //#endif
00043 
00044 //#ifndef min
00045 //inline bool min(float a,float b)     { return        (((a) < (b)) ? (a) : (b)); };
00046 //#endif
00047 // from irrlicht
00048 //
00049 
00050 void* appMalloc(unsigned long count, const char *Tag=0x00);
00051 void* appCalloc(unsigned long count, int value=0, const char *Tag=0x00);
00052 void appFree(void* mem );
00053 void *appRealloc(void* mem, unsigned long count, const char *Tag=0x00);
00054 
00055 
00056 //
00057 //
00058 //
00059 // C++ style memory allocation.
00060 //
00061 #include <stdio.h>
00062 #include <stdlib.h>
00063 #include <math.h>
00064 #ifndef _WIN32
00065 #include <sys/time.h>
00066 #endif
00067 //
00068 
00069 //
00070 //#if !defined(_MemoryLeak_Defined_)
00071 //
00072 
00073 void* operator new( unsigned int size,const char *file,int line);
00074 void operator delete(void* pMem, const char *file,int line);
00075 
00076 void* operator new(unsigned int size);
00077 void operator delete(void* ptr);
00078 
00079 void* operator new[](unsigned int size,const char *file,int line);
00080 void operator delete[](void* ptr);
00081 void operator delete[](void* pMem, const char *file,int line);
00082 
00083 #define new new(__FILE__,__LINE__)
00084 
00085 //
00086 // from irrlicht ..
00087 //
00088 class _iclass_
00089 {
00090 public:
00091 
00093         _iclass_()
00094                 : ReferenceCounter(1), DebugName(0)
00095         {
00096         }
00097 
00099         virtual ~_iclass_()
00100         {
00101         }
00102         void grab() { ++ReferenceCounter; }
00103         bool drop()
00104         {
00105                 //assert(ReferenceCounter <= 0) // someone is doing bad reference counting.
00106                 --ReferenceCounter;
00107                 if (!ReferenceCounter)
00108                 {
00109                         delete this;
00110                         return true;
00111                 }
00112                 return false;
00113         }
00114         const char* getDebugName() const
00115         {
00116                 return DebugName;
00117         }
00118 protected:
00119         void setDebugName(const char* newName)
00120         {
00121                 DebugName = newName;
00122         }
00123         //
00124 private:
00125         int     ReferenceCounter;
00126         const char* DebugName;
00127 };
00128 
00129 //
00130 //
00131 // Memory allocator.
00132 //
00133 class IAlloc
00134 {
00135 private:
00136         
00137 public:
00138         // Ãß°¡.
00139         virtual ~IAlloc(void) {};
00140         //
00141         virtual void Init(){};
00142         virtual void Shut(){};
00143         virtual unsigned long Alloc( unsigned long count, const char *Tag ){return 0;};
00144         virtual void * Malloc(unsigned long count, const char* Tag ){return 0;};
00145         virtual void * Realloc( void *mem, unsigned long count, const char* Tag ){return 0;};
00146         virtual void Free( void *mem ){};
00147         virtual void DumpAllocs(){};
00148         virtual void HeapCheck(){};
00149 };
00150 
00151 
00152 
00153 class TSimpleAlloc : public IAlloc
00154 {
00155 private:
00156         int allocations;
00157 
00158 public:
00159         virtual void Init();
00160         virtual void Shut();
00161         virtual unsigned long Alloc( unsigned long count, const char *Tag );
00162         virtual void * Malloc( unsigned long count, const char *Tag );
00163         virtual void * Realloc( void* mem, unsigned long count, const char *Tag );
00164         virtual void Free( void* mem );
00165         virtual void DumpAllocs();
00166         virtual void HeapCheck();
00167         TSimpleAlloc(void);
00168         ~TSimpleAlloc(void);
00169 };
00170 
00171 
00172 
00173 #include <assert.h>
00174 //##ModelId=42E34E8603s4D
00175 
00176 class vertex3
00177 {
00178 public:
00179 #if !defined(EMBEDED_LINUX)
00180 #pragma warning(push)
00181 #pragma warning (disable : 4201)
00182 #endif
00183         union {
00184         float x;
00185         float u;
00186         float r;
00187         };
00188         union {
00189         float y;
00190         float v;
00191         float g;
00192         };
00193         union {
00194         float z;
00195         float q;
00196         float b;
00197         };
00198 #if !defined(EMBEDED_LINUX)     
00199 #pragma warning(pop)
00200 #endif
00201         vertex3(float a,float b,float c);
00202         vertex3(float* pos);
00203         vertex3(void);
00204         vertex3 operator* (float a);
00205         float operator * (const vertex3 &v) const;
00206         vertex3 operator+ (const vertex3 &v);
00207         vertex3 operator- (const vertex3 &v);
00208         vertex3 operator/ (float a);
00209         vertex3 operator/=(float val);
00210         vertex3 operator+=(const vertex3 &v);
00211         vertex3 operator-=(const vertex3 &v);
00212         int MaxIndex(void);
00213         float& operator[](int i);
00214         int operator== (const vertex3 &v);
00215         vertex3 Cross(vertex3 v);
00216         float Length(void);
00217         float Normalize(void);
00218         // Ãß°¡.
00219         vertex3 operator ^ (const vertex3 &v) const;
00220         vertex3 & operator ^= (const vertex3 &v);
00221 };
00222 
00223 
00224 typedef vertex3 gvVERTEX;
00225 typedef vertex3 gvVERTEX3;
00226 typedef vertex3 gvVECTOR3;
00227 typedef gvVERTEX *PVERTEX;
00228 
00232 
00233 class _gvMATRIX
00234 {
00235 public:
00236 #if !defined(EMBEDED_LINUX)
00237 #pragma warning(push)
00238 #pragma warning (disable : 4201)
00239 #endif
00240         union {
00241                 struct {
00242                         float        _11, _12, _13, _14;
00243                         float        _21, _22, _23, _24;
00244                         float        _31, _32, _33, _34;
00245                         float        _41, _42, _43, _44;
00246 
00247                 };
00248                 float m[4][4];
00249         };
00250 #if !defined(EMBEDED_LINUX)     
00251 #pragma warning(pop)
00252 #endif
00253         float& operator()(int iRow, int iColumn) { return m[iRow][iColumn]; }
00254         const float& operator()(int iRow, int iColumn) const { return m[iRow][iColumn]; }
00255 
00256 public:
00257         _gvMATRIX &operator = (const _gvMATRIX &M);
00258         _gvMATRIX operator * (const _gvMATRIX &M) const;
00259 
00260 public:
00261         void Identify();
00262         void Inverse();
00263         void Transpose();
00264         void Zero();
00265         void Scale(const float X, const float Y, const float Z);
00266 
00267         void Project(const float near_plane, const float far_plane,     const float fov_w, const float fov_h);
00268         void ProjectMy(const float fFOV, const float fAspect, const float fNearPlane, const float fFarPlane);           
00269         void View(const gvVECTOR3 &from, const gvVECTOR3 &at,
00270                 const gvVECTOR3 &up, const float roll);
00271         void Translate(const float dx, const float dy, const float dz);
00272 
00273         void RotateX(const float rads);
00274         void RotateY(const float rads);
00275         void RotateZ(const float rads);
00276 
00277         gvVECTOR3 TransNormal(const gvVECTOR3 &n) const;
00278         gvVECTOR3 TransVector(const gvVECTOR3 &v) const;
00279 
00280 private:
00281         static void lubksb(_gvMATRIX & a, int *indx, float *b);
00282         static void ludcmp(_gvMATRIX & a, int *indx, float *d);
00283 };
00284 
00285 typedef _gvMATRIX gvMATRIX;
00286 typedef gvMATRIX *LPGVMATRIX;
00287 typedef gvMATRIX gvMatrix;
00288 
00289 gvVECTOR3 operator * (const gvMATRIX &M, const gvVECTOR3 &v);
00290 gvVECTOR3 operator * (const gvVECTOR3 &v, const gvMATRIX &M);
00291 
00292 
00293 //
00295  typedef struct __simple_vector4
00296  {
00297 #if !defined(EMBEDED_LINUX)
00298 #pragma warning(push)
00299 #pragma warning (disable : 4201)
00300 #endif
00301          union {
00302       struct {
00303                         float x,y,z,w;
00304       };
00305       float v[4];
00306     };
00307 #if !defined(EMBEDED_LINUX)
00308 #pragma warning(pop)
00309 #endif
00310 } simple_vector4;
00311 //
00312  //
00313  //
00314 struct gvVector4 {
00315         union {
00316         float x;
00317         float u;
00318         float r;
00319         };
00320         union {
00321         float y;
00322         float v;
00323         float g;
00324         };
00325         union {
00326         float z;
00327         //float r;
00328         float b;
00329         };
00330         union {
00331         float w;
00332         float rhw;
00333         float q;
00334         float a;
00335         };
00336 
00337         gvVector4(void);
00338         gvVector4(float a, float b, float c, float d = 1);
00339         gvVector4(const gvVECTOR3 & vec);
00340         ~gvVector4();
00341         
00342         gvVector4 operator-(void) const;
00343         gvVector4 operator+(const gvVector4 &rhs) const;
00344         gvVector4 operator-(const gvVector4 &rhs) const;
00345         gvVector4 operator*(const float scalar) const;
00346         gvVector4 operator/(const float scalar) const;
00347         friend gvVector4 operator*(const float scalar, const gvVector4 &rhs);
00348 //      gvVector4 operator*(const float scalar, const gvVector4 &rhs);
00349         float operator*(const gvVector4 &rhs) const;
00350         gvVector4 operator*(const gvMatrix &m) const;
00351         gvVector4 & operator*=(const gvMatrix &m);
00352         gvVector4 & operator+=(const gvVector4 &rhs);
00353         gvVector4 & operator-=(const gvVector4 &rhs);
00354         gvVector4 & operator*=(const float scalar);
00355         gvVector4 & operator/=(const float scalar);
00356 public:
00357         void PerspectiveDivideOne(void);
00358 };
00359 
00360 //
00361 typedef struct gvVector4 gvVERTEX4;
00362 
00363 
00366 const float VECTOR2_ZERO_TOLERANCE = 0.0001f;
00367 
00368 class VECTOR2 
00369 {
00370 public:
00371         VECTOR2(): x(0.0f), y(0.0f) {}
00372         VECTOR2(const float x, const float y) : x(x), y(y) {}
00373         VECTOR2(const VECTOR2& v) : x(v.x), y(v.y) {}
00374 //      inline D3DXVECTOR2 ToD3DXVECTOR2() const {
00375 //              return D3DXVECTOR2((float)x,(float)y);
00376 //      }
00377         VECTOR2 operator- () const;
00378         VECTOR2 operator+ (const VECTOR2& v) const;
00379         VECTOR2 operator- (const VECTOR2& v) const;
00380         VECTOR2 operator* (const VECTOR2& v) const;
00381         VECTOR2 operator/ (const VECTOR2& v) const;
00382 
00383         //NO_TEMPLATE_SELECTION »ç¿ë¾ÈÇÔ.
00384         VECTOR2 operator* (const float a) const;
00385         VECTOR2 operator/ (const float a) const;
00386         VECTOR2 operator+ (const float a) const;
00387         VECTOR2 operator- (const float a) const;
00388 
00389         void operator+= (const VECTOR2& v);
00390         void operator-= (const VECTOR2& v);
00391         void operator*= (const VECTOR2& v);
00392         void operator/= (const VECTOR2& v);
00393         
00394         bool operator== (const VECTOR2& v) const;
00395         bool operator!= (const VECTOR2& v) const;
00396         void operator+= (const float a);
00397         void operator-= (const float a);
00398         void operator*= (const float a);
00399         void operator/= (const float a);
00400         bool operator== (const float a) const;
00401         bool operator!= (const float a) const;
00402         VECTOR2 ScalarAddition(const float a) const;
00403         VECTOR2 ScalarSubtraction(const float a) const;
00404         VECTOR2 ScalarMultiplication(const float a) const;
00405         VECTOR2 ScalarDivision(const float a) const;
00406         bool IsEqualTo(const float a) const;
00407         bool IsNotEqualTo(const float a) const;
00408         float DistanceTo(const VECTOR2& v) const;
00409         float AngleTo(const VECTOR2& v) const;
00410         float Magnitude(void) const;
00411         void Normalize(void);
00412         float DotProduct(const VECTOR2& v);
00413         float CrossProduct(const VECTOR2& v);
00414         float Length(void);
00415 
00416         float x;        
00417         float y;        
00418 };
00419 
00420 
00421 typedef VECTOR2 XVECTOR2;
00422 
00423 //
00424 //
00425 //
00426 //
00427 
00428 class Matrix3 {
00429 public:
00430         float _11, _12, _13;
00431         float _21, _22, _23;
00432         float _31, _32, _33;
00433 
00434         Matrix3();
00435         Matrix3(float m11, float m12, float m13,
00436                         float m21, float m22, float m23,
00437                         float m31, float m32, float m33);
00438 
00439         ~Matrix3();
00440 
00441         void operator+=(const Matrix3 &m);
00442         void operator-=(const Matrix3 &m);
00443         Matrix3 operator+(const Matrix3 &m) const;
00444         Matrix3 operator-(const Matrix3 &m) const;
00445         void operator*=(const Matrix3 &m);
00446         Matrix3 operator*(const Matrix3 &m) const;
00447         void operator*=(const float scalar);
00448         Matrix3 operator*(const float scalar) const;
00449         friend Matrix3 operator*(const float scalar, const Matrix3 &m);
00450         void Identity(void);
00451         void Transpose(void);
00452         void Inverse(void);
00453 };
00454 
00455 
00456 class Matrix4 {
00457 public:
00458         float _11, _12, _13, _14;
00459         float _21, _22, _23, _24;
00460         float _31, _32, _33, _34;
00461         float _41, _42, _43, _44;
00462 
00463         Matrix4(void);
00464         Matrix4(float m11, float m12, float m13, float m14,
00465                         float m21, float m22, float m23, float m24,
00466                         float m31, float m32, float m33, float m34,
00467                         float m41, float m42, float m43, float m44);
00468         ~Matrix4();
00469         void operator+=(const Matrix4 &m);
00470         void operator-=(const Matrix4 &m);
00471         Matrix4 operator+(const Matrix4 &m) const;
00472         Matrix4 operator-(const Matrix4 &m) const;
00473         void operator*=(const Matrix4 &m);
00474         Matrix4 operator*(const Matrix4 &m) const;
00475         void operator*=(const float scalar);
00476         Matrix4 operator*(const float scalar) const;
00477         friend Matrix4 operator*(const float scalar, const Matrix4 &m);
00478         void Identity();
00479         void Transpose();
00480         void Inverse();
00481 
00482 };
00483 
00484 
00485 //
00486 //
00487 
00488 typedef enum _MATRIXMODETYPE {
00489         MM_WORLD = 0,
00490         MM_VIEW = 1,
00491         MM_PROJECT = 2,
00492         MM_VIEWPORT = 3,
00493         MM_FORCE_DWORD = 0x7fffffff
00494 }MATRIXMODETYPE;
00495 
00496 //#define PI 3.1415926535f
00497 // from revision.
00498 //
00499 class gv_gteTransform 
00500 {
00501         MATRIXMODETYPE CurrentMode;
00502         Matrix4 WorldTM;
00503         Matrix4 ViewTM;
00504         Matrix4 ProjectTM;
00505         Matrix4 ViewportTM;
00506         
00507         Matrix4 TM[4];
00508         Matrix3 NormalTM;
00509 
00510         Matrix4 WorldViewTM;
00511         Matrix4 WorldViewProjectTM;
00512         
00513         friend class CRenBuffer;
00514 
00515 public:
00516         void LoadMatrix(const Matrix4 & M);
00517         void SetMatrixMode(const MATRIXMODETYPE i);
00518         void RotateX(float theta);
00519         void RotateY(float theta);
00520         void RotateZ(float theta);
00521         void Scale(float x, float y, float z);
00522         void Translate(float x, float y, float z);
00523         void LoadIndentity(void);
00524         void SimplePerspective(void);
00525         void Perspective(float width, float height, float nearz, float farz);
00526         void PerspectiveFOVW(float fovw, float aspectw, float nearz, float farz);
00527         void PerspectiveFOVH(float fovh, float aspecth, float nearz, float farz);
00528         void SetTransform(void);
00529 
00530 //private:
00531 //      void CalcNormalTM(void){};
00532 
00533 };
00534 
00535 //
00536 //
00537 //
00538 //
00539 
00540 //
00541 #endif
00542 
00543 //#define RGB16 ( (r << 11) + (g << 5) + b)
00544 
00545 #define rgb16(r,g,b) ( ((r << 11)&0xF800) | ((g<< 5)&0x7E0) | ( b & 0x1F ) ) 
00546 #define rgb32(a,r,g,b) ((a << 24) | (r << 16) | (g << 8) | b)
00547 
00548 //add
00549 // from msdn
00550 gvMatrix* D3DXMatrixOrthoLH_MY(gvMatrix* pOut,float w,float h,float zn,float zf);
00551 gvMatrix *D3DXMatrixOrthoOffCenterLH_MY(gvMatrix* pOut,float l,float r,float b,float t,float zn,float zf);
00552 gvMatrix *D3DXMatrixOrthoOffCenterRH_MY(gvMatrix* pOut,float l,float r,float b,float t,float zn,float zf);
00553 #ifndef __GM_VB_H__
00554 #include "gm_vb.h"
00555 #endif
00556 //
00557 // material
00558 
00559 //
00560 //
00561 
00562 
00563 
00564 

Copyright(C) gvSystem & GamePlus All Rights Reserved.