public SelectColorBox(TextBoxEnterEvent e, Color c)
     : base("", "", e, -1, Keys.Enter)
 {
     this.size = new Vector2(320, 256);
     Center();
     r = new ColorDial(this.position + new Vector2((SPACE / (BARS + 1)) * 1 + 0 * (this.size.X - SPACE) / BARS , 8), new Vector2((this.size.X - SPACE) / BARS, this.size.Y - 48), Color.Red, c.ToVector4().X);
     g = new ColorDial(this.position + new Vector2((SPACE / (BARS + 1)) * 2 + 1 * (this.size.X - SPACE) / BARS, 8), new Vector2((this.size.X - SPACE) / BARS, this.size.Y - 48), Color.Green, c.ToVector4().Y);
     b = new ColorDial(this.position + new Vector2((SPACE / (BARS + 1)) * 3 + 2 * (this.size.X - SPACE) / BARS, 8), new Vector2((this.size.X - SPACE) / BARS, this.size.Y - 48), Color.Blue, c.ToVector4().Z);
     a = new ColorDial(this.position + new Vector2((SPACE / (BARS + 1)) * 4 + 3 * (this.size.X - SPACE) / BARS, 8), new Vector2((this.size.X - SPACE) / BARS, this.size.Y - 48), Color.Gray, c.ToVector4().W);
 }
Example #2
0
		public Triangle( Vector3 p1, Vector3 p2, Vector3 p3, Color color ) {
			myColor = color.ToVector4();
			InitEffect();
			SetUpVertices( p1, p2, p3, color );
			SetUpIndices();
			Update();
		}
Example #3
0
 //public void BeginWire()
 //{
 //    graphics.RasterizerState = wire;
 //}
 void SetStates(Color color, Vector2 targetSize)
 {
     graphics.RasterizerState = wire;
     effectColor.SetValue(color.ToVector4());
     effectSize.SetValue(new Vector2(1f / targetSize.X, 1f / targetSize.Y));
     effect.CurrentTechnique.Passes[0].Apply();
 }
        public static Color MultiplyBlend(Color a, Color b)
        {
            Vector4 av = a.ToVector4();
            Vector4 bv = b.ToVector4();

            return new Color(av * bv);
        }
Example #5
0
 public BlockVertex(Vector3 position, HalfVector2 blockTextureCoordinate, HalfVector4 light, Color tint)
 {
     m_position = position;
     m_blockTextureCoordinate = blockTextureCoordinate;
     m_light = light;
     m_tint = new HalfVector4(tint.ToVector4());
 }
Example #6
0
        public static Color Multiply(Color color1, Color color2)
        {
            Vector4 v1 = color1.ToVector4();
            Vector4 v2 = color2.ToVector4();

            return new Color(v1.X * v2.X, v1.Y * v2.Y, v1.Z * v2.Z, v1.W * v2.W);
        }
        public void initialize( string name, Vector3 position, Vector3 direction, Color color, float scaleModifier = 1.0f, int nParticlesModifier = 0, float lifetimeModifier = 0.0f)
        {
            particles.Clear();
            data = ParticleManager.Instance.getBaseParticleSystemData(name);
            this.position = position;
            this.direction = direction;

            // modify the base data with the parameters
            if (nParticlesModifier != 0)
            {
                data.nParticles = nParticlesModifier;
            }
            if (lifetimeModifier != 0.0f)
            {
                data.systemLife = lifetimeModifier;
                data.particlesLife = lifetimeModifier;
            }

            data.size *= scaleModifier;
            data.sizeIni *= scaleModifier;
            data.sizeEnd *= scaleModifier;
            data.positionVarianceMin *= scaleModifier;
            data.positionVarianceMax *= scaleModifier;
            data.directionVarianceMin *= scaleModifier;
            data.directionVarianceMax *= scaleModifier;
            data.accelerationVarianceMin *= scaleModifier;
            data.accelerationVarianceMax *= scaleModifier;
            data.color = new Color(data.color.ToVector4() * color.ToVector4());

            // get an aproximate number of the simultaneous particles that will have the system
            float spawnRatio = data.particlesLife / (float)data.nParticles;
            particles.Capacity = data.nParticles;

            switch(data.type)
            {
                case ParticleSystemData.tParticleSystem.Burst:
                    for(int i=0; i<data.nParticles; i++)
                    {
                        Particle p = new Particle();
                        p.isDead = true;
                        initializeParticle(p);
                        particles.Add(p);
                    }
                    break;
                case ParticleSystemData.tParticleSystem.Fountain:
                    for(int i=0; i<data.nParticles; i++)
                    {
                        Particle p = new Particle();
                        // we want particles prepared to be spawned with the spawnRatio ratio, so we set'em all alive but invisible
                        p.life = 1.3f + spawnRatio * i;
                        p.isDead = false;
                        p.color *= 0;
                        particles.Add(p);
                    }
                    break;
                default:
                    break;
            }
        }
