void SE_BipedController::createBoneBaseMatrixInverse() { mBindposeMatrixInverse.clear(); for(int i = 0; i < oneBipAnimation.size(); ++i) { SE_Matrix4f bp = oneBipAnimation[i]->bind_pose; mBindposeMatrixInverse.push_back(bp.inverse()); } }
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(); } }
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(); }
void SE_Camera::getFrustumPlanes(SE_Plane planes[6]) const { if(!mChanged) { for(int i = 0 ; i < 6 ; i++) { planes[i] = mPlanes[i]; } return; } SE_Plane lplanes[6]; lplanes[0] = mFrustum.getLeftPlane(); lplanes[1] = mFrustum.getRightPlane(); lplanes[2] = mFrustum.getTopPlane(); lplanes[3] = mFrustum.getBottomPlane(); lplanes[4] = mFrustum.getNearPlane(); lplanes[5] = mFrustum.getFarPlane(); SE_Matrix4f vtom = getViewToWorldMatrix(); vtom = vtom.inverse(); vtom = vtom.transpose(); for(int i = 0 ; i < 6 ; i++) { SE_Plane p = lplanes[i].transform(vtom); planes[i].set(p.getNormal().neg(), p.getDistance()); mPlanes[i] = planes[i]; } #ifdef DEBUG /* SE_Plane nplanes[6]; SE_Vector3f NearLeftBottom, NearLeftTop, NearRightBottom, NearRightTop, FarLeftBottom, FarLeftTop, FarRightBottom, FarRightTop; SE_Vector3f tmp1; SE_Vector3f tmp[4]; SE_Rect<float> nearplane = mFrustum.getNearPlaneRect(); tmp[0] = mAxisZ.mul(-mFrustum.getNear()); tmp[1] = mAxisX.mul(nearplane.left); tmp[2] = mAxisY.mul(nearplane.bottom); tmp[3] = mLocation; NearLeftBottom = tmp[0] + tmp[1] + tmp[2] + tmp[3]; tmp1 = tmp[0] + tmp[1] + tmp[2]; tmp1 = tmp1.mul(mFrustum.getFar() / mFrustum.getNear()); FarLeftBottom = mLocation + tmp1; tmp[1] = mAxisX.mul(nearplane.left); tmp[2] = mAxisY.mul(nearplane.top); NearLeftTop = tmp[0] + tmp[1] + tmp[2] + tmp[3]; tmp1 = tmp[0] + tmp[1] + tmp[2]; tmp1 = tmp1.mul(mFrustum.getFar() / mFrustum.getNear()); FarLeftTop = mLocation + tmp1; tmp[1] = mAxisX.mul(nearplane.right); tmp[2] = mAxisY.mul(nearplane.bottom); NearRightBottom = tmp[0] + tmp[1] + tmp[2] + tmp[3]; tmp1 = tmp[0] + tmp[1] + tmp[2]; tmp1 = tmp1.mul(mFrustum.getFar() / mFrustum.getNear()); FarRightBottom = mLocation + tmp1; tmp[1] = mAxisX.mul(nearplane.right); tmp[2] = mAxisY.mul(nearplane.top); NearRightTop = tmp[0] + tmp[1] + tmp[2] + tmp[3]; tmp1 = tmp[0] + tmp[1] + tmp[2]; tmp1 = tmp1.mul(mFrustum.getFar() / mFrustum.getNear()); FarRightTop = mLocation + tmp1; nplanes[0].set(NearLeftBottom, mLocation, NearLeftTop); nplanes[1].set(NearRightTop, mLocation, NearRightBottom); nplanes[2].set(mLocation, NearLeftBottom, NearRightBottom); nplanes[3].set(mLocation, NearRightTop, NearLeftTop); nplanes[4].set(NearLeftBottom, NearRightBottom, NearRightTop); nplanes[5].set(FarLeftBottom, FarLeftTop, FarRightTop); for(int i = 0 ; i < 6 ; i++) { planes[i] = nplanes[i]; } */ #endif }
SE_Matrix4f SE_Camera::getWorldToViewMatrix() const { SE_Matrix4f vtow = getViewToWorldMatrix(); return vtow.inverse(); }