chore: KDIS datatypes
[KDIS.git] / KDIS / DataTypes / Vector.h
blob3d5a87eaf1b82a96b1d0fce13d16b4999e795579
1 /*********************************************************************
2 Copyright 2013 Karl Jones
3 All rights reserved.
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
26 Karljj1@yahoo.com
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
30 /********************************************************************
31 class: Vector
32 created: 18/09/2008
33 author: Karl Jones
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 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.
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.
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.
59 4)Aggregate dimensions box size
61 size: 96 bits / 12 octets
62 *********************************************************************/
64 #pragma once
66 #include "./DataTypeBase.h"
68 namespace KDIS {
69 namespace DATA_TYPE {
71 class KDIS_EXPORT Vector : public DataTypeBase
73 protected:
75 KFLOAT32 m_f32X;
77 KFLOAT32 m_f32Y;
79 KFLOAT32 m_f32Z;
81 public:
83 static const KUINT16 VECTOR_SIZE = 12;
85 Vector();
87 Vector( KFLOAT32 X, KFLOAT32 Y, KFLOAT32 Z );
89 Vector( KDataStream & stream ) ;
91 virtual ~Vector();
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;
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;
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;
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 );
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;
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).
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 );
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 other value.
189 KFLOAT32 & operator[] ( KUINT16 i ) ;
190 const KFLOAT32 & operator[] ( KUINT16 i ) const ;
193 } // END namespace DATA_TYPES
194 } // END namespace KDIS