コード例 #1
1
 // Reset
 public void Reset()
 {
     Offset = new Vector2();
     Scale = new Vector2( 1.0f );
     Rotation = new Vector3();
     TransformMatrix = Matrix.Identity;
 }
コード例 #2
1
ファイル: Boundary.cs プロジェクト: boddie/AsteroidDestroyer
        public override void Draw(GameTime gameTime)
        {
            Matrix worldMatrix = Matrix.Identity;
            switch (Resources.Instance.GameSize)
            {
                case Resources.LevelSize.SMALL:
                    worldMatrix = Matrix.Identity * Matrix.CreateScale(85);
                    break;
                case Resources.LevelSize.MEDIUM:
                    worldMatrix = Matrix.Identity * Matrix.CreateScale(100);
                    break;

                case Resources.LevelSize.LARGE:
                    worldMatrix = Matrix.Identity * Matrix.CreateScale(115);
                    break;
            }
            

            Matrix[] transforms = new Matrix[_model.Bones.Count];
            _model.CopyAbsoluteBoneTransformsTo(transforms);
            foreach (ModelMesh mesh in _model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.Projection = MathConverter.Convert(_manager.Camera.ProjectionMatrix);
                    effect.View = MathConverter.Convert(_manager.Camera.ViewMatrix);
                    effect.World = worldMatrix;
                }

                mesh.Draw();
            }

            base.Draw(gameTime);
        }
コード例 #3
0
        public Planet(string name, Vector3d position, IModule module, Effect testEffect, float radius, Color sea, Color land, Color mountains)
        {
            nodesBeingBuilt  = new Dictionary <Vector3, PatchMinMax>();
            neighbourTracker = new NeighbourTracker();
            this.Name        = name;
            planetId         = ++planetIdList;
            this.module      = module;
            this.testEffect  = testEffect;
            this.radius      = radius;

            Position = new HighPrecisionPosition();
            AddComponent(Position);

            Transform.SetHighPrecisionPosition(position);

            splitDistance = radius * 4;

            customProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                   SystemCore.GraphicsDevice.Viewport.AspectRatio, 1f, this.radius * 10);

            SeaColor      = sea;
            LandColor     = land;
            MountainColor = mountains;


            Initialise();
        }
コード例 #4
0
ファイル: ARView.xaml.cs プロジェクト: ogu83/RealSquare
        private void InitializeXNA()
        {
            _device = SharedGraphicsDeviceManager.Current.GraphicsDevice;

            // Set the sharing mode of the graphics device to turn on XNA rendering
            _device.SetSharingMode(true);

            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(_device);

            BackgroundRenderer = new UIElementRenderer(this, _device.Viewport.Width, _device.Viewport.Height);
            // Create a timer for this page
            _gameTimer = new GameTimer();
            _gameTimer.UpdateInterval = TimeSpan.FromTicks(333333);
            _gameTimer.Update        += new EventHandler <GameTimerEventArgs>(_gameTimer_Update);
            _gameTimer.Draw          += new EventHandler <GameTimerEventArgs>(_gameTimer_Draw);

            _cameraMatrix     = Matrix.CreateLookAt(Vector3.Zero, Vector3.Forward, Vector3.Up);
            _projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, (float)(this.LayoutRoot.ActualWidth / this.LayoutRoot.ActualHeight), 0.01f, 10000.0f);

            foreach (LocationsVM.Location l in myVM.SelectedNearbyLocations)
            {
                l.Object3dEffect                = new BasicEffect(_device);
                l.Object3dEffect.World          = l.WorldMatrix;
                l.Object3dEffect.View           = _cameraMatrix;
                l.Object3dEffect.Projection     = _projectionMatrix;
                l.Object3dEffect.TextureEnabled = true;
            }

            _gameTimer.Start();
        }
コード例 #5
0
ファイル: ARPanel.cs プロジェクト: TKonov/NasaChallenge
 private void UpdateViewMatrix(PageOrientation orientation)
 {
     if (orientation == LandscapeLeft)
     {
         view = Microsoft.Xna.Framework.Matrix.CreateLookAt(
             new Microsoft.Xna.Framework.Vector3(0, 0, 1),
             Microsoft.Xna.Framework.Vector3.Zero,
             Microsoft.Xna.Framework.Vector3.Right);
     }
     else if (orientation == LandscapeRight)
     {
         view = Microsoft.Xna.Framework.Matrix.CreateLookAt(
             new Microsoft.Xna.Framework.Vector3(0, 0, 1),
             Microsoft.Xna.Framework.Vector3.Zero,
             Microsoft.Xna.Framework.Vector3.Left);
     }
     else //if (orientation == PageOrientation.PortraitUp)
     {
         view = Microsoft.Xna.Framework.Matrix.CreateLookAt(
             new Microsoft.Xna.Framework.Vector3(0, 0, 1),
             Microsoft.Xna.Framework.Vector3.Zero,
             Microsoft.Xna.Framework.Vector3.Up);
     }
     //Camera projection relies on the view matrix - invalidate camera projection
     _cameraProjection = null;
     InvalidateArrange();
 }
コード例 #6
0
        public override void StartFrame(ref Microsoft.Xna.Framework.Matrix view, ref Microsoft.Xna.Framework.Matrix projection, Microsoft.Xna.Framework.BoundingFrustum frustrum)
        {
            rend = 0;
            MaterialSortedObjects.Clear();

            Vector3[] corners = new Vector3[8];
            frustrum.GetCorners(corners);
            List <I2DPhysicObject> objs = world.PhysicWorld.TestAABB(new Vector2(corners[0].X, corners[0].Y), new Vector2(corners[2].X, corners[2].Y));

            foreach (var item in objs)
            {
                I2DObject obj = item.Owner;
                if (!MaterialSortedObjects.ContainsKey(obj.Material.GetType()))
                {
                    MaterialSortedObjects[obj.Material.GetType()] = new List <I2DObject>();
                }

                MaterialSortedObjects[obj.Material.GetType()].Add(obj);
                rend++;
            }

            foreach (var obj  in ghosts)
            {
                if (!MaterialSortedObjects.ContainsKey(obj.Material.GetType()))
                {
                    MaterialSortedObjects[obj.Material.GetType()] = new List <I2DObject>();
                }
                MaterialSortedObjects[obj.Material.GetType()].Add(obj);
            }
            rend += ghosts.Count;
        }
