namespace gmtl { const Matrix22f MAT_IDENTITY22F = Matrix22f(); const Matrix22d MAT_IDENTITY22D = Matrix22d(); const Matrix23f MAT_IDENTITY23F = Matrix23f(); const Matrix23d MAT_IDENTITY23D = Matrix23d(); const Matrix33f MAT_IDENTITY33F = Matrix33f(); const Matrix33d MAT_IDENTITY33D = Matrix33d(); const Matrix34f MAT_IDENTITY34F = Matrix34f(); const Matrix34d MAT_IDENTITY34D = Matrix34d(); const Matrix44f MAT_IDENTITY44F = Matrix44f(); const Matrix44d MAT_IDENTITY44D = Matrix44d(); }
void ARToolKitPlusTracker::update(unsigned char* data) { ARToolKitPlus::ARMarkerInfo* m_infos; int numActiveTrackables; std::vector<int> markerId = _tracker->calc(data, &m_infos, &numActiveTrackables); int best_id = _tracker->selectBestMarkerByCf(); { std::lock_guard<mutex> lock(_mtx_ar); _n_trackables = numActiveTrackables; for (int j = 0; j < numActiveTrackables; j++) { if (m_infos[j].id == best_id) { for(int i=0; i<4; i++) _pts_corner[i] = ci::Vec2f(m_infos[j].vertex[i][0], m_infos[j].vertex[i][1]); _mat_proj = Matrix44d(_tracker->getProjectionMatrix()); _mat_modelview = Matrix44d(_tracker->getModelViewMatrix()); break; } } } }
void S9FbxDrawer::applyRotations(shared_ptr<FbxMesh> pMesh) { //int clusterMode = pMesh->clusters[0]->mode; // set skin matrices to ALL ZEROS if not additive (which it is likely to be but we'll need to change that) for (vector<Matrix44d>::iterator it = pMesh->skinmatrices.begin(); it != pMesh->skinmatrices.end(); it++) { (*it) = Matrix44d(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); } // set skin weights to zero for (vector<float>::iterator it = pMesh->skinweights.begin(); it != pMesh->skinweights.end(); it++) { *it = 0.0; } // Compute the skin matrices (a matrix for each vertex) - This is the shader bit I'd have thought for (int i = 0; i < pMesh->clusters.size(); ++i) { shared_ptr<FbxCluster> cinderCluster = pMesh->clusters[i]; Matrix44d clusterMatrix; clusterMatrix = cinderCluster->pretransform * (*cinderCluster->transform) * cinderCluster->posttransform; // Modify this cluster's matrices by the current indicies weight then add this up for all matrices // affecting that vertex (as multiple clusters can influence one vertex) Vec3f centre(0,0,0); for (int j=0; j < cinderCluster->indicies.size(); ++j) { int idx = cinderCluster->indicies[j]; float w = cinderCluster->weights[j]; if (w == 0.0) continue; Matrix44d influenceMatrix = clusterMatrix * w; pMesh->skinmatrices[idx] = pMesh->skinmatrices[idx] + influenceMatrix; pMesh->skinweights[idx] += w; } } pMesh->skinvertices = pMesh->vertices; for (int i =0; i < pMesh->skinvertices.size(); ++i) { float w = pMesh->skinweights[i]; if (w != 0.0) { pMesh->skinvertices[i] = pMesh->skinmatrices[i] * pMesh->vertices[i]; int idx = pMesh->indiciesToIterative[pMesh->indicies[i]]; pMesh->skinnormals[idx] = pMesh->skinmatrices[i].transformVec(pMesh->normals[idx]); } } ///\todo - There is definitely a performance hit here. Can we perhaps do some things with that? for (int i = 0; i < pMesh->clusters.size(); ++i) { shared_ptr<FbxCluster> cinderCluster = pMesh->clusters[i]; // Modify this cluster's matrices by the current indicies weight then add this up for all matrices // affecting that vertex (as multiple clusters can influence one vertex) Vec3f centre(0,0,0); cinderCluster->mMax = Vec3f(-1e10,-1e10,-1e10); cinderCluster->mMin = Vec3f(1e10,1e10,1e10); for (int j=0; j < cinderCluster->indicies.size(); ++j) { //Centre points - how best to do this? Dont want to loop again! >< int idx = cinderCluster->indicies[j]; Vec3f vert = pMesh->skinvertices[idx]; cinderCluster->mMax.x = vert.x > cinderCluster->mMax.x ? vert.x : cinderCluster->mMax.x; cinderCluster->mMax.y = vert.y > cinderCluster->mMax.y ? vert.y : cinderCluster->mMax.y; cinderCluster->mMax.z = vert.z > cinderCluster->mMax.z ? vert.z : cinderCluster->mMax.z; cinderCluster->mMin.x = vert.x < cinderCluster->mMin.x ? vert.x : cinderCluster->mMin.x; cinderCluster->mMin.y = vert.y < cinderCluster->mMin.y ? vert.y : cinderCluster->mMin.y; cinderCluster->mMin.z = vert.z < cinderCluster->mMin.z ? vert.z : cinderCluster->mMin.z; centre += vert; } if (centre != Vec3f::zero()) { cinderCluster->mCentre = centre * 1.0 / static_cast<float>(cinderCluster->indicies.size()); } else { cinderCluster->mCentre = centre; } } }