Example #8
0
 public structVertex(Vector4 CoordVertex, Vector2 CoordTex, Vector4 Normale, Color Couleur, Vector4 Tangent)
 {
     this.CoordTex = CoordTex;
     this.CoordVertex = CoordVertex;
     this.Normale = Normale;
     this.Couleur = Couleur.ToVector4();
     this.Tangent = Tangent;
 }
Example #9
0
 public Spark(Texture2D Texture, int From, int To, float Time, Color color)
 {
     start = From;
     end = To;
     time = Time;
     parameter = 0.0f;
     Color = color.ToVector4();
 }
        public override Color GetColor(Player player, Color lightColor)
        {
            bool lighting = true;
            Color color = _colorProcessor(player, player.hairColor, ref lighting);
            if (lighting)
                return new Color(color.ToVector4() * lightColor.ToVector4());

            return color;
        }
Example #11
0
        /// <summary>
        /// Drawn text using given font, position and color
        /// </summary>
        public void DrawText(FontType font, String text, Vector2 position, Color color, bool dropShadow)
        {
            if (mIsTextModeActive)
            {
                if (dropShadow)
                    mSpriteBatch.DrawString(Fonts[(int)font], text, position + mDropShadowOffset, new Color(color.ToVector4() * new Vector4(0, 0, 0, 1)));

                mSpriteBatch.DrawString(Fonts[(int)font], text, position, color);
            }
        }
		public override Color GetColor(Player player, Color lightColor)
		{
			bool flag = true;
			Color result = this._colorProcessor(player, player.hairColor, ref flag);
			if (flag)
			{
				return new Color(result.ToVector4() * lightColor.ToVector4());
			}
			return result;
		}
Example #13
0
        public static Texture2D Create(GraphicsDevice graphicsDevice, int width = 1, int height = 1, Color color = new Color())
        {
            var texture = new Texture2D(graphicsDevice,
                                        width,
                                        height);

            var colors = new Color[width * height];
            for (var i = 0; i < colors.Length; i++) colors[i] = new Color(color.ToVector4());

            texture.SetData(colors);

            return texture;
        }
        //  Add 3d line into cache, so then we can draw many lines at once - by calling DrawLinesFromCache()
        public static void AddLine(Vector3 pointFrom, Vector3 pointTo, Color colorFrom, Color colorTo)
        {
            MyCommonDebugUtils.AssertDebug(IsFull(0) == false);

            if (m_linesCount + 2 >= MyDebugDrawCachedLinesConstants.MAX_LINES_IN_CACHE)
                return;

            m_verticesLine[m_linesCount * 2 + 0].Position = pointFrom;
            m_verticesLine[m_linesCount * 2 + 0].Color = colorFrom.ToVector4();
            m_verticesLine[m_linesCount * 2 + 1].Position = pointTo;
            m_verticesLine[m_linesCount * 2 + 1].Color = colorTo.ToVector4();
            m_linesCount++;
        }
