From 81b311f75385f0b0a597174c35ad983b9b23e0ff Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 9 Apr 2013 18:41:01 -0700 Subject: [PATCH 1/2] added a method to ask the avatar for it's head lookat vector --- interface/src/Head.cpp | 64 ++++++++++++++++++++---------------------- interface/src/Head.h | 1 + 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 3e7512a8b7..d06f35cc39 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -272,7 +272,7 @@ void Head::setLeanSideways(float dist){ -// Simulate the head over time +// Simulate the avatar over time //--------------------------------------------------- void Head::simulate(float deltaTime) { @@ -293,64 +293,50 @@ void Head::simulate(float deltaTime) thrust = glm::vec3(0); */ - const float THRUST_MAG = 10.0; - const float THRUST_LATERAL_MAG = 10.0; - const float THRUST_VERTICAL_MAG = 10.0; + const float THRUST_MAG = 10.0; + const float YAW_MAG = 300.0; avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); - + + //notice that the z values from avatar.orientation are flipped to accommodate different coordinate system if (driveKeys[FWD]) { - avatar.thrust.x += avatar.orientation.getFront().getX() * THRUST_MAG; - avatar.thrust.y += avatar.orientation.getFront().getY() * THRUST_MAG; - avatar.thrust.z -= avatar.orientation.getFront().getZ() * THRUST_MAG; - //thrust += THRUST_MAG*forward; + glm::vec3 front( avatar.orientation.getFront().getX(), avatar.orientation.getFront().getY(), -avatar.orientation.getFront().getZ() ); + avatar.thrust += front * THRUST_MAG; } if (driveKeys[BACK]) { - avatar.thrust.x -= avatar.orientation.getFront().getX() * THRUST_MAG; - avatar.thrust.y -= avatar.orientation.getFront().getY() * THRUST_MAG; - avatar.thrust.z += avatar.orientation.getFront().getZ() * THRUST_MAG; - //thrust += -THRUST_MAG*forward; + glm::vec3 front( avatar.orientation.getFront().getX(), avatar.orientation.getFront().getY(), -avatar.orientation.getFront().getZ() ); + avatar.thrust -= front * THRUST_MAG; } if (driveKeys[RIGHT]) { - avatar.thrust.x += avatar.orientation.getRight().getX() * THRUST_LATERAL_MAG; - avatar.thrust.y += avatar.orientation.getRight().getY() * THRUST_LATERAL_MAG; - avatar.thrust.z -= avatar.orientation.getRight().getZ() * THRUST_LATERAL_MAG; - //thrust.x += forward.z*-THRUST_LATERAL_MAG; - //thrust.z += forward.x*THRUST_LATERAL_MAG; + glm::vec3 right( avatar.orientation.getRight().getX(), avatar.orientation.getRight().getY(), -avatar.orientation.getRight().getZ() ); + avatar.thrust += right * THRUST_MAG; } if (driveKeys[LEFT]) { - avatar.thrust.x -= avatar.orientation.getRight().getX() * THRUST_LATERAL_MAG; - avatar.thrust.y -= avatar.orientation.getRight().getY() * THRUST_LATERAL_MAG; - avatar.thrust.z += avatar.orientation.getRight().getZ() * THRUST_LATERAL_MAG; - //thrust.x += forward.z*THRUST_LATERAL_MAG; - //thrust.z += forward.x*-THRUST_LATERAL_MAG; + glm::vec3 right( avatar.orientation.getRight().getX(), avatar.orientation.getRight().getY(), -avatar.orientation.getRight().getZ() ); + avatar.thrust -= right * THRUST_MAG; } if (driveKeys[UP]) { - avatar.thrust.x -= avatar.orientation.getUp().getX() * THRUST_VERTICAL_MAG; - avatar.thrust.y -= avatar.orientation.getUp().getY() * THRUST_VERTICAL_MAG; - avatar.thrust.z += avatar.orientation.getUp().getZ() * THRUST_VERTICAL_MAG; - //thrust.y += -THRUST_VERTICAL_MAG; + glm::vec3 up( avatar.orientation.getUp().getX(), avatar.orientation.getUp().getY(), -avatar.orientation.getUp().getZ() ); + avatar.thrust += up * THRUST_MAG; } if (driveKeys[DOWN]) { - avatar.thrust.x += avatar.orientation.getUp().getX() * THRUST_VERTICAL_MAG; - avatar.thrust.y += avatar.orientation.getUp().getY() * THRUST_VERTICAL_MAG; - avatar.thrust.z -= avatar.orientation.getUp().getZ() * THRUST_VERTICAL_MAG; - //thrust.y += THRUST_VERTICAL_MAG; + glm::vec3 up( avatar.orientation.getUp().getX(), avatar.orientation.getUp().getY(), -avatar.orientation.getUp().getZ() ); + avatar.thrust -= up * THRUST_MAG; } if (driveKeys[ROT_RIGHT]) { - avatar.yawDelta -= 300.0 * deltaTime; + avatar.yawDelta -= YAW_MAG * deltaTime; } if (driveKeys[ROT_LEFT]) { - avatar.yawDelta += 300.0 * deltaTime; + avatar.yawDelta += YAW_MAG * deltaTime; } avatar.yaw += avatar.yawDelta * deltaTime; @@ -910,6 +896,18 @@ float Head::getAvatarYaw() } +//------------------------------------------- +glm::vec3 Head::getAvatarHeadLookatDirection() +{ + return glm::vec3 + ( + avatar.bone[ AVATAR_BONE_HEAD ].worldOrientation.getFront().x, + avatar.bone[ AVATAR_BONE_HEAD ].worldOrientation.getFront().y, + avatar.bone[ AVATAR_BONE_HEAD ].worldOrientation.getFront().z + ); +} + + //------------------------------- void Head::updateHandMovement() diff --git a/interface/src/Head.h b/interface/src/Head.h index 964d44ece4..f8008ae857 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -158,6 +158,7 @@ class Head : public AgentData { float getLastMeasuredYaw() {return YawRate;} float getAvatarYaw(); + glm::vec3 getAvatarHeadLookatDirection(); void render(int faceToFace, int isMine); From 1b833fb4a9d2daa2e8adf80d5847913b7af8e61a Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 9 Apr 2013 21:14:24 -0700 Subject: [PATCH 2/2] added grid plane to aid in testing avatar navigation --- interface/src/Head.h | 18 ++++++------ interface/src/main.cpp | 65 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 69 insertions(+), 14 deletions(-) diff --git a/interface/src/Head.h b/interface/src/Head.h index f8008ae857..bf8318ef61 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -103,15 +103,15 @@ enum AvatarBones struct AvatarBone { - AvatarBones parent; - glm::vec3 worldPosition; - glm::vec3 defaultPosePosition; - glm::dvec3 velocity; - float yaw; - float pitch; - float roll; - Orientation worldOrientation; - float length; + AvatarBones parent; // which bone is this bone connected to? + glm::vec3 worldPosition; // the position at the "end" of the bone + glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose" + glm::dvec3 velocity; // pertains to spring physics + 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 worldOrientation; // three orthogonal normals determined by yaw, pitch, roll + float length; // the length of the bone }; struct Avatar diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 2fed06120d..52b6df6c68 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -109,6 +109,8 @@ int starsTiles = 20; double starsLod = 1.0; #endif +bool showingVoxels = false; + glm::vec3 box(WORLD_SIZE,WORLD_SIZE,WORLD_SIZE); ParticleSystem balls(0, box, @@ -569,8 +571,42 @@ int render_test_direction = 1; +void drawGroundPlaneGrid( float size, int resolution ) +{ + + glColor3f( 0.4f, 0.5f, 0.3f ); + glLineWidth(2.0); + + float gridSize = 10.0; + int gridResolution = 10; + + for (int g=0; g