Invert() public static method

public static Invert ( Matrix matrix ) : Matrix
matrix Matrix
return Matrix
示例#1
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));
        }
示例#2
0
        bool intersectPixels(Vector2 worldpos)
        {
            Vector2 positionInB = Vector2.Transform(worldpos, Matrix.Invert(_transform));

            var xB = (int)Math.Round(positionInB.X);
            var yB = (int)Math.Round(positionInB.Y);

            if (_properties.FlipHorizontally)
            {
                xB = _texture.Width - xB;
            }

            if (_properties.FlipVertically)
            {
                yB = _texture.Height - yB;
            }

            // If the pixel lies within the bounds of B
            if (0 <= xB && xB < _texture.Width && 0 <= yB && yB < _texture.Height)
            {
                Color colorB = _colorDataForTexture[xB + yB * _texture.Width];
                if (colorB.A != 0)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#3
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);
        }
示例#4
0
        protected override void Update(GameTime gameTime)
        {
            currentMouseState = Mouse.GetState();
            curKeyboardState  = Keyboard.GetState();

            mousePosiiton = Vector2.Transform(currentMouseState.Position.ToVector2(),
                                              Matrix.Invert(camera.Transform));

            if (mapCreated)
            {
                UpdateMapLogic();
                Camera();
            }


            previousMouseState = currentMouseState;
            prevKeyboardState  = curKeyboardState;
        }
示例#5
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));
            }
        }
示例#6
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));
        }
示例#7
0
        public void Draw(TimeSpan elapsedTime)
        {
            // Reset the XNA viewport to our centered and resized viewport
            State.Device.Viewport = viewport;

            // Set the render target for rendering the AR scene
            scene.SceneRenderTarget = arViewRenderTarget;
            scene.BackgroundColor   = Color.Black;
            // Set the scene background size to be the size of the AR scene viewport
            scene.BackgroundBound = arViewRect;
            // Set the camera to be the AR camera
            scene.CameraNode = arCameraNode;
            // Associate the overlaid model with the ground marker for rendering it in AR scene
            scene.RootNode.RemoveChild(overlayRoot);
            groundMarkerNode.AddChild(overlayRoot);
            // Don't render the marker board and camera representation
            markerBoardGeom.Enabled = false;
            vrCameraRepNode.Enabled = false;
            // Show the video background
            scene.BackgroundTexture = videoTexture;
            // Render the AR scene
            scene.Draw(elapsedTime, false);

            // Set the render target for rendering the VR scene
            scene.SceneRenderTarget = vrViewRenderTarget;
            scene.BackgroundColor   = Color.CornflowerBlue;
            // Set the scene background size to be the size of the VR scene viewport
            scene.BackgroundBound = vrViewRect;
            // Set the camera to be the VR camera
            scene.CameraNode = vrCameraNode;
            // Remove the overlaid model from the ground marker for rendering it in VR scene
            groundMarkerNode.RemoveChild(overlayRoot);
            scene.RootNode.AddChild(overlayRoot);
            // Render the marker board and camera representation in VR scene
            markerBoardGeom.Enabled = true;
            vrCameraRepNode.Enabled = true;
            // Update the transformation of the camera representation in VR scene based on the
            // marker array transformation
            if (groundMarkerNode.MarkerFound)
            {
                vrCameraRepTransNode.WorldTransformation = Matrix.Invert(groundMarkerNode.WorldTransformation);
            }
            // Do not show the video background
            scene.BackgroundTexture = null;
            // Re-traverse the scene graph since we have modified it, and render the VR scene
            scene.RenderScene(false, true);

            // Adjust the viewport to be centered
            arViewRect.X += viewport.X;
            vrViewRect.X += viewport.X;

            // Set the render target back to the frame buffer
            State.Device.SetRenderTarget(null);
            State.Device.Clear(Color.Black);
            // Render the two textures rendered on the render targets
            State.SharedSpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);
            State.SharedSpriteBatch.Draw(arViewRenderTarget, arViewRect, Color.White);
            State.SharedSpriteBatch.Draw(vrViewRenderTarget, vrViewRect, Color.White);
            State.SharedSpriteBatch.End();

            // Reset the adjustments
            arViewRect.X -= viewport.X;
            vrViewRect.X -= viewport.X;
        }