From 5d1ba857c55c402858edf678c07f6dcc9c236d0f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 27 May 2013 09:56:35 -0700 Subject: [PATCH 01/11] Optimize View Frustum wire format. - Changed View frstum orientaton to be a quaternion - Implemented packing formats for Orientation Quats, Ratios, and Clipping values - Changed wire format for View Frustum details to be more efficient 28 bytes vs 64 bytes --- interface/src/Application.cpp | 8 +- interface/src/Avatar.cpp | 2 +- interface/src/Head.cpp | 4 +- libraries/avatars/src/AvatarData.cpp | 167 +++++++++++++++++++-------- libraries/avatars/src/AvatarData.h | 50 +++++--- libraries/shared/src/SharedUtil.cpp | 1 + libraries/shared/src/SharedUtil.h | 1 + libraries/voxels/src/ViewFrustum.cpp | 42 +++++-- libraries/voxels/src/ViewFrustum.h | 29 ++--- voxel-server/src/VoxelAgentData.cpp | 2 +- 10 files changed, 210 insertions(+), 96 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a0979eb4b9..790a7f9495 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1092,7 +1092,7 @@ static void sendVoxelEditMessage(PACKET_HEADER header, VoxelDetail& detail) { void Application::addVoxelInFrontOfAvatar() { VoxelDetail detail; - glm::vec3 position = (_myAvatar.getPosition() + _myAvatar.getCameraDirection()) * (1.0f / TREE_SCALE); + glm::vec3 position = (_myAvatar.getPosition() + _myAvatar.calculateCameraDirection()) * (1.0f / TREE_SCALE); detail.s = _mouseVoxelScale; detail.x = detail.s * floor(position.x / detail.s); @@ -1347,9 +1347,7 @@ void Application::updateAvatar(float deltaTime) { // to the server. loadViewFrustum(_myCamera, _viewFrustum); _myAvatar.setCameraPosition(_viewFrustum.getPosition()); - _myAvatar.setCameraDirection(_viewFrustum.getDirection()); - _myAvatar.setCameraUp(_viewFrustum.getUp()); - _myAvatar.setCameraRight(_viewFrustum.getRight()); + _myAvatar.setCameraOrientation(_viewFrustum.getOrientation()); _myAvatar.setCameraFov(_viewFrustum.getFieldOfView()); _myAvatar.setCameraAspectRatio(_viewFrustum.getAspectRatio()); _myAvatar.setCameraNearClip(_viewFrustum.getNearClip()); @@ -1435,7 +1433,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { // Set the viewFrustum up with the correct position and orientation of the camera viewFrustum.setPosition(position); - viewFrustum.setOrientation(direction,up,right); + viewFrustum.setOrientation(o.getQuat()); // Also make sure it's got the correct lens details from the camera viewFrustum.setFieldOfView(fov); diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 8ce1abb05b..fce56ff670 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -80,8 +80,8 @@ Avatar::Avatar(Agent* owningAgent) : _bodyRollDelta(0.0f), _movedHandOffset(0.0f, 0.0f, 0.0f), _rotation(0.0f, 0.0f, 0.0f, 0.0f), - _cameraPosition(0.0f, 0.0f, 0.0f), _mode(AVATAR_MODE_STANDING), + _cameraPosition(0.0f, 0.0f, 0.0f), _handHoldingPosition(0.0f, 0.0f, 0.0f), _velocity(0.0f, 0.0f, 0.0f), _thrust(0.0f, 0.0f, 0.0f), diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 1486013c9c..736534f087 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -62,9 +62,9 @@ Head::Head(Avatar* owningAvatar) : _audioAttack(0.0f), _returnSpringScale(1.0f), _bodyRotation(0.0f, 0.0f, 0.0f), + _renderLookatVectors(false), _mohawkTriangleFan(NULL), - _mohawkColors(NULL), - _renderLookatVectors(false) { + _mohawkColors(NULL) { for (int t = 0; t < NUM_HAIR_TUFTS; t ++) { _hairTuft[t].length = HAIR_LENGTH; diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 4b97a2a047..fa0a8d1e20 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -17,20 +17,6 @@ using namespace std; -int packFloatAngleToTwoByte(unsigned char* buffer, float angle) { - const float ANGLE_CONVERSION_RATIO = (std::numeric_limits::max() / 360.0); - - uint16_t angleHolder = floorf((angle + 180) * ANGLE_CONVERSION_RATIO); - memcpy(buffer, &angleHolder, sizeof(uint16_t)); - - return sizeof(uint16_t); -} - -int unpackFloatAngleFromTwoByte(uint16_t* byteAnglePointer, float* destinationPointer) { - *destinationPointer = (*byteAnglePointer / (float) std::numeric_limits::max()) * 360.0 - 180; - return sizeof(uint16_t); -} - AvatarData::AvatarData(Agent* owningAgent) : AgentData(owningAgent), _handPosition(0,0,0), @@ -40,9 +26,7 @@ AvatarData::AvatarData(Agent* owningAgent) : _audioLoudness(0), _handState(0), _cameraPosition(0,0,0), - _cameraDirection(0,0,0), - _cameraUp(0,0,0), - _cameraRight(0,0,0), + _cameraOrientation(), _cameraFov(0.0f), _cameraAspectRatio(0.0f), _cameraNearClip(0.0f), @@ -110,20 +94,11 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { // camera details memcpy(destinationBuffer, &_cameraPosition, sizeof(_cameraPosition)); destinationBuffer += sizeof(_cameraPosition); - memcpy(destinationBuffer, &_cameraDirection, sizeof(_cameraDirection)); - destinationBuffer += sizeof(_cameraDirection); - memcpy(destinationBuffer, &_cameraRight, sizeof(_cameraRight)); - destinationBuffer += sizeof(_cameraRight); - memcpy(destinationBuffer, &_cameraUp, sizeof(_cameraUp)); - destinationBuffer += sizeof(_cameraUp); - memcpy(destinationBuffer, &_cameraFov, sizeof(_cameraFov)); - destinationBuffer += sizeof(_cameraFov); - memcpy(destinationBuffer, &_cameraAspectRatio, sizeof(_cameraAspectRatio)); - destinationBuffer += sizeof(_cameraAspectRatio); - memcpy(destinationBuffer, &_cameraNearClip, sizeof(_cameraNearClip)); - destinationBuffer += sizeof(_cameraNearClip); - memcpy(destinationBuffer, &_cameraFarClip, sizeof(_cameraFarClip)); - destinationBuffer += sizeof(_cameraFarClip); + destinationBuffer += packOrientationQuatToBytes(destinationBuffer, _cameraOrientation); + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _cameraFov); + destinationBuffer += packFloatRatioToTwoByte(destinationBuffer, _cameraAspectRatio); + destinationBuffer += packClipValueToTwoByte(destinationBuffer, _cameraNearClip); + destinationBuffer += packClipValueToTwoByte(destinationBuffer, _cameraFarClip); // key state *destinationBuffer++ = _keyState; @@ -204,21 +179,12 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { // camera details memcpy(&_cameraPosition, sourceBuffer, sizeof(_cameraPosition)); sourceBuffer += sizeof(_cameraPosition); - memcpy(&_cameraDirection, sourceBuffer, sizeof(_cameraDirection)); - sourceBuffer += sizeof(_cameraDirection); - memcpy(&_cameraRight, sourceBuffer, sizeof(_cameraRight)); - sourceBuffer += sizeof(_cameraRight); - memcpy(&_cameraUp, sourceBuffer, sizeof(_cameraUp)); - sourceBuffer += sizeof(_cameraUp); - memcpy(&_cameraFov, sourceBuffer, sizeof(_cameraFov)); - sourceBuffer += sizeof(_cameraFov); - memcpy(&_cameraAspectRatio, sourceBuffer, sizeof(_cameraAspectRatio)); - sourceBuffer += sizeof(_cameraAspectRatio); - memcpy(&_cameraNearClip, sourceBuffer, sizeof(_cameraNearClip)); - sourceBuffer += sizeof(_cameraNearClip); - memcpy(&_cameraFarClip, sourceBuffer, sizeof(_cameraFarClip)); - sourceBuffer += sizeof(_cameraFarClip); - + sourceBuffer += unpackOrientationQuatFromBytes(sourceBuffer, _cameraOrientation); + sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_cameraFov); + sourceBuffer += unpackFloatRatioFromTwoByte(sourceBuffer,_cameraAspectRatio); + sourceBuffer += unpackClipValueFromTwoByte(sourceBuffer,_cameraNearClip); + sourceBuffer += unpackClipValueFromTwoByte(sourceBuffer,_cameraFarClip); + // key state _keyState = (KeyState)*sourceBuffer++; @@ -236,3 +202,112 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { return sourceBuffer - startPosition; } + +glm::vec3 AvatarData::calculateCameraDirection() const { + const glm::vec3 IDENTITY_FRONT = glm::vec3( 0.0f, 0.0f, 1.0f); + glm::mat4 rotationMatrix = glm::mat4_cast(_cameraOrientation); + glm::vec3 direction = glm::vec3(glm::vec4(IDENTITY_FRONT, 0.0f) * rotationMatrix); + return direction; +} + + +int packFloatAngleToTwoByte(unsigned char* buffer, float angle) { + const float ANGLE_CONVERSION_RATIO = (std::numeric_limits::max() / 360.0); + + uint16_t angleHolder = floorf((angle + 180) * ANGLE_CONVERSION_RATIO); + memcpy(buffer, &angleHolder, sizeof(uint16_t)); + + return sizeof(uint16_t); +} + +int unpackFloatAngleFromTwoByte(uint16_t* byteAnglePointer, float* destinationPointer) { + *destinationPointer = (*byteAnglePointer / (float) std::numeric_limits::max()) * 360.0 - 180; + return sizeof(uint16_t); +} + +int packOrientationQuatToBytes(unsigned char* buffer, const glm::quat& quatInput) { + const float QUAT_PART_CONVERSION_RATIO = (std::numeric_limits::max() / 2.0); + uint16_t quatParts[4]; + quatParts[0] = floorf((quatInput.x + 1.0) * QUAT_PART_CONVERSION_RATIO); + quatParts[1] = floorf((quatInput.y + 1.0) * QUAT_PART_CONVERSION_RATIO); + quatParts[2] = floorf((quatInput.z + 1.0) * QUAT_PART_CONVERSION_RATIO); + quatParts[3] = floorf((quatInput.w + 1.0) * QUAT_PART_CONVERSION_RATIO); + + memcpy(buffer, &quatParts, sizeof(quatParts)); + return sizeof(quatParts); +} + +int unpackOrientationQuatFromBytes(unsigned char* buffer, glm::quat& quatOutput) { + uint16_t quatParts[4]; + memcpy(&quatParts, buffer, sizeof(quatParts)); + + quatOutput.x = ((quatParts[0] / (float) std::numeric_limits::max()) * 2.0) - 1.0; + quatOutput.y = ((quatParts[1] / (float) std::numeric_limits::max()) * 2.0) - 1.0; + quatOutput.z = ((quatParts[2] / (float) std::numeric_limits::max()) * 2.0) - 1.0; + quatOutput.w = ((quatParts[3] / (float) std::numeric_limits::max()) * 2.0) - 1.0; + + return sizeof(quatParts); +} + +float SMALL_LIMIT = 10.0; +float LARGE_LIMIT = 1000.0; + +int packFloatRatioToTwoByte(unsigned char* buffer, float ratio) { + // if the ratio is less than 10, then encode it as a positive number scaled from 0 to int16::max() + int16_t ratioHolder; + + if (ratio < SMALL_LIMIT) { + const float SMALL_RATIO_CONVERSION_RATIO = (std::numeric_limits::max() / SMALL_LIMIT); + ratioHolder = floorf(ratio * SMALL_RATIO_CONVERSION_RATIO); + } else { + const float LARGE_RATIO_CONVERSION_RATIO = std::numeric_limits::min() / LARGE_LIMIT; + ratioHolder = floorf((std::min(ratio,LARGE_LIMIT) - SMALL_LIMIT) * LARGE_RATIO_CONVERSION_RATIO); + } + memcpy(buffer, &ratioHolder, sizeof(ratioHolder)); + return sizeof(ratioHolder); +} + +int unpackFloatRatioFromTwoByte(unsigned char* buffer, float& ratio) { + int16_t ratioHolder; + memcpy(&ratioHolder, buffer, sizeof(ratioHolder)); + + // If it's positive, than the original ratio was less than SMALL_LIMIT + if (ratioHolder > 0) { + ratio = (ratioHolder / (float) std::numeric_limits::max()) * SMALL_LIMIT; + } else { + // If it's negative, than the original ratio was between SMALL_LIMIT and LARGE_LIMIT + ratio = ((ratioHolder / (float) std::numeric_limits::min()) * LARGE_LIMIT) + SMALL_LIMIT; + } + return sizeof(ratioHolder); +} + +int packClipValueToTwoByte(unsigned char* buffer, float clipValue) { + // Clip values must be less than max signed 16bit integers + assert(clipValue < std::numeric_limits::max()); + int16_t holder; + + // if the clip is less than 10, then encode it as a positive number scaled from 0 to int16::max() + if (clipValue < SMALL_LIMIT) { + const float SMALL_RATIO_CONVERSION_RATIO = (std::numeric_limits::max() / SMALL_LIMIT); + holder = floorf(clipValue * SMALL_RATIO_CONVERSION_RATIO); + } else { + // otherwise we store it as a negative integer + holder = -1 * floorf(clipValue); + } + memcpy(buffer, &holder, sizeof(holder)); + return sizeof(holder); +} + +int unpackClipValueFromTwoByte(unsigned char* buffer, float& clipValue) { + int16_t holder; + memcpy(&holder, buffer, sizeof(holder)); + + // If it's positive, than the original clipValue was less than SMALL_LIMIT + if (holder > 0) { + clipValue = (holder / (float) std::numeric_limits::max()) * SMALL_LIMIT; + } else { + // If it's negative, than the original holder can be found as the opposite sign of holder + clipValue = -1.0f * holder; + } + return sizeof(holder); +} diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 5773dedffd..d86cc6078b 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -12,6 +12,7 @@ #include #include +#include #include #include "HeadData.h" @@ -58,23 +59,21 @@ public: // getters for camera details const glm::vec3& getCameraPosition() const { return _cameraPosition; }; - const glm::vec3& getCameraDirection() const { return _cameraDirection; } - const glm::vec3& getCameraUp() const { return _cameraUp; } - const glm::vec3& getCameraRight() const { return _cameraRight; } + const glm::quat& getCameraOrientation() const { return _cameraOrientation; } float getCameraFov() const { return _cameraFov; } float getCameraAspectRatio() const { return _cameraAspectRatio; } float getCameraNearClip() const { return _cameraNearClip; } float getCameraFarClip() const { return _cameraFarClip; } + glm::vec3 calculateCameraDirection() const; + // setters for camera details - void setCameraPosition(const glm::vec3& position) { _cameraPosition = position; }; - void setCameraDirection(const glm::vec3& direction) { _cameraDirection = direction; } - void setCameraUp(const glm::vec3& up) { _cameraUp = up; } - void setCameraRight(const glm::vec3& right) { _cameraRight = right; } - void setCameraFov(float fov) { _cameraFov = fov; } - void setCameraAspectRatio(float aspectRatio) { _cameraAspectRatio = aspectRatio; } - void setCameraNearClip(float nearClip) { _cameraNearClip = nearClip; } - void setCameraFarClip(float farClip) { _cameraFarClip = farClip; } + void setCameraPosition(const glm::vec3& position) { _cameraPosition = position; } + void setCameraOrientation(const glm::quat& orientation) { _cameraOrientation = orientation; } + void setCameraFov(float fov) { _cameraFov = fov; } + void setCameraAspectRatio(float aspectRatio) { _cameraAspectRatio = aspectRatio; } + void setCameraNearClip(float nearClip) { _cameraNearClip = nearClip; } + void setCameraFarClip(float farClip) { _cameraFarClip = farClip; } // key state void setKeyState(KeyState s) { _keyState = s; } @@ -111,11 +110,7 @@ protected: // camera details for the avatar glm::vec3 _cameraPosition; - - // can we describe this in less space? For example, a Quaternion? or Euler angles? - glm::vec3 _cameraDirection; - glm::vec3 _cameraUp; - glm::vec3 _cameraRight; + glm::quat _cameraOrientation; float _cameraFov; float _cameraAspectRatio; float _cameraNearClip; @@ -139,4 +134,27 @@ private: AvatarData& operator= (const AvatarData&); }; + +// These pack/unpack functions are designed to start specific known types in as efficient a manner +// as possible. Taking advantage of the known characteristics of the semantic types. + +// Angles are known to be between 0 and 360deg, this allows us to encode in 16bits with great accuracy +int packFloatAngleToTwoByte(unsigned char* buffer, float angle); +int unpackFloatAngleFromTwoByte(uint16_t* byteAnglePointer, float* destinationPointer); + +// Orientation Quats are known to have 4 normalized components be between -1.0 and 1.0 +// this allows us to encode each component in 16bits with great accuracy +int packOrientationQuatToBytes(unsigned char* buffer, const glm::quat& quatInput); +int unpackOrientationQuatFromBytes(unsigned char* buffer, glm::quat& quatOutput); + +// Ratios need the be highly accurate when less than 10, but not very accurate above 10, and they +// are never greater than 1000 to 1, this allows us to encode each component in 16bits +int packFloatRatioToTwoByte(unsigned char* buffer, float ratio); +int unpackFloatRatioFromTwoByte(unsigned char* buffer, float& ratio); + +// Near/Far Clip values need the be highly accurate when less than 10, but only integer accuracy above 10 and +// they are never greater than 16,000, this allows us to encode each component in 16bits +int packClipValueToTwoByte(unsigned char* buffer, float clipValue); +int unpackClipValueFromTwoByte(unsigned char* buffer, float& clipValue); + #endif /* defined(__hifi__AvatarData__) */ diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index 5829bbe34a..ca31cdd994 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -421,3 +421,4 @@ int insertIntoSortedArrays(void* value, float key, int originalIndex, } return -1; // error case } + diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index 8da9d7beca..9d858f11e0 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -87,4 +87,5 @@ class debug { public: static const char* valueOf(bool checkValue) { return checkValue ? "yes" : "no"; }; }; + #endif /* defined(__hifi__SharedUtil__) */ diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 061727b003..0f10428b23 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -19,22 +19,40 @@ using namespace std; ViewFrustum::ViewFrustum() : - _position(glm::vec3(0,0,0)), - _direction(glm::vec3(0,0,0)), - _up(glm::vec3(0,0,0)), - _right(glm::vec3(0,0,0)), + _position(0,0,0), + _orientation(), + _direction(0,0,0), + _up(0,0,0), + _right(0,0,0), _fieldOfView(0.0), _aspectRatio(1.0), _nearClip(0.1), _farClip(500.0), - _farTopLeft(glm::vec3(0,0,0)), - _farTopRight(glm::vec3(0,0,0)), - _farBottomLeft(glm::vec3(0,0,0)), - _farBottomRight(glm::vec3(0,0,0)), - _nearTopLeft(glm::vec3(0,0,0)), - _nearTopRight(glm::vec3(0,0,0)), - _nearBottomLeft(glm::vec3(0,0,0)), - _nearBottomRight(glm::vec3(0,0,0)) { } + _farTopLeft(0,0,0), + _farTopRight(0,0,0), + _farBottomLeft(0,0,0), + _farBottomRight(0,0,0), + _nearTopLeft(0,0,0), + _nearTopRight(0,0,0), + _nearBottomLeft(0,0,0), + _nearBottomRight(0,0,0) { } + +void ViewFrustum::setOrientation(const glm::quat& orientationAsQuaternion) { + glm::quat quat; + quat = quat * orientationAsQuaternion; + + // this is where the coordinate system is represented + const glm::vec3 IDENTITY_RIGHT = glm::vec3(-1.0f, 0.0f, 0.0f); + const glm::vec3 IDENTITY_UP = glm::vec3( 0.0f, 1.0f, 0.0f); + const glm::vec3 IDENTITY_FRONT = glm::vec3( 0.0f, 0.0f, 1.0f); + + glm::mat4 rotationMatrix = glm::mat4_cast(quat); + + _orientation = orientationAsQuaternion; + _right = glm::vec3(glm::vec4(IDENTITY_RIGHT, 0.0f) * rotationMatrix); + _up = glm::vec3(glm::vec4(IDENTITY_UP, 0.0f) * rotationMatrix); + _direction = glm::vec3(glm::vec4(IDENTITY_FRONT, 0.0f) * rotationMatrix); +} ///////////////////////////////////////////////////////////////////////////////////// // ViewFrustum::calculateViewFrustum() diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index 1ae33d55ad..1c61160566 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -21,6 +21,9 @@ private: // camera location/orientation attributes glm::vec3 _position; + glm::quat _orientation; + + // calculated for orientation glm::vec3 _direction; glm::vec3 _up; glm::vec3 _right; @@ -53,23 +56,23 @@ private: public: // setters for camera attributes - void setPosition (const glm::vec3& p) { _position = p; } - void setOrientation (const glm::vec3& d, const glm::vec3& u, const glm::vec3& r ) - { _direction = d; _up = u; _right = r; } + void setPosition (const glm::vec3& p) { _position = p; }; + void setOrientation (const glm::quat& orientationAsQuaternion); // getters for camera attributes - const glm::vec3& getPosition() const { return _position; }; - const glm::vec3& getDirection() const { return _direction; }; - const glm::vec3& getUp() const { return _up; }; - const glm::vec3& getRight() const { return _right; }; + const glm::vec3& getPosition() const { return _position; }; + const glm::quat& getOrientation() const { return _orientation; }; + const glm::vec3& getDirection() const { return _direction; }; + const glm::vec3& getUp() const { return _up; }; + const glm::vec3& getRight() const { return _right; }; // setters for lens attributes - void setFieldOfView ( float f ) { _fieldOfView = f; } - void setAspectRatio ( float a ) { _aspectRatio = a; } - void setNearClip ( float n ) { _nearClip = n; } - void setFarClip ( float f ) { _farClip = f; } - void setEyeOffsetPosition (const glm::vec3& p) { _eyeOffsetPosition = p; } - void setEyeOffsetOrientation (const glm::quat& o) { _eyeOffsetOrientation = o; } + void setFieldOfView ( float f ) { _fieldOfView = f; }; + void setAspectRatio ( float a ) { _aspectRatio = a; }; + void setNearClip ( float n ) { _nearClip = n; }; + void setFarClip ( float f ) { _farClip = f; }; + void setEyeOffsetPosition (const glm::vec3& p) { _eyeOffsetPosition = p; }; + void setEyeOffsetOrientation (const glm::quat& o) { _eyeOffsetOrientation = o; }; // getters for lens attributes diff --git a/voxel-server/src/VoxelAgentData.cpp b/voxel-server/src/VoxelAgentData.cpp index 082fc5e7fc..289b1161e6 100644 --- a/voxel-server/src/VoxelAgentData.cpp +++ b/voxel-server/src/VoxelAgentData.cpp @@ -48,7 +48,7 @@ bool VoxelAgentData::updateCurrentViewFrustum() { ViewFrustum newestViewFrustum; // get position and orientation details from the camera newestViewFrustum.setPosition(getCameraPosition()); - newestViewFrustum.setOrientation(getCameraDirection(), getCameraUp(), getCameraRight()); + newestViewFrustum.setOrientation(getCameraOrientation()); // Also make sure it's got the correct lens details from the camera newestViewFrustum.setFieldOfView(getCameraFov()); From ddf4d7c748fb1bc6ca7389c839bd249264fae1be Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 27 May 2013 09:59:53 -0700 Subject: [PATCH 02/11] removed extra comment --- libraries/avatars/src/AvatarData.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index fa0a8d1e20..b5ef015c7b 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -108,7 +108,6 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { memcpy(destinationBuffer, _chatMessage.data(), _chatMessage.size() * sizeof(char)); destinationBuffer += _chatMessage.size() * sizeof(char); - // voxel sending features... // voxel sending features... unsigned char wantItems = 0; if (_wantResIn) { setAtBit(wantItems,WANT_RESIN_AT_BIT); } From 04f4e499e131c88a74cb66ecc96dc71ee86c8cbf Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 27 May 2013 14:10:51 -0700 Subject: [PATCH 03/11] Optimize wire-format for AvatarData - moved HandState into semi-nibble in bitItems - moved KeyState into semi-nibble in bitItems - moved AudioLoudness into scaled float stored as byte - overall savings - 5 bytes --- interface/src/AvatarTouch.h | 2 +- libraries/avatars/src/AvatarData.cpp | 72 ++++++++++++++++------------ libraries/avatars/src/AvatarData.h | 12 ++++- libraries/shared/src/SharedUtil.cpp | 9 ++++ libraries/shared/src/SharedUtil.h | 4 ++ 5 files changed, 66 insertions(+), 33 deletions(-) diff --git a/interface/src/AvatarTouch.h b/interface/src/AvatarTouch.h index 2111c0ecf1..cc4d21ae82 100644 --- a/interface/src/AvatarTouch.h +++ b/interface/src/AvatarTouch.h @@ -12,7 +12,7 @@ enum AvatarHandState { - HAND_STATE_NULL = -1, + HAND_STATE_NULL = 0, HAND_STATE_OPEN, HAND_STATE_GRASPING, HAND_STATE_POINTING, diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index b5ef015c7b..1c126b7587 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -83,13 +83,8 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { memcpy(destinationBuffer, &_headData->_lookAtPosition, sizeof(_headData->_lookAtPosition)); destinationBuffer += sizeof(_headData->_lookAtPosition); - // Hand State (0 = not grabbing, 1 = grabbing) - memcpy(destinationBuffer, &_handState, sizeof(char)); - destinationBuffer += sizeof(char); - // Instantaneous audio loudness (used to drive facial animation) - memcpy(destinationBuffer, &_audioLoudness, sizeof(float)); - destinationBuffer += sizeof(float); + destinationBuffer += packFloatToByte(destinationBuffer, std::min(MAX_AUDIO_LOUDNESS, _audioLoudness), MAX_AUDIO_LOUDNESS); // camera details memcpy(destinationBuffer, &_cameraPosition, sizeof(_cameraPosition)); @@ -100,20 +95,22 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { destinationBuffer += packClipValueToTwoByte(destinationBuffer, _cameraNearClip); destinationBuffer += packClipValueToTwoByte(destinationBuffer, _cameraFarClip); - // key state - *destinationBuffer++ = _keyState; - // chat message *destinationBuffer++ = _chatMessage.size(); memcpy(destinationBuffer, _chatMessage.data(), _chatMessage.size() * sizeof(char)); destinationBuffer += _chatMessage.size() * sizeof(char); - // voxel sending features... - unsigned char wantItems = 0; - if (_wantResIn) { setAtBit(wantItems,WANT_RESIN_AT_BIT); } - if (_wantColor) { setAtBit(wantItems,WANT_COLOR_AT_BIT); } - if (_wantDelta) { setAtBit(wantItems,WANT_DELTA_AT_BIT); } - *destinationBuffer++ = wantItems; + // bitMask of less than byte wide items + unsigned char bitItems = 0; + if (_wantResIn) { setAtBit(bitItems,WANT_RESIN_AT_BIT); } + if (_wantColor) { setAtBit(bitItems,WANT_COLOR_AT_BIT); } + if (_wantDelta) { setAtBit(bitItems,WANT_DELTA_AT_BIT); } + + // key state + setSemiNibbleAt(bitItems,KEY_STATE_START_BIT,_keyState); + // hand state + setSemiNibbleAt(bitItems,HAND_STATE_START_BIT,_handState); + *destinationBuffer++ = bitItems; return destinationBuffer - bufferStart; } @@ -162,18 +159,13 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { // Hand Position memcpy(&_handPosition, sourceBuffer, sizeof(float) * 3); sourceBuffer += sizeof(float) * 3; - + // Lookat Position memcpy(&_headData->_lookAtPosition, sourceBuffer, sizeof(_headData->_lookAtPosition)); sourceBuffer += sizeof(_headData->_lookAtPosition); - - // Hand State - memcpy(&_handState, sourceBuffer, sizeof(char)); - sourceBuffer += sizeof(char); - + // Instantaneous audio loudness (used to drive facial animation) - memcpy(&_audioLoudness, sourceBuffer, sizeof(float)); - sourceBuffer += sizeof(float); + sourceBuffer += unpackFloatFromByte(sourceBuffer, _audioLoudness, MAX_AUDIO_LOUDNESS); // camera details memcpy(&_cameraPosition, sourceBuffer, sizeof(_cameraPosition)); @@ -184,20 +176,23 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { sourceBuffer += unpackClipValueFromTwoByte(sourceBuffer,_cameraNearClip); sourceBuffer += unpackClipValueFromTwoByte(sourceBuffer,_cameraFarClip); - // key state - _keyState = (KeyState)*sourceBuffer++; - // the rest is a chat message int chatMessageSize = *sourceBuffer++; _chatMessage = string((char*)sourceBuffer, chatMessageSize); sourceBuffer += chatMessageSize * sizeof(char); // voxel sending features... - unsigned char wantItems = 0; - wantItems = (unsigned char)*sourceBuffer++; - _wantResIn = oneAtBit(wantItems,WANT_RESIN_AT_BIT); - _wantColor = oneAtBit(wantItems,WANT_COLOR_AT_BIT); - _wantDelta = oneAtBit(wantItems,WANT_DELTA_AT_BIT); + unsigned char bitItems = 0; + bitItems = (unsigned char)*sourceBuffer++; + _wantResIn = oneAtBit(bitItems,WANT_RESIN_AT_BIT); + _wantColor = oneAtBit(bitItems,WANT_COLOR_AT_BIT); + _wantDelta = oneAtBit(bitItems,WANT_DELTA_AT_BIT); + + // key state, stored as a semi-nibble in the bitItems + _keyState = (KeyState)getSemiNibbleAt(bitItems,KEY_STATE_START_BIT); + + // hand state, stored as a semi-nibble in the bitItems + _handState = getSemiNibbleAt(bitItems,HAND_STATE_START_BIT); return sourceBuffer - startPosition; } @@ -310,3 +305,18 @@ int unpackClipValueFromTwoByte(unsigned char* buffer, float& clipValue) { } return sizeof(holder); } + +int packFloatToByte(unsigned char* buffer, float value, float scaleBy) { + unsigned char holder; + const float CONVERSION_RATIO = (255 / scaleBy); + holder = floorf(value * CONVERSION_RATIO); + memcpy(buffer, &holder, sizeof(holder)); + return sizeof(holder); +} + +int unpackFloatFromByte(unsigned char* buffer, float& value, float scaleBy) { + unsigned char holder; + memcpy(&holder, buffer, sizeof(holder)); + value = ((float)holder / (float) 255) * scaleBy; + return sizeof(holder); +} diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index d86cc6078b..04bc7e6ad5 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -20,10 +20,15 @@ const int WANT_RESIN_AT_BIT = 0; const int WANT_COLOR_AT_BIT = 1; const int WANT_DELTA_AT_BIT = 2; +const int KEY_STATE_START_BIT = 3; // 4th and 5th bits +const int HAND_STATE_START_BIT = 5; // 6th and 7th bits + +const float MAX_AUDIO_LOUDNESS = 1000.0; // close enough for mouth animation + enum KeyState { - NO_KEY_DOWN, + NO_KEY_DOWN = 0, INSERT_KEY_DOWN, DELETE_KEY_DOWN }; @@ -157,4 +162,9 @@ int unpackFloatRatioFromTwoByte(unsigned char* buffer, float& ratio); int packClipValueToTwoByte(unsigned char* buffer, float clipValue); int unpackClipValueFromTwoByte(unsigned char* buffer, float& clipValue); +// Positive floats that don't need to be very precise +int packFloatToByte(unsigned char* buffer, float value, float scaleBy); +int unpackFloatFromByte(unsigned char* buffer, float& value, float scaleBy); + + #endif /* defined(__hifi__AvatarData__) */ diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index ca31cdd994..10967ea3e7 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -101,6 +101,15 @@ void setAtBit(unsigned char& byte, int bitIndex) { byte += (1 << (7 - bitIndex)); } +int getSemiNibbleAt(unsigned char& byte, int bitIndex) { + return (byte >> (7 - bitIndex) & 3); // semi-nibbles store 00, 01, 10, or 11 +} + +void setSemiNibbleAt(unsigned char& byte, int bitIndex, int value) { + assert(value <= 3 && value >= 0); + byte += ((value & 3) << (7 - bitIndex)); // semi-nibbles store 00, 01, 10, or 11 +} + void switchToResourcesParentIfRequired() { #ifdef __APPLE__ diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index 9d858f11e0..75c00c71f7 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -53,6 +53,10 @@ int numberOfOnes(unsigned char byte); bool oneAtBit(unsigned char byte, int bitIndex); void setAtBit(unsigned char& byte, int bitIndex); +int getSemiNibbleAt(unsigned char& byte, int bitIndex); +void setSemiNibbleAt(unsigned char& byte, int bitIndex, int value); + + void switchToResourcesParentIfRequired(); void loadRandomIdentifier(unsigned char* identifierBuffer, int numBytes); From b3045ea6811de31fd500924b78aa45dc255619af Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 28 May 2013 16:11:07 -0700 Subject: [PATCH 04/11] working on handPosition optimizations --- libraries/avatars/src/AvatarData.cpp | 109 +++++++++++++++++++++++++-- libraries/avatars/src/AvatarData.h | 3 + 2 files changed, 107 insertions(+), 5 deletions(-) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 1c126b7587..7baee5f06a 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -75,8 +75,16 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { memcpy(destinationBuffer, &_headData->_leanForward, sizeof(_headData->_leanForward)); destinationBuffer += sizeof(_headData->_leanForward); - // Hand Position - memcpy(destinationBuffer, &_handPosition, sizeof(float) * 3); + // Hand Position - is relative to body position + glm::vec3 handPositionRelative = _handPosition - _position; + memcpy(destinationBuffer, &handPositionRelative, sizeof(float) * 3); + + printf("handPositionRelative=%f,%f,%f\n",handPositionRelative.x, handPositionRelative.y, handPositionRelative.z); + printf("_handPosition=%f,%f,%f\n",_handPosition.x, _handPosition.y, _handPosition.z); + printf("_position=%f,%f,%f\n",_position.x, _position.y, _position.z); + +packVec3ToBytes(NULL, handPositionRelative, -1.0f , 1.0f, 4); + destinationBuffer += sizeof(float) * 3; // Lookat Position @@ -156,10 +164,15 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { memcpy(&_headData->_leanForward, sourceBuffer, sizeof(_headData->_leanForward)); sourceBuffer += sizeof(_headData->_leanForward); - // Hand Position - memcpy(&_handPosition, sourceBuffer, sizeof(float) * 3); + // Hand Position - is relative to body position + glm::vec3 handPositionRelative; + memcpy(&handPositionRelative, sourceBuffer, sizeof(float) * 3); + _handPosition = _position + handPositionRelative; sourceBuffer += sizeof(float) * 3; - + printf("handPositionRelative=%f,%f,%f\n",handPositionRelative.x, handPositionRelative.y, handPositionRelative.z); + printf("_handPosition=%f,%f,%f\n",_handPosition.x, _handPosition.y, _handPosition.z); + printf("_position=%f,%f,%f\n",_position.x, _position.y, _position.z); + // Lookat Position memcpy(&_headData->_lookAtPosition, sourceBuffer, sizeof(_headData->_lookAtPosition)); sourceBuffer += sizeof(_headData->_lookAtPosition); @@ -320,3 +333,89 @@ int unpackFloatFromByte(unsigned char* buffer, float& value, float scaleBy) { value = ((float)holder / (float) 255) * scaleBy; return sizeof(holder); } + +int packVec3ToBytes(unsigned char* buffer, const glm::vec3& vec, float min, float max, int bytes) { + const int ITEMS_IN_VEC3 = 3; + const int BITS_IN_BYTE = 8; + const int BYTE_MASK = 0xff; + assert(bytes < sizeof(double) * ITEMS_IN_VEC3); + unsigned char holder[bytes]; + memset(&holder, 0, bytes); + + int bitsTotal = bytes * BITS_IN_BYTE; + int bitsPerItem = floor(bitsTotal / ITEMS_IN_VEC3); + long maxEncodedPerItem = powf(2, bitsPerItem) - 1; // must be a better way to get this + float scaleBy = (max - min); + float conversionRatio = (maxEncodedPerItem / scaleBy); + +printf("bitsTotal=%d\n", bitsTotal); +printf("bitsPerItem=%d\n", bitsPerItem); +printf("maxEncodedPerItem=%ld\n", maxEncodedPerItem); +printf("scaleBy=%f\n", scaleBy); +printf("conversionRatio=%f\n", conversionRatio); + + int bitInByte = 0; + int byteInHolder = 0; + long encodedItem = 0; + int leftShiftThisByte = 0; + + for (int i = 0; i < ITEMS_IN_VEC3; i++) { + +printf(">>> item=%d\n", i); +printf("vec[item]=%f\n", vec[i]); + + long encodedItemMask = maxEncodedPerItem; + encodedItem = floorf((vec[i] - min) * conversionRatio); + +printf("encodedItem=%ld\n", encodedItem); +printf("encodedItemMask=%ld\n", encodedItemMask); +printf("leftShiftThisByte=%d\n", leftShiftThisByte); + + for (int bitsInThisItem = 0; bitsInThisItem < bitsPerItem; ) { + +printf(">>> bitsInThisItem=%d\n", bitsInThisItem); + + unsigned char thisBytePortion = (encodedItemMask << leftShiftThisByte) & BYTE_MASK; + +printf("thisBytePortion=%d\n", (int)thisBytePortion); + + unsigned char thisByteValue = (encodedItem << leftShiftThisByte) & thisBytePortion; + +printf("thisByteValue=%d\n", (int)thisByteValue); + + holder[byteInHolder] |= thisByteValue; + +printf("after byte %d: ", byteInHolder); +outputBufferBits((unsigned char*)&holder, bytes); + + +///////not handling this correctly... second portion of second item is not moving to 3rd byte... + + leftShiftThisByte = 0; // reset after first time; + int numberOfBitsInThisByte = numberOfOnes(thisBytePortion); + bitsInThisItem += numberOfBitsInThisByte; + if (numberOfBitsInThisByte == 8) { + byteInHolder++; + encodedItemMask = encodedItemMask >> numberOfBitsInThisByte; + encodedItem = encodedItem >> numberOfBitsInThisByte; + } else { + leftShiftThisByte = numberOfBitsInThisByte; + } +printf("numberOfBitsInThisByte=%d\n", numberOfBitsInThisByte); +printf("AFTER bitsInThisItem=%d\n", bitsInThisItem); +printf("AFTER encodedItem=%ld\n", encodedItem); +printf("AFTER encodedItemMask=%ld\n", encodedItemMask); + } + } + + printf("done: "); + outputBufferBits((unsigned char*)&holder, bytes); + + //memcpy(buffer, &holder, sizeof(holder)); + return sizeof(holder); +} + +int unpackVec3FromBytes(unsigned char* buffer, glm::vec3& vec, float min, float max, int bytes) { + unsigned char holder[bytes]; + return sizeof(holder); +} diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 04bc7e6ad5..b530fe285d 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -166,5 +166,8 @@ int unpackClipValueFromTwoByte(unsigned char* buffer, float& clipValue); int packFloatToByte(unsigned char* buffer, float value, float scaleBy); int unpackFloatFromByte(unsigned char* buffer, float& value, float scaleBy); +int unpackVec3FromBytes(unsigned char* buffer, glm::vec3& vec, float min, float max, int bytes); +int packVec3ToBytes(unsigned char* buffer, const glm::vec3& vec, float min, float max, int bytes); + #endif /* defined(__hifi__AvatarData__) */ From eef06366555ae3d72d40c6c6092f36a36277a05a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 3 Jun 2013 21:53:06 -0700 Subject: [PATCH 05/11] some cleanup --- interface/src/Application.cpp | 16 +---- interface/src/Avatar.cpp | 1 - libraries/avatars/src/AvatarData.cpp | 100 +-------------------------- libraries/avatars/src/AvatarData.h | 4 -- 4 files changed, 2 insertions(+), 119 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9abe3d4510..d48935ae27 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1560,24 +1560,10 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { float farClip = camera.getFarClip(); glm::quat rotation = camera.getRotation(); - glm::vec3 direction = rotation * AVATAR_FRONT; - glm::vec3 up = rotation * AVATAR_UP; - glm::vec3 right = rotation * AVATAR_RIGHT; - /* - printf("position.x=%f, position.y=%f, position.z=%f\n", position.x, position.y, position.z); - printf("yaw=%f, pitch=%f, roll=%f\n", yaw,pitch,roll); - printf("direction.x=%f, direction.y=%f, direction.z=%f\n", direction.x, direction.y, direction.z); - printf("up.x=%f, up.y=%f, up.z=%f\n", up.x, up.y, up.z); - printf("right.x=%f, right.y=%f, right.z=%f\n", right.x, right.y, right.z); - printf("fov=%f\n", fov); - printf("nearClip=%f\n", nearClip); - printf("farClip=%f\n", farClip); - */ - // Set the viewFrustum up with the correct position and orientation of the camera viewFrustum.setPosition(position); - viewFrustum.setOrientation(o.getQuat()); + viewFrustum.setOrientation(rotation); // Also make sure it's got the correct lens details from the camera viewFrustum.setFieldOfView(fov); diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index b1a56f723f..3949120737 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -72,7 +72,6 @@ Avatar::Avatar(Agent* owningAgent) : _bodyYawDelta(0.0f), _bodyRollDelta(0.0f), _movedHandOffset(0.0f, 0.0f, 0.0f), - _rotation(0.0f, 0.0f, 0.0f, 0.0f), _mode(AVATAR_MODE_STANDING), _cameraPosition(0.0f, 0.0f, 0.0f), _handHoldingPosition(0.0f, 0.0f, 0.0f), diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 41812f8d3a..6ff6967b61 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -78,13 +78,6 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { // Hand Position - is relative to body position glm::vec3 handPositionRelative = _handPosition - _position; memcpy(destinationBuffer, &handPositionRelative, sizeof(float) * 3); - - printf("handPositionRelative=%f,%f,%f\n",handPositionRelative.x, handPositionRelative.y, handPositionRelative.z); - printf("_handPosition=%f,%f,%f\n",_handPosition.x, _handPosition.y, _handPosition.z); - printf("_position=%f,%f,%f\n",_position.x, _position.y, _position.z); - -packVec3ToBytes(NULL, handPositionRelative, -1.0f , 1.0f, 4); - destinationBuffer += sizeof(float) * 3; // Lookat Position @@ -92,12 +85,9 @@ packVec3ToBytes(NULL, handPositionRelative, -1.0f , 1.0f, 4); destinationBuffer += sizeof(_headData->_lookAtPosition); // Instantaneous audio loudness (used to drive facial animation) -<<<<<<< HEAD - destinationBuffer += packFloatToByte(destinationBuffer, std::min(MAX_AUDIO_LOUDNESS, _audioLoudness), MAX_AUDIO_LOUDNESS); -======= + //destinationBuffer += packFloatToByte(destinationBuffer, std::min(MAX_AUDIO_LOUDNESS, _audioLoudness), MAX_AUDIO_LOUDNESS); memcpy(destinationBuffer, &_headData->_audioLoudness, sizeof(float)); destinationBuffer += sizeof(float); ->>>>>>> c7921c4be90dc45a82793845a9a55b77a3fb5a3f // camera details memcpy(destinationBuffer, &_cameraPosition, sizeof(_cameraPosition)); @@ -174,9 +164,6 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { memcpy(&handPositionRelative, sourceBuffer, sizeof(float) * 3); _handPosition = _position + handPositionRelative; sourceBuffer += sizeof(float) * 3; - printf("handPositionRelative=%f,%f,%f\n",handPositionRelative.x, handPositionRelative.y, handPositionRelative.z); - printf("_handPosition=%f,%f,%f\n",_handPosition.x, _handPosition.y, _handPosition.z); - printf("_position=%f,%f,%f\n",_position.x, _position.y, _position.z); // Lookat Position memcpy(&_headData->_lookAtPosition, sourceBuffer, sizeof(_headData->_lookAtPosition)); @@ -341,88 +328,3 @@ int unpackFloatFromByte(unsigned char* buffer, float& value, float scaleBy) { return sizeof(holder); } -int packVec3ToBytes(unsigned char* buffer, const glm::vec3& vec, float min, float max, int bytes) { - const int ITEMS_IN_VEC3 = 3; - const int BITS_IN_BYTE = 8; - const int BYTE_MASK = 0xff; - assert(bytes < sizeof(double) * ITEMS_IN_VEC3); - unsigned char holder[bytes]; - memset(&holder, 0, bytes); - - int bitsTotal = bytes * BITS_IN_BYTE; - int bitsPerItem = floor(bitsTotal / ITEMS_IN_VEC3); - long maxEncodedPerItem = powf(2, bitsPerItem) - 1; // must be a better way to get this - float scaleBy = (max - min); - float conversionRatio = (maxEncodedPerItem / scaleBy); - -printf("bitsTotal=%d\n", bitsTotal); -printf("bitsPerItem=%d\n", bitsPerItem); -printf("maxEncodedPerItem=%ld\n", maxEncodedPerItem); -printf("scaleBy=%f\n", scaleBy); -printf("conversionRatio=%f\n", conversionRatio); - - int bitInByte = 0; - int byteInHolder = 0; - long encodedItem = 0; - int leftShiftThisByte = 0; - - for (int i = 0; i < ITEMS_IN_VEC3; i++) { - -printf(">>> item=%d\n", i); -printf("vec[item]=%f\n", vec[i]); - - long encodedItemMask = maxEncodedPerItem; - encodedItem = floorf((vec[i] - min) * conversionRatio); - -printf("encodedItem=%ld\n", encodedItem); -printf("encodedItemMask=%ld\n", encodedItemMask); -printf("leftShiftThisByte=%d\n", leftShiftThisByte); - - for (int bitsInThisItem = 0; bitsInThisItem < bitsPerItem; ) { - -printf(">>> bitsInThisItem=%d\n", bitsInThisItem); - - unsigned char thisBytePortion = (encodedItemMask << leftShiftThisByte) & BYTE_MASK; - -printf("thisBytePortion=%d\n", (int)thisBytePortion); - - unsigned char thisByteValue = (encodedItem << leftShiftThisByte) & thisBytePortion; - -printf("thisByteValue=%d\n", (int)thisByteValue); - - holder[byteInHolder] |= thisByteValue; - -printf("after byte %d: ", byteInHolder); -outputBufferBits((unsigned char*)&holder, bytes); - - -///////not handling this correctly... second portion of second item is not moving to 3rd byte... - - leftShiftThisByte = 0; // reset after first time; - int numberOfBitsInThisByte = numberOfOnes(thisBytePortion); - bitsInThisItem += numberOfBitsInThisByte; - if (numberOfBitsInThisByte == 8) { - byteInHolder++; - encodedItemMask = encodedItemMask >> numberOfBitsInThisByte; - encodedItem = encodedItem >> numberOfBitsInThisByte; - } else { - leftShiftThisByte = numberOfBitsInThisByte; - } -printf("numberOfBitsInThisByte=%d\n", numberOfBitsInThisByte); -printf("AFTER bitsInThisItem=%d\n", bitsInThisItem); -printf("AFTER encodedItem=%ld\n", encodedItem); -printf("AFTER encodedItemMask=%ld\n", encodedItemMask); - } - } - - printf("done: "); - outputBufferBits((unsigned char*)&holder, bytes); - - //memcpy(buffer, &holder, sizeof(holder)); - return sizeof(holder); -} - -int unpackVec3FromBytes(unsigned char* buffer, glm::vec3& vec, float min, float max, int bytes) { - unsigned char holder[bytes]; - return sizeof(holder); -} diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 7bf4be1382..d728ff53d8 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -164,8 +164,4 @@ int unpackClipValueFromTwoByte(unsigned char* buffer, float& clipValue); int packFloatToByte(unsigned char* buffer, float value, float scaleBy); int unpackFloatFromByte(unsigned char* buffer, float& value, float scaleBy); -int unpackVec3FromBytes(unsigned char* buffer, glm::vec3& vec, float min, float max, int bytes); -int packVec3ToBytes(unsigned char* buffer, const glm::vec3& vec, float min, float max, int bytes); - - #endif /* defined(__hifi__AvatarData__) */ From ceb15d407df6a5ee5f43506ffb14679e2fbe344c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 3 Jun 2013 22:08:19 -0700 Subject: [PATCH 06/11] removed assert --- libraries/shared/src/SharedUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index 10967ea3e7..08b84e2b7e 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -106,7 +106,7 @@ int getSemiNibbleAt(unsigned char& byte, int bitIndex) { } void setSemiNibbleAt(unsigned char& byte, int bitIndex, int value) { - assert(value <= 3 && value >= 0); + //assert(value <= 3 && value >= 0); byte += ((value & 3) << (7 - bitIndex)); // semi-nibbles store 00, 01, 10, or 11 } From edf6e767f02bed6c75dea1279e8ba360dab4d913 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Jun 2013 09:35:38 -0700 Subject: [PATCH 07/11] removed unused variable --- interface/src/Head.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index bbf773a8a9..21df933416 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -595,7 +595,7 @@ void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosi void Head::updateHairPhysics(float deltaTime) { glm::quat orientation = getOrientation(); - glm::vec3 right = orientation * AVATAR_RIGHT; + //glm::vec3 right = orientation * AVATAR_RIGHT; // not used for now glm::vec3 up = orientation * AVATAR_UP; glm::vec3 front = orientation * AVATAR_FRONT; From a12353e112081c78c439c7cb5dbb68b3e40d1416 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Jun 2013 11:38:47 -0700 Subject: [PATCH 08/11] hopefully fix unix build buster --- libraries/avatars/src/AvatarData.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index d728ff53d8..0fc1104a0a 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -10,6 +10,7 @@ #define __hifi__AvatarData__ #include +#include #include #include From 4f2af717f29baed7906ff732c0ac9a887d7560e8 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Jun 2013 17:27:40 -0700 Subject: [PATCH 09/11] Fixed merge issue with new orientation vectors, migrated to common identity names --- interface/src/Avatar.cpp | 16 ++++----- interface/src/Avatar.h | 6 ++-- interface/src/Head.cpp | 47 +++++++++++++-------------- interface/src/Head.h | 6 ++-- interface/src/Util.cpp | 8 +++-- libraries/avatars/src/AvatarData.cpp | 4 +-- libraries/avatars/src/AvatarData.h | 5 --- libraries/voxels/src/ViewFrustum.cpp | 17 +++------- libraries/voxels/src/VoxelConstants.h | 5 +++ 9 files changed, 52 insertions(+), 62 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 4a3e8db2bc..dde6bca334 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -427,9 +427,9 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { } glm::quat orientation = getOrientation(); - glm::vec3 front = orientation * AVATAR_FRONT; - glm::vec3 right = orientation * AVATAR_RIGHT; - glm::vec3 up = orientation * AVATAR_UP; + glm::vec3 front = orientation * IDENTITY_FRONT; + glm::vec3 right = orientation * IDENTITY_RIGHT; + glm::vec3 up = orientation * IDENTITY_UP; // driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely) const float THRUST_MAG = 600.0f; @@ -649,9 +649,9 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { glm::quat orientation = getOrientation(); // reset hand and arm positions according to hand movement - glm::vec3 right = orientation * AVATAR_RIGHT; - glm::vec3 up = orientation * AVATAR_UP; - glm::vec3 front = orientation * AVATAR_FRONT; + glm::vec3 right = orientation * IDENTITY_RIGHT; + glm::vec3 up = orientation * IDENTITY_UP; + glm::vec3 front = orientation * IDENTITY_FRONT; glm::vec3 transformedHandMovement = right * _movedHandOffset.x * 2.0f @@ -1123,14 +1123,14 @@ void Avatar::updateArmIKAndConstraints(float deltaTime) { glm::quat Avatar::computeRotationFromBodyToWorldUp(float proportion) const { glm::quat orientation = getOrientation(); - glm::vec3 currentUp = orientation * AVATAR_UP; + glm::vec3 currentUp = orientation * IDENTITY_UP; float angle = glm::degrees(acosf(glm::clamp(glm::dot(currentUp, _worldUpDirection), -1.0f, 1.0f))); if (angle < EPSILON) { return glm::quat(); } glm::vec3 axis; if (angle > 179.99f) { // 180 degree rotation; must use another axis - axis = orientation * AVATAR_RIGHT; + axis = orientation * IDENTITY_RIGHT; } else { axis = glm::normalize(glm::cross(currentUp, _worldUpDirection)); } diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 20c431ef82..58e7127957 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -106,9 +106,9 @@ public: bool getIsNearInteractingOther () const { return _avatarTouch.getAbleToReachOtherAvatar();} const glm::vec3& getHeadJointPosition () const { return _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].position;} const glm::vec3& getBallPosition (AvatarJointID j) const { return _bodyBall[j].position;} - glm::vec3 getBodyRightDirection () const { return getOrientation() * AVATAR_RIGHT; } - glm::vec3 getBodyUpDirection () const { return getOrientation() * AVATAR_UP; } - glm::vec3 getBodyFrontDirection () const { return getOrientation() * AVATAR_FRONT; } + glm::vec3 getBodyRightDirection () const { return getOrientation() * IDENTITY_RIGHT; } + glm::vec3 getBodyUpDirection () const { return getOrientation() * IDENTITY_UP; } + glm::vec3 getBodyFrontDirection () const { return getOrientation() * IDENTITY_FRONT; } const glm::vec3& getVelocity () const { return _velocity;} float getSpeed () const { return _speed;} float getHeight () const { return _height;} diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 21df933416..98e5c57cb1 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -171,9 +171,9 @@ void Head::determineIfLookingAtSomething() { void Head::calculateGeometry() { //generate orientation directions glm::quat orientation = getOrientation(); - glm::vec3 right = orientation * AVATAR_RIGHT; - glm::vec3 up = orientation * AVATAR_UP; - glm::vec3 front = orientation * AVATAR_FRONT; + glm::vec3 right = orientation * IDENTITY_RIGHT; + glm::vec3 up = orientation * IDENTITY_UP; + glm::vec3 front = orientation * IDENTITY_FRONT; //calculate the eye positions _leftEyePosition = _position @@ -346,9 +346,9 @@ void Head::renderMouth() { float s = sqrt(_averageLoudness); glm::quat orientation = getOrientation(); - glm::vec3 right = orientation * AVATAR_RIGHT; - glm::vec3 up = orientation * AVATAR_UP; - glm::vec3 front = orientation * AVATAR_FRONT; + glm::vec3 right = orientation * IDENTITY_RIGHT; + glm::vec3 up = orientation * IDENTITY_UP; + glm::vec3 front = orientation * IDENTITY_FRONT; glm::vec3 r = right * _scale * (0.30f + s * 0.0014f ); glm::vec3 u = up * _scale * (0.05f + s * 0.0040f ); @@ -414,9 +414,9 @@ void Head::renderEyeBrows() { glm::vec3 rightBottom = _leftEyePosition; glm::quat orientation = getOrientation(); - glm::vec3 right = orientation * AVATAR_RIGHT; - glm::vec3 up = orientation * AVATAR_UP; - glm::vec3 front = orientation * AVATAR_FRONT; + glm::vec3 right = orientation * IDENTITY_RIGHT; + glm::vec3 up = orientation * IDENTITY_UP; + glm::vec3 front = orientation * IDENTITY_FRONT; glm::vec3 r = right * length; glm::vec3 u = up * height; @@ -501,20 +501,20 @@ void Head::renderEyeBalls() { //rotate the eyeball to aim towards the lookat position glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - _leftEyePosition); // the lookat direction - glm::vec3 rotationAxis = glm::cross(targetLookatAxis, AVATAR_UP); - float angle = 180.0f - angleBetween(targetLookatAxis, AVATAR_UP); + glm::vec3 rotationAxis = glm::cross(targetLookatAxis, IDENTITY_UP); + float angle = 180.0f - angleBetween(targetLookatAxis, IDENTITY_UP); glRotatef(angle, rotationAxis.x, rotationAxis.y, rotationAxis.z); glRotatef(180.0, 0.0f, 1.0f, 0.0f); //adjust roll to correct after previous rotations } else { //rotate the eyeball to aim straight ahead - glm::vec3 rotationAxisToHeadFront = glm::cross(front, AVATAR_UP); - float angleToHeadFront = 180.0f - angleBetween(front, AVATAR_UP); + glm::vec3 rotationAxisToHeadFront = glm::cross(front, IDENTITY_UP); + float angleToHeadFront = 180.0f - angleBetween(front, IDENTITY_UP); glRotatef(angleToHeadFront, rotationAxisToHeadFront.x, rotationAxisToHeadFront.y, rotationAxisToHeadFront.z); //set the amount of roll (for correction after previous rotations) - float rollRotation = angleBetween(front, AVATAR_FRONT); - float dot = glm::dot(front, -AVATAR_RIGHT); + float rollRotation = angleBetween(front, IDENTITY_FRONT); + float dot = glm::dot(front, -IDENTITY_RIGHT); if ( dot < 0.0f ) { rollRotation = -rollRotation; } glRotatef(rollRotation, 0.0f, 1.0f, 0.0f); //roll the iris or correct roll about the lookat vector } @@ -545,21 +545,21 @@ void Head::renderEyeBalls() { //rotate the eyeball to aim towards the lookat position glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - _rightEyePosition); - glm::vec3 rotationAxis = glm::cross(targetLookatAxis, AVATAR_UP); - float angle = 180.0f - angleBetween(targetLookatAxis, AVATAR_UP); + glm::vec3 rotationAxis = glm::cross(targetLookatAxis, IDENTITY_UP); + float angle = 180.0f - angleBetween(targetLookatAxis, IDENTITY_UP); glRotatef(angle, rotationAxis.x, rotationAxis.y, rotationAxis.z); glRotatef(180.0f, 0.0f, 1.0f, 0.0f); //adjust roll to correct after previous rotations } else { //rotate the eyeball to aim straight ahead - glm::vec3 rotationAxisToHeadFront = glm::cross(front, AVATAR_UP); - float angleToHeadFront = 180.0f - angleBetween(front, AVATAR_UP); + glm::vec3 rotationAxisToHeadFront = glm::cross(front, IDENTITY_UP); + float angleToHeadFront = 180.0f - angleBetween(front, IDENTITY_UP); glRotatef(angleToHeadFront, rotationAxisToHeadFront.x, rotationAxisToHeadFront.y, rotationAxisToHeadFront.z); //set the amount of roll (for correction after previous rotations) - float rollRotation = angleBetween(front, AVATAR_FRONT); - float dot = glm::dot(front, -AVATAR_RIGHT); + float rollRotation = angleBetween(front, IDENTITY_FRONT); + float dot = glm::dot(front, -IDENTITY_RIGHT); if ( dot < 0.0f ) { rollRotation = -rollRotation; } glRotatef(rollRotation, 0.0f, 1.0f, 0.0f); //roll the iris or correct roll about the lookat vector } @@ -595,9 +595,8 @@ void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosi void Head::updateHairPhysics(float deltaTime) { glm::quat orientation = getOrientation(); - //glm::vec3 right = orientation * AVATAR_RIGHT; // not used for now - glm::vec3 up = orientation * AVATAR_UP; - glm::vec3 front = orientation * AVATAR_FRONT; + glm::vec3 up = orientation * IDENTITY_UP; + glm::vec3 front = orientation * IDENTITY_FRONT; for (int t = 0; t < NUM_HAIR_TUFTS; t ++) { diff --git a/interface/src/Head.h b/interface/src/Head.h index f49e127caf..66ce07d133 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -49,9 +49,9 @@ public: glm::quat getOrientation() const; glm::quat getWorldAlignedOrientation () const; - glm::vec3 getRightDirection() const { return getOrientation() * AVATAR_RIGHT; } - glm::vec3 getUpDirection () const { return getOrientation() * AVATAR_UP; } - glm::vec3 getFrontDirection() const { return getOrientation() * AVATAR_FRONT; } + glm::vec3 getRightDirection() const { return getOrientation() * IDENTITY_RIGHT; } + glm::vec3 getUpDirection () const { return getOrientation() * IDENTITY_UP; } + glm::vec3 getFrontDirection() const { return getOrientation() * IDENTITY_FRONT; } const bool getReturnToCenter() const { return _returnHeadToCenter; } // Do you want head to try to return to center (depends on interface detected) float getAverageLoudness() {return _averageLoudness;}; diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 08ec6cf011..d16e6d36bb 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -21,6 +21,8 @@ #include "world.h" #include "Util.h" +#include "VoxelConstants.h" + using namespace std; // no clue which versions are affected... @@ -415,9 +417,9 @@ void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int void renderOrientationDirections(glm::vec3 position, const glm::quat& orientation, float size) { - glm::vec3 pRight = position + orientation * AVATAR_RIGHT * size; - glm::vec3 pUp = position + orientation * AVATAR_UP * size; - glm::vec3 pFront = position + orientation * AVATAR_FRONT * size; + glm::vec3 pRight = position + orientation * IDENTITY_RIGHT * size; + glm::vec3 pUp = position + orientation * IDENTITY_UP * size; + glm::vec3 pFront = position + orientation * IDENTITY_FRONT * size; glColor3f(1.0f, 0.0f, 0.0f); glBegin(GL_LINE_STRIP); diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 6ff6967b61..afb43f75ea 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -205,9 +205,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { } glm::vec3 AvatarData::calculateCameraDirection() const { - const glm::vec3 IDENTITY_FRONT = glm::vec3( 0.0f, 0.0f, 1.0f); - glm::mat4 rotationMatrix = glm::mat4_cast(_cameraOrientation); - glm::vec3 direction = glm::vec3(glm::vec4(IDENTITY_FRONT, 0.0f) * rotationMatrix); + glm::vec3 direction = glm::vec3(_cameraOrientation * glm::vec4(IDENTITY_FRONT, 0.0f)); return direction; } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 0fc1104a0a..cf9845ab4c 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -27,11 +27,6 @@ const int HAND_STATE_START_BIT = 5; // 6th and 7th bits const float MAX_AUDIO_LOUDNESS = 1000.0; // close enough for mouth animation -// this is where the coordinate system is represented -const glm::vec3 AVATAR_RIGHT = glm::vec3(1.0f, 0.0f, 0.0f); -const glm::vec3 AVATAR_UP = glm::vec3(0.0f, 1.0f, 0.0f); -const glm::vec3 AVATAR_FRONT = glm::vec3(0.0f, 0.0f, -1.0f); - enum KeyState { NO_KEY_DOWN = 0, diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 0f10428b23..b3c890ed07 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -13,6 +13,7 @@ #include #include "ViewFrustum.h" +#include "VoxelConstants.h" #include "SharedUtil.h" #include "Log.h" @@ -38,20 +39,10 @@ ViewFrustum::ViewFrustum() : _nearBottomRight(0,0,0) { } void ViewFrustum::setOrientation(const glm::quat& orientationAsQuaternion) { - glm::quat quat; - quat = quat * orientationAsQuaternion; - - // this is where the coordinate system is represented - const glm::vec3 IDENTITY_RIGHT = glm::vec3(-1.0f, 0.0f, 0.0f); - const glm::vec3 IDENTITY_UP = glm::vec3( 0.0f, 1.0f, 0.0f); - const glm::vec3 IDENTITY_FRONT = glm::vec3( 0.0f, 0.0f, 1.0f); - - glm::mat4 rotationMatrix = glm::mat4_cast(quat); - _orientation = orientationAsQuaternion; - _right = glm::vec3(glm::vec4(IDENTITY_RIGHT, 0.0f) * rotationMatrix); - _up = glm::vec3(glm::vec4(IDENTITY_UP, 0.0f) * rotationMatrix); - _direction = glm::vec3(glm::vec4(IDENTITY_FRONT, 0.0f) * rotationMatrix); + _right = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_RIGHT, 0.0f)); + _up = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_UP, 0.0f)); + _direction = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_FRONT, 0.0f)); } ///////////////////////////////////////////////////////////////////////////////////// diff --git a/libraries/voxels/src/VoxelConstants.h b/libraries/voxels/src/VoxelConstants.h index 5bf1345d73..d0ae6f538a 100644 --- a/libraries/voxels/src/VoxelConstants.h +++ b/libraries/voxels/src/VoxelConstants.h @@ -15,6 +15,11 @@ #include #include +// this is where the coordinate system is represented +const glm::vec3 IDENTITY_RIGHT = glm::vec3( 1.0f, 0.0f, 0.0f); +const glm::vec3 IDENTITY_UP = glm::vec3( 0.0f, 1.0f, 0.0f); +const glm::vec3 IDENTITY_FRONT = glm::vec3( 0.0f, 0.0f,-1.0f); + const int TREE_SCALE = 128; const int NUMBER_OF_CHILDREN = 8; From 726a0cecf22ef9a4bf3585f495328a7ad36fbac7 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Jun 2013 17:40:34 -0700 Subject: [PATCH 10/11] fixed build issue --- libraries/avatars/CMakeLists.txt | 5 ++++- libraries/avatars/src/AvatarData.cpp | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/avatars/CMakeLists.txt b/libraries/avatars/CMakeLists.txt index b1c593a4a6..207057e244 100644 --- a/libraries/avatars/CMakeLists.txt +++ b/libraries/avatars/CMakeLists.txt @@ -15,4 +15,7 @@ include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} ${ROOT_DIR}) include(${MACRO_DIR}/LinkHifiLibrary.cmake) -link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) \ No newline at end of file +link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) + +# link in the hifi voxels library +link_hifi_library(voxels ${TARGET_NAME} ${ROOT_DIR}) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index afb43f75ea..d24754b28f 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -14,6 +14,7 @@ #include #include "AvatarData.h" +#include using namespace std; From b75bd80de7e2eb22ff04c810a4de3efb0afcadd5 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Jun 2013 17:54:48 -0700 Subject: [PATCH 11/11] fix build busters --- interface/src/Application.cpp | 11 ++---- interface/src/Application.h | 65 ++--------------------------------- interface/src/Avatar.cpp | 10 ++---- interface/src/Avatar.h | 4 +-- 4 files changed, 7 insertions(+), 83 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f4b63acc5a..ae233e8d8c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -162,8 +162,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _packetCount(0), _packetsPerSecond(0), _bytesPerSecond(0), - _bytesCount(0), - _settings("HighFidelity", "Interface") + _bytesCount(0) { _applicationStartupTime = startup_time; _window->setWindowTitle("Interface"); @@ -975,7 +974,7 @@ void Application::terminate() { if (_autosave) { saveSettings(); - _settings.sync(); + _settings->sync(); } if (_enableNetworkThread) { @@ -1166,8 +1165,6 @@ void Application::chooseVoxelPaintColor() { _window->activateWindow(); } -<<<<<<< HEAD -======= const int MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE = 1500; struct SendVoxelsOperationArgs { unsigned char* newBaseOctCode; @@ -1331,7 +1328,6 @@ void Application::pasteVoxels() { } } ->>>>>>> 82c1ee2062577f614cfde096f08adfc9e83e4f0f void Application::initMenu() { QMenuBar* menuBar = new QMenuBar(); _window->setMenuBar(menuBar); @@ -1450,7 +1446,6 @@ void Application::initMenu() { debugMenu->addAction("Wants Res-In", this, SLOT(setWantsResIn(bool)))->setCheckable(true); debugMenu->addAction("Wants Monochrome", this, SLOT(setWantsMonochrome(bool)))->setCheckable(true); debugMenu->addAction("Wants View Delta Sending", this, SLOT(setWantsDelta(bool)))->setCheckable(true); -<<<<<<< HEAD QMenu* settingsMenu = menuBar->addMenu("Settings"); (_settingsAutosave = settingsMenu->addAction("Autosave", this, SLOT(setAutosave(bool))))->setCheckable(true); @@ -1459,11 +1454,9 @@ void Application::initMenu() { settingsMenu->addAction("Save settings", this, SLOT(saveSettings())); settingsMenu->addAction("Import settings", this, SLOT(importSettings())); settingsMenu->addAction("Export settings", this, SLOT(exportSettings())); -======= _networkAccessManager = new QNetworkAccessManager(this); _settings = new QSettings("High Fidelity", "Interface", this); ->>>>>>> 82c1ee2062577f614cfde096f08adfc9e83e4f0f } void Application::updateFrustumRenderModeAction() { diff --git a/interface/src/Application.h b/interface/src/Application.h index df30199e25..446efce8a9 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -71,66 +71,12 @@ public: Camera* getCamera() { return &_myCamera; } ViewFrustum* getViewFrustum() { return &_viewFrustum; } VoxelSystem* getVoxels() { return &_voxels; } - QSettings* getSettings() { return &_settings; } + QSettings* getSettings() { return _settings; } Environment* getEnvironment() { return &_environment; } bool shouldEchoAudio() { return _echoAudioMode->isChecked(); } -<<<<<<< HEAD -======= QNetworkAccessManager* getNetworkAccessManager() { return _networkAccessManager; } - /*! - @fn getSettingBool - @brief A function for getting boolean settings from the settings file. - @param settingName The desired setting to get the value for. - @param boolSetting The referenced variable where the setting will be stored. - @param defaultSetting The default setting to assign to boolSetting if this function fails to find the appropriate setting. Defaults to false. - */ - bool getSetting(const char* setting, bool &value, const bool defaultSetting = false) const; - - /*! - @fn getSettingFloat - @brief A function for getting float settings from the settings file. - @param settingName The desired setting to get the value for. - @param floatSetting The referenced variable where the setting will be stored. - @param defaultSetting The default setting to assign to boolSetting if this function fails to find the appropriate setting. Defaults to 0.0f. - */ - bool getSetting(const char* setting, float &value, const float defaultSetting = 0.0f) const; - - /*! - @fn getSettingVec3 - @brief A function for getting boolean settings from the settings file. - @param settingName The desired setting to get the value for. - @param vecSetting The referenced variable where the setting will be stored. - @param defaultSetting The default setting to assign to boolSetting if this function fails to find the appropriate setting. Defaults to <0.0f, 0.0f, 0.0f> - */ - bool getSetting(const char* setting, glm::vec3 &value, const glm::vec3& defaultSetting = glm::vec3(0.0f, 0.0f, 0.0f)) const; - - /*! - @fn setSettingBool - @brief A function for setting boolean setting values when saving the settings file. - @param settingName The desired setting to populate a value for. - @param boolSetting The value to set. - */ - void setSetting(const char* setting, const bool value); - - /*! - @fn setSettingFloat - @brief A function for setting boolean setting values when saving the settings file. - @param settingName The desired setting to populate a value for. - @param floatSetting The value to set. - */ - void setSetting(const char* setting, const float value); - - /*! - @fn setSettingVec3 - @brief A function for setting boolean setting values when saving the settings file. - @param settingName The desired setting to populate a value for. - @param vecSetting The value to set. - */ - void setSetting(const char* setting, const glm::vec3& value); ->>>>>>> 82c1ee2062577f614cfde096f08adfc9e83e4f0f - private slots: void timer(); @@ -167,22 +113,16 @@ private slots: void decreaseVoxelSize(); void increaseVoxelSize(); void chooseVoxelPaintColor(); -<<<<<<< HEAD - void setAutosave(bool wantsAutosave); void loadSettings(QSettings* set = NULL); void saveSettings(QSettings* set = NULL); void importSettings(); void exportSettings(); - -======= void exportVoxels(); void importVoxels(); void cutVoxels(); void copyVoxels(); void pasteVoxels(); - ->>>>>>> 82c1ee2062577f614cfde096f08adfc9e83e4f0f private: static bool sendVoxelsOperation(VoxelNode* node, void* extraData); @@ -260,7 +200,6 @@ private: QAction* _settingsAutosave; // Whether settings are saved automatically QNetworkAccessManager* _networkAccessManager; - QSettings* _settings; SerialInterface _serialPort; bool _displayLevels; @@ -353,7 +292,7 @@ private: int _bytesPerSecond; int _bytesCount; - QSettings _settings; // Contain Menu settings and Avatar data + QSettings* _settings; // Contain Menu settings and Avatar data bool _autosave; // True if the autosave is on. }; diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index cff3c718e1..49b83dd670 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -1252,7 +1252,6 @@ void Avatar::setHeadFromGyros(glm::vec3* eulerAngles, glm::vec3* angularVelocity } } -<<<<<<< HEAD void Avatar::loadData(QSettings* set) { set->beginGroup("Avatar"); @@ -1265,18 +1264,13 @@ void Avatar::loadData(QSettings* set) { _position.z = set->value("position_z", _position.z).toFloat(); set->endGroup(); -======= +} + void Avatar::getBodyBallTransform(AvatarJointID jointID, glm::vec3& position, glm::quat& rotation) const { position = _bodyBall[jointID].position; rotation = _bodyBall[jointID].rotation; } -void Avatar::writeAvatarDataToFile() { - Application::getInstance()->setSetting("avatarPos", _position); - Application::getInstance()->setSetting("avatarRotation", glm::vec3(_bodyYaw, _bodyPitch, _bodyRoll)); ->>>>>>> 82c1ee2062577f614cfde096f08adfc9e83e4f0f -} - void Avatar::saveData(QSettings* set) { set->beginGroup("Avatar"); diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 58fe7a34a7..73ab3ddaba 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -131,18 +131,16 @@ public: void addThrust(glm::vec3 newThrust) { _thrust += newThrust; }; glm::vec3 getThrust() { return _thrust; }; -<<<<<<< HEAD // get/set avatar data void saveData(QSettings* set); void loadData(QSettings* set); -======= + // Get the position/rotation of a single body ball void getBodyBallTransform(AvatarJointID jointID, glm::vec3& position, glm::quat& rotation) const; //read/write avatar data void writeAvatarDataToFile(); void readAvatarDataFromFile(); ->>>>>>> 82c1ee2062577f614cfde096f08adfc9e83e4f0f private: // privatize copy constructor and assignment operator to avoid copying