// Aerodynamic forces, 50x1g flyers void InitAero() { const float s = 2; const int segments = 6; const int count = 50; Random random = new Random(); for (int i = 0; i < count; ++i) { SoftBody psb = SoftBodyHelpers.CreatePatch(softBodyWorldInfo, new Vector3(-s, 0, -s), new Vector3(+s, 0, -s), new Vector3(-s, 0, +s), new Vector3(+s, 0, +s), segments, segments, 0, true); Material pm = psb.AppendMaterial(); pm.Flags -= FMaterial.DebugDraw; psb.GenerateBendingConstraints(2, pm); psb.Cfg.LF = 0.004f; psb.Cfg.DG = 0.0003f; psb.Cfg.AeroModel = AeroModel.VTwoSided; Matrix trans = Matrix.Identity; Vector3 ra = 0.1f * GetRandomVector(random); Vector3 rp = 75 * GetRandomVector(random) + new Vector3(-50, 15, 0); Quaternion rot = Quaternion.RotationYawPitchRoll( (float)Math.PI / 8 + ra.X, (float)-Math.PI / 7 + ra.Y, ra.Z); trans *= Matrix.RotationQuaternion(rot); trans *= Matrix.Translation(rp); psb.Transform(trans); psb.TotalMass = 0.1f; psb.AddForce(new Vector3(0, (float)random.NextDouble(), 0), 0); SoftWorld.AddSoftBody(psb); } CullingEnabled = false; }
void InitClusterCollide2() { for (int i = 0; i < 3; ++i) { SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, TorusMesh.Vertices, TorusMesh.Indices); Material pm = psb.AppendMaterial(); pm.Flags -= FMaterial.DebugDraw; psb.GenerateBendingConstraints(2, pm); psb.Cfg.PIterations = 2; psb.Cfg.DF = 1; psb.Cfg.SshrCl = 1; psb.Cfg.SSSplitCl = 0; psb.Cfg.SkhrCl = 0.1f; psb.Cfg.SKSplitCl = 1; psb.Cfg.Collisions = FCollisions.CLSS | FCollisions.CLRS; psb.RandomizeConstraints(); Matrix m = Matrix.RotationYawPitchRoll((float)Math.PI / 2 * (i & 1), (float)Math.PI / 2 * (1 - (i & 1)), 0) * Matrix.Translation(3 * i, 2, 0); psb.Transform(m); psb.Scale(new Vector3(2, 2, 2)); psb.SetTotalMass(50, true); psb.GenerateClusters(16); SoftWorld.AddSoftBody(psb); } }
void InitTorusMatch() { SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, TorusMesh.Vertices, TorusMesh.Indices); psb.Materials[0].Lst = 0.1f; psb.Cfg.MT = 0.05f; psb.RandomizeConstraints(); Matrix m = Matrix.RotationYawPitchRoll(0, (float)Math.PI / 2, 0) * Matrix.Translation(0, 4, 0); psb.Transform(m); psb.Scale(new Vector3(2, 2, 2)); psb.SetTotalMass(50, true); psb.SetPose(false, true); SoftWorld.AddSoftBody(psb); }
void InitTorus() { SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, TorusMesh.Vertices, TorusMesh.Indices); psb.GenerateBendingConstraints(2); psb.Cfg.PIterations = 2; psb.RandomizeConstraints(); Matrix m = Matrix.RotationYawPitchRoll(0, (float)Math.PI / 2, 0) * Matrix.Translation(0, 4, 0); psb.Transform(m); psb.Scale(new Vector3(2, 2, 2)); psb.SetTotalMass(50, true); SoftWorld.AddSoftBody(psb); cutting = true; }
void Init_Aero2() { const float s = 5; const int segments = 10; const int count = 5; Vector3 pos = new Vector3(-s * segments, 0, 0); float gap = 0.5f; for (int i = 0; i < count; ++i) { SoftBody psb = SoftBodyHelpers.CreatePatch(softBodyWorldInfo, new Vector3(-s, 0, -s * 3), new Vector3(+s, 0, -s * 3), new Vector3(-s, 0, +s), new Vector3(+s, 0, +s), segments, segments * 3, 1 + 2, true); psb.CollisionShape.Margin = 0.5f; Material pm = psb.AppendMaterial(); pm.Lst = 0.0004f; pm.Flags -= FMaterial.DebugDraw; psb.GenerateBendingConstraints(2, pm); psb.Cfg.LF = 0.05f; psb.Cfg.DG = 0.01f; //psb.Cfg.LF = 0.004f; //psb.Cfg.DG = 0.0003f; psb.Cfg.PIterations = 2; psb.Cfg.AeroModel = AeroModel.VTwoSidedLiftDrag; psb.WindVelocity = new Vector3(4, -12.0f, -25.0f); pos += new Vector3(s * 2 + gap, 0, 0); Matrix trs = Matrix.RotationX((float)Math.PI / 2) * Matrix.Translation(pos); psb.Transform(trs); psb.TotalMass = 2.0f; SoftBodyHelpers.ReoptimizeLinkOrder(psb); SoftWorld.AddSoftBody(psb); } Graphics.CullingEnabled = false; }
void InitCollide() { for (int i = 0; i < 3; ++i) { SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, TorusMesh.Vertices, TorusMesh.Indices); psb.GenerateBendingConstraints(2); psb.Cfg.PIterations = 2; psb.Cfg.Collisions |= FCollisions.VFSS; psb.RandomizeConstraints(); Matrix m = Matrix.RotationYawPitchRoll((float)Math.PI / 2 * (i & 1), (float)Math.PI / 2 * (1 - (i & 1)), 0) * Matrix.Translation(3 * i, 2, 0); psb.Transform(m); psb.Scale(new Vector3(2, 2, 2)); psb.SetTotalMass(50, true); SoftWorld.AddSoftBody(psb); } cutting = true; }
void InitBunny() { SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, BunnyMesh.Vertices, BunnyMesh.Indices); Material pm = psb.AppendMaterial(); pm.Lst = 0.5f; pm.Flags -= FMaterial.DebugDraw; psb.GenerateBendingConstraints(2, pm); psb.Cfg.PIterations = 2; psb.Cfg.DF = 0.5f; psb.RandomizeConstraints(); Matrix m = Matrix.RotationYawPitchRoll(0, (float)Math.PI / 2, 0) * Matrix.Translation(0, 4, 0); psb.Transform(m); psb.Scale(new Vector3(6, 6, 6)); psb.SetTotalMass(100, true); SoftWorld.AddSoftBody(psb); cutting = true; }
SoftBody CreateClusterTorus(Vector3 x, Vector3 a, Vector3 s) { SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, TorusMesh.Vertices, TorusMesh.Indices); Material pm = psb.AppendMaterial(); pm.Lst = 1; pm.Flags -= FMaterial.DebugDraw; psb.GenerateBendingConstraints(2, pm); psb.Cfg.PIterations = 2; psb.Cfg.Collisions = FCollisions.CLSS | FCollisions.CLRS; psb.RandomizeConstraints(); psb.Scale(s); Matrix m = Matrix.RotationYawPitchRoll(a.X, a.Y, a.Z) * Matrix.Translation(x); psb.Transform(m); psb.SetTotalMass(50, true); psb.GenerateClusters(64); SoftWorld.AddSoftBody(psb); return(psb); }
// Create a sequence of flag objects and add them to the world. void CreateFlag(int width, int height, out AlignedSoftBodyArray flags) { flags = new AlignedSoftBodyArray(); // First create a triangle mesh to represent a flag // Allocate a simple mesh consisting of a vertex array and a triangle index array IndexedMesh mesh = new IndexedMesh(); mesh.NumVertices = width * height; mesh.NumTriangles = 2 * (width - 1) * (height - 1); Vector3Array vertexArray = new Vector3Array(mesh.NumVertices); mesh.Vertices = vertexArray; mesh.VertexStride = Vector3.SizeInBytes; IntArray triangleVertexIndexArray = new IntArray(3 * mesh.NumTriangles); mesh.TriangleIndices = triangleVertexIndexArray; mesh.TriangleIndexStride = sizeof(int) * 3; // Generate normalised object space vertex coordinates for a rectangular flag Matrix defaultScale = Matrix.Scaling(5, 20, 1); for (int y = 0; y < height; ++y) { float yCoordinate = y * 2.0f / (float)height - 1.0f; for (int x = 0; x < width; ++x) { float xCoordinate = x * 2.0f / (float)width - 1.0f; Vector3 vertex = new Vector3(xCoordinate, yCoordinate, 0.0f); vertexArray[y * width + x] = Vector3.TransformCoordinate(vertex, defaultScale); } } // Generate vertex indices for triangles for (int y = 0; y < (height - 1); ++y) { for (int x = 0; x < (width - 1); ++x) { // Triangle 0 // Top left of square on mesh { int vertex0 = y * width + x; int vertex1 = vertex0 + 1; int vertex2 = vertex0 + width; int triangleIndex = 2 * (y * (width - 1) + x); triangleVertexIndexArray[(mesh.TriangleIndexStride * triangleIndex) / sizeof(int)] = vertex0; triangleVertexIndexArray[(mesh.TriangleIndexStride * triangleIndex + 1) / sizeof(int) + 1] = vertex1; triangleVertexIndexArray[(mesh.TriangleIndexStride * triangleIndex + 2) / sizeof(int) + 2] = vertex2; } // Triangle 1 // Bottom right of square on mesh { int vertex0 = y * width + x + 1; int vertex1 = vertex0 + width; int vertex2 = vertex1 - 1; int triangleIndex = 2 * y * (width - 1) + 2 * x + 1; triangleVertexIndexArray[(mesh.TriangleIndexStride * triangleIndex) / sizeof(int)] = vertex0; triangleVertexIndexArray[(mesh.TriangleIndexStride * triangleIndex) / sizeof(int) + 1] = vertex1; triangleVertexIndexArray[(mesh.TriangleIndexStride * triangleIndex) / sizeof(int) + 2] = vertex2; } } } Matrix defaultRotateAndScale = Matrix.RotationX(0.5f); // Construct the sequence flags applying a slightly different translation to each one to arrange them // appropriately in the scene. for (int i = 0; i < numFlags; ++i) { float zTranslate = flagSpacing * (i - numFlags / 2); Vector3 defaultTranslate = new Vector3(0, 20, zTranslate); Matrix transform = defaultRotateAndScale * Matrix.Translation(defaultTranslate); SoftBody softBody = CreateFromIndexedMesh(vertexArray, triangleVertexIndexArray, true); for (int j = 0; j < mesh.NumVertices; ++j) { softBody.SetMass(j, 10.0f / mesh.NumVertices); } softBody.SetMass((height - 1) * width, 0); softBody.SetMass((height - 1) * width + width - 1, 0); softBody.SetMass((height - 1) * width + width / 2, 0); softBody.Cfg.Collisions = FCollisions.CLSS | FCollisions.CLRS; softBody.Cfg.LF = 0.0005f; softBody.Cfg.VCF = 0.001f; softBody.Cfg.DP = 0.0f; softBody.Cfg.DG = 0.0f; flags.Add(softBody); softBody.Transform(transform); SoftWorld.AddSoftBody(softBody); } //delete [] vertexArray; //delete [] triangleVertexIndexArray; }