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); } }
void SE_BoneAnimation::onEnd() { if(!mSimObject) return; if(!mMesh) return; SE_Matrix4f m; m.identity(); mSimObject->setWorldMatrix(m); mSimObject->setUseWorldMatrix(false); mSimObject->setPrimitiveType(TRIANGLES); mMesh->clearVertexInfo(); }
void View::setPosition(float x, float y) { mX = x; mY = y; SE_Matrix3f identity3; identity3.identity(); SE_Matrix4f transform; transform.identity(); transform.set(identity3,SE_Vector3f(mX,mY,0)); setPrevMatrix(transform); //update updateWorldTransform(); updateBoundingVolume(); }
void SE_BoneAnimation::onRun() { if(!mSkinJointController) return; SE_Bone* bone = mSkinJointController->mBoneVector[0]; int num = bone->getMatrixNum(); setFrameNum(num); setTimePerFrame(getDuration() / num); mMesh = mSimObject->getMesh(); SE_Matrix4f m; m.identity(); mSimObject->setWorldMatrix(m); mSimObject->setUseWorldMatrix(true); mSimObject->setPrimitiveType(TRIANGLES_INDEX); mMesh->clearVertexInfo(); mSkinJointController->createBoneBaseMatrixInverse(); }
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(); }