void mjAssimpModel::RecursiveDraw(std::vector<mjShader*>& shaderList, float* modelMatrix, float* lookAtMatrix, float* modelViewMatrix, float* projectionMatrix, float* modelViewProjectionMatrix, aiNode *node, mjMatrixStack* matrixStack) { /*if (node == scene->mRootNode) { LOGI("Root"); }*/ float tempMatrix[16]; float poseMatrix[16]; aiMatrix4x4* nodeTrans = &node->mTransformation; /*Matrix4::MultiplyMM(poseMatrix, 0, (float* ) nodeTrans, 0, modelMatrix, 0);*/ matrixStack->Push((float* ) nodeTrans); for(unsigned i = 0; i < node->mNumMeshes; i++) { const aiMesh* assimpMesh = scene->mMeshes[node->mMeshes[i]]; // From the scene, fetch the mesh that is in use by the current node. mjModelMesh* mjMesh = meshes[node->mMeshes[i]]; Matrix4::MultiplyMM(modelViewProjectionMatrix, 0, projectionMatrix, 0, matrixStack->current, 0); // FIXME: find a way to tie the shaders from normal models with assimp-loaded models. // For now, the default shader is used. shaderList[0]->Run(mjMesh, mjMesh->vertexBuffer, mjMesh->textureCoordsBuffer, mjMesh->normalBuffer, matrixStack->current, modelViewProjectionMatrix, glTextureForMaterial[assimpMesh->mMaterialIndex]); //LOGI("Mesh %d has %d vertices ", i, mesh->mNumVertices); glDrawElements(GL_TRIANGLES, mjMesh->drawOrderCount, GL_UNSIGNED_SHORT, mjMesh->drawOrderBuffer); checkGlError("afterDrawElements"); } // honey I unrolled the children for (unsigned int n = 0; n < node->mNumChildren; n++) { RecursiveDraw(shaderList, modelMatrix, lookAtMatrix, modelViewMatrix, projectionMatrix, modelViewProjectionMatrix, node->mChildren[n], matrixStack); } matrixStack->Pop(); }
void DrawTree::Draw(string target) { string texfile = target + ".tex"; ofstream os(texfile.c_str()); if (header) { os << "\\documentclass{"; if (beamer) { os << "beamer"; } else { os << "amsart"; } os << "}\n"; os << "\\usepackage{times}\n"; os << "\\usepackage{pgf}\n"; os << "\\usepackage[english]{babel}\n"; os << "\\usepackage{tikz}\n"; os << "\\usepackage{nopageno}\n"; os << '\n'; os << "\\begin{document}\n"; if (beamer) { os << "\\begin{frame}[plain]\n"; } os << "\\begin{center}\n"; } else { os << "\\begin{center}\n"; } PrepareDrawing(); double scaleX = sizeX / GetDepth(); double startX = (GetDepth() - GetDepth(GetRoot())) * scaleX; double scaleY = sizeY / (GetSize(GetRoot()) - 1); // os << "\\setlength{\\unitlength}{0.6cm}\n"; os << "\\begin{tikzpicture}\n"; os << "[anchor=west,font=\\fontsize{" << fontsize << "}{" << fontsize << "}\\selectfont,scale=" << texscale<< "]\n"; // os << "\\begin{tikzpicture}(" << sizeX << ',' << sizeY << ")\n"; os << '\n'; RecursiveDraw(GetRoot(),os,startX,sizeY/2,scaleX,scaleY); RecursiveAfterDraw(GetRoot(),os,startX,sizeY/2,scaleX,scaleY); if (Z) { cerr << "write group names\n"; WriteGroupNames(os); } FinishDrawing(os,scaleX,scaleY); // texscalecale os << '\n'; os << "\\end{tikzpicture}\n"; if (header) { os << "\\end{center}\n"; if (beamer) { os << "\\end{frame}\n"; } os << "\\end{document}\n"; } else { os << "\\end{center}\n"; } os.close(); }
void mjAssimpModel::Draw(std::vector<mjShader*>& shaderList, GLfloat* modelMatrix, GLfloat* lookAtMatrix, GLfloat* modelViewMatrix, GLfloat* projectionMatrix, GLfloat* modelViewProjectionMatrix, mjModelPose* pose, mjMatrixStack* matrixStack) { float tempMatrix[16]; float poseMatrix[16]; float matrixAfterStack[16]; float* whichMatrix; aiNode* node = scene->mRootNode; //Matrix4::DebugM("mvp", modelViewProjectionMatrix); // aiMatrix4x4* baseTrans = &node->mTransformation; Matrix4::MultiplyMM(poseMatrix, 0, (float* )baseTrans, 0, modelMatrix, 0); Matrix4::MultiplyMM(tempMatrix, 0, lookAtMatrix, 0, poseMatrix, 0); //Matrix4::DebugM("modelMat", modelMatrix); //Matrix4::DebugM("baseTrans", (float*) baseTrans); matrixStack->Push(tempMatrix); //Matrix4::DebugM("current", matrixStack->current); /* poseMatrix[0] = baseTrans->a1; poseMatrix[1] = baseTrans->a2; poseMatrix[2] = baseTrans->a3; poseMatrix[3] = baseTrans->a4; poseMatrix[4] = baseTrans->b1; poseMatrix[5] = baseTrans->b2; poseMatrix[6] = baseTrans->b3; poseMatrix[7] = baseTrans->b4; poseMatrix[8] = baseTrans->c1; poseMatrix[9] = baseTrans->c2; poseMatrix[10] = baseTrans->c3; poseMatrix[11] = baseTrans->c4; poseMatrix[12] = baseTrans->d1; poseMatrix[13] = baseTrans->d2; poseMatrix[14] = baseTrans->d3; poseMatrix[15] = baseTrans->d4; Matrix4::MultiplyMM(tempMatrix, 0, poseMatrix, 0, modelMatrix, 0); Matrix4::MultiplyMM(modelViewMatrix, 0, lookAtMatrix, 0, tempMatrix, 0); Matrix4::MultiplyMM(modelViewProjectionMatrix, 0, projectionMatrix, 0, modelViewMatrix, 0);*/ RecursiveDraw(shaderList, modelMatrix, lookAtMatrix, modelViewMatrix, projectionMatrix, modelViewProjectionMatrix, node, matrixStack); matrixStack->Pop(); }
double DrawTree::RecursiveDraw(const Link* from, ostream& os, double X, double Y, double scaleX, double scaleY) { // string format = ""; // string format = "\\tiny "; // double thickness = 0.5; // os << "\\linethickness{" << thickness << "mm}\n"; double ret = 0; if (from->isLeaf()) { if (withleafnames) { // write species name os << "\\path (" << texapprox(X) + shiftname << "," << texapprox(Y) << ") node { " << GetPreLeafNodeName(from) << " \\, " << "\\it " << GetLeafNodeName(from) << " };\n"; // os << "\\path (" << texapprox(X) + 10 * shiftname << "," << texapprox(Y) << ") node { \\it " << GetLeafNodeName(from) << " };\n"; } ret = Y; } else { double y = Y - 0.5 * GetSize(from) * scaleY; if (groupname[from->GetNode()] != "") { groupy[from->GetNode()] = Y; } const Link* link = from->Next(); double yfirst = 0; double ylast = 0; while (link != from) { // compute horizontal offset for child node double xoffset = GetLength(link) * scaleX; // compute vertical span of child node double yspan = GetSize(link->Out()) * scaleY; // shift half the vertical offset y += 0.5 * yspan; // draw child node double x = X + xoffset; double downret = RecursiveDraw(link->Out(), os, x, y, scaleX, scaleY); // draw horizontal line LocalDrawBranch(link,os,X,downret,xoffset); LocalDraw(link,os,x,downret,scaleX,scaleY); if (link == from->Next()) { yfirst = downret; } if (link->Next() == from) { ylast = downret; } // shift half the vertical offset again y += 0.5 * yspan; link = link->Next(); } // draw vertical line LocalDrawVerticalTrait(from, os, X, yfirst, ylast); ret = (yfirst + ylast) / 2; if (from->isRoot()) { LocalDraw(from,os,X,ret,scaleX,scaleY); LocalDrawBranch(from,os,X,ret,0); } } return ret; }