2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef _SHORTVECTOR_H
20 #define _SHORTVECTOR_H
22 #include <G3D/Vector3.h>
27 Vector with 16 bit fix point values 12.4 bit.
37 const static short maxvalue
= 0x7fff;
38 const static short minvalue
= -0x7fff;
39 const static int fixpointdiv
= 16;
40 const static short fixpoint_maxvalue
= maxvalue
/ fixpointdiv
;
41 const static short fixpoint_minvalue
= minvalue
/ fixpointdiv
;
43 inline short float2Short(float fv
) const
46 debugAssert((fv
<= fixpoint_maxvalue
|| fv
>= 1000000) && (fv
>= fixpoint_minvalue
|| fv
<= -1000000));
47 if(fv
>= fixpoint_maxvalue
)
49 else if(fv
<= fixpoint_minvalue
)
52 sv
= (short) (fv
* fixpointdiv
+ 0.5);
55 inline float short2Float(short sv
) const
60 else if(sv
<= minvalue
)
63 fv
= ((float)sv
) / fixpointdiv
;
67 inline float getFX() const { return(short2Float(iX
)); }
68 inline float getFY() const { return(short2Float(iY
)); }
69 inline float getFZ() const { return(short2Float(iZ
)); }
71 inline ShortVector() {}
72 inline ShortVector(const G3D::Vector3
& pVector
)
74 iX
= float2Short(pVector
.x
);
75 iY
= float2Short(pVector
.y
);
76 iZ
= float2Short(pVector
.z
);
79 inline ShortVector(float pX
, float pY
, float pZ
)
85 inline ShortVector(short pX
, short pY
, short pZ
)
91 inline ShortVector(const ShortVector
& pShortVector
)
98 inline float getX() const { return(iX
); }
99 inline float getY() const { return(iY
); }
100 inline float getZ() const { return(iZ
); }
102 inline G3D::Vector3
getVector3() const { return(G3D::Vector3(getFX(), getFY(), getFZ())); }
104 inline ShortVector
min(const ShortVector pShortVector
)
106 ShortVector result
= pShortVector
;
107 if(pShortVector
.iX
> iX
) { result
.iX
= iX
; }
108 if(pShortVector
.iY
> iY
) { result
.iY
= iY
; }
109 if(pShortVector
.iZ
> iZ
) { result
.iZ
= iZ
; }
113 inline ShortVector
max(const ShortVector pShortVector
)
115 ShortVector result
= pShortVector
;
116 if(pShortVector
.iX
< iX
) { result
.iX
= iX
; }
117 if(pShortVector
.iY
< iY
) { result
.iY
= iY
; }
118 if(pShortVector
.iZ
< iZ
) { result
.iZ
= iZ
; }
122 inline bool operator==(const ShortVector
& v
) const
124 return (iX
== v
.iX
&& iY
== v
.iY
&& iZ
== v
.iZ
);
127 inline bool operator!=(const ShortVector
& v
) const
129 return !(iX
== v
.iX
&& iY
== v
.iY
&& iZ
== v
.iZ
);