KDIS  2-8-x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Vector.h
Go to the documentation of this file.
1 /*********************************************************************
2 Copyright 2013 Karl Jones
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 
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.
13 
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.
24 
25 For Further Information Please Contact me at
26 Karljj1@yahoo.com
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
29 
30 /********************************************************************
31  class: Vector
32  created: 18/09/2008
33  author: Karl Jones
34 
35  purpose: Stores a vector
36 
37  A Vector has 4 different representations:
38 
39  1)Entity Coordinate Vector
40  Location with respect to a particular entity shall be specified with respect
41  to three orthogonal axes whose origin shall be the geometric center of the
42  bounding volume of the entity excluding its articulated and attached parts.
43  The x-axis extends in the positive direction out the front of the entity.
44  The y-axis extends in the positive direction out the right side of the entity
45  as viewed from above, facing in the direction of the positive x-axis.
46  The z-axis extends in the positive direction out the bottom of the entity.
47  Each vector component shall represent meters from the origin.
48 
49  2)Linear Acceleration Vector - m/s2
50  Represented as a vector with components in either world coordinate system or
51  entity�s coordinate system depending on the value in the Dead Reckoning Algorithm
52  field. Each vector component shall represent acceleration in meters per second squared.
53 
54  3)Linear Velocity Vector - m/s
55  Represented as a vector with three components in either world coordinate system or
56  entity�s coordinate system depending on the value in the Dead Reckoning Algorithm
57  field. Each vector component shall represent velocity in meters per second.
58 
59  4)Aggregate dimensions box size
60 
61  size: 96 bits / 12 octets
62 *********************************************************************/
63 
64 #pragma once
65 
66 #include "./DataTypeBase.h"
67 
68 namespace KDIS {
69 namespace DATA_TYPE {
70 
72 {
73 protected:
74 
76 
78 
80 
81 public:
82 
83  static const KUINT16 VECTOR_SIZE = 12;
84 
85  Vector();
86 
87  Vector( KFLOAT32 X, KFLOAT32 Y, KFLOAT32 Z );
88 
89  Vector( KDataStream & stream ) throw( KException );
90 
91  virtual ~Vector();
92 
93  //************************************
94  // FullName: KDIS::DATA_TYPE::Vector::SetX
95  // KDIS::DATA_TYPE::Vector::GetX
96  //!Description: First Value / X
97  // Parameter: KFLOAT32 X
98  //************************************
99  void SetX( KFLOAT32 X );
100  KFLOAT32 GetX() const;
101 
102  //************************************
103  // FullName: KDIS::DATA_TYPE::Vector::SetY
104  // KDIS::DATA_TYPE::Vector::GetY
105  //!Description: Second Value / Y
106  // Parameter: KFLOAT32 Y
107  //************************************
108  void SetY( KFLOAT32 Y );
109  KFLOAT32 GetY() const;
110 
111  //************************************
112  // FullName: KDIS::DATA_TYPE::Vector::SetZ
113  // KDIS::DATA_TYPE::Vector::GetZ
114  //!Description: Third Value / Z
115  // Parameter: KFLOAT32 Z
116  //************************************
117  void SetZ( KFLOAT32 Z );
118  KFLOAT32 GetZ() const;
119 
120  //************************************
121  // FullName: KDIS::DATA_TYPE::Vector::Set
122  //!Description: Sets x,y and z.
123  // Parameter: KFLOAT32 X
124  // Parameter: KFLOAT32 Y
125  // Parameter: KFLOAT32 Z
126  //************************************
127  void Set( KFLOAT32 X, KFLOAT32 Y, KFLOAT32 Z );
128 
129  //************************************
130  // FullName: KDIS::DATA_TYPE::Vector::GetMagnitude
131  //!Description: Calculates and returns the magnitude or length.
132  // E.G If the vector represented a velocity then this would be the speed.
133  //************************************
134  KFLOAT32 GetMagnitude() const;
135 
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 );
142 
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).
147  //! T 0 = From
148  //! 1 = to
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 );
156 
157  //************************************
158  // FullName: KDIS::DATA_TYPE::Vector::GetAsString
159  //!Description: Returns a string representation
160  //************************************
161  virtual KString GetAsString() const;
162 
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 ) throw( KException );
169 
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;
177 
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 );
187 
188  // Valid values 0 - X, 1 - Y, 2 - Z. throws OUT_OF_BOUNDS exception for any other value.
189  KFLOAT32 & operator[] ( KUINT16 i ) throw( KException );
190  const KFLOAT32 & operator[] ( KUINT16 i ) const throw( KException );
191 };
192 
193 } // END namespace DATA_TYPES
194 } // END namespace KDIS
KFLOAT32 m_f32Z
Definition: Vector.h:79
KFLOAT32 m_f32X
Definition: Vector.h:75
unsigned short int KUINT16
Definition: KDefines.h:101
KFLOAT32 m_f32Y
Definition: Vector.h:77
float KFLOAT32
Definition: KDefines.h:113
Definition: Vector.h:71
Definition: KDefines.h:182
Definition: KDataStream.h:48
Definition: DataTypeBase.h:49
bool KBOOL
Definition: KDefines.h:119
std::string KString
Definition: KDefines.h:116
double KFLOAT64
Definition: KDefines.h:114
#define KDIS_EXPORT
Definition: KDefines.h:82