internal void BuildGem(CVector3Dbl aWorldPos) { this.WorldPos = aWorldPos; this.TimeToLive = new TimeSpan(0, 0, 10); this.Scale = 0.05d; this.Radius = 0.05d; }
internal CGemSprite CreateGemNullable(IEnumerable <CGemEnum> aGemEnums, CVector3Dbl aWorldPos) { var aPropability = this.GetGemPropability(aGemEnums); var aGemEnum = aPropability.Next(); var aGem = this.CreateGemNullable(aGemEnum, aWorldPos); return(aGem); }
public double GetAlpha(CVector3Dbl aCameraPos) { var d = this.WorldPos.Value.GetDistance(aCameraPos); var dmax = ((this.Cube.Depth - 1) / 2) + 0; // ; ; // * ((this.World.Cube.EdgeLength - 1) / 2); var df = Math.Min(1d, Math.Max(0d, d / dmax)); //var em = 1.0d; var a = 1d - df; // 1 - (Math.Exp(df * em) / Math.Pow( Math.E ,em)); return(a); }
public void AddExplosion(CVector3Dbl aPos, double aRadius) { var aExplosionSprite = this.AllocateSpriteNullable(); if (aExplosionSprite is object) { aExplosionSprite.WorldPos = aPos; aExplosionSprite.Radius = aRadius; } }
internal CGemSprite CreateGemNullable(CGemEnum aGemEnum, CVector3Dbl aWorldPos) { var aGem = this.AllocateSpriteNullable(aGemEnum); if (aGem is object) { aGem.BuildGem(aWorldPos); aGem.Update(this.World.FrameInfo); } return(aGem); }
internal CVector3Dbl GetWorldPos() { var aValueSprite = this; var aIndex = aValueSprite.Index; var aCount = aValueSprite.Count; var aDy = this.Scale.Value; var aX = ((double)aIndex).F01_Map(0, aCount - 1, -0.8d, 0.8d); var aY = 1d - aDy; var aWorldPos = new CVector3Dbl(aX, aY, 0d); return(aWorldPos); }
internal CQuadrantBuildArgs(CRandomGenerator aRanomdGenerator, CCubePos aTileCubePos, CVector3Dbl aTileWorldPos, Func <CSprite, CSpritePersistentData> aGetSpritePersistentDataFunc, Func <CSprite, int> aNewSpritePersistentId) { this.RandomGenerator = aRanomdGenerator; this.TileCubePos = aTileCubePos; this.TileWorldPos = aTileWorldPos; this.GetSpritePersistentDataFunc = aGetSpritePersistentDataFunc; this.NewSpritePersistentId = aNewSpritePersistentId; }
public CSphere(int c, double r = 1.0d, bool aSurfaceOnly = true) { var l = r / (double)c; var cnt = 2 * c + 1; var ys = new CVector3Dbl[cnt][][]; for (var sy = 0; sy < cnt; ++sy) { var yf1 = ((double)sy) / ((double)cnt - 1); // System.Diagnostics.Debug.Print(yf.ToString()); var xsf = Math.Sin(Math.PI * yf1); var yf = 1d - Math.Sin(Math.PI * (yf1 + 0.5d)); // System.Diagnostics.Debug.Print(yf.ToString()); var y2 = r - r * yf; var y = y2; //System.Diagnostics.Debug.Print(y.ToString()); var xs = new CVector3Dbl[aSurfaceOnly ? 2 : cnt][]; if (aSurfaceOnly) { xs[0] = CalcBelt(cnt, c, -c, xsf, y, r); xs[1] = CalcBelt(cnt, c, c, xsf, y, r); } else { for (var sx = -c; sx <= c; ++sx) { xs[sx + c] = CalcBelt(cnt, c, sx, xsf, y, r); } } ys[sy] = xs; } this.Slices = ys; this.Dots = (from d0 in this.Slices from d1 in d0 from d2 in d1 select d2).ToArray(); this.OutterDots = (from d0 in this.Slices select(from d1 in d0.First() select d1).ToArray()).ToArray(); this.HorizontalOutterPolygonLineList = (from aDots in this.OutterDots select aDots.DotsToPolygonLineList()).Flatten().ToArray(); { var ds = this.OutterDots; this.TriangleStrips = ( from i1 in Enumerable.Range(0, ds.Length - 1) from i2 in Enumerable.Range(0, ds[i1].Length - 1) select new CVector3Dbl[] { ds[i1 + 1][i2], ds[i1][i2], ds[i1][i2 + 1] } ) .Concat( from i1 in Enumerable.Range(0, ds.Length - 1).Reverse() from i2 in Enumerable.Range(0, ds[i1].Length - 1).Reverse() select new CVector3Dbl[] { ds[i1][i2 + 1], ds[i1 + 1][i2 + 1], ds[i1 + 1][i2] } ) .Flatten().ToArray(); } }
public CCircle(double r, int aSegmentCount) { var aDots = new CVector3Dbl[aSegmentCount]; var aSegmentAngle = Math.PI * 2d / aSegmentCount; for (var i = 0; i < aSegmentCount; ++i) { var rad = aSegmentAngle * i; var x = Math.Cos(rad); var y = 0; var z = Math.Sin(rad); aDots[i] = new CVector3Dbl(x, y, z); } this.Dots = aDots; this.LineList = aDots.DotsToPolygonLineList().ToArray();; }
public COctaeder(double aW = 1.0d) { W = aW; P0 = new CVector3Dbl(Xc, Yb, Zc); P1 = new CVector3Dbl(Xl, Yc, Zf); P2 = new CVector3Dbl(Xr, Yc, Zf); P3 = new CVector3Dbl(Xr, Yc, Zb); P4 = new CVector3Dbl(Xl, Yc, Zb); P5 = new CVector3Dbl(Xc, Yt, Zc); Ps = new CVector3Dbl[] { P0, P1, P2, P3, P4, P5 }; P0C = CColors.C_Red; P1C = CColors.C_Blue; P2C = CColors.C_Yellow; P3C = CColors.C_Blue; P4C = CColors.C_Yellow; P5C = CColors.C_Green; Colors = new CColor[] { P0C, P1C, P2C, P3C, P4C, P5C }; Tis = new int[] { 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 1, 1, 5, 2, 2, 5, 3, 3, 5, 4, 4, 5, 1 }; var aLineListIndexes = new int[] { 0, 1, 0, 2, 0, 3, 0, 4, 1, 2, 2, 3, 3, 4, 4, 1, 5, 1, 5, 2, 5, 3, 5, 4 }; this.LineList = (from aIdx in aLineListIndexes select Ps[aIdx]).ToArray(); this.ColoredTriangleList = (from aIdx in Enumerable.Range(0, TCount * 3) select Ps[Tis[aIdx]].ToColoredVertex(this.Colors[Tis[aIdx]])).ToArray(); this.ColoredLineList = this.ColoredTriangleList.TriangleListToLineList().ToArray(); }
private CVector3Dbl[] CalcBelt(int cnt, int c, int sx, double xsf, double y, double r) { var xf1 = ((double)sx + c) / ((double)cnt - 1); var xf2 = Math.Sin(Math.PI * xf1); var xf = r * ((double)sx * 2) / (double)(c * 2) * xsf; //var xf = r * xf1 * xf2; var rs = new CVector3Dbl[cnt]; for (var sr = 0; sr < cnt; ++sr) { var fkt = ((double)sr) / (double)(cnt - 1); var x = xf * Math.Sin(Math.PI * 2.0d * (fkt + 0.25d)); var z = xf * Math.Sin(Math.PI * 2.0d * fkt); var p = new CVector3Dbl(x, y, z); rs[sr] = p; } return(rs); }
internal static CVector3Dbl Subtract(this CVector3Dbl aLhs, CVector3Dbl aRhs) => aLhs - aRhs;
internal static CVector3Dbl Normalize(this CVector3Dbl v) { var len = Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z); return(new CVector3Dbl(v.x / len, v.y / len, v.z / len)); }
internal static CVector3Dbl Multiply(this CVector3Dbl aLhs, CVector3Dbl aRhs) => aLhs * aRhs;
internal static CVector3Dbl Divide(this CVector3Dbl aLhs, CVector3Dbl aRhs) => aLhs / aRhs;
internal static CVector3Dbl Subtract(this CVector3Dbl lhs, CVector3Dbl rhs) => lhs - rhs;
internal static CVector3Dbl Add(this CVector3Dbl aLhs, CVector3Dbl aRhs) => aLhs + aRhs;
internal static CVector3Dbl Max(this CVector3Dbl lhs, CVector3Dbl rhs) => new CVector3Dbl(Math.Max(lhs.x, rhs.x), Math.Max(lhs.y, rhs.y), Math.Max(lhs.z, rhs.z));
public static Vector3 ToVector3(this CVector3Dbl aVector) => new Vector3((float)aVector.x, (float)aVector.y, (float)aVector.z);
public static double GetLength(this CVector3Dbl aPoint) // Not tested, https://www.engineeringtoolbox.com/distance-relationship-between-two-points-d_1854.html => Math.Sqrt((aPoint.x * aPoint.x) + (aPoint.y * aPoint.y) + (aPoint.z * aPoint.z));
internal static CVector3Dbl Divide(this CVector3Dbl lhs, CVector3Dbl rhs) => lhs / rhs;
internal static CVector3Dbl MakeLongerDelta(this CVector3Dbl aVector, double aLength) // Not tested, https://www.freemathhelp.com/forum/threads/extend-length-of-line-in-3d-space-find-new-end-point.125160/ => (new CVector3Dbl(aLength) / new CVector3Dbl(aVector.GetLength())) * aVector;
public static Color ToColor(this CVector3Dbl v) => new Color(v.ToVector3());
public static CVector3Dbl Invert(this CVector3Dbl v) => new CVector3Dbl(-v.x, -v.y, -v.z);
internal static CVector3Dbl Abs(this CVector3Dbl v) => new CVector3Dbl(Math.Abs(v.x), Math.Abs(v.y), Math.Abs(v.z));
public CAvatarInfo(CVector3Dbl aWorldPos, CVector3Dbl aAimAt, double aSpeed) { this.WorldPos = aWorldPos; this.AimAt = aAimAt; this.Speed = aSpeed; }
internal static CVector3Dbl Sign(this CVector3Dbl v) => new CVector3Dbl(Math.Sign(v.x), Math.Sign(v.y), Math.Sign(v.z));
internal static double DotProduct(this CVector3Dbl lhs, CVector3Dbl rhs) => lhs.x * rhs.x + lhs.y * rhs.y + lhs.z + rhs.z;
internal CVector3Dbl NextDouble(CVector3Dbl aMultiplier) => this.NextWorldPos().Multiply(aMultiplier);
internal static double GetDistance(this CVector3Dbl v1, CVector3Dbl v2) => v1.Max(v2).Subtract(v1.Min(v2)).GetLength();