wxXmlProperty *nwxXmlContainer::CreateProperties(int *pnCount) { int nCount = 0; wxString sValue; wxXmlProperty *pFirst(NULL); wxXmlProperty *pLast(NULL); wxXmlProperty *pThis(NULL); PERSISTstr *pPERSIST; for(mapPERSISTstr::iterator itr = m_mapAttr.begin(); itr != m_mapAttr.end(); ++itr) { pPERSIST = itr->second; if(pPERSIST->pPersist->CreateString(&sValue,pPERSIST->pObj)) { pThis = new wxXmlProperty(pPERSIST->sName,sValue); ++nCount; if(pLast == NULL) { // begin list pFirst = pThis; pLast = pThis; } else { // append list pLast->SetNext(pThis); pLast = pThis; } } } if(pnCount != NULL) { *pnCount = nCount; } return pFirst; }
// Generate a lathe by rotating the given polyline void AProceduralLatheActor::GenerateLathe(const TArray<FVector>& InPoints, const int InSegments, TArray<FProceduralMeshTriangle>& OutTriangles) { UE_LOG(LogClass, Log, TEXT("AProceduralLatheActor::Lathe POINTS %d"), InPoints.Num()); TArray<FVector> verts; // precompute some trig float angle = FMath::DegreesToRadians(360.0f / InSegments); float sinA = FMath::Sin(angle); float cosA = FMath::Cos(angle); /* This implementation is rotation around the X Axis, other formulas below Z Axis Rotation x' = x*cos q - y*sin q y' = x*sin q + y*cos q z' = z X Axis Rotation y' = y*cos q - z*sin q z' = y*sin q + z*cos q x' = x Y Axis Rotation z' = z*cos q - x*sin q x' = z*sin q + x*cos q y' = y */ // Working point array, in which we keep the rotated line we draw with TArray<FVector> wp; for(int i = 0; i < InPoints.Num(); i++) { wp.Add(InPoints[i]); } // Add a first and last point on the axis to complete the OutTriangles FVector p0(wp[0].X, 0, 0); FVector pLast(wp[wp.Num() - 1].X, 0, 0); FProceduralMeshTriangle tri; // for each segment draw the OutTriangles clockwise for normals pointing out or counterclockwise for the opposite (this here does CW) for(int segment = 0; segment<InSegments; segment++) { for(int i = 0; i<InPoints.Num() - 1; i++) { FVector p1 = wp[i]; FVector p2 = wp[i + 1]; FVector p1r(p1.X, p1.Y*cosA - p1.Z*sinA, p1.Y*sinA + p1.Z*cosA); FVector p2r(p2.X, p2.Y*cosA - p2.Z*sinA, p2.Y*sinA + p2.Z*cosA); static const FColor Red(255, 51, 51); tri.Vertex0.Color = Red; tri.Vertex1.Color = Red; tri.Vertex2.Color = Red; if(i == 0) { tri.Vertex0.Position = p1; tri.Vertex1.Position = p0; tri.Vertex2.Position = p1r; OutTriangles.Add(tri); } tri.Vertex0.Position = p1; tri.Vertex1.Position = p1r; tri.Vertex2.Position = p2; OutTriangles.Add(tri); tri.Vertex0.Position = p2; tri.Vertex1.Position = p1r; tri.Vertex2.Position = p2r; OutTriangles.Add(tri); if(i == InPoints.Num() - 2) { tri.Vertex0.Position = p2; tri.Vertex1.Position = p2r; tri.Vertex2.Position = pLast; OutTriangles.Add(tri); wp[i + 1] = p2r; } wp[i] = p1r; } } }
void AQuadTree::Lathe(const TArray<FVector>& points, TArray<FGeneratedMeshTriangle>& triangles, int32 segments) { UE_LOG(LogClass, Log, TEXT("AQuadTree::Lathe POINTS %d"), points.Num()); // precompute some trig float angle = FMath::DegreesToRadians(360.0f / segments); float sinA = FMath::Sin(angle); float cosA = FMath::Cos(angle); //This implementation is rotation around the X Axis, other formulas below //Z Axis Rotation //x' = x*cos q - y*sin q //y' = x*sin q + y*cos q //z' = z //X Axis Rotation //y' = y*cos q - z*sin q //z' = y*sin q + z*cos q //x' = x //Y Axis Rotation //z' = z*cos q - x*sin q //x' = z*sin q + x*cos q //y' = y //Working point array, in which we keep the rotated line we draw with TArray<FVector> wp; for (int i = 0; i < points.Num(); i++) { wp.Add(points[i]); } // Add a first and last point on the axis to complete the triangles FVector p0(wp[0].X, 0, 0); FVector pLast(wp[wp.Num() - 1].X, 0, 0); FGeneratedMeshTriangle tri; //for each segment draw the triangles clockwise for normals pointing out or counterclockwise for the opposite (this here does CW) for (int segment = 0; segment<segments; segment++) { for (int i = 0; i<points.Num() - 1; i++) { FVector p1 = wp[i]; FVector p2 = wp[i + 1]; FVector p1r(p1.X, p1.Y*cosA - p1.Z*sinA, p1.Y*sinA + p1.Z*cosA); FVector p2r(p2.X, p2.Y*cosA - p2.Z*sinA, p2.Y*sinA + p2.Z*cosA); if (i == 0) { tri.Vertex0 = p1; tri.Vertex1 = p0; tri.Vertex2 = p1r; triangles.Add(tri); } tri.Vertex0 = p1; tri.Vertex1 = p1r; tri.Vertex2 = p2; triangles.Add(tri); tri.Vertex0 = p2; tri.Vertex1 = p1r; tri.Vertex2 = p2r; triangles.Add(tri); if (i == points.Num() - 2) { tri.Vertex0 = p2; tri.Vertex1 = p2r; tri.Vertex2 = pLast; triangles.Add(tri); wp[i + 1] = p2r; } wp[i] = p1r; } } }