コード例 #7
0
ファイル: TerrainRenderable.cs プロジェクト: thormme/Chimera
        protected override void Draw(Matrix worldTransform, Color overlayColor, float overlayColorWeight, bool tryCull)
        {
            BoundingBox[,] transformedBoundingBoxes = new BoundingBox[mBoundingBoxes.GetLength(0), mBoundingBoxes.GetLength(1)];
            for (int row = 0; row < mBoundingBoxes.GetLength(0); ++row)
            {
                for (int col = 0; col < mBoundingBoxes.GetLength(1); ++col)
                {
                    transformedBoundingBoxes[row, col] = new BoundingBox(Vector3.Transform(mBoundingBoxes[row, col].Min, worldTransform), Vector3.Transform(mBoundingBoxes[row, col].Max, worldTransform));
                }
            }

            TerrainRenderer.TerrainParameters parameters = new TerrainRenderer.TerrainParameters();
            parameters.BoundingBoxes = transformedBoundingBoxes;
            parameters.DrawCursor = DrawCursor;
            parameters.CursorPosition = CursorPosition;
            parameters.CursorInnerRadius = CursorInnerRadius;
            parameters.CursorOuterRadius = CursorOuterRadius;
            parameters.Name = Name;
            parameters.OverlayColor = overlayColor;
            parameters.OverlayWeight = overlayColorWeight;
            parameters.TextureMask = LayerMask;
            parameters.TryCull = tryCull;
            parameters.World = worldTransform;

            GraphicsManager.EnqueueRenderable(parameters, RendererType);
        }
コード例 #8
0
        /// <summary>
        /// Renders the bounding box for debugging purposes.
        /// </summary>
        /// <param name="box">The box to render.</param>
        /// <param name="graphicsDevice">The graphics device to use when rendering.</param>
        /// <param name="view">The current view matrix.</param>
        /// <param name="projection">The current projection matrix.</param>
        /// <param name="color">The color to use drawing the lines of the box.</param>
        public static void Render(
            BoundingBox box,
            GraphicsDevice graphicsDevice,
            Matrix view,
            Matrix projection,
            Color color)
        {
            if (box.Min == box.Max)
            {
                return;
            }

            if (effect == null)
            {
                effect = new BasicEffect(graphicsDevice)
                             {TextureEnabled = false, VertexColorEnabled = true, LightingEnabled = false};
            }

            Vector3[] corners = box.GetCorners();
            for (int i = 0; i < 8; i++)
            {
                verts[i].Position = corners[i];
                verts[i].Color = color;
            }

            effect.View = view;
            effect.Projection = projection;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, verts, 0, 8, indices, 0,
                                                         indices.Length/2);
            }
        }
コード例 #9
0
 /// <summary>
 /// Handy dandy game method for implementating screen shake
 /// </summary>
 /// <param name="Transform"></param>
 /// <returns></returns>
 public override Microsoft.Xna.Framework.Matrix ModifyTransformMatrix(Microsoft.Xna.Framework.Matrix Transform)
 {
     if (!Main.gameMenu)
     {
         if (!Main.gamePaused)
         {
             shakeTick++;
             if (shakeIntensity >= 0 && shakeTick >= 4)
             {
                 shakeIntensity--;
             }
             if (shakeIntensity > 10)
             {
                 shakeIntensity = 10;                     //cap it
             }
             if (shakeIntensity < 0)
             {
                 shakeIntensity = 0;
             }
             return(Transform
                    * Microsoft.Xna.Framework.Matrix.CreateTranslation(
                        Main.rand.Next((int)(shakeIntensity * -0.5f), (int)(shakeIntensity * 0.5f + 1)),
                        Main.rand.Next((int)(shakeIntensity * -0.5f), (int)(shakeIntensity * 0.5f + 1)),
                        0f));
         }
     }
     else
     {
         shakeIntensity = 0;
         shakeTick      = 0;
     }
     return(Transform);
 }
コード例 #10
0
        public static Matrix Convert(Microsoft.Xna.Framework.Matrix matrix)
        {
            Matrix toReturn;

            Convert(ref matrix, out toReturn);
            return(toReturn);
        }
コード例 #11
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(MXF.GameTime gameTime)
        {
            ICameraManagerService cameraManagerService = (ICameraManagerService)this.Services.GetService(typeof(ICameraManagerService));

            graphics.GraphicsDevice.Clear(MXF.Color.CornflowerBlue);

            // Copy any parent transforms.
            MXF.Matrix[] transforms = new MXF.Matrix[castle.Bones.Count];
            castle.CopyAbsoluteBoneTransformsTo(transforms);

            //// Draw the model. A model can have multiple meshes, so loop.
            foreach (XFG.ModelMesh mesh in castle.Meshes)
            {
                // This is where the mesh orientation is set, as well as our camera and projection.
                foreach (XFG.BasicEffect effect in mesh.Effects)
                {
                    effect.World      = MXF.Matrix.CreateRotationY(this.modelRotation) * MXF.Matrix.CreateTranslation(this.modelPosition);
                    effect.View       = cameraManagerService.Camera.View;
                    effect.Projection = cameraManagerService.Camera.Projection;
                    effect.EnableDefaultLighting();
                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }

            base.Draw(gameTime);
        }
コード例 #12
0
        public override void Render(XNA.Matrix ViewMatrix, XNA.Matrix ProjectionMatrix)
        {
            base.Render(ViewMatrix, ProjectionMatrix);
            Gl.DrawElements(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedInt, IntPtr.Zero);

            Gl.BindVertexArray(0);
        }
コード例 #13
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Draw(GameTime gameTime)
        {
            Game.GraphicsDevice.RenderState.DepthBufferWriteEnable = true;
            Game.GraphicsDevice.RenderState.DepthBufferEnable = true;
            Game.GraphicsDevice.RenderState.AlphaBlendEnable = false;
            Game.GraphicsDevice.RenderState.AlphaTestEnable = false;

            var transforms = new Matrix[_cube.Bones.Count];
            _cube.CopyAbsoluteBoneTransformsTo(transforms);

            const int cols = 10, rows = 10;

            for (int z = -rows/2; z < rows/2; z++)
                for (int x = -cols/2; x < cols/2; x++)
                {
                    foreach (ModelMesh mesh in _cube.Meshes)
                    {
                        foreach (BasicEffect effect in mesh.Effects)
                        {
                            effect.EnableDefaultLighting();
                            effect.View = _basicEffect.View;
                            effect.Projection = _basicEffect.Projection;
                            effect.World = transforms[mesh.ParentBone.Index]*
                                           Matrix.CreateScale(0.01f, 0.005f, 0.01f)*
                                           Matrix.CreateTranslation(x/1.0f, -0.5f, z/1.0f);
                        }
                        mesh.Draw();
                    }
                }

            base.Draw(gameTime);
        }
コード例 #14
0
        /// <summary>
        /// Gets an array of vertices and indices from the provided model.
        /// </summary>
        /// <param name="collisionModel">Model to use for the collision shape.</param>
        /// <param name="vertices">Compiled set of vertices from the model.</param>
        /// <param name="indices">Compiled set of indices from the model.</param>
        public static void GetVerticesAndIndicesFromModel(Model collisionModel, out Microsoft.Xna.Framework.Vector3[] vertices, out int[] indices)
        {
            var verticesList = new List <Microsoft.Xna.Framework.Vector3>();
            var indicesList  = new List <int>();
            var transforms   = new Microsoft.Xna.Framework.Matrix[collisionModel.Bones.Count];

            collisionModel.CopyAbsoluteBoneTransformsTo(transforms);

            Microsoft.Xna.Framework.Matrix transform;
            foreach (Microsoft.Xna.Framework.Graphics.ModelMesh mesh in collisionModel.Meshes)
            {
                if (mesh.ParentBone != null)
                {
                    transform = transforms[mesh.ParentBone.Index];
                }
                else
                {
                    transform = Microsoft.Xna.Framework.Matrix.Identity;
                }
                AddMesh(mesh, transform, verticesList, indicesList);
            }

            vertices = verticesList.ToArray();
            indices  = indicesList.ToArray();
        }
コード例 #15
0
ファイル: HighlightModule.cs プロジェクト: jdc20181/OpenCraft
        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));
                }
            }
        }
