예제 #1
0
        /// <summary>
        /// Korvaa värin toisella värillä.
        /// </summary>
        /// <param name="src">Korvattava väri.</param>
        /// <param name="dest">Väri jolla korvataan.</param>
        /// <param name="tolerance">Kuinka paljon korvattava väri voi poiketa annetusta.</param>
        /// <param name="blend">Sävytetäänkö korvattavaa väriä sen mukaan kuinka kaukana se on alkuperäisestä väristä</param>
        /// <param name="exactAlpha">Vaaditaanko täsmälleen sama läpinäkyvyys ennen kuin korvataan</param>
        public void ReplaceColor(Color src, Color dest, double tolerance, bool blend, bool exactAlpha = false)
        {
            XnaColor          srcColor  = src.AsXnaColor();
            XnaColor          destColor = dest.AsXnaColor();
            XnaColorConverter op        = delegate(XnaColor c)
            {
                if (exactAlpha && c.A != srcColor.A)
                {
                    return(c);
                }

                if (JyColor.Distance(c, srcColor) <= tolerance)
                {
                    if (!blend)
                    {
                        return(destColor);
                    }
                    Vector3 srcDist = new Vector3(c.R - srcColor.R, c.G - srcColor.G, c.B - srcColor.B);
                    return(new XnaColor(destColor.ToVector3() + srcDist));
                }

                return(c);
            };

            ApplyPixelOperation(op);
        }
예제 #2
0
        public void Draw(GraphicsDevice device, BoundingBox boundingBox, Camera camera, Color color)
        {
            if (declaration == null)
            {
                declaration = VertexPositionColor.VertexDeclaration;
            }

            if (effect == null)
            {
                effect = new BasicEffect(device);
            }
            effect.DiffuseColor = color.ToVector3();

            effect.View = camera.EyeTransform;
            effect.Projection = camera.ProjectionTransform;
            Vector3 size = boundingBox.Max - boundingBox.Min;
            effect.World = Matrix.CreateScale(size)*Matrix.CreateTranslation(boundingBox.Max - size*0.5f);
            
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawUserIndexedPrimitives<VertexPositionColor>(
                                    PrimitiveType.LineList, points,
                                    0,
                                    8,
                                    index,
                                    0,
                                    12);
            }
        }
예제 #3
0
        /// <summary>
        /// 指定された単色ビットマップ画像をDXT3テクスチャへ変換する
        /// </summary>
        /// <param name="source">変換元画像</param>
        /// <param name="color0">単色カラー</param>
        /// <returns>DXT3圧縮された画像</returns>
        public static Dxt3BitmapContent Compress(PixelBitmapContent<Color> source,
                                                    Color color0)
        {
            // DXT3ブロックデータを格納するためのバッファを確保
            byte[] outputData = new byte[source.Width * source.Height];

            // 単色カラーをBGR565に変換する
            ushort packedColor = new Bgr565(color0.ToVector3()).PackedValue;

            // 指定された画像を圧縮ブロック単位に処理をする
            int outputIndex = 0;
            for (int blockY = 0; blockY < source.Height; blockY += 4)
            {
                for (int blockX = 0; blockX < source.Width; blockX += 4)
                {
                    CompressDxt3Block(source, blockX, blockY, packedColor,
                                        outputData, outputIndex);
                    outputIndex += 16;
                }
            }

            // DXT3テクスチャの生成と圧縮したブロックデータの設定
            var result = new Dxt3BitmapContent(source.Width, source.Height);
            result.SetPixelData(outputData);

            return result;
        }
예제 #4
0
        public static Color Shift(Color color, float hueShift)
        {
            Vector3 colorVector = color.ToVector3();
            Matrix hueShiftMatrix = HueShifter.CreateHueTransformationMatrix(hueShift);
            HueShifter.Shift(ref colorVector, ref hueShiftMatrix);

            return new Color(colorVector);
        }
