From d094c6fc3bf046a431fd79bd1b2d3f538b2a64bf Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 14:41:59 -0700 Subject: [PATCH 01/20] refactor LinkHifiLibrary, add SetupHifiLibrary macro --- cmake/macros/LinkHifiLibrary.cmake | 6 ------ cmake/macros/SetupHifiLibrary.cmake | 9 +++++++++ libraries/voxels/CMakeLists.txt | 16 +++++----------- 3 files changed, 14 insertions(+), 17 deletions(-) create mode 100644 cmake/macros/SetupHifiLibrary.cmake diff --git a/cmake/macros/LinkHifiLibrary.cmake b/cmake/macros/LinkHifiLibrary.cmake index 6aaf784437..6a4122d583 100644 --- a/cmake/macros/LinkHifiLibrary.cmake +++ b/cmake/macros/LinkHifiLibrary.cmake @@ -3,12 +3,6 @@ MACRO(LINK_HIFI_LIBRARY LIBRARY TARGET ROOT_DIR) add_subdirectory(${ROOT_DIR}/libraries/${LIBRARY} ${ROOT_DIR}/libraries/${LIBRARY}) endif (NOT TARGET ${LIBRARY}) - string(TOUPPER ${LIBRARY} UPPERCASED_LIBRARY_NAME) - set(HIFI_LIBRARY_PROPERTY "HIFI_${UPPERCASED_LIBRARY_NAME}_LIBRARY") - get_directory_property(HIFI_LIBRARY - DIRECTORY ${ROOT_DIR}/libraries/${LIBRARY} - DEFINITION ${HIFI_LIBRARY_PROPERTY}) - include_directories(${ROOT_DIR}/libraries/${LIBRARY}/src) add_dependencies(${TARGET} ${LIBRARY}) diff --git a/cmake/macros/SetupHifiLibrary.cmake b/cmake/macros/SetupHifiLibrary.cmake new file mode 100644 index 0000000000..156ca186b2 --- /dev/null +++ b/cmake/macros/SetupHifiLibrary.cmake @@ -0,0 +1,9 @@ +MACRO(SETUP_HIFI_LIBRARY TARGET) + project(${TARGET_NAME}) + + # grab the implemenation and header files + file(GLOB LIB_SRCS src/*.h src/*.cpp) + + # create a library and set the property so it can be referenced later + add_library(${TARGET_NAME} ${LIB_SRCS}) +ENDMACRO(SETUP_HIFI_LIBRARY _target) \ No newline at end of file diff --git a/libraries/voxels/CMakeLists.txt b/libraries/voxels/CMakeLists.txt index 21188c26f9..4a6aea05b2 100644 --- a/libraries/voxels/CMakeLists.txt +++ b/libraries/voxels/CMakeLists.txt @@ -8,19 +8,13 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../../cm set(TARGET_NAME voxels) -project(${TARGET_NAME}) +include(${MACRO_DIR}/SetupHifiLibrary.cmake) +setup_hifi_library(${TARGET_NAME}) -# set up the external glm library +# include glm include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} ${MACRO_DIR}) -# grab the implemenation and header files -file(GLOB HIFI_VOXELS_SRCS src/*.h src/*.cpp) - -# create a library and set the property so it can be referenced later -add_library(${TARGET_NAME} ${HIFI_VOXELS_SRCS}) - +# link the shared library include(${MACRO_DIR}/LinkHifiLibrary.cmake) -link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) - -set(HIFI_VOXELS_LIBRARY ${TARGET_NAME}) \ No newline at end of file +link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) \ No newline at end of file From d0eed9269953f7e6a26dca3b4a40a049c74c1d46 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 14:47:51 -0700 Subject: [PATCH 02/20] add an avatars library and move AvatarAgentData there --- avatar-mixer/CMakeLists.txt | 7 ++----- interface/CMakeLists.txt | 5 +++-- libraries/avatars/CMakeLists.txt | 9 +++++++++ .../avatars}/src/AvatarAgentData.cpp | 0 .../avatars}/src/AvatarAgentData.h | 0 5 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 libraries/avatars/CMakeLists.txt rename {avatar-mixer => libraries/avatars}/src/AvatarAgentData.cpp (100%) rename {avatar-mixer => libraries/avatars}/src/AvatarAgentData.h (100%) diff --git a/avatar-mixer/CMakeLists.txt b/avatar-mixer/CMakeLists.txt index c3251fe513..76803e877a 100644 --- a/avatar-mixer/CMakeLists.txt +++ b/avatar-mixer/CMakeLists.txt @@ -9,10 +9,7 @@ set(MACRO_DIR ${ROOT_DIR}/cmake/macros) include(${MACRO_DIR}/SetupHifiProject.cmake) setup_hifi_project(${TARGET_NAME}) -# link the shared hifi library +# link required hifi libraries include(${MACRO_DIR}/LinkHifiLibrary.cmake) link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) - -# link the threads library -find_package(Threads REQUIRED) -target_link_libraries(${TARGET_NAME} ${CMAKE_THREAD_LIBS_INIT}) +link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR}) \ No newline at end of file diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 257e88a571..ddb9f65d10 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -56,10 +56,11 @@ add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS}) # link in the hifi shared library include(${MACRO_DIR}/LinkHifiLibrary.cmake) -link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) -# link in the hifi voxels library +# link required hifi libraries +link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) link_hifi_library(voxels ${TARGET_NAME} ${ROOT_DIR}) +link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR}) # find required libraries find_package(GLM REQUIRED) diff --git a/libraries/avatars/CMakeLists.txt b/libraries/avatars/CMakeLists.txt new file mode 100644 index 0000000000..5ce41cb1c2 --- /dev/null +++ b/libraries/avatars/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 2.8) + +set(ROOT_DIR ../..) +set(MACRO_DIR ${ROOT_DIR}/cmake/macros) + +set(TARGET_NAME avatars) + +include(${MACRO_DIR}/SetupHifiLibrary.cmake) +setup_hifi_library(${TARGET_NAME}) \ No newline at end of file diff --git a/avatar-mixer/src/AvatarAgentData.cpp b/libraries/avatars/src/AvatarAgentData.cpp similarity index 100% rename from avatar-mixer/src/AvatarAgentData.cpp rename to libraries/avatars/src/AvatarAgentData.cpp diff --git a/avatar-mixer/src/AvatarAgentData.h b/libraries/avatars/src/AvatarAgentData.h similarity index 100% rename from avatar-mixer/src/AvatarAgentData.h rename to libraries/avatars/src/AvatarAgentData.h From 4702e6ade03406b152027da0873a42cd29fd2d48 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 14:59:48 -0700 Subject: [PATCH 03/20] remove the unecessary trailing slash when setting root dir --- audio-mixer/CMakeLists.txt | 2 +- avatar-mixer/CMakeLists.txt | 2 +- domain-server/CMakeLists.txt | 2 +- injector/CMakeLists.txt | 2 +- interface/CMakeLists.txt | 2 +- libraries/voxels/CMakeLists.txt | 2 +- space-server/CMakeLists.txt | 2 +- voxel-server/CMakeLists.txt | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/audio-mixer/CMakeLists.txt b/audio-mixer/CMakeLists.txt index 0eb0dab782..1e6637aeb2 100644 --- a/audio-mixer/CMakeLists.txt +++ b/audio-mixer/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.8) -set(ROOT_DIR ../) +set(ROOT_DIR ..) set(MACRO_DIR ${ROOT_DIR}/cmake/macros) set(TARGET_NAME audio-mixer) diff --git a/avatar-mixer/CMakeLists.txt b/avatar-mixer/CMakeLists.txt index 76803e877a..95cfd60a88 100644 --- a/avatar-mixer/CMakeLists.txt +++ b/avatar-mixer/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8) set(TARGET_NAME "avatar-mixer") -set(ROOT_DIR ../) +set(ROOT_DIR ..) set(MACRO_DIR ${ROOT_DIR}/cmake/macros) # setup the project diff --git a/domain-server/CMakeLists.txt b/domain-server/CMakeLists.txt index 2752e514ad..27863f01df 100644 --- a/domain-server/CMakeLists.txt +++ b/domain-server/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.8) -set(ROOT_DIR ../) +set(ROOT_DIR ..) set(MACRO_DIR ${ROOT_DIR}/cmake/macros) set(TARGET_NAME domain-server) diff --git a/injector/CMakeLists.txt b/injector/CMakeLists.txt index d8a448b7bc..6e3e61326c 100644 --- a/injector/CMakeLists.txt +++ b/injector/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.8) -set(ROOT_DIR ../) +set(ROOT_DIR ..) set(MACRO_DIR ${ROOT_DIR}/cmake/macros) set(TARGET_NAME injector) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index ddb9f65d10..1dc201cfe9 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.8) -set(ROOT_DIR ../) +set(ROOT_DIR ..) set(MACRO_DIR ${ROOT_DIR}/cmake/macros) set(TARGET_NAME interface) diff --git a/libraries/voxels/CMakeLists.txt b/libraries/voxels/CMakeLists.txt index 4a6aea05b2..61718c58da 100644 --- a/libraries/voxels/CMakeLists.txt +++ b/libraries/voxels/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.8) -set(ROOT_DIR ../../) +set(ROOT_DIR ../..) set(MACRO_DIR ${ROOT_DIR}/cmake/macros) # setup for find modules diff --git a/space-server/CMakeLists.txt b/space-server/CMakeLists.txt index 4e5c698254..5b34f86a4c 100644 --- a/space-server/CMakeLists.txt +++ b/space-server/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.8) -set(ROOT_DIR ../) +set(ROOT_DIR ..) set(MACRO_DIR ${ROOT_DIR}/cmake/macros) set(TARGET_NAME space-server) diff --git a/voxel-server/CMakeLists.txt b/voxel-server/CMakeLists.txt index 56b728c186..5f9ff87fd7 100644 --- a/voxel-server/CMakeLists.txt +++ b/voxel-server/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8) set(TARGET_NAME voxel-server) -set(ROOT_DIR ../) +set(ROOT_DIR ..) set(MACRO_DIR ${ROOT_DIR}/cmake/macros) include(${MACRO_DIR}/SetupHifiProject.cmake) From 2dfe49a885d28617972839376b7cfa148ff89611 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 15:05:55 -0700 Subject: [PATCH 04/20] moved AvatarAgentData to AvatarData --- avatar-mixer/src/main.cpp | 6 +- libraries/avatars/src/AvatarAgentData.cpp | 118 ------------------ libraries/avatars/src/AvatarData.cpp | 118 ++++++++++++++++++ .../src/{AvatarAgentData.h => AvatarData.h} | 18 ++- 4 files changed, 129 insertions(+), 131 deletions(-) delete mode 100644 libraries/avatars/src/AvatarAgentData.cpp create mode 100644 libraries/avatars/src/AvatarData.cpp rename libraries/avatars/src/{AvatarAgentData.h => AvatarData.h} (75%) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index 8aa57c0ad4..c56ddf4802 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -32,7 +32,7 @@ #include #include -#include "AvatarAgentData.h" +#include "AvatarData.h" const int AVATAR_LISTEN_PORT = 55444; const unsigned short BROADCAST_INTERVAL_USECS = 20 * 1000 * 1000; @@ -40,7 +40,7 @@ const unsigned short BROADCAST_INTERVAL_USECS = 20 * 1000 * 1000; unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) { currentPosition += packAgentId(currentPosition, agentToAdd->getAgentId()); - AvatarAgentData *agentData = (AvatarAgentData *)agentToAdd->getLinkedData(); + AvatarData *agentData = (AvatarData *)agentToAdd->getLinkedData(); int bytesWritten = sprintf((char *)currentPosition, PACKET_FORMAT, @@ -62,7 +62,7 @@ unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent * void attachAvatarDataToAgent(Agent *newAgent) { if (newAgent->getLinkedData() == NULL) { - newAgent->setLinkedData(new AvatarAgentData()); + newAgent->setLinkedData(new AvatarData()); } } diff --git a/libraries/avatars/src/AvatarAgentData.cpp b/libraries/avatars/src/AvatarAgentData.cpp deleted file mode 100644 index 0ee5981c53..0000000000 --- a/libraries/avatars/src/AvatarAgentData.cpp +++ /dev/null @@ -1,118 +0,0 @@ -// -// AvatarAgentData.cpp -// hifi -// -// Created by Stephen Birarda on 4/9/13. -// -// - -#include - -#include "AvatarAgentData.h" - -AvatarAgentData::AvatarAgentData() { - -} - -AvatarAgentData::~AvatarAgentData() { - -} - -AvatarAgentData* AvatarAgentData::clone() const { - return new AvatarAgentData(*this); -} - -void AvatarAgentData::parseData(void *data, int size) { - char* packetData = (char *)data + 1; - - // Extract data from packet - sscanf(packetData, - PACKET_FORMAT, - &_pitch, - &_yaw, - &_roll, - &_headPositionX, - &_headPositionY, - &_headPositionZ, - &_loudness, - &_averageLoudness, - &_handPositionX, - &_handPositionY, - &_handPositionZ); -} - -float AvatarAgentData::getPitch() { - return _pitch; -} - -float AvatarAgentData::getYaw() { - return _yaw; -} - -float AvatarAgentData::getRoll() { - return _roll; -} - -float AvatarAgentData::getHeadPositionX() { - return _headPositionX; -} - -float AvatarAgentData::getHeadPositionY() { - return _headPositionY; -} - -float AvatarAgentData::getHeadPositionZ() { - return _headPositionZ; -} - -float AvatarAgentData::getLoudness() { - return _loudness; -} - -float AvatarAgentData::getAverageLoudness() { - return _averageLoudness; -} - -float AvatarAgentData::getHandPositionX() { - return _handPositionX; -} - -float AvatarAgentData::getHandPositionY() { - return _handPositionY; -} - -float AvatarAgentData::getHandPositionZ() { - return _handPositionZ; -} - -void AvatarAgentData::setPitch(float pitch) { - _pitch = pitch; -} - -void AvatarAgentData::setYaw(float yaw) { - _yaw = yaw; -} - -void AvatarAgentData::setRoll(float roll) { - _roll = roll; -} - -void AvatarAgentData::setHeadPosition(float x, float y, float z) { - _headPositionX = x; - _headPositionY = y; - _headPositionZ = z; -} - -void AvatarAgentData::setLoudness(float loudness) { - _loudness = loudness; -} - -void AvatarAgentData::setAverageLoudness(float averageLoudness) { - _averageLoudness = averageLoudness; -} - -void AvatarAgentData::setHandPosition(float x, float y, float z) { - _handPositionX = x; - _handPositionY = y; - _handPositionZ = z; -} diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp new file mode 100644 index 0000000000..c1f862b14c --- /dev/null +++ b/libraries/avatars/src/AvatarData.cpp @@ -0,0 +1,118 @@ +// +// AvatarData.cpp +// hifi +// +// Created by Stephen Birarda on 4/9/13. +// +// + +#include + +#include "AvatarData.h" + +AvatarData::AvatarData() { + +} + +AvatarData::~AvatarData() { + +} + +AvatarData* AvatarData::clone() const { + return new AvatarData(*this); +} + +void AvatarData::parseData(void *data, int size) { + char* packetData = (char *)data + 1; + +// // Extract data from packet +// sscanf(packetData, +// PACKET_FORMAT, +// &_pitch, +// &_yaw, +// &_roll, +// &_headPositionX, +// &_headPositionY, +// &_headPositionZ, +// &_loudness, +// &_averageLoudness, +// &_handPositionX, +// &_handPositionY, +// &_handPositionZ); +} + +float AvatarData::getPitch() { + return _pitch; +} + +float AvatarData::getYaw() { + return _yaw; +} + +float AvatarData::getRoll() { + return _roll; +} + +float AvatarData::getHeadPositionX() { + return _headPositionX; +} + +float AvatarData::getHeadPositionY() { + return _headPositionY; +} + +float AvatarData::getHeadPositionZ() { + return _headPositionZ; +} + +float AvatarData::getLoudness() { + return _loudness; +} + +float AvatarData::getAverageLoudness() { + return _averageLoudness; +} + +float AvatarData::getHandPositionX() { + return _handPositionX; +} + +float AvatarData::getHandPositionY() { + return _handPositionY; +} + +float AvatarData::getHandPositionZ() { + return _handPositionZ; +} + +void AvatarData::setPitch(float pitch) { + _pitch = pitch; +} + +void AvatarData::setYaw(float yaw) { + _yaw = yaw; +} + +void AvatarData::setRoll(float roll) { + _roll = roll; +} + +void AvatarData::setHeadPosition(float x, float y, float z) { + _headPositionX = x; + _headPositionY = y; + _headPositionZ = z; +} + +void AvatarData::setLoudness(float loudness) { + _loudness = loudness; +} + +void AvatarData::setAverageLoudness(float averageLoudness) { + _averageLoudness = averageLoudness; +} + +void AvatarData::setHandPosition(float x, float y, float z) { + _handPositionX = x; + _handPositionY = y; + _handPositionZ = z; +} diff --git a/libraries/avatars/src/AvatarAgentData.h b/libraries/avatars/src/AvatarData.h similarity index 75% rename from libraries/avatars/src/AvatarAgentData.h rename to libraries/avatars/src/AvatarData.h index 2b06928886..b22ce5df1f 100644 --- a/libraries/avatars/src/AvatarAgentData.h +++ b/libraries/avatars/src/AvatarData.h @@ -1,26 +1,24 @@ // -// AvatarAgentData.h +// AvatarData.h // hifi // // Created by Stephen Birarda on 4/9/13. // // -#ifndef __hifi__AvatarAgentData__ -#define __hifi__AvatarAgentData__ +#ifndef __hifi__AvatarData__ +#define __hifi__AvatarData__ #include #include -const char PACKET_FORMAT[] = "%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f"; - -class AvatarAgentData : public AgentData { +class AvatarData : public AgentData { public: - AvatarAgentData(); - ~AvatarAgentData(); + AvatarData(); + ~AvatarData(); void parseData(void *data, int size); - AvatarAgentData* clone() const; + AvatarData* clone() const; float getPitch(); void setPitch(float pitch); @@ -55,4 +53,4 @@ private: float _handPositionZ; }; -#endif /* defined(__hifi__AvatarAgentData__) */ +#endif /* defined(__hifi__AvatarData__) */ From a4011934c6e9e7976f6376429e2f95f36d00706e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 15:39:23 -0700 Subject: [PATCH 05/20] move Orientation class to avatars library, constants to SharedUtil --- interface/src/Camera.cpp | 3 +- interface/src/Head.cpp | 3 - interface/src/Head.h | 103 +----------------- interface/src/Util.cpp | 5 +- interface/src/Util.h | 15 --- libraries/avatars/CMakeLists.txt | 11 +- libraries/avatars/src/AvatarData.h | 58 ++++++++++ .../avatars}/src/Orientation.cpp | 3 +- .../avatars}/src/Orientation.h | 0 libraries/shared/src/SharedUtil.h | 16 +++ 10 files changed, 97 insertions(+), 120 deletions(-) rename {interface => libraries/avatars}/src/Orientation.cpp (98%) rename {interface => libraries/avatars}/src/Orientation.h (100%) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 5a6899467c..32a7c5f441 100755 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -5,8 +5,9 @@ // //--------------------------------------------------------------------- +#include + #include "Camera.h" -#include "Util.h" //------------------------ Camera::Camera() diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 2e9933fb57..244059576c 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -42,9 +42,6 @@ vector iris_texture; unsigned int iris_texture_width = 512; unsigned int iris_texture_height = 256; - - - Head::Head() { initializeAvatar(); diff --git a/interface/src/Head.h b/interface/src/Head.h index 9ee8b28367..0bf92aa546 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -10,10 +10,13 @@ #define __interface__head__ #include -#include "AgentData.h" + +#include +#include // added by Ventrella as a utility + #include "Field.h" #include "world.h" -#include "Orientation.h" // added by Ventrella as a utility + #include "InterfaceConfig.h" #include "SerialInterface.h" @@ -31,101 +34,7 @@ enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH}; #define NUM_OTHER_AVATARS 5 -/* -enum AvatarJoints -{ - AVATAR_JOINT_NULL = -1, - AVATAR_JOINT_PELVIS, - AVATAR_JOINT_TORSO, - AVATAR_JOINT_CHEST, - AVATAR_JOINT_NECK_BASE, - AVATAR_JOINT_HEAD_BASE, - AVATAR_JOINT_HEAD_TOP, - - AVATAR_JOINT_LEFT_CLAVICLE, - AVATAR_JOINT_LEFT_SHOULDER, - AVATAR_JOINT_LEFT_ELBOW, - AVATAR_JOINT_LEFT_WRIST, - AVATAR_JOINT_LEFT_FINGERTIPS, - - AVATAR_JOINT_RIGHT_CLAVICLE, - AVATAR_JOINT_RIGHT_SHOULDER, - AVATAR_JOINT_RIGHT_ELBOW, - AVATAR_JOINT_RIGHT_WRIST, - AVATAR_JOINT_RIGHT_FINGERTIPS, - - AVATAR_JOINT_LEFT_HIP, - AVATAR_JOINT_LEFT_KNEE, - AVATAR_JOINT_LEFT_HEEL, - AVATAR_JOINT_LEFT_TOES, - - AVATAR_JOINT_RIGHT_HIP, - AVATAR_JOINT_RIGHT_KNEE, - AVATAR_JOINT_RIGHT_HEEL, - AVATAR_JOINT_RIGHT_TOES, - - NUM_AVATAR_JOINTS -}; -*/ - - - - -enum AvatarBones -{ - AVATAR_BONE_NULL = -1, - AVATAR_BONE_PELVIS_SPINE, // connects pelvis joint with torso joint (not supposed to be rotated) - AVATAR_BONE_MID_SPINE, // connects torso joint with chest joint - AVATAR_BONE_CHEST_SPINE, // connects chest joint with neckBase joint (not supposed to be rotated) - AVATAR_BONE_NECK, // connects neckBase joint with headBase joint - AVATAR_BONE_HEAD, // connects headBase joint with headTop joint - AVATAR_BONE_LEFT_CHEST, // connects chest joint with left clavicle joint (not supposed to be rotated) - AVATAR_BONE_LEFT_SHOULDER, // connects left clavicle joint with left shoulder joint - AVATAR_BONE_LEFT_UPPER_ARM, // connects left shoulder joint with left elbow joint - AVATAR_BONE_LEFT_FOREARM, // connects left elbow joint with left wrist joint - AVATAR_BONE_LEFT_HAND, // connects left wrist joint with left fingertips joint - AVATAR_BONE_RIGHT_CHEST, // connects chest joint with right clavicle joint (not supposed to be rotated) - AVATAR_BONE_RIGHT_SHOULDER, // connects right clavicle joint with right shoulder joint - AVATAR_BONE_RIGHT_UPPER_ARM, // connects right shoulder joint with right elbow joint - AVATAR_BONE_RIGHT_FOREARM, // connects right elbow joint with right wrist joint - AVATAR_BONE_RIGHT_HAND, // connects right wrist joint with right fingertips joint - AVATAR_BONE_LEFT_PELVIS, // connects pelvis joint with left hip joint (not supposed to be rotated) - AVATAR_BONE_LEFT_THIGH, // connects left hip joint with left knee joint - AVATAR_BONE_LEFT_SHIN, // connects left knee joint with left heel joint - AVATAR_BONE_LEFT_FOOT, // connects left heel joint with left toes joint - AVATAR_BONE_RIGHT_PELVIS, // connects pelvis joint with right hip joint (not supposed to be rotated) - AVATAR_BONE_RIGHT_THIGH, // connects right hip joint with right knee joint - AVATAR_BONE_RIGHT_SHIN, // connects right knee joint with right heel joint - AVATAR_BONE_RIGHT_FOOT, // connects right heel joint with right toes joint - - NUM_AVATAR_BONES -}; - -struct AvatarBone -{ - AvatarBones parent; // which bone is this bone connected to? - glm::vec3 position; // the position at the "end" of the bone - glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose" - glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) - glm::dvec3 springyVelocity; // used for special effects ( the velocity of the springy position) - float springBodyTightness; // how tightly (0 to 1) the springy position tries to stay on the position - float yaw; // the yaw Euler angle of the bone rotation off the parent - float pitch; // the pitch Euler angle of the bone rotation off the parent - float roll; // the roll Euler angle of the bone rotation off the parent - Orientation orientation; // three orthogonal normals determined by yaw, pitch, roll - float length; // the length of the bone -}; - -struct Avatar -{ - glm::dvec3 velocity; - glm::vec3 thrust; - float maxArmLength; - Orientation orientation; - AvatarBone bone[ NUM_AVATAR_BONES ]; -}; - -class Head : public AgentData { +class Head : public AvatarData { public: Head(); ~Head(); diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 637204dc83..f9dc085793 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -8,8 +8,11 @@ #include "InterfaceConfig.h" #include -#include #include + +#include +#include + #include "world.h" #include "Util.h" diff --git a/interface/src/Util.h b/interface/src/Util.h index 56bc16f5d1..13b2810092 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -17,21 +17,6 @@ #include -static const double ZERO = 0.0; -static const double ONE = 1.0; -static const double ONE_HALF = 0.5; -static const double ONE_THIRD = 0.3333333; -static const double PIE = 3.14159265359; -static const double PI_TIMES_TWO = 3.14159265359 * 2.0; -static const double PI_OVER_180 = 3.14159265359 / 180.0; -static const double EPSILON = 0.00001; //smallish number - used as margin of error for some computations -static const double SQUARE_ROOT_OF_2 = sqrt(2); -static const double SQUARE_ROOT_OF_3 = sqrt(3); -static const double METER = 1.0; -static const double DECIMETER = 0.1; -static const double CENTIMETER = 0.01; -static const double MILLIIMETER = 0.001; - float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos); float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float head_yaw); diff --git a/libraries/avatars/CMakeLists.txt b/libraries/avatars/CMakeLists.txt index 5ce41cb1c2..35bb4df9e9 100644 --- a/libraries/avatars/CMakeLists.txt +++ b/libraries/avatars/CMakeLists.txt @@ -3,7 +3,16 @@ cmake_minimum_required(VERSION 2.8) set(ROOT_DIR ../..) set(MACRO_DIR ${ROOT_DIR}/cmake/macros) +# setup for find modules +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/modules/") + set(TARGET_NAME avatars) include(${MACRO_DIR}/SetupHifiLibrary.cmake) -setup_hifi_library(${TARGET_NAME}) \ No newline at end of file +setup_hifi_library(${TARGET_NAME}) + +include(${MACRO_DIR}/IncludeGLM.cmake) +include_glm(${TARGET_NAME} ${MACRO_DIR}) + +include(${MACRO_DIR}/LinkHifiLibrary.cmake) +link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) \ No newline at end of file diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index b22ce5df1f..17ae8df9cc 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -10,8 +10,66 @@ #define __hifi__AvatarData__ #include + +#include #include +#include "Orientation.h" + +enum AvatarBones +{ + AVATAR_BONE_NULL = -1, + AVATAR_BONE_PELVIS_SPINE, // connects pelvis joint with torso joint (not supposed to be rotated) + AVATAR_BONE_MID_SPINE, // connects torso joint with chest joint + AVATAR_BONE_CHEST_SPINE, // connects chest joint with neckBase joint (not supposed to be rotated) + AVATAR_BONE_NECK, // connects neckBase joint with headBase joint + AVATAR_BONE_HEAD, // connects headBase joint with headTop joint + AVATAR_BONE_LEFT_CHEST, // connects chest joint with left clavicle joint (not supposed to be rotated) + AVATAR_BONE_LEFT_SHOULDER, // connects left clavicle joint with left shoulder joint + AVATAR_BONE_LEFT_UPPER_ARM, // connects left shoulder joint with left elbow joint + AVATAR_BONE_LEFT_FOREARM, // connects left elbow joint with left wrist joint + AVATAR_BONE_LEFT_HAND, // connects left wrist joint with left fingertips joint + AVATAR_BONE_RIGHT_CHEST, // connects chest joint with right clavicle joint (not supposed to be rotated) + AVATAR_BONE_RIGHT_SHOULDER, // connects right clavicle joint with right shoulder joint + AVATAR_BONE_RIGHT_UPPER_ARM, // connects right shoulder joint with right elbow joint + AVATAR_BONE_RIGHT_FOREARM, // connects right elbow joint with right wrist joint + AVATAR_BONE_RIGHT_HAND, // connects right wrist joint with right fingertips joint + AVATAR_BONE_LEFT_PELVIS, // connects pelvis joint with left hip joint (not supposed to be rotated) + AVATAR_BONE_LEFT_THIGH, // connects left hip joint with left knee joint + AVATAR_BONE_LEFT_SHIN, // connects left knee joint with left heel joint + AVATAR_BONE_LEFT_FOOT, // connects left heel joint with left toes joint + AVATAR_BONE_RIGHT_PELVIS, // connects pelvis joint with right hip joint (not supposed to be rotated) + AVATAR_BONE_RIGHT_THIGH, // connects right hip joint with right knee joint + AVATAR_BONE_RIGHT_SHIN, // connects right knee joint with right heel joint + AVATAR_BONE_RIGHT_FOOT, // connects right heel joint with right toes joint + + NUM_AVATAR_BONES +}; + +struct AvatarBone +{ + AvatarBones parent; // which bone is this bone connected to? + glm::vec3 position; // the position at the "end" of the bone + glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose" + glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) + glm::dvec3 springyVelocity; // used for special effects ( the velocity of the springy position) + float springBodyTightness; // how tightly (0 to 1) the springy position tries to stay on the position + float yaw; // the yaw Euler angle of the bone rotation off the parent + float pitch; // the pitch Euler angle of the bone rotation off the parent + float roll; // the roll Euler angle of the bone rotation off the parent + Orientation orientation; // three orthogonal normals determined by yaw, pitch, roll + float length; // the length of the bone +}; + +struct Avatar +{ + glm::dvec3 velocity; + glm::vec3 thrust; + float maxArmLength; + Orientation orientation; + AvatarBone bone[ NUM_AVATAR_BONES ]; +}; + class AvatarData : public AgentData { public: AvatarData(); diff --git a/interface/src/Orientation.cpp b/libraries/avatars/src/Orientation.cpp similarity index 98% rename from interface/src/Orientation.cpp rename to libraries/avatars/src/Orientation.cpp index b42cba997c..ed1500a506 100755 --- a/interface/src/Orientation.cpp +++ b/libraries/avatars/src/Orientation.cpp @@ -6,8 +6,7 @@ //----------------------------------------------------------- #include "Orientation.h" -#include "Util.h" - +#include Orientation::Orientation() { right = glm::vec3( 1.0, 0.0, 0.0 ); diff --git a/interface/src/Orientation.h b/libraries/avatars/src/Orientation.h similarity index 100% rename from interface/src/Orientation.h rename to libraries/avatars/src/Orientation.h diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index 24517c9a68..d2402bb21f 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -10,6 +10,7 @@ #define __hifi__SharedUtil__ #include +#include #ifdef _WIN32 #include "Systime.h" @@ -17,6 +18,21 @@ #include #endif +static const double ZERO = 0.0; +static const double ONE = 1.0; +static const double ONE_HALF = 0.5; +static const double ONE_THIRD = 0.3333333; +static const double PIE = 3.14159265359; +static const double PI_TIMES_TWO = 3.14159265359 * 2.0; +static const double PI_OVER_180 = 3.14159265359 / 180.0; +static const double EPSILON = 0.00001; //smallish number - used as margin of error for some computations +static const double SQUARE_ROOT_OF_2 = sqrt(2); +static const double SQUARE_ROOT_OF_3 = sqrt(3); +static const double METER = 1.0; +static const double DECIMETER = 0.1; +static const double CENTIMETER = 0.01; +static const double MILLIIMETER = 0.001; + double usecTimestamp(timeval *time); double usecTimestampNow(); From af1071b374b9b95721003c6d0077c2b6a9969cf5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 16:07:46 -0700 Subject: [PATCH 06/20] comments to AvatarData and avatar-mixer before pack/unpack refactor --- avatar-mixer/src/main.cpp | 28 ++++++++++++++-------------- libraries/avatars/src/AvatarData.h | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index c56ddf4802..2a60112b4b 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -42,21 +42,21 @@ unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent * AvatarData *agentData = (AvatarData *)agentToAdd->getLinkedData(); - int bytesWritten = sprintf((char *)currentPosition, - PACKET_FORMAT, - agentData->getPitch(), - agentData->getYaw(), - agentData->getRoll(), - agentData->getHeadPositionX(), - agentData->getHeadPositionY(), - agentData->getHeadPositionZ(), - agentData->getLoudness(), - agentData->getAverageLoudness(), - agentData->getHandPositionX(), - agentData->getHandPositionY(), - agentData->getHandPositionZ()); +// int bytesWritten = sprintf((char *)currentPosition, +// PACKET_FORMAT, +// agentData->getPitch(), +// agentData->getYaw(), +// agentData->getRoll(), +// agentData->getHeadPositionX(), +// agentData->getHeadPositionY(), +// agentData->getHeadPositionZ(), +// agentData->getLoudness(), +// agentData->getAverageLoudness(), +// agentData->getHandPositionX(), +// agentData->getHandPositionY(), +// agentData->getHandPositionZ()); - currentPosition += bytesWritten; +// currentPosition += bytesWritten; return currentPosition; } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 17ae8df9cc..efd2a2e98b 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -12,8 +12,8 @@ #include #include -#include +#include #include "Orientation.h" enum AvatarBones From ed3f308a0e8a401dc670af815bfb0fdd793cf18f Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 16:08:35 -0700 Subject: [PATCH 07/20] pass ROOT_DIR to IncludeGLM macro instead of MACRO_DIR, include glm for AM --- avatar-mixer/CMakeLists.txt | 7 +++++++ cmake/macros/IncludeGLM.cmake | 6 +++--- interface/CMakeLists.txt | 2 +- libraries/avatars/CMakeLists.txt | 2 +- libraries/voxels/CMakeLists.txt | 4 +--- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/avatar-mixer/CMakeLists.txt b/avatar-mixer/CMakeLists.txt index 95cfd60a88..da25b6e981 100644 --- a/avatar-mixer/CMakeLists.txt +++ b/avatar-mixer/CMakeLists.txt @@ -5,10 +5,17 @@ set(TARGET_NAME "avatar-mixer") set(ROOT_DIR ..) set(MACRO_DIR ${ROOT_DIR}/cmake/macros) +# setup for find modules +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/") + # setup the project include(${MACRO_DIR}/SetupHifiProject.cmake) setup_hifi_project(${TARGET_NAME}) +# include glm +include(${MACRO_DIR}/IncludeGLM.cmake) +include_glm(${TARGET_NAME} ${ROOT_DIR}) + # link required hifi libraries include(${MACRO_DIR}/LinkHifiLibrary.cmake) link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) diff --git a/cmake/macros/IncludeGLM.cmake b/cmake/macros/IncludeGLM.cmake index f77ad9e06d..c5530bf8c9 100644 --- a/cmake/macros/IncludeGLM.cmake +++ b/cmake/macros/IncludeGLM.cmake @@ -1,5 +1,5 @@ -MACRO(INCLUDE_GLM TARGET MACRO_DIR) - set(GLM_ROOT_DIR ${MACRO_DIR}/../../externals) +MACRO(INCLUDE_GLM TARGET ROOT_DIR) + set(GLM_ROOT_DIR ${ROOT_DIR}/externals) find_package(GLM REQUIRED) include_directories(${GLM_INCLUDE_DIRS}) -ENDMACRO(INCLUDE_GLM _target _macro_dir) \ No newline at end of file +ENDMACRO(INCLUDE_GLM _target _root_dir) \ No newline at end of file diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 1dc201cfe9..de9b31c9df 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -26,7 +26,7 @@ endif (WIN32) # set up the external glm library include(${MACRO_DIR}/IncludeGLM.cmake) -include_glm(${TARGET_NAME} ${MACRO_DIR}) +include_glm(${TARGET_NAME} ${ROOT_DIR}) # create the InterfaceConfig.h file based on GL_HEADERS above configure_file(InterfaceConfig.h.in ${PROJECT_BINARY_DIR}/includes/InterfaceConfig.h) diff --git a/libraries/avatars/CMakeLists.txt b/libraries/avatars/CMakeLists.txt index 35bb4df9e9..b1c593a4a6 100644 --- a/libraries/avatars/CMakeLists.txt +++ b/libraries/avatars/CMakeLists.txt @@ -12,7 +12,7 @@ include(${MACRO_DIR}/SetupHifiLibrary.cmake) setup_hifi_library(${TARGET_NAME}) include(${MACRO_DIR}/IncludeGLM.cmake) -include_glm(${TARGET_NAME} ${MACRO_DIR}) +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 diff --git a/libraries/voxels/CMakeLists.txt b/libraries/voxels/CMakeLists.txt index 61718c58da..d873320064 100644 --- a/libraries/voxels/CMakeLists.txt +++ b/libraries/voxels/CMakeLists.txt @@ -11,10 +11,8 @@ set(TARGET_NAME voxels) include(${MACRO_DIR}/SetupHifiLibrary.cmake) setup_hifi_library(${TARGET_NAME}) -# include glm include(${MACRO_DIR}/IncludeGLM.cmake) -include_glm(${TARGET_NAME} ${MACRO_DIR}) +include_glm(${TARGET_NAME} ${ROOT_DIR}) -# link the shared library include(${MACRO_DIR}/LinkHifiLibrary.cmake) link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) \ No newline at end of file From a5a93443c6b48d01c1f133c19cefa4076ccd228e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 18:05:22 -0700 Subject: [PATCH 08/20] re-work AvatarData to handle body position and rotation --- avatar-mixer/src/main.cpp | 1 - interface/src/Audio.cpp | 2 +- interface/src/Head.cpp | 73 +++----------- interface/src/Head.h | 66 ++++++++++--- interface/src/VoxelSystem.cpp | 2 +- interface/src/main.cpp | 14 +-- libraries/avatars/src/AvatarData.cpp | 138 +++++++++++++-------------- libraries/avatars/src/AvatarData.h | 108 ++++----------------- libraries/shared/src/AgentList.cpp | 3 +- 9 files changed, 164 insertions(+), 243 deletions(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index 2a60112b4b..62c9cb07e7 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -35,7 +35,6 @@ #include "AvatarData.h" const int AVATAR_LISTEN_PORT = 55444; -const unsigned short BROADCAST_INTERVAL_USECS = 20 * 1000 * 1000; unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) { currentPosition += packAgentId(currentPosition, agentToAdd->getAgentId()); diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index db69dcb380..4300418856 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -156,7 +156,7 @@ int audioCallback (const void *inputBuffer, // memcpy the three float positions for (int p = 0; p < 3; p++) { - memcpy(currentPacketPtr, &data->linkedHead->getPos()[p], sizeof(float)); + memcpy(currentPacketPtr, &data->linkedHead->getBodyPosition()[p], sizeof(float)); currentPacketPtr += sizeof(float); } diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 244059576c..92d3fc6ed8 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -17,6 +17,7 @@ #include "Head.h" #include #include +#include using namespace std; @@ -125,7 +126,6 @@ Head::Head() { Head::Head(const Head &otherHead) { initializeAvatar(); - position = otherHead.position; //velocity = otherHead.velocity; //thrust = otherHead.thrust; for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = otherHead.driveKeys[i]; @@ -375,16 +375,16 @@ void Head::simulate(float deltaTime) { bodyYawDelta += YAW_MAG * deltaTime; } - bodyYaw += bodyYawDelta * deltaTime; + _bodyYaw += bodyYawDelta * deltaTime; - Yaw = bodyYaw; + Yaw = _bodyYaw; const float TEST_YAW_DECAY = 5.0; bodyYawDelta *= ( 1.0 - TEST_YAW_DECAY * deltaTime ); avatar.velocity += glm::dvec3( avatar.thrust * deltaTime ); - position += (glm::vec3)avatar.velocity * deltaTime; + _bodyPosition += (glm::vec3)avatar.velocity * deltaTime; //avatar.position += (glm::vec3)avatar.velocity * deltaTime; //position = avatar.position; @@ -515,7 +515,7 @@ void Head::render(int faceToFace, int isMine) { // show avatar position //--------------------------------------------------- glPushMatrix(); - glTranslatef( position.x, position.y, position.z ); + glTranslatef(_bodyPosition.x, _bodyPosition.y, _bodyPosition.z); glScalef( 0.03, 0.03, 0.03 ); glutSolidSphere( 1, 10, 10 ); glPopMatrix(); @@ -624,7 +624,7 @@ void Head::renderHead( int faceToFace, int isMine ) { //glRotatef(Yaw, 0, 1, 0); - glRotatef( bodyYaw, 0, 1, 0); + glRotatef( _bodyYaw, 0, 1, 0); //hand->render(1); @@ -780,9 +780,9 @@ void Head::initializeAvatar() { closestOtherAvatar = 0; - bodyYaw = -90.0; - bodyPitch = 0.0; - bodyRoll = 0.0; + _bodyYaw = -90.0; + _bodyPitch = 0.0; + _bodyRoll = 0.0; bodyYawDelta = 0.0; @@ -899,7 +899,7 @@ void Head::updateAvatarSkeleton() { // rotate... //---------------------------------- avatar.orientation.setToIdentity(); - avatar.orientation.yaw( bodyYaw ); + avatar.orientation.yaw( _bodyYaw ); //------------------------------------------------------------------------ // calculate positions of all bones by traversing the skeleton tree: @@ -907,7 +907,7 @@ void Head::updateAvatarSkeleton() { for (int b=0; bgetPos().x, hand->getPos().y, hand->getPos().z); //previous to Ventrella change - avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.x, - avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.y, - avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.z ); - return strlen(data); -} - - -//called on the other agents - assigns it to my views of the others -void Head::parseData(void *data, int size) { - sscanf - ( - (char *)data, "H%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f", - &Pitch, &Yaw, &Roll, - //&avatar.yaw, &avatar.pitch, &avatar.roll, - &position.x, &position.y, &position.z, - &loudness, &averageLoudness, - &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.x, - &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.y, - &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.z - ); - - handBeingMoved = true; -} - void Head::SetNewHeadTarget(float pitch, float yaw) { PitchTarget = pitch; YawTarget = yaw; diff --git a/interface/src/Head.h b/interface/src/Head.h index 0bf92aa546..06676c4231 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -34,6 +34,60 @@ enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH}; #define NUM_OTHER_AVATARS 5 +enum AvatarBones +{ + AVATAR_BONE_NULL = -1, + AVATAR_BONE_PELVIS_SPINE, // connects pelvis joint with torso joint (not supposed to be rotated) + AVATAR_BONE_MID_SPINE, // connects torso joint with chest joint + AVATAR_BONE_CHEST_SPINE, // connects chest joint with neckBase joint (not supposed to be rotated) + AVATAR_BONE_NECK, // connects neckBase joint with headBase joint + AVATAR_BONE_HEAD, // connects headBase joint with headTop joint + AVATAR_BONE_LEFT_CHEST, // connects chest joint with left clavicle joint (not supposed to be rotated) + AVATAR_BONE_LEFT_SHOULDER, // connects left clavicle joint with left shoulder joint + AVATAR_BONE_LEFT_UPPER_ARM, // connects left shoulder joint with left elbow joint + AVATAR_BONE_LEFT_FOREARM, // connects left elbow joint with left wrist joint + AVATAR_BONE_LEFT_HAND, // connects left wrist joint with left fingertips joint + AVATAR_BONE_RIGHT_CHEST, // connects chest joint with right clavicle joint (not supposed to be rotated) + AVATAR_BONE_RIGHT_SHOULDER, // connects right clavicle joint with right shoulder joint + AVATAR_BONE_RIGHT_UPPER_ARM, // connects right shoulder joint with right elbow joint + AVATAR_BONE_RIGHT_FOREARM, // connects right elbow joint with right wrist joint + AVATAR_BONE_RIGHT_HAND, // connects right wrist joint with right fingertips joint + AVATAR_BONE_LEFT_PELVIS, // connects pelvis joint with left hip joint (not supposed to be rotated) + AVATAR_BONE_LEFT_THIGH, // connects left hip joint with left knee joint + AVATAR_BONE_LEFT_SHIN, // connects left knee joint with left heel joint + AVATAR_BONE_LEFT_FOOT, // connects left heel joint with left toes joint + AVATAR_BONE_RIGHT_PELVIS, // connects pelvis joint with right hip joint (not supposed to be rotated) + AVATAR_BONE_RIGHT_THIGH, // connects right hip joint with right knee joint + AVATAR_BONE_RIGHT_SHIN, // connects right knee joint with right heel joint + AVATAR_BONE_RIGHT_FOOT, // connects right heel joint with right toes joint + + NUM_AVATAR_BONES +}; + +struct AvatarBone +{ + AvatarBones parent; // which bone is this bone connected to? + glm::vec3 position; // the position at the "end" of the bone + glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose" + glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) + glm::dvec3 springyVelocity; // used for special effects ( the velocity of the springy position) + float springBodyTightness; // how tightly (0 to 1) the springy position tries to stay on the position + float yaw; // the yaw Euler angle of the bone rotation off the parent + float pitch; // the pitch Euler angle of the bone rotation off the parent + float roll; // the roll Euler angle of the bone rotation off the parent + Orientation orientation; // three orthogonal normals determined by yaw, pitch, roll + float length; // the length of the bone +}; + +struct Avatar +{ + glm::dvec3 velocity; + glm::vec3 thrust; + float maxArmLength; + Orientation orientation; + AvatarBone bone[ NUM_AVATAR_BONES ]; +}; + class Head : public AvatarData { public: Head(); @@ -69,7 +123,6 @@ class Head : public AvatarData { glm::vec3 getHeadLookatDirectionRight(); glm::vec3 getHeadPosition(); glm::vec3 getBonePosition( AvatarBones b ); - glm::vec3 getBodyPosition(); void render(int faceToFace, int isMine); @@ -82,18 +135,12 @@ class Head : public AvatarData { void setHandMovement( glm::vec3 movement ); void updateHandMovement(); - // Send and receive network data - int getBroadcastData(char * data); - void parseData(void *data, int size); - float getLoudness() {return loudness;}; float getAverageLoudness() {return averageLoudness;}; void setAverageLoudness(float al) {averageLoudness = al;}; void setLoudness(float l) {loudness = l;}; void SetNewHeadTarget(float, float); - glm::vec3 getPos() { return position; }; - void setPos(glm::vec3 newpos) { position = newpos; }; // Set what driving keys are being pressed to control thrust levels void setDriveKeys(int key, bool val) { driveKeys[key] = val; }; @@ -145,12 +192,7 @@ class Head : public AvatarData { float averageLoudness; float audioAttack; float browAudioLift; - - glm::vec3 position; - float bodyYaw; - float bodyPitch; - float bodyRoll; float bodyYawDelta; float closeEnoughToInteract; diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index d9df0fd0d8..33b063ef38 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -184,7 +184,7 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, float nodePosition[3]) { int voxelsAdded = 0; float halfUnitForVoxel = powf(0.5, *currentNode->octalCode) * (0.5 * TREE_SCALE); - glm::vec3 viewerPosition = viewerHead->getPos(); + glm::vec3 viewerPosition = viewerHead->getBodyPosition(); // XXXBHG - Note: It appears as if the X and Z coordinates of Head or Agent are flip-flopped relative to the // coords of the voxel space. This flip flop causes LOD behavior to be extremely odd. This is my temporary hack diff --git a/interface/src/main.cpp b/interface/src/main.cpp index afbff94616..eb61281541 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -222,7 +222,7 @@ void displayStats(void) char legend2[] = "* - toggle stars, & - toggle paint mode, '-' - send erase all, '%' - send add scene"; drawtext(10, statsVerticalOffset + 32, 0.10f, 0, 1.0, 0, legend2); - glm::vec3 avatarPos = myAvatar.getPos(); + glm::vec3 avatarPos = myAvatar.getBodyPosition(); char stats[200]; sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d Head(x,y,z)= %4.2f, %4.2f, %4.2f ", @@ -308,7 +308,7 @@ void init(void) if (noiseOn) { myAvatar.setNoise(noise); } - myAvatar.setPos(start_location ); + myAvatar.setBodyPosition(start_location); myCamera.setPosition( start_location ); @@ -350,7 +350,7 @@ void reset_sensors() yaw = renderYawRate = 0; pitch = renderPitch = renderPitchRate = 0; - myAvatar.setPos(start_location); + myAvatar.setBodyPosition(start_location); headMouseX = WIDTH/2; headMouseY = HEIGHT/2; @@ -461,7 +461,7 @@ void simulateHead(float frametime) // If I'm in paint mode, send a voxel out to VOXEL server agents. if (::paintOn) { - glm::vec3 avatarPos = myAvatar.getPos(); + glm::vec3 avatarPos = myAvatar.getBodyPosition(); // For some reason, we don't want to flip X and Z here. ::paintingVoxel.x = avatarPos.x/10.0; @@ -687,7 +687,7 @@ void display(void) //-------------------------------------------------------- // camera settings //-------------------------------------------------------- - myCamera.setTargetPosition( myAvatar.getPos() ); + myCamera.setTargetPosition( myAvatar.getBodyPosition() ); if ( displayHead ) { //----------------------------------------------- @@ -799,7 +799,7 @@ void display(void) if (agent->getLinkedData() != NULL) { Head *agentHead = (Head *)agent->getLinkedData(); glPushMatrix(); - glm::vec3 pos = agentHead->getPos(); + glm::vec3 pos = agentHead->getBodyPosition(); glTranslatef(-pos.x, -pos.y, -pos.z); agentHead->render(0, 0); glPopMatrix(); @@ -1083,7 +1083,7 @@ void shiftPaintingColor() } void setupPaintingVoxel() { - glm::vec3 avatarPos = myAvatar.getPos(); + glm::vec3 avatarPos = myAvatar.getBodyPosition(); ::paintingVoxel.x = avatarPos.z/-10.0; // voxel space x is negative z head space ::paintingVoxel.y = avatarPos.y/-10.0; // voxel space y is negative y head space diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index c1f862b14c..d8f3862e27 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -8,9 +8,28 @@ #include +#include + #include "AvatarData.h" -AvatarData::AvatarData() { +int packFloatAngleToTwoByte(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 / std::numeric_limits::max()) * 360.0 - 180; + return sizeof(uint16_t); +} + +AvatarData::AvatarData() : + _bodyYaw(-90.0), + _bodyPitch(0.0), + _bodyRoll(0.0) { } @@ -22,97 +41,70 @@ AvatarData* AvatarData::clone() const { return new AvatarData(*this); } -void AvatarData::parseData(void *data, int size) { - char* packetData = (char *)data + 1; +// transmit data to agents requesting it +// called on me just prior to sending data to others (continuasly called) +int AvatarData::getBroadcastData(char* destinationBuffer) { + char* bufferPointer = destinationBuffer; + *(bufferPointer++) = PACKET_HEADER_HEAD_DATA; + + // TODO: DRY this up to a shared method + // that can pack any type given the number of bytes + // and return the number of bytes to push the pointer + memcpy(bufferPointer, &_bodyPosition, sizeof(float) * 3); + bufferPointer += sizeof(float) * 3; -// // Extract data from packet -// sscanf(packetData, -// PACKET_FORMAT, -// &_pitch, -// &_yaw, -// &_roll, -// &_headPositionX, -// &_headPositionY, -// &_headPositionZ, -// &_loudness, -// &_averageLoudness, -// &_handPositionX, -// &_handPositionY, -// &_handPositionZ); + bufferPointer += packFloatAngleToTwoByte(bufferPointer, _bodyYaw); + bufferPointer += packFloatAngleToTwoByte(bufferPointer, _bodyPitch); + bufferPointer += packFloatAngleToTwoByte(bufferPointer, _bodyRoll); + + return bufferPointer - destinationBuffer; } -float AvatarData::getPitch() { - return _pitch; +// called on the other agents - assigns it to my views of the others +void AvatarData::parseData(void *sourceBuffer, int numBytes) { + + char* bufferPointer = (char*) sourceBuffer + 1; + + memcpy(&_bodyPosition, bufferPointer, sizeof(float) * 3); + bufferPointer += sizeof(float) * 3; + + bufferPointer += unpackFloatAngleFromTwoByte((uint16_t*)bufferPointer, &_bodyYaw); + bufferPointer += unpackFloatAngleFromTwoByte((uint16_t*)bufferPointer, &_bodyPitch); + bufferPointer += unpackFloatAngleFromTwoByte((uint16_t*)bufferPointer, &_bodyRoll); } -float AvatarData::getYaw() { - return _yaw; +glm::vec3 AvatarData::getBodyPosition() { + return glm::vec3(_bodyPosition.x, + _bodyPosition.y, + _bodyPosition.z); } -float AvatarData::getRoll() { - return _roll; +void AvatarData::setBodyPosition(glm::vec3 bodyPosition) { + _bodyPosition = bodyPosition; } -float AvatarData::getHeadPositionX() { - return _headPositionX; +float AvatarData::getBodyYaw() { + return _bodyYaw; } -float AvatarData::getHeadPositionY() { - return _headPositionY; +void AvatarData::setBodyYaw(float bodyYaw) { + _bodyYaw = bodyYaw; } -float AvatarData::getHeadPositionZ() { - return _headPositionZ; +float AvatarData::getBodyPitch() { + return _bodyPitch; } -float AvatarData::getLoudness() { - return _loudness; +void AvatarData::setBodyPitch(float bodyPitch) { + _bodyPitch = bodyPitch; } -float AvatarData::getAverageLoudness() { - return _averageLoudness; +float AvatarData::getBodyRoll() { + return _bodyRoll; } -float AvatarData::getHandPositionX() { - return _handPositionX; +void AvatarData::setBodyRoll(float bodyRoll) { + _bodyRoll = bodyRoll; } -float AvatarData::getHandPositionY() { - return _handPositionY; -} -float AvatarData::getHandPositionZ() { - return _handPositionZ; -} - -void AvatarData::setPitch(float pitch) { - _pitch = pitch; -} - -void AvatarData::setYaw(float yaw) { - _yaw = yaw; -} - -void AvatarData::setRoll(float roll) { - _roll = roll; -} - -void AvatarData::setHeadPosition(float x, float y, float z) { - _headPositionX = x; - _headPositionY = y; - _headPositionZ = z; -} - -void AvatarData::setLoudness(float loudness) { - _loudness = loudness; -} - -void AvatarData::setAverageLoudness(float averageLoudness) { - _averageLoudness = averageLoudness; -} - -void AvatarData::setHandPosition(float x, float y, float z) { - _handPositionX = x; - _handPositionY = y; - _handPositionZ = z; -} diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index efd2a2e98b..9dbc04a1f7 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -14,101 +14,35 @@ #include #include -#include "Orientation.h" - -enum AvatarBones -{ - AVATAR_BONE_NULL = -1, - AVATAR_BONE_PELVIS_SPINE, // connects pelvis joint with torso joint (not supposed to be rotated) - AVATAR_BONE_MID_SPINE, // connects torso joint with chest joint - AVATAR_BONE_CHEST_SPINE, // connects chest joint with neckBase joint (not supposed to be rotated) - AVATAR_BONE_NECK, // connects neckBase joint with headBase joint - AVATAR_BONE_HEAD, // connects headBase joint with headTop joint - AVATAR_BONE_LEFT_CHEST, // connects chest joint with left clavicle joint (not supposed to be rotated) - AVATAR_BONE_LEFT_SHOULDER, // connects left clavicle joint with left shoulder joint - AVATAR_BONE_LEFT_UPPER_ARM, // connects left shoulder joint with left elbow joint - AVATAR_BONE_LEFT_FOREARM, // connects left elbow joint with left wrist joint - AVATAR_BONE_LEFT_HAND, // connects left wrist joint with left fingertips joint - AVATAR_BONE_RIGHT_CHEST, // connects chest joint with right clavicle joint (not supposed to be rotated) - AVATAR_BONE_RIGHT_SHOULDER, // connects right clavicle joint with right shoulder joint - AVATAR_BONE_RIGHT_UPPER_ARM, // connects right shoulder joint with right elbow joint - AVATAR_BONE_RIGHT_FOREARM, // connects right elbow joint with right wrist joint - AVATAR_BONE_RIGHT_HAND, // connects right wrist joint with right fingertips joint - AVATAR_BONE_LEFT_PELVIS, // connects pelvis joint with left hip joint (not supposed to be rotated) - AVATAR_BONE_LEFT_THIGH, // connects left hip joint with left knee joint - AVATAR_BONE_LEFT_SHIN, // connects left knee joint with left heel joint - AVATAR_BONE_LEFT_FOOT, // connects left heel joint with left toes joint - AVATAR_BONE_RIGHT_PELVIS, // connects pelvis joint with right hip joint (not supposed to be rotated) - AVATAR_BONE_RIGHT_THIGH, // connects right hip joint with right knee joint - AVATAR_BONE_RIGHT_SHIN, // connects right knee joint with right heel joint - AVATAR_BONE_RIGHT_FOOT, // connects right heel joint with right toes joint - - NUM_AVATAR_BONES -}; - -struct AvatarBone -{ - AvatarBones parent; // which bone is this bone connected to? - glm::vec3 position; // the position at the "end" of the bone - glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose" - glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) - glm::dvec3 springyVelocity; // used for special effects ( the velocity of the springy position) - float springBodyTightness; // how tightly (0 to 1) the springy position tries to stay on the position - float yaw; // the yaw Euler angle of the bone rotation off the parent - float pitch; // the pitch Euler angle of the bone rotation off the parent - float roll; // the roll Euler angle of the bone rotation off the parent - Orientation orientation; // three orthogonal normals determined by yaw, pitch, roll - float length; // the length of the bone -}; - -struct Avatar -{ - glm::dvec3 velocity; - glm::vec3 thrust; - float maxArmLength; - Orientation orientation; - AvatarBone bone[ NUM_AVATAR_BONES ]; -}; class AvatarData : public AgentData { public: AvatarData(); ~AvatarData(); - void parseData(void *data, int size); AvatarData* clone() const; - float getPitch(); - void setPitch(float pitch); - float getYaw(); - void setYaw(float yaw); - float getRoll(); - void setRoll(float roll); - float getHeadPositionX(); - float getHeadPositionY(); - float getHeadPositionZ(); - void setHeadPosition(float x, float y, float z); - float getLoudness(); - void setLoudness(float loudness); - float getAverageLoudness(); - void setAverageLoudness(float averageLoudness); - float getHandPositionX(); - float getHandPositionY(); - float getHandPositionZ(); - void setHandPosition(float x, float y, float z); - -private: - float _pitch; - float _yaw; - float _roll; - float _headPositionX; - float _headPositionY; - float _headPositionZ; - float _loudness; - float _averageLoudness; - float _handPositionX; - float _handPositionY; - float _handPositionZ; + glm::vec3 getBodyPosition(); + void setBodyPosition(glm::vec3 bodyPosition); + + int getBroadcastData(char* destinationBuffer); + void parseData(void *sourceBuffer, int numBytes); + + float getBodyYaw(); + void setBodyYaw(float bodyYaw); + + float getBodyPitch(); + void setBodyPitch(float bodyPitch); + + float getBodyRoll(); + void setBodyRoll(float bodyRoll); + +protected: + glm::vec3 _bodyPosition; + + float _bodyYaw; + float _bodyPitch; + float _bodyRoll; }; #endif /* defined(__hifi__AvatarData__) */ diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 4895e421cd..346785ab61 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -118,8 +118,9 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, void *packetData, while ((currentPosition - startPosition) < numTotalBytes) { currentPosition += unpackAgentId(currentPosition, &agentID); memcpy(packetHolder + 1, currentPosition, numBytesPerAgent); - + int matchingAgentIndex = indexOfMatchingAgent(agentID); + if (matchingAgentIndex >= 0) { updateAgentWithData(&agents[matchingAgentIndex], packetHolder, numBytesPerAgent + 1); } From 61cf17da731691c548ac5cf69290a85ebd24a98c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 18:19:01 -0700 Subject: [PATCH 09/20] update agent-mixer to use new AvatarData class --- avatar-mixer/src/main.cpp | 18 ++---------------- libraries/avatars/src/AvatarData.cpp | 3 +-- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index 62c9cb07e7..439da691a0 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -40,22 +40,8 @@ unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent * currentPosition += packAgentId(currentPosition, agentToAdd->getAgentId()); AvatarData *agentData = (AvatarData *)agentToAdd->getLinkedData(); + currentPosition += agentData->getBroadcastData((char *) currentPosition); -// int bytesWritten = sprintf((char *)currentPosition, -// PACKET_FORMAT, -// agentData->getPitch(), -// agentData->getYaw(), -// agentData->getRoll(), -// agentData->getHeadPositionX(), -// agentData->getHeadPositionY(), -// agentData->getHeadPositionZ(), -// agentData->getLoudness(), -// agentData->getAverageLoudness(), -// agentData->getHandPositionX(), -// agentData->getHandPositionY(), -// agentData->getHandPositionZ()); - -// currentPosition += bytesWritten; return currentPosition; } @@ -91,7 +77,7 @@ int main(int argc, char* argv[]) switch (packetData[0]) { case PACKET_HEADER_HEAD_DATA: // this is positional data from an agent - agentList->updateAgentWithData(agentAddress, (void *)packetData, receivedBytes); + agentList->updateAgentWithData(agentAddress, (void *)(packetData + 1), receivedBytes); currentBufferPosition = broadcastPacket + 1; agentIndex = 0; diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index d8f3862e27..40695766c3 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -45,7 +45,6 @@ AvatarData* AvatarData::clone() const { // called on me just prior to sending data to others (continuasly called) int AvatarData::getBroadcastData(char* destinationBuffer) { char* bufferPointer = destinationBuffer; - *(bufferPointer++) = PACKET_HEADER_HEAD_DATA; // TODO: DRY this up to a shared method // that can pack any type given the number of bytes @@ -63,7 +62,7 @@ int AvatarData::getBroadcastData(char* destinationBuffer) { // called on the other agents - assigns it to my views of the others void AvatarData::parseData(void *sourceBuffer, int numBytes) { - char* bufferPointer = (char*) sourceBuffer + 1; + char* bufferPointer = (char*) sourceBuffer ; memcpy(&_bodyPosition, bufferPointer, sizeof(float) * 3); bufferPointer += sizeof(float) * 3; From 2b4944203975b5e3495a7955e50c6c9dc7a7c07e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 18:34:40 -0700 Subject: [PATCH 10/20] resolve conflicts on merge with upstream master --- interface/src/Camera.cpp | 0 interface/src/Camera.h | 0 interface/src/Head.cpp | 83 ++++++++++++++++++++++++++++++++-------- interface/src/Head.h | 10 +++-- 4 files changed, 74 insertions(+), 19 deletions(-) mode change 100755 => 100644 interface/src/Camera.cpp mode change 100755 => 100644 interface/src/Camera.h diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp old mode 100755 new mode 100644 diff --git a/interface/src/Camera.h b/interface/src/Camera.h old mode 100755 new mode 100644 diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 7af3347a7c..898d213781 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -122,8 +122,6 @@ Head::Head() { Head::Head(const Head &otherHead) { initializeAvatar(); - //velocity = otherHead.velocity; - //thrust = otherHead.thrust; for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = otherHead.driveKeys[i]; PupilSize = otherHead.PupilSize; @@ -362,8 +360,26 @@ void Head::simulate(float deltaTime) { bodyYawDelta += YAW_MAG * deltaTime; } + //---------------------------------------------------------- + float translationalSpeed = glm::length( avatar.velocity ); + float rotationalSpeed = fabs( bodyYawDelta ); + if ( translationalSpeed + rotationalSpeed > 0.2 ) + { + mode = AVATAR_MODE_WALKING; + } + else + { + mode = AVATAR_MODE_COMMUNICATING; + } + + //---------------------------------------------------------- + // update body yaw by body yaw delta + //---------------------------------------------------------- _bodyYaw += bodyYawDelta * deltaTime; + //---------------------------------------------------------- + // (for now) set head yaw to body yaw + //---------------------------------------------------------- Yaw = _bodyYaw; //---------------------------------------------------------- @@ -377,11 +393,10 @@ void Head::simulate(float deltaTime) { //---------------------------------------------------------- avatar.velocity += glm::dvec3( avatar.thrust * deltaTime ); + //---------------------------------------------------------- + // update position by velocity + //---------------------------------------------------------- _bodyPosition += (glm::vec3)avatar.velocity * deltaTime; - //avatar.position += (glm::vec3)avatar.velocity * deltaTime; - //position = avatar.position; - - //avatar.velocity *= 0.9; //---------------------------------------------------------- // decay velocity @@ -600,12 +615,7 @@ void Head::renderHead( int faceToFace, int isMine ) { glScalef( 0.03, 0.03, 0.03 ); - - //glTranslatef(leanSideways, 0.f, leanForward); - - //glRotatef(Yaw, 0, 1, 0); - - glRotatef( _bodyYaw, 0, 1, 0); + glRotatef(_bodyYaw, 0, 1, 0); // Don't render a head if it is really close to your location, because that is your own head! @@ -892,9 +902,14 @@ void Head::updateAvatarSkeleton() { // calculate positions of all bones by traversing the skeleton tree: //------------------------------------------------------------------------ for (int b=0; bgetPos().x, hand->getPos().y, hand->getPos().z); //previous to Ventrella change + bone[ AVATAR_BONE_RIGHT_HAND ].position.x, + bone[ AVATAR_BONE_RIGHT_HAND ].position.y, + bone[ AVATAR_BONE_RIGHT_HAND ].position.z ); + return strlen(data); +} + + +//called on the other agents - assigns it to my views of the others +void Head::parseData(void *data, int size) { + sscanf + ( + (char *)data, "H%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f", + &Pitch, &Yaw, &Roll, + //&avatar.yaw, &avatar.pitch, &avatar.roll, + &bodyPosition.x, &bodyPosition.y, &bodyPosition.z, + &loudness, &averageLoudness, + &bone[ AVATAR_BONE_RIGHT_HAND ].position.x, + &bone[ AVATAR_BONE_RIGHT_HAND ].position.y, + &bone[ AVATAR_BONE_RIGHT_HAND ].position.z + ); + + handBeingMoved = true; +} + void Head::SetNewHeadTarget(float pitch, float yaw) { PitchTarget = pitch; YawTarget = yaw; diff --git a/interface/src/Head.h b/interface/src/Head.h index d11c08128e..5b3c7eeeff 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -42,8 +42,6 @@ enum AvatarMode NUM_AVATAR_MODES }; - - enum AvatarBones { AVATAR_BONE_NULL = -1, @@ -131,7 +129,11 @@ class Head : public AvatarData { glm::vec3 getHeadLookatDirectionUp(); glm::vec3 getHeadLookatDirectionRight(); glm::vec3 getHeadPosition(); - glm::vec3 getBonePosition( AvatarBones b ); + glm::vec3 getBonePosition( AvatarBones b ); + + AvatarMode getMode(); + + void setTriggeringAction( bool trigger ); void render(int faceToFace, int isMine); @@ -202,6 +204,8 @@ class Head : public AvatarData { float audioAttack; float browAudioLift; + bool triggeringAction; + float bodyYawDelta; float closeEnoughToInteract; From 861c8e76ee6ec41e9eb9b9eb2cfd135072908e1d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 18:35:46 -0700 Subject: [PATCH 11/20] grab jeffrey's changes to Util consts --- libraries/shared/src/SharedUtil.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index d2402bb21f..6941c74462 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -18,9 +18,9 @@ #include #endif -static const double ZERO = 0.0; -static const double ONE = 1.0; -static const double ONE_HALF = 0.5; +static const float ZERO = 0.0; +static const float ONE = 1.0; +static const float ONE_HALF = 0.5; static const double ONE_THIRD = 0.3333333; static const double PIE = 3.14159265359; static const double PI_TIMES_TWO = 3.14159265359 * 2.0; @@ -28,10 +28,10 @@ static const double PI_OVER_180 = 3.14159265359 / 180.0; static const double EPSILON = 0.00001; //smallish number - used as margin of error for some computations static const double SQUARE_ROOT_OF_2 = sqrt(2); static const double SQUARE_ROOT_OF_3 = sqrt(3); -static const double METER = 1.0; -static const double DECIMETER = 0.1; -static const double CENTIMETER = 0.01; -static const double MILLIIMETER = 0.001; +static const float METER = 1.0; +static const float DECIMETER = 0.1; +static const float CENTIMETER = 0.01; +static const float MILLIIMETER = 0.001; double usecTimestamp(timeval *time); double usecTimestampNow(); From 288a259ac186610bbb70fc58999ba360d9d14f54 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 18:37:25 -0700 Subject: [PATCH 12/20] more conflict resolutions for broken build after pull --- interface/src/Head.cpp | 36 ------------------------------------ interface/src/main.cpp | 4 ++-- 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 898d213781..2e679763f0 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -1169,42 +1169,6 @@ void Head::renderBody() { } - - -// Transmit data to agents requesting it -// called on me just prior to sending data to others (continuasly called) -int Head::getBroadcastData(char* data) { - // Copy data for transmission to the buffer, return length of data - sprintf(data, "H%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f", - getRenderPitch() + Pitch, -getRenderYaw() + 180 -Yaw, Roll, - //avatar.yaw, avatar.pitch, avatar.roll, - bodyPosition.x + leanSideways, bodyPosition.y, bodyPosition.z + leanForward, - loudness, averageLoudness, - //hand->getPos().x, hand->getPos().y, hand->getPos().z); //previous to Ventrella change - bone[ AVATAR_BONE_RIGHT_HAND ].position.x, - bone[ AVATAR_BONE_RIGHT_HAND ].position.y, - bone[ AVATAR_BONE_RIGHT_HAND ].position.z ); - return strlen(data); -} - - -//called on the other agents - assigns it to my views of the others -void Head::parseData(void *data, int size) { - sscanf - ( - (char *)data, "H%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f", - &Pitch, &Yaw, &Roll, - //&avatar.yaw, &avatar.pitch, &avatar.roll, - &bodyPosition.x, &bodyPosition.y, &bodyPosition.z, - &loudness, &averageLoudness, - &bone[ AVATAR_BONE_RIGHT_HAND ].position.x, - &bone[ AVATAR_BONE_RIGHT_HAND ].position.y, - &bone[ AVATAR_BONE_RIGHT_HAND ].position.z - ); - - handBeingMoved = true; -} - void Head::SetNewHeadTarget(float pitch, float yaw) { PitchTarget = pitch; YawTarget = yaw; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 46d72bb076..9df332a25e 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -696,7 +696,7 @@ void display(void) //----------------------------------------------- // set the camera to looking at my own face //----------------------------------------------- - myCamera.setTargetPosition ( myAvatar.getPos() ); + myCamera.setTargetPosition ( myAvatar.getBodyPosition() ); myCamera.setYaw ( - myAvatar.getBodyYaw() ); myCamera.setPitch ( 0.0 ); myCamera.setRoll ( 0.0 ); @@ -708,7 +708,7 @@ void display(void) //---------------------------------------------------- // set the camera to third-person view behind my av //---------------------------------------------------- - myCamera.setTargetPosition ( myAvatar.getPos() ); + myCamera.setTargetPosition ( myAvatar.getBodyPosition() ); myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() ); myCamera.setPitch ( 10.0 ); myCamera.setRoll ( 0.0 ); From 5c091a51a60e2e7376646426c16b27e89028acb8 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Apr 2013 11:51:36 -0700 Subject: [PATCH 13/20] change signature of parseData to use unsigned char*, include packet header always --- audio-mixer/src/main.cpp | 2 +- avatar-mixer/src/main.cpp | 2 +- interface/src/Head.cpp | 2 +- interface/src/Head.h | 4 ++-- interface/src/VoxelSystem.cpp | 16 ++++++++-------- interface/src/VoxelSystem.h | 2 +- interface/src/main.cpp | 2 +- libraries/avatars/src/AvatarData.cpp | 15 ++++++++------- libraries/avatars/src/AvatarData.h | 2 +- libraries/shared/src/AgentData.h | 2 +- libraries/shared/src/AgentList.cpp | 6 +++--- libraries/shared/src/AgentList.h | 8 ++++---- libraries/shared/src/AudioRingBuffer.cpp | 12 +++++------- libraries/shared/src/AudioRingBuffer.h | 2 +- voxel-server/src/VoxelAgentData.h | 2 +- voxel-server/src/main.cpp | 2 +- 16 files changed, 40 insertions(+), 41 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 9f77bbc9bb..0d571d1c74 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -309,7 +309,7 @@ int main(int argc, const char * argv[]) agentList->increaseAgentId(); } - agentList->updateAgentWithData(agentAddress, (void *)packetData, receivedBytes); + agentList->updateAgentWithData(agentAddress, packetData, receivedBytes); } else { memcpy(loopbackAudioPacket, packetData + 1 + (sizeof(float) * 4), 1024); agentList->getAgentSocket().send(agentAddress, loopbackAudioPacket, 1024); diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index 439da691a0..b92cff6783 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) switch (packetData[0]) { case PACKET_HEADER_HEAD_DATA: // this is positional data from an agent - agentList->updateAgentWithData(agentAddress, (void *)(packetData + 1), receivedBytes); + agentList->updateAgentWithData(agentAddress, packetData, receivedBytes); currentBufferPosition = broadcastPacket + 1; agentIndex = 0; diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 2e679763f0..4589636f77 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -1174,7 +1174,7 @@ void Head::SetNewHeadTarget(float pitch, float yaw) { YawTarget = yaw; } -void Head::processTransmitterData(char *packetData, int numBytes) { +void Head::processTransmitterData(unsigned char *packetData, int numBytes) { // Read a packet from a transmitter app, process the data float accX, accY, accZ, graX, graY, graZ, diff --git a/interface/src/Head.h b/interface/src/Head.h index 5b3c7eeeff..ad4f1f665f 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -139,7 +139,7 @@ class Head : public AvatarData { void renderBody(); void renderHead( int faceToFace, int isMine ); - void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ); + void renderOrientataionDirections( glm::vec3 position, Orientation orientation, float size ); void simulate(float); @@ -166,7 +166,7 @@ class Head : public AvatarData { // Related to getting transmitter UDP data used to animate the avatar hand // - void processTransmitterData(char * packetData, int numBytes); + void processTransmitterData(unsigned char * packetData, int numBytes); float getTransmitterHz() { return transmitterHz; }; private: diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 33b063ef38..ba12218f45 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -112,33 +112,33 @@ long int VoxelSystem::getVoxelsBytesReadRunningAverage() { } -void VoxelSystem::parseData(void *data, int size) { +void VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { - unsigned char command = *(unsigned char*)data; - unsigned char *voxelData = (unsigned char *) data + 1; + unsigned char command = *sourceBuffer; + unsigned char *voxelData = sourceBuffer + 1; switch(command) { case PACKET_HEADER_VOXEL_DATA: // ask the VoxelTree to read the bitstream into the tree - tree->readBitstreamToTree(voxelData, size - 1); + tree->readBitstreamToTree(voxelData, numBytes - 1); break; case PACKET_HEADER_ERASE_VOXEL: // ask the tree to read the "remove" bitstream - tree->processRemoveVoxelBitstream((unsigned char*)data,size); + tree->processRemoveVoxelBitstream(sourceBuffer, numBytes); break; case PACKET_HEADER_Z_COMMAND: // the Z command is a special command that allows the sender to send high level semantic // requests, like erase all, or add sphere scene, different receivers may handle these // messages differently - char* packetData =(char*)data; + char* packetData = (char *)sourceBuffer; char* command = &packetData[1]; // start of the command int commandLength = strlen(command); // commands are null terminated strings int totalLength = 1+commandLength+1; - printf("got Z message len(%d)= %s\n",size,command); + printf("got Z message len(%d)= %s\n", numBytes, command); - while (totalLength <= size) { + while (totalLength <= numBytes) { if (0==strcmp(command,(char*)"erase all")) { printf("got Z message == erase all\n"); tree->eraseAllVoxels(); diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index f49b57d612..a8bfd376c5 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -26,7 +26,7 @@ public: VoxelSystem(); ~VoxelSystem(); - void parseData(void *data, int size); + void parseData(unsigned char* sourceBuffer, int numBytes); VoxelSystem* clone() const; void init(); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 9df332a25e..75bf28cc26 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1260,7 +1260,7 @@ void *networkReceive(void *args) { sockaddr senderAddress; ssize_t bytesReceived; - char *incomingPacket = new char[MAX_PACKET_SIZE]; + unsigned char *incomingPacket = new unsigned char[MAX_PACKET_SIZE]; while (!stopNetworkReceiveThread) { if (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) { diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 40695766c3..73641fe94c 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -60,16 +60,17 @@ int AvatarData::getBroadcastData(char* destinationBuffer) { } // called on the other agents - assigns it to my views of the others -void AvatarData::parseData(void *sourceBuffer, int numBytes) { +void AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { - char* bufferPointer = (char*) sourceBuffer ; + // increment to push past the packet header + sourceBuffer++; - memcpy(&_bodyPosition, bufferPointer, sizeof(float) * 3); - bufferPointer += sizeof(float) * 3; + memcpy(&_bodyPosition, sourceBuffer, sizeof(float) * 3); + sourceBuffer += sizeof(float) * 3; - bufferPointer += unpackFloatAngleFromTwoByte((uint16_t*)bufferPointer, &_bodyYaw); - bufferPointer += unpackFloatAngleFromTwoByte((uint16_t*)bufferPointer, &_bodyPitch); - bufferPointer += unpackFloatAngleFromTwoByte((uint16_t*)bufferPointer, &_bodyRoll); + sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyYaw); + sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyPitch); + sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyRoll); } glm::vec3 AvatarData::getBodyPosition() { diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 9dbc04a1f7..464927a98c 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -26,7 +26,7 @@ public: void setBodyPosition(glm::vec3 bodyPosition); int getBroadcastData(char* destinationBuffer); - void parseData(void *sourceBuffer, int numBytes); + void parseData(unsigned char* sourceBuffer, int numBytes); float getBodyYaw(); void setBodyYaw(float bodyYaw); diff --git a/libraries/shared/src/AgentData.h b/libraries/shared/src/AgentData.h index 9db7535521..640798b52b 100644 --- a/libraries/shared/src/AgentData.h +++ b/libraries/shared/src/AgentData.h @@ -12,7 +12,7 @@ class AgentData { public: virtual ~AgentData() = 0; - virtual void parseData(void * data, int size) = 0; + virtual void parseData(unsigned char* sourceBuffer, int numBytes) = 0; virtual AgentData* clone() const = 0; }; diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 346785ab61..092ce6de3f 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -98,7 +98,7 @@ void AgentList::processAgentData(sockaddr *senderAddress, void *packetData, size } } -void AgentList::processBulkAgentData(sockaddr *senderAddress, void *packetData, int numTotalBytes, int numBytesPerAgent) { +void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes, int numBytesPerAgent) { // find the avatar mixer in our agent list and update the lastRecvTime from it int bulkSendAgentIndex = indexOfMatchingAgent(senderAddress); @@ -131,7 +131,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, void *packetData, delete[] packetHolder; } -void AgentList::updateAgentWithData(sockaddr *senderAddress, void *packetData, size_t dataBytes) { +void AgentList::updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) { // find the agent by the sockaddr int agentIndex = indexOfMatchingAgent(senderAddress); @@ -140,7 +140,7 @@ void AgentList::updateAgentWithData(sockaddr *senderAddress, void *packetData, s } } -void AgentList::updateAgentWithData(Agent *agent, void *packetData, int dataBytes) { +void AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes) { agent->setLastRecvTimeUsecs(usecTimestampNow()); if (agent->getLinkedData() == NULL) { diff --git a/libraries/shared/src/AgentList.h b/libraries/shared/src/AgentList.h index 454d02ea1a..8c77b557de 100644 --- a/libraries/shared/src/AgentList.h +++ b/libraries/shared/src/AgentList.h @@ -49,11 +49,11 @@ public: bool addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType, uint16_t agentId); - void processAgentData(sockaddr *senderAddress, void *packetData, size_t dataBytes); - void processBulkAgentData(sockaddr *senderAddress, void *packetData, int numTotalBytes, int numBytesPerAgent); + void processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes); + void processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes, int numBytesPerAgent); - void updateAgentWithData(sockaddr *senderAddress, void *packetData, size_t dataBytes); - void updateAgentWithData(Agent *agent, void *packetData, int dataBytes); + void updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes); + void updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes); void broadcastToAgents(char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes); char getOwnerType(); diff --git a/libraries/shared/src/AudioRingBuffer.cpp b/libraries/shared/src/AudioRingBuffer.cpp index 6dd18de520..2197d03706 100644 --- a/libraries/shared/src/AudioRingBuffer.cpp +++ b/libraries/shared/src/AudioRingBuffer.cpp @@ -105,12 +105,10 @@ void AudioRingBuffer::setBearing(float newBearing) { bearing = newBearing; } -void AudioRingBuffer::parseData(void *data, int size) { - unsigned char *audioDataStart = (unsigned char *) data; - - if (size > (bufferLengthSamples * sizeof(int16_t))) { +void AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { + if (numBytes > (bufferLengthSamples * sizeof(int16_t))) { - unsigned char *dataPtr = audioDataStart + 1; + unsigned char *dataPtr = sourceBuffer + 1; for (int p = 0; p < 3; p ++) { memcpy(&position[p], dataPtr, sizeof(float)); @@ -123,7 +121,7 @@ void AudioRingBuffer::parseData(void *data, int size) { memcpy(&bearing, dataPtr, sizeof(float)); dataPtr += sizeof(float); - audioDataStart = dataPtr; + sourceBuffer = dataPtr; } if (endOfLastWrite == NULL) { @@ -134,7 +132,7 @@ void AudioRingBuffer::parseData(void *data, int size) { started = false; } - memcpy(endOfLastWrite, audioDataStart, bufferLengthSamples * sizeof(int16_t)); + memcpy(endOfLastWrite, sourceBuffer, bufferLengthSamples * sizeof(int16_t)); endOfLastWrite += bufferLengthSamples; diff --git a/libraries/shared/src/AudioRingBuffer.h b/libraries/shared/src/AudioRingBuffer.h index 6b214a5f8f..65f28ff737 100644 --- a/libraries/shared/src/AudioRingBuffer.h +++ b/libraries/shared/src/AudioRingBuffer.h @@ -19,7 +19,7 @@ class AudioRingBuffer : public AgentData { ~AudioRingBuffer(); AudioRingBuffer(const AudioRingBuffer &otherRingBuffer); - void parseData(void *data, int size); + void parseData(unsigned char* sourceBuffer, int numBytes); AudioRingBuffer* clone() const; int16_t* getNextOutput(); diff --git a/voxel-server/src/VoxelAgentData.h b/voxel-server/src/VoxelAgentData.h index 3ab7670a93..98ec7e9ed7 100644 --- a/voxel-server/src/VoxelAgentData.h +++ b/voxel-server/src/VoxelAgentData.h @@ -22,7 +22,7 @@ public: ~VoxelAgentData(); VoxelAgentData(const VoxelAgentData &otherAgentData); - void parseData(void *data, int size); + void parseData(unsigned char* sourceBuffer, int numBytes); VoxelAgentData* clone() const; }; diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index d012f23995..44993eb8c7 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -385,7 +385,7 @@ int main(int argc, const char * argv[]) agentList->increaseAgentId(); } - agentList->updateAgentWithData(&agentPublicAddress, (void *)packetData, receivedBytes); + agentList->updateAgentWithData(&agentPublicAddress, packetData, receivedBytes); } } } From e71f21b7bf0efc10142b2b8780b5290f8182d2c7 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Apr 2013 11:59:03 -0700 Subject: [PATCH 14/20] fix broken builds from last commit, pull new avatar data in VoxelAgentData --- avatar-mixer/src/main.cpp | 4 ++-- interface/src/Audio.cpp | 2 +- interface/src/Head.cpp | 2 +- interface/src/Head.h | 2 +- libraries/shared/src/AgentList.cpp | 4 ++-- voxel-server/src/VoxelAgentData.cpp | 9 +++++---- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index b92cff6783..e674156151 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -63,7 +63,7 @@ int main(int argc, char* argv[]) agentList->startPingUnknownAgentsThread(); sockaddr *agentAddress = new sockaddr; - char *packetData = new char[MAX_PACKET_SIZE]; + unsigned char *packetData = new unsigned char[MAX_PACKET_SIZE]; ssize_t receivedBytes = 0; unsigned char *broadcastPacket = new unsigned char[MAX_PACKET_SIZE]; @@ -101,7 +101,7 @@ int main(int argc, char* argv[]) break; default: // hand this off to the AgentList - agentList->processAgentData(agentAddress, (void *)packetData, receivedBytes); + agentList->processAgentData(agentAddress, packetData, receivedBytes); break; } } diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 4300418856..578e1368c8 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -411,7 +411,7 @@ void *receiveAudioViaUDP(void *args) { } if (packetsReceivedThisPlayback == 1) gettimeofday(&firstPlaybackTimer, NULL); - ringBuffer->parseData(receivedData, PACKET_LENGTH_BYTES); + ringBuffer->parseData((unsigned char *)receivedData, PACKET_LENGTH_BYTES); previousReceiveTime = currentReceiveTime; } diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 4589636f77..06ebdad0f3 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -1174,7 +1174,7 @@ void Head::SetNewHeadTarget(float pitch, float yaw) { YawTarget = yaw; } -void Head::processTransmitterData(unsigned char *packetData, int numBytes) { +void Head::processTransmitterData(unsigned char* packetData, int numBytes) { // Read a packet from a transmitter app, process the data float accX, accY, accZ, graX, graY, graZ, diff --git a/interface/src/Head.h b/interface/src/Head.h index ad4f1f665f..3d34b2defa 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -139,7 +139,7 @@ class Head : public AvatarData { void renderBody(); void renderHead( int faceToFace, int isMine ); - void renderOrientataionDirections( glm::vec3 position, Orientation orientation, float size ); + void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ); void simulate(float); diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 092ce6de3f..0dfcad1c58 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -81,10 +81,10 @@ unsigned int AgentList::getSocketListenPort() { return socketListenPort; } -void AgentList::processAgentData(sockaddr *senderAddress, void *packetData, size_t dataBytes) { +void AgentList::processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) { switch (((char *)packetData)[0]) { case PACKET_HEADER_DOMAIN: { - updateList((unsigned char *)packetData, dataBytes); + updateList(packetData, dataBytes); break; } case PACKET_HEADER_PING: { diff --git a/voxel-server/src/VoxelAgentData.cpp b/voxel-server/src/VoxelAgentData.cpp index e54ce0df89..8f9b41e4ca 100644 --- a/voxel-server/src/VoxelAgentData.cpp +++ b/voxel-server/src/VoxelAgentData.cpp @@ -27,9 +27,10 @@ VoxelAgentData* VoxelAgentData::clone() const { return new VoxelAgentData(*this); } -void VoxelAgentData::parseData(void *data, int size) { +void VoxelAgentData::parseData(unsigned char* sourceBuffer, int numBytes) { + // push past the packet header + sourceBuffer++; + // pull the position from the interface agent data packet - sscanf((char *)data, - "H%*f,%*f,%*f,%f,%f,%f", - &position[0], &position[1], &position[2]); + memcpy(&position, sourceBuffer, sizeof(float) * 3); } From 53108b01ef852f7ccdfd4fcafac6b505393b0238 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Apr 2013 12:02:33 -0700 Subject: [PATCH 15/20] resolve conflicts on merge with upstream master --- interface/src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index efb9a70e28..90950f4060 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -354,8 +354,8 @@ void reset_sensors() // myAvatar.setRenderYaw(startYaw); - yaw = renderYawRate = 0; - pitch = renderPitch = renderPitchRate = 0; + renderYawRate = 0; + renderPitchRate = 0; myAvatar.setBodyPosition(start_location); headMouseX = WIDTH/2; headMouseY = HEIGHT/2; From e7e7bd290a8a0d35a5e0efea4cdba32e206fa32d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Apr 2013 12:04:56 -0700 Subject: [PATCH 16/20] remove debugging on voxel deletion --- libraries/voxels/src/VoxelTree.cpp | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index cf0d339954..2f18b8af50 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -192,37 +192,23 @@ void VoxelTree::deleteVoxelCodeFromTree(unsigned char *codeBuffer) { VoxelNode* parentNode = NULL; VoxelNode* nodeToDelete = nodeForOctalCode(rootNode, codeBuffer, &parentNode); - printf("deleteVoxelCodeFromTree() looking [codeBuffer] for:\n"); - printOctalCode(codeBuffer); - - printf("deleteVoxelCodeFromTree() found [nodeToDelete->octalCode] for:\n"); - printOctalCode(nodeToDelete->octalCode); - // If the node exists... int lengthInBytes = bytesRequiredForCodeLength(*codeBuffer); // includes octet count, not color! - printf("compare octal codes of length %d\n",lengthInBytes); - if (0==memcmp(nodeToDelete->octalCode,codeBuffer,lengthInBytes)) { - printf("found node to delete...\n"); + if (0 == memcmp(nodeToDelete->octalCode,codeBuffer,lengthInBytes)) { float* vertices = firstVertexForCode(nodeToDelete->octalCode); - printf("deleting voxel at: %f,%f,%f\n",vertices[0],vertices[1],vertices[2]); delete []vertices; if (parentNode) { float* vertices = firstVertexForCode(parentNode->octalCode); - printf("parent of deleting voxel at: %f,%f,%f\n",vertices[0],vertices[1],vertices[2]); delete []vertices; int childNDX = branchIndexWithDescendant(parentNode->octalCode, codeBuffer); - printf("child INDEX=%d\n",childNDX); - printf("deleting Node at parentNode->children[%d]\n",childNDX); delete parentNode->children[childNDX]; // delete the child nodes - printf("setting parentNode->children[%d] to NULL\n",childNDX); parentNode->children[childNDX]=NULL; // set it to NULL - printf("reaverageVoxelColors()\n"); reaverageVoxelColors(rootNode); // Fix our colors!! Need to call it on rootNode } } From 598bed3b55390aa528ceb9790ca8ffd6a4d1624d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Apr 2013 12:22:09 -0700 Subject: [PATCH 17/20] include cstring and stdint in AvatarData UNIX build --- libraries/avatars/src/AvatarData.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 73641fe94c..6af298a65b 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -7,6 +7,8 @@ // #include +#include +#include #include From 0182c29e7b93736ac46f49cf6bf9aecc05e94ef2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Apr 2013 12:25:23 -0700 Subject: [PATCH 18/20] switch Util for SharedUtil in ViewFrustum --- libraries/voxels/src/ViewFrustum.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 1de5c11d6a..eef6f14c73 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -8,7 +8,8 @@ // // -#include "Util.h" +#include + #include "ViewFrustum.h" ViewFrustum::ViewFrustum() : From c921fd9b87c76d8b4c5158e3eaab756e71b6f7d3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Apr 2013 12:26:44 -0700 Subject: [PATCH 19/20] remove unnecessary SharedUtil include --- libraries/voxels/src/ViewFrustum.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index eef6f14c73..d0b1382a4a 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -8,8 +8,6 @@ // // -#include - #include "ViewFrustum.h" ViewFrustum::ViewFrustum() : From 8129c2477a0a6fb1241d6363625ae8b365d61583 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Apr 2013 12:35:49 -0700 Subject: [PATCH 20/20] fix broken voxel server build, change some char* to unsigned char* --- avatar-mixer/src/main.cpp | 2 +- interface/src/main.cpp | 8 ++++---- libraries/avatars/src/AvatarData.cpp | 20 ++++++++++---------- libraries/avatars/src/AvatarData.h | 2 +- libraries/shared/src/AgentList.cpp | 2 +- libraries/shared/src/AgentList.h | 2 +- voxel-server/src/main.cpp | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index e674156151..1d446f40f4 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -40,7 +40,7 @@ unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent * currentPosition += packAgentId(currentPosition, agentToAdd->getAgentId()); AvatarData *agentData = (AvatarData *)agentToAdd->getLinkedData(); - currentPosition += agentData->getBroadcastData((char *) currentPosition); + currentPosition += agentData->getBroadcastData(currentPosition); return currentPosition; } diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 90950f4060..b2f92b06fd 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -454,7 +454,7 @@ void updateAvatar(float frametime) #endif // Send my stream of head/hand data to the avatar mixer and voxel server - char broadcastString[200]; + unsigned char broadcastString[200]; int broadcastBytes = myAvatar.getBroadcastData(broadcastString); const char broadcastReceivers[2] = {AGENT_TYPE_VOXEL, AGENT_TYPE_AVATAR_MIXER}; @@ -478,7 +478,7 @@ void updateAvatar(float frametime) ::paintingVoxel.z >= 0.0 && ::paintingVoxel.z <= 1.0) { if (createVoxelEditMessage(PACKET_HEADER_SET_VOXEL, 0, 1, &::paintingVoxel, bufferOut, sizeOut)){ - AgentList::getInstance()->broadcastToAgents((char*)bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1); + AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1); delete bufferOut; } } @@ -1096,14 +1096,14 @@ void sendVoxelServerEraseAll() { char message[100]; sprintf(message,"%c%s",'Z',"erase all"); int messageSize = strlen(message) + 1; - AgentList::getInstance()->broadcastToAgents(message, messageSize, &AGENT_TYPE_VOXEL, 1); + AgentList::getInstance()->broadcastToAgents((unsigned char*) message, messageSize, &AGENT_TYPE_VOXEL, 1); } void sendVoxelServerAddScene() { char message[100]; sprintf(message,"%c%s",'Z',"add scene"); int messageSize = strlen(message) + 1; - AgentList::getInstance()->broadcastToAgents(message, messageSize, &AGENT_TYPE_VOXEL, 1); + AgentList::getInstance()->broadcastToAgents((unsigned char*)message, messageSize, &AGENT_TYPE_VOXEL, 1); } void shiftPaintingColor() diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 6af298a65b..0bf9ddff74 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -14,7 +14,7 @@ #include "AvatarData.h" -int packFloatAngleToTwoByte(char* buffer, float angle) { +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); @@ -45,20 +45,20 @@ AvatarData* AvatarData::clone() const { // transmit data to agents requesting it // called on me just prior to sending data to others (continuasly called) -int AvatarData::getBroadcastData(char* destinationBuffer) { - char* bufferPointer = destinationBuffer; - +int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { + unsigned char* bufferStart = destinationBuffer; + // TODO: DRY this up to a shared method // that can pack any type given the number of bytes // and return the number of bytes to push the pointer - memcpy(bufferPointer, &_bodyPosition, sizeof(float) * 3); - bufferPointer += sizeof(float) * 3; + memcpy(destinationBuffer, &_bodyPosition, sizeof(float) * 3); + destinationBuffer += sizeof(float) * 3; - bufferPointer += packFloatAngleToTwoByte(bufferPointer, _bodyYaw); - bufferPointer += packFloatAngleToTwoByte(bufferPointer, _bodyPitch); - bufferPointer += packFloatAngleToTwoByte(bufferPointer, _bodyRoll); + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyYaw); + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyPitch); + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll); - return bufferPointer - destinationBuffer; + return destinationBuffer - bufferStart; } // called on the other agents - assigns it to my views of the others diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 464927a98c..5e7f52a04d 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -25,7 +25,7 @@ public: glm::vec3 getBodyPosition(); void setBodyPosition(glm::vec3 bodyPosition); - int getBroadcastData(char* destinationBuffer); + int getBroadcastData(unsigned char* destinationBuffer); void parseData(unsigned char* sourceBuffer, int numBytes); float getBodyYaw(); diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 0dfcad1c58..6d56aac726 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -258,7 +258,7 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, } } -void AgentList::broadcastToAgents(char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes) { +void AgentList::broadcastToAgents(unsigned char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes) { for(std::vector::iterator agent = agents.begin(); agent != agents.end(); agent++) { // only send to the AgentTypes we are asked to send to. if (agent->getActiveSocket() != NULL && memchr(agentTypes, agent->getType(), numAgentTypes)) { diff --git a/libraries/shared/src/AgentList.h b/libraries/shared/src/AgentList.h index 8c77b557de..e01147db9f 100644 --- a/libraries/shared/src/AgentList.h +++ b/libraries/shared/src/AgentList.h @@ -55,7 +55,7 @@ public: void updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes); void updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes); - void broadcastToAgents(char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes); + void broadcastToAgents(unsigned char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes); char getOwnerType(); unsigned int getSocketListenPort(); diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 44993eb8c7..70a743b9c0 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -289,7 +289,7 @@ int main(int argc, const char * argv[]) sockaddr agentPublicAddress; - char *packetData = new char[MAX_PACKET_SIZE]; + unsigned char *packetData = new unsigned char[MAX_PACKET_SIZE]; ssize_t receivedBytes; // loop to send to agents requesting data @@ -352,7 +352,7 @@ int main(int argc, const char * argv[]) // the Z command is a special command that allows the sender to send the voxel server high level semantic // requests, like erase all, or add sphere scene - char* command = &packetData[1]; // start of the command + char* command = (char*) &packetData[1]; // start of the command int commandLength = strlen(command); // commands are null terminated strings int totalLength = 1+commandLength+1;