コード例 #16
0
 public RectangleProjection(RectangleF rectangle, Matrix transform)
 {
     Vertices[0] = Vector2.Transform(rectangle.TopLeft, transform);
     Vertices[1] = Vector2.Transform(rectangle.TopRight, transform);
     Vertices[2] = Vector2.Transform(rectangle.BottomLeft, transform);
     Vertices[3] = Vector2.Transform(rectangle.BottomRight, transform);
 }
コード例 #17
0
ファイル: Vector3Test.cs プロジェクト: Zodge/MonoGame
        public void Transform()
        {
            // STANDART OVERLOADS TEST

            var expectedResult1 = new Vector3(51, 58, 65);
            var expectedResult2 = new Vector3(33, -14, -1);

            var v1 = new Vector3(1, 2, 3);
            var m1 = new Matrix(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);

            var v2 = new Vector3(1, 2, 3);
            var q1 = new Quaternion(2, 3, 4, 5);

            Vector3 result1;
            Vector3 result2;

            Assert.That(expectedResult1, Is.EqualTo(Vector3.Transform(v1, m1)).Using(Vector3Comparer.Epsilon));
            Assert.That(expectedResult2, Is.EqualTo(Vector3.Transform(v2, q1)).Using(Vector3Comparer.Epsilon));

            // OUTPUT OVERLOADS TEST

            Vector3.Transform(ref v1, ref m1, out result1);
            Vector3.Transform(ref v2, ref q1, out result2);

            Assert.That(expectedResult1, Is.EqualTo(result1).Using(Vector3Comparer.Epsilon));
            Assert.That(expectedResult2, Is.EqualTo(result2).Using(Vector3Comparer.Epsilon));
        }
コード例 #18
0
        private void Transform(AstroObject astroObject, Matrix3D baseTransformation, FrameworkElement txt)
        {
            // Transform Model
            if (astroObject == null)
            {
                return;
            }
            var m = Matrix.Identity;

            m *= Matrix.CreateTranslation(0, 60, 0);
            m *= Matrix.CreateRotationX(Microsoft.Xna.Framework.MathHelper.ToRadians(90));
            m *= baseTransformation.ToXnaMatrix();
            astroObject.Transform = m;
            astroObject.IsVisible = true;

            // Transform FrameworkElement
            // Center at origin of the TextBlock
            var centerAtOrigin = Matrix3DFactory.CreateTranslation(-txt.ActualWidth * 0.5, -txt.ActualHeight * 0.5, 0);
            // Swap the y-axis
            var scale = Matrix3DFactory.CreateScale(1, -1, 1);
            // Move a bit away from the center
            var translation = Matrix3DFactory.CreateTranslation(0, 50, 0);
            // Calculate the complete transformation matrix based on the first detection result
            var world = centerAtOrigin * translation * scale * baseTransformation;

            // Calculate the final transformation matrix by using the camera projection matrix
            var vp = Matrix3DFactory.CreateViewportTransformation(Viewport.ActualWidth, Viewport.ActualHeight);
            var mp = Matrix3DFactory.CreateViewportProjection(world, Matrix3D.Identity, arDetector.Projection, vp);

            // Apply the final transformation matrix to the TextBox
            txt.Projection = new Matrix3DProjection {
                ProjectionMatrix = mp
            };
            txt.Visibility = Visibility.Visible;
        }
コード例 #19
0
ファイル: Sphere.cs プロジェクト: tgjones/osiris
        public static void DrawWireframe(PrimitiveDrawer primitiveDrawer,
			Vector3 cameraPosition, Matrix cameraView, Matrix cameraProjection,
			Vector3 center, float radius, Quaternion rotation, Color color)
        {
            // Draw three orthogonal discs.
            Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, center, Vector3.Normalize(Vector3.Transform(Vector3.Up, rotation)), radius, color, true);
            Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, center, Vector3.Normalize(Vector3.Transform(Vector3.Forward, rotation)), radius, color, true);
            Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, center, Vector3.Normalize(Vector3.Transform(Vector3.Left, rotation)), radius, color, true);

            // Draw disc aligned with camera. To do this, first calculate the largest visible cross section using
             			// the technique described here: http://www.quantimegroup.com/solutions/pages/Article/Article.html

            // Solve for dy.
            Vector3 cameraToCenter = center - cameraPosition;
            float distanceToCenter = cameraToCenter.Length();
            float radius2 = radius * radius;
            float dy = radius2 / distanceToCenter;
            float r = MathUtility.Sqrt(radius2 - (dy * dy));

            Vector3 directionToCenter = Vector3.Normalize(cameraToCenter);
            Vector3 newCenter = cameraPosition + directionToCenter * (distanceToCenter - dy);

            // Disc aligned with camera
            Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection,
                newCenter, directionToCenter, r, Color.White, false);
        }