Example #15
0
        //int colormixer = NewImage(1, 1);
        Color ColorMorph(Color col1, Color col2, int step, int totalsteps)
        {
            float factor = step / (float)totalsteps;
            var vcol1 = col1.ToVector4();
            var vcol2 = col2.ToVector4();
            var result = vcol1 * (1-factor) + vcol2 * factor;
            result.W = 1;
            return new Color(result);

            //SetPixel(0, 0, col1, colormixer);
            //SetLucent(100 - (step * 100 / totalsteps));
            //SetPixel(0, 0, col2, colormixer);
            //SetLucent(0);
            //return GetPixel(0, 0, colormixer);
        }
Example #16
0
        public void SetElement(int i, Vector2 start, Vector2 end, Color color, float radius)
        {
            Debug.Assert(i < Count);

            positionData[i] = new Vector4(start.X, start.Y, end.X, end.Y);
            colorData[i] = color.ToVector4();

            switch(i%4)
            {
                case 0: radiusData[i/4].X = radius; break;
                case 1: radiusData[i/4].Y = radius; break;
                case 2: radiusData[i/4].Z = radius; break;
                case 3: radiusData[i/4].W = radius; break;
            }
        }
        public static void render(this Texture texture, Matrix worldMatrix, Color color, bool customUVs = false)
        {
            fxWVP.SetValue(worldMatrix * Camera2D.view * Camera2D.projection);
            fxTexture.SetValue(texture);
            fxColor.SetValue(color.ToVector4());
            quadEffect.Techniques[0].Passes[0].Apply();

            if (customUVs)
            {
                GraphicsManager.Instance.graphicsDevice.DrawUserIndexedPrimitives<VertexPositionTexture>(
                    PrimitiveType.TriangleList, vertexUVs, 0, 4, index, 0, 2);
            }
            else
            {
                GraphicsManager.Instance.graphicsDevice.DrawUserIndexedPrimitives<VertexPositionTexture>(
                    PrimitiveType.TriangleList, vertex, 0, 4, index, 0, 2);
            }
        }
Example #18
0
        public Progressbar ( string name, Vector2 position, Color color, int width, int value, bool bContinuous )
        {
            Type = ControlType.ProgressBar;
            this.name = name;
            //this.origin = position;
            this.position = position;
            this.width = width;
            this.value = value;
            this.color = color.ToVector4();

            if (bContinuous)
                style = Style.Continuous;
            else
                style = Style.Blocks;

            numberOfBlocks = width / blockWidth + 1;
            max = 100;

            CreateTextures();
        }
Example #19
0
        public HslColor(Color rgba)
        {
            Vector4 v4 = rgba.ToVector4();

            double min = Math.Min(Math.Min(v4.X, v4.Y), v4.Z);
            double max = Math.Max(Math.Max(v4.X, v4.Y), v4.Z);

            L = (min + max) / 2.0;
            H = double.NaN;

            if (min == max)
            {
                S = 0;
                H = 0;
            }
            else if (L < 0.5)
            {
                S = (max - min) / (max + min);
            }
            else
            {
                S = (max - min) / (2.0 - max - min);
            }

            if (H == double.NaN)
            {
                if (v4.X == max)
                {
                    H = ((v4.Y - v4.Z) / (max - min)) / 6.0;
                }
                else if (v4.Y == max)
                {
                    H = (2.0 + (v4.Z - v4.X) / (max - min)) / 6.0;
                }
                else
                {
                    H = (4.0 + (v4.X - v4.Y) / (max - min)) / 6.0;
                }
            }
        }
Example #20
0
 public static void ColorKey(TextureContent texture, Color colorKey)
 {
     foreach (MipmapChain chain in texture.Faces)
     {
         foreach (BitmapContent content in chain)
         {
             var content3 = content as PixelBitmapContent<Color>;
             if (content3 == null)
             {
                 var content2 = content as PixelBitmapContent<Vector4>;
                 if (content2 == null)
                 {
                     throw new NotSupportedException();
                 }
                 content2.ReplaceColor(colorKey.ToVector4(), Vector4.Zero);
             }
             else
             {
                 content3.ReplaceColor(colorKey, Color.Transparent);
             }
         }
     }
 }
