// Constructor. public Projectile(LabGame game, MyModel myModel, Vector3 pos, Vector3 vel, GameObjectType targetType) { this.game = game; this.myModel = myModel; this.pos = pos; this.vel = vel; this.targetType = targetType; squareHitRadius = hitRadius * hitRadius; GetParamsFromModel(); }
private Vector3 vel; //Local class velocity for projectile only behaviours #endregion Fields #region Constructors /// <summary> /// Create a new projectile. /// </summary> /// <param name="game"></param> /// <param name="myModel"></param> /// <param name="pos"></param> /// <param name="vel"></param> /// <param name="targetType"></param> public Projectile(LabGame game, MyModel myModel, Vector3 pos, Vector3 vel, PhysicalObject shooter) { this.game = game; this.myModel = myModel; this.pos = pos; this.vel = vel; this.shooter = shooter; this.locallight.lightPos = new Vector4(this.pos.X, this.pos.Y, this.pos.Z - 2, 1f); this.locallight.lightCol = new Vector4(0.15f, 0.15f, 0.15f, 1f); squareHitRadius = hitRadius * hitRadius; GetParamsFromModel(); initPos = pos; }
/// <summary> /// Create a new ocean. /// </summary> /// <param name="size">Size of ocean</param> /// <param name="seaLevel">Height of ocean.</param> /// <returns>An ocean model.</returns> public MyModel CreateOcean(int size, int seaLevel) { float collisionRadius = 1; int sidelength = (int)Math.Pow(2, size); int min = -sidelength / 2; int k = 0; // Data structures for generating vertice heightmap Vector3[][] points = new Vector3[sidelength][]; Vector3[][] normals = new Vector3[sidelength][]; Random rand = new Random(); // Generate an ocean by calling the function points = genMap(sidelength, -WORLD_WIDTH, WORLD_WIDTH, -WORLD_WIDTH, WORLD_WIDTH, -seaLevel); // Calculate vertex normals normals = getNormals(points); VertexPositionNormalColor[] shapeArray = new VertexPositionNormalColor[sidelength * sidelength * 6]; for (int i = 0; i < sidelength; i++) { for (int j = 0; j < sidelength; j++) { //Each step creates a square in the map mesh //Bottom triangle shapeArray[k] = new VertexPositionNormalColor(points[i][j], -Vector3.UnitZ, Color.SkyBlue); shapeArray[k + 1] = new VertexPositionNormalColor(points[i+1][j+1], -Vector3.UnitZ, Color.SkyBlue); shapeArray[k + 2] = new VertexPositionNormalColor(points[i+1][j], -Vector3.UnitZ, Color.SkyBlue); //Top Triangle shapeArray[k + 3] = new VertexPositionNormalColor(points[i][j], -Vector3.UnitZ, Color.SkyBlue); shapeArray[k + 4] = new VertexPositionNormalColor(points[i][j+1], -Vector3.UnitZ, Color.SkyBlue); shapeArray[k + 5] = new VertexPositionNormalColor(points[i+1][j+1], -Vector3.UnitZ, Color.SkyBlue); k += 6; } } MyModel m = new MyModel(game, shapeArray, collisionRadius); // Make reference to points game.worldBase.heights = points; m.modelMap = points; return m; }
/// <summary> /// Create a world base to use. /// </summary> /// <param name="size">Size of world.</param> /// <returns>A world model.</returns> public MyModel CreateWorldBase(int size) { float collisionRadius = 1; float magnitude = HEIGHT_INIT; int sidelength = (int)Math.Pow(2, size); int min = -sidelength / 2; int k = 0; // Data structures for generating vertice heightmap Vector3[][] points = new Vector3[sidelength][]; Vector3[][] normals = new Vector3[sidelength][]; Random rand = new Random(); // Generate a map by calling the function points = genMap(sidelength, -WORLD_WIDTH, WORLD_WIDTH, -WORLD_WIDTH, WORLD_WIDTH, 0.0f); // Apply diamond square algorithm points = diamondSquare(points, rand, HEIGHT_INIT, 0, sidelength, 0, sidelength, CORNER); // Apply diamond square algorithm points = flattenSection(points, sidelength, 30,50,30,50); points = diamondSquare(points, rand, 1, 32, 49, 32, 49, -4); // Apply diamond square algorithm points = flattenSection(points, sidelength, 30,50,85,100); points = diamondSquare(points, rand, 1, 32, 49, 87, 96, -4); // Apply diamond square algorithm points = flattenSection(points, sidelength, 85,100,30,50); points = diamondSquare(points, rand, 1, 87, 96, 32, 49, -4); // Apply diamond square algorithm points = flattenSection(points, sidelength, 85,100,85,100); points = diamondSquare(points, rand, 1, 87, 96, 87, 96, -4); // Lower points points = lowerSeaFloor(points, sidelength, -1, 2.0f); // Calculate vertex normals normals = getNormals(points); VertexPositionNormalColor[] shapeArray = new VertexPositionNormalColor[(sidelength + 1) * (sidelength + 1) *6]; for (int i = 0; i < sidelength; i++) { for (int j = 0; j < sidelength; j++) { //Each step creates a square in the map mesh //Bottom triangle shapeArray[k] = new VertexPositionNormalColor(points[i][j], -Vector3.UnitZ, getColor(points[i][j])); shapeArray[k + 1] = new VertexPositionNormalColor(points[i+1][j+1], -Vector3.UnitZ, getColor(points[i+1][j+1])); shapeArray[k + 2] = new VertexPositionNormalColor(points[i+1][j], -Vector3.UnitZ, getColor(points[i+1][j])); //Top Triangle shapeArray[k + 3] = new VertexPositionNormalColor(points[i][j], -Vector3.UnitZ, getColor(points[i][j])); shapeArray[k + 4] = new VertexPositionNormalColor(points[i][j+1], -Vector3.UnitZ, getColor(points[i][j+1])); shapeArray[k + 5] = new VertexPositionNormalColor(points[i+1][j+1], -Vector3.UnitZ, getColor(points[i+1][j+1])); k += 6; } } MyModel m = new MyModel(game, shapeArray, collisionRadius); // Make reference to points m.modelMap = points; return m; }