CreateScale() public static méthode

public static CreateScale ( float scale ) : Matrix
scale float
Résultat Matrix
Exemple #1
0
        public Matrix GetScaleMatrix()
        {
            if (scaleMatrix.HasValue == false)
            {
                var screenSize = Client.ScreenManager.CurrentScreen.GetLayoutSize();

                var gameWorldSize = new Vector2(screenSize.Width, screenSize.Height);
                var vp            = graphicsDevice.Viewport;

                var scaleX = vp.Width / gameWorldSize.X;
                var scaleY = vp.Height / gameWorldSize.Y;
                scaleY = scaleX;

                var translateX = (vp.Width - (gameWorldSize.X * scaleX)) / 2f;
                var translateY = (vp.Height - (gameWorldSize.Y * scaleY)) / 2f;


                var camera = Matrix.CreateScale(scaleX, scaleY, 1)
                             * Matrix.CreateTranslation(translateX, translateY, 0);

                scaleMatrix = camera;
            }

            return(scaleMatrix.Value);
        }
        public void Update(GameTime gameTime)
        {
            var direction = XVector3.Transform(XVector3.UnitZ,
                                               Matrix.CreateRotationX(MathHelper.ToRadians(Game.Client.Pitch)) *
                                               Matrix.CreateRotationY(MathHelper.ToRadians(-(Game.Client.Yaw - 180) + 180)));

            var cast = VoxelCast.Cast(Game.Client.World,
                                      new TRay(Game.Camera.Position, new TVector3(direction.X, direction.Y, direction.Z)),
                                      Game.BlockRepository, TrueCraftGame.Reach, TrueCraftGame.Reach + 2);

            if (cast == null)
            {
                Game.HighlightedBlock = -Coordinates3D.One;
            }
            else
            {
                var provider = Game.BlockRepository.GetBlockProvider(Game.Client.World.GetBlockID(cast.Item1));
                if (provider.InteractiveBoundingBox != null)
                {
                    var box = provider.InteractiveBoundingBox.Value;

                    Game.HighlightedBlock     = cast.Item1;
                    Game.HighlightedBlockFace = cast.Item2;

                    DestructionEffect.World = HighlightEffect.World = Matrix.Identity
                                                                      * Matrix.CreateScale(new XVector3((float)box.Width, (float)box.Height, (float)box.Depth))
                                                                      * Matrix.CreateTranslation(new XVector3((float)box.Min.X, (float)box.Min.Y, (float)box.Min.Z))
                                                                      * Matrix.CreateTranslation(new XVector3(cast.Item1.X, cast.Item1.Y, cast.Item1.Z));
                }
            }
        }
Exemple #3
0
        public BasicEntity(ModelDefinition modelbb, MaterialEffect material, Vector3 position, double angleZ, double angleX, double angleY, Vector3 scale, MeshMaterialLibrary library = null, Entity physicsObject = null)
        {
            Id                  = IdGenerator.GetNewId();
            Name                = GetType().Name + " " + Id;
            WorldTransform      = new TransformMatrix(Matrix.Identity, Id);
            ModelDefinition     = modelbb;
            Model               = modelbb.Model;
            BoundingBox         = modelbb.BoundingBox;
            BoundingBoxOffset   = modelbb.BoundingBoxOffset;
            SignedDistanceField = modelbb.SDF;

            Material = material;
            Position = position;
            Scale    = scale;

            RotationMatrix = Matrix.CreateRotationX((float)angleX) * Matrix.CreateRotationY((float)angleY) *
                             Matrix.CreateRotationZ((float)angleZ);

            if (library != null)
            {
                RegisterInLibrary(library);
            }

            if (physicsObject != null)
            {
                RegisterPhysics(physicsObject);
            }

            WorldTransform.World        = Matrix.CreateScale(Scale) * RotationMatrix * Matrix.CreateTranslation(Position);
            WorldTransform.Scale        = Scale;
            WorldTransform.InverseWorld = Matrix.Invert(Matrix.CreateTranslation(BoundingBoxOffset * Scale) * RotationMatrix * Matrix.CreateTranslation(Position));
        }
