-
Notifications
You must be signed in to change notification settings - Fork 202
/
Copy pathTornadoDemo.cs
103 lines (95 loc) · 4.36 KB
/
TornadoDemo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using BEPUphysics.BroadPhaseEntries;
using BEPUphysics.Entities;
using BEPUphysics.Entities.Prefabs;
using BEPUutilities;
using BEPUphysics.UpdateableSystems.ForceFields;
using BEPUphysicsDemos.SampleCode;
namespace BEPUphysicsDemos.Demos
{
/// <summary>
/// Unsuspecting blocks get ambushed by a whirlwind.
/// </summary>
public class TornadoDemo : StandardDemo
{
private readonly BoundingBoxForceFieldShape shape;
private readonly Tornado tornado;
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public TornadoDemo(DemosGame game)
: base(game)
{
shape = new BoundingBoxForceFieldShape(new BoundingBox(new Vector3(-100, -20, -40), new Vector3(-20, 120, 40)));
tornado = new Tornado(shape, (shape.BoundingBox.Min + shape.BoundingBox.Max) / 2, new Vector3(0, 1, 0),
150, false, 50, 10, 200, 200, 80, 2000, 40, 10);
tornado.ForceWakeUp = true; //The tornado will be moving, so it should wake up things that it comes into contact with.
Space.Add(tornado);
//Create the unfortunate box-like citizens about to be hit by the tornado.
int numColumns = 10;
int numRows = 10;
int numHigh = 1;
float separation = 1.5f;
Entity toAdd;
for (int i = 0; i < numRows; i++)
for (int j = 0; j < numColumns; j++)
for (int k = 0; k < numHigh; k++)
{
toAdd = new Box(new Vector3(
separation * i - numRows * separation / 2,
5 + k * separation,
separation * j - numColumns * separation / 2),
1, 1, 1, 10);
Space.Add(toAdd);
}
//x and y, in terms of heightmaps, refer to their local x and y coordinates. In world space, they correspond to x and z.
//Setup the heights of the terrain.
//[The size here is limited by the Reach profile the demos use- the drawer draws the terrain as a big block and runs into primitive drawing limits.
//The physics can support far larger terrains!]
int xLength = 180;
int zLength = 180;
float xSpacing = 8f;
float zSpacing = 8f;
var heights = new float[xLength,zLength];
for (int i = 0; i < xLength; i++)
{
for (int j = 0; j < zLength; j++)
{
float x = i - xLength / 2;
float z = j - zLength / 2;
//heights[i,j] = (float)Math.Pow(1.2 * Math.Sqrt(x * x + y * y), 2);
//heights[i,j] = -1f / (x * x + y * y);
//heights[i,j] = (float)(x * y / 100f);
heights[i,j] = (float)(5 * (Math.Sin(x / 8f) + Math.Sin(z / 8f)));
//heights[i,j] = 3 * (float)Math.Sin(x * y / 100f);
//heights[i,j] = (x * x * x * y - y * y * y * x) / 1000f;
}
}
//Create the terrain.
var terrain = new Terrain(heights, new AffineTransform(
new Vector3(xSpacing, 1, zSpacing),
Quaternion.Identity,
new Vector3(-xLength * xSpacing / 2, 0, -zLength * zSpacing / 2)));
Space.Add(terrain);
game.ModelDrawer.Add(terrain);
game.Camera.Position = new Vector3(0, 5, 60);
}
/// <summary>
/// Gets the name of the simulation.
/// </summary>
public override string Name
{
get { return "Tornado"; }
}
public override void Update(float dt)
{
//Move the origin of the force of the tornado,
Vector3 increment = new Vector3(10, 0, 0) * dt;
//Move the detection shape as well.
shape.BoundingBox = new BoundingBox(shape.BoundingBox.Min + increment, shape.BoundingBox.Max + increment);
tornado.Position += increment;
base.Update(dt);
}
}
}