コード例 #20
0
ファイル: Skybox.cs プロジェクト: PhoenixWright/Mystery
        private void DrawSkybox()
        {
            SamplerState ss = new SamplerState();
              ss.AddressU = TextureAddressMode.Clamp;
              ss.AddressV = TextureAddressMode.Clamp;

              Engine.Video.GraphicsDevice.SamplerStates[0] = ss;

              DepthStencilState dss = new DepthStencilState();
              dss.DepthBufferEnable = false;
              Engine.Video.GraphicsDevice.DepthStencilState = dss;

              Matrix[] skyboxTransforms = new Matrix[skyboxModel.Bones.Count];
              skyboxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms);

              int i = 0;
              foreach(ModelMesh mesh in skyboxModel.Meshes) {
            foreach(Effect currentEffect in mesh.Effects) {
              Matrix worldMatrix = skyboxTransforms[mesh.ParentBone.Index];
              currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"];
              currentEffect.Parameters["xWorld"].SetValue(worldMatrix);
              currentEffect.Parameters["xView"].SetValue(camera.ViewMatrix);
              currentEffect.Parameters["xProjection"].SetValue(camera.ProjectionMatrix);
              currentEffect.Parameters["xTexture"].SetValue(skyboxTextures[i++]);
            }

            mesh.Draw();
              }

              dss = new DepthStencilState();
              dss.DepthBufferEnable = true;
              Engine.Video.GraphicsDevice.DepthStencilState = dss;
        }
コード例 #21
0
        protected override void LoadContent()
        {
            base.LoadContent();

            _projectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                (float)Math.PI * 0.25f,
                (float)TargetSize.Width / TargetSize.Height,
                0.05f,
                1000f);

            var camera = new Camera(_projectionMatrix)
            {
                ViewPosition = new Vector3(-.0f, .0f, 1.2f)
            };
            var device = Graphics.GraphicsDevice;

            _sun = new Sun(StarType);
            _sun.Create(Graphics, Content, camera);

            _usePostProcessor = device.GraphicsDeviceCapabilities.DeviceType == DeviceType.Hardware &&
                                device.GraphicsDeviceCapabilities.MaxPixelShaderProfile >= ShaderProfile.PS_3_0;

            if (_usePostProcessor)
            {
                _postProcessor = new PostProcessor(device, Content);
            }
        }
コード例 #22
0
ファイル: AfterScore.cs プロジェクト: DizWARE/Mr-Gravity
        /*
         * Draw
         *
         * This function will draw the current menu
         *
         * SpriteBatch spriteBatch: The current sprite batch used to draw
         *
         * GraphicsDeviceManager graphics: The current graphics manager
         */
        public void Draw(SpriteBatch spriteBatch, GraphicsDeviceManager graphics, Matrix scale)
        {
            spriteBatch.Begin(SpriteSortMode.Immediate,
                BlendState.AlphaBlend,
                SamplerState.LinearClamp,
                DepthStencilState.None,
                RasterizerState.CullCounterClockwise,
                null,
                scale);

            var mSize = new float[2] { _mScreenRect.Width / (float)graphics.GraphicsDevice.Viewport.Width, _mScreenRect.Height / (float)graphics.GraphicsDevice.Viewport.Height };

            spriteBatch.Draw(_mTrans, graphics.GraphicsDevice.Viewport.Bounds, Color.White);

            spriteBatch.Draw(_mTitle, new Rectangle(_mScreenRect.Center.X - (int)(_mTitle.Width * mSize[0]) / 2, _mScreenRect.Top, (int)(_mTitle.Width * mSize[0]), (int)(_mTitle.Height * mSize[1])), Color.White);

            var currentLocation = new Vector2(_mScreenRect.Left, _mScreenRect.Top + (int)(_mTitle.Height * mSize[1]));
            var height = _mScreenRect.Height - (int)(_mTitle.Height * mSize[1]);
            height -= ((int)(_mItems[0].Height * mSize[1]) + (int)(_mItems[1].Height * mSize[1]) + (int)(_mItems[2].Height * mSize[1]));
            height /= 2;
            currentLocation.Y += height;
            for (var i = 0; i < NumOptions; i++)
            {
                spriteBatch.Draw(_mItems[i], new Rectangle(_mScreenRect.Center.X - ((int)(_mItems[i].Width * mSize[0]) / 2), (int)currentLocation.Y, (int)(_mItems[i].Width * mSize[0]), (int)(_mItems[i].Height * mSize[1])), Color.White);
                currentLocation.Y += (int)(_mItems[i].Height * mSize[1]);
            }

            spriteBatch.End();
        }
コード例 #23
0
ファイル: Entity.cs プロジェクト: kaisellgren/Osmium-Wars
        /// <summary>
        /// Draw the model.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // Copy any parent transforms.
            Matrix[] transforms = new Matrix[this.model.Bones.Count];

            ModelBone bone = this.model.Bones["AF_Helmet_Xmas_D.bmp"];
            //Matrix boneTransform = bone.Transform;
            bone.Transform *= Matrix.CreateRotationY(this.rotation / 30);

            this.model.CopyAbsoluteBoneTransformsTo(transforms);

            // Draw the model. A model can have multiple meshes, so loop.
            foreach (ModelMesh mesh in this.model.Meshes)
            {
                // This is where the mesh orientation is set, as well
                // as our camera and projection.
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.AmbientLightColor = new Vector3(255, 255, 255);
                    effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateScale(this.size, this.size, this.size) * Matrix.CreateRotationY(this.rotation + this.baseRotation) * Matrix.CreateTranslation(this.position);
                    effect.View = this.game.Camera.View;
                    effect.Projection = this.game.Camera.Projection;
                }

                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }

            base.Draw(gameTime);
        }
コード例 #24
0
ファイル: Camera.cs プロジェクト: ChadyG/MUGE-GLEED2D
 void updatematrix()
 {
     matrix = Matrix.CreateTranslation(-position.X, -position.Y, 0.0f) *
              Matrix.CreateRotationZ(rotation) *
              Matrix.CreateScale(scale) *
              Matrix.CreateTranslation(viewport.X / 2, viewport.Y / 2, 0.0f);
 }
