Пример #1
0
        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;
        }
Пример #2
0
        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();
        }
Пример #3
0
 public static Vector3 Round(this Vector3 v)
 {
     return(new Vector3((float)FezMath.Round((double)v.X), (float)FezMath.Round((double)v.Y), (float)FezMath.Round((double)v.Z)));
 }
Пример #4
0
 public static Vector2 Round(this Vector2 v)
 {
     return(new Vector2((float)FezMath.Round((double)v.X), (float)FezMath.Round((double)v.Y)));
 }
Пример #5
0
 public static float SnapPhi(float phi)
 {
     return((float)FezMath.Round(0.636619754652023 * (double)phi) / 0.6366197f);
 }