preparation for extending the avatar ball array to accommodate more touch capabilities

This commit is contained in:
Jeffrey Ventrella 2013-06-03 11:53:00 -07:00
parent cf67f28b57
commit 8d031b5c2d
5 changed files with 77 additions and 50 deletions

View file

@ -289,22 +289,22 @@ void Application::paintGL() {
if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
_myCamera.setTightness (100.0f);
_myCamera.setTargetPosition(_myAvatar.getSpringyHeadPosition());
_myCamera.setTargetPosition(_myAvatar.getBallPosition(AVATAR_JOINT_HEAD_BASE));
_myCamera.setTargetRotation(_myAvatar.getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
} else if (OculusManager::isConnected()) {
_myCamera.setUpShift (0.0f);
_myCamera.setDistance (0.0f);
_myCamera.setTightness (100.0f);
_myCamera.setTargetPosition(_myAvatar.getHeadPosition());
_myCamera.setTargetPosition(_myAvatar.getHeadJointPosition());
_myCamera.setTargetRotation(_myAvatar.getHead().getOrientation());
} else if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
_myCamera.setTargetPosition(_myAvatar.getSpringyHeadPosition());
_myCamera.setTargetPosition(_myAvatar.getBallPosition(AVATAR_JOINT_HEAD_BASE));
_myCamera.setTargetRotation(_myAvatar.getHead().getWorldAlignedOrientation());
} else if (_myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
_myCamera.setTargetPosition(_myAvatar.getHeadPosition());
_myCamera.setTargetPosition(_myAvatar.getHeadJointPosition());
_myCamera.setTargetRotation(_myAvatar.getHead().getWorldAlignedOrientation());
}
@ -1556,7 +1556,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {
if (_cameraFrustum->isChecked()) {
position = camera.getPosition();
} else {
position = _myAvatar.getHeadPosition();
position = _myAvatar.getHeadJointPosition();
}
float fov = camera.getFieldOfView();

View file

@ -143,7 +143,7 @@ int audioCallback (const void* inputBuffer,
unsigned char *currentPacketPtr = dataPacket + 1;
// memcpy the three float positions
memcpy(currentPacketPtr, &interfaceAvatar->getHeadPosition(), sizeof(float) * 3);
memcpy(currentPacketPtr, &interfaceAvatar->getHeadJointPosition(), sizeof(float) * 3);
currentPacketPtr += (sizeof(float) * 3);
// tell the mixer not to add additional attenuation to our source

View file

@ -118,16 +118,18 @@ Avatar::Avatar(Agent* owningAgent) :
void Avatar::initializeBodyBalls() {
for (int b=0; b<NUM_AVATAR_JOINTS; b++) {
_bodyBall[b].isCollidable = true;
for (int b=0; b<NUM_AVATAR_BODY_BALLS; b++) {
_bodyBall[b].parent = AVATAR_JOINT_NULL;
_bodyBall[b].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[b].position = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[b].velocity = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[b].radius = 0.0;
_bodyBall[b].touchForce = 0.0;
_bodyBall[b].isCollidable = true;
_bodyBall[b].jointTightness = BODY_SPRING_DEFAULT_TIGHTNESS;
}
// specify the radii of the joints
// specify the radii of the balls
_bodyBall[ AVATAR_JOINT_PELVIS ].radius = 0.07;
_bodyBall[ AVATAR_JOINT_TORSO ].radius = 0.065;
_bodyBall[ AVATAR_JOINT_CHEST ].radius = 0.08;
@ -500,7 +502,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
void Avatar::checkForMouseRayTouching() {
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) {
glm::vec3 directionToBodySphere = glm::normalize(_bodyBall[b].position - _mouseRayOrigin);
float dot = glm::dot(directionToBodySphere, _mouseRayDirection);
@ -657,25 +659,22 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
void Avatar::updateCollisionWithSphere(glm::vec3 position, float radius, float deltaTime) {
float myBodyApproximateBoundingRadius = 1.0f;
glm::vec3 vectorFromMyBodyToBigSphere(_position - position);
bool jointCollision = false;
float distanceToBigSphere = glm::length(vectorFromMyBodyToBigSphere);
if (distanceToBigSphere < myBodyApproximateBoundingRadius + radius) {
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) {
glm::vec3 vectorFromJointToBigSphereCenter(_bodyBall[b].position - position);
float distanceToBigSphereCenter = glm::length(vectorFromJointToBigSphereCenter);
float combinedRadius = _bodyBall[b].radius + radius;
if (distanceToBigSphereCenter < combinedRadius) {
jointCollision = true;
if (distanceToBigSphereCenter > 0.0) {
glm::vec3 directionVector = vectorFromJointToBigSphereCenter / distanceToBigSphereCenter;
float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius);
glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration;
_bodyBall[b].velocity += collisionForce * 0.0f * deltaTime;
_velocity += collisionForce * 40.0f * deltaTime;
_velocity += collisionForce * 40.0f * deltaTime;
_bodyBall[b].position = position + directionVector * combinedRadius;
}
}
@ -760,11 +759,11 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime
glm::vec3 bodyPushForce = glm::vec3(0.0f, 0.0f, 0.0f);
// loop through the joints of each avatar to check for every possible collision
for (int b=1; b<NUM_AVATAR_JOINTS; b++) {
// loop through the body balls of each avatar to check for every possible collision
for (int b=1; b<NUM_AVATAR_BODY_BALLS; b++) {
if (_bodyBall[b].isCollidable) {
for (int o=b+1; o<NUM_AVATAR_JOINTS; o++) {
for (int o=b+1; o<NUM_AVATAR_BODY_BALLS; o++) {
if (otherAvatar->_bodyBall[o].isCollidable) {
glm::vec3 vectorBetweenJoints(_bodyBall[b].position - otherAvatar->_bodyBall[o].position);
@ -893,8 +892,8 @@ void Avatar::render(bool lookingInMirror) {
}
void Avatar::resetBodyBalls() {
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
_bodyBall[b].position = _skeleton.joint[b].position;
for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) {
_bodyBall[b].position = _skeleton.joint[b].position; // put balls on joints
_bodyBall[b].velocity = glm::vec3(0.0f, 0.0f, 0.0f);
}
}
@ -905,7 +904,7 @@ void Avatar::updateBodyBalls(float deltaTime) {
if (glm::length(_position - _bodyBall[AVATAR_JOINT_PELVIS].position) > BEYOND_BODY_SPRING_RANGE) {
resetBodyBalls();
}
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) {
glm::vec3 springVector(_bodyBall[b].position);
if (_skeleton.joint[b].parent == AVATAR_JOINT_NULL) {
@ -942,8 +941,8 @@ void Avatar::updateBodyBalls(float deltaTime) {
/*
//apply forces from touch...
if (_skeleton.joint[b].touchForce > 0.0) {
_skeleton.joint[b].springyVelocity += _mouseRayDirection * _skeleton.joint[b].touchForce * 0.7f;
if (_bodyBall[b].touchForce > 0.0) {
_bodyBall[b].velocity += _mouseRayDirection * _bodyBall[b].touchForce * 0.7f;
}
*/
@ -1010,8 +1009,8 @@ void Avatar::renderBody(bool lookingInMirror) {
const float RENDER_TRANSLUCENT_BEYOND = 0.5f;
// Render the body as balls and cones
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
float distanceToCamera = glm::length(_cameraPosition - _skeleton.joint[b].position);
for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) {
float distanceToCamera = glm::length(_cameraPosition - _bodyBall[b].position);
float alpha = lookingInMirror ? 1.0f : glm::clamp((distanceToCamera - RENDER_TRANSLUCENT_BEYOND) /
(RENDER_OPAQUE_BEYOND - RENDER_TRANSLUCENT_BEYOND), 0.f, 1.f);
@ -1029,7 +1028,7 @@ void Avatar::renderBody(bool lookingInMirror) {
|| b == AVATAR_JOINT_RIGHT_ELBOW
|| b == AVATAR_JOINT_RIGHT_WRIST
|| b == AVATAR_JOINT_RIGHT_FINGERTIPS ) {
// Render the sphere at the joint
// Render the body ball sphere
if (_owningAgent || b == AVATAR_JOINT_RIGHT_ELBOW
|| b == AVATAR_JOINT_RIGHT_WRIST
|| b == AVATAR_JOINT_RIGHT_FINGERTIPS ) {
@ -1051,7 +1050,7 @@ void Avatar::renderBody(bool lookingInMirror) {
glPopMatrix();
}
// Render the cone connecting this joint to its parent
// Render the cone connecting this ball to its parent
if (_skeleton.joint[b].parent != AVATAR_JOINT_NULL) {
if ((b != AVATAR_JOINT_HEAD_TOP )
&& (b != AVATAR_JOINT_HEAD_BASE )

View file

@ -20,6 +20,37 @@
#include "Skeleton.h"
#include "Transmitter.h"
enum AvatarBodyBallID
{
BODY_BALL_NULL = -1,
BODY_BALL_PELVIS,
BODY_BALL_TORSO,
BODY_BALL_CHEST,
BODY_BALL_NECK_BASE,
BODY_BALL_HEAD_BASE,
BODY_BALL_HEAD_TOP,
BODY_BALL_LEFT_COLLAR,
BODY_BALL_LEFT_SHOULDER,
BODY_BALL_LEFT_ELBOW,
BODY_BALL_LEFT_WRIST,
BODY_BALL_LEFT_FINGERTIPS,
BODY_BALL_RIGHT_COLLAR,
BODY_BALL_RIGHT_SHOULDER,
BODY_BALL_RIGHT_ELBOW,
BODY_BALL_RIGHT_WRIST,
BODY_BALL_RIGHT_FINGERTIPS,
BODY_BALL_LEFT_HIP,
BODY_BALL_LEFT_KNEE,
BODY_BALL_LEFT_HEEL,
BODY_BALL_LEFT_TOES,
BODY_BALL_RIGHT_HIP,
BODY_BALL_RIGHT_KNEE,
BODY_BALL_RIGHT_HEEL,
BODY_BALL_RIGHT_TOES,
NUM_AVATAR_BODY_BALLS
};
enum DriveKeys
{
FWD = 0,
@ -64,19 +95,14 @@ public:
void setOrientation (const glm::quat& orientation);
//getters
float getHeadYawRate () const { return _head.yawRate;}
float getBodyYaw () const { return _bodyYaw;}
bool getIsNearInteractingOther() const { return _avatarTouch.getAbleToReachOtherAvatar();}
const glm::vec3& getHeadPosition () const { return _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].position;}
const glm::vec3& getSpringyHeadPosition () const { return _bodyBall[ AVATAR_JOINT_HEAD_BASE ].position;}
const glm::vec3& getJointPosition (AvatarJointID j) const { return _bodyBall[j].position;}
glm::vec3 getBodyRightDirection () const { return getOrientation() * AVATAR_RIGHT; }
glm::vec3 getBodyUpDirection () const { return getOrientation() * AVATAR_UP; }
glm::vec3 getBodyFrontDirection () const { return getOrientation() * AVATAR_FRONT; }
float getHeadYawRate () const { return _head.yawRate;}
float getBodyYaw () const { return _bodyYaw;}
bool getIsNearInteractingOther () const { return _avatarTouch.getAbleToReachOtherAvatar();}
const glm::vec3& getHeadJointPosition () const { return _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].position;}
const glm::vec3& getBallPosition (AvatarJointID j) const { return _bodyBall[j].position;}
glm::vec3 getBodyRightDirection () const { return getOrientation() * AVATAR_RIGHT; }
glm::vec3 getBodyUpDirection () const { return getOrientation() * AVATAR_UP; }
glm::vec3 getBodyFrontDirection () const { return getOrientation() * AVATAR_FRONT; }
const glm::vec3& getVelocity () const { return _velocity;}
float getSpeed () const { return _speed;}
float getHeight () const { return _height;}
@ -106,12 +132,14 @@ private:
struct AvatarBall
{
glm::vec3 position;
glm::vec3 velocity;
float jointTightness;
float radius;
bool isCollidable;
float touchForce;
AvatarJointID parent;
glm::vec3 parentOffset;
glm::vec3 position;
glm::vec3 velocity;
float jointTightness;
float radius;
bool isCollidable;
float touchForce;
};
Head _head;
@ -124,7 +152,7 @@ private:
float _bodyRollDelta;
glm::vec3 _movedHandOffset;
glm::quat _rotation; // the rotation of the avatar body as a whole expressed as a quaternion
AvatarBall _bodyBall[ NUM_AVATAR_JOINTS ];
AvatarBall _bodyBall[ NUM_AVATAR_BODY_BALLS ];
AvatarMode _mode;
glm::vec3 _cameraPosition;
glm::vec3 _handHoldingPosition;

View file

@ -60,9 +60,9 @@ public:
{
AvatarJointID parent; // which joint is this joint connected to?
glm::vec3 position; // the position at the "end" of the joint - in global space
glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose"
glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the default pose
glm::quat rotation; // the parent-relative rotation (orientation) of the joint as a quaternion
float length; // the length of vector connecting the joint and its parent
float length; // the length of vector between the joint and its parent
};
AvatarJoint joint[ NUM_AVATAR_JOINTS ];