コード例 #25
0
ファイル: BaseCamera.cs プロジェクト: koenbollen/canyon
 /// <summary>
 /// Simply set the matrices.
 /// </summary>
 /// <param name="view">The view.</param>
 /// <param name="projection">The bad.</param>
 public BaseCamera(Matrix view, Matrix projection)
 {
     this.View = view;
     this.Projection = projection;
     if (ProjectionChanged != null)
         ProjectionChanged(this);
 }
コード例 #26
0
ファイル: ObjectSkydome.cs プロジェクト: Andrusza/PiratesArr
        public void Draw(Scattaring fx)
        {
            Matrix[] modelTansforms = new Matrix[Fbx.Bones.Count];
            Fbx.CopyAbsoluteBoneTransformsTo(modelTansforms);

            foreach (ModelMesh mesh in Fbx.Meshes)
            {
                foreach (Effect currentEffect in mesh.Effects)
                {
                    Matrix world = modelTansforms[mesh.ParentBone.Index] * fx.WorldMatrix;
                    currentEffect.Parameters["WorldViewProj"].SetValue(world * fx.viewProjection);
                    currentEffect.Parameters["WorldInverseTranspose"].SetValue(fx.invertTransposeWorld);
                    currentEffect.Parameters["World"].SetValue(world);
                    currentEffect.Parameters["ViewInv"].SetValue(fx.invertView);

                    currentEffect.Parameters["LightDirection"].SetValue(fx.lightDirection);
                    currentEffect.Parameters["LightColor"].SetValue(fx.lightColor);
                    currentEffect.Parameters["LightColorAmbient"].SetValue(fx.lightColorAmbient);
                    currentEffect.Parameters["FogColor"].SetValue(fx.fogColor);
                    currentEffect.Parameters["fDensity"].SetValue(fx.fogDensity);
                    currentEffect.Parameters["SunLightness"].SetValue(fx.sunLightness);
                    currentEffect.Parameters["sunRadiusAttenuation"].SetValue(fx.sunRadiusAttenuation);
                    currentEffect.Parameters["largeSunLightness"].SetValue(fx.largeSunLightness);
                    currentEffect.Parameters["largeSunRadiusAttenuation"].SetValue(fx.largeSunRadiusAttenuation);
                    currentEffect.Parameters["dayToSunsetSharpness"].SetValue(fx.dayToSunsetSharpness);
                    currentEffect.Parameters["hazeTopAltitude"].SetValue(fx.hazeTopAltitude);
                }
                mesh.Draw();
            }
        }
コード例 #27
0
ファイル: TextureItemEditor.cs プロジェクト: SteveDunn/oglr
        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);
        }
コード例 #28
0
        void RenderResults(RenderMode renderMode, simengine.MatrixTransforms transforms, simengine.CameraEntity currentCamera)
        {
            _timeAttenuationHandle.SetValue(new xna.Vector4(100 * (float)Math.Cos(_appTime * (1.0f / SCAN_INTERVAL)), 0, 0, 1));

            // render impact points as a quad
            xna.Matrix inverseViewRotation = currentCamera.ViewMatrix;
            inverseViewRotation.M41 = inverseViewRotation.M42 = inverseViewRotation.M43 = 0;
            xna.Matrix.Invert(ref inverseViewRotation, out inverseViewRotation);
            xna.Matrix localTransform = xna.Matrix.CreateFromAxisAngle(new xna.Vector3(1, 0, 0), (float)-Math.PI / 2) * inverseViewRotation;

            simengine.SimulationEngine.GlobalInstance.Device.DepthStencilState = xnagrfx.DepthStencilState.DepthRead;
            for (int i = 0; i < _lastResults.ImpactPoints.Count; i++)
            {
                xna.Vector3 pos = new xna.Vector3(_lastResults.ImpactPoints[i].Position.X,
                                                  _lastResults.ImpactPoints[i].Position.Y,
                                                  _lastResults.ImpactPoints[i].Position.Z);

                xna.Vector3 resultDir = pos - Position;
                resultDir.Normalize();

                localTransform.Translation = pos - .02f * resultDir;
                transforms.World           = localTransform;

                base.Render(renderMode, transforms, Meshes[0]);
            }
            simengine.SimulationEngine.GlobalInstance.Device.DepthStencilState = xnagrfx.DepthStencilState.Default;
        }
コード例 #29
0
 public EnvironmentBatch(GraphicsDevice device, ContentManager content, Matrix projection)
 {
     _environmentEffect = content.Load<Effect>("AmbientEffect");
     _environmentEffect.Parameters["BaseTexture"].SetValue(content.Load<Texture2D>("Drydock Floor"));
     _environmentEffect.Parameters["Projection"].SetValue(projection);
     _environmentEffect.Parameters["World"].SetValue(Matrix.CreateScale(_environmentScale));
 }
コード例 #30
0
        /// <summary>
        /// Processes the particles.
        /// </summary>
        /// <param name="dt">Elapsed time in whole and fractional seconds.</param>
        /// <param name="particleArray">A pointer to an array of particles.</param>
        /// <param name="count">The number of particles which need to be processed.</param>
        protected internal override unsafe void Process(float dt, Particle* particleArray, int count)
        {
            // Create the transformation matrix...
            float h = ((this.HueShift * dt) * Calculator.Pi) / 180f;

            float u = Calculator.Cos(h);
            float w = Calculator.Sin(h);

            Matrix hueTransform = new Matrix(1f, 0f, 0f, 0f,
                                             0f,  u, -w, 0f,
                                             0f,  w,  u, 0f,
                                             0f, 0f, 0f, 1f);

            for (int i = 0; i < count; i++)
            {
                Particle* particle = (particleArray + i);

                Vector4 colour;

                // Convert the current colour of the particle to YIQ colour space...
                Vector4.Transform(ref particle->Colour, ref HueShiftModifier.YIQTransformMatrix, out colour);

                // Transform the colour in YIQ space...
                Vector4.Transform(ref colour, ref hueTransform, out colour);

                // Convert the colour back to RGB...
                Vector4.Transform(ref colour, ref HueShiftModifier.RGBTransformMatrix, out colour);

                // And apply back to the particle...
                particle->Colour.X = colour.X;
                particle->Colour.Y = colour.Y;
                particle->Colour.Z = colour.Z;
            }
        }
コード例 #31
0
ファイル: Camera3D.cs プロジェクト: PhoenixWright/Mystery
 public void ResetCamera()
 {
     Position = Vector3.Zero;
       Target = Vector3.Zero;
       ViewMatrix = Matrix.Identity;
       ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), Engine.Video.GraphicsDevice.Viewport.AspectRatio, 0.5f, 500f);
 }
