Public Functions
mathRead(Stream & stream, Box3F * b)
mathRead(Stream & stream, EaseF * e)
mathRead(Stream & stream, MatrixF * m)
mathRead(Stream & stream, PlaneF * p)
mathRead(Stream & stream, Point2F * p)
mathRead(Stream & stream, Point2I * p)
mathRead(Stream & stream, Point3D * p)
mathRead(Stream & stream, Point3F * p)
mathRead(Stream & stream, Point3I * p)
mathRead(Stream & stream, Point4F * p)
mathRead(Stream & stream, QuatF * q)
mathRead(Stream & stream, RectF * r)
mathRead(Stream & stream, RectI * r)
mathRead(Stream & stream, RotationF * e)
mathRead(Stream & stream, SphereF * s)
mathWrite(Stream & stream, const Box3F & b)
mathWrite(Stream & stream, const EaseF & e)
mathWrite(Stream & stream, const MatrixF & m)
mathWrite(Stream & stream, const PlaneF & p)
mathWrite(Stream & stream, const Point2F & p)
mathWrite(Stream & stream, const Point2I & p)
mathWrite(Stream & stream, const Point3D & p)
mathWrite(Stream & stream, const Point3F & p)
mathWrite(Stream & stream, const Point3I & p)
mathWrite(Stream & stream, const Point4F & p)
mathWrite(Stream & stream, const QuatF & q)
mathWrite(Stream & stream, const RectF & r)
mathWrite(Stream & stream, const RectI & r)
mathWrite(Stream & stream, const RotationF & e)
mathWrite(Stream & stream, const SphereF & s)
1
2//-----------------------------------------------------------------------------
3// Copyright (c) 2012 GarageGames, LLC
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to
7// deal in the Software without restriction, including without limitation the
8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _MATHIO_H_
25#define _MATHIO_H_
26
27//Includes
28#ifndef _PLATFORM_H_
29#include "platform/platform.h"
30#endif
31#ifndef _STREAM_H_
32#include "core/stream/stream.h"
33#endif
34#ifndef _MMATH_H_
35#include "math/mMath.h"
36#endif
37
38
39//------------------------------------------------------------------------------
40//-------------------------------------- READING
41//
42inline bool mathRead(Stream& stream, Point2I* p)
43{
44 bool success = stream.read(&p->x);
45 success &= stream.read(&p->y);
46 return success;
47}
48
49inline bool mathRead(Stream& stream, Point3I* p)
50{
51 bool success = stream.read(&p->x);
52 success &= stream.read(&p->y);
53 success &= stream.read(&p->z);
54 return success;
55}
56
57inline bool mathRead(Stream& stream, Point2F* p)
58{
59 bool success = stream.read(&p->x);
60 success &= stream.read(&p->y);
61 return success;
62}
63
64inline bool mathRead(Stream& stream, Point3F* p)
65{
66 bool success = stream.read(&p->x);
67 success &= stream.read(&p->y);
68 success &= stream.read(&p->z);
69 return success;
70}
71
72inline bool mathRead(Stream& stream, Point4F* p)
73{
74 bool success = stream.read(&p->x);
75 success &= stream.read(&p->y);
76 success &= stream.read(&p->z);
77 success &= stream.read(&p->w);
78 return success;
79}
80
81inline bool mathRead(Stream& stream, Point3D* p)
82{
83 bool success = stream.read(&p->x);
84 success &= stream.read(&p->y);
85 success &= stream.read(&p->z);
86 return success;
87}
88
89inline bool mathRead(Stream& stream, PlaneF* p)
90{
91 bool success = stream.read(&p->x);
92 success &= stream.read(&p->y);
93 success &= stream.read(&p->z);
94 success &= stream.read(&p->d);
95 return success;
96}
97
98inline bool mathRead(Stream& stream, Box3F* b)
99{
100 bool success = mathRead(stream, &b->minExtents);
101 success &= mathRead(stream, &b->maxExtents);
102 return success;
103}
104
105inline bool mathRead(Stream& stream, SphereF* s)
106{
107 bool success = mathRead(stream, &s->center);
108 success &= stream.read(&s->radius);
109 return success;
110}
111
112inline bool mathRead(Stream& stream, RectI* r)
113{
114 bool success = mathRead(stream, &r->point);
115 success &= mathRead(stream, &r->extent);
116 return success;
117}
118
119inline bool mathRead(Stream& stream, RectF* r)
120{
121 bool success = mathRead(stream, &r->point);
122 success &= mathRead(stream, &r->extent);
123 return success;
124}
125
126inline bool mathRead(Stream& stream, MatrixF* m)
127{
128 bool success = true;
129 F32* pm = *m;
130 for (U32 i = 0; i < 16; i++)
131 success &= stream.read(&pm[i]);
132 return success;
133}
134
135inline bool mathRead(Stream& stream, QuatF* q)
136{
137 bool success = stream.read(&q->x);
138 success &= stream.read(&q->y);
139 success &= stream.read(&q->z);
140 success &= stream.read(&q->w);
141 return success;
142}
143
144inline bool mathRead(Stream& stream, EaseF* e)
145{
146 bool success = stream.read( &e->mDir );
147 success &= stream.read( &e->mType );
148 success &= stream.read( &e->mParam[ 0 ] );
149 success &= stream.read( &e->mParam[ 1 ] );
150 return success;
151}
152
153inline bool mathRead(Stream& stream, RotationF* e)
154{
155 bool success = stream.read(&e->x);
156 success &= stream.read(&e->y);
157 success &= stream.read(&e->z);
158 success &= stream.read(&e->w);
159
160 U32 rotType;
161 success &= stream.read(&rotType);
162 e->mRotationType = (RotationF::RotationTypes)rotType;
163
164 return success;
165}
166
167//------------------------------------------------------------------------------
168//-------------------------------------- WRITING
169//
170inline bool mathWrite(Stream& stream, const Point2I& p)
171{
172 bool success = stream.write(p.x);
173 success &= stream.write(p.y);
174 return success;
175}
176
177inline bool mathWrite(Stream& stream, const Point3I& p)
178{
179 bool success = stream.write(p.x);
180 success &= stream.write(p.y);
181 success &= stream.write(p.z);
182 return success;
183}
184
185inline bool mathWrite(Stream& stream, const Point2F& p)
186{
187 bool success = stream.write(p.x);
188 success &= stream.write(p.y);
189 return success;
190}
191
192inline bool mathWrite(Stream& stream, const Point3F& p)
193{
194 bool success = stream.write(p.x);
195 success &= stream.write(p.y);
196 success &= stream.write(p.z);
197 return success;
198}
199
200inline bool mathWrite(Stream& stream, const Point4F& p)
201{
202 bool success = stream.write(p.x);
203 success &= stream.write(p.y);
204 success &= stream.write(p.z);
205 success &= stream.write(p.w);
206 return success;
207}
208
209inline bool mathWrite(Stream& stream, const Point3D& p)
210{
211 bool success = stream.write(p.x);
212 success &= stream.write(p.y);
213 success &= stream.write(p.z);
214 return success;
215}
216
217inline bool mathWrite(Stream& stream, const PlaneF& p)
218{
219 bool success = stream.write(p.x);
220 success &= stream.write(p.y);
221 success &= stream.write(p.z);
222 success &= stream.write(p.d);
223 return success;
224}
225
226inline bool mathWrite(Stream& stream, const Box3F& b)
227{
228 bool success = mathWrite(stream, b.minExtents);
229 success &= mathWrite(stream, b.maxExtents);
230 return success;
231}
232
233inline bool mathWrite(Stream& stream, const SphereF& s)
234{
235 bool success = mathWrite(stream, s.center);
236 success &= stream.write(s.radius);
237 return success;
238}
239
240inline bool mathWrite(Stream& stream, const RectI& r)
241{
242 bool success = mathWrite(stream, r.point);
243 success &= mathWrite(stream, r.extent);
244 return success;
245}
246
247inline bool mathWrite(Stream& stream, const RectF& r)
248{
249 bool success = mathWrite(stream, r.point);
250 success &= mathWrite(stream, r.extent);
251 return success;
252}
253
254inline bool mathWrite(Stream& stream, const MatrixF& m)
255{
256 bool success = true;
257 const F32* pm = m;
258 for (U32 i = 0; i < 16; i++)
259 success &= stream.write(pm[i]);
260 return success;
261}
262
263inline bool mathWrite(Stream& stream, const QuatF& q)
264{
265 bool success = stream.write(q.x);
266 success &= stream.write(q.y);
267 success &= stream.write(q.z);
268 success &= stream.write(q.w);
269 return success;
270}
271
272inline bool mathWrite(Stream& stream, const EaseF& e)
273{
274 bool success = stream.write(e.mDir);
275 success &= stream.write(e.mType);
276 success &= stream.write(e.mParam[0]);
277 success &= stream.write(e.mParam[1]);
278 return success;
279}
280
281inline bool mathWrite(Stream& stream, const RotationF& e)
282{
283 bool success = stream.write(e.x);
284 success &= stream.write(e.y);
285 success &= stream.write(e.z);
286 success &= stream.write(e.w);
287 success &= stream.write(e.mRotationType);
288 return success;;
289}
290
291#endif //_MATHIO_H_
292
293