1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2003 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGMATHFIELDTRAITS_H_
40 #define _OSGMATHFIELDTRAITS_H_
45 #include "OSGFieldTraits.h"
46 #include "OSGDataType.h"
48 #include "OSGMatrix.h"
49 #include "OSGQuaternion.h"
53 /*! \ingroup GrpBaseFieldTraits
54 \ingroup GrpLibOSGBase
58 struct FieldTraits
<Matrix
> : public FieldTraitsTemplateBase
<Matrix
>
62 static DataType _type
;
66 typedef FieldTraits
<Matrix
> Self
;
68 enum { Convertible
= (Self::FromStringConvertible
|
69 Self::ToStreamConvertible
) };
71 static OSG_BASE_DLLMAPPING
72 DataType
&getType (void);
74 static const Char8
*getSName (void) { return "SFMatrix"; }
75 static const Char8
*getMName (void) { return "MFMatrix"; }
77 static Matrix
getDefault (void) { return Matrix(); }
80 static bool getFromCString( Matrix
&outVal
,
83 outVal
.setValue(inVal
, false);
87 static void putToStream(const Matrix
&val
,
90 typedef TypeTraits
<Matrix::ValueType
> TypeTrait
;
92 TypeTrait::putToStream((val
.getValues())[0], outStr
);
94 TypeTrait::putToStream((val
.getValues())[4], outStr
);
96 TypeTrait::putToStream((val
.getValues())[8], outStr
);
98 TypeTrait::putToStream((val
.getValues())[12], outStr
);
101 TypeTrait::putToStream((val
.getValues())[1], outStr
);
103 TypeTrait::putToStream((val
.getValues())[5], outStr
);
105 TypeTrait::putToStream((val
.getValues())[9], outStr
);
107 TypeTrait::putToStream((val
.getValues())[13], outStr
);
110 TypeTrait::putToStream((val
.getValues())[2], outStr
);
112 TypeTrait::putToStream((val
.getValues())[6], outStr
);
114 TypeTrait::putToStream((val
.getValues())[10], outStr
);
116 TypeTrait::putToStream((val
.getValues())[14], outStr
);
119 TypeTrait::putToStream((val
.getValues())[3], outStr
);
121 TypeTrait::putToStream((val
.getValues())[7], outStr
);
123 TypeTrait::putToStream((val
.getValues())[11], outStr
);
125 TypeTrait::putToStream((val
.getValues())[15], outStr
);
128 static SizeT
getBinSize (const Matrix
&)
130 return sizeof(Real32
) * 16;
133 static SizeT
getBinSize (const Matrix
*,
136 return sizeof(Real32
) * 16 * uiNumObjects
;
139 static void copyToBin ( BinaryDataHandler
&pMem
,
140 const Matrix
&oObject
)
142 pMem
.putValues(&oObject
[0][0], 16);
146 static void copyFromBin( BinaryDataHandler
&pMem
,
149 pMem
.getValues(&oObject
[0][0], 16);
152 static void copyToBin ( BinaryDataHandler
&pMem
,
153 const Matrix
*pObjectStore
,
156 pMem
.putValues(&pObjectStore
[0][0][0], uiNumObjects
* 16);
159 static void copyFromBin ( BinaryDataHandler
&pMem
,
160 Matrix
*pObjectStore
,
163 pMem
.getValues(&pObjectStore
[0][0][0], uiNumObjects
* 16);
169 /*! \ingroup GrpBaseFieldTraits
170 \ingroup GrpLibOSGBase
174 struct FieldTraits
<Matrix4d
> : public FieldTraitsTemplateBase
<Matrix4d
>
178 static DataType _type
;
182 typedef FieldTraits
<Matrix4d
> Self
;
184 enum { Convertible
= (Self::FromStringConvertible
|
185 Self::ToStreamConvertible
) };
187 static OSG_BASE_DLLMAPPING
188 DataType
&getType (void);
190 static const Char8
*getSName (void) { return "SFMatrix4d"; }
191 static const Char8
*getMName (void) { return "MFMatrix4d"; }
193 static Matrix4d
getDefault (void) { return Matrix4d(); }
195 static bool getFromCString( Matrix4d
&outVal
,
198 outVal
.setValue(inVal
, false);
202 static void putToStream (const Matrix4d
&val
,
205 typedef TypeTraits
<Matrix4d::ValueType
> TypeTrait
;
207 TypeTrait::putToStream((val
.getValues())[0], outStr
);
209 TypeTrait::putToStream((val
.getValues())[4], outStr
);
211 TypeTrait::putToStream((val
.getValues())[8], outStr
);
213 TypeTrait::putToStream((val
.getValues())[12], outStr
);
216 TypeTrait::putToStream((val
.getValues())[1], outStr
);
218 TypeTrait::putToStream((val
.getValues())[5], outStr
);
220 TypeTrait::putToStream((val
.getValues())[9], outStr
);
222 TypeTrait::putToStream((val
.getValues())[13], outStr
);
225 TypeTrait::putToStream((val
.getValues())[2], outStr
);
227 TypeTrait::putToStream((val
.getValues())[6], outStr
);
229 TypeTrait::putToStream((val
.getValues())[10], outStr
);
231 TypeTrait::putToStream((val
.getValues())[14], outStr
);
234 TypeTrait::putToStream((val
.getValues())[3], outStr
);
236 TypeTrait::putToStream((val
.getValues())[7], outStr
);
238 TypeTrait::putToStream((val
.getValues())[11], outStr
);
240 TypeTrait::putToStream((val
.getValues())[15], outStr
);
243 static SizeT
getBinSize (const Matrix4d
&)
245 return sizeof(Real64
) * 16;
248 static SizeT
getBinSize (const Matrix4d
*,
251 return sizeof(Real64
) * 16 * uiNumObjects
;
254 static void copyToBin ( BinaryDataHandler
&pMem
,
255 const Matrix4d
&oObject
)
257 pMem
.putValues(&oObject
[0][0], 16);
261 static void copyFromBin( BinaryDataHandler
&pMem
,
264 pMem
.getValues(&oObject
[0][0], 16);
267 static void copyToBin ( BinaryDataHandler
&pMem
,
268 const Matrix4d
*pObjectStore
,
271 pMem
.putValues(&pObjectStore
[0][0][0], uiNumObjects
* 16);
274 static void copyFromBin( BinaryDataHandler
&pMem
,
275 Matrix4d
*pObjectStore
,
278 pMem
.getValues(&pObjectStore
[0][0][0], uiNumObjects
* 16);
284 /*! \ingroup GrpBaseFieldTraits
285 \ingroup GrpLibOSGBase
289 struct FieldTraits
<Matrix4fx
> : public FieldTraitsTemplateBase
<Matrix4fx
>
293 static DataType _type
;
297 typedef FieldTraits
<Matrix4fx
> Self
;
299 enum { Convertible
= Self::NotConvertible
};
301 static OSG_BASE_DLLMAPPING
302 DataType
&getType (void);
304 static const Char8
*getSName (void) { return "SFMatrix4fx"; }
305 static const Char8
*getMName (void) { return "MFMatrix4fx"; }
307 static Matrix4fx
getDefault (void) { return Matrix4fx(); }
310 static bool getFromString( Matrix4fx
&outVal
,
313 outVal
.setValue(inVal
, false);
317 static SizeT
getBinSize (const Matrix4fx
&)
319 return sizeof(Fixed32
) * 16;
322 static SizeT
getBinSize (const Matrix4fx
*,
325 return sizeof(Fixed32
) * 16 * uiNumObjects
;
328 static void copyToBin ( BinaryDataHandler
&pMem
,
329 const Matrix4fx
&oObject
)
331 pMem
.putValues(&oObject
[0][0], 16);
335 static void copyFromBin( BinaryDataHandler
&pMem
,
338 pMem
.getValues(&oObject
[0][0], 16);
341 static void copyToBin( BinaryDataHandler
&pMem
,
342 const Matrix4fx
*pObjectStore
,
345 pMem
.putValues(&pObjectStore
[0][0][0], uiNumObjects
* 16);
348 static void copyFromBin( BinaryDataHandler
&pMem
,
349 Matrix4fx
*pObjectStore
,
352 pMem
.getValues(&pObjectStore
[0][0][0], uiNumObjects
* 16);
358 /*! \ingroup GrpBaseFieldTraits
362 struct FieldTraits
<Quaternion
> : public FieldTraitsVec4TemplateBase
<Quaternion
>
366 static DataType _type
;
370 typedef FieldTraits
<Quaternion
> Self
;
372 enum { Convertible
= (Self::FromStringConvertible
|
373 Self::ToStreamConvertible
) };
375 static OSG_BASE_DLLMAPPING
376 DataType
&getType (void);
378 static const Char8
*getSName (void) { return "SFQuaternion"; }
379 static const Char8
*getMName (void) { return "MFQuaternion"; }
381 static Quaternion
getDefault (void) { return Quaternion(); }
383 static bool getFromCString( Quaternion
&outVal
,
386 // VRML requires axis and angle in radians
387 outVal
.setValueAsAxisRad(inVal
);
395 /*! \ingroup GrpBaseFieldTraits
396 \ingroup GrpLibOSGBase
400 struct FieldTraits
<Quaternionfx
> :
401 public FieldTraitsVec4TemplateBase
<Quaternionfx
>
405 static DataType _type
;
409 typedef FieldTraits
<Quaternionfx
> Self
;
411 enum { Convertible
= Self::ToStreamConvertible
};
413 static OSG_BASE_DLLMAPPING
414 DataType
&getType (void);
416 static const Char8
*getSName (void) { return "SFQuaternionfx"; }
417 static const Char8
*getMName (void) { return "MFQuaternionfx"; }
419 static Quaternionfx
getDefault (void) { return Quaternionfx(); }
425 #endif /* _OSGMATHFIELDTRAITS_H_ */