1 /*********************************************************************
2 Copyright 2013 Karl Jones
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 For Further Information Please Contact me at
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
30 /********************************************************************
35 purpose: Stores a vector
37 A Vector has 4 different representations:
39 1)Entity Coordinate Vector
40 Location with respect to a particular entity shall be
41 specified with respect to three orthogonal axes whose origin shall be the
42 geometric center of the bounding volume of the entity excluding its articulated
43 and attached parts. The x-axis extends in the positive direction out the front
44 of the entity. The y-axis extends in the positive direction out the right side
45 of the entity as viewed from above, facing in the direction of the positive
46 x-axis. The z-axis extends in the positive direction out the bottom of the
47 entity. Each vector component shall represent meters from the origin.
49 2)Linear Acceleration Vector - m/s2
50 Represented as a vector with components in either world
51 coordinate system or entity's coordinate system depending on the value in the
52 Dead Reckoning Algorithm field. Each vector component shall represent
53 acceleration in meters per second squared.
55 3)Linear Velocity Vector - m/s
56 Represented as a vector with three components in either
57 world coordinate system or entity's coordinate system depending on the value in
58 the Dead Reckoning Algorithm field. Each vector component shall represent
59 velocity in meters per second.
61 4)Aggregate dimensions box size
63 size: 96 bits / 12 octets
64 *********************************************************************/
68 #include "KDIS/DataTypes/DataTypeBase.hpp"
73 class KDIS_EXPORT Vector
: public DataTypeBase
{
82 static const KUINT16 VECTOR_SIZE
= 12;
86 Vector(KFLOAT32 X
, KFLOAT32 Y
, KFLOAT32 Z
);
88 Vector(KDataStream
& stream
);
92 //************************************
93 // FullName: KDIS::DATA_TYPE::Vector::SetX
94 // KDIS::DATA_TYPE::Vector::GetX
95 // Description: First Value / X
96 // Parameter: KFLOAT32 X
97 //************************************
98 void SetX(KFLOAT32 X
);
99 KFLOAT32
GetX() const;
101 //************************************
102 // FullName: KDIS::DATA_TYPE::Vector::SetY
103 // KDIS::DATA_TYPE::Vector::GetY
104 // Description: Second Value / Y
105 // Parameter: KFLOAT32 Y
106 //************************************
107 void SetY(KFLOAT32 Y
);
108 KFLOAT32
GetY() const;
110 //************************************
111 // FullName: KDIS::DATA_TYPE::Vector::SetZ
112 // KDIS::DATA_TYPE::Vector::GetZ
113 // Description: Third Value / Z
114 // Parameter: KFLOAT32 Z
115 //************************************
116 void SetZ(KFLOAT32 Z
);
117 KFLOAT32
GetZ() const;
119 //************************************
120 // FullName: KDIS::DATA_TYPE::Vector::Set
121 // Description: Sets x,y and z.
122 // Parameter: KFLOAT32 X
123 // Parameter: KFLOAT32 Y
124 // Parameter: KFLOAT32 Z
125 //************************************
126 void Set(KFLOAT32 X
, KFLOAT32 Y
, KFLOAT32 Z
);
128 //************************************
129 // FullName: KDIS::DATA_TYPE::Vector::GetMagnitude
130 // Description: Calculates and returns the magnitude or length.
131 // E.G If the vector represented a velocity then this would be
133 //************************************
134 KFLOAT32
GetMagnitude() const;
136 //************************************
137 // FullName: KDIS::DATA_TYPE::Vector::GetDistance
138 // Description: Calculates the distance from this vector to an other.
139 // Parameter: KFLOAT32 Z
140 //************************************
141 KFLOAT32
GetDistance(const Vector
& Other
);
143 //************************************
144 // FullName: KDIS::DATA_TYPE::Vector::Lerp
145 // Description: Linearly interpolate between From and To by T.
146 // T should be between 0 and 1(its not checked).
149 // 0.5 = halfway between From and To.
150 // Parameter: const Vector & From
151 // Parameter: const Vector & To
152 // Parameter: KFLOAT32 T
153 //************************************
154 static Vector
Lerp(const Vector
& From
, const Vector
& To
, KFLOAT32 T
);
155 void Lerp(const Vector
& To
, KFLOAT32 T
);
157 //************************************
158 // FullName: KDIS::DATA_TYPE::Vector::GetAsString
159 // Description: Returns a string representation
160 //************************************
161 virtual KString
GetAsString() const;
163 //************************************
164 // FullName: KDIS::DATA_TYPE::Vector::Decode
165 // Description: Convert From Network Data.
166 // Parameter: KDataStream & stream
167 //************************************
168 virtual void Decode(KDataStream
& stream
);
170 //************************************
171 // FullName: KDIS::DATA_TYPE::Vector::Encode
172 // Description: Convert To Network Data.
173 // Parameter: KDataStream & stream
174 //************************************
175 virtual KDataStream
Encode() const;
176 virtual void Encode(KDataStream
& stream
) const;
178 KBOOL
operator==(const Vector
& Value
) const;
179 KBOOL
operator!=(const Vector
& Value
) const;
180 Vector
operator*(const Vector
& Value
) const;
181 Vector
operator*(KFLOAT64 Value
) const;
182 Vector
operator*(KFLOAT32 Value
) const;
183 Vector
operator+(const Vector
& Value
) const;
184 Vector
& operator+=(const Vector
& Value
);
185 Vector
operator-(const Vector
& Value
) const;
186 Vector
& operator-=(const Vector
& Value
);
188 // Valid values 0 - X, 1 - Y, 2 - Z. throws OUT_OF_BOUNDS exception for any
190 KFLOAT32
& operator[](KUINT16 i
);
191 const KFLOAT32
& operator[](KUINT16 i
) const;
194 } // namespace DATA_TYPE
195 } // END namespace KDIS