Exemple #1
0
        public ComplexVertex(Vector3 position, Color4b color)
        {
            X = position.X;
            Y = position.Y;
            Z = position.Z;

            colorR = color.R;
            colorG = (ushort)(color.G * 2048 / 255);
            colorB = color.B;

            matrix1 = Matrix4x4.Identity;

            sixtyThree      = 63;
            sixtyFour       = 64;
            oneTwoThreeFour = new Vector4(1, 2, 3, 4);
            alwaysZero      = 0;
            alsoZero        = 0;

            nothing0 = default;

            padding0  = default;
            padding1  = default;
            padding2  = default;
            padding3  = default;
            padding4  = default;
            padding5  = default;
            padding6  = default;
            padding7  = default;
            padding8  = default;
            padding9  = default;
            padding10 = default;
        }
Exemple #2
0
        /// <summary>
        /// The update method is used by the emitter to apply the action
        /// to every particle. It is called within the emitter's update
        /// loop and need not be called by the user.
        /// </summary>
        /// <param name="emitter">The Emitter that created the particle.</param>
        /// <param name="particle">The particle to be updated.</param>
        /// <param name="elapsedTime">The duration of the frame - used for time based updates.</param>
        public override void Update(Emitter emitter, Particle particle, double elapsedTime)
        {
            double alpha = m_endAlpha + m_diffAlpha * particle.Energy;
            int    a     = Math.Max(0, Math.Min(255, (int)(alpha * 256)));

            particle.Color = Color4b.FromArgb(a, particle.Color);
        }
Exemple #3
0
        public void ParseTest()
        {
            Assert.AreEqual(Color4bs.Blue, Color4b.Parse("Blue"));
            Assert.AreEqual(Color4bs.Blue, Color4b.Parse("blue"));
            Assert.AreEqual(Color4bs.Blue, Color4b.Parse(" blue "));
            Assert.AreEqual(Color4bs.Blue, Color4b.Parse(" blUe"));
            Assert.AreEqual(Color4bs.Blue, Color4b.Parse("BLUE"));

            var color = Color4b.FromValue(0xFFCCBBAA);

            Assert.AreEqual(Color4bs.Black, Color4b.Parse("#FF000000"));
            Assert.AreEqual(Color4bs.YellowGreen, Color4b.Parse("#FF9ACD32"));
            Assert.AreEqual(Color4bs.YellowGreen, Color4b.Parse("#9ACD32"));
            Assert.AreEqual(color, Color4b.Parse("#FFCCBBAA"));
            Assert.AreEqual(color, Color4b.Parse("#CCbBaA"));
            Assert.AreEqual(color, Color4b.Parse("#FCBA"));
            Assert.AreEqual(color, Color4b.Parse("#cba"));
            Assert.AreEqual(color, Color4b.Parse(" #CBA "));

            Assert.Catch <FormatException>(() => Color4b.Parse(" bl Ue"));
            Assert.Catch <FormatException>(() => Color4b.Parse(" blxUe"));
            Assert.Catch <FormatException>(() => Color4b.Parse(" blUex"));

            Assert.Catch <FormatException>(() => Color4b.Parse("#0xFFCCBBAA"));
            Assert.Catch <FormatException>(() => Color4b.Parse("# C B A"));
            Assert.Catch <FormatException>(() => Color4b.Parse("#d0C0BcA"));
        }
 public TerrainVertex(Vector3 position, Vector3 normal, Color4b color, Vector2 lightingConfig)
 {
     Position       = position;
     Normal         = normal;
     Color          = color;
     LightingConfig = lightingConfig;
 }
        void Update(Vector2i v)
        {
            int num = 0;

            Color4b[] neighbors = new Color4b[8];
            neighbors[0] = Get(v + new Vector2i(-1, -1), ref num);
            neighbors[1] = Get(v + new Vector2i(0, -1), ref num);
            neighbors[2] = Get(v + new Vector2i(1, -1), ref num);
            neighbors[3] = Get(v + new Vector2i(-1, 0), ref num);
            neighbors[4] = Get(v + new Vector2i(1, -0), ref num);
            neighbors[5] = Get(v + new Vector2i(-1, 1), ref num);
            neighbors[6] = Get(v + new Vector2i(0, 1), ref num);
            neighbors[7] = Get(v + new Vector2i(1, 1), ref num);

            int r = 0;
            int g = 0;
            int b = 0;

            for (int i = 0; i < 8; i++)
            {
                Color4b n = neighbors[i];
                r += n.r;
                g += n.g;
                b += n.b;
            }

            r /= num;
            g /= num;
            b /= num;

            var color = new Color4b(r, g, b, 0);

            scratch[GetIndex(v)] = color;
        }
        protected override void OnKeyDown(IKeyboard sender, Key key, int n)
        {
            if (Window.IsClosing)
            {
                return;
            }

            switch (key)
            {
            case Key.Home:
                offset        = Vector2.Zero;
                scaleExponent = 0.2f;
                scale         = MathF.Pow(10, scaleExponent);
                UpdateTransformMatrix();
                break;

            case Key.R:
                Color4b[] noise = new Color4b[fbo1.Width * fbo1.Height];
                for (int i = 0; i < noise.Length; i++)
                {
                    noise[i] = new Color4b((byte)r.Next(256), (byte)r.Next(255), (byte)r.Next(255), 255);
                }
                fbo1.Texture.SetData <Color4b>(noise);
                break;
            }
        }
        void Run()
        {
            var start = new Vector2i(Width / 2, Height / 2);

            //start with one pixel colored
            SetPixel(start, ColorSource.Get());

            while (running && ColorSource.Count > 0 && front.Count > 0)
            {
                Color4b color = ColorSource.Get();

                int      bestScore = int.MaxValue;
                Vector2i bestPos   = new Vector2i();

                foreach (var v in front)
                {
                    int score = GetScore(v, color);
                    if (score < bestScore)
                    {
                        bestScore = score;
                        bestPos   = v;
                    }
                }

                front.Remove(bestPos);

                SetPixel(bestPos, color);
            }
        }
