Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CS_CSGEOM_FIXED_H__
00021 #define __CS_CSGEOM_FIXED_H__
00022
00023 #include "csqint.h"
00024
00036 class csFixed16
00037 {
00038 int32 v;
00039 public:
00040 csFixed16 () {}
00041 csFixed16 (const float f) : v (csQfixed16 (f)) {}
00042
00044 csFixed16& operator= (const float f)
00045 {
00046 v = csQfixed16 (f);
00047 return *this;
00048 }
00049
00051 inline friend csFixed16 operator- (const csFixed16& v1,
00052 const csFixed16& v2)
00053 {
00054 csFixed16 v;
00055 v.v = v1.v - v2.v;
00056 return v;
00057 }
00059 inline friend csFixed16 operator- (float v1,
00060 const csFixed16& v2)
00061 {
00062 csFixed16 v;
00063 v.v = csQfixed16 (v1) - v2.v;
00064 return v;
00065 }
00067 inline friend csFixed16 operator- (const csFixed16& v1,
00068 float v2)
00069 {
00070 csFixed16 v;
00071 v.v = v1.v - csQfixed16 (v2);
00072 return v;
00073 }
00074
00076 inline friend csFixed16 operator* (const csFixed16& v1,
00077 float v2)
00078 {
00079 csFixed16 v;
00080 v.v = (int32)(v1.v * v2);
00081 return v;
00082 }
00083
00085 inline friend csFixed16 operator* (const csFixed16& v1,
00086 int v2)
00087 {
00088 csFixed16 v;
00089 v.v = v1.v * v2;
00090 return v;
00091 }
00092
00094 inline csFixed16& operator+= (const csFixed16& x)
00095 {
00096 v += x.v;
00097 return *this;
00098 }
00099
00101 inline operator int() const
00102 { return v >> 16; }
00103
00105 inline int32 GetFixed() const { return v; }
00106
00108 inline friend csFixed16 operator>> (const csFixed16& v1, int n)
00109 {
00110 csFixed16 vn;
00111 vn.v = v1.v >> n;
00112 return vn;
00113 }
00114 };
00115
00120 class csFixed24
00121 {
00122 int32 v;
00123 public:
00125 csFixed24& operator= (float f)
00126 {
00127 v = csQfixed24 (f);
00128 return *this;
00129 }
00130
00132 inline friend csFixed24 operator- (const csFixed24& v1,
00133 const csFixed24& v2)
00134 {
00135 csFixed24 v;
00136 v.v = v1.v - v2.v;
00137 return v;
00138 }
00140 inline friend csFixed24 operator- (float v1,
00141 const csFixed24& v2)
00142 {
00143 csFixed24 v;
00144 v.v = csQfixed24 (v1) - v2.v;
00145 return v;
00146 }
00148 inline friend csFixed24 operator- (const csFixed24& v1,
00149 float v2)
00150 {
00151 csFixed24 v;
00152 v.v = v1.v - csQfixed24 (v2);
00153 return v;
00154 }
00155
00157 inline friend csFixed24 operator* (const csFixed24& v1,
00158 float v2)
00159 {
00160 csFixed24 v;
00161 v.v = (int32)(v1.v * v2);
00162 return v;
00163 }
00164
00166 inline csFixed24& operator+= (const csFixed24& x)
00167 {
00168 v += x.v;
00169 return *this;
00170 }
00171
00173 inline operator int() const
00174 { return v >> 16; }
00175
00177 inline int32 GetFixed() const { return v; }
00178 };
00179
00182 #endif // __CS_CSGEOM_FIXED_H__
00183