Example #21
0
 /// <summary>
 /// Multiplies the the specified <see cref="Color"/> with this <see cref="Color"/>.
 /// </summary>
 /// <param name="a">A.</param>
 /// <param name="colour">The colour.</param>
 /// <returns>This <see cref="Color"/> multiplied with the specified <see cref="Color"/>.</returns>
 public static Color Multiply(this Color a, Color colour)
 {
     var aVec = a.ToVector4();
     var bVec = colour.ToVector4();
     return new Color(aVec * bVec);
 }
Example #22
0
 public static Color Between(Color col1, Color col2, float val)
 {
     Vector4 v1 = col1.ToVector4(), v2 = col2.ToVector4();
     return new Color(v1 + ((v2 - v1) * val));
 }
        /// <summary>
        /// Render car model with this seperate method because we
        /// render it in 2 steps, first the solid stuff, then the alpha glass.
        /// We also rotate the wheels around :)
        /// </summary>
        /// <param name="shadowCarMode">In the shadow car mode we render
        /// everything (including wheels and glass) with a special ShadowCar
        /// shader, that is very transparent. Used for the shadow car when
        /// playing that shows how we drove the last time.</param>
        /// <param name="renderMatrix">Render matrix for the car</param>
        public void RenderCar(bool shadowCarMode, Matrix renderMatrix)
        {
            // Multiply object matrix by render matrix, result is used multiple
            // times here.
            renderMatrix = objectMatrix * renderMatrix;

            // Do we just want to render the shadow car? Then do this in a
            // simpified way here instead of messing with the already complicated
            // code below.
            if (shadowCarMode)
            {
                // Start shadow car shader
                ShaderEffect simpleShader = ShaderEffect.simple;
                simpleShader.Render(
                    "ShadowCar",
                    delegate
                    {
                        int wheelNumber = 0;
                        // And just render all meshes with it!
                        for (int meshNum = 0; meshNum < xnaModel.Meshes.Count; meshNum++)
                        {
                            ModelMesh mesh = xnaModel.Meshes[meshNum];

                            Matrix meshMatrix = transforms[mesh.ParentBone.Index];

                            // Only the wheels have 2 mesh parts (gummi and chrome)
                            if (mesh.MeshParts.Count == 2)
                            {
                                wheelNumber++;
                                meshMatrix =
                                    Matrix.CreateRotationX(
                                    // Rotate left 2 wheels forward, the other 2 backward!
                                    (wheelNumber == 2 || wheelNumber == 4 ? 1 : -1) *
                                    SpeedyRacerManager.Player.CarWheelPos) *
                                    meshMatrix;
                            } // if (mesh.MeshParts.Count)

                            // Assign world matrix
                            BaseGame.WorldMatrix =
                                meshMatrix *
                                renderMatrix;

                            // Set all matrices
                            simpleShader.SetParameters();
                            simpleShader.Update();

                            // And render (must be done without mesh.Draw, which would just
                            // use the original shaders for the model)
                            for (int partNum = 0; partNum < mesh.MeshParts.Count; partNum++)
                            {
                                ModelMeshPart part = mesh.MeshParts[partNum];
                                // Make sure vertex declaration is correct
                                BaseGame.Device.VertexDeclaration = part.VertexDeclaration;
                                // Set vertex buffer and index buffer
                                BaseGame.Device.Vertices[0].SetSource(
                                    mesh.VertexBuffer, part.StreamOffset, part.VertexStride);
                                BaseGame.Device.Indices = mesh.IndexBuffer;

                                // And render all primitives
                                BaseGame.Device.DrawIndexedPrimitives(
                                    PrimitiveType.TriangleList,
                                    part.BaseVertex, 0, part.NumVertices,
                                    part.StartIndex, part.PrimitiveCount);
                            } // for
                        } // for
                    });

                // And get outta here
                return;
            } // if

            // Usually use default color values
            Color carAmbientColor = new Color(100, 100, 100),
                carDiffuseColor = Material.DefaultDiffuseColor;
            EffectTechnique remCurrentTechnique = null;
            for (int alphaPass = 0; alphaPass < 2; alphaPass++)
            {
                int wheelNumber = 0;

                int effectParameterIndex = 0;
                int effectTechniqueIndex = 0;

                for (int meshNum = 0; meshNum < xnaModel.Meshes.Count; meshNum++)
                {
                    ModelMesh mesh = xnaModel.Meshes[meshNum];
                    bool dontRender = false;

                    for (int effectNum = 0; effectNum < mesh.Effects.Count; effectNum++)
                    {
                        Effect effect = mesh.Effects[effectNum];
                        if (effectNum == 0)
                            remCurrentTechnique = effect.CurrentTechnique;

                        // Find out if this is ReflectionSimpleGlass.fx,
                        // NormalMapping.fx will also use reflection, but the techniques
                        // are named in another way (SpecularWithReflection, etc.)
                        if (cachedIsReflectionSpecularTechnique[effectTechniqueIndex++])
                        {
                            if (alphaPass == 0)
                            {
                                dontRender = true;
                                effectParameterIndex += 7;
                                break;
                            } // if (alphaPass)

                            // Skip the first 3 effect parameters
                            effectParameterIndex += 3;
                        } // if (effect.CurrentTechnique.Name.Contains)
                        else
                        {
                            if (alphaPass == 1)
                            {
                                dontRender = true;
                                effectParameterIndex += 7;
                                break;
                            } // if (alphaPass)

                            // To improve performance we only have to set this when it changes!
                            // Doesn't do much, because this eats only 10% performance,
                            // 5-10% are the matrices below and most of the performance is
                            // just rendering the car with Draw!

                            // Skip texture, not used here.
                            effectParameterIndex++;

                            // Set ambient and diffuse colors
                            cachedEffectParameters[effectParameterIndex++].SetValue(
                                carAmbientColor.ToVector4());
                            cachedEffectParameters[effectParameterIndex++].SetValue(
                                carDiffuseColor.ToVector4());
                        } // else

                        Matrix meshMatrix = transforms[mesh.ParentBone.Index];

                        // Only the wheels have 2 mesh parts (gummi and chrome)
                        if (mesh.MeshParts.Count == 2)
                        {
                            wheelNumber++;
                            meshMatrix =
                                Matrix.CreateRotationX(
                                // Rotate left 2 wheels forward, the other 2 backward!
                                (wheelNumber == 2 || wheelNumber == 4 ? 1 : -1) *
                                SpeedyRacerManager.Player.CarWheelPos) *
                                meshMatrix;
                        } // if (mesh.MeshParts.Count)

                        // Assign world matrix
                        BaseGame.WorldMatrix =
                            meshMatrix *
                            renderMatrix;

                        // Set matrices
                        //effect.Parameters["world"].SetValue(
                        cachedEffectParameters[effectParameterIndex++].SetValue(
                            BaseGame.WorldMatrix);

                        // These values should only be set once every frame (see above)!
                        // to improve performance again, also we should access them
                        // with EffectParameter and not via name!
                        // But since we got only 1 car it doesn't matter so much ..
                        cachedEffectParameters[effectParameterIndex++].SetValue(
                            BaseGame.ViewProjectionMatrix);
                        cachedEffectParameters[effectParameterIndex++].SetValue(
                            BaseGame.InverseViewMatrix);
                        // Set light direction
                        cachedEffectParameters[effectParameterIndex++].SetValue(
                            BaseGame.LightDirection);
                    } // foreach (effect)

                    // Render
                    if (dontRender == false)
                        mesh.Draw();
                } // foreach (mesh)
            } // for (alphaPass)
        }
