mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 11:53:28 +02:00
Merge pull request #1340 from PhilipRosedale/remove_avatar_balls
Remove avatar balls
This commit is contained in:
commit
91d6ef633d
13 changed files with 31 additions and 1307 deletions
|
@ -1415,10 +1415,7 @@ void Application::processAvatarURLsMessage(unsigned char* packetData, size_t dat
|
|||
QDataStream in(QByteArray((char*)packetData, dataBytes));
|
||||
QUrl voxelURL;
|
||||
in >> voxelURL;
|
||||
|
||||
// invoke the set URL functions on the simulate/render thread
|
||||
QMetaObject::invokeMethod(avatar->getVoxels(), "setVoxelURL", Q_ARG(QUrl, voxelURL));
|
||||
|
||||
|
||||
// use this timing to as the data-server for an updated mesh for this avatar (if we have UUID)
|
||||
DataServerClient::getValuesForKeysAndUUID(QStringList() << DataServerKey::FaceMeshURL << DataServerKey::SkeletonURL,
|
||||
avatar->getUUID());
|
||||
|
@ -1793,9 +1790,6 @@ void Application::init() {
|
|||
_voxels.setDisableFastVoxelPipeline(false);
|
||||
_voxels.init();
|
||||
|
||||
|
||||
Avatar::sendAvatarURLsMessage(_myAvatar.getVoxels()->getVoxelURL());
|
||||
|
||||
_palette.init(_glWidget->width(), _glWidget->height());
|
||||
_palette.addAction(Menu::getInstance()->getActionForOption(MenuOption::VoxelAddMode), 0, 0);
|
||||
_palette.addAction(Menu::getInstance()->getActionForOption(MenuOption::VoxelDeleteMode), 0, 1);
|
||||
|
@ -2330,20 +2324,6 @@ void Application::updateTransmitter(float deltaTime) {
|
|||
if (_voxels.findRayIntersection(_transmitterPickStart, direction, detail, distance, face)) {
|
||||
minDistance = min(minDistance, distance);
|
||||
}
|
||||
NodeList* nodeList = NodeList::getInstance();
|
||||
for(NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
|
||||
node->lock();
|
||||
if (node->getLinkedData() != NULL) {
|
||||
Avatar *avatar = (Avatar*)node->getLinkedData();
|
||||
if (!avatar->isInitialized()) {
|
||||
avatar->init();
|
||||
}
|
||||
if (avatar->findRayIntersection(_transmitterPickStart, direction, distance)) {
|
||||
minDistance = min(minDistance, distance);
|
||||
}
|
||||
}
|
||||
node->unlock();
|
||||
}
|
||||
_transmitterPickEnd = _transmitterPickStart + direction * minDistance;
|
||||
|
||||
} else {
|
||||
|
@ -2573,12 +2553,6 @@ void Application::updateAvatar(float deltaTime) {
|
|||
controlledBroadcastToNodes(broadcastString, endOfBroadcastStringWrite - broadcastString,
|
||||
nodeTypesOfInterest, sizeof(nodeTypesOfInterest));
|
||||
|
||||
// once in a while, send my urls
|
||||
const float AVATAR_URLS_SEND_INTERVAL = 1.0f; // seconds
|
||||
if (shouldDo(AVATAR_URLS_SEND_INTERVAL, deltaTime)) {
|
||||
Avatar::sendAvatarURLsMessage(_myAvatar.getVoxels()->getVoxelURL());
|
||||
}
|
||||
|
||||
// Update _viewFrustum with latest camera and view frustum data...
|
||||
// NOTE: we get this from the view frustum, to make it simpler, since the
|
||||
// loadViewFrumstum() method will get the correct details from the camera
|
||||
|
|
|
@ -317,15 +317,8 @@ Menu::Menu() :
|
|||
QMenu* avatarOptionsMenu = developerMenu->addMenu("Avatar Options");
|
||||
|
||||
addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::Avatars, 0, true);
|
||||
addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::AvatarAsBalls);
|
||||
addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::CollisionProxies);
|
||||
|
||||
addActionToQMenuAndActionHash(avatarOptionsMenu,
|
||||
MenuOption::VoxelMode,
|
||||
0,
|
||||
appInstance->getAvatar()->getVoxels(),
|
||||
SLOT(cycleMode()));
|
||||
|
||||
addActionToQMenuAndActionHash(avatarOptionsMenu,
|
||||
MenuOption::FaceMode,
|
||||
0,
|
||||
|
@ -781,11 +774,7 @@ void Menu::editPreferences() {
|
|||
|
||||
QFormLayout* form = new QFormLayout();
|
||||
layout->addLayout(form, 1);
|
||||
|
||||
QLineEdit* avatarURL = new QLineEdit(applicationInstance->getAvatar()->getVoxels()->getVoxelURL().toString());
|
||||
avatarURL->setMinimumWidth(QLINE_MINIMUM_WIDTH);
|
||||
form->addRow("Avatar URL:", avatarURL);
|
||||
|
||||
|
||||
QString faceURLString = applicationInstance->getProfile()->getFaceModelURL().toString();
|
||||
QLineEdit* faceURLEdit = new QLineEdit(faceURLString);
|
||||
faceURLEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH);
|
||||
|
@ -868,12 +857,7 @@ void Menu::editPreferences() {
|
|||
DataServerClient::putValueForKey(DataServerKey::SkeletonURL,
|
||||
skeletonModelURL.toString().toLocal8Bit().constData());
|
||||
}
|
||||
|
||||
QUrl avatarVoxelURL(avatarURL->text());
|
||||
applicationInstance->getAvatar()->getVoxels()->setVoxelURL(avatarVoxelURL);
|
||||
|
||||
Avatar::sendAvatarURLsMessage(avatarVoxelURL);
|
||||
|
||||
|
||||
applicationInstance->getAvatar()->getHead().setPupilDilation(pupilDilation->value() / (float)pupilDilation->maximum());
|
||||
|
||||
_maxVoxels = maxVoxels->value();
|
||||
|
|
|
@ -147,7 +147,6 @@ namespace MenuOption {
|
|||
const QString AboutApp = "About Interface";
|
||||
const QString AmbientOcclusion = "Ambient Occlusion";
|
||||
const QString Avatars = "Avatars";
|
||||
const QString AvatarAsBalls = "Avatar as Balls";
|
||||
const QString Atmosphere = "Atmosphere";
|
||||
const QString AutomaticallyAuditTree = "Automatically Audit Tree Stats";
|
||||
const QString Bandwidth = "Bandwidth Display";
|
||||
|
|
|
@ -60,7 +60,7 @@ const float SKIN_COLOR[] = {1.0, 0.84, 0.66};
|
|||
const float DARK_SKIN_COLOR[] = {0.9, 0.78, 0.63};
|
||||
const int NUM_BODY_CONE_SIDES = 9;
|
||||
const float chatMessageScale = 0.0015;
|
||||
const float chatMessageHeight = 0.20;
|
||||
const float chatMessageHeight = 0.4f;
|
||||
|
||||
void Avatar::sendAvatarURLsMessage(const QUrl& voxelURL) {
|
||||
QByteArray message;
|
||||
|
@ -96,7 +96,6 @@ Avatar::Avatar(Node* owningNode) :
|
|||
_mouseRayDirection(0.0f, 0.0f, 0.0f),
|
||||
_isCollisionsOn(true),
|
||||
_leadingAvatar(NULL),
|
||||
_voxels(this),
|
||||
_moving(false),
|
||||
_initialized(false),
|
||||
_handHoldingPosition(0.0f, 0.0f, 0.0f),
|
||||
|
@ -112,13 +111,11 @@ Avatar::Avatar(Node* owningNode) :
|
|||
|
||||
_skeleton.initialize();
|
||||
|
||||
initializeBodyBalls();
|
||||
|
||||
_height = _skeleton.getHeight() + _bodyBall[BODY_BALL_LEFT_HEEL].radius + _bodyBall[BODY_BALL_HEAD_BASE].radius;
|
||||
_height = _skeleton.getHeight();
|
||||
|
||||
_maxArmLength = _skeleton.getArmLength();
|
||||
_pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _bodyBall[BODY_BALL_LEFT_HEEL].radius;
|
||||
_pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _bodyBall[BODY_BALL_LEFT_HEEL].radius;
|
||||
_pelvisStandingHeight = _skeleton.getPelvisStandingHeight();
|
||||
_pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight();
|
||||
_pelvisToHeadLength = _skeleton.getPelvisToHeadLength();
|
||||
|
||||
if (BALLS_ON) {
|
||||
|
@ -129,126 +126,6 @@ Avatar::Avatar(Node* owningNode) :
|
|||
}
|
||||
|
||||
|
||||
void Avatar::initializeBodyBalls() {
|
||||
|
||||
_ballSpringsInitialized = false; //this gets set to true on the first update pass...
|
||||
|
||||
for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) {
|
||||
_bodyBall[b].parentJoint = 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 radius of each ball
|
||||
_bodyBall[BODY_BALL_PELVIS].radius = BODY_BALL_RADIUS_PELVIS;
|
||||
_bodyBall[BODY_BALL_TORSO].radius = BODY_BALL_RADIUS_TORSO;
|
||||
_bodyBall[BODY_BALL_CHEST].radius = BODY_BALL_RADIUS_CHEST;
|
||||
_bodyBall[BODY_BALL_NECK_BASE].radius = BODY_BALL_RADIUS_NECK_BASE;
|
||||
_bodyBall[BODY_BALL_HEAD_BASE].radius = BODY_BALL_RADIUS_HEAD_BASE;
|
||||
_bodyBall[BODY_BALL_LEFT_COLLAR].radius = BODY_BALL_RADIUS_LEFT_COLLAR;
|
||||
_bodyBall[BODY_BALL_LEFT_SHOULDER].radius = BODY_BALL_RADIUS_LEFT_SHOULDER;
|
||||
_bodyBall[BODY_BALL_LEFT_ELBOW].radius = BODY_BALL_RADIUS_LEFT_ELBOW;
|
||||
_bodyBall[BODY_BALL_LEFT_WRIST].radius = BODY_BALL_RADIUS_LEFT_WRIST;
|
||||
_bodyBall[BODY_BALL_LEFT_FINGERTIPS].radius = BODY_BALL_RADIUS_LEFT_FINGERTIPS;
|
||||
_bodyBall[BODY_BALL_RIGHT_COLLAR].radius = BODY_BALL_RADIUS_RIGHT_COLLAR;
|
||||
_bodyBall[BODY_BALL_RIGHT_SHOULDER].radius = BODY_BALL_RADIUS_RIGHT_SHOULDER;
|
||||
_bodyBall[BODY_BALL_RIGHT_ELBOW].radius = BODY_BALL_RADIUS_RIGHT_ELBOW;
|
||||
_bodyBall[BODY_BALL_RIGHT_WRIST].radius = BODY_BALL_RADIUS_RIGHT_WRIST;
|
||||
_bodyBall[BODY_BALL_RIGHT_FINGERTIPS].radius = BODY_BALL_RADIUS_RIGHT_FINGERTIPS;
|
||||
_bodyBall[BODY_BALL_LEFT_HIP].radius = BODY_BALL_RADIUS_LEFT_HIP;
|
||||
_bodyBall[BODY_BALL_LEFT_KNEE].radius = BODY_BALL_RADIUS_LEFT_KNEE;
|
||||
_bodyBall[BODY_BALL_LEFT_HEEL].radius = BODY_BALL_RADIUS_LEFT_HEEL;
|
||||
_bodyBall[BODY_BALL_LEFT_TOES].radius = BODY_BALL_RADIUS_LEFT_TOES;
|
||||
_bodyBall[BODY_BALL_RIGHT_HIP].radius = BODY_BALL_RADIUS_RIGHT_HIP;
|
||||
_bodyBall[BODY_BALL_RIGHT_KNEE].radius = BODY_BALL_RADIUS_RIGHT_KNEE;
|
||||
_bodyBall[BODY_BALL_RIGHT_HEEL].radius = BODY_BALL_RADIUS_RIGHT_HEEL;
|
||||
_bodyBall[BODY_BALL_RIGHT_TOES].radius = BODY_BALL_RADIUS_RIGHT_TOES;
|
||||
|
||||
|
||||
// specify the parent joint for each ball
|
||||
_bodyBall[BODY_BALL_PELVIS].parentJoint = AVATAR_JOINT_PELVIS;
|
||||
_bodyBall[BODY_BALL_TORSO].parentJoint = AVATAR_JOINT_TORSO;
|
||||
_bodyBall[BODY_BALL_CHEST].parentJoint = AVATAR_JOINT_CHEST;
|
||||
_bodyBall[BODY_BALL_NECK_BASE].parentJoint = AVATAR_JOINT_NECK_BASE;
|
||||
_bodyBall[BODY_BALL_HEAD_BASE].parentJoint = AVATAR_JOINT_HEAD_BASE;
|
||||
_bodyBall[BODY_BALL_HEAD_TOP].parentJoint = AVATAR_JOINT_HEAD_TOP;
|
||||
_bodyBall[BODY_BALL_LEFT_COLLAR].parentJoint = AVATAR_JOINT_LEFT_COLLAR;
|
||||
_bodyBall[BODY_BALL_LEFT_SHOULDER].parentJoint = AVATAR_JOINT_LEFT_SHOULDER;
|
||||
_bodyBall[BODY_BALL_LEFT_ELBOW].parentJoint = AVATAR_JOINT_LEFT_ELBOW;
|
||||
_bodyBall[BODY_BALL_LEFT_WRIST].parentJoint = AVATAR_JOINT_LEFT_WRIST;
|
||||
_bodyBall[BODY_BALL_LEFT_FINGERTIPS].parentJoint = AVATAR_JOINT_LEFT_FINGERTIPS;
|
||||
_bodyBall[BODY_BALL_RIGHT_COLLAR].parentJoint = AVATAR_JOINT_RIGHT_COLLAR;
|
||||
_bodyBall[BODY_BALL_RIGHT_SHOULDER].parentJoint = AVATAR_JOINT_RIGHT_SHOULDER;
|
||||
_bodyBall[BODY_BALL_RIGHT_ELBOW].parentJoint = AVATAR_JOINT_RIGHT_ELBOW;
|
||||
_bodyBall[BODY_BALL_RIGHT_WRIST].parentJoint = AVATAR_JOINT_RIGHT_WRIST;
|
||||
_bodyBall[BODY_BALL_RIGHT_FINGERTIPS].parentJoint = AVATAR_JOINT_RIGHT_FINGERTIPS;
|
||||
_bodyBall[BODY_BALL_LEFT_HIP].parentJoint = AVATAR_JOINT_LEFT_HIP;
|
||||
_bodyBall[BODY_BALL_LEFT_KNEE].parentJoint = AVATAR_JOINT_LEFT_KNEE;
|
||||
_bodyBall[BODY_BALL_LEFT_HEEL].parentJoint = AVATAR_JOINT_LEFT_HEEL;
|
||||
_bodyBall[BODY_BALL_LEFT_TOES].parentJoint = AVATAR_JOINT_LEFT_TOES;
|
||||
_bodyBall[BODY_BALL_RIGHT_HIP].parentJoint = AVATAR_JOINT_RIGHT_HIP;
|
||||
_bodyBall[BODY_BALL_RIGHT_KNEE].parentJoint = AVATAR_JOINT_RIGHT_KNEE;
|
||||
_bodyBall[BODY_BALL_RIGHT_HEEL].parentJoint = AVATAR_JOINT_RIGHT_HEEL;
|
||||
_bodyBall[BODY_BALL_RIGHT_TOES].parentJoint = AVATAR_JOINT_RIGHT_TOES;
|
||||
|
||||
// specify the parent offset for each ball
|
||||
_bodyBall[BODY_BALL_PELVIS].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_TORSO].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_CHEST].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_NECK_BASE].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_HEAD_BASE].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_HEAD_TOP].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_LEFT_COLLAR].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_LEFT_SHOULDER].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_LEFT_ELBOW].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_LEFT_WRIST].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_LEFT_FINGERTIPS].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_RIGHT_COLLAR].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_RIGHT_SHOULDER].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_RIGHT_ELBOW].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_RIGHT_WRIST].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_RIGHT_FINGERTIPS].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_LEFT_HIP].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_LEFT_KNEE].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_LEFT_HEEL].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_LEFT_TOES].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_RIGHT_HIP].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_RIGHT_KNEE].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_RIGHT_HEEL].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
_bodyBall[BODY_BALL_RIGHT_TOES].parentOffset = glm::vec3(0.0, 0.0, 0.0);
|
||||
|
||||
// specify the parent BALL for each ball
|
||||
_bodyBall[BODY_BALL_PELVIS].parentBall = BODY_BALL_NULL;
|
||||
_bodyBall[BODY_BALL_TORSO].parentBall = BODY_BALL_PELVIS;
|
||||
_bodyBall[BODY_BALL_CHEST].parentBall = BODY_BALL_TORSO;
|
||||
_bodyBall[BODY_BALL_NECK_BASE].parentBall = BODY_BALL_CHEST;
|
||||
_bodyBall[BODY_BALL_HEAD_BASE].parentBall = BODY_BALL_NECK_BASE;
|
||||
_bodyBall[BODY_BALL_HEAD_TOP].parentBall = BODY_BALL_HEAD_BASE;
|
||||
_bodyBall[BODY_BALL_LEFT_COLLAR].parentBall = BODY_BALL_CHEST;
|
||||
_bodyBall[BODY_BALL_LEFT_SHOULDER].parentBall = BODY_BALL_LEFT_COLLAR;
|
||||
_bodyBall[BODY_BALL_LEFT_ELBOW].parentBall = BODY_BALL_LEFT_SHOULDER;
|
||||
_bodyBall[BODY_BALL_LEFT_WRIST].parentBall = BODY_BALL_LEFT_ELBOW;
|
||||
_bodyBall[BODY_BALL_LEFT_FINGERTIPS].parentBall = BODY_BALL_LEFT_WRIST;
|
||||
_bodyBall[BODY_BALL_RIGHT_COLLAR].parentBall = BODY_BALL_CHEST;
|
||||
_bodyBall[BODY_BALL_RIGHT_SHOULDER].parentBall = BODY_BALL_RIGHT_COLLAR;
|
||||
_bodyBall[BODY_BALL_RIGHT_ELBOW].parentBall = BODY_BALL_RIGHT_SHOULDER;
|
||||
_bodyBall[BODY_BALL_RIGHT_WRIST].parentBall = BODY_BALL_RIGHT_ELBOW;
|
||||
_bodyBall[BODY_BALL_RIGHT_FINGERTIPS].parentBall = BODY_BALL_RIGHT_WRIST;
|
||||
_bodyBall[BODY_BALL_LEFT_HIP].parentBall = BODY_BALL_PELVIS;
|
||||
_bodyBall[BODY_BALL_LEFT_KNEE].parentBall = BODY_BALL_LEFT_HIP;
|
||||
_bodyBall[BODY_BALL_LEFT_HEEL].parentBall = BODY_BALL_LEFT_KNEE;
|
||||
_bodyBall[BODY_BALL_LEFT_TOES].parentBall = BODY_BALL_LEFT_HEEL;
|
||||
_bodyBall[BODY_BALL_RIGHT_HIP].parentBall = BODY_BALL_PELVIS;
|
||||
_bodyBall[BODY_BALL_RIGHT_KNEE].parentBall = BODY_BALL_RIGHT_HIP;
|
||||
_bodyBall[BODY_BALL_RIGHT_HEEL].parentBall = BODY_BALL_RIGHT_KNEE;
|
||||
_bodyBall[BODY_BALL_RIGHT_TOES].parentBall = BODY_BALL_RIGHT_HEEL;
|
||||
}
|
||||
|
||||
Avatar::~Avatar() {
|
||||
_headData = NULL;
|
||||
_handData = NULL;
|
||||
|
@ -264,7 +141,6 @@ void Avatar::init() {
|
|||
_head.init();
|
||||
_hand.init();
|
||||
_skeletonModel.init();
|
||||
_voxels.init();
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
|
@ -293,10 +169,6 @@ void Avatar::follow(Avatar* leadingAvatar) {
|
|||
|
||||
void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||
|
||||
glm::quat orientation = getOrientation();
|
||||
glm::vec3 front = orientation * IDENTITY_FRONT;
|
||||
glm::vec3 right = orientation * IDENTITY_RIGHT;
|
||||
|
||||
if (_leadingAvatar && !_leadingAvatar->getOwningNode()->isAlive()) {
|
||||
follow(NULL);
|
||||
}
|
||||
|
@ -336,23 +208,6 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
// update avatar skeleton
|
||||
_skeleton.update(deltaTime, getOrientation(), _position);
|
||||
|
||||
//determine the lengths of the body springs now that we have updated the skeleton at least once
|
||||
if (!_ballSpringsInitialized) {
|
||||
for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) {
|
||||
|
||||
glm::vec3 targetPosition
|
||||
= _skeleton.joint[_bodyBall[b].parentJoint].position
|
||||
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
|
||||
|
||||
glm::vec3 parentTargetPosition
|
||||
= _skeleton.joint[_bodyBall[b].parentJoint].position
|
||||
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
|
||||
|
||||
_bodyBall[b].springLength = glm::length(targetPosition - parentTargetPosition);
|
||||
}
|
||||
|
||||
_ballSpringsInitialized = true;
|
||||
}
|
||||
|
||||
// if this is not my avatar, then hand position comes from transmitted data
|
||||
_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handPosition;
|
||||
|
@ -360,42 +215,11 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
//update the movement of the hand and process handshaking with other avatars...
|
||||
updateHandMovementAndTouching(deltaTime, enableHandMovement);
|
||||
|
||||
// update body balls
|
||||
updateBodyBalls(deltaTime);
|
||||
|
||||
//apply the head lean values to the ball positions...
|
||||
if (USING_HEAD_LEAN) {
|
||||
if (fabs(_head.getLeanSideways() + _head.getLeanForward()) > 0.0f) {
|
||||
glm::vec3 headLean =
|
||||
right * _head.getLeanSideways() +
|
||||
front * _head.getLeanForward();
|
||||
|
||||
_bodyBall[BODY_BALL_TORSO].position += headLean * 0.1f;
|
||||
_bodyBall[BODY_BALL_CHEST].position += headLean * 0.4f;
|
||||
_bodyBall[BODY_BALL_NECK_BASE].position += headLean * 0.7f;
|
||||
_bodyBall[BODY_BALL_HEAD_BASE].position += headLean * 1.0f;
|
||||
|
||||
_bodyBall[BODY_BALL_LEFT_COLLAR].position += headLean * 0.6f;
|
||||
_bodyBall[BODY_BALL_LEFT_SHOULDER].position += headLean * 0.6f;
|
||||
_bodyBall[BODY_BALL_LEFT_ELBOW].position += headLean * 0.2f;
|
||||
_bodyBall[BODY_BALL_LEFT_WRIST].position += headLean * 0.1f;
|
||||
_bodyBall[BODY_BALL_LEFT_FINGERTIPS].position += headLean * 0.0f;
|
||||
|
||||
_bodyBall[BODY_BALL_RIGHT_COLLAR].position += headLean * 0.6f;
|
||||
_bodyBall[BODY_BALL_RIGHT_SHOULDER].position += headLean * 0.6f;
|
||||
_bodyBall[BODY_BALL_RIGHT_ELBOW].position += headLean * 0.2f;
|
||||
_bodyBall[BODY_BALL_RIGHT_WRIST].position += headLean * 0.1f;
|
||||
_bodyBall[BODY_BALL_RIGHT_FINGERTIPS].position += headLean * 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
_hand.simulate(deltaTime, false);
|
||||
_skeletonModel.simulate(deltaTime);
|
||||
_head.setBodyRotation(glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll));
|
||||
glm::vec3 headPosition;
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::AvatarAsBalls) || !_skeletonModel.getHeadPosition(headPosition)) {
|
||||
headPosition = _bodyBall[BODY_BALL_HEAD_BASE].position;
|
||||
}
|
||||
_skeletonModel.getHeadPosition(headPosition);
|
||||
_head.setPosition(headPosition);
|
||||
_head.setScale(_scale);
|
||||
_head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2]));
|
||||
|
@ -479,7 +303,7 @@ void Avatar::render(bool forceRenderHead) {
|
|||
}
|
||||
glPushMatrix();
|
||||
|
||||
glm::vec3 chatPosition = _bodyBall[BODY_BALL_HEAD_BASE].position + getBodyUpDirection() * chatMessageHeight * _scale;
|
||||
glm::vec3 chatPosition = getPosition() + getBodyUpDirection() * chatMessageHeight * _scale;
|
||||
glTranslatef(chatPosition.x, chatPosition.y, chatPosition.z);
|
||||
glm::quat chatRotation = Application::getInstance()->getCamera()->getRotation();
|
||||
glm::vec3 chatAxis = glm::axis(chatRotation);
|
||||
|
@ -514,90 +338,7 @@ void Avatar::render(bool forceRenderHead) {
|
|||
}
|
||||
}
|
||||
|
||||
void Avatar::resetBodyBalls() {
|
||||
for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) {
|
||||
|
||||
glm::vec3 targetPosition
|
||||
= _skeleton.joint[_bodyBall[b].parentJoint].position
|
||||
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
|
||||
|
||||
_bodyBall[b].position = targetPosition; // put ball on target position
|
||||
_bodyBall[b].velocity = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void Avatar::updateBodyBalls(float deltaTime) {
|
||||
// Check for a large repositioning, and re-initialize balls if this has happened
|
||||
const float BEYOND_BODY_SPRING_RANGE = _scale * 2.f;
|
||||
if (glm::length(_position - _bodyBall[BODY_BALL_PELVIS].position) > BEYOND_BODY_SPRING_RANGE) {
|
||||
resetBodyBalls();
|
||||
}
|
||||
glm::quat orientation = getOrientation();
|
||||
for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) {
|
||||
|
||||
glm::vec3 springVector;
|
||||
float length = 0.0f;
|
||||
if (_ballSpringsInitialized) {
|
||||
|
||||
// apply spring forces
|
||||
springVector = _bodyBall[b].position;
|
||||
|
||||
if (b == BODY_BALL_PELVIS) {
|
||||
springVector -= _position;
|
||||
} else {
|
||||
springVector -= _bodyBall[_bodyBall[b].parentBall].position;
|
||||
}
|
||||
|
||||
length = glm::length(springVector);
|
||||
|
||||
if (length > 0.0f) { // to avoid divide by zero
|
||||
glm::vec3 springDirection = springVector / length;
|
||||
|
||||
float force = (length - _skeleton.joint[b].length) * BODY_SPRING_FORCE * deltaTime;
|
||||
_bodyBall[b].velocity -= springDirection * force;
|
||||
|
||||
if (_bodyBall[b].parentBall != BODY_BALL_NULL) {
|
||||
_bodyBall[_bodyBall[b].parentBall].velocity += springDirection * force;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// apply tightness force - (causing ball position to be close to skeleton joint position)
|
||||
glm::vec3 targetPosition
|
||||
= _skeleton.joint[_bodyBall[b].parentJoint].position
|
||||
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
|
||||
|
||||
_bodyBall[b].velocity += (targetPosition - _bodyBall[b].position) * _bodyBall[b].jointTightness * deltaTime;
|
||||
|
||||
// apply decay
|
||||
float decay = 1.0 - BODY_SPRING_DECAY * deltaTime;
|
||||
if (decay > 0.0) {
|
||||
_bodyBall[b].velocity *= decay;
|
||||
} else {
|
||||
_bodyBall[b].velocity = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
// update position by velocity...
|
||||
_bodyBall[b].position += _bodyBall[b].velocity * deltaTime;
|
||||
|
||||
// update rotation
|
||||
const float SMALL_SPRING_LENGTH = 0.001f; // too-small springs can change direction rapidly
|
||||
if (_skeleton.joint[b].parent == AVATAR_JOINT_NULL || length < SMALL_SPRING_LENGTH) {
|
||||
_bodyBall[b].rotation = orientation * _skeleton.joint[_bodyBall[b].parentJoint].absoluteBindPoseRotation;
|
||||
} else {
|
||||
glm::vec3 parentDirection = _bodyBall[ _bodyBall[b].parentBall ].rotation * JOINT_DIRECTION;
|
||||
_bodyBall[b].rotation = rotationBetween(parentDirection, springVector) *
|
||||
_bodyBall[ _bodyBall[b].parentBall ].rotation;
|
||||
}
|
||||
}
|
||||
|
||||
// copy the head's rotation
|
||||
_bodyBall[BODY_BALL_HEAD_BASE].rotation = _bodyBall[BODY_BALL_HEAD_TOP].rotation = _head.getOrientation();
|
||||
_bodyBall[BODY_BALL_HEAD_BASE].position = _bodyBall[BODY_BALL_NECK_BASE].position +
|
||||
_bodyBall[BODY_BALL_HEAD_BASE].rotation * _skeleton.joint[BODY_BALL_HEAD_BASE].bindPosePosition;
|
||||
_bodyBall[BODY_BALL_HEAD_TOP].position = _bodyBall[BODY_BALL_HEAD_BASE].position +
|
||||
_bodyBall[BODY_BALL_HEAD_TOP].rotation * _skeleton.joint[BODY_BALL_HEAD_TOP].bindPosePosition;
|
||||
}
|
||||
|
||||
// returns true if the Leap controls any of the avatar's hands.
|
||||
bool Avatar::updateLeapHandPositions() {
|
||||
|
@ -658,7 +399,7 @@ void Avatar::updateArmIKAndConstraints(float deltaTime, AvatarJointID fingerTipJ
|
|||
float distance = glm::length(armVector);
|
||||
|
||||
// don't let right hand get dragged beyond maximum arm length...
|
||||
float armLength = (_skeletonModel.isActive() && !Menu::getInstance()->isOptionChecked(MenuOption::AvatarAsBalls)) ?
|
||||
float armLength = _skeletonModel.isActive() ?
|
||||
_skeletonModel.getRightArmLength() : _skeleton.getArmLength();
|
||||
const float ARM_RETRACTION = 0.75f;
|
||||
float retractedArmLength = armLength * ARM_RETRACTION;
|
||||
|
@ -702,79 +443,17 @@ glm::quat Avatar::computeRotationFromBodyToWorldUp(float proportion) const {
|
|||
return glm::angleAxis(angle * proportion, axis);
|
||||
}
|
||||
|
||||
float Avatar::getBallRenderAlpha(int ball, bool forceRenderHead) const {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
|
||||
void Avatar::renderBody(bool forceRenderHead) {
|
||||
|
||||
if (_head.getVideoFace().isFullFrame()) {
|
||||
// Render the full-frame video
|
||||
float alpha = getBallRenderAlpha(BODY_BALL_HEAD_BASE, forceRenderHead);
|
||||
if (alpha > 0.0f) {
|
||||
_head.getVideoFace().render(1.0f);
|
||||
}
|
||||
} else if (Menu::getInstance()->isOptionChecked(MenuOption::AvatarAsBalls)) {
|
||||
// Render the body as balls and cones
|
||||
glm::vec3 skinColor, darkSkinColor;
|
||||
getSkinColors(skinColor, darkSkinColor);
|
||||
for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) {
|
||||
float alpha = getBallRenderAlpha(b, forceRenderHead);
|
||||
|
||||
// When we have leap hands, hide part of the arms.
|
||||
if (_hand.getNumPalms() > 0) {
|
||||
if (b == BODY_BALL_LEFT_FINGERTIPS
|
||||
|| b == BODY_BALL_RIGHT_FINGERTIPS) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Always render other people, and render myself when beyond threshold distance
|
||||
if (b == BODY_BALL_HEAD_BASE) { // the head is rendered as a special
|
||||
if (alpha > 0.0f) {
|
||||
_head.render(alpha, true);
|
||||
}
|
||||
} else if (alpha > 0.0f) {
|
||||
// Render the body ball sphere
|
||||
glColor3f(skinColor.r + _bodyBall[b].touchForce * 0.3f,
|
||||
skinColor.g - _bodyBall[b].touchForce * 0.2f,
|
||||
skinColor.b - _bodyBall[b].touchForce * 0.1f);
|
||||
|
||||
if ((b != BODY_BALL_HEAD_TOP )
|
||||
&& (b != BODY_BALL_HEAD_BASE )) {
|
||||
glPushMatrix();
|
||||
glTranslatef(_bodyBall[b].position.x, _bodyBall[b].position.y, _bodyBall[b].position.z);
|
||||
glutSolidSphere(_bodyBall[b].radius, 20.0f, 20.0f);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
// Render the cone connecting this ball to its parent
|
||||
if (_bodyBall[b].parentBall != BODY_BALL_NULL) {
|
||||
if ((b != BODY_BALL_HEAD_TOP)
|
||||
&& (b != BODY_BALL_HEAD_BASE)
|
||||
&& (b != BODY_BALL_PELVIS)
|
||||
&& (b != BODY_BALL_TORSO)
|
||||
&& (b != BODY_BALL_CHEST)
|
||||
&& (b != BODY_BALL_LEFT_COLLAR)
|
||||
&& (b != BODY_BALL_LEFT_SHOULDER)
|
||||
&& (b != BODY_BALL_RIGHT_COLLAR)
|
||||
&& (b != BODY_BALL_RIGHT_SHOULDER)) {
|
||||
glColor3fv((const GLfloat*)&darkSkinColor);
|
||||
|
||||
float r2 = _bodyBall[b].radius * 0.8;
|
||||
renderJointConnectingCone(_bodyBall[_bodyBall[b].parentBall].position, _bodyBall[b].position, r2, r2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_head.getVideoFace().render(1.0f);
|
||||
} else {
|
||||
// Render the body's voxels and head
|
||||
float alpha = getBallRenderAlpha(BODY_BALL_HEAD_BASE, forceRenderHead);
|
||||
if (alpha > 0.0f) {
|
||||
if (!_skeletonModel.render(alpha)) {
|
||||
_voxels.render(false);
|
||||
}
|
||||
_head.render(alpha, false);
|
||||
}
|
||||
_skeletonModel.render(1.0f);
|
||||
_head.render(1.0f, false);
|
||||
}
|
||||
_hand.render(false);
|
||||
}
|
||||
|
@ -782,33 +461,13 @@ void Avatar::renderBody(bool forceRenderHead) {
|
|||
void Avatar::getSkinColors(glm::vec3& lighter, glm::vec3& darker) {
|
||||
lighter = glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2]);
|
||||
darker = glm::vec3(DARK_SKIN_COLOR[0], DARK_SKIN_COLOR[1], DARK_SKIN_COLOR[2]);
|
||||
if (!Menu::getInstance()->isOptionChecked(MenuOption::AvatarAsBalls) && _head.getFaceModel().isActive()) {
|
||||
if (_head.getFaceModel().isActive()) {
|
||||
lighter = glm::vec3(_head.getFaceModel().computeAverageColor());
|
||||
const float SKIN_DARKENING = 0.9f;
|
||||
darker = lighter * SKIN_DARKENING;
|
||||
}
|
||||
}
|
||||
|
||||
void Avatar::getBodyBallTransform(AvatarJointID jointID, glm::vec3& position, glm::quat& rotation) const {
|
||||
position = _bodyBall[jointID].position;
|
||||
rotation = _bodyBall[jointID].rotation;
|
||||
}
|
||||
|
||||
bool Avatar::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance) const {
|
||||
float minDistance = FLT_MAX;
|
||||
for (int i = 0; i < NUM_AVATAR_BODY_BALLS; i++) {
|
||||
float distance;
|
||||
if (rayIntersectsSphere(origin, direction, _bodyBall[i].position, _bodyBall[i].radius, distance)) {
|
||||
minDistance = min(minDistance, distance);
|
||||
}
|
||||
}
|
||||
if (minDistance == FLT_MAX) {
|
||||
return false;
|
||||
}
|
||||
distance = minDistance;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Avatar::findSpherePenetration(const glm::vec3& penetratorCenter, float penetratorRadius,
|
||||
glm::vec3& penetration, int skeletonSkipIndex) {
|
||||
bool didPenetrate = false;
|
||||
|
@ -922,36 +581,11 @@ void Avatar::setScale(const float scale) {
|
|||
|
||||
_skeleton.setScale(_scale);
|
||||
|
||||
// specify the new radius of each ball
|
||||
_bodyBall[BODY_BALL_PELVIS].radius = _scale * BODY_BALL_RADIUS_PELVIS;
|
||||
_bodyBall[BODY_BALL_TORSO].radius = _scale * BODY_BALL_RADIUS_TORSO;
|
||||
_bodyBall[BODY_BALL_CHEST].radius = _scale * BODY_BALL_RADIUS_CHEST;
|
||||
_bodyBall[BODY_BALL_NECK_BASE].radius = _scale * BODY_BALL_RADIUS_NECK_BASE;
|
||||
_bodyBall[BODY_BALL_HEAD_BASE].radius = _scale * BODY_BALL_RADIUS_HEAD_BASE;
|
||||
_bodyBall[BODY_BALL_LEFT_COLLAR].radius = _scale * BODY_BALL_RADIUS_LEFT_COLLAR;
|
||||
_bodyBall[BODY_BALL_LEFT_SHOULDER].radius = _scale * BODY_BALL_RADIUS_LEFT_SHOULDER;
|
||||
_bodyBall[BODY_BALL_LEFT_ELBOW].radius = _scale * BODY_BALL_RADIUS_LEFT_ELBOW;
|
||||
_bodyBall[BODY_BALL_LEFT_WRIST].radius = _scale * BODY_BALL_RADIUS_LEFT_WRIST;
|
||||
_bodyBall[BODY_BALL_LEFT_FINGERTIPS].radius = _scale * BODY_BALL_RADIUS_LEFT_FINGERTIPS;
|
||||
_bodyBall[BODY_BALL_RIGHT_COLLAR].radius = _scale * BODY_BALL_RADIUS_RIGHT_COLLAR;
|
||||
_bodyBall[BODY_BALL_RIGHT_SHOULDER].radius = _scale * BODY_BALL_RADIUS_RIGHT_SHOULDER;
|
||||
_bodyBall[BODY_BALL_RIGHT_ELBOW].radius = _scale * BODY_BALL_RADIUS_RIGHT_ELBOW;
|
||||
_bodyBall[BODY_BALL_RIGHT_WRIST].radius = _scale * BODY_BALL_RADIUS_RIGHT_WRIST;
|
||||
_bodyBall[BODY_BALL_RIGHT_FINGERTIPS].radius = _scale * BODY_BALL_RADIUS_RIGHT_FINGERTIPS;
|
||||
_bodyBall[BODY_BALL_LEFT_HIP].radius = _scale * BODY_BALL_RADIUS_LEFT_HIP;
|
||||
_bodyBall[BODY_BALL_LEFT_KNEE].radius = _scale * BODY_BALL_RADIUS_LEFT_KNEE;
|
||||
_bodyBall[BODY_BALL_LEFT_HEEL].radius = _scale * BODY_BALL_RADIUS_LEFT_HEEL;
|
||||
_bodyBall[BODY_BALL_LEFT_TOES].radius = _scale * BODY_BALL_RADIUS_LEFT_TOES;
|
||||
_bodyBall[BODY_BALL_RIGHT_HIP].radius = _scale * BODY_BALL_RADIUS_RIGHT_HIP;
|
||||
_bodyBall[BODY_BALL_RIGHT_KNEE].radius = _scale * BODY_BALL_RADIUS_RIGHT_KNEE;
|
||||
_bodyBall[BODY_BALL_RIGHT_HEEL].radius = _scale * BODY_BALL_RADIUS_RIGHT_HEEL;
|
||||
_bodyBall[BODY_BALL_RIGHT_TOES].radius = _scale * BODY_BALL_RADIUS_RIGHT_TOES;
|
||||
|
||||
_height = _skeleton.getHeight() + _bodyBall[BODY_BALL_LEFT_HEEL].radius + _bodyBall[BODY_BALL_HEAD_BASE].radius;
|
||||
_height = _skeleton.getHeight();
|
||||
|
||||
_maxArmLength = _skeleton.getArmLength();
|
||||
_pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _bodyBall[BODY_BALL_LEFT_HEEL].radius;
|
||||
_pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _bodyBall[BODY_BALL_LEFT_HEEL].radius;
|
||||
_pelvisStandingHeight = _skeleton.getPelvisStandingHeight();
|
||||
_pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight();
|
||||
_pelvisToHeadLength = _skeleton.getPelvisToHeadLength();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
#include <AvatarData.h>
|
||||
|
||||
#include "AvatarVoxelSystem.h"
|
||||
#include "Balls.h"
|
||||
#include "Hand.h"
|
||||
#include "Head.h"
|
||||
|
@ -159,20 +158,9 @@ public:
|
|||
Hand& getHand() { return _hand; }
|
||||
glm::quat getOrientation() const;
|
||||
glm::quat getWorldAlignedOrientation() const;
|
||||
AvatarVoxelSystem* getVoxels() { return &_voxels; }
|
||||
|
||||
void getSkinColors(glm::vec3& lighter, glm::vec3& darker);
|
||||
|
||||
// Get the position/rotation of a single body ball
|
||||
void getBodyBallTransform(AvatarJointID jointID, glm::vec3& position, glm::quat& rotation) const;
|
||||
|
||||
/// Checks for an intersection between the described ray and any of the avatar's body balls.
|
||||
/// \param origin the origin of the ray
|
||||
/// \param direction the unit direction vector
|
||||
/// \param[out] distance the variable in which to store the distance to intersection
|
||||
/// \return whether or not the ray intersected
|
||||
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance) const;
|
||||
|
||||
/// Checks for penetration between the described sphere and the avatar.
|
||||
/// \param penetratorCenter the center of the penetration test sphere
|
||||
/// \param penetratorRadius the radius of the penetration test sphere
|
||||
|
@ -217,7 +205,7 @@ protected:
|
|||
SkeletonModel _skeletonModel;
|
||||
bool _ballSpringsInitialized;
|
||||
float _bodyYawDelta;
|
||||
AvatarBall _bodyBall[ NUM_AVATAR_BODY_BALLS ];
|
||||
//AvatarBall _bodyBall[ NUM_AVATAR_BODY_BALLS ];
|
||||
AvatarMode _mode;
|
||||
glm::vec3 _velocity;
|
||||
glm::vec3 _thrust;
|
||||
|
@ -234,7 +222,6 @@ protected:
|
|||
bool _isCollisionsOn;
|
||||
Avatar* _leadingAvatar;
|
||||
float _stringLength;
|
||||
AvatarVoxelSystem _voxels;
|
||||
|
||||
bool _moving; ///< set when position is changing
|
||||
|
||||
|
@ -243,7 +230,6 @@ protected:
|
|||
glm::vec3 getBodyUpDirection() const { return getOrientation() * IDENTITY_UP; }
|
||||
glm::vec3 getBodyFrontDirection() const { return getOrientation() * IDENTITY_FRONT; }
|
||||
glm::quat computeRotationFromBodyToWorldUp(float proportion = 1.0f) const;
|
||||
void updateBodyBalls(float deltaTime);
|
||||
bool updateLeapHandPositions();
|
||||
void updateArmIKAndConstraints(float deltaTime, AvatarJointID fingerTipJointID);
|
||||
void setScale(const float scale);
|
||||
|
|
|
@ -1,120 +0,0 @@
|
|||
//
|
||||
// AvatarTouch.cpp
|
||||
// interface
|
||||
//
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
|
||||
#include <iostream>
|
||||
#include <glm/glm.hpp>
|
||||
#include <SharedUtil.h>
|
||||
#include "AvatarTouch.h"
|
||||
#include "InterfaceConfig.h"
|
||||
#include "Util.h"
|
||||
|
||||
const float THREAD_RADIUS = 0.007;
|
||||
const float HANDS_CLOSE_ENOUGH_TO_GRASP = 0.2;
|
||||
const float AVATAR_FACING_THRESHOLD = -0.5f; // (-1 to 1) (larger value indicates narrower angle of influence
|
||||
|
||||
AvatarTouch::AvatarTouch() {
|
||||
|
||||
_myHandPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_yourHandPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_myBodyPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_yourBodyPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_vectorBetweenHands = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_myHandState = HAND_STATE_NULL;
|
||||
_yourHandState = HAND_STATE_NULL;
|
||||
_reachableRadius = 0.0f;
|
||||
_weAreHoldingHands = false;
|
||||
_canReachToOtherAvatar = false;
|
||||
_handsCloseEnoughToGrasp = false;
|
||||
_hasInteractingOther = false;
|
||||
|
||||
for (int p=0; p<NUM_PARTICLE_POINTS; p++) {
|
||||
_point[p] = glm::vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
void AvatarTouch::simulate (float deltaTime) {
|
||||
|
||||
_canReachToOtherAvatar = false; // default
|
||||
|
||||
if (_hasInteractingOther) {
|
||||
|
||||
glm::vec3 vectorBetweenBodies = _yourBodyPosition - _myBodyPosition;
|
||||
float distanceBetweenBodies = glm::length(vectorBetweenBodies);
|
||||
|
||||
//KEEP THIS - it is another variation that we are considering getting rid of
|
||||
//the following code take into account of the two avatars are facing each other
|
||||
/*
|
||||
glm::vec3 directionBetweenBodies = vectorBetweenBodies / distanceBetweenBodies;
|
||||
|
||||
bool facingEachOther = false;
|
||||
|
||||
glm::vec3 myFront = _myOrientation * AVATAR_FRONT;
|
||||
glm::vec3 yourFront = _yourOrientation * AVATAR_FRONT;
|
||||
|
||||
if (( glm::dot(myFront, yourFront ) < -AVATAR_FACING_THRESHOLD) // we're facing each other
|
||||
&& ( glm::dot(myFront, directionBetweenBodies ) > AVATAR_FACING_THRESHOLD)) { // I'm facing you
|
||||
facingEachOther = true;
|
||||
}
|
||||
*/
|
||||
|
||||
if (distanceBetweenBodies < _reachableRadius)
|
||||
{
|
||||
_canReachToOtherAvatar = true;
|
||||
|
||||
_vectorBetweenHands = _yourHandPosition - _myHandPosition;
|
||||
|
||||
float distanceBetweenHands = glm::length(_vectorBetweenHands);
|
||||
if (distanceBetweenHands < HANDS_CLOSE_ENOUGH_TO_GRASP) {
|
||||
_handsCloseEnoughToGrasp = true;
|
||||
} else {
|
||||
_handsCloseEnoughToGrasp = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AvatarTouch::render(glm::vec3 cameraPosition) {
|
||||
|
||||
if (_canReachToOtherAvatar) {
|
||||
|
||||
//show circle indicating that we can reach out to each other...
|
||||
glColor4f(0.3, 0.4, 0.5, 0.5);
|
||||
glm::vec3 p(_yourBodyPosition);
|
||||
p.y = 0.0005f;
|
||||
renderCircle(p, _reachableRadius, glm::vec3(0.0f, 1.0f, 0.0f), 30);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AvatarTouch::renderBeamBetweenHands() {
|
||||
|
||||
glm::vec3 v1(_myHandPosition);
|
||||
glm::vec3 v2(_yourHandPosition);
|
||||
|
||||
glLineWidth(3.0);
|
||||
glColor4f(0.9f, 0.9f, 0.1f, 0.6);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
glVertex3f(v1.x, v1.y, v1.z);
|
||||
glVertex3f(v2.x, v2.y, v2.z);
|
||||
glEnd();
|
||||
|
||||
glColor3f(0.5f, 0.3f, 0.0f);
|
||||
for (int p=0; p<NUM_PARTICLE_POINTS; p++) {
|
||||
|
||||
_point[p] = _myHandPosition + _vectorBetweenHands * ((float)p / (float)NUM_PARTICLE_POINTS);
|
||||
_point[p].x += randFloatInRange(-THREAD_RADIUS, THREAD_RADIUS);
|
||||
_point[p].y += randFloatInRange(-THREAD_RADIUS, THREAD_RADIUS);
|
||||
_point[p].z += randFloatInRange(-THREAD_RADIUS, THREAD_RADIUS);
|
||||
|
||||
glBegin(GL_POINTS);
|
||||
glVertex3f(_point[p].x, _point[p].y, _point[p].z);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
//
|
||||
// AvatarTouch.h
|
||||
// interface
|
||||
//
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __interface__AvatarTouch__
|
||||
#define __interface__AvatarTouch__
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
#include <AvatarData.h>
|
||||
|
||||
enum AvatarHandState
|
||||
{
|
||||
HAND_STATE_NULL = 0,
|
||||
HAND_STATE_OPEN,
|
||||
HAND_STATE_GRASPING,
|
||||
HAND_STATE_POINTING,
|
||||
NUM_HAND_STATES
|
||||
};
|
||||
|
||||
class AvatarTouch {
|
||||
public:
|
||||
|
||||
AvatarTouch();
|
||||
|
||||
void simulate(float deltaTime);
|
||||
void render(glm::vec3 cameraPosition);
|
||||
|
||||
void setHasInteractingOther(bool hasInteractingOther) { _hasInteractingOther = hasInteractingOther;}
|
||||
void setMyHandPosition (glm::vec3 position ) { _myHandPosition = position;}
|
||||
void setYourHandPosition (glm::vec3 position ) { _yourHandPosition = position;}
|
||||
void setMyOrientation (glm::quat orientation ) { _myOrientation = orientation;}
|
||||
void setYourOrientation (glm::quat orientation ) { _yourOrientation = orientation;}
|
||||
void setMyBodyPosition (glm::vec3 position ) { _myBodyPosition = position;}
|
||||
void setYourBodyPosition (glm::vec3 position ) { _yourBodyPosition = position;}
|
||||
void setMyHandState (int state ) { _myHandState = state;}
|
||||
void setYourHandState (int state ) { _yourHandState = state;}
|
||||
void setReachableRadius (float radius ) { _reachableRadius = radius;}
|
||||
void setHoldingHands (bool holding ) { _weAreHoldingHands = holding;}
|
||||
|
||||
bool getAbleToReachOtherAvatar () const {return _canReachToOtherAvatar; }
|
||||
bool getHandsCloseEnoughToGrasp() const {return _handsCloseEnoughToGrasp;}
|
||||
bool getHoldingHands () const {return _weAreHoldingHands; }
|
||||
|
||||
private:
|
||||
|
||||
static const int NUM_PARTICLE_POINTS = 100;
|
||||
|
||||
bool _hasInteractingOther;
|
||||
bool _weAreHoldingHands;
|
||||
glm::vec3 _point [NUM_PARTICLE_POINTS];
|
||||
glm::vec3 _myBodyPosition;
|
||||
glm::vec3 _yourBodyPosition;
|
||||
glm::vec3 _myHandPosition;
|
||||
glm::vec3 _yourHandPosition;
|
||||
glm::quat _myOrientation;
|
||||
glm::quat _yourOrientation;
|
||||
glm::vec3 _vectorBetweenHands;
|
||||
int _myHandState;
|
||||
int _yourHandState;
|
||||
bool _canReachToOtherAvatar;
|
||||
bool _handsCloseEnoughToGrasp;
|
||||
float _reachableRadius;
|
||||
|
||||
void renderBeamBetweenHands();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,339 +0,0 @@
|
|||
//
|
||||
// AvatarVoxelSystem.cpp
|
||||
// interface
|
||||
//
|
||||
// Created by Andrzej Kapolka on 5/31/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include <GeometryUtil.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Avatar.h"
|
||||
#include "AvatarVoxelSystem.h"
|
||||
#include "renderer/ProgramObject.h"
|
||||
|
||||
const float AVATAR_TREE_SCALE = 1.0f;
|
||||
const int MAX_VOXELS_PER_AVATAR = 10000;
|
||||
const int BONE_ELEMENTS_PER_VOXEL = BONE_ELEMENTS_PER_VERTEX * VERTICES_PER_VOXEL;
|
||||
|
||||
AvatarVoxelSystem::AvatarVoxelSystem(Avatar* avatar) :
|
||||
VoxelSystem(AVATAR_TREE_SCALE, MAX_VOXELS_PER_AVATAR),
|
||||
_initialized(false),
|
||||
_mode(0),
|
||||
_avatar(avatar),
|
||||
_voxelReply(0) {
|
||||
|
||||
// we may have been created in the network thread, but we live in the main thread
|
||||
moveToThread(Application::getInstance()->thread());
|
||||
}
|
||||
|
||||
AvatarVoxelSystem::~AvatarVoxelSystem() {
|
||||
if (_initialized) {
|
||||
delete[] _readBoneIndicesArray;
|
||||
delete[] _readBoneWeightsArray;
|
||||
delete[] _writeBoneIndicesArray;
|
||||
delete[] _writeBoneWeightsArray;
|
||||
|
||||
glDeleteBuffers(1, &_vboBoneIndicesID);
|
||||
glDeleteBuffers(1, &_vboBoneWeightsID);
|
||||
}
|
||||
}
|
||||
|
||||
ProgramObject AvatarVoxelSystem::_skinProgram;
|
||||
int AvatarVoxelSystem::_boneMatricesLocation;
|
||||
int AvatarVoxelSystem::_boneIndicesLocation;
|
||||
int AvatarVoxelSystem::_boneWeightsLocation;
|
||||
|
||||
void AvatarVoxelSystem::init() {
|
||||
if (_initialized) {
|
||||
qDebug("[ERROR] AvatarVoxelSystem is already initialized.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
VoxelSystem::init();
|
||||
|
||||
// prep the data structures for incoming voxel data
|
||||
_writeBoneIndicesArray = new GLubyte[BONE_ELEMENTS_PER_VOXEL * _maxVoxels];
|
||||
_readBoneIndicesArray = new GLubyte[BONE_ELEMENTS_PER_VOXEL * _maxVoxels];
|
||||
|
||||
_writeBoneWeightsArray = new GLfloat[BONE_ELEMENTS_PER_VOXEL * _maxVoxels];
|
||||
_readBoneWeightsArray = new GLfloat[BONE_ELEMENTS_PER_VOXEL * _maxVoxels];
|
||||
|
||||
// VBO for the boneIndicesArray
|
||||
glGenBuffers(1, &_vboBoneIndicesID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboBoneIndicesID);
|
||||
glBufferData(GL_ARRAY_BUFFER, BONE_ELEMENTS_PER_VOXEL * sizeof(GLubyte) * _maxVoxels, NULL, GL_DYNAMIC_DRAW);
|
||||
|
||||
// VBO for the boneWeightsArray
|
||||
glGenBuffers(1, &_vboBoneWeightsID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboBoneWeightsID);
|
||||
glBufferData(GL_ARRAY_BUFFER, BONE_ELEMENTS_PER_VOXEL * sizeof(GLfloat) * _maxVoxels, NULL, GL_DYNAMIC_DRAW);
|
||||
|
||||
// load our skin program if this is the first avatar system to initialize
|
||||
if (!_skinProgram.isLinked()) {
|
||||
_skinProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/skin_voxels.vert");
|
||||
_skinProgram.link();
|
||||
}
|
||||
|
||||
_boneMatricesLocation = _skinProgram.uniformLocation("boneMatrices");
|
||||
_boneIndicesLocation = _skinProgram.attributeLocation("boneIndices");
|
||||
_boneWeightsLocation = _skinProgram.attributeLocation("boneWeights");
|
||||
|
||||
VoxelTreeElement::removeUpdateHook(this); // we don't want this
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
void AvatarVoxelSystem::removeOutOfView() {
|
||||
// no-op for now
|
||||
}
|
||||
|
||||
class Mode {
|
||||
public:
|
||||
|
||||
bool bindVoxelsTogether;
|
||||
int maxBonesPerBind;
|
||||
bool includeBonesOutsideBindRadius;
|
||||
};
|
||||
|
||||
const Mode MODES[] = {
|
||||
{ false, BONE_ELEMENTS_PER_VERTEX, false }, // original
|
||||
{ false, 1, true }, // one bone per vertex
|
||||
{ true, 1, true }, // one bone per voxel
|
||||
{ true, BONE_ELEMENTS_PER_VERTEX, false } }; // four bones per voxel
|
||||
|
||||
void AvatarVoxelSystem::cycleMode() {
|
||||
_mode = (_mode + 1) % (sizeof(MODES) / sizeof(MODES[0]));
|
||||
qDebug("Voxeltar bind mode %d.\n", _mode);
|
||||
|
||||
// rebind
|
||||
QUrl url = _voxelURL;
|
||||
setVoxelURL(QUrl());
|
||||
setVoxelURL(url);
|
||||
}
|
||||
|
||||
void AvatarVoxelSystem::setVoxelURL(const QUrl& url) {
|
||||
// don't restart the download if it's the same URL
|
||||
if (_voxelURL == url) {
|
||||
return;
|
||||
}
|
||||
|
||||
// cancel any current download
|
||||
if (_voxelReply != 0) {
|
||||
delete _voxelReply;
|
||||
_voxelReply = 0;
|
||||
}
|
||||
|
||||
killLocalVoxels();
|
||||
|
||||
// remember the URL
|
||||
_voxelURL = url;
|
||||
|
||||
// handle "file://" urls...
|
||||
if (url.isLocalFile()) {
|
||||
QString pathString = url.path();
|
||||
QByteArray pathAsAscii = pathString.toLocal8Bit();
|
||||
const char* path = pathAsAscii.data();
|
||||
readFromSVOFile(path);
|
||||
return;
|
||||
}
|
||||
|
||||
// load the URL data asynchronously
|
||||
if (!url.isValid()) {
|
||||
return;
|
||||
}
|
||||
_voxelReply = Application::getInstance()->getNetworkAccessManager()->get(QNetworkRequest(url));
|
||||
connect(_voxelReply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(handleVoxelDownloadProgress(qint64,qint64)));
|
||||
connect(_voxelReply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(handleVoxelReplyError()));
|
||||
}
|
||||
|
||||
void AvatarVoxelSystem::updateArraysDetails(glBufferIndex nodeIndex, const glm::vec3& startVertex,
|
||||
float voxelScale, const nodeColor& color) {
|
||||
VoxelSystem::updateArraysDetails(nodeIndex, startVertex, voxelScale, color);
|
||||
|
||||
GLubyte* writeBoneIndicesAt = _writeBoneIndicesArray + (nodeIndex * BONE_ELEMENTS_PER_VOXEL);
|
||||
GLfloat* writeBoneWeightsAt = _writeBoneWeightsArray + (nodeIndex * BONE_ELEMENTS_PER_VOXEL);
|
||||
|
||||
if (MODES[_mode].bindVoxelsTogether) {
|
||||
BoneIndices boneIndices;
|
||||
glm::vec4 boneWeights;
|
||||
computeBoneIndicesAndWeights(startVertex + glm::vec3(voxelScale, voxelScale, voxelScale) * 0.5f,
|
||||
boneIndices, boneWeights);
|
||||
for (int i = 0; i < VERTICES_PER_VOXEL; i++) {
|
||||
for (int j = 0; j < BONE_ELEMENTS_PER_VERTEX; j++) {
|
||||
*(writeBoneIndicesAt + i * BONE_ELEMENTS_PER_VERTEX + j) = boneIndices[j];
|
||||
*(writeBoneWeightsAt + i * BONE_ELEMENTS_PER_VERTEX + j) = boneWeights[j];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < VERTICES_PER_VOXEL; i++) {
|
||||
BoneIndices boneIndices;
|
||||
glm::vec4 boneWeights;
|
||||
computeBoneIndicesAndWeights(computeVoxelVertex(startVertex, voxelScale, i), boneIndices, boneWeights);
|
||||
for (int j = 0; j < BONE_ELEMENTS_PER_VERTEX; j++) {
|
||||
*(writeBoneIndicesAt + i * BONE_ELEMENTS_PER_VERTEX + j) = boneIndices[j];
|
||||
*(writeBoneWeightsAt + i * BONE_ELEMENTS_PER_VERTEX + j) = boneWeights[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AvatarVoxelSystem::copyWrittenDataSegmentToReadArrays(glBufferIndex segmentStart, glBufferIndex segmentEnd) {
|
||||
VoxelSystem::copyWrittenDataSegmentToReadArrays(segmentStart, segmentEnd);
|
||||
|
||||
int segmentLength = (segmentEnd - segmentStart) + 1;
|
||||
GLintptr segmentStartAt = segmentStart * BONE_ELEMENTS_PER_VOXEL * sizeof(GLubyte);
|
||||
GLsizeiptr segmentSizeBytes = segmentLength * BONE_ELEMENTS_PER_VOXEL * sizeof(GLubyte);
|
||||
GLubyte* readBoneIndicesAt = _readBoneIndicesArray + (segmentStart * BONE_ELEMENTS_PER_VOXEL);
|
||||
GLubyte* writeBoneIndicesAt = _writeBoneIndicesArray + (segmentStart * BONE_ELEMENTS_PER_VOXEL);
|
||||
memcpy(readBoneIndicesAt, writeBoneIndicesAt, segmentSizeBytes);
|
||||
|
||||
segmentStartAt = segmentStart * BONE_ELEMENTS_PER_VOXEL * sizeof(GLfloat);
|
||||
segmentSizeBytes = segmentLength * BONE_ELEMENTS_PER_VOXEL * sizeof(GLfloat);
|
||||
GLfloat* readBoneWeightsAt = _readBoneWeightsArray + (segmentStart * BONE_ELEMENTS_PER_VOXEL);
|
||||
GLfloat* writeBoneWeightsAt = _writeBoneWeightsArray + (segmentStart * BONE_ELEMENTS_PER_VOXEL);
|
||||
memcpy(readBoneWeightsAt, writeBoneWeightsAt, segmentSizeBytes);
|
||||
}
|
||||
|
||||
void AvatarVoxelSystem::updateVBOSegment(glBufferIndex segmentStart, glBufferIndex segmentEnd) {
|
||||
VoxelSystem::updateVBOSegment(segmentStart, segmentEnd);
|
||||
|
||||
int segmentLength = (segmentEnd - segmentStart) + 1;
|
||||
GLintptr segmentStartAt = segmentStart * BONE_ELEMENTS_PER_VOXEL * sizeof(GLubyte);
|
||||
GLsizeiptr segmentSizeBytes = segmentLength * BONE_ELEMENTS_PER_VOXEL * sizeof(GLubyte);
|
||||
GLubyte* readBoneIndicesFrom = _readBoneIndicesArray + (segmentStart * BONE_ELEMENTS_PER_VOXEL);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboBoneIndicesID);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, segmentStartAt, segmentSizeBytes, readBoneIndicesFrom);
|
||||
|
||||
segmentStartAt = segmentStart * BONE_ELEMENTS_PER_VOXEL * sizeof(GLfloat);
|
||||
segmentSizeBytes = segmentLength * BONE_ELEMENTS_PER_VOXEL * sizeof(GLfloat);
|
||||
GLfloat* readBoneWeightsFrom = _readBoneWeightsArray + (segmentStart * BONE_ELEMENTS_PER_VOXEL);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboBoneWeightsID);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, segmentStartAt, segmentSizeBytes, readBoneWeightsFrom);
|
||||
}
|
||||
|
||||
void AvatarVoxelSystem::applyScaleAndBindProgram(bool texture) {
|
||||
_skinProgram.bind();
|
||||
|
||||
// the base matrix includes centering and scale
|
||||
QMatrix4x4 baseMatrix;
|
||||
baseMatrix.scale(_treeScale);
|
||||
baseMatrix.translate(-0.5f, -0.5f, -0.5f);
|
||||
|
||||
// bone matrices include joint transforms
|
||||
QMatrix4x4 boneMatrices[NUM_AVATAR_JOINTS];
|
||||
for (int i = 0; i < NUM_AVATAR_JOINTS; i++) {
|
||||
glm::vec3 position;
|
||||
glm::quat orientation;
|
||||
_avatar->getBodyBallTransform((AvatarJointID)i, position, orientation);
|
||||
boneMatrices[i].translate(position.x, position.y, position.z);
|
||||
orientation = orientation * glm::inverse(_avatar->getSkeleton().joint[i].absoluteBindPoseRotation);
|
||||
boneMatrices[i].rotate(QQuaternion(orientation.w, orientation.x, orientation.y, orientation.z));
|
||||
const glm::vec3& bindPosition = _avatar->getSkeleton().joint[i].absoluteBindPosePosition;
|
||||
boneMatrices[i].translate(-bindPosition.x, -bindPosition.y, -bindPosition.z);
|
||||
boneMatrices[i] *= baseMatrix;
|
||||
}
|
||||
_skinProgram.setUniformValueArray(_boneMatricesLocation, boneMatrices, NUM_AVATAR_JOINTS);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboBoneIndicesID);
|
||||
glVertexAttribPointer(_boneIndicesLocation, BONE_ELEMENTS_PER_VERTEX, GL_UNSIGNED_BYTE, false, 0, 0);
|
||||
_skinProgram.enableAttributeArray(_boneIndicesLocation);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboBoneWeightsID);
|
||||
_skinProgram.setAttributeBuffer(_boneWeightsLocation, GL_FLOAT, 0, BONE_ELEMENTS_PER_VERTEX);
|
||||
_skinProgram.enableAttributeArray(_boneWeightsLocation);
|
||||
}
|
||||
|
||||
void AvatarVoxelSystem::removeScaleAndReleaseProgram(bool texture) {
|
||||
_skinProgram.release();
|
||||
_skinProgram.disableAttributeArray(_boneIndicesLocation);
|
||||
_skinProgram.disableAttributeArray(_boneWeightsLocation);
|
||||
}
|
||||
|
||||
void AvatarVoxelSystem::handleVoxelDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
|
||||
// for now, just wait until we have the full business
|
||||
if (bytesReceived < bytesTotal) {
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray entirety = _voxelReply->readAll();
|
||||
_voxelReply->disconnect(this);
|
||||
_voxelReply->deleteLater();
|
||||
_voxelReply = 0;
|
||||
|
||||
ReadBitstreamToTreeParams args(WANT_COLOR, NO_EXISTS_BITS);
|
||||
_tree->readBitstreamToTree((unsigned char*)entirety.data(), entirety.size(), args);
|
||||
setupNewVoxelsForDrawing();
|
||||
}
|
||||
|
||||
void AvatarVoxelSystem::handleVoxelReplyError() {
|
||||
qDebug("%s\n", _voxelReply->errorString().toLocal8Bit().constData());
|
||||
|
||||
_voxelReply->disconnect(this);
|
||||
_voxelReply->deleteLater();
|
||||
_voxelReply = 0;
|
||||
}
|
||||
|
||||
class IndexDistance {
|
||||
public:
|
||||
IndexDistance(GLubyte index = AVATAR_JOINT_PELVIS, float distance = FLT_MAX) : index(index), distance(distance) { }
|
||||
|
||||
GLubyte index;
|
||||
float distance;
|
||||
};
|
||||
|
||||
void AvatarVoxelSystem::computeBoneIndicesAndWeights(const glm::vec3& vertex, BoneIndices& indices, glm::vec4& weights) const {
|
||||
// transform into joint space
|
||||
glm::vec3 jointVertex = (vertex - glm::vec3(0.5f, 0.5f, 0.5f)) * AVATAR_TREE_SCALE;
|
||||
|
||||
// find the nearest four joints (TODO: use a better data structure for the pose positions to speed this up)
|
||||
IndexDistance nearest[BONE_ELEMENTS_PER_VERTEX];
|
||||
const Skeleton& skeleton = _avatar->getSkeleton();
|
||||
for (int i = 0; i < NUM_AVATAR_JOINTS; i++) {
|
||||
AvatarJointID parent = skeleton.joint[i].parent;
|
||||
float distance = glm::length(computeVectorFromPointToSegment(jointVertex,
|
||||
skeleton.joint[parent == AVATAR_JOINT_NULL ? i : parent].absoluteBindPosePosition,
|
||||
skeleton.joint[i].absoluteBindPosePosition));
|
||||
if (!MODES[_mode].includeBonesOutsideBindRadius && distance > skeleton.joint[i].bindRadius) {
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < BONE_ELEMENTS_PER_VERTEX; j++) {
|
||||
if (distance < nearest[j].distance) {
|
||||
// move the rest of the indices down
|
||||
for (int k = BONE_ELEMENTS_PER_VERTEX - 1; k > j; k--) {
|
||||
nearest[k] = nearest[k - 1];
|
||||
}
|
||||
nearest[j] = IndexDistance(i, distance);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// compute the weights based on inverse distance
|
||||
float totalWeight = 0.0f;
|
||||
for (int i = 0; i < MODES[_mode].maxBonesPerBind; i++) {
|
||||
indices[i] = nearest[i].index;
|
||||
if (nearest[i].distance != FLT_MAX) {
|
||||
weights[i] = 1.0f / glm::max(nearest[i].distance, EPSILON);
|
||||
totalWeight += weights[i];
|
||||
|
||||
} else {
|
||||
weights[i] = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// if it's not attached to anything, consider it attached to the hip
|
||||
if (totalWeight == 0.0f) {
|
||||
weights[0] = 1.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
// ortherwise, normalize the weights
|
||||
for (int i = 0; i < BONE_ELEMENTS_PER_VERTEX; i++) {
|
||||
weights[i] /= totalWeight;
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
//
|
||||
// AvatarVoxelSystem.h
|
||||
// interface
|
||||
//
|
||||
// Created by Andrzej Kapolka on 5/31/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __interface__AvatarVoxelSystem__
|
||||
#define __interface__AvatarVoxelSystem__
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
|
||||
#include "VoxelSystem.h"
|
||||
|
||||
const int BONE_ELEMENTS_PER_VERTEX = 4;
|
||||
typedef GLubyte BoneIndices[BONE_ELEMENTS_PER_VERTEX];
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
class Avatar;
|
||||
|
||||
class AvatarVoxelSystem : public VoxelSystem {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
AvatarVoxelSystem(Avatar* avatar);
|
||||
virtual ~AvatarVoxelSystem();
|
||||
|
||||
virtual void init();
|
||||
|
||||
virtual void removeOutOfView();
|
||||
|
||||
Q_INVOKABLE void setVoxelURL(const QUrl& url);
|
||||
const QUrl& getVoxelURL() const { return _voxelURL; }
|
||||
|
||||
public slots:
|
||||
|
||||
void cycleMode();
|
||||
|
||||
protected:
|
||||
|
||||
virtual void updateArraysDetails(glBufferIndex nodeIndex, const glm::vec3& startVertex,
|
||||
float voxelScale, const nodeColor& color);
|
||||
virtual void copyWrittenDataSegmentToReadArrays(glBufferIndex segmentStart, glBufferIndex segmentEnd);
|
||||
virtual void updateVBOSegment(glBufferIndex segmentStart, glBufferIndex segmentEnd);
|
||||
virtual void applyScaleAndBindProgram(bool texture);
|
||||
virtual void removeScaleAndReleaseProgram(bool texture);
|
||||
|
||||
private slots:
|
||||
|
||||
void handleVoxelDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||
void handleVoxelReplyError();
|
||||
|
||||
private:
|
||||
|
||||
void computeBoneIndicesAndWeights(const glm::vec3& vertex, BoneIndices& indices, glm::vec4& weights) const;
|
||||
|
||||
bool _initialized;
|
||||
int _mode;
|
||||
|
||||
Avatar* _avatar;
|
||||
|
||||
QUrl _voxelURL;
|
||||
|
||||
GLubyte* _readBoneIndicesArray;
|
||||
GLfloat* _readBoneWeightsArray;
|
||||
GLubyte* _writeBoneIndicesArray;
|
||||
GLfloat* _writeBoneWeightsArray;
|
||||
|
||||
GLuint _vboBoneIndicesID;
|
||||
GLuint _vboBoneWeightsID;
|
||||
|
||||
QNetworkReply* _voxelReply;
|
||||
|
||||
static ProgramObject _skinProgram;
|
||||
static int _boneMatricesLocation;
|
||||
static int _boneIndicesLocation;
|
||||
static int _boneWeightsLocation;
|
||||
};
|
||||
|
||||
#endif /* defined(__interface__AvatarVoxelSystem__) */
|
|
@ -24,6 +24,7 @@
|
|||
#include "ParticleSystem.h"
|
||||
#include "world.h"
|
||||
#include "devices/SerialInterface.h"
|
||||
#include "VoxelSystem.h"
|
||||
|
||||
class Avatar;
|
||||
class ProgramObject;
|
||||
|
|
|
@ -250,9 +250,8 @@ void Head::simulate(float deltaTime, bool isMine) {
|
|||
calculateGeometry();
|
||||
|
||||
// the blend face may have custom eye meshes
|
||||
if (!Menu::getInstance()->isOptionChecked(MenuOption::AvatarAsBalls)) {
|
||||
_faceModel.getEyePositions(_leftEyePosition, _rightEyePosition);
|
||||
}
|
||||
_faceModel.getEyePositions(_leftEyePosition, _rightEyePosition);
|
||||
|
||||
}
|
||||
|
||||
void Head::calculateGeometry() {
|
||||
|
|
|
@ -75,8 +75,6 @@ void MyAvatar::setMoveTarget(const glm::vec3 moveTarget) {
|
|||
void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||
|
||||
glm::quat orientation = getOrientation();
|
||||
glm::vec3 front = orientation * IDENTITY_FRONT;
|
||||
glm::vec3 right = orientation * IDENTITY_RIGHT;
|
||||
|
||||
// Update movement timers
|
||||
_elapsedTimeSinceCollision += deltaTime;
|
||||
|
@ -113,9 +111,6 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
// calculate speed
|
||||
_speed = glm::length(_velocity);
|
||||
|
||||
// figure out if the mouse cursor is over any body spheres...
|
||||
checkForMouseRayTouching();
|
||||
|
||||
// update balls
|
||||
if (_balls) {
|
||||
_balls->moveOrigin(_position);
|
||||
|
@ -143,24 +138,7 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
|
||||
// update avatar skeleton
|
||||
_skeleton.update(deltaTime, getOrientation(), _position);
|
||||
|
||||
// determine the lengths of the body springs now that we have updated the skeleton at least once
|
||||
if (!_ballSpringsInitialized) {
|
||||
for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) {
|
||||
|
||||
glm::vec3 targetPosition
|
||||
= _skeleton.joint[_bodyBall[b].parentJoint].position
|
||||
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
|
||||
|
||||
glm::vec3 parentTargetPosition
|
||||
= _skeleton.joint[_bodyBall[b].parentJoint].position
|
||||
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
|
||||
|
||||
_bodyBall[b].springLength = glm::length(targetPosition - parentTargetPosition);
|
||||
}
|
||||
|
||||
_ballSpringsInitialized = true;
|
||||
}
|
||||
|
||||
|
||||
// update the movement of the hand and process handshaking with other avatars...
|
||||
updateHandMovementAndTouching(deltaTime, enableHandMovement);
|
||||
|
@ -190,9 +168,6 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
updateAvatarCollisions(deltaTime);
|
||||
}
|
||||
|
||||
// update body balls
|
||||
updateBodyBalls(deltaTime);
|
||||
|
||||
// add thrust to velocity
|
||||
_velocity += _thrust * deltaTime;
|
||||
|
||||
|
@ -234,31 +209,7 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
} else {
|
||||
applyDamping(deltaTime, _velocity, linearDamping, SQUARED_DAMPING_STRENGTH);
|
||||
}
|
||||
|
||||
// pitch and roll the body as a function of forward speed and turning delta
|
||||
const float HIGH_VELOCITY = 10.f;
|
||||
if (glm::length(_velocity) < HIGH_VELOCITY) {
|
||||
const float BODY_PITCH_WHILE_WALKING = -20.0;
|
||||
const float BODY_ROLL_WHILE_TURNING = 0.2;
|
||||
float forwardComponentOfVelocity = glm::dot(getBodyFrontDirection(), _velocity);
|
||||
orientation = orientation * glm::quat(glm::radians(glm::vec3(
|
||||
BODY_PITCH_WHILE_WALKING * deltaTime * forwardComponentOfVelocity, 0.0f,
|
||||
BODY_ROLL_WHILE_TURNING * deltaTime * _speed * _bodyYawDelta)));
|
||||
}
|
||||
|
||||
// these forces keep the body upright...
|
||||
const float BODY_UPRIGHT_FORCE = _scale * 10.0;
|
||||
float tiltDecay = BODY_UPRIGHT_FORCE * deltaTime;
|
||||
if (tiltDecay > 1.0f) {
|
||||
tiltDecay = 1.0f;
|
||||
}
|
||||
|
||||
// update the euler angles
|
||||
setOrientation(orientation);
|
||||
|
||||
//the following will be used to make the avatar upright no matter what gravity is
|
||||
setOrientation(computeRotationFromBodyToWorldUp(tiltDecay) * orientation);
|
||||
|
||||
|
||||
// Compute instantaneous acceleration
|
||||
float forwardAcceleration = glm::length(glm::dot(getBodyFrontDirection(), getVelocity() - oldVelocity)) / deltaTime;
|
||||
const float ACCELERATION_PITCH_DECAY = 0.4f;
|
||||
|
@ -292,39 +243,11 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
}
|
||||
}
|
||||
|
||||
//apply the head lean values to the ball positions...
|
||||
if (USING_HEAD_LEAN) {
|
||||
if (fabs(_head.getLeanSideways() + _head.getLeanForward()) > 0.0f) {
|
||||
glm::vec3 headLean =
|
||||
right * _head.getLeanSideways() +
|
||||
front * _head.getLeanForward();
|
||||
|
||||
_bodyBall[BODY_BALL_TORSO].position += headLean * 0.1f;
|
||||
_bodyBall[BODY_BALL_CHEST].position += headLean * 0.4f;
|
||||
_bodyBall[BODY_BALL_NECK_BASE].position += headLean * 0.7f;
|
||||
_bodyBall[BODY_BALL_HEAD_BASE].position += headLean * 1.0f;
|
||||
|
||||
_bodyBall[BODY_BALL_LEFT_COLLAR].position += headLean * 0.6f;
|
||||
_bodyBall[BODY_BALL_LEFT_SHOULDER].position += headLean * 0.6f;
|
||||
_bodyBall[BODY_BALL_LEFT_ELBOW].position += headLean * 0.2f;
|
||||
_bodyBall[BODY_BALL_LEFT_WRIST].position += headLean * 0.1f;
|
||||
_bodyBall[BODY_BALL_LEFT_FINGERTIPS].position += headLean * 0.0f;
|
||||
|
||||
_bodyBall[BODY_BALL_RIGHT_COLLAR].position += headLean * 0.6f;
|
||||
_bodyBall[BODY_BALL_RIGHT_SHOULDER].position += headLean * 0.6f;
|
||||
_bodyBall[BODY_BALL_RIGHT_ELBOW].position += headLean * 0.2f;
|
||||
_bodyBall[BODY_BALL_RIGHT_WRIST].position += headLean * 0.1f;
|
||||
_bodyBall[BODY_BALL_RIGHT_FINGERTIPS].position += headLean * 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
_hand.simulate(deltaTime, true);
|
||||
_skeletonModel.simulate(deltaTime);
|
||||
_head.setBodyRotation(glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll));
|
||||
glm::vec3 headPosition;
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::AvatarAsBalls) || !_skeletonModel.getHeadPosition(headPosition)) {
|
||||
headPosition = _bodyBall[BODY_BALL_HEAD_BASE].position;
|
||||
}
|
||||
_skeletonModel.getHeadPosition(headPosition);
|
||||
_head.setPosition(headPosition);
|
||||
_head.setScale(_scale);
|
||||
_head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2]));
|
||||
|
@ -514,7 +437,7 @@ void MyAvatar::render(bool forceRenderHead) {
|
|||
}
|
||||
glPushMatrix();
|
||||
|
||||
glm::vec3 chatPosition = _bodyBall[BODY_BALL_HEAD_BASE].position + getBodyUpDirection() * chatMessageHeight * _scale;
|
||||
glm::vec3 chatPosition = getPosition() + getBodyUpDirection() * chatMessageHeight * _scale;
|
||||
glTranslatef(chatPosition.x, chatPosition.y, chatPosition.z);
|
||||
glm::quat chatRotation = Application::getInstance()->getCamera()->getRotation();
|
||||
glm::vec3 chatAxis = glm::axis(chatRotation);
|
||||
|
@ -562,7 +485,6 @@ void MyAvatar::saveData(QSettings* settings) {
|
|||
settings->setValue("position_y", _position.y);
|
||||
settings->setValue("position_z", _position.z);
|
||||
|
||||
settings->setValue("voxelURL", _voxels.getVoxelURL());
|
||||
settings->setValue("pupilDilation", _head.getPupilDilation());
|
||||
|
||||
settings->setValue("leanScale", _leanScale);
|
||||
|
@ -585,7 +507,6 @@ void MyAvatar::loadData(QSettings* settings) {
|
|||
_position.y = loadSetting(settings, "position_y", 0.0f);
|
||||
_position.z = loadSetting(settings, "position_z", 0.0f);
|
||||
|
||||
_voxels.setVoxelURL(settings->value("voxelURL").toUrl());
|
||||
_head.setPupilDilation(settings->value("pupilDilation", 0.0f).toFloat());
|
||||
|
||||
_leanScale = loadSetting(settings, "leanScale", 0.05f);
|
||||
|
@ -612,93 +533,15 @@ glm::vec3 MyAvatar::getEyeLevelPosition() const {
|
|||
glm::vec3(0.0f, _pelvisToHeadLength + _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_UP_OFFSET, 0.0f);
|
||||
}
|
||||
|
||||
float MyAvatar::getBallRenderAlpha(int ball, bool forceRenderHead) const {
|
||||
const float RENDER_OPAQUE_OUTSIDE = _scale * 0.25f; // render opaque if greater than this distance
|
||||
const float DO_NOT_RENDER_INSIDE = _scale * 0.25f; // do not render if less than this distance
|
||||
float distanceToCamera = glm::length(Application::getInstance()->getCamera()->getPosition() - _bodyBall[ball].position);
|
||||
return (forceRenderHead) ? 1.0f : glm::clamp(
|
||||
(distanceToCamera - DO_NOT_RENDER_INSIDE) / (RENDER_OPAQUE_OUTSIDE - DO_NOT_RENDER_INSIDE), 0.f, 1.f);
|
||||
}
|
||||
|
||||
void MyAvatar::renderBody(bool forceRenderHead) {
|
||||
|
||||
if (_head.getVideoFace().isFullFrame()) {
|
||||
// Render the full-frame video
|
||||
float alpha = getBallRenderAlpha(BODY_BALL_HEAD_BASE, forceRenderHead);
|
||||
if (alpha > 0.0f) {
|
||||
_head.getVideoFace().render(1.0f);
|
||||
}
|
||||
} else if (Menu::getInstance()->isOptionChecked(MenuOption::AvatarAsBalls)) {
|
||||
// Render the body as balls and cones
|
||||
glm::vec3 skinColor, darkSkinColor;
|
||||
getSkinColors(skinColor, darkSkinColor);
|
||||
for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) {
|
||||
float alpha = getBallRenderAlpha(b, forceRenderHead);
|
||||
|
||||
// When we have leap hands, hide part of the arms.
|
||||
if (_hand.getNumPalms() > 0) {
|
||||
if (b == BODY_BALL_LEFT_FINGERTIPS
|
||||
|| b == BODY_BALL_RIGHT_FINGERTIPS) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Always render other people, and render myself when beyond threshold distance
|
||||
if (b == BODY_BALL_HEAD_BASE) { // the head is rendered as a special
|
||||
if (alpha > 0.0f) {
|
||||
_head.render(alpha, true);
|
||||
}
|
||||
} else if (alpha > 0.0f) {
|
||||
// Render the body ball sphere
|
||||
if (b == BODY_BALL_RIGHT_ELBOW
|
||||
|| b == BODY_BALL_RIGHT_WRIST
|
||||
|| b == BODY_BALL_RIGHT_FINGERTIPS ) {
|
||||
glColor3f(skinColor.r + _bodyBall[b].touchForce * 0.3f,
|
||||
skinColor.g - _bodyBall[b].touchForce * 0.2f,
|
||||
skinColor.b - _bodyBall[b].touchForce * 0.1f);
|
||||
} else {
|
||||
glColor4f(skinColor.r + _bodyBall[b].touchForce * 0.3f,
|
||||
skinColor.g - _bodyBall[b].touchForce * 0.2f,
|
||||
skinColor.b - _bodyBall[b].touchForce * 0.1f,
|
||||
alpha);
|
||||
}
|
||||
|
||||
if ((b != BODY_BALL_HEAD_TOP )
|
||||
&& (b != BODY_BALL_HEAD_BASE )) {
|
||||
glPushMatrix();
|
||||
glTranslatef(_bodyBall[b].position.x, _bodyBall[b].position.y, _bodyBall[b].position.z);
|
||||
glutSolidSphere(_bodyBall[b].radius, 20.0f, 20.0f);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
// Render the cone connecting this ball to its parent
|
||||
if (_bodyBall[b].parentBall != BODY_BALL_NULL) {
|
||||
if ((b != BODY_BALL_HEAD_TOP)
|
||||
&& (b != BODY_BALL_HEAD_BASE)
|
||||
&& (b != BODY_BALL_PELVIS)
|
||||
&& (b != BODY_BALL_TORSO)
|
||||
&& (b != BODY_BALL_CHEST)
|
||||
&& (b != BODY_BALL_LEFT_COLLAR)
|
||||
&& (b != BODY_BALL_LEFT_SHOULDER)
|
||||
&& (b != BODY_BALL_RIGHT_COLLAR)
|
||||
&& (b != BODY_BALL_RIGHT_SHOULDER)) {
|
||||
glColor3fv((const GLfloat*)&darkSkinColor);
|
||||
|
||||
float r2 = _bodyBall[b].radius * 0.8;
|
||||
|
||||
renderJointConnectingCone(_bodyBall[_bodyBall[b].parentBall].position, _bodyBall[b].position, r2, r2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Render the body's voxels and head
|
||||
if (!_skeletonModel.render(1.0f)) {
|
||||
_voxels.render(false);
|
||||
}
|
||||
float alpha = getBallRenderAlpha(BODY_BALL_HEAD_BASE, forceRenderHead);
|
||||
if (alpha > 0.0f) {
|
||||
_head.render(alpha, false);
|
||||
}
|
||||
_skeletonModel.render(1.0f);
|
||||
_head.render(1.0f, false);
|
||||
}
|
||||
_hand.render(true);
|
||||
}
|
||||
|
@ -980,74 +823,13 @@ void MyAvatar::updateAvatarCollisions(float deltaTime) {
|
|||
NodeList* nodeList = NodeList::getInstance();
|
||||
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
|
||||
if (node->getLinkedData() && node->getType() == NODE_TYPE_AGENT) {
|
||||
Avatar *otherAvatar = (Avatar *)node->getLinkedData();
|
||||
|
||||
// check if the bounding spheres of the two avatars are colliding
|
||||
glm::vec3 vectorBetweenBoundingSpheres(_position - otherAvatar->_position);
|
||||
|
||||
if (glm::length(vectorBetweenBoundingSpheres) < _height * ONE_HALF + otherAvatar->_height * ONE_HALF) {
|
||||
// apply forces from collision
|
||||
applyCollisionWithOtherAvatar(otherAvatar, deltaTime);
|
||||
}
|
||||
// test other avatar hand position for proximity
|
||||
glm::vec3 v(_skeleton.joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position);
|
||||
v -= otherAvatar->getPosition();
|
||||
|
||||
float distance = glm::length(v);
|
||||
if (distance < _distanceToNearestAvatar) {
|
||||
_distanceToNearestAvatar = distance;
|
||||
}
|
||||
//Avatar *otherAvatar = (Avatar *)node->getLinkedData();
|
||||
//
|
||||
// Placeholder: Add code here when we want to add Avatar<->Avatar collision stuff
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// detect collisions with other avatars and respond
|
||||
void MyAvatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime) {
|
||||
|
||||
// for now, don't collide if we have a new skeleton
|
||||
if (_skeletonModel.isActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
glm::vec3 bodyPushForce = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
// 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_BODY_BALLS; o++) {
|
||||
if (otherAvatar->_bodyBall[o].isCollidable) {
|
||||
|
||||
glm::vec3 vectorBetweenBalls(_bodyBall[b].position - otherAvatar->_bodyBall[o].position);
|
||||
float distanceBetweenBalls = glm::length(vectorBetweenBalls);
|
||||
|
||||
if (distanceBetweenBalls > 0.0) { // to avoid divide by zero
|
||||
float combinedRadius = _bodyBall[b].radius + otherAvatar->_bodyBall[o].radius;
|
||||
|
||||
// check for collision
|
||||
if (distanceBetweenBalls < combinedRadius * COLLISION_RADIUS_SCALAR) {
|
||||
glm::vec3 directionVector = vectorBetweenBalls / distanceBetweenBalls;
|
||||
|
||||
// push balls away from each other and apply friction
|
||||
float penetration = 1.0f - (distanceBetweenBalls / (combinedRadius * COLLISION_RADIUS_SCALAR));
|
||||
|
||||
glm::vec3 ballPushForce = directionVector * COLLISION_BALL_FORCE * penetration * deltaTime;
|
||||
bodyPushForce += directionVector * COLLISION_BODY_FORCE * penetration * deltaTime;
|
||||
|
||||
_bodyBall[b].velocity += ballPushForce;
|
||||
otherAvatar->_bodyBall[o].velocity -= ballPushForce;
|
||||
|
||||
}// check for collision
|
||||
} // to avoid divide by zero
|
||||
} // o loop
|
||||
} // collidable
|
||||
} // b loop
|
||||
} // collidable
|
||||
|
||||
// apply force on the whole body
|
||||
_velocity += bodyPushForce;
|
||||
}
|
||||
|
||||
class SortedAvatar {
|
||||
public:
|
||||
Avatar* avatar;
|
||||
|
@ -1166,23 +948,6 @@ void MyAvatar::setGravity(glm::vec3 gravity) {
|
|||
}
|
||||
}
|
||||
|
||||
void MyAvatar::checkForMouseRayTouching() {
|
||||
|
||||
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);
|
||||
|
||||
float range = _bodyBall[b].radius * MOUSE_RAY_TOUCH_RANGE;
|
||||
|
||||
if (dot > (1.0f - range)) {
|
||||
_bodyBall[b].touchForce = (dot - (1.0f - range)) / range;
|
||||
} else {
|
||||
_bodyBall[b].touchForce = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MyAvatar::setOrientation(const glm::quat& orientation) {
|
||||
glm::vec3 eulerAngles = safeEulerAngles(orientation);
|
||||
_bodyPitch = eulerAngles.x;
|
||||
|
|
|
@ -88,7 +88,6 @@ private:
|
|||
int _moveTargetStepCounter;
|
||||
|
||||
// private methods
|
||||
float getBallRenderAlpha(int ball, bool forceRenderHead) const;
|
||||
void renderBody(bool forceRenderHead);
|
||||
void updateThrust(float deltaTime, Transmitter * transmitter);
|
||||
void updateHandMovementAndTouching(float deltaTime, bool enableHandMovement);
|
||||
|
@ -97,9 +96,7 @@ private:
|
|||
void updateCollisionWithVoxels(float deltaTime);
|
||||
void applyHardCollision(const glm::vec3& penetration, float elasticity, float damping);
|
||||
void updateCollisionSound(const glm::vec3& penetration, float deltaTime, float frequency);
|
||||
void applyCollisionWithOtherAvatar( Avatar * other, float deltaTime );
|
||||
void updateChatCircle(float deltaTime);
|
||||
void checkForMouseRayTouching();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue