Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/synchronizeable_var/synchronizeable_quaternion.cc @ 8040

Last change on this file since 8040 was 7954, checked in by patrick, 19 years ago

trunk: merged the network branche back to trunk.

File size: 2.7 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 + n, maxLength - n );
50  assert( res > 0 );
51  n += res;
52
53  res = Converter::floatToByteArray( vPtrIn->v.y, buf + n, maxLength - n );
54  assert( res > 0 );
55  n += res;
56
57  res = Converter::floatToByteArray( vPtrIn->v.z, buf + n, maxLength - n );
58  assert( res > 0 );
59  n += res;
60
61  res = Converter::floatToByteArray( vPtrIn->w, buf +  n, 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, &y );
90  assert( res > 0 );
91  n += res;
92
93  res = Converter::byteArrayToFloat( buf + n, &z );
94  assert( res > 0 );
95  n += res;
96
97  res = Converter::byteArrayToFloat( buf + n, &w );
98  assert( res > 0 );
99  n += res;
100 
101  Quaternion oldVal = *vPtrOut;
102
103  *vPtrOut = Quaternion( Vector(x, y, z), w );
104 
105  setHasChanged( ! ( oldVal == *vPtrOut ) );
106
107  assert( n == 4*FLOATSIZE );
108  return n;
109}
110
111
112/**
113 * print out variable value
114 */
115void SynchronizeableQuaternion::debug( )
116{
117  printf( "SYNCHRONIZEABLE_VAR: %s IN: ((%f, %f, %f), %f) OUT: ((%f %f %f), %f)\n", name.c_str(), vPtrIn->v.x, vPtrIn->v.y, vPtrIn->v.z, vPtrIn->w, vPtrOut->v.x, vPtrOut->v.y, vPtrOut->v.z, vPtrOut->w );
118}
119
Note: See TracBrowser for help on using the repository browser.