Exemple #8
0
        public void Render(AABB view, double interpolation)
        {
            var color = new Color4b(Color4b.White)
            {
                A = 0x7f
            };

            // vertical center
            if (PlatformSnapping)
            {
                Renderer.Instance.RenderLineOverlay(view,
                                                    new Vector2f(0, view.Size.Y / 2).Round(), new Vector2f(view.Size.X, view.Size.Y / 2).Round(),
                                                    color);
            }

            // window
            Renderer.Instance.RenderLineOverlay(view,
                                                Window.Min.Round(), new Vector2f(Window.Right, Window.Bottom).Round(),
                                                color);
            Renderer.Instance.RenderLineOverlay(view,
                                                Window.Min.Round(), new Vector2f(Window.Left, Window.Top).Round(),
                                                color);
            Renderer.Instance.RenderLineOverlay(view,
                                                new Vector2f(Window.Left, Window.Top).Round(), Window.Max.Round(),
                                                color);
            Renderer.Instance.RenderLineOverlay(view,
                                                new Vector2f(Window.Right, Window.Bottom).Round(), Window.Max.Round(),
                                                color);
        }
        protected override void OnRender(double dt)
        {
            float time = (float)stopwatch.Elapsed.TotalSeconds;

            graphicsDevice.Clear(ClearBufferMask.ColorBufferBit);

            Vector2 mousePos = new Vector2(InputContext.Mice[0].Position.X, InputContext.Mice[0].Position.Y);

            textureBatcher.Begin(BatcherBeginMode.OnTheFly);

            float loreIpsumScale = 1 + 0.1f * MathF.Sin(time * 4.32f);

            textureBatcher.DrawString(arialFont, loremIpsum, new Vector2(50, 25), Color4b.White, loreIpsumScale, Vector2.Zero);

            string  comicText      = "You can draw text!!\nIt's very nice :)";
            Vector2 comicTextSize  = comicSansFont.Measure(comicText);
            Color4b comicTextColor = Color4b.FromHSV(time % 1, 1f, 1f);
            float   comicTextScale = 1 + 0.1f * MathF.Sin(time);
            float   comicTextRot   = 0.3f * MathF.Sin(time * 4.32f);

            textureBatcher.DrawString(comicSansFont, comicText, new Vector2(500, 610), comicTextColor, comicTextScale, comicTextRot, comicTextSize / 2f);

            foreach (Particle particle in particles)
            {
                particle.Draw(textureBatcher);
            }
            for (int i = 0; i < diamonds.Length; i++)
            {
                diamonds[i].Draw(textureBatcher);
            }
            for (int i = 0; i < balls.Length; i++)
            {
                balls[i].Draw(textureBatcher);
            }

            textureBatcher.End();


            textureBatcher.Begin(BatcherBeginMode.SortBackToFront);
            Vector2     rectOrigin = new Vector2(rectangleTexture.Width / 2f, rectangleTexture.Height / 2f);
            const float meh        = 100;
            const int   times      = 6;

            for (float x = -meh * times; x <= meh * times; x += meh)
            {
                for (float y = -meh * times; y <= meh * times; y += meh)
                {
                    float dist  = Math.Abs(x) + Math.Abs(y);
                    byte  alpha = (byte)Math.Max(0, 255 - (3f / times) * dist);
                    float dep   = dist / 500f;
                    float sc    = dist / meh * 0.175f;
                    sc = 1 - sc * sc;
                    Vector2 pos = mousePos + new Vector2(MathF.Sign(x), MathF.Sign(y)) * Vector2.SquareRoot(new Vector2(MathF.Abs(x), MathF.Abs(y)) / meh) * meh;
                    textureBatcher.Draw(rectangleTexture, pos, null, new Color4b(255, 255, 255, alpha), sc, time, rectOrigin, dep);
                }
            }
            textureBatcher.End();

            Window.SwapBuffers();
        }
Exemple #10
0
 public void SubtractTest()
 {
     Test(Color4b.FromArgb(100, 150, 200, 250) - Color4b.FromArgb(10, 20, 30, 40),
          90, 130, 170, 210);
     Test(Color4b.FromArgb(10, 20, 30, 40) - Color4b.FromArgb(100, 150, 200, 250),
          0, 0, 0, 0);
 }
Exemple #11
0
 public void AddTest()
 {
     Test(Color4b.FromArgb(10, 20, 30, 40) + Color4b.FromArgb(100, 150, 200, 250),
          110, 170, 230, 255);
     Test(Color4b.FromArgb(255, 255, 255, 255) + Color4b.FromArgb(100, 150, 200, 250),
          255, 255, 255, 255);
 }
Exemple #12
0
        public override void RenderRectangle(AABB view, AABB rectangle, Color4b borderColor, Color4b fillColor)
        {
            var scale       = CurrentWindowSize / view.Size;
            var screenSpace = (rectangle.Min - view.Min) * scale;

            var rect = new SDL2.SDL.SDL_Rect
            {
                x = (int)screenSpace.X,
                y = (int)((view.Size.Y - rectangle.Size.Y) * scale.Y - screenSpace.Y),
                w = (int)(rectangle.Size.X * scale.X),
                h = (int)(rectangle.Size.Y * scale.Y),
            };

            if (fillColor.A > 0)
            {
                // fill rectangle
                SDL2.SDL.SDL_SetRenderDrawColor(RendererPtr, fillColor.R, fillColor.G, fillColor.B, fillColor.A);
                SDL2.SDL.SDL_RenderFillRect(RendererPtr, ref rect);
            }

            if (borderColor != fillColor)
            {
                if (borderColor.A > 0)
                {
                    // border rectangle
                    SDL2.SDL.SDL_SetRenderDrawColor(RendererPtr, borderColor.R, borderColor.G, borderColor.B, borderColor.A);
                    SDL2.SDL.SDL_RenderDrawRect(RendererPtr, ref rect);
                }
            }
        }
Exemple #13
0
        public static bool PixelClash(Color4b a, Color4b b, double threshold)
        {
            Color4 af = new Color4(a);
            Color4 bf = new Color4(b);

            return(PixelClash(af, bf, threshold));
        }
