Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/proxy: removed the dependency of the netdefs in pnode, which should decrease compile time enormously.

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