예제 #5
0
 public void DrawCircle(Vector2 center, float radius, Color color)
 {
     _effect.World = Matrix.CreateScale(radius) * Matrix.CreateTranslation(center.X, center.Y, 0f);
     _effect.DiffuseColor = color.ToVector3();
     foreach (var pass in _effect.CurrentTechnique.Passes)
     {
         pass.Apply();
         _graphicsDevice.DrawPrimitives(PrimitiveType.LineStrip, _circleStart, _circleCount);
     }
 }
예제 #6
0
 public void DrawLine(Vector2 start, float lenght, float direction, Color color)
 {
     _effect.World = Matrix.CreateScale(lenght) * Matrix.CreateRotationZ(direction) * Matrix.CreateTranslation(start.X, start.Y, 0f);
     _effect.DiffuseColor = color.ToVector3();
     foreach (var pass in _effect.CurrentTechnique.Passes)
     {
         pass.Apply();
         _graphicsDevice.DrawPrimitives(PrimitiveType.LineStrip, _lineStart, _lineCount);
     }
 }
예제 #7
0
 public void DrawRectangle(Rectangle rectangle, Color color)
 {
     _effect.World = Matrix.CreateScale(rectangle.Width, rectangle.Height, 0f) * Matrix.CreateTranslation(rectangle.X, rectangle.Y, 0f);
     _effect.DiffuseColor = color.ToVector3();
     foreach (var pass in _effect.CurrentTechnique.Passes)
     {
         pass.Apply();
         _graphicsDevice.DrawPrimitives(PrimitiveType.LineStrip, _rectangleStart, _rectangleCount);
     }
 }
예제 #8
0
 public void SetVector(string name, XNA.Color color, bool useAlpha)
 {
     if (useAlpha)
     {
         SetVector(name, color.ToVector4());
     }
     else
     {
         SetVector(name, color.ToVector3());
     }
 }
        public static Texture2D Create(GraphicsDevice graphicsDevice, int width, int height, Color color)
        {
            Texture2D texture = new Texture2D(graphicsDevice, width, height, false, SurfaceFormat.Color);

            Color[] colors = new Color[width * height];
            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = new Color(color.ToVector3());
            }

            texture.SetData(colors);

            return texture;
        }
예제 #10
0
        private static Texture2D CreateSinglePixel(GraphicsDevice graphicsDevice, int width, int height, Color color)
        {
            // create the rectangle texture without colors
            var texture = new Texture2D(graphicsDevice, width, height, false, SurfaceFormat.Color);

            // Create a color array for the pixels
            var colors = new Color[width * height];
            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = new Color(color.ToVector3());
            }

            // Set the color data for the texture
            texture.SetData(colors);

            return texture;
        }
예제 #11
0
		// per frame simulation update
		public void Update(float currentTime, float elapsedTime)
		{
			// determine upper bound for pursuit prediction time
			float seekerToGoalDist = Vector3.Distance(Globals.HomeBaseCenter, Globals.Seeker.Position);
			float adjustedDistance = seekerToGoalDist - Radius - Plugin.BaseRadius;
			float seekerToGoalTime = ((adjustedDistance < 0) ? 0 : (adjustedDistance / Globals.Seeker.Speed));
			float maxPredictionTime = seekerToGoalTime * 0.9f;

			// determine steering (pursuit, obstacle avoidance, or braking)
			Vector3 steer = Vector3.Zero;
			if (Globals.Seeker.State == SeekerState.Running)
			{
				Vector3 avoidance = SteerToAvoidObstacles(Globals.AVOIDANCE_PREDICT_TIME_MIN, AllObstacles);

				// saved for annotation
				Avoiding = (avoidance == Vector3.Zero);

				steer = Avoiding ? SteerForPursuit(Globals.Seeker, maxPredictionTime) : avoidance;
			}
			else
			{
				ApplyBrakingForce(Globals.BRAKING_RATE, elapsedTime);
			}
			ApplySteeringForce(steer, elapsedTime);

			// annotation
			annotation.VelocityAcceleration(this);
			Trail.Record(currentTime, Position);

			// detect and record interceptions ("tags") of seeker
			float seekerToMeDist = Vector3.Distance(Position, Globals.Seeker.Position);
			float sumOfRadii = Radius + Globals.Seeker.Radius;
			if (seekerToMeDist < sumOfRadii)
			{
				if (Globals.Seeker.State == SeekerState.Running) Globals.Seeker.State = SeekerState.Tagged;

				// annotation:
				if (Globals.Seeker.State == SeekerState.Tagged)
				{
					Color color = new Color((byte)(255.0f * 0.8f), (byte)(255.0f * 0.5f), (byte)(255.0f * 0.5f));
					annotation.DiskXZ(sumOfRadii, (Position + Globals.Seeker.Position) / 2, color.ToVector3().FromXna(), 20);
				}
			}
		}