Exemple #14
0
        public static void GenerateMSDF(Bitmap <Color4b> output, Shape shape, Rectangle region, double range, Vector2 scale, Vector2 translate, double edgeThreshold)
        {
            int contourCount = shape.Contours.Count;

            int[] windings = new int[contourCount];

            for (int i = 0; i < shape.Contours.Count; i++)
            {
                windings[i] = shape.Contours[i].Winding;
            }

            int xStart = Math.Min(Math.Max(0, (int)region.Left), output.Width);
            int yStart = Math.Min(Math.Max(0, (int)region.Top), output.Height);
            int xEnd   = Math.Min(Math.Max(0, (int)region.Right), output.Width);
            int yEnd   = Math.Min(Math.Max(0, (int)region.Bottom), output.Height);

            MultiDistance[] contourSD = new MultiDistance[contourCount];

            for (int y = yStart; y < yEnd; y++)
            {
                int row = shape.InverseYAxis ? yEnd - (y - yStart) - 1 : y;
                for (int x = xStart; x < xEnd; x++)
                {
                    Vector2 p = (new Vector2(x, y) - region.Position - translate) / scale;
                    output[x, row] = new Color4b(EvaluateMSDF(shape, windings, contourSD, p, range), 255);
                }
            }
        }
Exemple #15
0
        /// <summary>
        /// Sets the particles properties to their default values.
        /// </summary>
        public void Initialize()
        {
            m_x               = 0;
            m_y               = 0;
            m_previousX       = 0;
            m_previousY       = 0;
            m_targetX         = 0;
            m_targetY         = 0;
            m_velocityX       = 0;
            m_velocityY       = 0;
            m_rotation        = 0;
            m_angularVelocity = 0;
            m_color           = Color4bs.White;
            m_scale           = 1;
            m_lifetime        = 0;
            m_age             = 0;
            m_energy          = 1;
            m_isDead          = false;

            if (m_imageData != null)
            {
                m_imageData.Dispose();
                m_imageData = null;
            }
        }
Exemple #16
0
        public static Vec4f ToVec4f(this Color4b color)
        {
            ColorSetter4f setter = new ColorSetter4f();

            color.GetColor(setter);
            return(new Vec4f(setter.C1, setter.C2, setter.C3, setter.C4));
        }
Exemple #17
0
 private static void Test(Color4b c, int a, int r, int g, int b)
 {
     Assert.AreEqual(c.A, a);
     Assert.AreEqual(c.R, r);
     Assert.AreEqual(c.G, g);
     Assert.AreEqual(c.B, b);
     Assert.AreEqual(Color4b.FromArgb(a, r, g, b), c);
 }
Exemple #18
0
 private static void Test(Color4b c, int a, int r, int g, int b)
 {
     Assert.AreEqual(c.A, a);
     Assert.AreEqual(c.R, r);
     Assert.AreEqual(c.G, g);
     Assert.AreEqual(c.B, b);
     Assert.AreEqual(Color4b.FromArgb(a, r, g, b), c);
 }
Exemple #19
0
        public unsafe ImGuiHelper(Game game)
        {
            this.game                = game;
            game.Keyboard.KeyDown   += Keyboard_KeyDown;
            game.Keyboard.KeyUp     += Keyboard_KeyUp;
            game.Keyboard.TextInput += Keyboard_TextInput;
            context = ImGui.CreateContext();
            ImGui.SetCurrentContext(context);
            SetKeyMappings();

            var io = ImGui.GetIO();

            //IniFilename?
            io.WantSaveIniSettings = false;
            Default = io.Fonts.AddFontDefault();
            using (var stream = typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LibreLancer.ImUI.Roboto-Medium.ttf"))
            {
                var ttf = new byte[stream.Length];
                stream.Read(ttf, 0, ttf.Length);
                ttfPtr = Marshal.AllocHGlobal(ttf.Length);
                Marshal.Copy(ttf, 0, ttfPtr, ttf.Length);
                Noto = io.Fonts.AddFontFromMemoryTTF(ttfPtr, ttf.Length, 15);
            }
            using (var stream = typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LibreLancer.ImUI.checkerboard.png"))
            {
                checkerboard   = LibreLancer.ImageLib.Generic.FromStream(stream);
                CheckerboardId = RegisterTexture(checkerboard);
            }
            ImGuiExt.BuildFontAtlas((IntPtr)io.Fonts.NativePtr);
            byte *fontBytes;
            int   fontWidth, fontHeight;

            io.Fonts.GetTexDataAsAlpha8(out fontBytes, out fontWidth, out fontHeight);
            io.Fonts.TexUvWhitePixel = new Vector2(10, 10);
            fontTexture = new Texture2D(fontWidth, fontHeight, false, SurfaceFormat.R8);
            var bytes = new byte[fontWidth * fontHeight];

            Marshal.Copy((IntPtr)fontBytes, bytes, 0, fontWidth * fontHeight);
            fontTexture.SetData(bytes);
            fontTexture.SetFiltering(TextureFiltering.Linear);
            io.Fonts.SetTexID((IntPtr)FONT_TEXTURE_ID);
            io.Fonts.ClearTexData();
            textShader  = new Shader(vertex_source, text_fragment_source);
            colorShader = new Shader(vertex_source, color_fragment_source);
            dot         = new Texture2D(1, 1, false, SurfaceFormat.Color);
            var c = new Color4b[] { Color4b.White };

            dot.SetData(c);
            Theme.Apply();
            //Required for clipboard function on non-Windows platforms
            utf8buf    = Marshal.AllocHGlobal(8192);
            instance   = this;
            setTextDel = SetClipboardText;
            getTextDel = GetClipboardText;

            io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(getTextDel);
            io.SetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(setTextDel);
        }
Exemple #20
0
 /// <summary>
 /// Constructs a randomized <see cref="Color4b"/> with an alpha value of 255.
 /// </summary>
 /// <param name="random">The <see cref="Random"/> to use for randomizing.</param>
 public static Color4b NextColor4bFullAlpha(this Random random)
 {
     unchecked
     {
         uint    val   = (uint)random.Next();
         Color4b color = new Color4b((byte)(val & 255), (byte)((val >> 8) & 255), (byte)((val >> 16) & 255));
         return(color);
     }
 }
Exemple #21
0
        /// <summary>
        /// The constructor creates a ColorInit initializer for use by 
        /// an emitter. To add a ColorInit to all particles created by an emitter, use the
        /// emitter's addInitializer method.
        /// 
        /// <p>The color of particles initialized by this public class
        /// will be a random value between the two values pased to
        /// the constructor. For a fixed value, pass the same color
        /// in for both parameters.</p>
        /// </summary>
        /// <param name="color1">the color intensity start</param>
        /// <param name="color2">the color intensity end</param>
        public ColorRotateInit(int intensityStart, int intensityEnd)
        {
            m_intensityStart = intensityStart;
            m_intensityEnd = intensityEnd;
            int colorRotation = Utils.Random.Next(360);

            m_min = Utils.RotateHue(colorRotation, m_intensityStart);
            m_max = Utils.RotateHue(colorRotation, m_intensityEnd);
        }
Exemple #22
0
        /// <summary>
        /// The constructor creates a ColorInit initializer for use by
        /// an emitter. To add a ColorInit to all particles created by an emitter, use the
        /// emitter's addInitializer method.
        ///
        /// <p>The color of particles initialized by this public class
        /// will be a random value between the two values pased to
        /// the constructor. For a fixed value, pass the same color
        /// in for both parameters.</p>
        /// </summary>
        /// <param name="color1">the color intensity start</param>
        /// <param name="color2">the color intensity end</param>
        public ColorRotateInit(int intensityStart, int intensityEnd)
        {
            m_intensityStart = intensityStart;
            m_intensityEnd   = intensityEnd;
            int colorRotation = Utils.Random.Next(360);

            m_min = Utils.RotateHue(colorRotation, m_intensityStart);
            m_max = Utils.RotateHue(colorRotation, m_intensityEnd);
        }
Exemple #23
0
        public void MultiplyTest()
        {
            Test(Color4b.FromArgb(100, 150, 200, 250) * 2, 200, 255, 255, 255);
            Test(2 * Color4b.FromArgb(100, 150, 200, 250), 200, 255, 255, 255);
            Test(Color4b.FromArgb(100, 150, 200, 130) * 1.1, 110, 165, 220, 143);

            Test(Color4b.FromArgb(255, 255, 255, 255) * Color4b.FromArgb(255, 128, 64, 32),
                 255, 128, 64, 32);
        }
        public ImGuiHelper(Game game)
        {
            this.game                = game;
            game.Keyboard.KeyDown   += Keyboard_KeyDown;
            game.Keyboard.KeyUp     += Keyboard_KeyUp;
            game.Keyboard.TextInput += Keyboard_TextInput;
            SetKeyMappings();
            var io = ImGui.GetIO();

            unsafe
            {
                io.GetNativePointer()->IniFilename = IntPtr.Zero;
            }
            Default = io.FontAtlas.AddDefaultFont();
            using (var stream = typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LancerEdit.UILib.Roboto-Medium.ttf"))
            {
                var ttf = new byte[stream.Length];
                stream.Read(ttf, 0, ttf.Length);
                ttfPtr = Marshal.AllocHGlobal(ttf.Length);
                Marshal.Copy(ttf, 0, ttfPtr, ttf.Length);
                Noto = io.FontAtlas.AddFontFromMemoryTTF(ttfPtr, ttf.Length, 15);
            }
            using (var stream = typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LancerEdit.UILib.checkerboard.png"))
            {
                checkerboard   = LibreLancer.ImageLib.Generic.FromStream(stream);
                CheckerboardId = RegisterTexture(checkerboard);
            }
            using (var stream = typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LancerEdit.UILib.circle.png"))
            {
                circle   = LibreLancer.ImageLib.Generic.FromStream(stream);
                CircleId = RegisterTexture(circle);
            }
            unsafe
            {
                ImGuiExt.BuildFontAtlas((IntPtr)ImGuiNative.igGetIO()->FontAtlas);
            }
            FontTextureData texData = io.FontAtlas.GetTexDataAsAlpha8();

            fontTexture = new Texture2D(texData.Width, texData.Height, false, SurfaceFormat.R8);
            var bytes = new byte[texData.Width * texData.Height * texData.BytesPerPixel];

            unsafe
            {
                Marshal.Copy((IntPtr)texData.Pixels, bytes, 0, texData.Width * texData.Height * texData.BytesPerPixel);
            }
            fontTexture.SetData(bytes);
            fontTexture.SetFiltering(TextureFiltering.Linear);
            io.FontAtlas.SetTexID(FONT_TEXTURE_ID);
            io.FontAtlas.ClearTexData();
            textShader  = new Shader(vertex_source, text_fragment_source);
            colorShader = new Shader(vertex_source, color_fragment_source);
            dot         = new Texture2D(1, 1, false, SurfaceFormat.Color);
            var c = new Color4b[] { Color4b.White };

            dot.SetData(c);
            Theme.Apply();
        }
Exemple #25
0
        public void CreateTest()
        {
            var c = Color4b.FromArgb(50, 100, 150, 200);

            Test(Color4b.FromArgb(1, 2, 3, 4), 1, 2, 3, 4);
            Test(Color4b.FromArgb(1, 2, 3), 255, 1, 2, 3);
            Test(Color4b.FromArgb(10, c), 10, 100, 150, 200);
            Test(Color4b.FromValue(0x11223344), 0x11, 0x22, 0x33, 0x44);
        }
        int GetScore(Vector2i v, Color4b color)
        {
            Color4b nAvg = scratch[GetIndex(v)];

            int dr = nAvg.r - color.r;
            int dg = nAvg.g - color.g;
            int db = nAvg.b - color.b;

            return(dr * dr + dg * dg + db * db);
        }
Exemple #27
0
        /// <summary>
        /// render colored line between point a and b (screenspace)
        /// both points have origin in topleft corner of screen
        /// </summary>
        /// <param name="view"></param>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="color"></param>
        public override void RenderLineOverlay(AABB view, Vector2i a, Vector2i b, Color4b color)
        {
            var scale = CurrentWindowSize / view.Size;

            var af = a * scale;
            var bf = b * scale;

            SDL2.SDL.SDL_SetRenderDrawColor(RendererPtr, color.R, color.G, color.B, color.A);
            SDL2.SDL.SDL_RenderDrawLine(RendererPtr,
                                        (int)af.X, (int)af.Y,
                                        (int)bf.X, (int)bf.Y);
        }
Exemple #28
0
        public static void draw_solid(Transform transform, Color4b color,
                                      Vector3 upper, Vector3 lower)
        {
            VMIN = lower;
            VMAX = upper;
            EnsureMinMax(ref VMIN, ref VMAX);

            GL.Disable(EnableCap.Blend);
            GL.Disable(EnableCap.Texture2D);
            GL.Disable(EnableCap.AlphaTest);
            GL.PushMatrix();
            transform.GL_Load();

            GL.Begin(PrimitiveType.Quads);
            color.GL_Load();

            VERTEX(XMAX | YMAX | ZMIN);             // Top-right of top face
            VERTEX(XMIN | YMAX | ZMIN);             // Top-left of top face
            VERTEX(XMIN | YMAX | ZMAX);             // Bottom-left of top face
            VERTEX(XMAX | YMAX | ZMAX);             // Bottom-right of top face

            VERTEX(XMAX | YMIN | ZMIN);             // Top-right of bottom face
            VERTEX(XMIN | YMIN | ZMIN);             // Top-left of bottom face
            VERTEX(XMIN | YMIN | ZMAX);             // Bottom-left of bottom face
            VERTEX(XMAX | YMIN | ZMAX);             // Bottom-right of bottom face

            VERTEX(XMAX | YMAX | ZMAX);             // Top-Right of front face
            VERTEX(XMIN | YMAX | ZMAX);             // Top-left of front face
            VERTEX(XMIN | YMIN | ZMAX);             // Bottom-left of front face
            VERTEX(XMAX | YMIN | ZMAX);             // Bottom-right of front face

            VERTEX(XMAX | YMIN | ZMIN);             // Bottom-Left of back face
            VERTEX(XMIN | YMIN | ZMIN);             // Bottom-Right of back face
            VERTEX(XMIN | YMAX | ZMIN);             // Top-Right of back face
            VERTEX(XMAX | YMAX | ZMIN);             // Top-Left of back face

            VERTEX(XMIN | YMAX | ZMAX);             // Top-Right of left face
            VERTEX(XMIN | YMAX | ZMIN);             // Top-Left of left face
            VERTEX(XMIN | YMIN | ZMIN);             // Bottom-Left of left face
            VERTEX(XMIN | YMIN | ZMAX);             // Bottom-Right of left face

            VERTEX(XMAX | YMAX | ZMAX);             // Top-Right of left face
            VERTEX(XMAX | YMAX | ZMIN);             // Top-Left of left face
            VERTEX(XMAX | YMIN | ZMIN);             // Bottom-Left of left face
            VERTEX(XMAX | YMIN | ZMAX);             // Bottom-Right of left face

            Color4b.White.GL_Load();
            GL.End();
            GL.PopMatrix();
            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.AlphaTest);
        }
Exemple #29
0
        public static void draw_solid(
            Transform transform,
            Color4b color,
            Model3D model,
            float border = DefaultModelBorder)
        {
            Vector3 upper = model.UpperBoundary;
            Vector3 lower = model.LowerBoundary;

            ApplyMinMaxBorder(ref lower, ref upper, border);
            draw_solid(transform, color, upper, lower);
        }
Exemple #30
0
        /// <summary>
        /// render colored line between point a and b
        /// </summary>
        /// <param name="view"></param>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="color"></param>
        public override void RenderLine(AABB view, Vector2f a, Vector2f b, Color4b color)
        {
            var scale = CurrentWindowSize / view.Size;

            // line points in screen space
            a = (a - view.Min) * scale;
            b = (b - view.Min) * scale;

            SDL2.SDL.SDL_SetRenderDrawColor(RendererPtr, color.R, color.G, color.B, color.A);
            SDL2.SDL.SDL_RenderDrawLine(RendererPtr,
                                        (int)a.X, (int)(view.Size.Y * scale.Y - a.Y),
                                        (int)b.X, (int)(view.Size.Y * scale.Y - b.Y));
        }
        void SetPixel(Vector2i v, Color4b color)
        {
            Pixels[GetIndex(v)] = color;

            AddToFront(v + new Vector2i(-1, -1));
            AddToFront(v + new Vector2i(0, -1));
            AddToFront(v + new Vector2i(1, -1));
            AddToFront(v + new Vector2i(-1, 0));
            AddToFront(v + new Vector2i(1, -0));
            AddToFront(v + new Vector2i(-1, 1));
            AddToFront(v + new Vector2i(0, 1));
            AddToFront(v + new Vector2i(1, 1));
        }
Exemple #32
0
        public Particle()
        {
            Random r = TextureBatcherTest.random;

            source   = sources[TextureBatcherTest.random.Next(sources.Length)];
            position = new Vector2(r.NextFloat(TextureBatcherTest.MaxX), r.NextFloat(TextureBatcherTest.MaxY));
            const float spd = 300;

            velocity = new Vector2(r.NextFloat(-spd, spd), r.NextFloat(-spd, spd));
            color    = r.NextColor4bFullAlpha();
            rotation = r.NextFloat(MathF.PI * 2);
            rotSpeed = r.NextFloat(-10, 10);
        }
Exemple #33
0
        /// <summary>
		/// The constructor creates a ColorInit initializer for use by 
		/// an emitter. To add a ColorInit to all particles created by an emitter, use the
		/// emitter's addInitializer method.
		/// 
		/// <p>The color of particles initialized by this public class
		/// will be a random value between the two values pased to
		/// the constructor. For a fixed value, pass the same color
		/// in for both parameters.</p>
        /// </summary>
        /// <param name="color1">the 32bit (ARGB) color at one end of the color range to use.</param>
        /// <param name="color2">the 32bit (ARGB) color at the other end of the color range to use.</param>
        public ColorInit(Color4b color1, Color4b color2)
        {
            m_min = color1;
            m_max = color2;
        }
Exemple #34
0
 public ColorChange(uint startColor, uint endColor)
 {
     m_startColor = Color4b.FromValue(startColor);
     m_endColor = Color4b.FromValue(endColor);
 }
Exemple #35
0
 public static Color ToColor(Color4b value)
 {
     return Color.FromArgb(value.A, value.R, value.G, value.B);
 }
Exemple #36
0
        /// <summary>
        /// This function is used to find a color between two other colors.
        /// </summary>
        /// <param name="color1">The first color.</param>
        /// <param name="color2">The second color.</param>
        /// <param name="ratio">The proportion of the first color to use. The rest of the color 
        /// is made from the second color.</param>
        /// <returns>The color created.</returns>
        public static Color4b InterpolateColors(Color4b color1, Color4b color2, double ratio)
        {
            double inv = 1.0 - ratio;
#if false
            int red = (int)Math.Round(color1.R * ratio + color2.R * inv);
            int green = (int)Math.Round(color1.G * ratio + color2.G * inv);
            int blue = (int)Math.Round(color1.B * ratio + color2.B * inv);
            int alpha = (int)Math.Round(color1.A * ratio + color2.A * inv);
#else
            int red = (int)(color1.R * ratio + color2.R * inv);
            int green = (int)(color1.G * ratio + color2.G * inv);
            int blue = (int)(color1.B * ratio + color2.B * inv);
            int alpha = (int)(color1.A * ratio + color2.A * inv);
#endif
            return Color4b.FromArgb(alpha, red, green, blue);
        }
Exemple #37
0
 /// <summary>
 /// The constructor creates a ColorChange action for use by 
 /// an emitter. To add a ColorChange to all particles created by an emitter, use the
 /// emitter's addAction method.
 /// 
 /// @see org.flintparticles.emitters.Emitter#addAction()
 /// </summary>
 public ColorChange(Color4b startColor, Color4b endColor)
 {
     m_startColor = startColor;
     m_endColor = endColor;
 }