Example #24
0
 /// <summary>
 /// Draws line between p0 and p1
 /// </summary>
 /// <param name="p0"></param>
 /// <param name="p1"></param>
 /// <param name="color"></param>
 public void DrawLine(Vector2 p0, Vector2 p1, Color color)
 {
     vertexDataAccum.Add(new LineVertex() { Pos = new Vector3(p0, 0), Color = color.ToVector4() });
     vertexDataAccum.Add(new LineVertex() { Pos = new Vector3(p1, 0), Color = color.ToVector4() });
     //DrawLine( p0, p1, color, Matrix.Identity );
 }
Example #25
0
 private Color MulColorByOverlay(Color c)
 {
     return Overlay == Color.White ? c : new Color(c.ToVector4() * Overlay.ToVector4());
 }
        /// <summary>
        /// Draw a list of Lines.
        /// </summary>
        public void Draw(List<RoundLine> roundLines, float lineRadius, Color lineColor, Matrix viewProjMatrix, 
            float time, string techniqueName)
        {
            device.SetVertexBuffer(vb);
            device.Indices = ib;

            viewProjMatrixParameter.SetValue(viewProjMatrix);
            timeParameter.SetValue(time);
            lineColorParameter.SetValue(lineColor.ToVector4());
            lineRadiusParameter.SetValue(lineRadius);
            blurThresholdParameter.SetValue(BlurThreshold);

            if (techniqueName == null)
                effect.CurrentTechnique = effect.Techniques[0];
            else
                effect.CurrentTechnique = effect.Techniques[techniqueName];
            EffectPass pass = effect.CurrentTechnique.Passes[0];
            pass.Apply();

            int iData = 0;
            int numInstancesThisDraw = 0;
            foreach (RoundLine roundLine in roundLines)
            {
                translationData[iData++] = roundLine.P0.X;
                translationData[iData++] = roundLine.P0.Y;
                translationData[iData++] = roundLine.Rho;
                translationData[iData++] = roundLine.Theta;
                numInstancesThisDraw++;

                if (numInstancesThisDraw == numInstances)
                {
                    instanceDataParameter.SetValue(translationData);
                    pass.Apply();
                    device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numVertices, 0, numPrimitivesPerInstance * numInstancesThisDraw);
                    NumLinesDrawn += numInstancesThisDraw;
                    numInstancesThisDraw = 0;
                    iData = 0;
                }
            }
            if (numInstancesThisDraw > 0)
            {
                instanceDataParameter.SetValue(translationData);
                pass.Apply();
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numVertices, 0, numPrimitivesPerInstance * numInstancesThisDraw);
                NumLinesDrawn += numInstancesThisDraw;
            }
        }