Exemple #4
0
        public override void Draw(GraphicsDevice gd, TimeSpan time, Camera camera)
        {
            if (!IsVisible)
            {
                return;
            }

            ccwState = new RasterizerState
            {
                CullMode = CullMode.CullCounterClockwiseFace,
                FillMode = ShowWireframe ? FillMode.WireFrame : FillMode.Solid,
            };


            gd.Textures[0] = sunTexture;
            gd.Textures[1] = turbulence1Texture;
            gd.Textures[2] = turbulence2Texture;
            gd.Textures[3] = gradientTexture;

            gd.SamplerStates[1] = SamplerState.AnisotropicWrap;
            gd.SamplerStates[2] = SamplerState.AnisotropicWrap;
            gd.SamplerStates[3] = SamplerState.LinearClamp;


            //
            // Pass 1, Sun map
            //
            var transform = Transform;

            transform = Matrix.CreateScale((float)Scale) * transform;
            shaderConstants.WorldMatrix = transform;
            shaderConstants.WorldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(transform));
            shaderConstants.WorldViewProjectionMatrix   = transform * camera.ViewTransform * camera.ProjectionTransform;
            shaderConstants.ViewInverseMatrix           = Matrix.Invert(camera.ViewTransform);
            shaderConstants.TotalSeconds.X = (float)time.TotalSeconds;
            shaderConstants.LightPos       = new Vector4(LightPosition, 1);
            gd.SetVertexShaderConstantFloat4(0, ref shaderConstants);

            var showWireframe = new Vector4(ShowWireframe ? 1 : 0);

            gd.SetPixelShaderConstantFloat4(0, ref showWireframe);

            gd.SetVertexShader(sunVertexShader);
            gd.SetPixelShader(sunPixelShader);

            gd.DepthStencilState = depthState;
            gd.BlendState        = BlendState.Opaque;
            gd.RasterizerState   = ccwState;

            // Perform refraction mapping
            if (ReflectionTexture != null)
            {
                gd.Textures[0] = ReflectionTexture;
                gd.SetPixelShader(refractionPixelShader);
            }
            mesh.Draw(gd);
        }
Exemple #5
0
        protected override void WhenUpdatedByUi()
        {
            _transform =
                Matrix.CreateTranslation(new Vector3(-_properties.Origin.X, -_properties.Origin.Y, 0.0f)) *
                Matrix.CreateScale(Scale.X, Scale.Y, 1) *
                Matrix.CreateRotationZ(Rotation) *
                Matrix.CreateTranslation(new Vector3(_properties.Position, 0.0f));

            Vector2 leftTop = Vector2.Zero;

            var leftBottom  = new Vector2(0, _texture.Height);
            var rightTop    = new Vector2(_texture.Width, 0);
            var rightBottom = new Vector2(_texture.Width, _texture.Height);

            // Transform all four corners into work space
            Vector2.Transform(ref leftTop, ref _transform, out leftTop);
            Vector2.Transform(ref rightTop, ref _transform, out rightTop);
            Vector2.Transform(ref leftBottom, ref _transform, out leftBottom);
            Vector2.Transform(ref rightBottom, ref _transform, out rightBottom);

            _polygon[0] = leftTop;
            _polygon[1] = rightTop;
            _polygon[3] = leftBottom;
            _polygon[2] = rightBottom;

            // Find the minimum and maximum extents of the rectangle in world space
            Vector2 min = Vector2.Min(
                Vector2.Min(leftTop, rightTop),
                Vector2.Min(leftBottom, rightBottom));

            Vector2 max = Vector2.Max(
                Vector2.Max(leftTop, rightTop),
                Vector2.Max(leftBottom, rightBottom));

            // Return as a rectangle
            _boundingRectangle = new Rectangle(
                (int)min.X,
                (int)min.Y,
                (int)(max.X - min.X),
                (int)(max.Y - min.Y));
        }
