📄 stdmeshimporter.cpp
字号:
// rotate n,n2 tmp = ca*ny - sa*nz; nz = sa*ny + ca*nz; ny = tmp; tmp = ca*ny2- sa*nz2; nz2 = sa*ny2 + ca*nz2; ny2 = tmp; } start_nx = start_nx2; start_ny = start_ny2; } // draw second cylinder cap start_nx = 0; start_ny = 1; for (j=0; j<(n/4); j++) { // get start_n2 = rotated start_n float start_nx2 = ca*start_nx - sa*start_ny; float start_ny2 = sa*start_nx + ca*start_ny; // get n=start_n and n2=start_n2 nx = start_nx; ny = start_ny; nz = 0; float nx2 = start_nx2; float ny2 = start_ny2; float nz2 = 0; for (i=0; i<=n; i++) { AddVertex(&cNormal,ny,nz,nx); AddVertex(&cVert,ny*ccRadius,nz*ccRadius,-l+nx*ccRadius); AddVertex(&cNormal,ny2,nz2,nx2); AddVertex(&cVert,ny2*ccRadius,nz2*ccRadius,-l+nx2*ccRadius); // rotate n,n2 tmp = ca*ny - sa*nz; nz = sa*ny + ca*nz; ny = tmp; tmp = ca*ny2- sa*nz2; nz2 = sa*ny2 + ca*nz2; ny2 = tmp; } start_nx = start_nx2; start_ny = start_ny2; } shared_ptr<IndexBuffer> idx(new IndexBuffer()); // triangle strip -> triangles int numFaces = (numVertices - 2); idx->EnsureFit(numFaces*3); for (i=0;i<numFaces;++i) { if (i%2) { idx->Cache(i+1); idx->Cache(i); idx->Cache(i+2); } else { idx->Cache(i); idx->Cache(i+1); idx->Cache(i+2); } } shared_ptr<TriMesh> mesh(new TriMesh()); mesh->SetPos(pos,numVertices); mesh->SetNormals(normals); mesh->AddFace(idx); mesh->SetName(MangleName(gCCylinderStr,parameter)); return mesh;}//// unit cylinder (radius = 1, length = 1)//static const int gNumCylinderVertices = 66;static const int gNumCylinderFaces = 128;static float gCylinderVertices[gNumCylinderVertices*3] = { 0.70711f,0.70711f,-0.5f, 0.83147f,0.55557f,-0.5f, 0.92388f,0.38268f,-0.5f, 0.98079f,0.19509f,-0.5f, 1.0f,0.0f,-0.5f, 0.98079f,-0.19509f,-0.5f, 0.92388f,-0.38268f,-0.5f, 0.83147f,-0.55557f,-0.5f, 0.70711f,-0.70711f,-0.5f, 0.55557f,-0.83147f,-0.5f, 0.38268f,-0.92388f,-0.5f, 0.19509f,-0.98079f,-0.5f, -0.0f,-1.0f,-0.5f, -0.19509f,-0.98079f,-0.5f, -0.38268f,-0.92388f,-0.5f, -0.55557f,-0.83147f,-0.5f, -0.70711f,-0.70711f,-0.5f, -0.83147f,-0.55557f,-0.5f, -0.92388f,-0.38268f,-0.5f, -0.98079f,-0.19509f,-0.5f, -1.0f,0.0f,-0.5f, -0.98079f,0.19509f,-0.5f, -0.92388f,0.38268f,-0.5f, -0.83147f,0.55557f,-0.5f, -0.70711f,0.70711f,-0.5f, -0.55557f,0.83147f,-0.5f, -0.38268f,0.92388f,-0.5f, -0.19509f,0.98079f,-0.5f, 0.0f,1.0f,-0.5f, 0.19509f,0.98078f,-0.5f, 0.38269f,0.92388f,-0.5f, 0.55557f,0.83147f,-0.5f, 0.70711f,0.70711f,0.5f, 0.83147f,0.55557f,0.5f, 0.92388f,0.38268f,0.5f, 0.98079f,0.19509f,0.5f, 1.0f,-0.0f,0.5f, 0.98078f,-0.19509f,0.5f, 0.92388f,-0.38268f,0.5f, 0.83147f,-0.55557f,0.5f, 0.70711f,-0.70711f,0.5f, 0.55557f,-0.83147f,0.5f, 0.38268f,-0.92388f,0.5f, 0.19509f,-0.98079f,0.5f, 0.0f,-1.0f,0.5f, -0.19509f,-0.98079f,0.5f, -0.38268f,-0.92388f,0.5f, -0.55557f,-0.83147f,0.5f, -0.7071f,-0.70711f,0.5f, -0.83147f,-0.55557f,0.5f, -0.92388f,-0.38269f,0.5f, -0.98078f,-0.19509f,0.5f, -1.0f,-0.0f,0.5f, -0.98079f,0.19509f,0.5f, -0.92388f,0.38268f,0.5f, -0.83147f,0.55557f,0.5f, -0.70711f,0.7071f,0.5f, -0.55558f,0.83147f,0.5f, -0.38269f,0.92388f,0.5f, -0.1951f,0.98078f,0.5f, -1e-05f,1.0f,0.5f, 0.19508f,0.98079f,0.5f, 0.38268f,0.92388f,0.5f, 0.55556f,0.83147f,0.5f, 0.0f,-0.0f,-0.5f, 0.0f,0.0f,0.5f };static float gCylinderNormals[gNumCylinderVertices*3] = { 0.49876f,0.49876f,-0.70879f, 0.5865f,0.39189f,-0.70879f, 0.65169f,0.26994f,-0.70879f, 0.69182f,0.13761f,-0.70879f, 0.70537f,0.0f,-0.70879f, 0.69182f,-0.13761f,-0.70879f, 0.65169f,-0.26994f,-0.70879f, 0.5865f,-0.39189f,-0.70879f, 0.49876f,-0.49876f,-0.70879f, 0.39189f,-0.5865f,-0.70879f, 0.26994f,-0.65169f,-0.70879f, 0.13761f,-0.69182f,-0.70879f, 0.0f,-0.70537f,-0.70879f, -0.13761f,-0.69182f,-0.70879f, -0.26994f,-0.65169f,-0.70879f, -0.39189f,-0.5865f,-0.70879f, -0.49876f,-0.49876f,-0.70879f, -0.5865f,-0.39189f,-0.70879f, -0.65169f,-0.26994f,-0.70879f, -0.69182f,-0.13761f,-0.70879f, -0.70537f,0.0f,-0.70879f, -0.69182f,0.13761f,-0.70879f, -0.65169f,0.26994f,-0.70879f, -0.5865f,0.39189f,-0.70879f, -0.49876f,0.49876f,-0.70879f, -0.39189f,0.5865f,-0.70879f, -0.26994f,0.65169f,-0.70879f, -0.13761f,0.69182f,-0.70879f, 0.0f,0.70537f,-0.70879f, 0.13761f,0.69182f,-0.70879f, 0.26994f,0.65169f,-0.70879f, 0.39189f,0.5865f,-0.70879f, 0.49876f,0.49876f,0.70879f, 0.5865f,0.39189f,0.70879f, 0.65169f,0.26994f,0.70879f, 0.69182f,0.13761f,0.70879f, 0.70537f,0.0f,0.70879f, 0.69182f,-0.13761f,0.70879f, 0.65169f,-0.26994f,0.70879f, 0.5865f,-0.39189f,0.70879f, 0.49876f,-0.49876f,0.70879f, 0.39189f,-0.5865f,0.70879f, 0.26994f,-0.65169f,0.70879f, 0.13761f,-0.69182f,0.70879f, 0.0f,-0.70537f,0.70879f, -0.13761f,-0.69182f,0.70879f, -0.26994f,-0.65169f,0.70879f, -0.39189f,-0.5865f,0.70879f, -0.49876f,-0.49876f,0.70879f, -0.5865f,-0.39189f,0.70879f, -0.65169f,-0.26994f,0.70879f, -0.69182f,-0.13761f,0.70879f, -0.70537f,0.0f,0.70879f, -0.69182f,0.13761f,0.70879f, -0.65169f,0.26994f,0.70879f, -0.5865f,0.39189f,0.70879f, -0.49876f,0.49876f,0.70879f, -0.39189f,0.5865f,0.70879f, -0.26994f,0.65169f,0.70879f, -0.13761f,0.69182f,0.70879f, 0.0f,0.70537f,0.70879f, 0.13761f,0.69182f,0.70879f, 0.26994f,0.65169f,0.70879f, 0.39189f,0.5865f,0.70879f, 0.0f,0.0f,-1.0f, 0.0f,0.0f,1.0f };static unsigned int gCylinderFaces[gNumCylinderFaces*3] = { 64,0,1, 65,33,32, 64,1,2, 65,34,33, 64,2,3, 65,35,34, 64,3,4, 65,36,35, 64,4,5, 65,37,36, 64,5,6, 65,38,37, 64,6,7, 65,39,38, 64,7,8, 65,40,39, 64,8,9, 65,41,40, 64,9,10, 65,42,41, 64,10,11, 65,43,42, 64,11,12, 65,44,43, 64,12,13, 65,45,44, 64,13,14, 65,46,45, 64,14,15, 65,47,46, 64,15,16, 65,48,47, 64,16,17, 65,49,48, 64,17,18, 65,50,49, 64,18,19, 65,51,50, 64,19,20, 65,52,51, 64,20,21, 65,53,52, 64,21,22, 65,54,53, 64,22,23, 65,55,54, 64,23,24, 65,56,55, 64,24,25, 65,57,56, 64,25,26, 65,58,57, 64,26,27, 65,59,58, 64,27,28, 65,60,59, 64,28,29, 65,61,60, 64,29,30, 65,62,61, 64,30,31, 65,63,62, 31,0,64, 65,32,63, 0,32,33, 33,1,0, 1,33,34, 34,2,1, 2,34,35, 35,3,2, 3,35,36, 36,4,3, 4,36,37, 37,5,4, 5,37,38, 38,6,5, 6,38,39, 39,7,6, 7,39,40, 40,8,7, 8,40,41, 41,9,8, 9,41,42, 42,10,9, 10,42,43, 43,11,10, 11,43,44, 44,12,11, 12,44,45, 45,13,12, 13,45,46, 46,14,13, 14,46,47, 47,15,14, 15,47,48, 48,16,15, 16,48,49, 49,17,16, 17,49,50, 50,18,17, 18,50,51, 51,19,18, 19,51,52, 52,20,19, 20,52,53, 53,21,20, 21,53,54, 54,22,21, 22,54,55, 55,23,22, 23,55,56, 56,24,23, 24,56,57, 57,25,24, 25,57,58, 58,26,25, 26,58,59, 59,27,26, 27,59,60, 60,28,27, 28,60,61, 61,29,28, 29,61,62, 62,30,29, 30,62,63, 63,31,30, 32,0,31, 31,63,32 };shared_ptr<TriMesh> StdMeshImporter::UnitCylinder(){ shared_ptr<TriMesh> mesh(new TriMesh()); shared_array<float> pos(new float[gNumCylinderVertices*3]); memcpy(pos.get(),gCylinderVertices,gNumCylinderVertices*3*sizeof(float)); mesh->SetPos(pos,gNumCylinderVertices); shared_array<float> normals(new float[gNumCylinderVertices*3]); memcpy(normals.get(),gCylinderNormals,gNumCylinderVertices*3*sizeof(float)); mesh->SetNormals(normals); shared_ptr<IndexBuffer> idx(new IndexBuffer()); idx->Cache(gNumCylinderFaces*3,gCylinderFaces); mesh->AddFace(idx); return mesh;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -