public MapCompiled(MapData data) { Walls = new List<WallCompiled>(); foreach (var wallData in data.Walls) { var wall = new WallCompiled(wallData); Walls.Add(wall); } NumGoalTriangles = 0; Goals = new List<GoalCompiled>(); foreach (var goalData in data.Goals) { var goal = new GoalCompiled(goalData); Goals.Add(goal); NumGoalTriangles += goal.Triangles.Count; } NumSpeedupTriangles = 0; Speedups = new List<SpeedupCompiled>(); foreach (var speedupData in data.Speedups) { var speedup = new SpeedupCompiled(speedupData); Speedups.Add(speedup); NumSpeedupTriangles += speedup.Triangles.Count; } Spawns = data.Spawns; Balls = data.Balls; Goalies = data.Goalies; }
public Wall(World world, WallCompiled wall) { if (wall.Shape == ShapeData.Closed) Fixtures = new Fixture[wall.Verts1.Length]; else Fixtures = new Fixture[wall.Verts1.Length-1]; for (int i = 0; i < wall.Verts1.Length-1; i++) addQuad(world, wall, i, i+1); if (wall.Shape == ShapeData.Closed) addQuad(world, wall, wall.Verts1.Length-1, 0); }
public void addQuad(World world, WallCompiled wall, int a, int b) { var verts = new Vertices(4); verts.Add(wall.Verts1[a]); verts.Add(wall.Verts4[a]); verts.Add(wall.Verts4[b]); verts.Add(wall.Verts1[b]); var wallBody = new Body(world); var wallShape = new PolygonShape(verts, 1f); Fixtures[a] = wallBody.CreateFixture(wallShape); Fixtures[a].Friction = 0f; }
void makeQuads(WallCompiled wall, MeshBuilder<VertexTNP3> builder, int a, int b) { Quad<VertexTNP3> quad; var bottom = wall.Thickness * bottomLength; var mid = wall.Thickness * midLength; var top = wall.Thickness * topLength; Vector3 v1, v2, v3, v4, normal; Vector2 t1, t2, t3, t4; t1 = new Vector2(.5f, wall.TexesBegin1[a]); v1 = new Vector3(wall.Verts1[a].X, wall.Verts1[a].Y, bottom); t2 = new Vector2(.5f, wall.TexesEnd1[b]); v2 = new Vector3(wall.Verts1[b].X, wall.Verts1[b].Y, bottom); t3 = new Vector2(1f, wall.TexesBegin1[a]); v3 = new Vector3(wall.Verts1[a].X, wall.Verts1[a].Y, mid); t4 = new Vector2(1f, wall.TexesEnd1[b]); v4 = new Vector3(wall.Verts1[b].X, wall.Verts1[b].Y, mid); normal = Vector3.Cross(v3 - v1, v4 - v1); normal.Normalize(); quad.A.Normal = normal; quad.A.Position = v2; quad.A.TexCoord = t2; quad.B.Normal = normal; quad.B.Position = v1; quad.B.TexCoord = t1; quad.C.Normal = normal; quad.C.Position = v3; quad.C.TexCoord = t3; quad.D.Normal = normal; quad.D.Position = v4; quad.D.TexCoord = t4; builder.Add(quad); t1 = new Vector2(.5f, wall.TexesBegin4[a]); v1 = new Vector3(wall.Verts4[a].X, wall.Verts4[a].Y, bottom); t2 = new Vector2(.5f, wall.TexesEnd4[b]); v2 = new Vector3(wall.Verts4[b].X, wall.Verts4[b].Y, bottom); t3 = new Vector2(1f, wall.TexesBegin4[a]); v3 = new Vector3(wall.Verts4[a].X, wall.Verts4[a].Y, mid); t4 = new Vector2(1f, wall.TexesEnd4[b]); v4 = new Vector3(wall.Verts4[b].X, wall.Verts4[b].Y, mid); normal = Vector3.Cross(v1 - v3, v4 - v3); normal.Normalize(); quad.A.Normal = normal; quad.A.Position = v1; quad.A.TexCoord = t1; quad.B.Normal = normal; quad.B.Position = v2; quad.B.TexCoord = t2; quad.C.Normal = normal; quad.C.Position = v4; quad.C.TexCoord = t4; quad.D.Normal = normal; quad.D.Position = v3; quad.D.TexCoord = t3; builder.Add(quad); t1 = new Vector2(.5f, wall.TexesBegin2[a]); v1 = new Vector3(wall.Verts2[a].X, wall.Verts2[a].Y, top); t2 = new Vector2(.5f, wall.TexesEnd2[b]); v2 = new Vector3(wall.Verts2[b].X, wall.Verts2[b].Y, top); t3 = new Vector2(1f, wall.TexesBegin3[a]); v3 = new Vector3(wall.Verts3[a].X, wall.Verts3[a].Y, top); t4 = new Vector2(1f, wall.TexesEnd3[b]); v4 = new Vector3(wall.Verts3[b].X, wall.Verts3[b].Y, top); normal = Vector3.Cross(v3 - v1, v4 - v1); normal.Normalize(); quad.A.Normal = normal; quad.A.Position = v2; quad.A.TexCoord = t2; quad.B.Normal = normal; quad.B.Position = v1; quad.B.TexCoord = t1; quad.C.Normal = normal; quad.C.Position = v3; quad.C.TexCoord = t3; quad.D.Normal = normal; quad.D.Position = v4; quad.D.TexCoord = t4; builder.Add(quad); t1 = new Vector2(0f, wall.TexesBegin1[a]); v1 = new Vector3(wall.Verts1[a].X, wall.Verts1[a].Y, mid); t2 = new Vector2(0f, wall.TexesEnd1[b]); v2 = new Vector3(wall.Verts1[b].X, wall.Verts1[b].Y, mid); t3 = new Vector2(.5f, wall.TexesBegin2[a]); v3 = new Vector3(wall.Verts2[a].X, wall.Verts2[a].Y, top); t4 = new Vector2(.5f, wall.TexesEnd2[b]); v4 = new Vector3(wall.Verts2[b].X, wall.Verts2[b].Y, top); normal = Vector3.Cross(v3 - v1, v4 - v1); normal.Normalize(); quad.A.Normal = normal; quad.A.Position = v2; quad.A.TexCoord = t2; quad.B.Normal = normal; quad.B.Position = v1; quad.B.TexCoord = t1; quad.C.Normal = normal; quad.C.Position = v3; quad.C.TexCoord = t3; quad.D.Normal = normal; quad.D.Position = v4; quad.D.TexCoord = t4; builder.Add(quad); t1 = new Vector2(0f, wall.TexesBegin4[a]); v1 = new Vector3(wall.Verts4[a].X, wall.Verts4[a].Y, mid); t2 = new Vector2(0f, wall.TexesEnd4[b]); v2 = new Vector3(wall.Verts4[b].X, wall.Verts4[b].Y, mid); t3 = new Vector2(.5f, wall.TexesBegin3[a]); v3 = new Vector3(wall.Verts3[a].X, wall.Verts3[a].Y, top); t4 = new Vector2(.5f, wall.TexesEnd3[b]); v4 = new Vector3(wall.Verts3[b].X, wall.Verts3[b].Y, top); normal = Vector3.Cross(v1 - v3, v4 - v3); normal.Normalize(); quad.A.Normal = normal; quad.A.Position = v1; quad.A.TexCoord = t1; quad.B.Normal = normal; quad.B.Position = v2; quad.B.TexCoord = t2; quad.C.Normal = normal; quad.C.Position = v4; quad.C.TexCoord = t4; quad.D.Normal = normal; quad.D.Position = v3; quad.D.TexCoord = t3; builder.Add(quad); }