Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10578 was 9406, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

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#include <cassert>
20
21
22/**
23 * standard constructor
24 */
25SynchronizeableQuaternion::SynchronizeableQuaternion( Quaternion * ptrIn, Quaternion * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 4*INTSIZE, permission, priority )
26{
27  this->vPtrIn = ptrIn;
28  this->vPtrOut = ptrOut;
29}
30
31
32/**
33 * standard deconstructor
34 */
35SynchronizeableQuaternion::~SynchronizeableQuaternion ()
36{
37}
38
39/**
40 * write var data to byte buffer
41 * @param buf pointer to write to
42 * @param maxLength writeToBuf will not write more than maxLength bytes
43 * @return number bytes written
44 */
45int SynchronizeableQuaternion::writeToBuf( byte * buf, int maxLength )
46{
47  int n = 0;
48  int res;
49
50  res = Converter::floatToByteArray( vPtrIn->v.x, buf + n, maxLength - n );
51  assert( res > 0 );
52  n += res;
53
54  res = Converter::floatToByteArray( vPtrIn->v.y, buf + n, maxLength - n );
55  assert( res > 0 );
56  n += res;
57
58  res = Converter::floatToByteArray( vPtrIn->v.z, buf + n, maxLength - n );
59  assert( res > 0 );
60  n += res;
61
62  res = Converter::floatToByteArray( vPtrIn->w, buf +  n, maxLength - n );
63  assert( res > 0 );
64  n += res;
65
66  assert( 4*FLOATSIZE == n );
67
68  return n;
69}
70
71/**
72 * read var data from byte buffer
73 * @param buf pointer to read from
74 * @param maxLength readFromBuf will not read more than maxLength bytes
75 * @return number bytes read
76 */
77int SynchronizeableQuaternion::readFromBuf( byte * buf, int maxLength )
78{
79  assert( maxLength >= 4*FLOATSIZE );
80
81  float x,y,z,w;
82
83  int res;
84  int n = 0;
85
86  res = Converter::byteArrayToFloat( buf + n, &x );
87  assert( res > 0 );
88  n += res;
89
90  res = Converter::byteArrayToFloat( buf + n, &y );
91  assert( res > 0 );
92  n += res;
93
94  res = Converter::byteArrayToFloat( buf + n, &z );
95  assert( res > 0 );
96  n += res;
97
98  res = Converter::byteArrayToFloat( buf + n, &w );
99  assert( res > 0 );
100  n += res;
101
102  Quaternion oldVal = *vPtrOut;
103
104  *vPtrOut = Quaternion( Vector(x, y, z), w );
105
106  setHasChanged( ! ( oldVal == *vPtrOut ) );
107
108  assert( n == 4*FLOATSIZE );
109  return n;
110}
111
112
113/**
114 * print out variable value
115 */
116void SynchronizeableQuaternion::debug( )
117{
118  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 );
119}
120
Note: See TracBrowser for help on using the repository browser.