Example #27
0
 public override Color OnTileColor(Color inColor)
 {
     return new Color(Vector4.Lerp(inColor.ToVector4(), Vector4.One, _fadeOpacity * 0.5f));
 }
Example #28
0
 public override Color OnTileColor(Color inColor)
 {
     float intensity = this.GetIntensity();
     return new Color(Vector4.Lerp(new Vector4(0.5f, 0.8f, 1f, 1f), inColor.ToVector4(), 1f - intensity));
 }
Example #29
0
 public override Color OnTileColor(Color inColor)
 {
     Vector4 value = inColor.ToVector4();
     return new Color(Vector4.Lerp(value, Vector4.One, this._fadeOpacity * 0.5f));
 }
Example #30
0
        public void CreateShootBullet(Vector3 InitPos, Vector3 DirBullet, Color BulletColor)
        {
            if (BulletID == 20)
                return;

            GeometryNode ShootBullet = new GeometryNode("ShootBullet" + BulletID++);

            ShootBullet.Model = BulletModel;

            BulletrMat.Diffuse = BulletColor.ToVector4();

            ShootBullet.Material = BulletrMat;
            ShootBullet.Physics.Interactable = true;
            ShootBullet.Physics.Collidable = true;
            ShootBullet.Physics.Shape = GoblinXNA.Physics.ShapeType.Box;
            ShootBullet.Physics.Mass = 60f;
            ShootBullet.Physics.MaterialName = "Bullet";
            ShootBullet.AddToPhysicsEngine = true;

            // Assign the initial velocity to this shooting box
            ShootBullet.Physics.InitialLinearVelocity = new Vector3(DirBullet.X * 80, DirBullet.Y * 80, DirBullet.Z * 50);

            TransformNode BulletTrans = new TransformNode();
            BulletTrans.Translation = InitPos;

            groundMarkerNode.AddChild(BulletTrans);
            BulletTrans.AddChild(ShootBullet);
        }