From a4011934c6e9e7976f6376429e2f95f36d00706e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 15:39:23 -0700 Subject: [PATCH] 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();