예제 #1
0
        private void DrawOctaedres(CMonoBumperSprite aAsteroidSprite)
        {
            var aEffect      = aAsteroidSprite.BasicEffect;
            var aBasicMatrix = aEffect.World;

            foreach (var aSphereDot in this.SphereDots)
            {
                var aDotMatrix = aBasicMatrix * Matrix.CreateTranslation(aSphereDot.ToVector3());
                aEffect.World = aDotMatrix;
                foreach (var aEffectPass in aEffect.CurrentTechnique.Passes)
                {
                    aEffectPass.Apply();
                    this.OctaederLineListVertexBuffer.DrawLineList(this.Game.GraphicsDevice);
                }
            }
        }
예제 #2
0
        private void DrawOrbit(CMonoBumperSprite aAsteroidSprite)
        {
            var aBumperSprite = aAsteroidSprite.Sprite;

            if (aBumperSprite.OrbitIsDefined &&
                this.DrawOrbitsValue.Value)
            {
                var aGraphicsDevice = this.Game.GraphicsDevice;
                var aOrbit          = aBumperSprite.Orbit;

                var aOrbitRadians = aOrbit.Item1;
                var aOrbitCenter  = aOrbit.Item2;
                var aOrbitRadius  = aOrbit.Item3;

                var aScaleMatrix = Matrix.CreateScale((float)aOrbitRadius);

                var aRotateMatrix    = aOrbitRadians.ToVector3().ToRotateMatrixXyz();
                var aTranslateMatrix = aOrbitCenter.ToVector3().ToTranslateMatrix();

                var aBasicEffect    = this.Game.BasicEffect;
                var aOldWorldMatrix = aBasicEffect.World;

                var aWorldMatrix = aOldWorldMatrix * aScaleMatrix * aRotateMatrix * aTranslateMatrix;

                aBasicEffect.World = aWorldMatrix;

                var aVertexBuffer = this.CircleVertexBuffers.GetShapeByRadius(aOrbitRadius * 1000);



                var aOldAlpha = aBasicEffect.Alpha;
                var aAlpha    = aBumperSprite.GetAlpha(this.Game.Avatar.WorldPos); // TODO_OPT
                aBasicEffect.Alpha = (float)aAlpha;



                foreach (var aPass in aBasicEffect.CurrentTechnique.Passes)
                {
                    aPass.Apply();
                    aVertexBuffer.DrawLineList(aGraphicsDevice);
                }

                aBasicEffect.World = aOldWorldMatrix;
                aBasicEffect.Alpha = aOldAlpha;
            }
        }
예제 #3
0
 internal void Draw(CMonoBumperSprite aAsteroidSprite)
 {
     //this.DrawOctaedres(aAsteroidSprite);
     this.DrawSphere(aAsteroidSprite);
     this.DrawOrbit(aAsteroidSprite);
 }
예제 #4
0
        private void DrawSphere(CMonoBumperSprite aAsteroidSprite)
        {
            var aBumperSprite    = aAsteroidSprite.Sprite;
            var aAlpha           = aBumperSprite.GetAlpha(this.Game.Avatar.WorldPos);
            var aInvertedAlpha   = (float)(1d - aAlpha);
            var aBasicEffect     = aAsteroidSprite.BasicEffect;
            var aOldAlpha        = aBasicEffect.Alpha;
            var aOldWorldMatrix  = this.Game.WorldMatrix;
            var aScaleMatrix     = Matrix.CreateScale((float)aAsteroidSprite.Sprite.Radius);
            var aTranslateMatrix = Matrix.CreateTranslation(aBumperSprite.WorldPos.Value.ToVector3());
            var aWorldMatrix     = aOldWorldMatrix * aScaleMatrix * aTranslateMatrix;

            aBasicEffect.Alpha = (float)aAlpha;
            aBasicEffect.World = aWorldMatrix;
            //var aAvatarIsInTile = aBumperSprite.AvatarIsInQuadrant;
            var aAvatarDistanceToSurface  = aBumperSprite.AvatarDistanceToSurface;
            var aVertexBufferIndex        = this.MviAsteroidModel.GetSphereIdx(aAvatarDistanceToSurface);
            var aLineListVertexBuffer     = this.SphereLineListVertexBuffers[aVertexBufferIndex];     // this.GetSphereLineListVertexBuffer(aAvatarDistanceToSurface);
            var aTriangleListVertexBuffer = this.SphereTriangleListVertexBuffers[aVertexBufferIndex]; // this.GetSphereTriangleStripVertexBuffer(aAvatarDistanceToSurface);

            //var aIsNearest = aBumperSprite.IsNearest;
            //var aIsBelowSurface = aBumperSprite.IsBelowSurface;

            //if (((int)aBumperSprite.Color.x * 1000) == ((int)0.0577762010776327 * 1000))
            //{
            //    System.Diagnostics.Debug.Assert(true);
            //}
            var aFillColor          = aBumperSprite.Color.ToColor().SetAlpha(aInvertedAlpha);
            var aLineColor          = new Color(aFillColor.ToVector3() + new Vector3(0.1f));
            var aAsteroidColorWhite = Color.White.SetAlpha((float)aAlpha);

            var aGraphicsDevice = this.Game.GraphicsDevice;
            var aBlendState     = this.BlendState;

            var aOldBlendState = aGraphicsDevice.BlendState;

            aGraphicsDevice.BlendState  = aBlendState;
            aGraphicsDevice.BlendFactor = aFillColor;

            //aGraphicsDevice.BlendState = Microsoft.Xna.Framework.Graphics.BlendState.AlphaBlend;

            //if(aIsNearest)
            { // TriangleStrip
                var aOldRasterizerState = aGraphicsDevice.RasterizerState;
                aGraphicsDevice.RasterizerState = this.RasterizerState;
                foreach (var aPass in aBasicEffect.CurrentTechnique.Passes)
                {
                    aPass.Apply();
                    aTriangleListVertexBuffer.DrawTriangleList(aGraphicsDevice);
                }
                aGraphicsDevice.RasterizerState = aOldRasterizerState;
            }

            //if(aIsNearest
            //|| aIsBelowSurface)
            { // LineList
              // aBasicEffect.Alpha = 0.0f;
                aGraphicsDevice.BlendFactor = aLineColor.SetAlpha((float)aAlpha);
                foreach (var aPass in aBasicEffect.CurrentTechnique.Passes)
                {
                    aPass.Apply();
                    aLineListVertexBuffer.DrawLineList(aGraphicsDevice);
                }

                this.RotateBy90Degrees = Matrix.CreateRotationZ(MathHelper.ToRadians(90f));

                { // DrawLinesRotatedBy90Degrees
                    var aOldWorldMatrix2 = aBasicEffect.World;
                    var aNewWorldMatrix  = this.RotateBy90Degrees * aBasicEffect.World;
                    aBasicEffect.World = aNewWorldMatrix;
                    foreach (var aPass in aBasicEffect.CurrentTechnique.Passes)
                    {
                        aPass.Apply();
                        aLineListVertexBuffer.DrawLineList(aGraphicsDevice);
                    }
                    aBasicEffect.World = aOldWorldMatrix2;
                }
            }
            aBasicEffect.Alpha         = aOldAlpha;
            aBasicEffect.World         = aOldWorldMatrix;
            aGraphicsDevice.BlendState = aOldBlendState;
        }