コード例 #32
0
ファイル: BasicEntity.cs プロジェクト: zengqh/DeferredEngine
        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));
        }
コード例 #33
0
ファイル: ModelScene.cs プロジェクト: JohanGl/Outworld-XNA
        private void DrawModel(Model m)
        {
            Matrix[] transforms = new Matrix[m.Bones.Count];
            float aspectRatio = Context.Graphics.Device.Viewport.AspectRatio;
            m.CopyAbsoluteBoneTransformsTo(transforms);
            Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);
            Matrix view = Matrix.CreateLookAt(new Vector3(0.0f, 2.0f, 10f), Vector3.Zero, Vector3.Up);

            var state = new RasterizerState();
            state.CullMode = CullMode.None;
            Context.Graphics.Device.RasterizerState = state;

            foreach (ModelMesh mesh in m.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.DiffuseColor = new Vector3(1, 1, 1);

                    effect.View = view;
                    effect.Projection = projection;
                    effect.World = Matrix.Identity * transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(Position) * Matrix.CreateRotationY(MathHelper.ToRadians(angle));
                }

                mesh.Draw();
            }
        }
コード例 #34
0
ファイル: SkyBox.cs プロジェクト: BibleUs/Terrain-Engine
        public void Draw(Vector3 center, Matrix newView, short clip)
        {
            Game.device.DepthStencilState = DepthStencilState.None;
            Game.device.RasterizerState = RasterizerState.CullNone;
            Game.device.BlendState = BlendState.Opaque;

            Matrix[] skyboxTransforms = new Matrix[skyBoxModel.Bones.Count];
            skyBoxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms);
            int i = 0;
            foreach (ModelMesh mesh in skyBoxModel.Meshes)
            {
                foreach (Effect currentEffect in mesh.Effects)
                {
                    Matrix worldMatrix = /*Matrix.CreateRotationY(rotation+=0.0001f) **/ Matrix.CreateScale(500f) * skyboxTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(center);
                    currentEffect.CurrentTechnique = currentEffect.Techniques["Sky"];
                    currentEffect.Parameters["xWorld"].SetValue(skyboxTransforms[mesh.ParentBone.Index]*worldMatrix);
                    currentEffect.Parameters["xViewProjection"].SetValue(newView * Game.cam.infinite_proj);
                    currentEffect.Parameters["xTexture"].SetValue(skyBoxTextures[i++]);
                    currentEffect.Parameters["xCamPos"].SetValue(Game.cam.cameraPosition);
                    currentEffect.Parameters["xShEye"].SetValue(Game.cam.shEye);

                    currentEffect.Parameters["xGrayScale"].SetValue(Game.enviro.grayScale);
                    currentEffect.Parameters["xInvertedColors"].SetValue(Game.enviro.invertColors);
                    currentEffect.Parameters["xUnderWater"].SetValue(Game.enviro.underWater);

                    currentEffect.Parameters["xClipping"].SetValue(clip);
                    currentEffect.Parameters["xClipHeight"].SetValue(Game.enviro.waterLevel);
                }
                mesh.Draw();
            }
            Game.device.BlendState = BlendState.Opaque;
            Game.device.RasterizerState = RasterizerState.CullClockwise;
            Game.device.DepthStencilState = DepthStencilState.Default;
        }
コード例 #35
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);
        }
コード例 #36
0
 public void Draw(Matrix view, Matrix projection)
 {
     Effect.Projection = projection;
     Effect.View = view;
     Effect.CurrentTechnique.Passes[0].Apply();
     Device.DrawUserPrimitives(PrimitiveType.LineList, Vertices, 0, 3);
 }
コード例 #37
0
ファイル: Camera.cs プロジェクト: DynaStudios/LD24Jam
 public void Update(Matrix chasedObjectsWorld)
 {
     if (_target != null)
     {
         UpdateViewMatrix(chasedObjectsWorld);
     }
 }
コード例 #38
0
ファイル: MatrixHelper.cs プロジェクト: uhealin/asskicker
        public static Matrix ComputeMatrix(Vector2 size, Vector2 ptUL, Vector2 ptUR, 
                                                         Vector2 ptLL, Vector2 ptLR)
        {
            // Scale transform
            Matrix S = Matrix.CreateScale(1 / size.X, 1 / size.Y, 1);

            // Affine transform
            Matrix A = ComputeAffineTransform(ptUL, ptUR, ptLL);

            // Non-Affine transform
            Matrix B = new Matrix();
            float den = A.M11 * A.M22 - A.M12 * A.M21;
            float a = (A.M22 * ptLR.X - A.M21 * ptLR.Y +
                       A.M21 * A.M42 - A.M22 * A.M41) / den;

            float b = (A.M11 * ptLR.Y - A.M12 * ptLR.X +
                       A.M12 * A.M41 - A.M11 * A.M42) / den;

            B.M11 = a / (a + b - 1);
            B.M22 = b / (a + b - 1);
            B.M33 = 1;
            B.M14 = B.M11 - 1;
            B.M24 = B.M22 - 1;
            B.M44 = 1;

            // Product of three transforms
            return S * B * A;
        }
コード例 #39
0
ファイル: RebootPOSTEffect.cs プロジェクト: tanis2000/FEZ
 public RebootPOSTEffect()
   : base("RebootPOSTEffect")
 {
   this.texture = new SemanticMappedTexture(this.effect.Parameters, "BaseTexture");
   this.pseudoWorldMatrix = new SemanticMappedMatrix(this.effect.Parameters, "PseudoWorldMatrix");
   this.PseudoWorld = Matrix.Identity;
 }
コード例 #40
0
        public static void Draw(this BoundingFrustum frustum, GraphicsDevice graphicsDevice, Matrix view, Matrix projection, Color color)
        {
            if (effect == null)
            {
                effect = new BasicEffect(graphicsDevice);
                effect.VertexColorEnabled = true;
                effect.LightingEnabled = false;
            }

            Vector3[] corners = frustum.GetCorners();
            for (int i = 0; i < 8; i++)
            {
                verts[i].Position = corners[i];
                verts[i].Color = color;
            }

            effect.View = view;
            effect.Projection = projection;
            foreach (var t in effect.Techniques)
                foreach (var p in t.Passes)
                {
                    p.Apply();

                    graphicsDevice.DrawUserIndexedPrimitives(
                        PrimitiveType.LineList, verts, 0, 8,
                        indices, 0, indices.Length / 2);

                }
        }
