Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8690 was 7954, checked in by patrick, 18 years ago

trunk: merged the network branche back to trunk.

File size: 2.7 KB
RevLine 
[7444]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"
[7459]18#include "converter.h"
[7444]19
20
21/**
22 * standard constructor
[7459]23 */
24SynchronizeableQuaternion::SynchronizeableQuaternion( Quaternion * ptrIn, Quaternion * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 4*INTSIZE, permission, priority )
[7444]25{
26  this->vPtrIn = ptrIn;
27  this->vPtrOut = ptrOut;
28}
29
30
31/**
32 * standard deconstructor
[7459]33 */
[7444]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{
[7459]46  int n = 0;
47  int res;
[7559]48
49  res = Converter::floatToByteArray( vPtrIn->v.x, buf + n, maxLength - n );
[7459]50  assert( res > 0 );
51  n += res;
[7559]52
53  res = Converter::floatToByteArray( vPtrIn->v.y, buf + n, maxLength - n );
[7459]54  assert( res > 0 );
55  n += res;
[7559]56
57  res = Converter::floatToByteArray( vPtrIn->v.z, buf + n, maxLength - n );
[7459]58  assert( res > 0 );
59  n += res;
[7559]60
61  res = Converter::floatToByteArray( vPtrIn->w, buf +  n, maxLength - n );
[7459]62  assert( res > 0 );
63  n += res;
[7559]64
[7459]65  assert( 4*FLOATSIZE == n );
[7559]66
[7459]67  return n;
[7444]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{
[7459]78  assert( maxLength >= 4*FLOATSIZE );
[7559]79
[7459]80  float x,y,z,w;
[7559]81
[7459]82  int res;
83  int n = 0;
[7559]84
[7614]85  res = Converter::byteArrayToFloat( buf + n, &x );
[7459]86  assert( res > 0 );
87  n += res;
[7559]88
[7614]89  res = Converter::byteArrayToFloat( buf + n, &y );
[7459]90  assert( res > 0 );
91  n += res;
[7559]92
[7614]93  res = Converter::byteArrayToFloat( buf + n, &z );
[7459]94  assert( res > 0 );
95  n += res;
[7559]96
[7614]97  res = Converter::byteArrayToFloat( buf + n, &w );
[7459]98  assert( res > 0 );
99  n += res;
[7631]100 
101  Quaternion oldVal = *vPtrOut;
[7559]102
[7459]103  *vPtrOut = Quaternion( Vector(x, y, z), w );
[7631]104 
105  setHasChanged( ! ( oldVal == *vPtrOut ) );
[7559]106
[7614]107  assert( n == 4*FLOATSIZE );
108  return n;
[7459]109}
[7578]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.