Exemple #6
0
        public void ApplyTransformation()
        {
            if (_dynamicPhysicsObject == null)
            {
                //RotationMatrix = Matrix.CreateRotationX((float) AngleX)*Matrix.CreateRotationY((float) AngleY)*
                //                  Matrix.CreateRotationZ((float) AngleZ);
                Matrix scaleMatrix = Matrix.CreateScale(Scale);
                _worldOldMatrix = scaleMatrix * RotationMatrix * Matrix.CreateTranslation(Position);

                WorldTransform.Scale = Scale;
                WorldTransform.World = _worldOldMatrix;

                WorldTransform.InverseWorld = Matrix.Invert(Matrix.CreateTranslation(BoundingBoxOffset * Scale) * RotationMatrix * Matrix.CreateTranslation(Position));

                if (StaticPhysicsObject != null && !GameSettings.e_enableeditor)
                {
                    AffineTransform change = new AffineTransform(
                        new BEPUutilities.Vector3(Scale.X, Scale.Y, Scale.Z),
                        Quaternion.CreateFromRotationMatrix(MathConverter.Convert(RotationMatrix)),
                        MathConverter.Convert(Position));

                    if (!MathConverter.Equals(change.Matrix, StaticPhysicsObject.WorldTransform.Matrix))
                    {
                        //StaticPhysicsMatrix = MathConverter.Copy(Change.Matrix);

                        StaticPhysicsObject.WorldTransform = change;
                    }
                }
            }
            else
            {
                //Has something changed?
                WorldTransform.Scale = Scale;
                _worldOldMatrix      = Extensions.CopyFromBepuMatrix(_worldOldMatrix, _dynamicPhysicsObject.WorldTransform);
                Matrix scaleMatrix = Matrix.CreateScale(Scale);
                //WorldOldMatrix = Matrix.CreateScale(Scale)*WorldOldMatrix;
                WorldTransform.World = scaleMatrix * _worldOldMatrix;

                WorldTransform.InverseWorld = Matrix.Invert(Matrix.CreateTranslation(BoundingBoxOffset * Scale) * RotationMatrix * Matrix.CreateTranslation(Position));
            }
        }
Exemple #7
0
        public BasicEntity(ModelDefinition modelbb, MaterialEffect material, Vector3 position, Matrix rotationMatrix, Vector3 scale)
        {
            Id                  = IdGenerator.GetNewId();
            Name                = GetType().Name + " " + Id;
            WorldTransform      = new TransformMatrix(Matrix.Identity, Id);
            Model               = modelbb.Model;
            ModelDefinition     = modelbb;
            BoundingBox         = modelbb.BoundingBox;
            BoundingBoxOffset   = modelbb.BoundingBoxOffset;
            SignedDistanceField = modelbb.SDF;

            Material       = material;
            Position       = position;
            RotationMatrix = rotationMatrix;
            Scale          = scale;
            RotationMatrix = rotationMatrix;

            WorldTransform.World        = Matrix.CreateScale(Scale) * RotationMatrix * Matrix.CreateTranslation(Position);
            WorldTransform.Scale        = Scale;
            WorldTransform.InverseWorld = Matrix.Invert(Matrix.CreateTranslation(BoundingBoxOffset * Scale) * RotationMatrix * Matrix.CreateTranslation(Position));
        }
