public ToastTileMap(int level, int x, int y) { Level = level; Y = y; X = x; int levels = 0; Vector3d[,] oldBounds = null; backslash = false; while (levels <= level) { if (levels == 0) { oldBounds = masterBounds; } else { Vector3d[,] bounds = new Vector3d[3, 3]; // equiv : xTemp = (int) (x * Mat.Pow(2,levels-level)) ; note that levels-level < 0 int xTemp = (int)(x / Math.Pow(2, level - levels)); int yTemp = (int)(y / Math.Pow(2, level - levels)); int xIndex = xTemp % 2; int yIndex = yTemp % 2; if (levels == 1) { backslash = xIndex == 1 ^ yIndex == 1; } bounds[0, 0] = oldBounds[xIndex, yIndex]; bounds[1, 0] = Vector3d.MidPoint(oldBounds[xIndex, yIndex], oldBounds[xIndex + 1, yIndex]); bounds[2, 0] = oldBounds[xIndex + 1, yIndex]; bounds[0, 1] = Vector3d.MidPoint(oldBounds[xIndex, yIndex], oldBounds[xIndex, yIndex + 1]); if (backslash) { bounds[1, 1] = Vector3d.MidPoint(oldBounds[xIndex, yIndex], oldBounds[xIndex + 1, yIndex + 1]); } else { bounds[1, 1] = Vector3d.MidPoint(oldBounds[xIndex + 1, yIndex], oldBounds[xIndex, yIndex + 1]); } bounds[2, 1] = Vector3d.MidPoint(oldBounds[xIndex + 1, yIndex], oldBounds[xIndex + 1, yIndex + 1]); bounds[0, 2] = oldBounds[xIndex, yIndex + 1]; bounds[1, 2] = Vector3d.MidPoint(oldBounds[xIndex, yIndex + 1], oldBounds[xIndex + 1, yIndex + 1]); bounds[2, 2] = oldBounds[xIndex + 1, yIndex + 1]; oldBounds = bounds; } levels++; } Bounds = oldBounds; InitGrid(); }
// // Summary: // Initializes a new instance of the Microsoft.DirectX.Direct3D.CustomVertex.PositionTextured // class. // // Parameters: // pos: // A Microsoft.DirectX.Vector3d object that contains the vertex position. // // u: // Floating-point value that represents the Microsoft.DirectX.Direct3D.CustomVertex.PositionTextured.#ctor() // component of the texture coordinate. // // v: // Floating-point value that represents the Microsoft.DirectX.Direct3D.CustomVertex.PositionTextured.#ctor() // component of the texture coordinate. public PositionTexture(Vector3d pos, double u, double v) { Tu = u; Tv = v; X = pos.X; Y = pos.Y; Z = pos.Z; }
static ToastTileMap() { masterBounds[0, 0] = new Vector3d(0, -1, 0); masterBounds[1, 0] = new Vector3d(0, 0, -1); masterBounds[2, 0] = new Vector3d(0, -1, 0); masterBounds[0, 1] = new Vector3d(1, 0, 0); masterBounds[1, 1] = new Vector3d(0, 1, 0); masterBounds[2, 1] = new Vector3d(-1, 0, 0); masterBounds[0, 2] = new Vector3d(0, -1, 0); masterBounds[1, 2] = new Vector3d(0, 0, 1); masterBounds[2, 2] = new Vector3d(0, -1, 0); }
// // Summary: // Subtracts two 3-D vectors. // // Parameters: // source: // Source Microsoft.DirectX.Vector3d structure to subtract from the current instance. public void Subtract(Vector3d source) { this.X -= source.X; this.Y -= source.Y; this.Z -= source.Z; }
// // Summary: // Subtracts two 3-D vectors. // // Parameters: // left: // Source Microsoft.DirectX.Vector3d structure to the left of the subtraction // operator. // // right: // Source Microsoft.DirectX.Vector3d structure to the right of the subtraction // operator. // // Returns: // A Microsoft.DirectX.Vector3d structure that is the result of the operation. public static Vector3d Subtract(Vector3d left, Vector3d right) { Vector3d result = left; result.Subtract(right); return result; }
// // Summary: // Multiplies a 3-D vector by a System.Single value. // // Parameters: // source: // Source Microsoft.DirectX.Vector3d structure. // // f: // Source System.Single value used as a multiplier. // // Returns: // A Microsoft.DirectX.Vector3d structure that is multiplied by the System.Single // value. public static Vector3d Multiply(Vector3d source, double f) { Vector3d result = new Vector3d(source); result.Multiply(f); return result; }
// // Summary: // Scales a 3-D vector. // // Parameters: // source: // Source Microsoft.DirectX.Vector3d structure. // // scalingFactor: // Scaling value. // // Returns: // A Microsoft.DirectX.Vector3d structure that is the scaled vector. public static Vector3d Scale(Vector3d source, double scalingFactor) { Vector3d result = source; result.Multiply(scalingFactor); return result; }
// // Summary: // Performs a linear interpolation between two 3-D vectors. // // Parameters: // left: // Source Microsoft.DirectX.Vector3d structure. // // right: // Source Microsoft.DirectX.Vector3d structure. // // interpolater: // Parameter that linearly interpolates between the vectors. // // Returns: // A Microsoft.DirectX.Vector3d structure that is the result of the linear interpolation. public static Vector3d Lerp(Vector3d left, Vector3d right, double interpolater) { return new Vector3d( left.X * (1.0 - interpolater) + right.X * interpolater, left.Y * (1.0 - interpolater) + right.Y * interpolater, left.Z * (1.0 - interpolater) + right.Z * interpolater); }
public Vector3d(Vector3d value) { X = value.X; Y = value.Y; Z = value.Z; }
// // Summary: // Returns the length of a 3-D vector. // // Parameters: // source: // Source Microsoft.DirectX.Vector3d structure. // // Returns: // A System.Single value that contains the vector's length. public static double Length(Vector3d source) { return System.Math.Sqrt(source.X * source.X + source.Y * source.Y + source.Z * source.Z); }
// // Summary: // Returns the square of the length of a 3-D vector. // // Parameters: // source: // Source Microsoft.DirectX.Vector3d structure. // // Returns: // A System.Single value that contains the vector's squared length. public static double LengthSq(Vector3d source) { return source.X * source.X + source.Y * source.Y + source.Z * source.Z; }
// // Summary: // Determines the dot product of two 3-D vectors. // // Parameters: // left: // Source Microsoft.DirectX.Vector3d structure. // // right: // Source Microsoft.DirectX.Vector3d structure. // // Returns: // A System.Single value that is the dot product. public static double Dot(Vector3d left, Vector3d right) { return left.X * right.X + left.Y * right.Y + left.Z * right.Z; }
// // Summary: // Returns a point in barycentric coordinates, using specified 3-D vectors. // // Parameters: // v1: // Source Microsoft.DirectX.Vector3d structure. // // v2: // Source Microsoft.DirectX.Vector3d structure. // // v3: // Source Microsoft.DirectX.Vector3d structure. // // f: // Weighting factor. See Remarks. // // g: // Weighting factor. See Remarks. // // Returns: // A Microsoft.DirectX.Vector3d structure in barycentric coordinates. //public static Vector3d BaryCentric(Vector3d v1, Vector3d v2, Vector3d v3, double f, double g); // // Summary: // Performs a Catmull-Rom interpolation using specified 3-D vectors. // // Parameters: // position1: // Source Microsoft.DirectX.Vector3d structure that is a position vector. // // position2: // Source Microsoft.DirectX.Vector3d structure that is a position vector. // // position3: // Source Microsoft.DirectX.Vector3d structure that is a position vector. // // position4: // Source Microsoft.DirectX.Vector3d structure that is a position vector. // // weightingFactor: // Weighting factor. See Remarks. // // Returns: // A Microsoft.DirectX.Vector3d structure that is the result of the Catmull-Rom // interpolation. //public static Vector3d CatmullRom(Vector3d position1, Vector3d position2, Vector3d position3, Vector3d position4, double weightingFactor) //{ //} // // Summary: // Determines the cross product of two 3-D vectors. // // Parameters: // left: // Source Microsoft.DirectX.Vector3d structure. // // right: // Source Microsoft.DirectX.Vector3d structure. // // Returns: // A Microsoft.DirectX.Vector3d structure that is the cross product of two 3-D // vectors. public static Vector3d Cross(Vector3d left, Vector3d right) { return new Vector3d( left.Y * right.Z - left.Z * right.Y, left.Z * right.X - left.X * right.Z, left.X * right.Y - left.Y * right.X); }
// // Summary: // Adds two 3-D vectors. // // Parameters: // left: // Source Microsoft.DirectX.Vector3d. // // right: // Source Microsoft.DirectX.Vector3d. // // Returns: // Sum of the two Microsoft.DirectX.Vector3d structures. public static Vector3d Add(Vector3d left, Vector3d right) { return new Vector3d(left.X + right.X, left.Y + right.Y, left.Z + right.Z); }
// Summary: // Adds two 3-D vectors. // // Parameters: // source: public void Add(Vector3d source) { X += source.X; Y += source.Y; Z += source.Z; }
public static Vector3d MidPoint(Vector3d left, Vector3d right) { Vector3d result = new Vector3d((left.X + right.X) / 2, (left.Y + right.Y) / 2, (left.Z + right.Z) / 2); result.Normalize(); return result; }