Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/network/synchronizeable_var/synchronizeable_quaternion.cc @ 7459

Last change on this file since 7459 was 7459, checked in by rennerc, 18 years ago

finished some SynchronizeableVars classes

File size: 2.4 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Christoph Renner
13   co-programmer: ...
14*/
15
16
17#include "synchronizeable_quaternion.h"
18#include "converter.h"
19
20
21/**
22 * standard constructor
23 */
24SynchronizeableQuaternion::SynchronizeableQuaternion( Quaternion * ptrIn, Quaternion * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 4*INTSIZE, permission, priority )
25{
26  this->vPtrIn = ptrIn;
27  this->vPtrOut = ptrOut;
28}
29
30
31/**
32 * standard deconstructor
33 */
34SynchronizeableQuaternion::~SynchronizeableQuaternion ()
35{
36}
37
38/**
39 * write var data to byte buffer
40 * @param buf pointer to write to
41 * @param maxLength writeToBuf will not write more than maxLength bytes
42 * @return number bytes written
43 */
44int SynchronizeableQuaternion::writeToBuf( byte * buf, int maxLength )
45{
46  int n = 0;
47  int res;
48 
49  res = Converter::floatToByteArray( vPtrIn->v.x, buf, maxLength - n );
50  assert( res > 0 );
51  n += res;
52 
53  res = Converter::floatToByteArray( vPtrIn->v.y, buf, maxLength - n );
54  assert( res > 0 );
55  n += res;
56 
57  res = Converter::floatToByteArray( vPtrIn->v.z, buf, maxLength - n );
58  assert( res > 0 );
59  n += res;
60 
61  res = Converter::floatToByteArray( vPtrIn->w, buf, maxLength - n );
62  assert( res > 0 );
63  n += res;
64 
65  assert( 4*FLOATSIZE == n );
66 
67  return n;
68}
69
70/**
71 * read var data from byte buffer
72 * @param buf pointer to read from
73 * @param maxLength readFromBuf will not read more than maxLength bytes
74 * @return number bytes read
75 */
76int SynchronizeableQuaternion::readFromBuf( byte * buf, int maxLength )
77{
78  assert( maxLength >= 4*FLOATSIZE );
79 
80  float x,y,z,w;
81 
82  int res;
83  int n = 0;
84 
85  res += Converter::byteArrayToFloat( buf + n, &x );
86  assert( res > 0 );
87  n += res;
88 
89  res += Converter::byteArrayToFloat( buf + n, &x );
90  assert( res > 0 );
91  n += res;
92 
93  res += Converter::byteArrayToFloat( buf + n, &x );
94  assert( res > 0 );
95  n += res;
96 
97  res += Converter::byteArrayToFloat( buf + n, &w );
98  assert( res > 0 );
99  n += res;
100 
101  *vPtrOut = Quaternion( Vector(x, y, z), w );
102 
103  assert( res == 4*FLOATSIZE );
104  return res;
105}
Note: See TracBrowser for help on using the repository browser.