Esempio n. 1
0
void SE_BipedController::finalTransformMatrix(int frameindex)
{
    for(int i = 0; i < oneBipAnimation.size(); ++i)
    {
        //use local coordinate.
        SE_Matrix4f worldToModel = mOriginalModelToWorld.inverse();

        SE_Matrix4f finalMatrix = worldToModel.mul(mAfterTransformMatrixToWorld[i]).mul(mBindposeMatrixInverse[i]).mul(mOriginalModelToWorld);

        AllFrameFinalTransformMatrix[frameindex].push_back(finalMatrix);
    }


    for(int i = 0; i < AllFrameFinalTransformMatrix[frameindex].size(); ++i)
    {
        float f[16];
        
        SE_Matrix4f m = AllFrameFinalTransformMatrix[frameindex][i];        

        m.getColumnSequence(f);

        for(int j = 0; j < 16; ++j)
        {
            AllFrameFinalTransformToShader[frameindex].push_back(f[j]);
        }
    }        

}
Esempio n. 2
0
SE_Vector3f SE_SimObject::localToWorld(const SE_Vector3f& v)
{
    SE_Spatial* spatial = getSpatial();
    SE_Matrix4f worldTransform = spatial->getWorldTransform();
    SE_Vector4f v4(v, 1);
    v4 = worldTransform.mul(getLocalMatrix()).map(v4);
    return v4.xyz();
}
SE_Vector3f SE_SkinJointController::convert(int vertexIndex, int boneMatrixIndex, const SE_Vector3f& v)
{
    BoneWeightVector bwv = mVertexBoneWeightInfo[vertexIndex];
    BoneWeightVector::iterator it;
    SE_Vector4f result(0, 0, 0, 0);
    SE_Vector4f inputV(v.x, v.y, v.z, 1.0);
    for(it = bwv.begin() ; it != bwv.end() ; it++)
    {
        int boneIndex = it->boneIndex;
        float weight = it->weight;
        SE_Bone* bone = mBoneVector[boneIndex - 1];
		/*
        SE_Matrix4f boneBaseMatrix = bone->getBaseMatrix();
        SE_Matrix4f worldToBone;
        SE_Matrix4f boneToWorld;
        if(boneMatrixIndex == -1)
        {
            boneToWorld = bone->getBaseMatrix();
        }
        else
        {
            boneToWorld = bone->getMatrix(boneMatrixIndex);
        }
        SE_Bone* parent = bone->getParent();
        while(parent != NULL)
        {
            SE_Matrix4f parentBoneMatrix;
            if(boneMatrixIndex == -1)
                parentBoneMatrix = parent->getBaseMatrix();
            else
                parentBoneMatrix = parent->getMatrix(boneMatrixIndex);
            boneToWorld = parentBoneMatrix.mul(boneToWorld);
			SE_Matrix4f parentBaseBoneMatrix = parent->getBaseMatrix();
			boneBaseMatrix = parentBaseBoneMatrix.mul(boneBaseMatrix);
			parent = parent->getParent();
        }
        SE_Matrix4f boneBaseMatrixInverse = boneBaseMatrix.inverse();
        SE_Matrix4f m = boneToWorld.mul(boneBaseMatrixInverse);
		*/
		SE_Matrix4f boneBaseMatrixInverse = mBoneBaseMatrixInverse[boneIndex - 1];
		SE_Matrix4f boneToWorld = mBoneToWorldMatrix[boneIndex - 1];
		SE_Matrix4f m = boneToWorld.mul(boneBaseMatrixInverse);
        result = result + m.map(inputV) * weight;
    }
    return result.xyz();
}
void SE_SkinJointController::createBoneBaseMatrixInverse()
{
	mBoneBaseMatrixInverse.resize(mBoneVector.size());
	for(int i = 0 ; i < mBoneVector.size() ; i++)
	{
		SE_Bone* bone = mBoneVector[i];
		SE_Matrix4f boneBaseMatrix = bone->getBaseMatrix();
		SE_Bone* parent = bone->getParent();
		while(parent)
		{
			SE_Matrix4f parentBaseMatrix = parent->getBaseMatrix();
			boneBaseMatrix = parentBaseMatrix.mul(boneBaseMatrix);
			parent = parent->getParent();
		}
		mBoneBaseMatrixInverse[i] = boneBaseMatrix.inverse();
	}
}
void SE_SkinJointController::createBoneToWorldMatrix(int boneMatrixIndex)
{
	if(mBoneToWorldMatrix.size() == 0)
		mBoneToWorldMatrix.resize(mBoneVector.size());
	for(int i = 0 ; i < mBoneVector.size() ; i++)
	{
		SE_Bone* bone = mBoneVector[i];
		SE_Bone* parent = bone->getParent();
		SE_Matrix4f boneToWorld = bone->getMatrix(boneMatrixIndex);
        while(parent)
		{
			SE_Matrix4f parentBoneToWorld = parent->getMatrix(boneMatrixIndex);
			boneToWorld = parentBoneToWorld.mul(boneToWorld);
			parent = parent->getParent();
		}
		mBoneToWorldMatrix[i] = boneToWorld;
	}
}
Esempio n. 6
0
void SE_BipedController::createBoneToWorldMatrix(int frameindex)
{

    //per frame refresh;
    mAfterTransformMatrixToWorld.clear();    

    for(int i = 0; i < oneBipAnimation.size(); ++i)
    {
        SE_Biped * bip = oneBipAnimation[i];

        SE_Matrix4f transform;        

        if(bip->animationInfo.size() == 0)
        {
            transform.identity();            
        }
        else
        {
            SE_Quat worldR = bip->animationInfo[frameindex]->rotateQ;
            SE_Vector3f worldT = bip->animationInfo[frameindex]->translate;
            SE_Vector3f worldS = bip->animationInfo[frameindex]->scale;
            
            //not use scale
            transform.set(worldR.toMatrix3f(),SE_Vector3f(1,1,1),worldT);//myTransform relate parent
        
        }

        SE_Matrix4f parentBoneToWorld;
        parentBoneToWorld.identity();


        if(bip->parent)
        {
            parentBoneToWorld = *(bip->parent->boneToWorldPerFrame[frameindex]);
        }
        else
        {
            //this bip is ROOT,the transform is world relative;
        }

        SE_Matrix4f tranToWorld = parentBoneToWorld.mul(transform);
        mAfterTransformMatrixToWorld.push_back(tranToWorld);
    }    
}
Esempio n. 7
0
SE_Vector3f SE_BipedController::convert(int vertexIndex,int frameindex,const char * objname, const SE_Vector3f& v)
{
    SE_Vector4f input;
    input.set(v,1);
    SE_Vector4f result(0,0,0,0);

    SE_SkeletonUnit *su = findSU(objname);

    //bipedIndex.size is number that how many bips effact this vertext.
    int bipNumPerVertex = su->objVertexBlendInfo[vertexIndex]->bipedIndex.size();  

    //how many bips will take effact to one vertex
    for(int i = 0; i < bipNumPerVertex; ++i)
    {
        int bipIndex = su->objVertexBlendInfo[vertexIndex]->bipedIndex[i];//bipIndex is start from 1, not 0.

        int bipindexfromcache = su->bipCache[bipIndex-1]->bipIndexOnBipAnimation;

        SE_Biped *bip = oneBipAnimation[bipindexfromcache];// find bip from all bips

        if(bip->animationInfo.size() == 0)
        {
            continue;
        }

#ifdef _FORDEBUG
        SE_Matrix4f bindpos = bip->bind_pose;
        SE_Matrix4f inversOfbp = bindpos.inverse();

        SE_Quat worldR = bip->animationInfo[frameindex]->rotateQ;
        SE_Vector3f worldT = bip->animationInfo[frameindex]->translate;
        SE_Vector3f worldS = bip->animationInfo[frameindex]->scale;

        SE_Matrix4f transform;
        transform.identity();
        //not use scale
        transform.set(worldR.toMatrix3f(),SE_Vector3f(1,1,1),worldT);//myTransform relate parent        

        SE_Matrix4f parentBoneToWorld;
        parentBoneToWorld.identity();

        if(bip->parent)
        {
            parentBoneToWorld = *(bip->parent->boneToWorldPerFrame[frameindex]);
        }
        else
        {
            //this bip is ROOT,the transform is world relative;
        }        

        SE_Matrix4f m = parentBoneToWorld.mul(transform).mul(inversOfbp);

        SE_Matrix4f m = mAfterTransformMatrixToWorld[bipindexfromcache].mul(mBindposeMatrixInverse[bipindexfromcache]);
#else
        SE_Matrix4f m = AllFrameFinalTransformMatrix[frameindex][bipindexfromcache];
#endif

        result = result + m.map(input) * su->objVertexBlendInfo[vertexIndex]->weight[i];
    }
    return result.xyz();
}