More work on Kinect-driven joints.

This commit is contained in:
Andrzej Kapolka 2013-07-02 16:49:07 -07:00
parent 4f01db6dc7
commit 1fdfca727d
2 changed files with 23 additions and 7 deletions

View file

@ -305,7 +305,7 @@ void Avatar::updateFromGyrosAndOrWebcam() {
const JointVector& joints = webcam->getEstimatedJoints();
_joints.clear();
for (int i = 0; i < NUM_AVATAR_JOINTS; i++) {
if (joints[i].isValid) {
if (joints.size() > i && joints[i].isValid) {
JointData data = { i, joints[i].position, joints[i].orientation };
_joints.push_back(data);
}
@ -503,7 +503,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
_skeleton.joint[it->jointID].position = _position + orientation * it->position;
AvatarJointID derivedJointID = AVATAR_JOINT_NULL;
AvatarJointID secondJointID = (AvatarJointID)it->jointID;
AvatarJointID secondJointID = AVATAR_JOINT_NULL;
float proportion = 0.5f;
switch (it->jointID) {
case AVATAR_JOINT_NECK_BASE:
@ -547,10 +547,17 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
break;
}
if (derivedJointID != AVATAR_JOINT_NULL) {
_skeleton.joint[derivedJointID].position = glm::mix(_skeleton.joint[it->jointID].position,
_skeleton.joint[secondJointID].position, proportion);
_skeleton.joint[derivedJointID].absoluteRotation = safeMix(_skeleton.joint[it->jointID].absoluteRotation,
_skeleton.joint[secondJointID].absoluteRotation, proportion);
if (secondJointID == AVATAR_JOINT_NULL) {
_skeleton.joint[derivedJointID].position = _skeleton.joint[it->jointID].position +
_skeleton.joint[it->jointID].absoluteRotation * JOINT_DIRECTION * _skeleton.joint[derivedJointID].length;
_skeleton.joint[derivedJointID].absoluteRotation = _skeleton.joint[it->jointID].absoluteRotation;
} else {
_skeleton.joint[derivedJointID].position = glm::mix(_skeleton.joint[it->jointID].position,
_skeleton.joint[secondJointID].position, proportion);
_skeleton.joint[derivedJointID].absoluteRotation = safeMix(_skeleton.joint[it->jointID].absoluteRotation,
_skeleton.joint[secondJointID].absoluteRotation, proportion);
}
}
}

View file

@ -108,11 +108,16 @@ void Webcam::renderPreview(int screenWidth, int screenHeight) {
glPointSize(4.0f);
glBegin(GL_POINTS);
float projectedScale = PREVIEW_HEIGHT / (float)_depthHeight;
int idx = 0;
foreach (const Joint& joint, _joints) {
if (joint.isValid) {
if (joint.projected.x == 0.0f && joint.projected.y == 0.0f) {
printLog("%d\n", idx);
}
glVertex2f(depthLeft + joint.projected.x * projectedScale,
top - PREVIEW_HEIGHT + joint.projected.y * projectedScale);
}
idx++;
}
glEnd();
glPointSize(1.0f);
@ -210,7 +215,8 @@ void Webcam::setFrame(const Mat& frame, int format, const Mat& depth, const Rota
const float JOINT_SMOOTHING = 0.95f;
_estimatedJoints[i].isValid = true;
_estimatedJoints[i].position = glm::mix(_joints[i].position, _estimatedJoints[i].position, JOINT_SMOOTHING);
_estimatedJoints[i].orientation = safeMix(_joints[i].orientation, _estimatedJoints[i].orientation, JOINT_SMOOTHING);
_estimatedJoints[i].orientation = safeMix(_joints[i].orientation,
_estimatedJoints[i].orientation, JOINT_SMOOTHING);
}
_estimatedRotation = safeEulerAngles(_estimatedJoints[AVATAR_JOINT_HEAD_BASE].orientation);
_estimatedPosition = _estimatedJoints[AVATAR_JOINT_HEAD_BASE].position;
@ -359,6 +365,9 @@ void FrameGrabber::grabFrame() {
_userGenerator.GetUsers(&_userID, userCount);
if (userCount > 0 && _userGenerator.GetSkeletonCap().IsTracking(_userID)) {
joints.resize(NUM_AVATAR_JOINTS);
for (int i = 0; i < NUM_AVATAR_JOINTS; i++) {
joints[i].isValid = false;
}
const int MAX_ACTIVE_JOINTS = 16;
XnSkeletonJoint activeJoints[MAX_ACTIVE_JOINTS];
XnUInt16 activeJointCount = MAX_ACTIVE_JOINTS;