예제 #12
0
        // Draws the triangle mesh.
        public void Draw(GraphicsDevice graphicsDevice, BasicEffect effect, Pose pose, Color color)
        {
            if (_vertexBuffer == null)
            return;

              // Select the vertex buffer.
              graphicsDevice.SetVertexBuffer(_vertexBuffer);

              // The parameter 'pose' defines the world matrix and can be implicitly converted to
              // a XNA Matrix.
              effect.World = pose;
              effect.DiffuseColor = color.ToVector3();

              // Draw the vertex buffer.
              foreach (EffectPass pass in effect.CurrentTechnique.Passes)
              {
            pass.Apply();
            graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, _numberOfTriangles);
              }
        }
예제 #13
0
        public void Draw(Matrix world, Matrix view, Matrix projection, Color color)
        {
            basicEffect.World = world;
            basicEffect.View = view;
            basicEffect.Projection = projection;
            basicEffect.DiffuseColor = color.ToVector3();

            GraphicsDevice graphicsDevice = basicEffect.GraphicsDevice;
            graphicsDevice.SetVertexBuffer(vertexBuffer);
            graphicsDevice.Indices = indexBuffer;

            foreach (EffectPass effectPass in basicEffect.CurrentTechnique.Passes)
            {
                effectPass.Apply();

                int triangles = indexBuffer.IndexCount / 3;
                graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0,
                                                     vertexBuffer.VertexCount, 0, triangles);
            }
        }
예제 #14
0
        public void Draw(Matrix world, Matrix view, Matrix projection, Color color, Texture2D texture)
        {
            basicEffect.World = world;
            basicEffect.View = view;
            basicEffect.Projection = projection;
            basicEffect.DiffuseColor = color.ToVector3();
            basicEffect.Texture = texture;
            basicEffect.TextureEnabled = true;

            GraphicsDevice graphicsDevice = basicEffect.GraphicsDevice;
            graphicsDevice.SetVertexBuffer(vertexBuffer);
            graphicsDevice.Indices = indexBuffer;

            // BugFix::
            // Windows Phone 7 的XNA中默认的纹理寻址模式使用了Wrap,造成了与GPU的不兼容,
            // 如果改成Clamp就好了。
            graphicsDevice.SamplerStates[0] = SamplerState.PointClamp;

            foreach (EffectPass effectPass in basicEffect.CurrentTechnique.Passes)
            {
                effectPass.Apply();

                int triangles = indexBuffer.IndexCount / 3;
                graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0,
                                                     vertexBuffer.VertexCount, 0, triangles);
            }
        }
 public static void ToVector3(this DrawingColor color, out Vector3 result)
 {
     var xnaColor = new XnaColor(color.R, color.G, color.B);
     result = xnaColor.ToVector3();
 }
예제 #16
0
        public void ToVector3Tests()
        {
            Color c = new Color(0xFF, 0xBF, 0x7F, 0x00);
            Vector3 v = c.ToVector3();

            Assert.IsTrue(TestHelper.ApproximatelyEquals(1.0f, v.X), "Unexpected value for X");
            Assert.IsTrue(TestHelper.ApproximatelyEquals(0.75f, v.Y), "Unexpected value for Y");
            Assert.IsTrue(TestHelper.ApproximatelyEquals(0.5f, v.Z), "Unexpected value for Z");
        }
예제 #17
0
 public static Color Mix(this Color a, Color b, float percent = 0.5f)
 {
     percent = MathHelper.Clamp (percent, 0f, 1f);
     return new Color (a.ToVector3 () * (1f - percent) + b.ToVector3 () * percent);
 }