public static Vector3 Slerp(Vector3 from, Vector3 to, float step) { if (FezMath.AlmostEqual(step, 0.0f)) { return(from); } if (FezMath.AlmostEqual(step, 1f)) { return(to); } float num1 = Vector3.Dot(from, to); if ((double)num1 == -1.0) { Vector3 vector3 = Vector3.Cross(Vector3.Normalize(to - from), Vector3.UnitY); if ((double)step < 0.5) { return(FezMath.Slerp(from, vector3, step * 2f)); } else { return(FezMath.Slerp(vector3, to, (float)(((double)step - 0.5) / 2.0))); } } else { double a = Math.Acos((double)MathHelper.Clamp(num1, -1f, 1f)); if (FezMath.AlmostEqual(a, 0.0)) { return(to); } double num2 = Math.Sin(a); return((float)(Math.Sin((1.0 - (double)step) * a) / num2) * from + (float)(Math.Sin((double)step * a) / num2) * to); } }
public void Update(GameTime gameTime) { if (this.Reached || this.Paused) { return; } this.totalElapsed += gameTime.ElapsedGameTime; int index1 = this.Points.Length - 1; if (this.totalElapsed >= this.duration) { this.TotalStep = 1f; this.Current = this.Points[index1]; this.totalElapsed = this.duration; this.Reached = true; this.Paused = true; } else { float num1 = SplineInterpolation <T> .EaseInType != EasingType.None ? (SplineInterpolation <T> .EaseOutType != EasingType.None ? (SplineInterpolation <T> .EaseInType != SplineInterpolation <T> .EaseOutType ? Easing.EaseInOut((double)this.totalElapsed.Ticks / (double)this.duration.Ticks, SplineInterpolation <T> .EaseInType, SplineInterpolation <T> .EaseOutType) : Easing.EaseInOut((double)this.totalElapsed.Ticks / (double)this.duration.Ticks, SplineInterpolation <T> .EaseInType)) : Easing.EaseIn((double)this.totalElapsed.Ticks / (double)this.duration.Ticks, SplineInterpolation <T> .EaseInType)) : Easing.EaseOut((double)this.totalElapsed.Ticks / (double)this.duration.Ticks, SplineInterpolation <T> .EaseOutType); int index2 = (int)MathHelper.Clamp((float)((double)index1 * (double)num1 - 1.0), 0.0f, (float)index1); int index3 = (int)MathHelper.Clamp((float)index1 * num1, 0.0f, (float)index1); int index4 = (int)MathHelper.Clamp((float)((double)index1 * (double)num1 + 1.0), 0.0f, (float)index1); int index5 = (int)MathHelper.Clamp((float)((double)index1 * (double)num1 + 2.0), 0.0f, (float)index1); double num2 = (double)index3 / (double)index1; double num3 = (double)index4 / (double)index1 - num2; float t = (float)FezMath.Saturate(((double)num1 - num2) / (num3 == 0.0 ? 1.0 : num3)); this.TotalStep = num1; this.Interpolate(this.Points[index2], this.Points[index3], this.Points[index4], this.Points[index5], t); } }
private void InitializeSurfaces() { this.surfaces.Clear(); foreach (FaceOrientation faceOrientation in Util.GetValues <FaceOrientation>()) { TrixelEmplacement firstTrixel = new TrixelEmplacement(FezMath.IsPositive(faceOrientation) ? FezMath.AsVector(faceOrientation) * (this.size * 16f - Vector3.One) : Vector3.Zero); TrixelSurface trixelSurface = new TrixelSurface(faceOrientation, firstTrixel); Vector3 mask1 = FezMath.GetMask(FezMath.AsAxis(FezMath.GetTangent(faceOrientation))); int num1 = (int)Vector3.Dot(this.size, mask1) * 16; Vector3 mask2 = FezMath.GetMask(FezMath.AsAxis(FezMath.GetBitangent(faceOrientation))); int num2 = (int)Vector3.Dot(this.size, mask2) * 16; trixelSurface.RectangularParts.Add(new RectangularTrixelSurfacePart() { Orientation = faceOrientation, TangentSize = num1, BitangentSize = num2, Start = firstTrixel }); for (int index1 = 0; index1 < num1; ++index1) { for (int index2 = 0; index2 < num2; ++index2) { trixelSurface.Trixels.Add(new TrixelEmplacement(firstTrixel + mask1 * (float)index1 + mask2 * (float)index2)); } } this.surfaces.Add(trixelSurface); } }
public void RecomputeTexCoords(bool widen) { for (int index = 0; index < this.artObject.Geometry.Vertices.Length; ++index) { this.artObject.Geometry.Vertices[index].TextureCoordinate = FezMath.ComputeTexCoord <VertexPositionNormalTextureInstance>(this.artObject.Geometry.Vertices[index], this.artObject.Size) * (!widen ? Vector2.One : new Vector2(1.333333f, 1f)); } }
public static Vector3 AlmostClamp(Vector3 v, float epsilon) { v.X = FezMath.AlmostClamp(v.X, epsilon); v.Y = FezMath.AlmostClamp(v.Y, epsilon); v.Z = FezMath.AlmostClamp(v.Z, epsilon); return(v); }
public static void SetupViewport(this GraphicsDevice device, bool forceLetterbox = false) { int backBufferWidth = device.PresentationParameters.BackBufferWidth; int backBufferHeight = device.PresentationParameters.BackBufferHeight; if (!forceLetterbox) { RenderTargetBinding[] renderTargets = device.GetRenderTargets(); if (renderTargets.Length > 0 && renderTargets[0].RenderTarget is Texture2D) { return; } } device.ScissorRectangle = new Rectangle(0, 0, backBufferWidth, backBufferHeight); double num1 = (double)backBufferWidth / (double)backBufferHeight; int num2 = Math.Max(backBufferWidth / 640 * 640, 1280); int num3 = FezMath.Round((double)num2 / 1.77777779102325); device.Viewport = new Viewport() { X = (backBufferWidth - num2) / 2, Y = (backBufferHeight - num3) / 2, Width = num2, Height = num3, MinDepth = 0.0f, MaxDepth = 1f }; SettingsManager.viewScale = (float)device.Viewport.Width / 1280f; }
private void Invalidate(ArtObjectMaterializer.InvalidationContext context) { using (IEnumerator <TrixelEmplacement> enumerator = context.Trixels.GetEnumerator()) { while (enumerator.MoveNext()) { TrixelEmplacement trixel = enumerator.Current; for (int index = 0; index < 6; ++index) { FaceOrientation face = (FaceOrientation)index; TrixelEmplacement traversed = trixel.GetTraversal(face); if (this.IsBorderTrixelFace(traversed)) { if (Enumerable.Any <TrixelSurface>((IEnumerable <TrixelSurface>) this.surfaces, (Func <TrixelSurface, bool>)(x => { if (x.Orientation == face) { return(x.AnyRectangleContains(trixel)); } else { return(false); } }))) { context.Removed.Add(new TrixelFace(trixel, face)); } if (context.TrixelsExist) { context.Added.Add(new TrixelFace(trixel, face)); } } else { FaceOrientation oppositeFace = FezMath.GetOpposite(face); if (Enumerable.Any <TrixelSurface>((IEnumerable <TrixelSurface>) this.surfaces, (Func <TrixelSurface, bool>)(x => { if (x.Orientation == oppositeFace) { return(x.AnyRectangleContains(traversed)); } else { return(false); } }))) { context.Removed.Add(new TrixelFace(traversed, oppositeFace)); } if (!context.TrixelsExist) { context.Added.Add(new TrixelFace(traversed, oppositeFace)); } } } } } }
public void RebuildGeometry() { int capacity = Enumerable.Sum <TrixelSurface>((IEnumerable <TrixelSurface>) this.surfaces, (Func <TrixelSurface, int>)(x => x.RectangularParts.Count)); VertexGroup <VertexPositionNormalTextureInstance> vertexGroup = new VertexGroup <VertexPositionNormalTextureInstance>(capacity * 4); Dictionary <RectangularTrixelSurfacePart, FaceMaterialization <VertexPositionNormalTextureInstance> > dictionary = new Dictionary <RectangularTrixelSurfacePart, FaceMaterialization <VertexPositionNormalTextureInstance> >(capacity); Vector3 vector3_1 = new Vector3(0.5f); foreach (RectangularTrixelSurfacePart key in Enumerable.SelectMany <TrixelSurface, RectangularTrixelSurfacePart>((IEnumerable <TrixelSurface>) this.surfaces, (Func <TrixelSurface, IEnumerable <RectangularTrixelSurfacePart> >)(x => (IEnumerable <RectangularTrixelSurfacePart>)x.RectangularParts))) { Vector3 normal = FezMath.AsVector(key.Orientation); Vector3 vector3_2 = FezMath.AsVector(FezMath.GetTangent(key.Orientation)) * (float)key.TangentSize / 16f; Vector3 vector3_3 = FezMath.AsVector(FezMath.GetBitangent(key.Orientation)) * (float)key.BitangentSize / 16f; Vector3 position = key.Start.Position / 16f + (key.Orientation >= FaceOrientation.Right ? 1f : 0.0f) * normal / 16f - vector3_1; if (!dictionary.ContainsKey(key)) { FaceMaterialization <VertexPositionNormalTextureInstance> faceMaterialization = new FaceMaterialization <VertexPositionNormalTextureInstance>() { V0 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(position, normal)), V1 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(position + vector3_2, normal)), V2 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(position + vector3_2 + vector3_3, normal)), V3 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(position + vector3_3, normal)) }; faceMaterialization.SetupIndices(key.Orientation); dictionary.Add(key, faceMaterialization); } } VertexPositionNormalTextureInstance[] normalTextureInstanceArray = new VertexPositionNormalTextureInstance[vertexGroup.Vertices.Count]; int index = 0; foreach (SharedVertex <VertexPositionNormalTextureInstance> sharedVertex in (IEnumerable <SharedVertex <VertexPositionNormalTextureInstance> >)vertexGroup.Vertices) { normalTextureInstanceArray[index] = sharedVertex.Vertex; normalTextureInstanceArray[index].TextureCoordinate = FezMath.ComputeTexCoord <VertexPositionNormalTextureInstance>(normalTextureInstanceArray[index]) * (this.EngineState == null || !this.EngineState.InEditor ? Vector2.One : new Vector2(1.333333f, 1f)); sharedVertex.Index = index++; } int[] numArray = new int[dictionary.Count * 6]; int num = 0; foreach (FaceMaterialization <VertexPositionNormalTextureInstance> faceMaterialization in dictionary.Values) { for (ushort relativeIndex = (ushort)0; (int)relativeIndex < 6; ++relativeIndex) { numArray[num++] = faceMaterialization.GetIndex(relativeIndex); } } if (this.geometry == null) { this.geometry = new ShaderInstancedIndexedPrimitives <VertexPositionNormalTextureInstance, Vector4>(PrimitiveType.TriangleList, 220); this.geometry.NeedsEffectCommit = true; if (this.group != null) { this.group.Geometry = (IIndexedPrimitiveCollection)this.geometry; } } this.geometry.Vertices = normalTextureInstanceArray; this.geometry.Indices = numArray; this.DetermineFlags(); }
public static bool In <T>(T value, T value1, T value2, T value3, T value4, T value5, T value6, T value7, T value8) where T : IEquatable <T> { if (!FezMath.In <T>(value, value1, value2, value3, value4, value5, value6, value7)) { return(value.Equals(value8)); } else { return(true); } }
public static bool In <T>(T value, T value1, T value2, T value3) where T : IEquatable <T> { if (!FezMath.In <T>(value, value1, value2)) { return(value.Equals(value3)); } else { return(true); } }
public static bool In <T>(T value, T value1, T value2, T value3, T value4, T value5, T value6, T value7, T value8, IEqualityComparer <T> comparer) { if (!FezMath.In <T>(value, value1, value2, value3, value4, value5, value6, value7, comparer)) { return(comparer.Equals(value, value8)); } else { return(true); } }
protected override void Interpolate(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t) { if (SplineInterpolation <Vector3> .LongScreenshot) { this.Current = FezMath.Slerp(p1, p2, t); } else { this.Current = Vector3.CatmullRom(p0, p1, p2, p3, t); } }
public static bool AlmostEqual(Vector3 a, Vector3 b, float epsilon) { if (FezMath.AlmostEqual(a.X, b.X, epsilon) && FezMath.AlmostEqual(a.Y, b.Y, epsilon)) { return(FezMath.AlmostEqual(a.Z, b.Z, epsilon)); } else { return(false); } }
public static bool AlmostEqual(Quaternion a, Quaternion b, float epsilon) { if (FezMath.AlmostEqual(a.X, b.X, epsilon) && FezMath.AlmostEqual(a.Y, b.Y, epsilon) && FezMath.AlmostEqual(a.Z, b.Z, epsilon)) { return(FezMath.AlmostEqual(a.W, b.W, epsilon)); } else { return(false); } }
public static bool AlmostWrapEqual(Vector2 a, Vector2 b, float epsilon) { if (FezMath.AlmostWrapEqual(a.X, b.X, epsilon)) { return(FezMath.AlmostWrapEqual(a.Y, b.Y, epsilon)); } else { return(false); } }
public static Vector3 MaxClampXZ(this Vector3 vector) { Vector3 vector3 = FezMath.Abs(vector); if ((double)vector3.X >= (double)vector3.Z) { return(new Vector3((float)Math.Sign(vector.X), 0.0f, 0.0f)); } else { return(new Vector3(0.0f, 0.0f, (float)Math.Sign(vector.Z))); } }
public static float CurveAngle(float from, float to, float step) { if (FezMath.AlmostEqual(step, 0.0f)) { return(from); } if (FezMath.AlmostEqual(from, to) || FezMath.AlmostEqual(step, 1f)) { return(to); } Vector2 vector2 = FezMath.Slerp(new Vector2((float)Math.Cos((double)from), (float)Math.Sin((double)from)), new Vector2((float)Math.Cos((double)to), (float)Math.Sin((double)to)), step); return((float)Math.Atan2((double)vector2.Y, (double)vector2.X)); }
public static float AlmostClamp(float x, float epsilon) { if (FezMath.AlmostEqual(x, 0.0f, epsilon)) { return(0.0f); } if (FezMath.AlmostEqual(x, 1f, epsilon)) { return(1f); } if (FezMath.AlmostEqual(x, -1f, epsilon)) { return(-1f); } else { return(x); } }
public static Vector2 Slerp(Vector2 from, Vector2 to, float step) { if (FezMath.AlmostEqual(step, 0.0f)) { return(from); } if (FezMath.AlmostEqual(step, 1f)) { return(to); } double a = Math.Acos((double)MathHelper.Clamp(Vector2.Dot(from, to), -1f, 1f)); if (FezMath.AlmostEqual(a, 0.0)) { return(to); } double num = Math.Sin(a); return((float)(Math.Sin((1.0 - (double)step) * a) / num) * from + (float)(Math.Sin((double)step * a) / num) * to); }
public static Vector2 ComputeTexCoord <T>(this T vertex, Vector3 trileSize) where T : ILitVertex, ITexturedVertex { FaceOrientation orientation = FezMath.OrientationFromDirection(vertex.Normal); Vector2 vector2; switch (orientation) { case FaceOrientation.Left: vector2 = new Vector2(0.375f, 0.0f); break; case FaceOrientation.Back: vector2 = new Vector2(0.375f, 0.0f); break; case FaceOrientation.Right: vector2 = new Vector2(0.25f, 0.0f); break; case FaceOrientation.Top: vector2 = new Vector2(0.5f, 0.0f); break; case FaceOrientation.Front: vector2 = Vector2.Zero; break; default: vector2 = new Vector2(0.625f, 0.0f); break; } Vector3 b = ((Vector3.One - FezMath.Abs(vertex.Normal)) * vertex.Position / trileSize * 2f + vertex.Normal) / 2f + new Vector3(0.5f); float num1 = FezMath.Dot(FezMath.RightVector(FezMath.AsViewpoint(orientation)), b); float num2 = FezMath.Dot(FezMath.UpVector(FezMath.AsViewpoint(orientation)), b); if (orientation != FaceOrientation.Top) { num2 = 1f - num2; } return(new Vector2(vector2.X + num1 / 8f, vector2.Y + num2)); }
public static FaceOrientation OrientationFromPhi(float phi) { phi = FezMath.WrapAngle(phi); if (FezMath.AlmostEqual(phi, 0.0f)) { return(FaceOrientation.Front); } if (FezMath.AlmostEqual(phi, 1.570796f)) { return(FaceOrientation.Right); } if (FezMath.AlmostEqual(phi, -3.141593f)) { return(FaceOrientation.Back); } if (FezMath.AlmostEqual(phi, -1.570796f)) { return(FaceOrientation.Left); } else { return(FezMath.OrientationFromPhi(FezMath.SnapPhi(phi))); } }
public MovingTrileInstanceComparer(Vector3 ordering) { this.ordering = FezMath.Sign(ordering); }
public void RebuildGeometry() { if (this.surfaces == null) { return; } if (this.Geometry == null) { this.Geometry = new ShaderInstancedIndexedPrimitives <VertexPositionNormalTextureInstance, Matrix>(PrimitiveType.TriangleList, 60); } int capacity = Enumerable.Sum <TrixelSurface>((IEnumerable <TrixelSurface>) this.surfaces, (Func <TrixelSurface, int>)(x => x.RectangularParts.Count)); Dictionary <RectangularTrixelSurfacePart, FaceMaterialization <VertexPositionNormalTextureInstance> > dictionary = new Dictionary <RectangularTrixelSurfacePart, FaceMaterialization <VertexPositionNormalTextureInstance> >(capacity * 4); VertexGroup <VertexPositionNormalTextureInstance> vertexGroup = new VertexGroup <VertexPositionNormalTextureInstance>(capacity); Vector3 vector3_1 = this.size / 2f; foreach (RectangularTrixelSurfacePart key in Enumerable.SelectMany <TrixelSurface, RectangularTrixelSurfacePart>((IEnumerable <TrixelSurface>) this.surfaces, (Func <TrixelSurface, IEnumerable <RectangularTrixelSurfacePart> >)(x => (IEnumerable <RectangularTrixelSurfacePart>)x.RectangularParts))) { if (!dictionary.ContainsKey(key)) { Vector3 normal = FezMath.AsVector(key.Orientation); Vector3 vector3_2 = FezMath.AsVector(FezMath.GetTangent(key.Orientation)) * (float)key.TangentSize / 16f; Vector3 vector3_3 = FezMath.AsVector(FezMath.GetBitangent(key.Orientation)) * (float)key.BitangentSize / 16f; Vector3 v = key.Start.Position / 16f + (FezMath.IsPositive(key.Orientation) ? 1f : 0.0f) * normal / 16f - vector3_1; FaceMaterialization <VertexPositionNormalTextureInstance> faceMaterialization = new FaceMaterialization <VertexPositionNormalTextureInstance>() { V0 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(FezMath.Round(v, 4), normal)), V1 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(FezMath.Round(v + vector3_2, 4), normal)), V2 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(FezMath.Round(v + vector3_2 + vector3_3, 4), normal)), V3 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(FezMath.Round(v + vector3_3, 4), normal)) }; faceMaterialization.SetupIndices(key.Orientation); dictionary.Add(key, faceMaterialization); } } VertexPositionNormalTextureInstance[] normalTextureInstanceArray = new VertexPositionNormalTextureInstance[vertexGroup.Vertices.Count]; int index = 0; foreach (SharedVertex <VertexPositionNormalTextureInstance> sharedVertex in (IEnumerable <SharedVertex <VertexPositionNormalTextureInstance> >)vertexGroup.Vertices) { normalTextureInstanceArray[index] = sharedVertex.Vertex; normalTextureInstanceArray[index].TextureCoordinate = FezMath.ComputeTexCoord <VertexPositionNormalTextureInstance>(normalTextureInstanceArray[index], this.size) * new Vector2(1.333333f, 1f); sharedVertex.Index = index++; } int[] numArray = new int[dictionary.Count * 6]; int num = 0; foreach (FaceMaterialization <VertexPositionNormalTextureInstance> faceMaterialization in dictionary.Values) { for (ushort relativeIndex = (ushort)0; (int)relativeIndex < 6; ++relativeIndex) { numArray[num++] = faceMaterialization.GetIndex(relativeIndex); } } this.Geometry.Vertices = normalTextureInstanceArray; this.Geometry.Indices = numArray; if (this.artObject == null) { return; } this.PostInitialize(); }
public static Vector3 AlmostClamp(Vector3 v) { return(FezMath.AlmostClamp(v, 1.0 / 1000.0)); }
public static float AlmostClamp(float x) { return(FezMath.AlmostClamp(x, 1.0 / 1000.0)); }
public static bool AlmostWrapEqual(float a, float b, float epsilon) { return(FezMath.AlmostEqual(Vector2.Dot(new Vector2((float)Math.Cos((double)a), (float)Math.Sin((double)a)), new Vector2((float)Math.Cos((double)b), (float)Math.Sin((double)b))), 1f, epsilon)); }
public static bool AlmostWrapEqual(float a, float b) { return(FezMath.AlmostWrapEqual(a, b, 1.0 / 1000.0)); }
public static bool AlmostWrapEqual(Vector2 a, Vector2 b) { return(FezMath.AlmostWrapEqual(a, b, 1.0 / 1000.0)); }
public static bool AlmostEqual(Vector3 a, Vector3 b) { return(FezMath.AlmostEqual(a, b, 1.0 / 1000.0)); }
public static bool AlmostEqual(Quaternion a, Quaternion b) { return(FezMath.AlmostEqual(a, b, 1.0 / 1000.0)); }