SE_Matrix4f SE_BufferInput::readMatrix4f() { SE_Matrix4f m; for(int i = 0 ; i < 4 ; i++) { for(int j = 0 ; j < 4 ; j++) { m.set(i, j, readFloat()); } } return m; }
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_NewGeometry::updateWorldTransform() { SE_Spatial::updateWorldTransform(); SE_Matrix4f localM; localM.set(getLocalRotate().toMatrix3f(), getLocalScale(), getLocalTranslate()); mWorldTransform = getPrevMatrix().mul(localM).mul(getPostMatrix()); SE_NewGeometry::_Impl::SimObjectList::iterator it; for(it = mImpl->attachObject.begin() ; it != mImpl->attachObject.end() ; it++) { (*it)->doTransform(getWorldTransform()); } std::list<SE_Spatial*>::iterator itchild = mImplchild->children.begin(); for(; itchild != mImplchild->children.end() ; itchild++) { SE_Spatial* s = *itchild; s->updateWorldTransform(); } }
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_BipedController::fillBoneToWorldPerFrame() { int maxFrameIndex = findMaxFrameIndex(); for(int i = 0; i < oneBipAnimation.size(); ++i) { //get bip one by one SE_Biped *bip = oneBipAnimation[i]; //fill bonetoworld for every frame for(int j = 0; j < maxFrameIndex + 1; ++j) { if(bip->parent) { SE_Matrix4f * m = new SE_Matrix4f(); SE_Matrix4f myTrans; if(bip->animationInfo.size() > 0) { //FIXME: the parent Allways has keyframe when child has keyframe myTrans.set(bip->animationInfo[j]->rotateQ.toMatrix3f(),SE_Vector3f(1,1,1),bip->animationInfo[j]->translate); *m = bip->parent->boneToWorldPerFrame[j]->mul(myTrans); } else { //this bip on this frame has no key. *m = bip->bind_pose; } bip->boneToWorldPerFrame.push_back(m); } else { //this bip is ROOT SE_Matrix4f * m = new SE_Matrix4f(); *m = bip->bind_pose; bip->boneToWorldPerFrame.push_back(m); } } } }
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(); }