From d094c6fc3bf046a431fd79bd1b2d3f538b2a64bf Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 14:41:59 -0700 Subject: [PATCH 01/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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 39df647dcb26076f26ca6d5a1b969b74d866743e Mon Sep 17 00:00:00 2001 From: stojce Date: Tue, 16 Apr 2013 02:24:38 +0200 Subject: [PATCH 08/51] #19261 - Add startup time to the main window title, fit to screen --- interface/src/main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 10f0eb526f..8041b3dbe4 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -893,9 +893,11 @@ void display(void) // If application has just started, report time from startup to now (first frame display) if (justStarted) { - printf("Startup Time: %4.2f\n", - (usecTimestampNow() - usecTimestamp(&applicationStartupTime))/1000000.0); + float startupTime = (usecTimestampNow() - usecTimestamp(&applicationStartupTime))/1000000.0; justStarted = false; + char title[30]; + sprintf(title, "Interface: %4.2f seconds", startupTime); + glutSetWindowTitle(title); } } @@ -1463,6 +1465,9 @@ int main(int argc, const char * argv[]) AgentList::getInstance()->startPingUnknownAgentsThread(); glutInit(&argc, (char**)argv); + WIDTH = glutGet (GLUT_SCREEN_WIDTH); + HEIGHT = glutGet (GLUT_SCREEN_HEIGHT); + glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(WIDTH, HEIGHT); glutCreateWindow("Interface"); From 8da449041c75148e9798013ecaf98698059e9cf7 Mon Sep 17 00:00:00 2001 From: stojce Date: Tue, 16 Apr 2013 02:26:11 +0200 Subject: [PATCH 09/51] small code formating fix --- 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 8041b3dbe4..16a0d9a43d 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1465,8 +1465,8 @@ int main(int argc, const char * argv[]) AgentList::getInstance()->startPingUnknownAgentsThread(); glutInit(&argc, (char**)argv); - WIDTH = glutGet (GLUT_SCREEN_WIDTH); - HEIGHT = glutGet (GLUT_SCREEN_HEIGHT); + WIDTH = glutGet(GLUT_SCREEN_WIDTH); + HEIGHT = glutGet(GLUT_SCREEN_HEIGHT); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(WIDTH, HEIGHT); From 3b994cbdcf2616649c1d350c51648f18fb58b539 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Apr 2013 17:54:44 -0700 Subject: [PATCH 10/51] Latest work on ViewFrustum - added support for specifying lens attributes (fov, near, far, ratio) - changed constructor and calculate methods to be separate - coding standard cleanup --- libraries/voxels/src/ViewFrustum.cpp | 90 ++++++++++++++----------- libraries/voxels/src/ViewFrustum.h | 98 ++++++++++++++++------------ 2 files changed, 108 insertions(+), 80 deletions(-) diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 73cce9baad..1de5c11d6a 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -8,14 +8,32 @@ // // +#include "Util.h" #include "ViewFrustum.h" -float ViewFrustum::fovAngleAdust=1.65; - -ViewFrustum::ViewFrustum(glm::vec3 position, glm::vec3 direction, - glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight) { - this->calculateViewFrustum(position, direction, up, right, screenWidth, screenHeight); -} +ViewFrustum::ViewFrustum() : + _position(glm::vec3(0,0,0)), + _direction(glm::vec3(0,0,0)), + _up(glm::vec3(0,0,0)), + _right(glm::vec3(0,0,0)), + _fieldOfView(0.0), + _aspectRatio(1.0), + _nearClip(0.1), + _farClip(500.0), + _nearHeight(0.0), + _nearWidth(0.0), + _farHeight(0.0), + _farWidth(0.0), + _farCenter(glm::vec3(0,0,0)), + _farTopLeft(glm::vec3(0,0,0)), + _farTopRight(glm::vec3(0,0,0)), + _farBottomLeft(glm::vec3(0,0,0)), + _farBottomRight(glm::vec3(0,0,0)), + _nearCenter(glm::vec3(0,0,0)), + _nearTopLeft(glm::vec3(0,0,0)), + _nearTopRight(glm::vec3(0,0,0)), + _nearBottomLeft(glm::vec3(0,0,0)), + _nearBottomRight(glm::vec3(0,0,0)) { } ///////////////////////////////////////////////////////////////////////////////////// // ViewFrustum::calculateViewFrustum() @@ -26,47 +44,41 @@ ViewFrustum::ViewFrustum(glm::vec3 position, glm::vec3 direction, // Notes on how/why this works: // http://www.lighthouse3d.com/tutorials/view-frustum-culling/view-frustums-shape/ // -void ViewFrustum::calculateViewFrustum(glm::vec3 position, glm::vec3 direction, - glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight) { +void ViewFrustum::calculate() { + + static const double PI_OVER_180 = 3.14159265359 / 180.0; // would be better if this was in a shared location - // Save the values we were passed... - this->_position = position; - this->_direction = direction; - this->_up = up; - this->_right = right; - this->_screenWidth = screenWidth; - this->_screenHeight = screenHeight; - - glm::vec3 front = direction; + glm::vec3 front = _direction; // Calculating field of view. - // 0.7854f is 45 deg - // ViewFrustum::fovAngleAdust defaults to 1.65 - // Apparently our fov is around 1.75 times this value or 74.25 degrees - // you can adjust this in interface by using the "|" and "\" keys to tweak - // the adjustment and see effects of different FOVs - float fovHalfAngle = 0.7854f * ViewFrustum::fovAngleAdust; - float ratio = screenWidth / screenHeight; + float fovInRadians = this->_fieldOfView * PI_OVER_180; - this->_nearDist = 0.1; - this->_farDist = 10.0; - - this->_nearHeight = 2 * tan(fovHalfAngle) * this->_nearDist; - this->_nearWidth = this->_nearHeight * ratio; - this->_farHeight = 2 * tan(fovHalfAngle) * this->_farDist; - this->_farWidth = this->_farHeight * ratio; + float twoTimesTanHalfFOV = 2.0f * tan(fovInRadians/2.0f); - float farHalfHeight = this->_farHeight * 0.5f; - float farHalfWidth = this->_farWidth * 0.5f; - this->_farCenter = this->_position+front * this->_farDist; + float slightlySmaller = 0.0f; + float slightlyInsideWidth= 0.0f - slightlySmaller; + float slightlyInsideNear = 0.0f + slightlySmaller; + float slightlyInsideFar = 0.0f - slightlySmaller; + + float nearClip = this->_nearClip + slightlyInsideNear; + float farClip = this->_farClip + slightlyInsideFar; + + this->_nearHeight = (twoTimesTanHalfFOV * nearClip); + this->_nearWidth = this->_nearHeight * this->_aspectRatio; + this->_farHeight = (twoTimesTanHalfFOV * farClip); + this->_farWidth = this->_farHeight * this->_aspectRatio; + + float farHalfHeight = (this->_farHeight * 0.5f) + slightlyInsideWidth; + float farHalfWidth = (this->_farWidth * 0.5f) + slightlyInsideWidth; + this->_farCenter = this->_position+front * farClip; this->_farTopLeft = this->_farCenter + (this->_up * farHalfHeight) - (this->_right * farHalfWidth); this->_farTopRight = this->_farCenter + (this->_up * farHalfHeight) + (this->_right * farHalfWidth); this->_farBottomLeft = this->_farCenter - (this->_up * farHalfHeight) - (this->_right * farHalfWidth); this->_farBottomRight = this->_farCenter - (this->_up * farHalfHeight) + (this->_right * farHalfWidth); - float nearHalfHeight = this->_nearHeight * 0.5f; - float nearHalfWidth = this->_nearWidth * 0.5f; - this->_nearCenter = this->_position+front * this->_nearDist; + float nearHalfHeight = (this->_nearHeight * 0.5f) + slightlyInsideWidth; + float nearHalfWidth = (this->_nearWidth * 0.5f) + slightlyInsideWidth; + this->_nearCenter = this->_position+front * nearClip; this->_nearTopLeft = this->_nearCenter + (this->_up * nearHalfHeight) - (this->_right * nearHalfWidth); this->_nearTopRight = this->_nearCenter + (this->_up * nearHalfHeight) + (this->_right * nearHalfWidth); this->_nearBottomLeft = this->_nearCenter - (this->_up * nearHalfHeight) - (this->_right * nearHalfWidth); @@ -80,11 +92,11 @@ void ViewFrustum::dump() { printf("up.x=%f, up.y=%f, up.z=%f\n", this->_up.x, this->_up.y, this->_up.z); printf("right.x=%f, right.y=%f, right.z=%f\n", this->_right.x, this->_right.y, this->_right.z); - printf("farDist=%f\n", this->_farDist); + printf("farDist=%f\n", this->_farClip); printf("farHeight=%f\n", this->_farHeight); printf("farWidth=%f\n", this->_farWidth); - printf("nearDist=%f\n", this->_nearDist); + printf("nearDist=%f\n", this->_nearClip); printf("nearHeight=%f\n", this->_nearHeight); printf("nearWidth=%f\n", this->_nearWidth); diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index 9fb17ae339..ed704e5755 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -15,54 +15,70 @@ class ViewFrustum { private: - glm::vec3 _position; - glm::vec3 _direction; - glm::vec3 _up; - glm::vec3 _right; - float _screenWidth; - float _screenHeight; - float _nearDist; - float _farDist; - - float _nearHeight; - float _nearWidth; - float _farHeight; - float _farWidth; + // camera location/orientation attributes + glm::vec3 _position; + glm::vec3 _direction; + glm::vec3 _up; + glm::vec3 _right; - glm::vec3 _farCenter; - glm::vec3 _farTopLeft; - glm::vec3 _farTopRight; - glm::vec3 _farBottomLeft; - glm::vec3 _farBottomRight; + // Lens attributes + float _fieldOfView; + float _aspectRatio; + float _nearClip; + float _farClip; - glm::vec3 _nearCenter; - glm::vec3 _nearTopLeft; - glm::vec3 _nearTopRight; - glm::vec3 _nearBottomLeft; - glm::vec3 _nearBottomRight; + // Calculated values + float _nearHeight; + float _nearWidth; + float _farHeight; + float _farWidth; + glm::vec3 _farCenter; + glm::vec3 _farTopLeft; + glm::vec3 _farTopRight; + glm::vec3 _farBottomLeft; + glm::vec3 _farBottomRight; + glm::vec3 _nearCenter; + glm::vec3 _nearTopLeft; + glm::vec3 _nearTopRight; + glm::vec3 _nearBottomLeft; + glm::vec3 _nearBottomRight; + public: - const glm::vec3& getFarCenter() const { return _farCenter; }; - const glm::vec3& getFarTopLeft() const { return _farTopLeft; }; - const glm::vec3& getFarTopRight() const { return _farTopRight; }; - const glm::vec3& getFarBottomLeft() const { return _farBottomLeft; }; - const glm::vec3& getFarBottomRight() const { return _farBottomRight; }; + // setters for camera attributes + void setPosition (const glm::vec3& p) { _position = p; } + void setOrientation (const glm::vec3& d, const glm::vec3& u, const glm::vec3& r ) + { _direction = d; _up = u; _right = r; } - const glm::vec3& getNearCenter() const { return _nearCenter; }; - const glm::vec3& getNearTopLeft() const { return _nearTopLeft; }; - const glm::vec3& getNearTopRight() const { return _nearTopRight; }; - const glm::vec3& getNearBottomLeft() const { return _nearBottomLeft; }; - const glm::vec3& getNearBottomRight() const { return _nearBottomRight; }; + // setters for lens attributes + void setFieldOfView ( float f ) { _fieldOfView = f; } + void setAspectRatio ( float a ) { _aspectRatio = a; } + void setNearClip ( float n ) { _nearClip = n; } + void setFarClip ( float f ) { _farClip = f; } - void calculateViewFrustum(glm::vec3 position, glm::vec3 direction, - glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight); + // getters for lens attributes + float getFieldOfView() const { return _fieldOfView; }; + float getAspectRatio() const { return _aspectRatio; }; + float getNearClip() const { return _nearClip; }; + float getFarClip() const { return _farClip; }; - ViewFrustum(glm::vec3 position, glm::vec3 direction, - glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight); - - void dump(); - - static float fovAngleAdust; + const glm::vec3& getFarCenter() const { return _farCenter; }; + const glm::vec3& getFarTopLeft() const { return _farTopLeft; }; + const glm::vec3& getFarTopRight() const { return _farTopRight; }; + const glm::vec3& getFarBottomLeft() const { return _farBottomLeft; }; + const glm::vec3& getFarBottomRight() const { return _farBottomRight; }; + + const glm::vec3& getNearCenter() const { return _nearCenter; }; + const glm::vec3& getNearTopLeft() const { return _nearTopLeft; }; + const glm::vec3& getNearTopRight() const { return _nearTopRight; }; + const glm::vec3& getNearBottomLeft() const { return _nearBottomLeft; }; + const glm::vec3& getNearBottomRight() const { return _nearBottomRight;}; + + void calculate(); + + ViewFrustum(); + + void dump(); }; From c2c36e6ceac755b42d0ed3cc0fb4e5270096e5ac Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Apr 2013 17:56:52 -0700 Subject: [PATCH 11/51] Tweaks to Camera class - added lens attributes - coding standard cleanup --- interface/src/Camera.cpp | 40 ++++++++++---------- interface/src/Camera.h | 81 +++++++++++++++++++++++----------------- 2 files changed, 68 insertions(+), 53 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 5a6899467c..303fa136c1 100755 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -11,16 +11,18 @@ //------------------------ Camera::Camera() { - mode = CAMERA_MODE_THIRD_PERSON; - fieldOfView = 60.0; // default - yaw = 0.0; - pitch = 0.0; - roll = 0.0; - up = 0.0; - distance = 0.0; - targetPosition = glm::vec3( 0.0, 0.0, 0.0 ); - position = glm::vec3( 0.0, 0.0, 0.0 ); - orientation.setToIdentity(); + _mode = CAMERA_MODE_THIRD_PERSON; + _fieldOfView = 60.0; // default + _nearClip = 0.1; // default + _farClip = 50.0; // default + _yaw = 0.0; + _pitch = 0.0; + _roll = 0.0; + _up = 0.0; + _distance = 0.0; + _targetPosition = glm::vec3( 0.0, 0.0, 0.0 ); + _position = glm::vec3( 0.0, 0.0, 0.0 ); + _orientation.setToIdentity(); } @@ -28,21 +30,21 @@ Camera::Camera() //------------------------ void Camera::update() { - double radian = ( yaw / 180.0 ) * PIE; + float radian = ( _yaw / 180.0 ) * PIE; //these need to be checked to make sure they correspond to the cordinate system. - double x = distance * -sin( radian ); - double z = distance * cos( radian ); - double y = up; + float x = _distance * -sin( radian ); + float z = _distance * cos( radian ); + float y = _up; - position = targetPosition + glm::vec3( x, y, z ); + _position = _targetPosition + glm::vec3( x, y, z ); //------------------------------------------------------------------------ //geterate the ortho-normals for the orientation based on the Euler angles //------------------------------------------------------------------------ - orientation.setToIdentity(); - orientation.yaw ( yaw ); - orientation.pitch ( pitch ); - orientation.roll ( roll ); + _orientation.setToIdentity(); + _orientation.yaw ( _yaw ); + _orientation.pitch ( _pitch ); + _orientation.roll ( _roll ); } diff --git a/interface/src/Camera.h b/interface/src/Camera.h index 1c8c3335b5..bd4e9d0ecb 100755 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -13,50 +13,63 @@ enum CameraMode { - CAMERA_MODE_NULL = -1, - CAMERA_MODE_FIRST_PERSON, - CAMERA_MODE_THIRD_PERSON, - CAMERA_MODE_MY_OWN_FACE, - NUM_CAMERA_MODES + CAMERA_MODE_NULL = -1, + CAMERA_MODE_FIRST_PERSON, + CAMERA_MODE_THIRD_PERSON, + CAMERA_MODE_MY_OWN_FACE, + NUM_CAMERA_MODES }; class Camera { public: - Camera(); - - void update(); - - void setMode ( CameraMode m ) { mode = m; } - void setYaw ( float y ) { yaw = y; } - void setPitch ( float p ) { pitch = p; } - void setRoll ( float r ) { roll = r; } - void setUp ( float u ) { up = u; } - void setDistance ( float d ) { distance = d; } - void setTargetPosition ( glm::vec3 t ) { targetPosition = t; }; - void setPosition ( glm::vec3 p ) { position = p; }; - void setOrientation ( Orientation o ) { orientation.set(o); } + Camera(); - float getYaw () { return yaw; } - float getPitch () { return pitch; } - float getRoll () { return roll; } - glm::vec3 getPosition () { return position; } - Orientation getOrientation () { return orientation; } - CameraMode getMode () { return mode; } + void update(); + + void setMode ( CameraMode m ) { _mode = m; } + void setYaw ( float y ) { _yaw = y; } + void setPitch ( float p ) { _pitch = p; } + void setRoll ( float r ) { _roll = r; } + void setUp ( float u ) { _up = u; } + void setDistance ( float d ) { _distance = d; } + void setTargetPosition ( glm::vec3 t ) { _targetPosition = t; }; + void setPosition ( glm::vec3 p ) { _position = p; }; + void setOrientation ( Orientation o ) { _orientation.set(o); } + void setFieldOfView ( float f ) { _fieldOfView = f; } + void setAspectRatio ( float a ) { _aspectRatio = a; } + void setNearClip ( float n ) { _nearClip = n; } + void setFarClip ( float f ) { _farClip = f; } + + float getYaw () { return _yaw; } + float getPitch () { return _pitch; } + float getRoll () { return _roll; } + glm::vec3 getPosition () { return _position; } + Orientation getOrientation () { return _orientation; } + CameraMode getMode () { return _mode; } + float getFieldOfView () { return _fieldOfView; } + float getAspectRatio () { return _aspectRatio; } + float getNearClip () { return _nearClip; } + float getFarClip () { return _farClip; } private: - CameraMode mode; - glm::vec3 position; - glm::vec3 targetPosition; - float fieldOfView; - float yaw; - float pitch; - float roll; - float up; - float distance; - Orientation orientation; + CameraMode _mode; + glm::vec3 _position; + glm::vec3 _targetPosition; + float _yaw; + float _pitch; + float _roll; + float _up; + float _distance; + Orientation _orientation; + + // Lens attributes + float _fieldOfView; // in degrees + float _aspectRatio; // width/height + float _nearClip; // in world units? - XXXBHG - we need to think about this! + float _farClip; // in world units? }; #endif From 2625ef014ca18cbf2317249533819528ad665200 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Apr 2013 17:57:48 -0700 Subject: [PATCH 12/51] latest View Frustum work --- interface/src/main.cpp | 265 +++++++++++++++++++++++++++++------------ 1 file changed, 186 insertions(+), 79 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index afbff94616..383db1ada2 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -79,6 +79,9 @@ using namespace std; +void reshape(int width, int height); // will be defined below + + pthread_t networkReceiveThread; bool stopNetworkReceiveThread = false; @@ -97,10 +100,14 @@ bool wantColorRandomizer = true; // for addSphere and load file Oscilloscope audioScope(256,200,true); -Head myAvatar; // The rendered avatar of oneself -Camera myCamera; // My view onto the world (sometimes on myself :) +ViewFrustum viewFrustum; // current state of view frustum, perspective, orientation, etc. - // Starfield information +Head myAvatar; // The rendered avatar of oneself +Camera myCamera; // My view onto the world (sometimes on myself :) +Camera viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode +Camera currentCamera = myCamera; // could be either myCamera or viewFrustumOffsetCamera, this is the camera for OpenGL + +// Starfield information char starFile[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; FieldOfView fov; Stars stars; @@ -525,39 +532,56 @@ float viewFrustumOffsetUp = 0.0; void render_view_frustum() { - glm::vec3 cameraPosition = ::myCamera.getPosition(); - glm::vec3 headPosition = ::myAvatar.getHeadPosition(); - - glm::vec3 cameraDirection = ::myCamera.getOrientation().getFront() * glm::vec3(1,1,-1); - glm::vec3 headDirection = myAvatar.getHeadLookatDirection(); // direction still backwards - - glm::vec3 cameraUp = myCamera.getOrientation().getUp() * glm::vec3(1,1,1); - glm::vec3 headUp = myAvatar.getHeadLookatDirectionUp(); - - glm::vec3 cameraRight = myCamera.getOrientation().getRight() * glm::vec3(1,1,-1); - glm::vec3 headRight = myAvatar.getHeadLookatDirectionRight() * glm::vec3(-1,1,-1); // z is flipped! - // We will use these below, from either the camera or head vectors calculated above glm::vec3 position; glm::vec3 direction; glm::vec3 up; glm::vec3 right; + float fov, nearClip, farClip; // Camera or Head? if (::cameraFrustum) { - position = cameraPosition; - direction = cameraDirection; - up = cameraUp; - right = cameraRight; + position = ::myCamera.getPosition(); + direction = ::myCamera.getOrientation().getFront() * glm::vec3(1,1,-1); + up = ::myCamera.getOrientation().getUp() * glm::vec3(1,1,1); + right = ::myCamera.getOrientation().getRight() * glm::vec3(1,1,-1); + fov = ::myCamera.getFieldOfView(); + nearClip = ::myCamera.getNearClip(); + farClip = ::myCamera.getFarClip(); } else { - position = headPosition; - direction = headDirection; - up = headUp; - right = headRight; + position = ::myAvatar.getHeadPosition(); + direction = ::myAvatar.getHeadLookatDirection(); + up = ::myAvatar.getHeadLookatDirectionUp(); + right = ::myAvatar.getHeadLookatDirectionRight() * glm::vec3(-1,1,-1); + + // NOTE: we use the same lens details if we draw from the head + fov = ::myCamera.getFieldOfView(); + nearClip = ::myCamera.getNearClip(); + farClip = ::myCamera.getFarClip(); } - + + printf("position.x=%f, position.y=%f, position.z=%f\n", position.x, position.y, position.z); + printf("direction.x=%f, direction.y=%f, direction.z=%f\n", direction.x, direction.y, direction.z); + printf("up.x=%f, up.y=%f, up.z=%f\n", up.x, up.y, up.z); + printf("right.x=%f, right.y=%f, right.z=%f\n", right.x, right.y, right.z); + printf("fov=%f\n", fov); + printf("nearClip=%f\n", nearClip); + printf("farClip=%f\n", farClip); + + + // Set the viewFrustum up with the correct position and orientation of the camera + viewFrustum.setPosition(position); + viewFrustum.setOrientation(direction,up,right); + + // Also make sure it's got the correct lens details from the camera + viewFrustum.setFieldOfView(fov); + viewFrustum.setNearClip(nearClip); + viewFrustum.setFarClip(farClip); + // Ask the ViewFrustum class to calculate our corners - ViewFrustum vf(position,direction,up,right,::WIDTH,::HEIGHT); + viewFrustum.calculate(); + + viewFrustum.dump(); // Get ready to draw some lines glDisable(GL_LIGHTING); @@ -590,64 +614,64 @@ void render_view_frustum() { if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_NEAR_PLANE) { // Drawing the bounds of the frustum - // vf.getNear plane - bottom edge + // viewFrustum.getNear plane - bottom edge glColor3f(1,0,0); - glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); - glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); + glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); + glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); - // vf.getNear plane - top edge - glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); - glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().z); + // viewFrustum.getNear plane - top edge + glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); + glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); - // vf.getNear plane - right edge - glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); - glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().z); + // viewFrustum.getNear plane - right edge + glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); + glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); - // vf.getNear plane - left edge - glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); - glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); + // viewFrustum.getNear plane - left edge + glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); + glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); } if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_FAR_PLANE) { - // vf.getFar plane - bottom edge + // viewFrustum.getFar plane - bottom edge glColor3f(0,1,0); // GREEN!!! - glVertex3f(vf.getFarBottomLeft().x, vf.getFarBottomLeft().y, vf.getFarBottomLeft().z); - glVertex3f(vf.getFarBottomRight().x, vf.getFarBottomRight().y, vf.getFarBottomRight().z); + glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); + glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); - // vf.getFar plane - top edge - glVertex3f(vf.getFarTopLeft().x, vf.getFarTopLeft().y, vf.getFarTopLeft().z); - glVertex3f(vf.getFarTopRight().x, vf.getFarTopRight().y, vf.getFarTopRight().z); + // viewFrustum.getFar plane - top edge + glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); + glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); - // vf.getFar plane - right edge - glVertex3f(vf.getFarBottomRight().x, vf.getFarBottomRight().y, vf.getFarBottomRight().z); - glVertex3f(vf.getFarTopRight().x, vf.getFarTopRight().y, vf.getFarTopRight().z); + // viewFrustum.getFar plane - right edge + glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); + glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); - // vf.getFar plane - left edge - glVertex3f(vf.getFarBottomLeft().x, vf.getFarBottomLeft().y, vf.getFarBottomLeft().z); - glVertex3f(vf.getFarTopLeft().x, vf.getFarTopLeft().y, vf.getFarTopLeft().z); + // viewFrustum.getFar plane - left edge + glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); + glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); } if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES) { // RIGHT PLANE IS CYAN - // right plane - bottom edge - vf.getNear to distant + // right plane - bottom edge - viewFrustum.getNear to distant glColor3f(0,1,1); - glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); - glVertex3f(vf.getFarBottomRight().x, vf.getFarBottomRight().y, vf.getFarBottomRight().z); + glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); + glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); - // right plane - top edge - vf.getNear to distant - glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().z); - glVertex3f(vf.getFarTopRight().x, vf.getFarTopRight().y, vf.getFarTopRight().z); + // right plane - top edge - viewFrustum.getNear to distant + glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); + glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); // LEFT PLANE IS BLUE - // left plane - bottom edge - vf.getNear to distant + // left plane - bottom edge - viewFrustum.getNear to distant glColor3f(0,0,1); - glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); - glVertex3f(vf.getFarBottomLeft().x, vf.getFarBottomLeft().y, vf.getFarBottomLeft().z); + glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); + glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); - // left plane - top edge - vf.getNear to distant - glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); - glVertex3f(vf.getFarTopLeft().x, vf.getFarTopLeft().y, vf.getFarTopLeft().z); + // left plane - top edge - viewFrustum.getNear to distant + glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); + glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); } glEnd(); @@ -657,8 +681,6 @@ void render_view_frustum() { void display(void) { - //printf( "avatar head lookat = %f, %f, %f\n", myAvatar.getAvatarHeadLookatDirection().x, myAvatar.getAvatarHeadLookatDirection().y, myAvatar.getAvatarHeadLookatDirection().z ); - PerfStat("display"); glEnable(GL_LINE_SMOOTH); @@ -711,7 +733,10 @@ void display(void) myCamera.setDistance( 0.5 ); myCamera.update(); } - // Note: whichCamera is used to pick between the normal camera myCamera for our + + +/****** + // Note: currentCamera is used to pick between the normal camera myCamera for our // main camera, vs, an alternate camera. The alternate camera we support right now // is the viewFrustumOffsetCamera. But theoretically, we could use this same mechanism // to add other cameras. @@ -719,10 +744,12 @@ void display(void) // Why have two cameras? Well, one reason is that because in the case of the render_view_frustum() // code, we want to keep the state of "myCamera" intact, so we can render what the view frustum of // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera - Camera whichCamera = myCamera; - Camera viewFrustumOffsetCamera = myCamera; + currentCamera = myCamera; if (::viewFrustumFromOffset && ::frustumOn) { + + viewFrustumOffsetCamera = myCamera; //.setTargetPosition( myAvatar.getPos() ); + //---------------------------------------------------- // set the camera to third-person view but offset so we can see the frustum //---------------------------------------------------- @@ -733,9 +760,47 @@ void display(void) viewFrustumOffsetCamera.setDistance ( 0.5 + ::viewFrustumOffsetDistance ); viewFrustumOffsetCamera.update(); - whichCamera = viewFrustumOffsetCamera; + // We'll be using this one! + currentCamera = viewFrustumOffsetCamera; } + //--------------------------------------------- + // transform view according to whichCamera + // could be myCamera (if in normal mode) + // or could be viewFrustumOffsetCamera if in offset mode + //--------------------------------------------- + glRotatef ( currentCamera.getPitch(), 1, 0, 0 ); + glRotatef ( currentCamera.getYaw(), 0, 1, 0 ); + glRotatef ( currentCamera.getRoll(), 0, 0, 1 ); + glTranslatef( -currentCamera.getPosition().x, -currentCamera.getPosition().y, -currentCamera.getPosition().z ); +*****/ + + + // Note: whichCamera is used to pick between the normal camera myCamera for our + // main camera, vs, an alternate camera. The alternate camera we support right now + // is the viewFrustumOffsetCamera. But theoretically, we could use this same mechanism + // to add other cameras. + // + // Why have two cameras? Well, one reason is that because in the case of the render_view_frustum() + // code, we want to keep the state of "myCamera" intact, so we can render what the view frustum of + // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera + Camera whichCamera = myCamera; + Camera viewFrustumOffsetCamera = myCamera; + + if (::viewFrustumFromOffset && ::frustumOn) { + //---------------------------------------------------- + // set the camera to third-person view but offset so we can see the frustum + //---------------------------------------------------- + viewFrustumOffsetCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw ); + viewFrustumOffsetCamera.setPitch ( 0.0 + ::viewFrustumOffsetPitch ); + viewFrustumOffsetCamera.setRoll ( 0.0 + ::viewFrustumOffsetRoll ); + viewFrustumOffsetCamera.setUp ( 0.2 + ::viewFrustumOffsetUp ); + viewFrustumOffsetCamera.setDistance ( 0.5 + ::viewFrustumOffsetDistance ); + viewFrustumOffsetCamera.update(); + + whichCamera = viewFrustumOffsetCamera; + } + //--------------------------------------------- // transform view according to whichCamera // could be myCamera (if in normal mode) @@ -746,6 +811,8 @@ void display(void) glRotatef ( whichCamera.getRoll(), 0, 0, 1 ); glTranslatef( -whichCamera.getPosition().x, -whichCamera.getPosition().y, -whichCamera.getPosition().z ); + + if (::starsOn) { // should be the first rendering pass - w/o depth buffer / lighting stars.render(fov); @@ -962,7 +1029,17 @@ int setDisplayFrustum(int state) { } int setFrustumOffset(int state) { - return setValue(state, &::viewFrustumFromOffset); + int value = setValue(state, &::viewFrustumFromOffset); + + // make sure we reset the camera for OpenGL appropriate + if (::viewFrustumFromOffset) { + currentCamera = ::viewFrustumOffsetCamera; + } else { + currentCamera = myCamera; + } + reshape(::WIDTH,::HEIGHT); + + return value; } int setFrustumOrigin(int state) { @@ -1183,7 +1260,7 @@ void key(unsigned char k, int x, int y) if (k == 'V' || k == 'v') ::showingVoxels = !::showingVoxels; // toggle voxels if (k == 'F') ::frustumOn = !::frustumOn; // toggle view frustum debugging if (k == 'C') ::cameraFrustum = !::cameraFrustum; // toggle which frustum to look at - if (k == 'O' || k == 'G') ::viewFrustumFromOffset = !::viewFrustumFromOffset; // toggle view frustum offset debugging + if (k == 'O' || k == 'G') setFrustumOffset(MENU_ROW_PICKED); // toggle view frustum offset debugging if (k == '[') ::viewFrustumOffsetYaw -= 0.5; if (k == ']') ::viewFrustumOffsetYaw += 0.5; @@ -1195,8 +1272,10 @@ void key(unsigned char k, int x, int y) if (k == '>') ::viewFrustumOffsetDistance += 0.5; if (k == ',') ::viewFrustumOffsetUp -= 0.05; if (k == '.') ::viewFrustumOffsetUp += 0.05; - if (k == '|') ViewFrustum::fovAngleAdust -= 0.05; - if (k == '\\') ViewFrustum::fovAngleAdust += 0.05; + +// if (k == '|') ViewFrustum::fovAngleAdust -= 0.05; +// if (k == '\\') ViewFrustum::fovAngleAdust += 0.05; + if (k == 'R') setFrustumRenderMode(MENU_ROW_PICKED); if (k == '&') { @@ -1343,27 +1422,49 @@ void idle(void) } - void reshape(int width, int height) { WIDTH = width; HEIGHT = height; + float aspectRatio = ((float)width/(float)height); // based on screen resize + + // get the lens details from the current camera + float fov = ::currentCamera.getFieldOfView(); + float nearClip = ::currentCamera.getNearClip(); + float farClip = ::currentCamera.getFarClip(); + + + printf("reshape() width=%d, height=%d, aspectRatio=%f fov=%f near=%f far=%f \n", + width,height,aspectRatio,fov,nearClip,farClip); + + // Tell our viewFrustum about this change + ::viewFrustum.setAspectRatio(aspectRatio); + + + glViewport(0, 0, width, height); // shouldn't this account for the menu??? glMatrixMode(GL_PROJECTION); //hello - fov.setResolution(width, height) - .setBounds(glm::vec3(-0.5f,-0.5f,-500.0f), glm::vec3(0.5f, 0.5f, 0.1f) ) - .setPerspective(0.7854f); - glLoadMatrixf(glm::value_ptr(fov.getViewerScreenXform())); + // XXXBHG - Note: this is Tobias's code for loading the perspective matrix. At Philip's suggestion, I'm removing + // it and putting back our old code that simply loaded the fov, ratio, and near/far clips. But I'm keeping this here + // for reference for now. + //fov.setResolution(width, height) + // .setBounds(glm::vec3(-0.5f,-0.5f,-500.0f), glm::vec3(0.5f, 0.5f, 0.1f) ) + // .setPerspective(0.7854f); + //glLoadMatrixf(glm::value_ptr(fov.getViewerScreenXform())); + + glLoadIdentity(); + + // On window reshape, we need to tell OpenGL about our new setting + gluPerspective(fov,aspectRatio,nearClip-0.01f,farClip+0.01f); + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glViewport(0, 0, width, height); + } - - void mouseFunc( int button, int state, int x, int y ) { if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) @@ -1453,6 +1554,12 @@ int main(int argc, const char * argv[]) #ifdef _WIN32 glewInit(); #endif + + // Before we render anything, let's set up our viewFrustumOffsetCamera with a sufficiently large + // field of view and near and far clip to make it interesting. + //viewFrustumOffsetCamera.setFieldOfView(90.0); + viewFrustumOffsetCamera.setNearClip(0.1); + viewFrustumOffsetCamera.setFarClip(500.0); printf( "Created Display Window.\n" ); From a5a93443c6b48d01c1f133c19cefa4076ccd228e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 18:05:22 -0700 Subject: [PATCH 13/51] 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 faf57d9fa80ecf8a01b04e76406193196afefe48 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Apr 2013 18:11:23 -0700 Subject: [PATCH 14/51] a little hackery when in view frustum mode so we can see the frustum without OpenGL clipping us --- interface/src/main.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index a61984f507..2d37414d62 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1471,8 +1471,15 @@ void reshape(int width, int height) glLoadIdentity(); + // XXXBHG - If we're in view frustum mode, then we need to do this little bit of hackery so that + // OpenGL won't clip our frustum rendering lines. This is a debug hack for sure! + if (::frustumOn) { + nearClip -= 0.01f; + farClip += 0.01f; + } + // On window reshape, we need to tell OpenGL about our new setting - gluPerspective(fov,aspectRatio,nearClip-0.01f,farClip+0.01f); + gluPerspective(fov,aspectRatio,nearClip,farClip); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); From 61cf17da731691c548ac5cf69290a85ebd24a98c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 18:19:01 -0700 Subject: [PATCH 15/51] 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 e7fa54079681ce47fb49ac47af4e0a9861ef08b9 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Apr 2013 18:30:33 -0700 Subject: [PATCH 16/51] cleaning up of whacky currentCamera experiment --- interface/src/main.cpp | 73 +++++++++++------------------------------- 1 file changed, 18 insertions(+), 55 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 2d37414d62..893fdf32f9 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -105,7 +105,6 @@ ViewFrustum viewFrustum; // current state of view frustum, perspective, orient Head myAvatar; // The rendered avatar of oneself Camera myCamera; // My view onto the world (sometimes on myself :) Camera viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode -Camera currentCamera = myCamera; // could be either myCamera or viewFrustumOffsetCamera, this is the camera for OpenGL // Starfield information char starFile[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; @@ -738,47 +737,6 @@ void display(void) myCamera.update ( 1.f/FPS ); } -/****** - // Note: currentCamera is used to pick between the normal camera myCamera for our - // main camera, vs, an alternate camera. The alternate camera we support right now - // is the viewFrustumOffsetCamera. But theoretically, we could use this same mechanism - // to add other cameras. - // - // Why have two cameras? Well, one reason is that because in the case of the render_view_frustum() - // code, we want to keep the state of "myCamera" intact, so we can render what the view frustum of - // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera - currentCamera = myCamera; - - if (::viewFrustumFromOffset && ::frustumOn) { - - viewFrustumOffsetCamera = myCamera; //.setTargetPosition( myAvatar.getPos() ); - - //---------------------------------------------------- - // set the camera to third-person view but offset so we can see the frustum - //---------------------------------------------------- - viewFrustumOffsetCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw ); - viewFrustumOffsetCamera.setPitch ( 0.0 + ::viewFrustumOffsetPitch ); - viewFrustumOffsetCamera.setRoll ( 0.0 + ::viewFrustumOffsetRoll ); - viewFrustumOffsetCamera.setUp ( 0.2 + ::viewFrustumOffsetUp ); - viewFrustumOffsetCamera.setDistance ( 0.5 + ::viewFrustumOffsetDistance ); - viewFrustumOffsetCamera.update(); - - // We'll be using this one! - currentCamera = viewFrustumOffsetCamera; - } - - //--------------------------------------------- - // transform view according to whichCamera - // could be myCamera (if in normal mode) - // or could be viewFrustumOffsetCamera if in offset mode - //--------------------------------------------- - glRotatef ( currentCamera.getPitch(), 1, 0, 0 ); - glRotatef ( currentCamera.getYaw(), 0, 1, 0 ); - glRotatef ( currentCamera.getRoll(), 0, 0, 1 ); - glTranslatef( -currentCamera.getPosition().x, -currentCamera.getPosition().y, -currentCamera.getPosition().z ); -*****/ - - // Note: whichCamera is used to pick between the normal camera myCamera for our // main camera, vs, an alternate camera. The alternate camera we support right now // is the viewFrustumOffsetCamera. But theoretically, we could use this same mechanism @@ -1032,13 +990,8 @@ int setDisplayFrustum(int state) { int setFrustumOffset(int state) { int value = setValue(state, &::viewFrustumFromOffset); - - // make sure we reset the camera for OpenGL appropriate - if (::viewFrustumFromOffset) { - currentCamera = ::viewFrustumOffsetCamera; - } else { - currentCamera = myCamera; - } + + // reshape so that OpenGL will get the right lens details for the camera of choice reshape(::WIDTH,::HEIGHT); return value; @@ -1443,12 +1396,20 @@ void reshape(int width, int height) HEIGHT = height; float aspectRatio = ((float)width/(float)height); // based on screen resize - - // get the lens details from the current camera - float fov = ::currentCamera.getFieldOfView(); - float nearClip = ::currentCamera.getNearClip(); - float farClip = ::currentCamera.getFarClip(); + float fov; + float nearClip; + float farClip; + // get the lens details from the current camera + if (::viewFrustumFromOffset) { + fov = ::viewFrustumOffsetCamera.getFieldOfView(); + nearClip = ::viewFrustumOffsetCamera.getNearClip(); + farClip = ::viewFrustumOffsetCamera.getFarClip(); + } else { + fov = ::myCamera.getFieldOfView(); + nearClip = ::myCamera.getNearClip(); + farClip = ::myCamera.getFarClip(); + } printf("reshape() width=%d, height=%d, aspectRatio=%f fov=%f near=%f far=%f \n", width,height,aspectRatio,fov,nearClip,farClip); @@ -1472,7 +1433,9 @@ void reshape(int width, int height) glLoadIdentity(); // XXXBHG - If we're in view frustum mode, then we need to do this little bit of hackery so that - // OpenGL won't clip our frustum rendering lines. This is a debug hack for sure! + // OpenGL won't clip our frustum rendering lines. This is a debug hack for sure! Basically, this makes + // the near clip a little bit closer (therefor you see more) and the far clip a little bit farther (also, + // to see more.) if (::frustumOn) { nearClip -= 0.01f; farClip += 0.01f; From 2b4944203975b5e3495a7955e50c6c9dc7a7c07e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 18:34:40 -0700 Subject: [PATCH 17/51] 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 18/51] 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 19/51] 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 cd3e414edaa24ca4ec4581db0f3fdc3c584ccbd5 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 15 Apr 2013 18:37:46 -0700 Subject: [PATCH 20/51] Removed unneeded variables in main.cpp for pitch,yaw. Renamed routines to make it more clear where gyros are being read. Re-enabled marker box being driven by head gyros. --- interface/src/Head.cpp | 1 + interface/src/main.cpp | 71 ++++++++++++++++++++---------------------- 2 files changed, 34 insertions(+), 38 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 826dbbe459..05310cafca 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -217,6 +217,7 @@ void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int hea if ((Pitch < MAX_PITCH) && (Pitch > MIN_PITCH)) addPitch(measured_pitch_rate * -HEAD_ROTATION_SCALE * frametime); + addRoll(-measured_roll_rate * HEAD_ROLL_SCALE * frametime); if (head_mirror) { diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 10f0eb526f..fcc0e87775 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -136,10 +136,7 @@ Audio audio(&audioScope, &myAvatar); #define IDLE_SIMULATE_MSECS 8 // How often should call simulate and other stuff // in the idle loop? -float yaw = 0.f; // The yaw, pitch for the avatar head -float pitch = 0.f; float startYaw = 122.f; -float renderPitch = 0.f; float renderYawRate = 0.f; float renderPitchRate = 0.f; @@ -351,8 +348,8 @@ void reset_sensors() // myAvatar.setRenderYaw(startYaw); - yaw = renderYawRate = 0; - pitch = renderPitch = renderPitchRate = 0; + renderYawRate = 0; + renderPitchRate = 0; myAvatar.setPos(start_location); headMouseX = WIDTH/2; headMouseY = HEIGHT/2; @@ -364,7 +361,7 @@ void reset_sensors() } } -void simulateHand(float deltaTime) { +void updateAvatarHand(float deltaTime) { // If mouse is being dragged, send current force to the hand controller if (mousePressed == 1) { @@ -378,28 +375,26 @@ void simulateHand(float deltaTime) { } } -void simulateHead(float frametime) -// Using serial data, update avatar/render position and angles +// +// Using gyro data, update both view frustum and avatar head position +// +void updateAvatar(float frametime) { -// float measured_pitch_rate = serialPort.getRelativeValue(PITCH_RATE); -// float measured_yaw_rate = serialPort.getRelativeValue(YAW_RATE); - - float measured_pitch_rate = 0; - float measured_yaw_rate = 0; - - //float measured_lateral_accel = serialPort.getRelativeValue(ACCEL_X); - //float measured_fwd_accel = serialPort.getRelativeValue(ACCEL_Z); + float gyroPitchRate = serialPort.getRelativeValue(PITCH_RATE); + float gyroYawRate = serialPort.getRelativeValue(YAW_RATE); myAvatar.UpdatePos(frametime, &serialPort, headMirror, &gravity); - // Update head_mouse model + // + // Update gyro-based mouse (X,Y on screen) + // const float MIN_MOUSE_RATE = 30.0; const float MOUSE_SENSITIVITY = 0.1f; - if (powf(measured_yaw_rate*measured_yaw_rate + - measured_pitch_rate*measured_pitch_rate, 0.5) > MIN_MOUSE_RATE) + if (powf(gyroYawRate*gyroYawRate + + gyroPitchRate*gyroPitchRate, 0.5) > MIN_MOUSE_RATE) { - headMouseX += measured_yaw_rate*MOUSE_SENSITIVITY; - headMouseY += measured_pitch_rate*MOUSE_SENSITIVITY*(float)HEIGHT/(float)WIDTH; + headMouseX += gyroYawRate*MOUSE_SENSITIVITY; + headMouseY += gyroPitchRate*MOUSE_SENSITIVITY*(float)HEIGHT/(float)WIDTH; } headMouseX = max(headMouseX, 0); headMouseX = min(headMouseX, WIDTH); @@ -409,7 +404,6 @@ void simulateHead(float frametime) // Update render direction (pitch/yaw) based on measured gyro rates const int MIN_YAW_RATE = 100; const int MIN_PITCH_RATE = 100; - const float YAW_SENSITIVITY = 0.02; const float PITCH_SENSITIVITY = 0.05; @@ -418,23 +412,22 @@ void simulateHead(float frametime) if (myAvatar.getDriveKeys(ROT_LEFT)) renderYawRate -= KEY_YAW_SENSITIVITY*frametime; if (myAvatar.getDriveKeys(ROT_RIGHT)) renderYawRate += KEY_YAW_SENSITIVITY*frametime; - if (fabs(measured_yaw_rate) > MIN_YAW_RATE) + if (fabs(gyroYawRate) > MIN_YAW_RATE) { - if (measured_yaw_rate > 0) - renderYawRate += (measured_yaw_rate - MIN_YAW_RATE) * YAW_SENSITIVITY * frametime; + if (gyroYawRate > 0) + renderYawRate += (gyroYawRate - MIN_YAW_RATE) * YAW_SENSITIVITY * frametime; else - renderYawRate += (measured_yaw_rate + MIN_YAW_RATE) * YAW_SENSITIVITY * frametime; + renderYawRate += (gyroYawRate + MIN_YAW_RATE) * YAW_SENSITIVITY * frametime; } - if (fabs(measured_pitch_rate) > MIN_PITCH_RATE) + if (fabs(gyroPitchRate) > MIN_PITCH_RATE) { - if (measured_pitch_rate > 0) - renderPitchRate += (measured_pitch_rate - MIN_PITCH_RATE) * PITCH_SENSITIVITY * frametime; + if (gyroPitchRate > 0) + renderPitchRate += (gyroPitchRate - MIN_PITCH_RATE) * PITCH_SENSITIVITY * frametime; else - renderPitchRate += (measured_pitch_rate + MIN_PITCH_RATE) * PITCH_SENSITIVITY * frametime; + renderPitchRate += (gyroPitchRate + MIN_PITCH_RATE) * PITCH_SENSITIVITY * frametime; } - renderPitch += renderPitchRate; - + float renderPitch = myAvatar.getRenderPitch(); // Decay renderPitch toward zero because we never look constantly up/down renderPitch *= (1.f - 2.0*frametime); @@ -442,9 +435,9 @@ void simulateHead(float frametime) renderPitchRate *= (1.f - 5.0*frametime); renderYawRate *= (1.f - 7.0*frametime); - // Update own head data + // Update own avatar data myAvatar.setRenderYaw(myAvatar.getRenderYaw() + renderYawRate); - myAvatar.setRenderPitch(renderPitch); + myAvatar.setRenderPitch(renderPitch + renderPitchRate); // Get audio loudness data from audio input device float loudness, averageLoudness; @@ -1325,8 +1318,10 @@ void idle(void) myAvatar.setTriggeringAction( false ); } - // Simulation - simulateHead( 1.f/FPS ); + // + // Sample hardware, update view frustum if needed, send avatar data to mixer/agents + // + updateAvatar( 1.f/FPS ); //test @@ -1341,8 +1336,8 @@ void idle(void) } */ - simulateHand(1.f/FPS); - + updateAvatarHand(1.f/FPS); + field.simulate(1.f/FPS); myAvatar.simulate(1.f/FPS); balls.simulate(1.f/FPS); From 5e5a7e0a0c666e82f210509a63b0675fc39cc5ed Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 15 Apr 2013 20:52:18 -0700 Subject: [PATCH 21/51] Improved SerialInterface: Added gravity vector get function, closer to coding standards, better rendering of levels. --- interface/src/SerialInterface.cpp | 95 ++++++++++++++++++------------- interface/src/SerialInterface.h | 5 +- 2 files changed, 58 insertions(+), 42 deletions(-) diff --git a/interface/src/SerialInterface.cpp b/interface/src/SerialInterface.cpp index 9ab1ce6373..7a124f02f3 100644 --- a/interface/src/SerialInterface.cpp +++ b/interface/src/SerialInterface.cpp @@ -6,12 +6,12 @@ // // Channels are received in the following order (integer 0-4096 based on voltage 0-3.3v) // -// AIN 15: Pitch Gyro (nodding your head 'yes') -// AIN 16: Yaw Gyro (shaking your head 'no') -// AIN 17: Roll Gyro (looking quizzical, tilting your head) -// AIN 18: Lateral acceleration (moving from side-to-side in front of your monitor) -// AIN 19: Up/Down acceleration (sitting up/ducking in front of your monitor) -// AIN 20: Forward/Back acceleration (Toward or away from your monitor) +// 0 - AIN 15: Pitch Gyro (nodding your head 'yes') +// 1 - AIN 16: Yaw Gyro (shaking your head 'no') +// 2 - AIN 17: Roll Gyro (looking quizzical, tilting your head) +// 3 - AIN 18: Lateral acceleration (moving from side-to-side in front of your monitor) +// 4 - AIN 19: Up/Down acceleration (sitting up/ducking in front of your monitor) +// 5 - AIN 20: Forward/Back acceleration (Toward or away from your monitor) // #include "SerialInterface.h" @@ -21,14 +21,15 @@ #include #endif -int serial_fd; +int serialFd; const int MAX_BUFFER = 255; -char serial_buffer[MAX_BUFFER]; -int serial_buffer_pos = 0; +char serialBuffer[MAX_BUFFER]; +int serialBufferPos = 0; const int ZERO_OFFSET = 2048; const short NO_READ_MAXIMUM_MSECS = 3000; -const short SAMPLES_TO_DISCARD = 100; +const short SAMPLES_TO_DISCARD = 100; // Throw out the first few samples +const int GRAVITY_SAMPLES = 200; // Use the first samples to compute gravity vector void SerialInterface::pair() { @@ -48,7 +49,7 @@ void SerialInterface::pair() { char *serialPortname = new char[100]; sprintf(serialPortname, "/dev/%s", entry->d_name); - init(serialPortname, 115200); + initializePort(serialPortname, 115200); delete [] serialPortname; } @@ -60,18 +61,20 @@ void SerialInterface::pair() { } -// Init the serial port to the specified values -int SerialInterface::init(char* portname, int baud) +// Connect to the serial port +int SerialInterface::initializePort(char* portname, int baud) { #ifdef __APPLE__ - serial_fd = open(portname, O_RDWR | O_NOCTTY | O_NDELAY); + serialFd = open(portname, O_RDWR | O_NOCTTY | O_NDELAY); - printf("Attemping to open serial interface: %s\n", portname); - - if (serial_fd == -1) return -1; // Failed to open port + printf("Opening SerialUSB %s: ", portname); + if (serialFd == -1) { + printf("Failed.\n"); + return -1; // Failed to open port + } struct termios options; - tcgetattr(serial_fd,&options); + tcgetattr(serialFd,&options); switch(baud) { case 9600: cfsetispeed(&options,B9600); @@ -95,10 +98,10 @@ int SerialInterface::init(char* portname, int baud) options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; - tcsetattr(serial_fd,TCSANOW,&options); + tcsetattr(serialFd,TCSANOW,&options); - printf("Serial interface opened!\n"); + printf("Connected.\n"); resetSerial(); active = true; #endif @@ -126,22 +129,17 @@ void SerialInterface::renderLevels(int width, int height) { glBegin(GL_LINES); glVertex2f(disp_x, height*0.95); glVertex2f(disp_x, height*(0.25 + 0.75f*getValue(i)/4096)); + glColor4f(1, 0, 0, 1); + glVertex2f(disp_x - 3, height*(0.25 + 0.75f*getValue(i)/4096)); + glVertex2f(disp_x, height*(0.25 + 0.75f*getValue(i)/4096)); glEnd(); // Trailing Average value - glColor4f(1, 1, 0, 1); glBegin(GL_LINES); - glVertex2f(disp_x + 2, height*0.95); - glVertex2f(disp_x + 2, height*(0.25 + 0.75f*getTrailingValue(i)/4096)); + glColor4f(1, 1, 1, 1); + glVertex2f(disp_x, height*(0.25 + 0.75f*getTrailingValue(i)/4096)); + glVertex2f(disp_x + 4, height*(0.25 + 0.75f*getTrailingValue(i)/4096)); glEnd(); - /* - glColor3f(1,0,0); - glBegin(GL_LINES); - glLineWidth(4.0); - glVertex2f(disp_x - 10, height*0.5 - getValue(i)/4096); - glVertex2f(disp_x + 10, height*0.5 - getValue(i)/4096); - glEnd(); - */ sprintf(val, "%d", getValue(i)); drawtext(disp_x-GAP/2, (height*0.95)+2, 0.08, 90, 1.0, 0, val, 0, 1, 0); @@ -162,20 +160,20 @@ void SerialInterface::renderLevels(int width, int height) { } void SerialInterface::readData() { #ifdef __APPLE__ - // This array sets the rate of trailing averaging for each channel. + // This array sets the rate of trailing averaging for each channel: // If the sensor rate is 100Hz, 0.001 will make the long term average a 10-second average - const float AVG_RATE[] = {0.01, 0.01, 0.01, 0.01, 0.01, 0.01}; + const float AVG_RATE[] = {0.002, 0.002, 0.002, 0.002, 0.002, 0.002}; char bufchar[1]; int initialSamples = totalSamples; - while (read(serial_fd, &bufchar, 1) > 0) { + while (read(serialFd, &bufchar, 1) > 0) { //std::cout << bufchar[0]; - serial_buffer[serial_buffer_pos] = bufchar[0]; - serial_buffer_pos++; + serialBuffer[serialBufferPos] = bufchar[0]; + serialBufferPos++; // Have we reached end of a line of input? - if ((bufchar[0] == '\n') || (serial_buffer_pos >= MAX_BUFFER)) { - std::string serialLine(serial_buffer, serial_buffer_pos-1); + if ((bufchar[0] == '\n') || (serialBufferPos >= MAX_BUFFER)) { + std::string serialLine(serialBuffer, serialBufferPos-1); //std::cout << serialLine << "\n"; int spot; //int channel = 0; @@ -191,6 +189,7 @@ void SerialInterface::readData() { serialLine = serialLine.substr(spot+1, serialLine.length() - spot - 1); } + // Update Trailing Averages for (int i = 0; i < NUM_CHANNELS; i++) { if (totalSamples > SAMPLES_TO_DISCARD) { trailingAverage[i] = (1.f - AVG_RATE[i])*trailingAverage[i] + @@ -200,8 +199,21 @@ void SerialInterface::readData() { } } + + // Use a set of initial samples to compute gravity + if (totalSamples < GRAVITY_SAMPLES) { + gravity.x += lastMeasured[ACCEL_X]; + gravity.y += lastMeasured[ACCEL_Y]; + gravity.z += lastMeasured[ACCEL_Z]; + } + if (totalSamples == GRAVITY_SAMPLES) { + gravity = glm::normalize(gravity); + std::cout << "gravity: " << gravity.x << "," << + gravity.y << "," << gravity.z << "\n"; + } + totalSamples++; - serial_buffer_pos = 0; + serialBufferPos = 0; } } @@ -210,7 +222,7 @@ void SerialInterface::readData() { gettimeofday(&now, NULL); if (diffclock(&lastGoodRead, &now) > NO_READ_MAXIMUM_MSECS) { - std::cout << "No data coming over serial. Shutting down SerialInterface.\n"; + std::cout << "No data - Shutting down SerialInterface.\n"; resetSerial(); } } else { @@ -223,6 +235,7 @@ void SerialInterface::resetSerial() { #ifdef __APPLE__ active = false; totalSamples = 0; + gravity = glm::vec3(0,-1,0); gettimeofday(&lastGoodRead, NULL); @@ -233,7 +246,7 @@ void SerialInterface::resetSerial() { } // Clear serial input buffer for (int i = 1; i < MAX_BUFFER; i++) { - serial_buffer[i] = ' '; + serialBuffer[i] = ' '; } #endif } diff --git a/interface/src/SerialInterface.h b/interface/src/SerialInterface.h index 8849d7f5d9..50fde4a13d 100644 --- a/interface/src/SerialInterface.h +++ b/interface/src/SerialInterface.h @@ -45,8 +45,10 @@ public: void resetTrailingAverages(); void renderLevels(int width, int height); bool active; + glm::vec3 getGravity() {return gravity;}; + private: - int init(char * portname, int baud); + int initializePort(char * portname, int baud); void resetSerial(); int lastMeasured[NUM_CHANNELS]; float trailingAverage[NUM_CHANNELS]; @@ -54,6 +56,7 @@ private: int LED; int totalSamples; timeval lastGoodRead; + glm::vec3 gravity; }; #endif From 246380b41e23e585638738b40eff644c275ba50e Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Apr 2013 00:55:44 -0700 Subject: [PATCH 22/51] temp fix to setPitch() problem. Removed some debug printfs. Fixed menu flicker bug. --- interface/src/main.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 893fdf32f9..5dcb379152 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -562,6 +562,7 @@ void render_view_frustum() { farClip = ::myCamera.getFarClip(); } + /* printf("position.x=%f, position.y=%f, position.z=%f\n", position.x, position.y, position.z); printf("direction.x=%f, direction.y=%f, direction.z=%f\n", direction.x, direction.y, direction.z); printf("up.x=%f, up.y=%f, up.z=%f\n", up.x, up.y, up.z); @@ -569,7 +570,7 @@ void render_view_frustum() { printf("fov=%f\n", fov); printf("nearClip=%f\n", nearClip); printf("farClip=%f\n", farClip); - + */ // Set the viewFrustum up with the correct position and orientation of the camera viewFrustum.setPosition(position); @@ -583,7 +584,7 @@ void render_view_frustum() { // Ask the ViewFrustum class to calculate our corners viewFrustum.calculate(); - viewFrustum.dump(); + //viewFrustum.dump(); // Get ready to draw some lines glDisable(GL_LIGHTING); @@ -729,7 +730,7 @@ void display(void) //---------------------------------------------------- myCamera.setTargetPosition ( myAvatar.getPos() ); myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() ); - myCamera.setPitch ( 10.0 ); + myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju myCamera.setRoll ( 0.0 ); myCamera.setUp ( 0.45 ); myCamera.setDistance ( 0.5 ); @@ -992,7 +993,9 @@ int setFrustumOffset(int state) { int value = setValue(state, &::viewFrustumFromOffset); // reshape so that OpenGL will get the right lens details for the camera of choice - reshape(::WIDTH,::HEIGHT); + if (state == MENU_ROW_PICKED) { + reshape(::WIDTH,::HEIGHT); + } return value; } @@ -1054,12 +1057,13 @@ void initMenu() { menuColumnOptions->addRow("(V)oxels", setVoxels); menuColumnOptions->addRow("Stars (*)", setStars); menuColumnOptions->addRow("(Q)uit", quitApp); + // Tools menuColumnTools = menu.addColumn("Tools"); menuColumnTools->addRow("Stats (/)", setStats); menuColumnTools->addRow("(M)enu", setMenu); - // Debug + // Frustum Options menuColumnFrustum = menu.addColumn("Frustum"); menuColumnFrustum->addRow("Display (F)rustum", setDisplayFrustum); menuColumnFrustum->addRow("Use (O)ffset Camera", setFrustumOffset); @@ -1411,8 +1415,8 @@ void reshape(int width, int height) farClip = ::myCamera.getFarClip(); } - printf("reshape() width=%d, height=%d, aspectRatio=%f fov=%f near=%f far=%f \n", - width,height,aspectRatio,fov,nearClip,farClip); + //printf("reshape() width=%d, height=%d, aspectRatio=%f fov=%f near=%f far=%f \n", + // width,height,aspectRatio,fov,nearClip,farClip); // Tell our viewFrustum about this change ::viewFrustum.setAspectRatio(aspectRatio); From 75c63f53fcbe86e362a9b95945a678b5b19c1789 Mon Sep 17 00:00:00 2001 From: stojce Date: Tue, 16 Apr 2013 17:38:34 +0200 Subject: [PATCH 23/51] use safe version of `sprintf` --- interface/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 16a0d9a43d..4368d7fd97 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -896,7 +896,7 @@ void display(void) float startupTime = (usecTimestampNow() - usecTimestamp(&applicationStartupTime))/1000000.0; justStarted = false; char title[30]; - sprintf(title, "Interface: %4.2f seconds", startupTime); + snprintf(title, 30, "Interface: %4.2f seconds", startupTime); glutSetWindowTitle(title); } } From dcca1699d3233e45021044c5bc56116dd80a26e5 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Apr 2013 11:29:31 -0700 Subject: [PATCH 24/51] Adding first cut at ViewFrustum pointIn,SphereIn,BoxIn code. - Added Plane class - Added AABox class - Removed some experimental "slightly inside" code from view frustum --- libraries/voxels/src/AABox.cpp | 76 +++++++++++++++++++++++++ libraries/voxels/src/AABox.h | 33 +++++++++++ libraries/voxels/src/Plane.cpp | 83 ++++++++++++++++++++++++++++ libraries/voxels/src/Plane.h | 35 ++++++++++++ libraries/voxels/src/ViewFrustum.cpp | 65 ++++++++++++++++++---- libraries/voxels/src/ViewFrustum.h | 11 ++++ 6 files changed, 292 insertions(+), 11 deletions(-) create mode 100755 libraries/voxels/src/AABox.cpp create mode 100755 libraries/voxels/src/AABox.h create mode 100755 libraries/voxels/src/Plane.cpp create mode 100755 libraries/voxels/src/Plane.h diff --git a/libraries/voxels/src/AABox.cpp b/libraries/voxels/src/AABox.cpp new file mode 100755 index 0000000000..bc36bca7a9 --- /dev/null +++ b/libraries/voxels/src/AABox.cpp @@ -0,0 +1,76 @@ +/* ------------------------------------------------------ + + Axis Aligned Boxes - Lighthouse3D + + -----------------------------------------------------*/ + +#include "AABox.h" + + +AABox::AABox(const glm::vec3& corner, float x, float y, float z) { + setBox(corner,x,y,z); +} + +AABox::AABox(void) { + corner.x = 0; corner.y = 0; corner.z = 0; + x = 1.0f; + y = 1.0f; + z = 1.0f; +} + + +AABox::~AABox() {} + + + +void AABox::setBox(const glm::vec3& corner, float x, float y, float z) { + this->corner = corner; + if (x < 0.0) { + x = -x; + this->corner.x -= x; + } + if (y < 0.0) { + y = -y; + this->corner.y -= y; + } + if (z < 0.0) { + z = -z; + this->corner.z -= z; + } + this->x = x; + this->y = y; + this->z = z; +} + + + +glm::vec3 AABox::getVertexP(const glm::vec3 &normal) { + glm::vec3 res = corner; + if (normal.x > 0) + res.x += x; + + if (normal.y > 0) + res.y += y; + + if (normal.z > 0) + res.z += z; + + return(res); +} + + + +glm::vec3 AABox::getVertexN(const glm::vec3 &normal) { + glm::vec3 res = corner; + + if (normal.x < 0) + res.x += x; + + if (normal.y < 0) + res.y += y; + + if (normal.z < 0) + res.z += z; + + return(res); +} diff --git a/libraries/voxels/src/AABox.h b/libraries/voxels/src/AABox.h new file mode 100755 index 0000000000..abc20f38d5 --- /dev/null +++ b/libraries/voxels/src/AABox.h @@ -0,0 +1,33 @@ +/* ------------------------------------------------------ + + Axis Aligned Boxes - Lighthouse3D + + -----------------------------------------------------*/ + + +#ifndef _AABOX_ +#define _AABOX_ + +#include + +class AABox +{ + +public: + + glm::vec3 corner; + float x,y,z; + + AABox(const glm::vec3 &corner, float x, float y, float z); + AABox(void); + ~AABox(); + + void setBox(const glm::vec3& corner, float x, float y, float z); + + // for use in frustum computations + glm::vec3 getVertexP(const glm::vec3& normal); + glm::vec3 getVertexN(const glm::vec3& normal); +}; + + +#endif \ No newline at end of file diff --git a/libraries/voxels/src/Plane.cpp b/libraries/voxels/src/Plane.cpp new file mode 100755 index 0000000000..fa23affe6c --- /dev/null +++ b/libraries/voxels/src/Plane.cpp @@ -0,0 +1,83 @@ +// Plane.cpp +// +////////////////////////////////////////////////////////////////////// + +#include "Plane.h" +#include + +// These are some useful utilities that vec3 is missing +float vec3_length(const glm::vec3& v) { + return((float)sqrt(v.x*v.x + v.y*v.y + v.z*v.z)); +} + +void vec3_normalize(glm::vec3& v) { + + float len; + + len = vec3_length(v); + if (len) { + v.x /= len;; + v.y /= len; + v.z /= len; + } +} + +float vec3_innerProduct(const glm::vec3& v1,const glm::vec3& v2) { + + return (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z); +} + + + +Plane::Plane(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3) { + + set3Points(v1,v2,v3); +} + + +Plane::Plane() {} + +Plane::~Plane() {} + + +void Plane::set3Points(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3) { + + + glm::vec3 aux1, aux2; + + aux1 = v1 - v2; + aux2 = v3 - v2; + + normal = aux2 * aux1; + + vec3_normalize(normal); + point = v2; + d = -(vec3_innerProduct(normal,point)); +} + +void Plane::setNormalAndPoint(const glm::vec3 &normal, const glm::vec3 &point) { + + this->normal = normal; + vec3_normalize(this->normal); + d = -(vec3_innerProduct(this->normal,point)); +} + +void Plane::setCoefficients(float a, float b, float c, float d) { + + // set the normal vector + normal = glm::vec3(a,b,c); + //compute the lenght of the vector + float l = normal.length(); + // normalize the vector + normal = glm::vec3(a/l,b/l,c/l); + // and divide d by th length as well + this->d = d/l; +} + +float Plane::distance(const glm::vec3 &p) { + return (d + vec3_innerProduct(normal,p)); +} + +void Plane::print() { + //printf("Plane(");normal.print();printf("# %f)",d); +} diff --git a/libraries/voxels/src/Plane.h b/libraries/voxels/src/Plane.h new file mode 100755 index 0000000000..5c23993dc9 --- /dev/null +++ b/libraries/voxels/src/Plane.h @@ -0,0 +1,35 @@ +////////////////////////////////////////////////////////////////////// +// Plane.h - inspired and modified from lighthouse3d.com +// + + +#ifndef _PLANE_ +#define _PLANE_ + +#include + + +class Plane +{ + +public: + + glm::vec3 normal,point; + float d; + + + Plane(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3); + Plane(void); + ~Plane(); + + void set3Points(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3); + void setNormalAndPoint(const glm::vec3 &normal, const glm::vec3 &point); + void setCoefficients(float a, float b, float c, float d); + float distance(const glm::vec3 &p); + + void print(); + +}; + + +#endif \ No newline at end of file diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 1de5c11d6a..487b715ca6 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -55,34 +55,43 @@ void ViewFrustum::calculate() { float twoTimesTanHalfFOV = 2.0f * tan(fovInRadians/2.0f); - float slightlySmaller = 0.0f; - float slightlyInsideWidth= 0.0f - slightlySmaller; - float slightlyInsideNear = 0.0f + slightlySmaller; - float slightlyInsideFar = 0.0f - slightlySmaller; - - float nearClip = this->_nearClip + slightlyInsideNear; - float farClip = this->_farClip + slightlyInsideFar; + // Do we need this? + //tang = (float)tan(ANG2RAD * angle * 0.5) ; + + float nearClip = this->_nearClip; + float farClip = this->_farClip; this->_nearHeight = (twoTimesTanHalfFOV * nearClip); this->_nearWidth = this->_nearHeight * this->_aspectRatio; this->_farHeight = (twoTimesTanHalfFOV * farClip); this->_farWidth = this->_farHeight * this->_aspectRatio; - float farHalfHeight = (this->_farHeight * 0.5f) + slightlyInsideWidth; - float farHalfWidth = (this->_farWidth * 0.5f) + slightlyInsideWidth; + float farHalfHeight = (this->_farHeight * 0.5f); + float farHalfWidth = (this->_farWidth * 0.5f); this->_farCenter = this->_position+front * farClip; this->_farTopLeft = this->_farCenter + (this->_up * farHalfHeight) - (this->_right * farHalfWidth); this->_farTopRight = this->_farCenter + (this->_up * farHalfHeight) + (this->_right * farHalfWidth); this->_farBottomLeft = this->_farCenter - (this->_up * farHalfHeight) - (this->_right * farHalfWidth); this->_farBottomRight = this->_farCenter - (this->_up * farHalfHeight) + (this->_right * farHalfWidth); - float nearHalfHeight = (this->_nearHeight * 0.5f) + slightlyInsideWidth; - float nearHalfWidth = (this->_nearWidth * 0.5f) + slightlyInsideWidth; + float nearHalfHeight = (this->_nearHeight * 0.5f); + float nearHalfWidth = (this->_nearWidth * 0.5f); this->_nearCenter = this->_position+front * nearClip; this->_nearTopLeft = this->_nearCenter + (this->_up * nearHalfHeight) - (this->_right * nearHalfWidth); this->_nearTopRight = this->_nearCenter + (this->_up * nearHalfHeight) + (this->_right * nearHalfWidth); this->_nearBottomLeft = this->_nearCenter - (this->_up * nearHalfHeight) - (this->_right * nearHalfWidth); this->_nearBottomRight = this->_nearCenter - (this->_up * nearHalfHeight) + (this->_right * nearHalfWidth); + + // compute the six planes + // the function set3Points assumes that the points + // are given in counter clockwise order + this->_planes[TOPP].set3Points(this->_nearTopRight,this->_nearTopLeft,this->_farTopLeft); + this->_planes[BOTTOMP].set3Points(this->_nearBottomLeft,this->_nearBottomRight,this->_farBottomRight); + this->_planes[LEFTP].set3Points(this->_nearTopLeft,this->_nearBottomLeft,this->_farBottomLeft); + this->_planes[RIGHTP].set3Points(this->_nearBottomRight,this->_nearTopRight,this->_farBottomRight); + this->_planes[NEARP].set3Points(this->_nearTopLeft,this->_nearTopRight,this->_nearBottomRight); + this->_planes[FARP].set3Points(this->_farTopRight,this->_farTopLeft,this->_farBottomLeft); + } void ViewFrustum::dump() { @@ -124,3 +133,37 @@ void ViewFrustum::dump() { } +int ViewFrustum::pointInFrustum(glm::vec3 &p) { + int result = INSIDE; + for(int i=0; i < 6; i++) { + if (this->_planes[i].distance(p) < 0) + return OUTSIDE; + } + return(result); +} + +int ViewFrustum::sphereInFrustum(glm::vec3 ¢er, float radius) { + int result = INSIDE; + float distance; + for(int i=0; i < 6; i++) { + distance = this->_planes[i].distance(center); + if (distance < -radius) + return OUTSIDE; + else if (distance < radius) + result = INTERSECT; + } + return(result); +} + + +int ViewFrustum::boxInFrustum(AABox &b) { + int result = INSIDE; + for(int i=0; i < 6; i++) { + if (this->_planes[i].distance(b.getVertexP(this->_planes[i].normal)) < 0) + return OUTSIDE; + else if (this->_planes[i].distance(b.getVertexN(this->_planes[i].normal)) < 0) + result = INTERSECT; + } + return(result); + } + diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index ed704e5755..15bdb484fb 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -12,6 +12,8 @@ #define __hifi__ViewFrustum__ #include +#include "Plane.h" +#include "AABox.h" class ViewFrustum { private: @@ -43,6 +45,8 @@ private: glm::vec3 _nearTopRight; glm::vec3 _nearBottomLeft; glm::vec3 _nearBottomRight; + enum { TOPP = 0, BOTTOMP, LEFTP, RIGHTP, NEARP, FARP }; + Plane _planes[6]; // How will this be used? public: // setters for camera attributes @@ -79,6 +83,13 @@ public: ViewFrustum(); void dump(); + + enum {OUTSIDE, INTERSECT, INSIDE}; + + int pointInFrustum(glm::vec3 &p); + int sphereInFrustum(glm::vec3 ¢er, float radius); + int boxInFrustum(AABox &b); + }; From 5c091a51a60e2e7376646426c16b27e89028acb8 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Apr 2013 11:51:36 -0700 Subject: [PATCH 25/51] 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 26/51] 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 27/51] 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 28/51] 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 29/51] 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 30/51] 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 31/51] 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 32/51] 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; From f8ab33ccc7e6bc3c45b89f77b1d2fc5318365936 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Apr 2013 12:48:47 -0700 Subject: [PATCH 33/51] add missing packet header for broadcast head data --- interface/src/main.cpp | 6 ++++-- libraries/shared/src/AgentList.cpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index b2f92b06fd..a5a354eca5 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -455,7 +455,9 @@ void updateAvatar(float frametime) // Send my stream of head/hand data to the avatar mixer and voxel server unsigned char broadcastString[200]; - int broadcastBytes = myAvatar.getBroadcastData(broadcastString); + *broadcastString = PACKET_HEADER_HEAD_DATA; + + int broadcastBytes = myAvatar.getBroadcastData(broadcastString + 1); const char broadcastReceivers[2] = {AGENT_TYPE_VOXEL, AGENT_TYPE_AVATAR_MIXER}; AgentList::getInstance()->broadcastToAgents(broadcastString, broadcastBytes, broadcastReceivers, 2); @@ -1097,7 +1099,7 @@ void sendVoxelServerEraseAll() { sprintf(message,"%c%s",'Z',"erase all"); int messageSize = strlen(message) + 1; AgentList::getInstance()->broadcastToAgents((unsigned char*) message, messageSize, &AGENT_TYPE_VOXEL, 1); -} +}\ void sendVoxelServerAddScene() { char message[100]; diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 6d56aac726..2751527d37 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -118,7 +118,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac while ((currentPosition - startPosition) < numTotalBytes) { currentPosition += unpackAgentId(currentPosition, &agentID); memcpy(packetHolder + 1, currentPosition, numBytesPerAgent); - + int matchingAgentIndex = indexOfMatchingAgent(agentID); if (matchingAgentIndex >= 0) { From 216cc465e7790a4fa1e28da6ff8122f763915f6a Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 16 Apr 2013 13:51:14 -0700 Subject: [PATCH 34/51] Added idealYaw to camera and also switched ordering of gl camera rotation commands --- interface/src/Camera.cpp | 10 +++++++--- interface/src/Camera.h | 3 ++- interface/src/main.cpp | 4 +++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index e9d8a26675..00960a5f26 100755 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -21,6 +21,7 @@ Camera::Camera() roll = 0.0; up = 0.0; distance = 0.0; + idealYaw = 0.0; targetPosition = glm::vec3( 0.0, 0.0, 0.0 ); position = glm::vec3( 0.0, 0.0, 0.0 ); idealPosition = glm::vec3( 0.0, 0.0, 0.0 ); @@ -35,7 +36,7 @@ void Camera::update( float deltaTime ) { double radian = ( yaw / 180.0 ) * PIE; - //these need to be checked to make sure they correspond to the cordinate system. + //these need to be checked to make sure they correspond to the coordinate system. double x = distance * -sin( radian ); double z = distance * cos( radian ); double y = up; @@ -48,10 +49,13 @@ void Camera::update( float deltaTime ) t = 1.0; } - position += ( idealPosition - position ) * t; + position += ( idealPosition - position ) * t; + yaw += ( idealYaw - yaw ) * t; + + //roll = 20.0; //------------------------------------------------------------------------- - //geterate the ortho-normals for the orientation based on the Euler angles + // generate the ortho-normals for the orientation based on the Euler angles //------------------------------------------------------------------------- orientation.setToIdentity(); orientation.yaw ( yaw ); diff --git a/interface/src/Camera.h b/interface/src/Camera.h index fd347d00f7..6350ba3540 100755 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -30,7 +30,7 @@ public: void update( float deltaTime ); void setMode ( CameraMode m ) { mode = m; } - void setYaw ( float y ) { yaw = y; } + void setYaw ( float y ) { idealYaw = y; } void setPitch ( float p ) { pitch = p; } void setRoll ( float r ) { roll = r; } void setUp ( float u ) { up = u; } @@ -58,6 +58,7 @@ private: float pitch; float roll; float up; + float idealYaw; float distance; float tightness; Orientation orientation; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index be94c863f8..0b382489cf 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -745,9 +745,11 @@ void display(void) // could be myCamera (if in normal mode) // or could be viewFrustumOffsetCamera if in offset mode //--------------------------------------------- + + // I changed the ordering here - roll is FIRST (JJV) + glRotatef ( whichCamera.getRoll(), 0, 0, 1 ); glRotatef ( whichCamera.getPitch(), 1, 0, 0 ); glRotatef ( whichCamera.getYaw(), 0, 1, 0 ); - glRotatef ( whichCamera.getRoll(), 0, 0, 1 ); glTranslatef( -whichCamera.getPosition().x, -whichCamera.getPosition().y, -whichCamera.getPosition().z ); if (::starsOn) { From 0ff88b882bb6e6dfe6da45f8d4eefbffcf6e9b4a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Apr 2013 14:06:48 -0700 Subject: [PATCH 35/51] tweaks to default Camera near clip, and camera positions in interface --- interface/src/Camera.cpp | 4 ++-- interface/src/main.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index a718c8a137..f14d397e41 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -17,8 +17,8 @@ Camera::Camera() _mode = CAMERA_MODE_THIRD_PERSON; _tightness = DEFAULT_CAMERA_TIGHTNESS; _fieldOfView = 60.0; // default - _nearClip = 0.1; // default - _farClip = 50.0; // default + _nearClip = 0.01; // default + _farClip = 50.0; // default _yaw = 0.0; _pitch = 0.0; _roll = 0.0; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index a5a354eca5..3e9e0639ef 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -713,12 +713,12 @@ void display(void) //----------------------------------------------- // set the camera to looking at my own face //----------------------------------------------- - myCamera.setTargetPosition ( myAvatar.getBodyPosition() ); + myCamera.setTargetPosition ( myAvatar.getBodyPosition() ); // XXXBHG - Shouldn't we use Head position here? myCamera.setYaw ( - myAvatar.getBodyYaw() ); myCamera.setPitch ( 0.0 ); myCamera.setRoll ( 0.0 ); - myCamera.setUp ( 0.53 ); - myCamera.setDistance ( 0.03 ); + myCamera.setUp ( 0.6 ); + myCamera.setDistance ( 0.3 ); myCamera.setTightness ( 100.0f ); myCamera.update ( 1.f/FPS ); } else { @@ -729,8 +729,8 @@ void display(void) myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() ); myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju myCamera.setRoll ( 0.0 ); - myCamera.setUp ( 0.45 ); - myCamera.setDistance ( 0.5 ); + myCamera.setUp ( 0.45); + myCamera.setDistance ( 1.0 ); myCamera.setTightness ( 10.0f ); myCamera.update ( 1.f/FPS ); } From 2f5d5398b2dc16df6b9b39cc895da14572849a09 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Apr 2013 14:39:23 -0700 Subject: [PATCH 36/51] comment cleanup in Camera.cpp --- interface/src/Camera.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index a718c8a137..aa3f0b70c1 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -9,9 +9,6 @@ #include "Camera.h" - - -//------------------------ Camera::Camera() { _mode = CAMERA_MODE_THIRD_PERSON; @@ -30,15 +27,11 @@ Camera::Camera() _orientation.setToIdentity(); } - - - -//------------------------------------ void Camera::update( float deltaTime ) { float radian = ( _yaw / 180.0 ) * PIE; - //these need to be checked to make sure they correspond to the cordinate system. + // these need to be checked to make sure they correspond to the cordinate system. float x = _distance * -sin( radian ); float z = _distance * cos( radian ); float y = _up; @@ -52,9 +45,7 @@ void Camera::update( float deltaTime ) _position += ( _idealPosition - _position ) * t; - //------------------------------------------------------------------------- - //geterate the ortho-normals for the orientation based on the Euler angles - //------------------------------------------------------------------------ + // geterate the ortho-normals for the orientation based on the Euler angles _orientation.setToIdentity(); _orientation.yaw ( _yaw ); _orientation.pitch ( _pitch ); From edfb1501f1386a6c5eeda5499a19a465c93cadba Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Apr 2013 15:41:38 -0700 Subject: [PATCH 37/51] fixed merge problem with shifted avatar --- interface/src/Camera.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 08cf7cb713..a74aace71e 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -45,13 +45,8 @@ void Camera::update( float deltaTime ) } _position += ( _idealPosition - _position ) * t; - _yaw += ( _idealYaw - _yaw ) * t; - //roll = 20.0; - - //------------------------------------------------------------------------- // generate the ortho-normals for the orientation based on the Euler angles - //------------------------------------------------------------------------- _orientation.setToIdentity(); _orientation.yaw ( _yaw ); _orientation.pitch ( _pitch ); From 4f5ddb3700fa0d372c65a1343334e6c697aba20f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Apr 2013 15:46:20 -0700 Subject: [PATCH 38/51] fixed yaw/ideal yaw problem correctly --- interface/src/Camera.cpp | 1 + interface/src/Camera.h | 15 +-------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index a74aace71e..6ea15bab0a 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -45,6 +45,7 @@ void Camera::update( float deltaTime ) } _position += ( _idealPosition - _position ) * t; + _yaw += ( _idealYaw - _yaw ) * t; // generate the ortho-normals for the orientation based on the Euler angles _orientation.setToIdentity(); diff --git a/interface/src/Camera.h b/interface/src/Camera.h index c76d6d2e43..354a5d8d16 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -29,21 +29,8 @@ public: void update( float deltaTime ); - /* - void setMode ( CameraMode m ) { mode = m; } - void setYaw ( float y ) { idealYaw = y; } - void setPitch ( float p ) { pitch = p; } - void setRoll ( float r ) { roll = r; } - void setUp ( float u ) { up = u; } - void setDistance ( float d ) { distance = d; } - void setTargetPosition ( glm::vec3 t ) { targetPosition = t; } - void setPosition ( glm::vec3 p ) { position = p; } - void setTightness ( float t ) { tightness = t; } - void setOrientation ( Orientation o ) { orientation.set(o); } -*/ - void setMode ( CameraMode m ) { _mode = m; } - void setYaw ( float y ) { _yaw = y; } + void setYaw ( float y ) { _idealYaw = y; } void setPitch ( float p ) { _pitch = p; } void setRoll ( float r ) { _roll = r; } void setUp ( float u ) { _up = u; } From fc5d412e535c0cc846348af8ebd9d7e4ba6d9dc9 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 16 Apr 2013 15:51:22 -0700 Subject: [PATCH 39/51] fixed idealYaw issue --- interface/src/Camera.cpp | 2 +- interface/src/Camera.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 08cf7cb713..e44369fe66 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -46,7 +46,7 @@ void Camera::update( float deltaTime ) _position += ( _idealPosition - _position ) * t; _yaw += ( _idealYaw - _yaw ) * t; - + //roll = 20.0; //------------------------------------------------------------------------- diff --git a/interface/src/Camera.h b/interface/src/Camera.h index c76d6d2e43..acda583213 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -43,7 +43,7 @@ public: */ void setMode ( CameraMode m ) { _mode = m; } - void setYaw ( float y ) { _yaw = y; } + void setYaw ( float y ) { _idealYaw = y; } void setPitch ( float p ) { _pitch = p; } void setRoll ( float r ) { _roll = r; } void setUp ( float u ) { _up = u; } From d0a83f3c0e2de373293d2f62ae4d6e95f78c65b6 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Apr 2013 18:09:27 -0700 Subject: [PATCH 40/51] correct the number of bytes per agent from avatar mixer --- interface/src/main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 7a992e8dcc..05ab585e12 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1310,7 +1310,10 @@ void *networkReceive(void *args) voxels.parseData(incomingPacket, bytesReceived); break; case PACKET_HEADER_BULK_AVATAR_DATA: - AgentList::getInstance()->processBulkAgentData(&senderAddress, incomingPacket, bytesReceived, sizeof(float) * 11); + AgentList::getInstance()->processBulkAgentData(&senderAddress, + incomingPacket, + bytesReceived, + (sizeof(float) * 3) + (sizeof(uint16_t) * 2)); break; default: AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived); From f766843b7ab9f01965a82239557359c6bedb719c Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 16 Apr 2013 18:27:19 -0700 Subject: [PATCH 41/51] adjusted the ordering of porcessed in camera update method --- interface/src/Camera.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index bafda75515..ef7943d8f3 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -9,8 +9,7 @@ #include "Camera.h" -Camera::Camera() -{ +Camera::Camera() { _mode = CAMERA_MODE_THIRD_PERSON; _tightness = DEFAULT_CAMERA_TIGHTNESS; _fieldOfView = 60.0; // default @@ -28,26 +27,40 @@ Camera::Camera() _orientation.setToIdentity(); } -void Camera::update( float deltaTime ) + + +void Camera::update( float deltaTime ) { + //---------------------------------------- + // derive t from tightness + //---------------------------------------- + float t = _tightness * deltaTime; + + if ( t > 1.0 ){ + t = 1.0; + } + + //---------------------------------------- + // update _yaw (before position!) + //---------------------------------------- + _yaw += ( _idealYaw - _yaw ) * t; float radian = ( _yaw / 180.0 ) * PIE; + //---------------------------------------- + // update _position + //---------------------------------------- //these need to be checked to make sure they correspond to the coordinate system. double x = _distance * -sin( radian ); double z = _distance * cos( radian ); double y = _up; _idealPosition = _targetPosition + glm::vec3( x, y, z ); - float t = _tightness * deltaTime; - - if ( t > 1.0 ){ - t = 1.0; - } _position += ( _idealPosition - _position ) * t; - _yaw += ( _idealYaw - _yaw ) * t; + //------------------------------------------------------------------------------ // generate the ortho-normals for the orientation based on the Euler angles + //------------------------------------------------------------------------------ _orientation.setToIdentity(); _orientation.yaw ( _yaw ); _orientation.pitch ( _pitch ); From e825764304dbf6fd8c612f842a4f94b0f08d7a82 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 16 Apr 2013 19:53:48 -0700 Subject: [PATCH 42/51] added instrumentation to Orientation class to test for normalized and orthogonal vectors --- libraries/avatars/src/Orientation.cpp | 81 +++++++++++++++++++++++++++ libraries/avatars/src/Orientation.h | 3 + libraries/shared/src/SharedUtil.h | 28 ++++----- 3 files changed, 98 insertions(+), 14 deletions(-) diff --git a/libraries/avatars/src/Orientation.cpp b/libraries/avatars/src/Orientation.cpp index ed1500a506..ed4af46d25 100755 --- a/libraries/avatars/src/Orientation.cpp +++ b/libraries/avatars/src/Orientation.cpp @@ -8,6 +8,9 @@ #include "Orientation.h" #include + +static bool testingForNormalizationAndOrthogonality = false; + Orientation::Orientation() { right = glm::vec3( 1.0, 0.0, 0.0 ); up = glm::vec3( 0.0, 1.0, 0.0 ); @@ -41,6 +44,8 @@ void Orientation::yaw( float angle ) { front = cosineFront + sineRight; right = cosineRight - sineFront; + + if ( testingForNormalizationAndOrthogonality ) { testForOrthogonalAndNormalizedVectors( EPSILON ); } } @@ -56,6 +61,8 @@ void Orientation::pitch( float angle ) { up = cosineUp + sineFront; front = cosineFront - sineUp; + + if ( testingForNormalizationAndOrthogonality ) { testForOrthogonalAndNormalizedVectors( EPSILON ); } } @@ -71,6 +78,8 @@ void Orientation::roll( float angle ) { up = cosineUp + sineRight; right = cosineRight - sineUp; + + if ( testingForNormalizationAndOrthogonality ) { testForOrthogonalAndNormalizedVectors( EPSILON ); } } @@ -79,3 +88,75 @@ void Orientation::setRightUpFront( const glm::vec3 &r, const glm::vec3 &u, const up = u; front = f; } + + + +//---------------------------------------------------------------------- +void Orientation::testForOrthogonalAndNormalizedVectors( float epsilon ) { + + //---------------------------------------------------------------- + // make sure vectors are normalized (or close to length 1) + //---------------------------------------------------------------- + float rightLength = glm::length( right ); + float upLength = glm::length( up ); + float frontLength = glm::length( front ); + + if (( rightLength > 1.0f + epsilon ) + || ( rightLength < 1.0f - epsilon )) { + printf( "Error in Orientation class: right direction length is %f \n", rightLength ); + } + assert ( rightLength > 1.0f - epsilon ); + assert ( rightLength < 1.0f + epsilon ); + + + if (( upLength > 1.0f + epsilon ) + || ( upLength < 1.0f - epsilon )) { + printf( "Error in Orientation class: up direction length is %f \n", upLength ); + } + assert ( upLength > 1.0f - epsilon ); + assert ( upLength < 1.0f + epsilon ); + + + if (( frontLength > 1.0f + epsilon ) + || ( frontLength < 1.0f - epsilon )) { + printf( "Error in Orientation class: front direction length is %f \n", frontLength ); + } + assert ( frontLength > 1.0f - epsilon ); + assert ( frontLength < 1.0f + epsilon ); + + + + //---------------------------------------------------------------- + // make sure vectors are orthoginal (or close enough) + //---------------------------------------------------------------- + glm::vec3 rightCross = glm::cross( up, front ); + glm::vec3 upCross = glm::cross( front, right ); + glm::vec3 frontCross = glm::cross( right, up ); + + float rightDiff = glm::length( rightCross - right ); + float upDiff = glm::length( upCross - up ); + float frontDiff = glm::length( frontCross - front ); + + + if ( rightDiff > epsilon ) { + printf( "Error in Orientation class: right direction not orthogonal to up and/or front. " ); + printf( "The tested cross of up and front is off by %f \n", rightDiff ); + } + assert ( rightDiff < epsilon ); + + + if ( upDiff > epsilon ) { + printf( "Error in Orientation class: up direction not orthogonal to front and/or right. " ); + printf( "The tested cross of front and right is off by %f \n", upDiff ); + } + assert ( upDiff < epsilon ); + + + if ( frontDiff > epsilon ) { + printf( "Error in Orientation class: front direction not orthogonal to right and/or up. " ); + printf( "The tested cross of right and up is off by %f \n", frontDiff ); + } + assert ( frontDiff < epsilon ); +} + + diff --git a/libraries/avatars/src/Orientation.h b/libraries/avatars/src/Orientation.h index ae209a5f47..e088f40517 100755 --- a/libraries/avatars/src/Orientation.h +++ b/libraries/avatars/src/Orientation.h @@ -39,6 +39,9 @@ public: glm::vec3 getFront() { return front; } void setRightUpFront( const glm::vec3 &, const glm::vec3 &, const glm::vec3 & ); + +private: + void testForOrthogonalAndNormalizedVectors( float epsilon ); }; diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index 6941c74462..f7e639ba43 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -18,20 +18,20 @@ #include #endif -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; -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 float METER = 1.0; -static const float DECIMETER = 0.1; -static const float CENTIMETER = 0.01; -static const float MILLIIMETER = 0.001; +static const float ZERO = 0.0f; +static const float ONE = 1.0f; +static const float ONE_HALF = 0.5f; +static const float ONE_THIRD = 0.333333f; +static const float PIE = 3.141592f; +static const float PI_TIMES_TWO = 3.141592f * 2.0f; +static const float PI_OVER_180 = 3.141592f / 180.0f; +static const float EPSILON = 0.000001f; //smallish positive number - used as margin of error for some computations +static const float SQUARE_ROOT_OF_2 = (float)sqrt(2); +static const float SQUARE_ROOT_OF_3 = (float)sqrt(3); +static const float METER = 1.0f; +static const float DECIMETER = 0.1f; +static const float CENTIMETER = 0.01f; +static const float MILLIIMETER = 0.001f; double usecTimestamp(timeval *time); double usecTimestampNow(); From 7a239fc7f02570faf526a3872f5c123e9e1536e9 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Apr 2013 20:25:08 -0700 Subject: [PATCH 43/51] Small tweaks to initial values for offset camera, so people can make sense of it --- interface/src/Camera.cpp | 2 +- interface/src/main.cpp | 28 ++++++++++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index ef7943d8f3..320acca51d 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -13,7 +13,7 @@ Camera::Camera() { _mode = CAMERA_MODE_THIRD_PERSON; _tightness = DEFAULT_CAMERA_TIGHTNESS; _fieldOfView = 60.0; // default - _nearClip = 0.01; // default + _nearClip = 0.08; // default _farClip = 50.0; // default _yaw = 0.0; _pitch = 0.0; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 05ab585e12..df0707518a 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -520,12 +520,12 @@ int frustumDrawingMode = FRUSTUM_DRAW_MODE_ALL; // the mode we're drawing the bool frustumOn = false; // Whether or not to display the debug view frustum bool cameraFrustum = true; // which frustum to look at -bool viewFrustumFromOffset=false; // Wether or not to offset the view of the frustum -float viewFrustumOffsetYaw = -90.0; // the following variables control yaw, pitch, roll and distance form regular -float viewFrustumOffsetPitch = 7.5; // camera to the offset camera -float viewFrustumOffsetRoll = 0.0; -float viewFrustumOffsetDistance = 0.0; -float viewFrustumOffsetUp = 0.0; +bool viewFrustumFromOffset =false; // Wether or not to offset the view of the frustum +float viewFrustumOffsetYaw = -135.0; // the following variables control yaw, pitch, roll and distance form regular +float viewFrustumOffsetPitch = 0.0; // camera to the offset camera +float viewFrustumOffsetRoll = 0.0; +float viewFrustumOffsetDistance = 25.0; +float viewFrustumOffsetUp = 0.0; void render_view_frustum() { @@ -747,24 +747,20 @@ void display(void) Camera viewFrustumOffsetCamera = myCamera; if (::viewFrustumFromOffset && ::frustumOn) { - //---------------------------------------------------- + // set the camera to third-person view but offset so we can see the frustum - //---------------------------------------------------- - viewFrustumOffsetCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw ); - viewFrustumOffsetCamera.setPitch ( 0.0 + ::viewFrustumOffsetPitch ); - viewFrustumOffsetCamera.setRoll ( 0.0 + ::viewFrustumOffsetRoll ); - viewFrustumOffsetCamera.setUp ( 0.2 + ::viewFrustumOffsetUp ); - viewFrustumOffsetCamera.setDistance ( 0.5 + ::viewFrustumOffsetDistance ); + viewFrustumOffsetCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw ); + viewFrustumOffsetCamera.setPitch ( ::viewFrustumOffsetPitch ); + viewFrustumOffsetCamera.setRoll ( ::viewFrustumOffsetRoll ); + viewFrustumOffsetCamera.setUp ( ::viewFrustumOffsetUp ); + viewFrustumOffsetCamera.setDistance ( ::viewFrustumOffsetDistance ); viewFrustumOffsetCamera.update(1.f/FPS); whichCamera = viewFrustumOffsetCamera; } - //--------------------------------------------- // transform view according to whichCamera // could be myCamera (if in normal mode) // or could be viewFrustumOffsetCamera if in offset mode - //--------------------------------------------- - // I changed the ordering here - roll is FIRST (JJV) glRotatef ( whichCamera.getRoll(), 0, 0, 1 ); glRotatef ( whichCamera.getPitch(), 1, 0, 0 ); From 1fb8d0b26841d538678ff406c40fdbd4fad86c5c Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 16 Apr 2013 20:35:50 -0700 Subject: [PATCH 44/51] consolidated some code in Head.cpp --- interface/src/Head.cpp | 72 +++++++++++++++++++++++---- interface/src/Head.h | 23 ++++++--- libraries/avatars/src/Orientation.cpp | 8 +-- 3 files changed, 82 insertions(+), 21 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 97b50bfc3e..6869cd659d 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -48,6 +48,26 @@ unsigned int iris_texture_height = 256; Head::Head() { initializeAvatar(); + + avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 ); + avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); + avatar.orientation.setToIdentity(); + + closestOtherAvatar = 0; + + _bodyYaw = -90.0; + _bodyPitch = 0.0; + _bodyRoll = 0.0; + + bodyYawDelta = 0.0; + + triggeringAction = false; + + mode = AVATAR_MODE_STANDING; + + initializeSkeleton(); + + for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = false; PupilSize = 0.10; @@ -121,6 +141,25 @@ Head::Head() { Head::Head(const Head &otherHead) { initializeAvatar(); + + avatar.velocity = otherHead.avatar.velocity; + avatar.thrust = otherHead.avatar.thrust; + avatar.orientation.set( otherHead.avatar.orientation ); + + closestOtherAvatar = otherHead.closestOtherAvatar; + + _bodyYaw = otherHead._bodyYaw; + _bodyPitch = otherHead._bodyPitch; + _bodyRoll = otherHead._bodyRoll; + + bodyYawDelta = otherHead.bodyYawDelta; + + triggeringAction = otherHead.triggeringAction; + + mode = otherHead.mode; + + initializeSkeleton(); + for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = otherHead.driveKeys[i]; @@ -298,14 +337,14 @@ void Head::simulate(float deltaTime) { //------------------------ // update avatar skeleton //------------------------ - updateAvatarSkeleton(); + updateSkeleton(); //------------------------------------------------------------------------ // reset hand and elbow position according to hand movement //------------------------------------------------------------------------ if ( handBeingMoved ){ if (! previousHandBeingMoved ){ - initializeAvatarSprings(); + initializeBodySprings(); usingSprings = true; //printf( "just started moving hand\n" ); } @@ -319,7 +358,7 @@ void Head::simulate(float deltaTime) { if ( handBeingMoved ) { updateHandMovement(); - updateAvatarSprings( deltaTime ); + updateBodySprings( deltaTime ); } previousHandBeingMoved = handBeingMoved; @@ -508,6 +547,8 @@ void Head::simulate(float deltaTime) { void Head::render(int faceToFace, int isMine) { + +/* //--------------------------------------------------- // show avatar position //--------------------------------------------------- @@ -516,7 +557,8 @@ void Head::render(int faceToFace, int isMine) { glScalef( 0.03, 0.03, 0.03 ); glutSolidSphere( 1, 10, 10 ); glPopMatrix(); - +*/ + //--------------------------------------------------- // show avatar orientation //--------------------------------------------------- @@ -768,6 +810,7 @@ AvatarMode Head::getMode() { void Head::initializeAvatar() { +/* avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 ); avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); avatar.orientation.setToIdentity(); @@ -783,7 +826,16 @@ void Head::initializeAvatar() { triggeringAction = false; mode = AVATAR_MODE_STANDING; - + + initializeSkeleton(); + */ +} + + + + +void Head::initializeSkeleton() { + for (int b=0; b -static bool testingForNormalizationAndOrthogonality = false; +static bool testingForNormalizationAndOrthogonality = true; Orientation::Orientation() { right = glm::vec3( 1.0, 0.0, 0.0 ); @@ -94,9 +94,9 @@ void Orientation::setRightUpFront( const glm::vec3 &r, const glm::vec3 &u, const //---------------------------------------------------------------------- void Orientation::testForOrthogonalAndNormalizedVectors( float epsilon ) { - //---------------------------------------------------------------- - // make sure vectors are normalized (or close to length 1) - //---------------------------------------------------------------- + //------------------------------------------------------------------ + // make sure vectors are normalized (or close enough to length 1.0) + //------------------------------------------------------------------ float rightLength = glm::length( right ); float upLength = glm::length( up ); float frontLength = glm::length( front ); From bd7c4273c3fa693e5eb3ec17ae14beb1259e39c8 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 16 Apr 2013 22:47:04 -0700 Subject: [PATCH 45/51] tested camera orthonormals --- interface/src/Camera.cpp | 3 +++ interface/src/main.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 320acca51d..d557e2050c 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -62,8 +62,11 @@ void Camera::update( float deltaTime ) // generate the ortho-normals for the orientation based on the Euler angles //------------------------------------------------------------------------------ _orientation.setToIdentity(); + _orientation.yaw ( _yaw ); _orientation.pitch ( _pitch ); _orientation.roll ( _roll ); + + //printf( "orientation.front = %f, %f, %f\n", _orientation.front.x, _orientation.front.y, _orientation.front.z ); } diff --git a/interface/src/main.cpp b/interface/src/main.cpp index df0707518a..5a9c3cf858 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -727,7 +727,7 @@ void display(void) //---------------------------------------------------- myCamera.setTargetPosition ( myAvatar.getBodyPosition() ); myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() ); - myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju + myCamera.setPitch ( 10.0 ); // temporarily, this must be 0.0 or else bad juju myCamera.setRoll ( 0.0 ); myCamera.setUp ( 0.45); myCamera.setDistance ( 1.0 ); From a6f82e12367e264e3c0bbaba8a2febc0ebf36ad7 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 16 Apr 2013 23:39:43 -0700 Subject: [PATCH 46/51] moved renderOrientstionDiretions to Utils --- interface/src/Head.cpp | 11 +++++++---- interface/src/Head.h | 4 ++-- interface/src/Util.cpp | 28 ++++++++++++++++++++++++++++ interface/src/Util.h | 6 +++++- interface/src/main.cpp | 7 +++++++ 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 6869cd659d..658e749eed 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -602,7 +602,9 @@ void Head::render(int faceToFace, int isMine) { } - + +//this has been moved to Utils.cpp +/* void Head::renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ) { glm::vec3 pRight = position + orientation.right * size; glm::vec3 pUp = position + orientation.up * size; @@ -610,22 +612,23 @@ void Head::renderOrientationDirections( glm::vec3 position, Orientation orientat glColor3f( 1.0f, 0.0f, 0.0f ); glBegin( GL_LINE_STRIP ); - glVertex3f( bone[ AVATAR_BONE_HEAD ].position.x, bone[ AVATAR_BONE_HEAD ].position.y, bone[ AVATAR_BONE_HEAD ].position.z ); + glVertex3f( position.x, position.y, position.z ); glVertex3f( pRight.x, pRight.y, pRight.z ); glEnd(); glColor3f( 0.0f, 1.0f, 0.0f ); glBegin( GL_LINE_STRIP ); - glVertex3f( bone[ AVATAR_BONE_HEAD ].position.x, bone[ AVATAR_BONE_HEAD ].position.y, bone[ AVATAR_BONE_HEAD ].position.z ); + glVertex3f( position.x, position.y, position.z ); glVertex3f( pUp.x, pUp.y, pUp.z ); glEnd(); glColor3f( 0.0f, 0.0f, 1.0f ); glBegin( GL_LINE_STRIP ); - glVertex3f( bone[ AVATAR_BONE_HEAD ].position.x, bone[ AVATAR_BONE_HEAD ].position.y, bone[ AVATAR_BONE_HEAD ].position.z ); + glVertex3f( position.x, position.y, position.z ); glVertex3f( pFront.x, pFront.y, pFront.z ); glEnd(); } +*/ diff --git a/interface/src/Head.h b/interface/src/Head.h index 8e28bb67ab..d3e1ab1bc8 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -12,7 +12,7 @@ #include #include -#include // added by Ventrella as a utility +#include #include "Field.h" #include "world.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 renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ); void simulate(float); diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index f9dc085793..03edf6c6e5 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -16,6 +16,7 @@ #include "world.h" #include "Util.h" + // Return the azimuth angle in degrees between two points. float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos) { return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf; @@ -202,3 +203,30 @@ void drawGroundPlaneGrid( float size, int resolution ) } +void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ) { + glm::vec3 pRight = position + orientation.right * size; + glm::vec3 pUp = position + orientation.up * size; + glm::vec3 pFront = position + orientation.front * size; + + glColor3f( 1.0f, 0.0f, 0.0f ); + glBegin( GL_LINE_STRIP ); + glVertex3f( position.x, position.y, position.z ); + glVertex3f( pRight.x, pRight.y, pRight.z ); + glEnd(); + + glColor3f( 0.0f, 1.0f, 0.0f ); + glBegin( GL_LINE_STRIP ); + glVertex3f( position.x, position.y, position.z ); + glVertex3f( pUp.x, pUp.y, pUp.z ); + glEnd(); + + glColor3f( 0.0f, 0.0f, 1.0f ); + glBegin( GL_LINE_STRIP ); + glVertex3f( position.x, position.y, position.z ); + glVertex3f( pFront.x, pFront.y, pFront.z ); + glEnd(); +} + + + + diff --git a/interface/src/Util.h b/interface/src/Util.h index 13b2810092..4ba9de5e70 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -17,6 +17,9 @@ #include +#include + + 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); @@ -30,7 +33,8 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl float r=1.0, float g=1.0, float b=1.0); double diffclock(timeval *clock1,timeval *clock2); - void drawGroundPlaneGrid( float size, int resolution ); +void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ); + #endif diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 5a9c3cf858..41c253ccd3 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -769,6 +769,13 @@ void display(void) + + //quick test for camera ortho-normal sanity check... + + + + + if (::starsOn) { // should be the first rendering pass - w/o depth buffer / lighting stars.render(fov); From 184d28e9051c24e24a3c2279436726f371cf84d9 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 17 Apr 2013 00:42:49 -0700 Subject: [PATCH 47/51] Adding testOrientationClass() to run unit tests on the orientation class. --- interface/src/Util.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++ interface/src/Util.h | 35 ++++++++++++++++++ interface/src/main.cpp | 4 ++- 3 files changed, 119 insertions(+), 1 deletion(-) diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 03edf6c6e5..5c41318ec0 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -227,6 +227,87 @@ void renderOrientationDirections( glm::vec3 position, Orientation orientation, f glEnd(); } +void testOrientationClass() { + printf("\n----------\ntestOrientationClass()\n----------\n\n"); + + oTestCase tests[] = { + // - inputs ------------, outputs -------------------- ------------------- ---------------------------- + // -- front -------------------, -- up -------------, -- right ------------------- + // ( yaw , pitch, roll , front.x , front.y , front.z , up.x , up.y , up.z , right.x , right.y , right.z ) + + // simple yaw tests + oTestCase( 0.f , 0.f , 0.f , 0.f , 0.f , 1.0f , 0.f , 1.0f , 0.f , -1.0f , 0.f , 0.f ), + oTestCase( 90.0f, 0.f , 0.f , 1.0f , 0.f , 0.f , 0.f , 1.0f , 0.f , 0.0f , 0.f , 1.0f ), + oTestCase(180.0f, 0.f , 0.f , 0.f , 0.f , -1.0f , 0.f , 1.0f , 0.f , 1.0f , 0.f , 0.f ), + oTestCase(270.0f, 0.f , 0.f , -1.0f , 0.f , 0.f , 0.f , 1.0f , 0.f , 0.0f , 0.f , -1.0f ), + + // simple pitch tests + oTestCase( 0.f ,90.f , 0.f , 0.f , 1.0f , 0.0f , 0.f , 0.0f , -1.0f, -1.0f , 0.f , 0.f ), + + }; + + int failedCount = 0; + int totalTests = sizeof(tests)/sizeof(oTestCase); + + for (int i=0; i < totalTests; i++) { + + bool passed = true; // I'm an optimist! + + float yaw = tests[i].yaw; + float pitch = tests[i].pitch; + float roll = tests[i].roll; + + Orientation o1; + o1.setToIdentity(); + o1.yaw(yaw); + o1.pitch(pitch); + o1.roll(roll); + + glm::vec3 front = o1.getFront(); + glm::vec3 up = o1.getUp(); + glm::vec3 right = o1.getRight(); + + printf("\n-----\nTest: %d - yaw=%f , pitch=%f , roll=%f \n\n",i+1,yaw,pitch,roll); + + printf(" +front.x=%f, front.y=%f, front.z=%f\n",front.x,front.y,front.z); + if (front.x == tests[i].frontX && front.y == tests[i].frontY && front.z == tests[i].frontZ) { + printf(" front vector PASSES!\n"); + } else { + printf(" front vector FAILED! expected: \n"); + printf(" front.x=%f, front.y=%f, front.z=%f\n",tests[i].frontX,tests[i].frontY,tests[i].frontZ); + passed = false; + } + + printf(" +up.x=%f, up.y=%f, up.z=%f\n",up.x,up.y,up.z); + if (up.x == tests[i].upX && up.y == tests[i].upY && up.z == tests[i].upZ) { + printf(" up vector PASSES!\n"); + } else { + printf(" up vector FAILED! expected: \n"); + printf(" up.x=%f, up.y=%f, up.z=%f\n",tests[i].upX,tests[i].upY,tests[i].upZ); + passed = false; + } + + + printf(" +right.x=%f, right.y=%f, right.z=%f\n",right.x,right.y,right.z); + if (right.x == tests[i].rightX && right.y == tests[i].rightY && right.z == tests[i].rightZ) { + printf(" right vector PASSES!\n"); + } else { + printf(" right vector FAILED! expected: \n"); + printf(" right.x=%f, right.y=%f, right.z=%f\n",tests[i].rightX,tests[i].rightY,tests[i].rightZ); + passed = false; + } + + if (!passed) { + printf("\n-----\nTest: %d - FAILED! \n----------\n\n",i+1); + failedCount++; + } + } + printf("\n-----\nTotal Failed: %d out of %d \n----------\n\n",failedCount,totalTests); + printf("\n----------DONE----------\n\n"); +} + + + diff --git a/interface/src/Util.h b/interface/src/Util.h index 4ba9de5e70..f2adc918be 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -37,4 +37,39 @@ void drawGroundPlaneGrid( float size, int resolution ); void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ); + +class oTestCase { +public: + float yaw; + float pitch; + float roll; + + float frontX; + float frontY; + float frontZ; + + float upX; + float upY; + float upZ; + + float rightX; + float rightY; + float rightZ; + + oTestCase( + float yaw, float pitch, float roll, + float frontX, float frontY, float frontZ, + float upX, float upY, float upZ, + float rightX, float rightY, float rightZ + ) : + yaw(yaw),pitch(pitch),roll(roll), + frontX(frontX),frontY(frontY),frontZ(frontZ), + upX(upX),upY(upY),upZ(upZ), + rightX(rightX),rightY(rightY),rightZ(rightZ) + {}; +}; + + +void testOrientationClass(); + #endif diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 41c253ccd3..851408b55e 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1511,6 +1511,9 @@ void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) { int main(int argc, const char * argv[]) { + // Quick test of the Orientation class on startup! + testOrientationClass(); + AgentList::createInstance(AGENT_TYPE_INTERFACE); gettimeofday(&applicationStartupTime, NULL); @@ -1605,4 +1608,3 @@ int main(int argc, const char * argv[]) ::terminate(); return EXIT_SUCCESS; } - From 0768785cfd5ac5180adfb7011f628439d4588484 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 17 Apr 2013 11:01:08 -0700 Subject: [PATCH 48/51] fix mutex movement when resizing AgentList vector --- libraries/shared/src/Agent.cpp | 16 ++++++++++++---- libraries/shared/src/Agent.h | 25 ++++++++++++------------- libraries/shared/src/AgentList.cpp | 2 +- voxel-server/src/main.cpp | 8 ++++---- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/libraries/shared/src/Agent.cpp b/libraries/shared/src/Agent.cpp index 8c14d9a617..1ac676e916 100644 --- a/libraries/shared/src/Agent.cpp +++ b/libraries/shared/src/Agent.cpp @@ -19,8 +19,6 @@ #include #endif -Agent::Agent() {} - Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, uint16_t thisAgentId) { publicSocket = new sockaddr; memcpy(publicSocket, agentPublicSocket, sizeof(sockaddr)); @@ -37,7 +35,8 @@ Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agent activeSocket = NULL; linkedData = NULL; - pthread_mutex_init(&deleteMutex, NULL); + deleteMutex = new pthread_mutex_t; + pthread_mutex_init(deleteMutex, NULL); } Agent::Agent(const Agent &otherAgent) { @@ -67,25 +66,34 @@ Agent::Agent(const Agent &otherAgent) { linkedData = NULL; } - pthread_mutex_init(&deleteMutex, NULL); + deleteMutex = new pthread_mutex_t; + pthread_mutex_init(deleteMutex, NULL); } Agent& Agent::operator=(Agent otherAgent) { + std::cout << "Agent swap constructor called on resize?\n"; swap(*this, otherAgent); return *this; } void Agent::swap(Agent &first, Agent &second) { using std::swap; + swap(first.publicSocket, second.publicSocket); swap(first.localSocket, second.localSocket); swap(first.activeSocket, second.activeSocket); swap(first.type, second.type); swap(first.linkedData, second.linkedData); swap(first.agentId, second.agentId); + swap(first.firstRecvTimeUsecs, second.firstRecvTimeUsecs); + swap(first.lastRecvTimeUsecs, second.lastRecvTimeUsecs); + swap(first.deleteMutex, second.deleteMutex); } Agent::~Agent() { + // the deleteMutex isn't destroyed here + // that's handled by the agent list silent agent removal thread + delete publicSocket; delete localSocket; delete linkedData; diff --git a/libraries/shared/src/Agent.h b/libraries/shared/src/Agent.h index bc6a6eb714..13d3326e57 100644 --- a/libraries/shared/src/Agent.h +++ b/libraries/shared/src/Agent.h @@ -19,17 +19,8 @@ #include #endif -class Agent { - void swap(Agent &first, Agent &second); - sockaddr *publicSocket, *localSocket, *activeSocket; - char type; - uint16_t agentId; - double firstRecvTimeUsecs; - double lastRecvTimeUsecs; - AgentData *linkedData; - -public: - Agent(); +class Agent { +public: Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, uint16_t thisAgentId); Agent(const Agent &otherAgent); ~Agent(); @@ -38,7 +29,7 @@ public: bool matches(sockaddr *otherPublicSocket, sockaddr *otherLocalSocket, char otherAgentType); - pthread_mutex_t deleteMutex; + pthread_mutex_t *deleteMutex; char getType() const; const char* getTypeName() const; @@ -59,7 +50,15 @@ public: AgentData* getLinkedData(); void setLinkedData(AgentData *newData); - friend std::ostream& operator<<(std::ostream& os, const Agent* agent); + friend std::ostream& operator<<(std::ostream& os, const Agent* agent); +private: + void swap(Agent &first, Agent &second); + sockaddr *publicSocket, *localSocket, *activeSocket; + char type; + uint16_t agentId; + double firstRecvTimeUsecs; + double lastRecvTimeUsecs; + AgentData *linkedData; }; std::ostream& operator<<(std::ostream& os, const Agent* agent); diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 2751527d37..33716ec9f1 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -331,7 +331,7 @@ void *removeSilentAgents(void *args) { for(std::vector::iterator agent = agents->begin(); agent != agents->end();) { - pthread_mutex_t * agentDeleteMutex = &agent->deleteMutex; + pthread_mutex_t* agentDeleteMutex = agent->deleteMutex; if ((checkTimeUSecs - agent->getLastRecvTimeUsecs()) > AGENT_SILENCE_THRESHOLD_USECS && agent->getType() != AGENT_TYPE_VOXEL diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 70a743b9c0..8f6bab7dc7 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -129,7 +129,7 @@ void eraseVoxelTreeAndCleanupAgentVisitData() { // lock this agent's delete mutex so that the delete thread doesn't // kill the agent while we are working with it - pthread_mutex_lock(&thisAgent->deleteMutex); + pthread_mutex_lock(thisAgent->deleteMutex); // clean up the agent visit data delete agentData->rootMarkerNode; @@ -137,7 +137,7 @@ void eraseVoxelTreeAndCleanupAgentVisitData() { // unlock the delete mutex so the other thread can // kill the agent if it has dissapeared - pthread_mutex_unlock(&thisAgent->deleteMutex); + pthread_mutex_unlock(thisAgent->deleteMutex); } } @@ -167,7 +167,7 @@ void *distributeVoxelsToListeners(void *args) { // lock this agent's delete mutex so that the delete thread doesn't // kill the agent while we are working with it - pthread_mutex_lock(&thisAgent->deleteMutex); + pthread_mutex_lock(thisAgent->deleteMutex); stopOctal = NULL; packetCount = 0; @@ -207,7 +207,7 @@ void *distributeVoxelsToListeners(void *args) { // unlock the delete mutex so the other thread can // kill the agent if it has dissapeared - pthread_mutex_unlock(&thisAgent->deleteMutex); + pthread_mutex_unlock(thisAgent->deleteMutex); } // dynamically sleep until we need to fire off the next set of voxels From 53796d067f77578839dc8185090761aae5927292 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 17 Apr 2013 11:11:05 -0700 Subject: [PATCH 49/51] changed Ori constructor to include setIdentity --- libraries/avatars/src/Orientation.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/avatars/src/Orientation.cpp b/libraries/avatars/src/Orientation.cpp index cd19b2aac0..8eeb3dd0ff 100755 --- a/libraries/avatars/src/Orientation.cpp +++ b/libraries/avatars/src/Orientation.cpp @@ -12,9 +12,7 @@ static bool testingForNormalizationAndOrthogonality = true; Orientation::Orientation() { - right = glm::vec3( 1.0, 0.0, 0.0 ); - up = glm::vec3( 0.0, 1.0, 0.0 ); - front = glm::vec3( 0.0, 0.0, 1.0 ); + setToIdentity(); } From 3cee28f0efabbeed186ea57732129ceb73436f7b Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 17 Apr 2013 11:23:47 -0700 Subject: [PATCH 50/51] added back the av position --- interface/src/Head.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 658e749eed..4f77e6fafe 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -548,7 +548,6 @@ void Head::simulate(float deltaTime) { void Head::render(int faceToFace, int isMine) { -/* //--------------------------------------------------- // show avatar position //--------------------------------------------------- @@ -557,7 +556,6 @@ void Head::render(int faceToFace, int isMine) { glScalef( 0.03, 0.03, 0.03 ); glutSolidSphere( 1, 10, 10 ); glPopMatrix(); -*/ //--------------------------------------------------- // show avatar orientation From e9592c45c744b1da105adaa81cfa09d57c74b966 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 17 Apr 2013 11:56:32 -0700 Subject: [PATCH 51/51] fix reference to resources directory on OS X --- interface/src/Audio.cpp | 4 ++-- interface/src/Head.cpp | 2 +- libraries/shared/src/SharedUtil.cpp | 3 ++- libraries/shared/src/SharedUtil.h | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 578e1368c8..997361a378 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -444,8 +444,8 @@ Audio::Audio(Oscilloscope *s, Head *linkedHead) // read the walking sound from the raw file and store it // in the in memory array - switchToResourcesIfRequired(); - FILE *soundFile = fopen("audio/walking.raw", "r"); + switchToResourcesParentIfRequired(); + FILE *soundFile = fopen("resources/audio/walking.raw", "r"); // get length of file: std::fseek(soundFile, 0, SEEK_END); diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 658e749eed..7a310b8171 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -114,7 +114,7 @@ Head::Head() { springVelocityDecay = 16.0f; if (iris_texture.size() == 0) { - switchToResourcesIfRequired(); + switchToResourcesParentIfRequired(); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); if (error != 0) { std::cout << "error " << error << ": " << lodepng_error_text(error) << std::endl; diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index 8fb8645730..97c9b047be 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -74,7 +74,7 @@ bool oneAtBit(unsigned char byte, int bitIndex) { return (byte >> (7 - bitIndex) & 1); } -void switchToResourcesIfRequired() { +void switchToResourcesParentIfRequired() { #ifdef __APPLE__ CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); @@ -85,6 +85,7 @@ void switchToResourcesIfRequired() { CFRelease(resourcesURL); chdir(path); + chdir(".."); #endif } diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index f7e639ba43..e70229637a 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -47,7 +47,7 @@ void printVoxelCode(unsigned char* voxelCode); int numberOfOnes(unsigned char byte); bool oneAtBit(unsigned char byte, int bitIndex); -void switchToResourcesIfRequired(); +void switchToResourcesParentIfRequired(); const char* getCmdOption(int argc, const char * argv[],const char* option); bool cmdOptionExists(int argc, const char * argv[],const char* option);