none
BlockMan joint orientations RRS feed

  • Question

  • Hi,

    I am looking at the BlockMan sample in the Kinect 2 SDK and wanted to clarify that my understanding of the following code is correct:

    void BlockManPanel::OnBodyFrame(_In_ BodyFrame^ bodyFrame)
    {
        if (nullptr == _bodies)
        {
            _bodies = ref new Platform::Collections::Vector<Body^>(bodyFrame->BodyCount);;
        }
    
        bodyFrame->GetAndRefreshBodyData(_bodies);
    
        for (int iBody = 0; iBody < bodyFrame->BodyCount; ++iBody)
        {
            IBody^ body = _bodies->GetAt(iBody);
            if (nullptr == body)
            {
                continue;
            }
    
            BOOLEAN bTracked = false;
            if (!body->IsTracked)
            {
                _blockMen[iBody].Reset();
    
                continue;
            }
    
            IMapView<JointType, Joint>^ joints = body->Joints;
            IMapView<JointType, JointOrientation>^ jointOrientations = body->JointOrientations;
            {
                for (UINT i = 0; i < joints->Size; i++)
                {
                    JointType jt = static_cast<JointType>(i);
    
                    // TODO: update when head orientation is fixed
                    if (jt == JointType::Head)
                    {
                        continue;
                    }
    
                    JointOrientation jo = jointOrientations->Lookup(jt);
                    _blockMen[iBody]._JointOrientations[i] = SmoothQuaternion(_blockMen[iBody]._JointOrientations[i], XMLoadFloat4((XMFLOAT4*) &jo.Orientation));
                }
    
                for (int blockIndex = 0; blockIndex < BLOCK_COUNT; ++blockIndex)
                {
                    JointType jointIndex = g_SkeletonBlocks[blockIndex].SkeletonJoint;
                    int parentIndex = g_SkeletonBlocks[blockIndex].ParentBlockIndex;
    
                    XMVECTOR translateFromParent = g_SkeletonBlocks[blockIndex].CenterFromParentCenter;
                    XMMATRIX parentTransform = (parentIndex > -1) ? _blockMen[iBody]._BlockTransforms[parentIndex] : XMMatrixIdentity();
                    XMVECTOR position = XMVector3Transform(translateFromParent, parentTransform);
    
                    XMVECTOR rotationQuat = XMVectorZero();
    
                    if (XMVector4Equal(_blockMen[iBody]._JointOrientations[(int)jointIndex], XMVectorZero()))
                    {
                        if (parentIndex > -1)
                        {
                            if (XMVector4Equal(_blockMen[iBody]._JointOrientations[parentIndex], XMVectorZero()))
                            {
                                rotationQuat = XMQuaternionIdentity();
                            }
                            else
                            {
                                rotationQuat = _blockMen[iBody]._JointOrientations[parentIndex];
                            }
                        }
                    }
                    else
                    {
                        rotationQuat = _blockMen[iBody]._JointOrientations[(int) jointIndex];
                    }
    
                    XMMATRIX translation = XMMatrixTranslationFromVector(position);
                    XMMATRIX scale = XMMatrixScalingFromVector(g_SkeletonBlocks[blockIndex].Scale);
                    XMMATRIX rotation = XMMatrixRotationQuaternion(rotationQuat);
    
                    _blockMen[iBody]._BlockTransforms[blockIndex] = scale * rotation * translation;
                }
    
                Joint joint = joints->Lookup(JointType::SpineBase);
    
                _blockMen[iBody]._position = XMLoadFloat4((XMFLOAT4*) &(joint.Position));
            }
        }
    }
    

    Is it true that, on each body frame the blockTransform that is applied, is actually a transformation that is applied to a rectangle that represents a "bone", this is because I am looking to avateer a rigid 3d model using this approach, but I can only transform the joints.. in the case of a rigid model, how would one go about this? 

    Thanks

    Wednesday, December 7, 2016 3:36 PM