Exemple #8
0
        public void Draw()
        {
            GraphicsDevice device = SharedGraphicsDeviceManager.Current.GraphicsDevice;

            device.BlendState        = BlendState.Opaque;
            device.RasterizerState   = RasterizerState.CullCounterClockwise;
            device.DepthStencilState = DepthStencilState.Default;

            // Store the old viewport and set the desired viewport
            Viewport oldViewport = device.Viewport;

            device.Viewport = new Viewport(state.ViewportRect);

            // Calculate the world-view-projection matrices for the tank and camera
            Matrix world      = Matrix.CreateScale(.002f) * Matrix.CreateRotationY(MathHelper.ToRadians((float)state.TankRotationY));
            Matrix view       = Matrix.CreateLookAt(state.CameraPosition, state.CameraTarget, Vector3.Up);
            Matrix projection = Matrix.CreatePerspectiveFieldOfView(1, device.Viewport.AspectRatio, .01f, 100f);

            // Draw the sky
            sky.Draw(view, projection);

            // Draw the ground
            groundEffect.World      = Matrix.Identity;
            groundEffect.View       = view;
            groundEffect.Projection = projection;
            device.SetVertexBuffer(groundVertices);
            foreach (var pass in groundEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            }

            // Draw the tank
            tank.Draw(world, view, projection, state);

            // Reset the viewport
            device.Viewport = oldViewport;
        }
Exemple #9
0
 void updateview()
 {
     mat = MX.CreateTranslation(-pos.X, -pos.Y, 0) * MX.CreateScale(G.zoom) * MX.CreateTranslation(G.w / 2, G.h / 2, 0);
 }
        /// <summary>
        /// Renders any queued display lists
        /// </summary>
        /// <param name="graphicsDevice"></param>
        public void Render(GraphicsDevice graphicsDevice)
        {
            CheckPolysPerSecond();

            if (mERASE > 1)
            {
                graphicsDevice.SetRenderTarget(ScreenBuffer);
                graphicsDevice.Clear(Color.Transparent);
                mERASE = 0;
            }

            while (DisplayListManager.GetNext(out DisplayList? displayList) && displayList != null)
            {
                if (PauseOnNextRender)
                {
                    PauseOnNextRender = false;
                    Machine.Paused    = true;
                }

                graphicsDevice.SetRenderTarget(SceneBuffer);
                graphicsDevice.DepthStencilState = DepthStencilState.Default;
                graphicsDevice.Clear(Color.Transparent);

                basicEffect.Projection = projectionMatrix;
                basicEffect.View       = Matrix.CreateScale(1.0f / 128) * viewMatrix;
                basicEffect.World      = worldMatrix;

                if (Settings.Wireframe)
                {
                    RasterizerState prevRasterizerState = graphicsDevice.RasterizerState;
                    graphicsDevice.RasterizerState = new RasterizerState()
                    {
                        FillMode             = FillMode.WireFrame,
                        CullMode             = CullMode.CullClockwiseFace,
                        MultiSampleAntiAlias = true,
                    };
                }
                else
                {
                    graphicsDevice.RasterizerState = new RasterizerState()
                    {
                        CullMode             = CullMode.CullClockwiseFace,
                        MultiSampleAntiAlias = true,
                    };
                }

                if (displayList != null)
                {
                    foreach (DisplayList.Primitive primitive in displayList)
                    {
                        System.Diagnostics.Debug.Assert(primitive.NumPrimitives > 0);

                        graphicsDevice.SetVertexBuffer(primitive.VertexBuffer);

                        foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
                        {
                            pass.Apply();
                            graphicsDevice.DrawPrimitives(primitive.Type, 0, primitive.NumPrimitives);
                        }
                    }
                    mEXT_DONE = true;
                }

                // now copy our newly rendered scene ontop of the current screen buffer
                graphicsDevice.SetRenderTarget(ScreenBuffer);
                if (displayList.Erase)
                {
                    graphicsDevice.Clear(Color.Transparent);
                }
                ScreenManager.SpriteBatch.Begin();
                ScreenManager.SpriteBatch.Draw(SceneBuffer, Vector2.Zero, Color.White);
                ScreenManager.SpriteBatch.End();

                TotalDots     += displayList.NumDots;
                TotalVectors  += displayList.NumVectors;
                TotalPolygons += displayList.NumPolygons;
                DisplayListManager.Return(displayList);
            }

            CheckPolysPerSecond();
        }