void BaseMesh::LoadMeshList(const Vector< pair<const BaseMesh *, Matrix4> > &Meshes) { UINT NewVertexCount = 0, NewFaceCount = 0; for(UINT MeshIndex = 0; MeshIndex < Meshes.Length(); MeshIndex++) { const BaseMesh &CurMesh = *(Meshes[MeshIndex].first); NewVertexCount += CurMesh.VertexCount(); NewFaceCount += CurMesh.FaceCount(); } Allocate(NewVertexCount, NewFaceCount); UINT VertexBaseIndex = 0, IndexBaseIndex = 0; for(UINT MeshIndex = 0; MeshIndex < Meshes.Length(); MeshIndex++) { const BaseMesh &CurMesh = *(Meshes[MeshIndex].first); Matrix4 Transform = Meshes[MeshIndex].second; for(UINT VertexIndex = 0; VertexIndex < CurMesh.VertexCount(); VertexIndex++) { Vertices()[VertexBaseIndex + VertexIndex] = CurMesh.Vertices()[VertexIndex]; Vertices()[VertexBaseIndex + VertexIndex].Pos = Transform.TransformPoint(Vertices()[VertexBaseIndex + VertexIndex].Pos); } for(UINT FaceIndex = 0; FaceIndex < CurMesh.FaceCount(); FaceIndex++) { for(UINT LocalVertexIndex = 0; LocalVertexIndex < 3; LocalVertexIndex++) { Indices()[IndexBaseIndex + FaceIndex * 3 + LocalVertexIndex] = CurMesh.Indices()[FaceIndex * 3 + LocalVertexIndex] + VertexBaseIndex; } } VertexBaseIndex += CurMesh.VertexCount(); IndexBaseIndex += CurMesh.FaceCount() * 3; } }
void BaseMesh::AppendVertices(const BaseMesh &O) { int vc = VertexCount(), ic = IndexCount(); MeshVertex *V = Vertices(), *OldV = new MeshVertex[vc]; DWORD *I = Indices(), *OldI = new DWORD[ic]; memcpy(OldV, V, vc * sizeof(MeshVertex)); memcpy(OldI, I, ic * sizeof(DWORD)); //store all the old vertices/indices Allocate(vc + O.VertexCount(), ic/3 + O.FaceCount()); //allocate space for the current vertices/indices and o's vertices/indices V = Vertices(); I = Indices(); memcpy(V, OldV, vc * sizeof(MeshVertex)); memcpy(I, OldI, ic * sizeof(DWORD)); //copy the old vertices/indices back into the mesh, memcpy(&(V[vc]), O.Vertices(), O.VertexCount() * sizeof(MeshVertex)); //copy the new vertices after the current ones, UINT oic = O.IndexCount(); const DWORD *oI = O.Indices(); for(UINT i = 0; i < oic; i++) { I[ic+i] = oI[i] + vc; //copy o's indices as well, except increasing the index by vc (since o's vertices start at vc, not 0) } delete[] OldV; delete[] OldI; }
CVector3 CVertices<Vertex, Allocator>::GetCenter(void) const { CVector3 center = CVector3(0, 0, 0); for (const auto& vertex : Vertices()) { center += vertex.Position(); } center /= static_cast<float>(Vertices().size()); return center; }
void CVertices<Vertex, Allocator>::Render() { if (m_pRenderBeginFunction) m_pRenderBeginFunction(); if (IsDynamic()) { Vertex::RenderBegin(Vertices()[0]); #ifdef USING_OPENGL glDrawArrays( m_type, 0, m_vertices.size()); #endif #ifdef USING_DIRECTX CheckDirectXErrer( CGraphicManager::GetManager(). GetDevice()->DrawPrimitiveUP( (D3DPRIMITIVETYPE)m_type, GetPrimitiveNum(), Vertices().data(), sizeof(Vertex))); #endif } else { m_vertexBuffer.Bind(); Vertex::RenderBegin(); #ifdef USING_OPENGL glDrawArrays( m_type, 0, m_vertices.size()); CGLFunctions::GetInstance().CheckErrer(); #endif #ifdef USING_DIRECTX CheckDirectXErrer( CGraphicManager::GetManager(). GetDevice()->DrawPrimitive( (D3DPRIMITIVETYPE)m_type, 0, GetPrimitiveNum())); #endif m_vertexBuffer.UnBind(); } Vertex::RenderEnd(); };
void BaseMesh::ReCreateCylinder(Vec3f (*PositionFunction) (float), float Start, float End, float radius, UINT slices, UINT stacks) { MeshVertex *V = Vertices(); Matrix4 Face, Translate; Vec3f Tangent; float DeltaT = 0.0001f,Time,Theta; float PI2_Slices = 2.0f * Math::PIf / float(slices); Vec3f CurPos; for(UINT i = 0; i <= stacks; i++) { Time = float(Math::LinearMap(0.0f,float(stacks),Start,End,float(i))); //get the approriate value between Start and End CurPos = PositionFunction(Time); //get the current position along the curve if(Time + DeltaT <= End) Tangent = PositionFunction(Time + DeltaT) - CurPos; //approximate the derivative (tangent vector) else Tangent = CurPos - PositionFunction(Time - DeltaT); Face = Matrix4::Face(Vec3f(0.0f, 0.0f, 1.0f), Tangent); //face Matrix4 causes the local cylinder ring to face the right direction Translate = Matrix4::Translation(CurPos); //the local cylinder ring should be centered on CurPos Face = Face * Translate; for(UINT i2 = 0; i2 < slices; i2++) { Theta = float(i2) * PI2_Slices; V[i*slices+i2].Pos = Vec3f(radius * cosf(Theta), radius * sinf(Theta), 0.0f); //construct the basic circle V[i*slices+i2].Pos = Face.TransformPoint(V[i*slices+i2].Pos); //transform the circle to its approrpriate using the Matrix4 } } GenerateNormals(); }
void BaseMesh::ReCreateCylinder(float radius, const Vec3f &pt1, const Vec3f &pt2, UINT slices, UINT stacks) { //a merge of the CreateCylinder(radius, height, slices, stacks) and CreateCylinder(radius, pt1, pt2, slices, stacks) Vec3f Diff = pt2 - pt1; float height = Diff.Length(); float PI2_Slices = 2.0f * Math::PIf / float(slices); float Theta; int vc = 0, ic = 0; MeshVertex *V = Vertices(); DWORD *I = Indices(); MeshVertex MVtx(Vec3f::Origin, Vec3f::Origin, RGBColor::White, Vec2f::Origin); for(UINT i = 0; i <= stacks; i++) { for(UINT i2 = 0; i2 < slices; i2++) { Theta = float(i2) * PI2_Slices; MVtx.Pos = Vec3f(radius * cosf(Theta), radius * sinf(Theta), height * (float(i) / stacks - 0.5f)); V[vc++] = MVtx; } } Matrix4 T1 = Matrix4::Translation(Vec3f(0.0f,0.0f,height / 2.0f)); Matrix4 Face = Matrix4::Face(Vec3f(0.0f,0.0f,1.0f),pt2 - pt1); Matrix4 T2 = Matrix4::Translation(pt1); ApplyMatrix(T1 * Face * T2); GenerateNormals(); }
ConjuntoInt puntosArt(Grafo g) { int v, w, hijosraiz, *prenum, *masalto; ConjuntoInt aux, ady, pa; pa = crearConjunto(); aux = Vertices(g); iniciarRecorridaConjunto(aux); if(siguienteConjunto(v, aux)) { destruirConjunto(aux); prenum = prenumeraDFS(v, g); masalto = calculamasalto(v, g, prenum); aux = crearConjunto(); agregarElementoConjunto(v, aux); hijosraiz = 0; ady = Adyacentes(g, v); iniciarRecorridaConjunto(ady); while(siguienteConjunto(w, ady)) { if (!perteneceConjunto(w, m)) { aux_puntosArt(w, g, prenum, masalto, pa); hijosraiz++; } } destruirConjunto(ady); if (hijosraiz > 1) agregarElementoConjunto(v, pa); delete(prenum); delete(masalto); } destruirConjunto(aux); return pa; }
ShapeEntity::ShapeEntity() : ShapeEntity(Vertices()) //Entity(0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f), //shape_(), //bounds_() { }
void CreateScreenQuad( MeshData& Quad) { AttribData<vec3> Vertices(4); Vertices.Set(0, vec3(-1.0f, -1.0f, 0.0f)); Vertices.Set(1, vec3( 1.0f, -1.0f, 0.0f)); Vertices.Set(2, vec3( 1.0f, 1.0f, 0.0f)); Vertices.Set(3, vec3(-1.0f, 1.0f, 0.0f)); AttribData<vec2> TexCoords(4); TexCoords.Set(0, vec2(0.0f, 0.0f)); TexCoords.Set(1, vec2(1.0f, 0.0f)); TexCoords.Set(2, vec2(1.0f, 1.0f)); TexCoords.Set(3, vec2(0.0f, 1.0f)); AttribData<GLFace16> Faces(2); Faces.Set(0, GLFace16(0, 1, 2) ); Faces.Set(1, GLFace16(2, 3, 0) ); Polygons Polylist1; Polylist1.SetMaterial(0); Polylist1.SetFaces(Faces); AttribData<poly> Polygons(1); Polygons.Set(0, Polylist1); Quad.SetVertexArray(Vertices); Quad.SetUVArray(TexCoords); Quad.SetPolygonList(Polygons); Quad.GenerateNormals(false); Quad.GenerateTangents(); }
void BaseMesh::CopyMesh(BaseMesh &Copy) const { Copy._GD = _GD; Copy.Allocate(VertexCount(), FaceCount()); memcpy(Copy.Vertices(), Vertices(), sizeof(MeshVertex) * VertexCount()); memcpy(Copy.Indices(), Indices(), sizeof(DWORD) * IndexCount()); }
void BaseMesh::TextureSphericalMap(int variable) { int i; //spherical coordinates have two angles. This function computes //these angles for each vertex and maps these angles into tx and ty. //variable exists for the same reason as TextureMapToNormals int vc = VertexCount(); MeshVertex *V = Vertices(); Vec3f Pos; for(i=0;i<vc;i++) { if(variable == 0) Pos = Vec3f(V[i].Pos.x,V[i].Pos.y,V[i].Pos.z); if(variable == 1) Pos = Vec3f(V[i].Pos.x,V[i].Pos.z,V[i].Pos.y); V[i].TexCoord.x = (atan2f(Pos.y,Pos.x) + Math::PIf) / (2.0f * Math::PIf); V[i].TexCoord.y = 1.0f - (atan2f(Pos.z,sqrtf(Pos.y * Pos.y + Pos.x * Pos.x)) + Math::PIf / 2.0f) / Math::PIf; } }
void BaseMesh::GenerateNormals() { UINT vc = VertexCount(), ic = IndexCount(); MeshVertex *V = Vertices(); DWORD *I = Indices(); Vec3f V1, V2, Normal; for(UINT i = 0; i < vc; i++) { V[i].Normal = Vec3f::Origin; //zero each normal } for(UINT i = 0; i < ic; i += 3) //for every triangle { V1 = V[I[i+2]].Pos - V[I[i+0]].Pos; V2 = V[I[i+1]].Pos - V[I[i+0]].Pos; Normal = Vec3f::Cross(V1, V2); //compute the triangle normal V[I[i+0]].Normal += Normal; V[I[i+1]].Normal += Normal; V[I[i+2]].Normal += Normal; //each adjacent vertex adds the triangle normal to its summed normal } NormalizeNormals(); }
Hilbert::Hilbert ( const Glib::ustring& id, unsigned level, double size, Fill::pointer fill, Stroke::pointer stroke ) : Polyline ( id, Vertices(), fill, stroke ), m_level ( level ), m_size ( size ) { this->create_vertices(); }
void BaseMesh::CreateBox(float w, float h, float d, int refinement) { Allocate(8, 12); MeshVertex Temp(Vec3f::Origin, Vec3f::Origin, RGBColor::White, Vec2f::Origin); int i,vc=VertexCount(),ic=IndexCount(); MeshVertex *V = Vertices(); DWORD *I = Indices(); for(i=0;i<8;i++) { Temp.Pos = Vec3f(CubeVData[i][0],CubeVData[i][1],CubeVData[i][2]); V[i] = Temp; ///load the vertices } for(i=0;i<12;i++) { I[i*3+0] = CubeIData[i][0]; I[i*3+1] = CubeIData[i][1]; I[i*3+2] = CubeIData[i][2]; //load the triangles } for(i=0;i<refinement;i++) { TwoPatch(); //refine the requested number of times } Stretch(Vec3f(0.5f*w, 0.5f*h, 0.5f*d)); //stretch to the requested dimensions GenerateNormals(); }
void BaseMesh::ColorNormalsGrayScale(RGBColor Color) { int i,vc = VertexCount(); MeshVertex *V = Vertices(); for(i=0;i<vc;i++) { Vec3f normal = V[i].Normal; int r = Utility::Bound(int(Math::Abs(normal.x/2.0f+0.5f)*255), 0, 255); int g = Utility::Bound(int(Math::Abs(normal.y/2.0f+0.5f)*255), 0, 255); int b = Utility::Bound(int(Math::Abs(normal.z/2.0f+0.5f)*255), 0, 255); //remap each normal's (x, y, z) to (r, g, b) const bool UseMaximumValue = false; if(UseMaximumValue) { if(g > r) r = g; if(b > r) r = b; } else { r = (r + g + b) / 3; //merge the 3 values into one value via some method } V[i].Color = RGBColor(r / 255.0f * Vec3f(Color)); } }
int main() { double V0[] = {1,0,0, 0,1,0, 0,0,0, 0,0,1}; std::vector<double> Vertices(V0, V0+12); Tetrahedron::SetGlobalCoordinatesArray(Vertices); Triangle<3>::SetGlobalCoordinatesArray(Vertices); Segment<3>::SetGlobalCoordinatesArray(Vertices); P13DElement<2> Elm(1,2,3,4); P13DElementBoundaryTraces<2> EBT(Elm, true, false, true, true, P13DTrace<2>::ThreeDofs); std::cout<<"\n Number of Traces: "<<EBT.getNumTraceFaces()<<" should be 3. \n"; for(unsigned int a=0; a<3; a++) // Change to test different/all traces. { int facenumber = EBT.getTraceFaceIds()[a]; std::cout<<" \n FaceNumber :"<<facenumber<<"\n"; std::cout<<"\n Normal to face: "; for(unsigned int q=0; q<EBT.getNormal(a).size(); q++) std::cout<< EBT.getNormal(a)[q]<<", "; std::cout<<"\n"; } for(unsigned int a=0; a<1; a++) { int facenumber = EBT.getTraceFaceIds()[a]; std::cout<<"\nFace Number :"<<facenumber<<"\n"; const Element &face = EBT[a]; // Integration weights: std::cout<<"\n Integration weights: \n"; for(unsigned int q=0; q<face.getIntegrationWeights(0).size(); q++) std::cout<<face.getIntegrationWeights(0)[q]<<", "; // Integration points: std::cout<<"\n Integration point coordinates: \n"; for(unsigned int q=0; q<face.getIntegrationPtCoords(0).size(); q++) std::cout<<face.getIntegrationPtCoords(0)[q]<<", "; // Shape functions: std::cout<<"\n Shape Functions at quadrature points: \n"; for(unsigned int q=0; q<face.getShapes(0).size(); q++) std::cout<<face.getShapes(0)[q]<<", "; std::cout<<"\n"; } }
void BaseMesh::CleanVerticesAndTriangles(Vector<UINT> &OldToNewMapping) { UINT NumFaces = FaceCount(), NumVertices = VertexCount(); DWORD *I = Indices(); MeshVertex *V = Vertices(); Vector<DWORD> NewIndices; Vector<MeshVertex> NewVertices; OldToNewMapping.ReSize(NumVertices); OldToNewMapping.Clear(NumVertices); for(UINT FaceIndex = 0; FaceIndex < NumFaces; FaceIndex++) { if(I[FaceIndex * 3 + 0] != I[FaceIndex * 3 + 1] && I[FaceIndex * 3 + 1] != I[FaceIndex * 3 + 2] && I[FaceIndex * 3 + 2] != I[FaceIndex * 3 + 0]) { for(UINT i = 0; i < 3; i++) { UINT SourceIndex = I[FaceIndex * 3 + i]; if(OldToNewMapping[SourceIndex] == NumVertices) { OldToNewMapping[SourceIndex] = NewVertices.Length(); NewVertices.PushEnd(V[SourceIndex]); } NewIndices.PushEnd(OldToNewMapping[SourceIndex]); } } } Allocate(NewVertices.Length(), NewIndices.Length() / 3); NumFaces = FaceCount(); NumVertices = VertexCount(); I = Indices(); V = Vertices(); for(UINT VertexIndex = 0; VertexIndex < NumVertices; VertexIndex++) { V[VertexIndex] = NewVertices[VertexIndex]; } for(UINT FaceIndex = 0; FaceIndex < NumFaces; FaceIndex++) { for(UINT i = 0; i < 3; i++) { I[FaceIndex * 3 + i] = NewIndices[FaceIndex * 3 + i]; } } }
void CMine::SizeLine (CDSegment *seg,int point0,int point1,INT32 inc) { double x,y,z,radius; // round a bit if (inc > 0) if (inc & 0xf) inc++; else if (inc & 1) inc--; else if (inc & 0xf) inc--; else if (inc & 1) inc++; vms_vector *v1 = Vertices (seg->verts [point0]), *v2 = Vertices (seg->verts [point1]); // figure out direction to modify line x = v1->x - v2->x; y = v1->y - v2->y; z = v1->z - v2->z; // normalize direction radius = sqrt (x*x + y*y + z*z); if (radius > (double) F1_0* (double) F1_0 - inc) return; if ((inc < 0) && (radius <= (double)-inc*3)) return; if (radius == 0) return; x /= radius; y /= radius; z /= radius; // multiply by increment value x *= inc; y *= inc; z *= inc; // update vertices v1->x += (INT32)x; v1->y += (INT32)y; v1->z += (INT32)z; v2->x -= (INT32)x; v2->y -= (INT32)y; v2->z -= (INT32)z; }
void BaseMesh::RandomizeColors() { int i,vc=VertexCount(); MeshVertex *V = Vertices(); for(i=0;i<vc;i++) { V[i].Color = RGBColor::RandomColor(); } }
Vec3f BaseMesh::EvaluateBarycentricPos(UINT FaceIndex, float u, float v) const { const MeshVertex *V = Vertices(); const DWORD *I = Indices(); Vec3f V0 = V[I[FaceIndex * 3 + 0]].Pos; Vec3f V1 = V[I[FaceIndex * 3 + 1]].Pos; Vec3f V2 = V[I[FaceIndex * 3 + 2]].Pos; return V0 + u * (V1 - V0) + v * (V2 - V0); }
void BaseMesh::CreateTorus(float MainRadius, float SmallRadius, UINT slices, UINT stacks) { //much like all the others shape functions...create a torus by taking a cylinder and wrapping //it around a point in space, then connect the two ends. Allocate(slices * stacks,2 * stacks * slices); float PI2_Stacks = 2.0f * Math::PIf / float(stacks); float PI2_Slices = 2.0f * Math::PIf / float(slices); float Theta,SinT,CosT,Phi,SinP; UINT vc = 0, ic = 0; MeshVertex *V = Vertices(); DWORD *I = Indices(); MeshVertex MVtx(Vec3f::Origin, Vec3f::Origin, RGBColor::White, Vec2f::Origin); for(UINT i = 0; i < stacks; i++) { Theta = float(i) * PI2_Stacks; SinT = sinf(Theta); CosT = cosf(Theta); Vec3f MainTranslation(CosT*MainRadius,SinT*MainRadius,0.0f); for(UINT i2 = 0; i2 < slices; i2++) { Phi = float(i2) * PI2_Slices; SinP = sinf(Phi); MVtx.Pos = Vec3f(SmallRadius * CosT * SinP, SmallRadius * SinT * SinP, SmallRadius * cosf(Phi)) + MainTranslation; V[vc++] = MVtx; } } UINT i2p1,ip1; for(UINT i = 0; i < stacks; i++) { ip1 = i + 1; if(ip1 == stacks) { ip1 = 0; } for(UINT i2 = 0; i2 < slices; i2++) { i2p1 = i2 + 1; if(i2p1 == slices) i2p1 = 0; I[ic++] = ip1 * slices + i2; I[ic++] = i * slices + i2; I[ic++] = i * slices + i2p1; I[ic++] = ip1 * slices + i2; I[ic++] = i * slices + i2p1; I[ic++] = ip1 * slices + i2p1; } } GenerateNormals(); }
void BaseMesh::SetAlpha(BYTE Alpha) { MeshVertex *V = Vertices(); UINT vc = VertexCount(); for(UINT i = 0; i < vc; i++) { V[i].Color.a = Alpha; } }
void BaseMesh::Translate(const Vec3f &v) { UINT vc = VertexCount(); MeshVertex *V = Vertices(); for(UINT i = 0; i < vc; i++) { V[i].Pos += v; } }
float BaseMesh::SidedSurfaceArea(const Plane &P) { float Result = 0.0f; DWORD *MyIndices = Indices(); MeshVertex *MyVertices = Vertices(); UINT TriangleCount = FaceCount(); for(UINT TriangleIndex = 0; TriangleIndex < TriangleCount; TriangleIndex++) { Vec3f LocalTriangle[6]; UINT TSide[3]; for(UINT LocalVertexIndex = 0; LocalVertexIndex < 3; LocalVertexIndex++) { LocalTriangle[LocalVertexIndex] = MyVertices[MyIndices[TriangleIndex * 3 + LocalVertexIndex]].Pos; if(Plane::DotCoord(P, LocalTriangle[LocalVertexIndex]) < 0.0f) { TSide[LocalVertexIndex] = 0; } else { TSide[LocalVertexIndex] = 1; } } UINT TriangleType = TSide[0] * 4 + TSide[1] * 2 + TSide[2] * 1; for(UINT EdgeIndex = 0; EdgeIndex < 3; EdgeIndex++) { if(PerfectEdges[TriangleType][EdgeIndex]) { Vec3f Vtx1 = MyVertices[MyIndices[TriangleIndex * 3 + PerfectEdgeList[EdgeIndex][0]]].Pos; Vec3f Vtx2 = MyVertices[MyIndices[TriangleIndex * 3 + PerfectEdgeList[EdgeIndex][1]]].Pos; Vec3f VtxIntersect = P.IntersectLine(Vtx1, Vtx2); if(!Vec3f::WithinRect(VtxIntersect, Rectangle3f::ConstructFromTwoPoints(Vtx1, Vtx2))) { VtxIntersect = (Vtx1 + Vtx2) * 0.5f; } LocalTriangle[3 + EdgeIndex] = VtxIntersect; } } for(UINT LocalTriangleIndex = 0; LocalTriangleIndex < 6; LocalTriangleIndex += 3) { if(M1Indices[TriangleType][LocalTriangleIndex] != -1) { Vec3f V[3]; V[0] = LocalTriangle[M1Indices[TriangleType][LocalTriangleIndex + 0]]; V[1] = LocalTriangle[M1Indices[TriangleType][LocalTriangleIndex + 1]]; V[2] = LocalTriangle[M1Indices[TriangleType][LocalTriangleIndex + 2]]; Result += Math::TriangleArea(V[0], V[1], V[2]); } } } return Result; }
void BaseMesh::ApplyMatrix(const Matrix4 &M) { UINT vc = VertexCount(); MeshVertex *V = Vertices(); for(UINT i = 0; i < vc; i++) { V[i].Pos = M.TransformPoint(V[i].Pos); V[i].Normal = M.TransformNormal(V[i].Normal); } }
void BaseMesh::Stretch(const Vec3f &v) { UINT vc = VertexCount(); MeshVertex *V = Vertices(); for(UINT i = 0; i < vc; i++) { V[i].Pos.x *= v.x; V[i].Pos.y *= v.y; V[i].Pos.z *= v.z; } }
void BaseMesh::WeldVertices(float Epsilon, Vector<UINT> &OldToNewMapping) { PointSet MyPoints; MyPoints.LoadFromMesh(*this); KDTree3 &Tree = MyPoints.KDTree(); UINT VC = VertexCount(), IC = IndexCount(); MeshVertex *V = Vertices(); DWORD *I = Indices(); OldToNewMapping.ReSize(VC); OldToNewMapping.Clear(VC); Vector<UINT> NNResult; //MeshVertex *VStorage = new MeshVertex[VC]; for(UINT VertexIndex = 0; VertexIndex < VC; VertexIndex++) { Vec3f Pos = V[VertexIndex].Pos; Tree.WithinDistance(Pos, Epsilon, NNResult); bool MatchFound = false; //VStorage[VertexIndex] = V[VertexIndex]; for(UINT ResultIndex = 0; ResultIndex < NNResult.Length() && !MatchFound; ResultIndex++) { UINT CurIndex = NNResult[ResultIndex]; if(OldToNewMapping[CurIndex] != VC) { MatchFound = true; OldToNewMapping[VertexIndex] = CurIndex; } } if(!MatchFound) { OldToNewMapping[VertexIndex] = VertexIndex; } } //DWORD *IStorage = new DWORD[IC]; for(UINT IndexIndex = 0; IndexIndex < IC; IndexIndex++) { I[IndexIndex] = OldToNewMapping[UINT(I[IndexIndex])]; } //Allocate( //delete[] VStorage; Vector<UINT> SecondMapping, SplitToUnsplit = OldToNewMapping; CleanVerticesAndTriangles(SecondMapping); for(UINT VertexIndex = 0; VertexIndex < VC; VertexIndex++) { OldToNewMapping[VertexIndex] = SecondMapping[SplitToUnsplit[VertexIndex]]; } }
void BaseMesh::NormalizeNormals() { UINT vc = VertexCount(); MeshVertex *V = Vertices(); for(UINT i = 0; i < vc; i++) { if(V[i].Normal.LengthSq() != 0.0f) { V[i].Normal = Vec3f::Normalize(V[i].Normal); } } }
void CMine::EditGeoFwd () { double x,y,z; double radius; vms_vector center,opp_center; int i; /* calculate center of current side */ center.x = center.y = center.z = 0; for (i = 0; i < 4; i++) { int vertnum = Segments (Current ()->segment)->verts [side_vert [Current ()->side][i]]; center.x += Vertices (vertnum)->x; center.y += Vertices (vertnum)->y; center.z += Vertices (vertnum)->z; } center.x /= 4; center.y /= 4; center.z /= 4; // calculate center of opposite of current side opp_center.x = opp_center.y = opp_center.z = 0; for (i = 0; i < 4; i++) { int vertnum = Segments (Current ()->segment)->verts [opp_side_vert [Current ()->side][i]]; opp_center.x += Vertices (vertnum)->x; opp_center.y += Vertices (vertnum)->y; opp_center.z += Vertices (vertnum)->z; } opp_center.x /= 4; opp_center.y /= 4; opp_center.z /= 4; // normalize vector x = center.x - opp_center.x; y = center.y - opp_center.y; z = center.z - opp_center.z; // normalize direction radius = sqrt(x*x + y*y + z*z); if (radius > (F1_0/10)) { x /= radius; y /= radius; z /= radius; } else { vms_vector direction; CalcOrthoVector(direction,Current ()->segment,Current ()->side); x = (double)direction.x/(double)F1_0; y = (double)direction.y/(double)F1_0; z = (double)direction.z/(double)F1_0; } // move on x, y, and z theApp.SetModified (TRUE); theApp.LockUndo (); MoveOn('X', (INT32) (x*move_rate)); MoveOn('Y', (INT32) (y*move_rate)); MoveOn('Z', (INT32) (z*move_rate)); theApp.UnlockUndo (); }
void BaseMesh::CullFaces(const BYTE FaceTest[]) { Vector<DWORD> NewIndices; Vector<MeshVertex> NewVertices; UINT NumFaces = FaceCount(), NumVertices = VertexCount(); DWORD *I = Indices(); MeshVertex *V = Vertices(); for(UINT VertexIndex = 0; VertexIndex < NumVertices; VertexIndex++) { NewVertices.PushEnd(V[VertexIndex]); } for(UINT FaceIndex = 0; FaceIndex < NumFaces; FaceIndex++) { if(FaceTest[FaceIndex]) { for(UINT i = 0; i < 3; i++) { NewIndices.PushEnd(I[FaceIndex * 3 + i]); } } } Allocate(NewVertices.Length(), NewIndices.Length() / 3); NumFaces = FaceCount(); NumVertices = VertexCount(); I = Indices(); V = Vertices(); for(UINT VertexIndex = 0; VertexIndex < NumVertices; VertexIndex++) { V[VertexIndex] = NewVertices[VertexIndex]; } for(UINT FaceIndex = 0; FaceIndex < NumFaces; FaceIndex++) { for(UINT i = 0; i < 3; i++) { I[FaceIndex * 3 + i] = NewIndices[FaceIndex * 3 + i]; } } }