void Joint::updateJointMatrix(const kmMat4& bindShape, kmVec4* matrixPalette) { // Note: If more than one MeshSkin influences this Joint, we need to skip // the _jointMatrixDirty optimization since updateJointMatrix() may be // called multiple times a frame with different bindShape matrices (and // different matrixPallete pointers). if (_skin.next || _jointMatrixDirty) { _jointMatrixDirty = false; static kmMat4 t = mat4Identity; //Matrix::multiply(Node::getWorldMatrix(), getInverseBindPose(), &t); //Matrix::multiply(t, bindShape, &t); kmMat4Multiply(&t, &Node::getWorldMatrix(), &getInverseBindPose()); kmMat4Multiply(&t, &t, &bindShape); GP_ASSERT(matrixPalette); //matrixPalette[0].set(t.m[0], t.m[4], t.m[8], t.m[12]); //matrixPalette[1].set(t.m[1], t.m[5], t.m[9], t.m[13]); //matrixPalette[2].set(t.m[2], t.m[6], t.m[10], t.m[14]); kmVec4Fill(&matrixPalette[0], t.mat[0], t.mat[4], t.mat[8], t.mat[12]); kmVec4Fill(&matrixPalette[1], t.mat[1], t.mat[5], t.mat[9], t.mat[13]); kmVec4Fill(&matrixPalette[2], t.mat[2], t.mat[6], t.mat[10], t.mat[14]); } }
bool Renderer::checkVisibility(const kmMat4 &transform, const Size &size) { // half size of the screen Size screen_half = Director::getInstance()->getWinSize(); screen_half.width /= 2; screen_half.height /= 2; float hSizeX = size.width/2; float hSizeY = size.height/2; kmVec4 v4world, v4local; kmVec4Fill(&v4local, hSizeX, hSizeY, 0, 1); kmVec4MultiplyMat4(&v4world, &v4local, &transform); // center of screen is (0,0) v4world.x -= screen_half.width; v4world.y -= screen_half.height; // convert content size to world coordinates float wshw = std::max(fabsf(hSizeX * transform.mat[0] + hSizeY * transform.mat[4]), fabsf(hSizeX * transform.mat[0] - hSizeY * transform.mat[4])); float wshh = std::max(fabsf(hSizeX * transform.mat[1] + hSizeY * transform.mat[5]), fabsf(hSizeX * transform.mat[1] - hSizeY * transform.mat[5])); // compare if it in the positive quadrant of the screen float tmpx = (fabsf(v4world.x)-wshw); float tmpy = (fabsf(v4world.y)-wshh); bool ret = (tmpx < screen_half.width && tmpy < screen_half.height); return ret; }
kmVec3* kmVec3TransformCoord(kmVec3* pOut, const kmVec3* pV, const kmMat4* pM) { /* a = (Vx, Vy, Vz, 1) b = (a×M)T Out = 1⁄bw(bx, by, bz) */ kmVec4 v; kmVec4 inV; kmVec4Fill(&inV, pV->x, pV->y, pV->z, 1.0); kmVec4Transform(&v, &inV,pM); pOut->x = v.x / v.w; pOut->y = v.y / v.w; pOut->z = v.z / v.w; return pOut; }
bool CSkin::Load() { bool bRet = false; BEATS_ASSERT(!IsLoaded(), _T("Can't Load a skin which is already loaded!")); // Load From File CSerializer serializer(_T("..\\Resource\\skin\\org.skin")); CSerializer tmpVerticesBufferPos, tmpVerticesBufferUV; CSerializer indexBuffer; size_t uVertexCount = 0; serializer >> uVertexCount; m_uVertexCount = uVertexCount; m_vertices = new CVertexPTB[uVertexCount]; float x, y, z; float u,v; for (size_t i = 0; i < uVertexCount; ++i) { ESkeletonBoneType bone, bone1, bone2, bone3; float weight, weight1, weight2,weight3; serializer >> x >> y >> z >> u >> v; serializer >> bone; serializer >> weight; serializer >> bone1; serializer >> weight1; serializer >> bone2; serializer >> weight2; serializer >> bone3; serializer >> weight3; CVertexPTB &vertex = m_vertices[i]; kmVec3Fill(&vertex.position,x,y,z); vertex.tex = CTex(u,v); vertex.bones = CIVector4(bone, bone1, bone2, bone3); kmVec4Fill(&vertex.weights,weight,weight1,weight2,weight3); #ifdef _DEBUG float sum = weight + weight1 + weight2+weight3; BEATS_ASSERT(sum < 1.01F, _T("Weight can't be greater than 1.01F, cur Value : %f!"), sum); BEATS_WARNING(sum > 0.99F, _T("Weight can't be smaller than 0.99F, cur Value : %f!"), sum); #endif } for (size_t i = 0; i < uVertexCount; ++i) { indexBuffer << (short)i; } CRenderer* pRenderer = CRenderer::GetInstance(); pRenderer->GenVertexArrays(1, &m_uVAO); pRenderer->GenBuffers(2, m_uVBO); #ifndef SW_SKEL_ANIM buildVBOVertex(m_vertices, m_uVertexCount*sizeof(CVertexPTB)); BEATS_SAFE_DELETE_ARRAY(m_vertices); #endif buildVBOIndex(indexBuffer.GetBuffer(), indexBuffer.GetWritePos()); buildVAO(); SetLoadedFlag(true); return bRet; }
void ShaderParams::set_colour(const std::string& uniform_name, const Colour& values) { kmVec4 tmp; kmVec4Fill(&tmp, values.r, values.g, values.b, values.a); set_vec4(uniform_name, tmp); }