19#ifndef HEADER_COMPRESS_NETWORK_BODY_HPP
20#define HEADER_COMPRESS_NETWORK_BODY_HPP
23#include "mini_glm.hpp"
25#include "LinearMath/btMotionState.h"
26#include "btBulletDynamicsCommon.h"
28namespace CompressNetworkBody
30 using namespace MiniGLM;
33 inline void setCompressedValues(
float x,
float y,
float z,
34 uint32_t compressed_q,
35 short lvx,
short lvy,
short lvz,
36 short avx,
short avy,
short avz,
37 btRigidBody* body, btMotionState* ms)
40 trans.setOrigin(btVector3(x,y,z));
41 trans.setRotation(decompressbtQuaternion(compressed_q));
42 btVector3 lv(toFloat32(lvx), toFloat32(lvy), toFloat32(lvz));
43 btVector3 av(toFloat32(avx), toFloat32(avy), toFloat32(avz));
45 body->setWorldTransform(trans);
46 ms->setWorldTransform(trans);
47 body->setInterpolationWorldTransform(trans);
48 body->setLinearVelocity(lv);
49 body->setAngularVelocity(av);
50 body->setInterpolationLinearVelocity(lv);
51 body->setInterpolationAngularVelocity(av);
52 body->updateInertiaTensor();
62 inline void compress(btRigidBody* body, btMotionState* ms,
65 float x = body->getWorldTransform().getOrigin().x();
66 float y = body->getWorldTransform().getOrigin().y();
67 float z = body->getWorldTransform().getOrigin().z();
68 uint32_t compressed_q =
69 compressQuaternion(body->getWorldTransform().getRotation());
70 short lvx = toFloat16(body->getLinearVelocity().x());
71 short lvy = toFloat16(body->getLinearVelocity().y());
72 short lvz = toFloat16(body->getLinearVelocity().z());
73 short avx = toFloat16(body->getAngularVelocity().x());
74 short avy = toFloat16(body->getAngularVelocity().y());
75 short avz = toFloat16(body->getAngularVelocity().z());
76 setCompressedValues(x, y, z, compressed_q, lvx, lvy, lvz, avx, avy,
82 bns->addFloat(x).addFloat(y).addFloat(z).addUInt32(compressed_q);
83 bns->addUInt16(lvx).addUInt16(lvy).addUInt16(lvz)
84 .addUInt16(avx).addUInt16(avy).addUInt16(avz);
89 btRigidBody* body, btMotionState* ms)
101 setCompressedValues(x, y, z, compressed_q, lvx, lvy, lvz, avx, avy,
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
float getFloat() const
Gets a 4 byte floating point value.
Definition: network_string.hpp:358
uint32_t getUInt32() const
Returns a unsigned 32 bit integer.
Definition: network_string.hpp:324
uint16_t getUInt16() const
Returns an unsigned 16 bit integer.
Definition: network_string.hpp:340
Defines functions to easily manipulate 8-bit network destinated strings.