コード例 #41
0
ファイル: ObjectMesh.cs プロジェクト: Andrusza/PiratesArr
 public void Update(Matrix modelMatrix)
 {
     for (int j = 0; j < 8; j++)
     {
         transformedCorners[j] = Vector3.Transform(corners[j], modelMatrix);
     }
 }
コード例 #42
0
ファイル: Skybox.cs プロジェクト: boddie/AsteroidDestroyer
        public override void Draw(GameTime gameTime)
        {
            Vector3 cameraPosition = MathConverter.Convert(_manager.Camera.Position);

            Matrix[] transforms = new Matrix[_model.Bones.Count];
            _model.CopyAbsoluteBoneTransformsTo(transforms);
            foreach (ModelMesh mesh in _model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    if (_texture != null)
                    {
                        effect.TextureEnabled = true;
                        effect.Texture = _texture;
                    }
                    effect.EnableDefaultLighting();
                    effect.Projection = MathConverter.Convert(_manager.Camera.ProjectionMatrix);
                    effect.View = MathConverter.Convert(_manager.Camera.ViewMatrix);
                    effect.World = Matrix.CreateScale(3000) * Matrix.CreateTranslation(cameraPosition.X, cameraPosition.Y, cameraPosition.Z);
                }

                mesh.Draw();
            }

            base.Draw(gameTime);
        }
コード例 #43
0
ファイル: Lamp.cs プロジェクト: steinbergerbernd/Shaders
 public Lamp(Game game, Matrix worldMatrix)
     : base(game)
 {
     Name = "Lamp";
     On = true;
     WorldMatrix = worldMatrix;
 }
コード例 #44
0
ファイル: EffectHelpers.cs プロジェクト: Zeludon/FEZ
 internal static EffectDirtyFlags SetWorldViewProjAndFog(EffectDirtyFlags dirtyFlags, ref Matrix world, ref Matrix view, ref Matrix projection, ref Matrix worldView, bool fogEnabled, float fogStart, float fogEnd, EffectParameter worldViewProjParam, EffectParameter fogVectorParam)
 {
   if ((dirtyFlags & EffectDirtyFlags.WorldViewProj) != ~EffectDirtyFlags.All)
   {
     Matrix.Multiply(ref world, ref view, out worldView);
     Matrix result;
     Matrix.Multiply(ref worldView, ref projection, out result);
     worldViewProjParam.SetValue(result);
     dirtyFlags &= ~EffectDirtyFlags.WorldViewProj;
   }
   if (fogEnabled)
   {
     if ((dirtyFlags & (EffectDirtyFlags.Fog | EffectDirtyFlags.FogEnable)) != ~EffectDirtyFlags.All)
     {
       EffectHelpers.SetFogVector(ref worldView, fogStart, fogEnd, fogVectorParam);
       dirtyFlags &= ~(EffectDirtyFlags.Fog | EffectDirtyFlags.FogEnable);
     }
   }
   else if ((dirtyFlags & EffectDirtyFlags.FogEnable) != ~EffectDirtyFlags.All)
   {
     fogVectorParam.SetValue(Vector4.Zero);
     dirtyFlags &= ~EffectDirtyFlags.FogEnable;
   }
   return dirtyFlags;
 }
コード例 #45
0
ファイル: Utilities.cs プロジェクト: Bakkes/Karo
        public static BoundingBox CreateBoundingBox(Model model, Matrix worldTransform)
        {
            Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue);

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    int vertexStride = meshPart.VertexBuffer.VertexDeclaration.VertexStride;
                    int vertexBufferSize = meshPart.NumVertices * vertexStride;

                    float[] vertexData = new float[vertexBufferSize / sizeof(float)];
                    meshPart.VertexBuffer.GetData<float>(vertexData);

                    for (int i = 0; i < vertexBufferSize / sizeof(float); i += vertexStride / sizeof(float))
                    {
                        Vector3 transformedPosition = Vector3.Transform(new Vector3(vertexData[i + 1], vertexData[i + 2], vertexData[i]), worldTransform);

                        min = Vector3.Min(min, transformedPosition);
                        max = Vector3.Max(max, transformedPosition);
                    }
                }
            }
            return new BoundingBox(min, max);
        }
コード例 #46
0
        /// <summary>
        /// Draws the display object.
        /// </summary>
        /// <param name="viewMatrix">Current view matrix.</param>
        /// <param name="projectionMatrix">Current projection matrix.</param>
        public override void Draw(Matrix viewMatrix, Matrix projectionMatrix)
        {
            //This is not a particularly fast method of drawing.
            //It's used very rarely in the demos.
            model.CopyAbsoluteBoneTransformsTo(transforms);
            for (int i = 0; i < Model.Meshes.Count; i++)
            {
                for (int j = 0; j < Model.Meshes[i].Effects.Count; j++)
                {
                    var effect = Model.Meshes[i].Effects[j] as BasicEffect;
                    if (effect != null)
                    {
                        effect.World = transforms[Model.Meshes[i].ParentBone.Index] * WorldTransform;
                        effect.View = viewMatrix;
                        effect.Projection = projectionMatrix;

                        if (Texture != null)
                        {
                            effect.TextureEnabled = true;
                            effect.Texture = Texture;
                        }
                        else
                            effect.TextureEnabled = false;
                    }
                }
                Model.Meshes[i].Draw();
            }
        }
コード例 #47
0
        public void RotateAboutAxis(Vector3D axis, double angleRad)
        {
            var v = new sVector3D((float)axis.X, (float)axis.Y, (float)axis.Z);

            m = m * sMatrix3D.CreateFromQuaternion(sQuaternion.CreateFromAxisAngle(v, (float)angleRad));
            //m.Rotate(new sQuaternion(new sVector3D(axis.X, axis.Y, axis.Z), angleRad.ToDeg()));
        }
コード例 #48
0
        public void Begin(Microsoft.Xna.Framework.Matrix transform)
        {
            var mt3x2 = new SharpDX.Matrix3x2(transform.M11, transform.M12,
                                              transform.M21, transform.M22,
                                              transform.M41, transform.M42);

            this.Begin(mt3x2);
        }
コード例 #49
0
ファイル: MMatrix.cs プロジェクト: SE346-H11-NT/Project
        private MMatrix(MMatrix mat)
        {
            m_matrix = new Matrix();
            m_matrix = mat.m_matrix;
            MMatrix instance = this;

            addMatrix(ref instance);
        }
