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();
}
예제 #2
0
void SE_Camera::rotateLocal(const SE_Quat& rotate)
{
    SE_Vector3f localxAxis(1, 0, 0);
    SE_Vector3f localyAxis(0, 1, 0);
    SE_Vector3f localzAxis(0, 0, 1);
    localxAxis = rotate.map(localxAxis);
    localyAxis = rotate.map(localyAxis);
    //localzAxis = rotate.map(zAxis);
    SE_Matrix4f vtom = getViewToWorldMatrix();
    SE_Vector4f worldxAxis = vtom.map(SE_Vector4f(localxAxis, 0));
    SE_Vector4f worldyAxis = vtom.map(SE_Vector4f(localyAxis, 0));
    //SE_Vector4f worldzAxis = vtom.map(SE_Vector4f(localzAxis, 0));
	SE_Vector4f worldzAxis(worldxAxis.xyz().cross(worldyAxis.xyz()), 0);
    mAxisX = worldxAxis.normalize().xyz();
    mAxisY = worldyAxis.normalize().xyz();
    mAxisZ = worldzAxis.normalize().xyz();
    mChanged = true;
}
예제 #3
0
void SE_BoneAnimation::onUpdate(SE_TimeMS realDelta, SE_TimeMS simulateDelta, float percent, int frameIndex)
{
	if(getCurrentFrame() == frameIndex)
		return;
    if(!mSkinJointController)
        return;
    if(!mMesh)
        return;
    int surfaceNum = mMesh->getSurfaceNum();
    for(int i = 0 ; i < surfaceNum ; i++)
    {
        SE_Surface* surface = mMesh->getSurface(i);
        _Vector3f* vertex = NULL;
        int vertexNum = 0;
        int* vertexIndex = NULL;
        int vertexIndexNum = 0;
        surface->getVertex(vertex, vertexNum);
		if(!mVertex)
		{
			mVertexNum = vertexNum;
			mVertex = new _Vector3f[vertexNum];
			memcpy(mVertex, vertex, sizeof(_Vector3f) * vertexNum);
		}
        surface->getVertexIndexInGeometryData(vertexIndex, vertexIndexNum);
        if(vertex)
        {
			mSkinJointController->createBoneToWorldMatrix(frameIndex);
            for(int j = 0 ; j < vertexNum ; j++)
            {
                SE_Vector3f v(mVertex[j].d[0], mVertex[j].d[1], mVertex[j].d[2]);
				SE_Spatial* spatial = mSimObject->getSpatial();
				SE_Matrix4f worldTM = spatial->getWorldTransform();
				SE_Vector4f v4(v.x, v.y, v.z, 1.0);
				v4 = worldTM.map(v4);
				v = v4.xyz();
                v = mSkinJointController->convert(vertexIndex[j], frameIndex, v4.xyz());
                vertex[j].d[0] = v.x;
                vertex[j].d[1] = v.y;
                vertex[j].d[2] = v.z;
            }
        }
    }
}
예제 #4
0
void SE_GeometryData::transform(SE_GeometryData* src, const SE_Matrix4f& m, SE_GeometryData* dst)
{
    SE_Vector3f* vertex = NULL;
    SE_Vector3i* faces = NULL;
    SE_Vector3f* facenormal = NULL;
    SE_Vector3f* facevertexnormal = NULL;

    int vertexNum = 0;
    int faceNum = 0;
    int facenormalNum = 0;
    int facevertexnormalNum = 0;

    if(src->vertexArray)
    {
        vertex = new SE_Vector3f[src->vertexNum];
        for(int i = 0 ; i < src->vertexNum ; i++)
        {
            SE_Vector4f v(src->vertexArray[i], 1.0f);
            v = m.map(v);
            vertex[i] = v.xyz();
        }
        vertexNum = src->vertexNum;
    }
    /*
    if(src->faceArray)
    {
        faces = new SE_Vector3i[src->faceNum];
        for(int i = 0 ; i < src->faceNum; i++)
        {
            faces[i] = src->faceArray[i];
        }
        faceNum = src->faceNum;
    }
    */
    if(src->faceNormalArray)
    {
        /*
        //SE_Matrix3f t = m.toMatrix3f();
        //if(t.hasInverse())
        //{
            SE_Matrix4f inverse = m.inverse();
            inverse = inverse.transpose();
            facenormal = new SE_Vector3f[src->faceNormalNum];
            for(int i = 0 ; i < src->faceNormalNum ; i++)
            {
                facenormal[i] = (inverse.map(SE_Vector4f(src->faceNormalArray[i],0))).xyz();
                LOGI("facevertexnormal[%d].x = %f\n",i,facenormal[i].x);
                LOGI("facevertexnormal[%d].y = %f\n",i,facenormal[i].y);
                LOGI("facevertexnormal[%d].z = %f\n",i,facenormal[i].z);
            }
            facenormalNum = src->faceNormalNum;
        //}
        */
    }

    if(src->faceVertexNormalArray)
    {
        /*
        SE_Matrix3f t = m.toMatrix3f();
        if(t.hasInverse())
        {
            SE_Matrix3f inverse = t.inverse();
            inverse = inverse.transpose();
            facevertexnormal = new SE_Vector3f[src->faceVertexNormalNum];
            for(int i = 0 ; i < src->faceVertexNormalNum ; i++)
            {
                facevertexnormal[i] = inverse.map(src->faceVertexNormalArray[i]);
                LOGI("facevertexnormal[%d].x = %f\n",i,facevertexnormal[i].x);
                LOGI("facevertexnormal[%d].y = %f\n",i,facevertexnormal[i].y);
                LOGI("facevertexnormal[%d].z = %f\n",i,facevertexnormal[i].z);
            }
            facevertexnormalNum = src->faceVertexNormalNum;
        }
        */
    }

    dst->setVertexArray(vertex, vertexNum);
    dst->setFaceArray(src->faceArray, src->faceNum, false);
    dst->setFaceNormalArray(facenormal, facenormalNum);
    dst->setFaceVertexNormalArray(facevertexnormal,facevertexnormalNum);
}
예제 #5
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();
}