コード例 #50
0
        /// <summary>
        /// Gets the value of the annotation as a matrix.
        /// </summary>
        /// <returns>
        /// The matrix value
        /// </returns>
        public Matrix GetValueMatrix()
        {
            XNA.Matrix xm = _annotation.GetValueMatrix();
            Matrix     m;

            XNAHelper.ConvertMatrix(ref xm, out m);
            return(m);
        }
コード例 #51
0
        /// <summary>
        /// Gets the value of the parameter as a matrix transpose.
        /// </summary>
        /// <returns>
        /// The matrix transpose value
        /// </returns>
        public Matrix GetValueMatrixTranspose()
        {
            XNA.Matrix xm = _param.GetValueMatrixTranspose();
            Matrix     m;

            XNAHelper.ConvertMatrix(ref xm, out m);
            return(m);
        }
コード例 #52
0
ファイル: MMatrix.cs プロジェクト: SE346-H11-NT/Project
        private MMatrix()
        {
            m_matrix = new Matrix();
            m_matrix = Matrix.Identity;
            MMatrix instance = this;

            addMatrix(ref instance);
        }
コード例 #53
0
ファイル: ARView.xaml.cs プロジェクト: ogu83/RealSquare
        private void _motion_CurrentValueChanged(object sender, SensorReadingEventArgs <MotionReading> e)
        {
            double motionDelta = 0.01;

            if (!_motion.IsDataValid)
            {
                return;
            }

            if (Math.Abs(e.SensorReading.Attitude.Yaw - _yaw) > motionDelta)
            {
                _yaw = e.SensorReading.Attitude.Yaw;
            }

            if (Math.Abs(e.SensorReading.Attitude.Roll - _roll) > motionDelta)
            {
                _roll = e.SensorReading.Attitude.Roll;
            }

            if (Math.Abs(e.SensorReading.Attitude.Pitch - _pitch) > motionDelta)
            {
                _pitch = e.SensorReading.Attitude.Pitch;
            }

            Dispatcher.BeginInvoke(delegate()
            {
                if (myVM.ClickedNearbyLocation != null)
                {
                    myVM.ClickedNearbyLocation.CalculateHeadingAngle(MathHelper.ToDegrees(_yaw));
                }
            });

            if (_onDragEndAnimation)
            {
                return;
            }

            if (_gestureState == GestureStateEnum.OnFreeDrag)
            {
                _cameraMatrixBehindDrag  = Matrix.CreateLookAt(new Vector3(0, 0, 0), new Vector3(0, 0, -1), Vector3.Up);
                _cameraMatrixBehindDrag *= Matrix.CreateRotationY(-_yaw);
                _cameraMatrixBehindDrag *= Matrix.CreateRotationZ(_roll);
                _cameraMatrixBehindDrag *= Matrix.CreateRotationX(-_pitch + MathHelper.PiOver2);
            }
            else
            {
                _cameraMatrix  = Matrix.CreateLookAt(new Vector3(0, 0, 0), new Vector3(0, 0, -1), Vector3.Up);
                _cameraMatrix *= Matrix.CreateRotationY(-_yaw);
                _cameraMatrix *= Matrix.CreateRotationZ(_roll);
                _cameraMatrix *= Matrix.CreateRotationX(-_pitch + MathHelper.PiOver2);

                //rotate radar
                Dispatcher.BeginInvoke(delegate()
                {
                    (radarCanvas.RenderTransform as System.Windows.Media.RotateTransform).Angle = MathHelper.ToDegrees((_yaw));
                });
            }
        }
コード例 #54
0
 void LoadRotationMatrix(UInt16 address)
 {
     System.Diagnostics.Debug.Assert(address < 0x8000);
     if (address == 0x787C)
     {
         address = 0x15;
     }
     WorldRotation = GetMatrix4At(address);
 }
コード例 #55
0
 public override void Render(XNA.Matrix ViewMatrix, XNA.Matrix ProjectionMatrix)
 {
     if (ShaderProgram != null)
     {
         ShaderProgram.Use();
         Gl.BindVertexArray(VAO);
         SetMVP(ViewMatrix, ProjectionMatrix);
     }
 }
コード例 #56
0
ファイル: Sun.cs プロジェクト: amoldeshpande/slartoolkit
        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);
        }
コード例 #57
0
        public void InitializeViewport()
        {
            // Initialize the viewport and matrixes for 3d projection.
            viewport = new Viewport(0, 0, (int)this.ActualWidth, (int)this.ActualHeight);
            float aspect = viewport.AspectRatio;

            projection = Matrix.CreatePerspectiveFieldOfView(1, aspect, 1, 12);
            view       = Matrix.CreateLookAt(new Vector3(0, 0, 1), Vector3.Zero, Vector3.Up);
        }
コード例 #58
0
 public Camera(Game g, Vector3 position, Vector3 target, Vector3 up)
     : base(g)
 {
     view       = Matrix.CreateLookAt(position, target, up);
     projection = Matrix.CreatePerspectiveFieldOfView(
         MathHelper.PiOver4,
         (float)g.Window.ClientBounds.Width / g.Window.ClientBounds.Height,
         1, 100);
 }
コード例 #59
0
        public static string ToString(Microsoft.Xna.Framework.Matrix m)
        {
            string s = "";

            s += m.M11.ToString("0.000000") + " " + m.M12.ToString("0.000000") + " " + m.M13.ToString("0.000000") + " " + m.M14.ToString("0.000000") + "\r\n";
            s += m.M12.ToString("0.000000") + " " + m.M22.ToString("0.000000") + " " + m.M23.ToString("0.000000") + " " + m.M24.ToString("0.000000") + "\r\n";
            s += m.M13.ToString("0.000000") + " " + m.M32.ToString("0.000000") + " " + m.M33.ToString("0.000000") + " " + m.M34.ToString("0.000000") + "\r\n";
            s += m.M14.ToString("0.000000") + " " + m.M42.ToString("0.000000") + " " + m.M43.ToString("0.000000") + " " + m.M44.ToString("0.000000") + "\r\n";
            return(s);
        }
コード例 #60
0
        private void EndDrag()
        {
            if (_targetImage.IsMouseCaptured)
            {
                _targetImage.ReleaseMouseCapture();
            }

            _isDragging  = false;
            _worldMatrix = Matrix.Identity;
        }