Esempio n. 1
0
        private Affine2D CalcDragTranslation()
        {
            Affine2D result = dragSrcTransform;
            Vec2     newPos = new Vec2();

            if ((dragModifier & DragModifier.Shift) == DragModifier.Shift)
            {
                Vec2 norm = mouseWorldPos.GetNormal();
                if ((dragModifier & DragModifier.Ctrl) == DragModifier.Ctrl)
                {
                    norm.SnapToNormalizedAngle(12);
                }
                newPos = norm * dragSrcTransform.Translation.Length;
            }
            else
            {
                if ((dragModifier & DragModifier.Ctrl) == DragModifier.Ctrl)
                {
                    newPos = snapToGrid(mouseWorldPos);
                }
                else
                {
                    newPos = mouseWorldPos + dragHandleOffset;
                }
            }
            result.Translation = newPos;
            dragHandlePos      = result.Translation;
            return(result);
        }
Esempio n. 2
0
        //adjust the camera's rotation/scale so that screenMousePos will align with the world target
        private void CameraRotateScale(Vec2 screenMousePos, Vec2 worldTarget)
        {
            Vec2     v  = ScreenToView(screenMousePos);
            Affine2D ct = FractalManager.CameraTransform;

            //first figure out if the camera is flipped
            float k;
            float cz = ct.XAxis.X * ct.YAxis.Y - ct.XAxis.Y * ct.YAxis.X;

            if (cz > 0)
            {
                k = 1.0f;
            }
            else
            {
                k = -1.0f;
            }

            //compute the new cam matrix
            float rsq = v.X * v.X + v.Y * v.Y;
            float a   = k * (v.Y * (worldTarget.Y - ct.F) + k * v.X * (worldTarget.X - ct.C)) / rsq;
            float d   = -k * (v.Y * (worldTarget.X - ct.C) + k * v.X * (ct.F - worldTarget.Y)) / rsq;

            ct.A = a;
            ct.D = d;
            ct.B = -k * d;
            ct.E = k * a;

            FractalManager.CameraTransform = ct;
        }
Esempio n. 3
0
 public static void GLMultAffineMatrix(Affine2D a)
 {
     float[] vals = new float[] { a.XAxis.X, a.XAxis.Y, 0.0f, 0.0f,
                                  a.YAxis.X, a.YAxis.Y, 0.0f, 0.0f,
                                  0.0f, 0.0f, 1.0f, 0.0f,
                                  a.Translation.X, a.Translation.Y, 0.0f, 1.0f };
     GL.MultMatrix(vals);
 }
Esempio n. 4
0
 public static void GLLoadAffineMatrix(Affine2D a, float z)
 {
     float[] vals = new float[] { a.XAxis.X, a.XAxis.Y, 0.0f, 0.0f,
                                  a.YAxis.X, a.YAxis.Y, 0.0f, 0.0f,
                                  0.0f, 0.0f, z, 0.0f,
                                  a.Translation.X, a.Translation.Y, 0.0f, 1.0f };
     GL.LoadMatrix(vals);
 }
Esempio n. 5
0
        public static void ChangeZoom(float ammount)
        {
            Affine2D ct = FractalManager.CameraTransform;

            ct.XAxis /= ammount;
            ct.YAxis /= ammount;
            FractalManager.CameraTransform = ct;
        }
Esempio n. 6
0
 public Branch()
 {
     Transform   = new Affine2D(0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f);
     Localized   = false;
     Chroma      = new Vec2(0.5f, 0.5f);
     Weight      = 1.0f;
     ColorWeight = 0.5f;
     variations  = new List <VariEntry>();
     variations.Add(new VariEntry(0, 1.0f));
 }
Esempio n. 7
0
        //adjust the camera's position so that screenMousePos will align with the world target
        private void Pan(Vec2 screenMousePos, Vec2 worldTarget)
        {
            Vec2     viewMousePos = ScreenToView(screenMousePos);
            Affine2D ct           = FractalManager.CameraTransform;

            ct.Translation.X = worldTarget.X - ct.XAxis.X * viewMousePos.X - ct.YAxis.X * viewMousePos.Y;
            ct.Translation.Y = worldTarget.Y - ct.XAxis.Y * viewMousePos.X - ct.YAxis.Y * viewMousePos.Y;

            FractalManager.CameraTransform = ct;
        }
Esempio n. 8
0
        public RenderControl() : base()
        {
            ResizeRedraw = true;
            FractalManager.GeometryChanged += (frac) =>
            {
                UpdateTransforms();
            };

            viewTransform   = Affine2D.Identity;
            projTransform   = Affine2D.Identity;
            screenTransform = Affine2D.Identity;
        }
Esempio n. 9
0
        public KLEITexture(BinaryReader reader)
        {
            signature  = reader.ReadBytes(8);
            StructSize = reader.ReadUInt32();

            ParentSurfaceResourceIdx = reader.ReadUInt32();

            Width  = reader.ReadUInt32();
            Height = reader.ReadUInt32();

            Affine2d = new Affine2D(reader);
        }
Esempio n. 10
0
        public KLEITexture(BinaryReader reader)
        {
            signature = reader.ReadBytes(8);
            StructSize = reader.ReadUInt32();

            ParentSurfaceResourceIdx = reader.ReadUInt32();

            Width = reader.ReadUInt32();
            Height = reader.ReadUInt32();

            Affine2d = new Affine2D(reader);
        }
Esempio n. 11
0
 public Branch(Branch src)
 {
     Transform   = src.Transform;
     Localized   = src.Localized;
     Chroma      = src.Chroma;
     Weight      = src.Weight;
     ColorWeight = src.ColorWeight;
     variations  = new List <VariEntry>();
     foreach (VariEntry v in src.Variations)
     {
         variations.Add(v);
     }
 }
Esempio n. 12
0
        protected override void OnMouseDown(MouseEventArgs ea)
        {
            if (!SafeToRender)
            {
                return;
            }
            Focus();
            mouseWorldPos = WindowToWorld(ea.X, ea.Y);


            if (dragState == DragState.None)
            {
                if (EditMode && ea.Button == MouseButtons.Left)
                {
                    UpdateHover(WindowToScreen(ea.X, ea.Y));
                    FractalManager.SelectedBranch = hoverBranch;
                    if (hoverBranch != null)
                    {
                        mouseDownWorldPos = mouseWorldPos;
                        dragSrcTransform  = hoverBranch.Transform;
                        dragHandlePos     = hoverHandlePos;
                        dragHandleOffset  = dragHandlePos - mouseWorldPos;
                        dragState         = DragState.Dragging;
                        Capture           = true;
                    }
                    else
                    {
                        dragState         = DragState.Panning;
                        Capture           = true;
                        mouseDownWorldPos = mouseWorldPos;
                    }
                }
                else if (ea.Button == MouseButtons.Middle)
                {
                    dragState         = DragState.Panning;
                    Capture           = true;
                    mouseDownWorldPos = mouseWorldPos;
                }
                else if (ea.Button == MouseButtons.Right)
                {
                    if (EditMode)
                    {
                        UpdateHover(WindowToScreen(ea.X, ea.Y));
                        FractalManager.SelectedBranch = hoverBranch;
                    }
                    dragState         = DragState.RotateScale;
                    Capture           = true;
                    mouseDownWorldPos = mouseWorldPos;
                }
            }
        }
Esempio n. 13
0
        private void UpdateTransforms()
        {
            float invAspectRatio = (ClientSize.Width > 0) ? ((float)ClientSize.Height / (float)ClientSize.Width) : 0.0f;

            viewTransform = FractalManager.CameraTransform.Inverse;
            projTransform = new Affine2D(invAspectRatio, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
            float xHalf = (float)ClientSize.Width / 2.0f;
            float yHalf = (float)ClientSize.Height / 2.0f;

            screenTransform = new Affine2D(xHalf, 0.0f, 0.0f, yHalf, xHalf, yHalf);

            vpsTransform = screenTransform * projTransform * viewTransform;
            vpsInverse   = vpsTransform.Inverse;
        }
Esempio n. 14
0
        private Affine2D CalcDragYAxis()
        {
            Affine2D result = dragSrcTransform;
            Vec2     targetPos;
            Vec2     newAxis;

            if ((dragModifier & DragModifier.Shift) == DragModifier.Shift)
            {
                //if((dragModifier&DragModifier.Ctrl) == DragModifier.Ctrl)
                //	targetPos = snapToGrid(mouseWorldPos);

                Vec2 targetAxis = mouseWorldPos - dragSrcTransform.Translation;
                Vec2 norm       = targetAxis.GetNormal();

                if ((dragModifier & DragModifier.Ctrl) == DragModifier.Ctrl)
                {
                    norm.SnapToNormalizedAngle(24);
                }

                newAxis = norm * dragSrcTransform.YAxis.Length;
            }
            else
            {
                if ((dragModifier & DragModifier.Ctrl) == DragModifier.Ctrl)
                {
                    targetPos = snapToGrid(mouseWorldPos);
                }
                else
                {
                    targetPos = mouseWorldPos + dragHandleOffset;
                }

                newAxis = targetPos - dragSrcTransform.Translation;
            }

            if ((dragModifier & DragModifier.Alt) == DragModifier.Alt)
            {
                result.YAxis = newAxis;
            }
            else
            {
                result.RotateScaleYTo(newAxis);
            }

            dragHandlePos = result.Translation + result.YAxis;
            return(result);
        }
Esempio n. 15
0
 private static void readAffine2D(XmlNode node, ref Affine2D value)
 {
     foreach (XmlNode child in node.ChildNodes)
     {
         if (child.Name == "XAxis")
         {
             readVec2Elem(child, ref value.XAxis);
         }
         else if (child.Name == "YAxis")
         {
             readVec2Elem(child, ref value.YAxis);
         }
         else if (child.Name == "Translation")
         {
             readVec2Elem(child, ref value.Translation);
         }
     }
 }
Esempio n. 16
0
        public override void ApplyParameters(Fractal fractal)
        {
            if (!IsAllocated())
            {
                return;
            }

            fractal.FillNativeFractal(xRes, yRes, this.fractal, this.branches, this.variWeights);

            foreach (Iterator iter in iterators)
            {
                iter.SetFractal(this.fractal, this.branches, this.variWeights);
            }

            float invAspectRatio = (xRes > 0) ? ((float)yRes / (float)xRes) : 0.0f;

            viewTransform = FractalManager.CameraTransform.Inverse;
            projTransform = new Affine2D(invAspectRatio, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
        }
Esempio n. 17
0
        public Fractal(Fractal src)
        {
            this.Name    = src.Name;
            this.Version = src.Version;

            this.CameraTransform = src.CameraTransform;
            this.Brightness      = src.Brightness;
            this.Gamma           = src.Gamma;
            this.Vibrancy        = src.Vibrancy;
            this.BackgroundColor = src.BackgroundColor;

            this.Branches = new List <Branch>();
            foreach (Branch branch in src.Branches)
            {
                Branches.Add(new Branch(branch));
            }

            this.palette     = src.Palette;
            this.OriginalXml = src.OriginalXml;
        }
Esempio n. 18
0
 public Fractal()
 {
     CameraTransform = new Affine2D(2.0f, 0.0f, 0.0f, 2.0f, 0.0f, 0.0f);
     Branches        = new List <Branch>();
 }
Esempio n. 19
0
 public static void GLLoadAffineMatrix(Affine2D a)
 {
     GLLoadAffineMatrix(a, 1.0f);
 }
Esempio n. 20
0
        public override void ApplyParameters(Fractal fractal)
        {
            context.Synchronize();
            mainStream.Synchronize();

            float    invAspectRatio = (XRes > 0) ? ((float)YRes / (float)XRes) : 0.0f;
            Affine2D viewTransform  = fractal.CameraTransform.Inverse;
            Affine2D projTransform  = new Affine2D(invAspectRatio, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
            float    xHalf          = (float)XRes / 2.0f;
            float    yHalf          = (float)YRes / 2.0f;

            Affine2D screenTransform = new Affine2D(xHalf, 0.0f, 0.0f, yHalf, xHalf, yHalf);

            vpsTransform = screenTransform * projTransform * viewTransform;
            module.WriteConstant("vpsTransform", vpsTransform);

            module.WriteConstant("brightness", fractal.Brightness);

            float invGamma = 1.0f / fractal.Gamma;

            module.WriteConstant("invGamma", invGamma);

            module.WriteConstant("vibrancy", fractal.Vibrancy);

            module.WriteConstant("bgColor", fractal.BackgroundColor);

            Int32 branchCount = Math.Min(MaxBranches, fractal.Branches.Count);

            module.WriteConstant("branchCount", branchCount);

            Affine2D[] branchPreTransforms  = new Affine2D[MaxBranches];
            Affine2D[] branchPostTransforms = new Affine2D[MaxBranches];

            float[] branchLumas   = new float[MaxBranches];
            Vec2[]  branchChromas = new Vec2[MaxBranches];

            float[]  branchFactors     = new float[MaxBranches * MaxFactors];
            UInt32[] branchNormWeights = new UInt32[MaxBranches];
            branchNormWeights.AssignAll((i) => (UInt32)0x00010000);

            float branchWeightSum = 0.0f;

            for (int bi = 0; bi < branchCount; bi++)
            {
                branchWeightSum += fractal.Branches[bi].Weight;
            }

            float[] branchColorWeights = new float[MaxBranches];

            UInt32 runningSum = 0;

            for (int bi = 0; bi < branchCount; bi++)
            {
                Branch branch = fractal.Branches[bi];

                branchPreTransforms[bi]  = branch.PreTransform;
                branchPostTransforms[bi] = branch.PostTransform;

                branchLumas[bi]   = branch.Luma;
                branchChromas[bi] = branch.Chroma;

                runningSum += (UInt32)(branch.Weight / branchWeightSum * 65536.0f);
                if (bi < branchCount - 1)
                {
                    branchNormWeights[bi] = runningSum;
                }
                else
                {
                    branchNormWeights[bi] = 0x00010000;
                }

                branchColorWeights[bi] = branch.ColorWeight;

                foreach (Branch.VariEntry ve in branch.Variations)
                {
                    if (ve.Index >= 0 && ve.Index < MaxFactors)
                    {
                        branchFactors[MaxFactors * bi + ve.Index] += ve.Weight;
                    }
                }
            }

            module.WriteConstant("branchPreTransforms", branchPreTransforms);
            module.WriteConstant("branchPostTransforms", branchPostTransforms);
            module.WriteConstant("branchLumas", branchLumas);
            module.WriteConstant("branchChromas", branchChromas);
            module.WriteConstant("branchNormWeights", branchNormWeights);
            module.WriteConstant("branchColorWeights", branchColorWeights);
            module.WriteConstant("branchFactors", branchFactors);

            context.Synchronize();
        }
Esempio n. 21
0
        unsafe public void FillNativeFractal(int xRes, int yRes, NativeFractal *nFractal, NativeBranch *nBranches, float *nVariWeights)
        {
            Int32 branchCount = Math.Min(NativeFractal.MaxBranches, this.Branches.Count);

            nFractal->BranchCount = (uint)branchCount;

            float    invAspectRatio = (xRes > 0) ? ((float)yRes / (float)xRes) : 0.0f;
            Affine2D viewTransform  = this.CameraTransform.Inverse;
            Affine2D projTransform  = new Affine2D(invAspectRatio, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
            float    xHalf          = (float)xRes / 2.0f;
            float    yHalf          = (float)yRes / 2.0f;

            Affine2D screenTransform = new Affine2D(xHalf, 0.0f, 0.0f, yHalf, xHalf, yHalf);

            nFractal->VpsTransform = screenTransform * projTransform * viewTransform;
            nFractal->Brightness   = this.Brightness;
            nFractal->InvGamma     = 1.0f / this.Gamma;
            nFractal->Vibrancy     = this.Vibrancy;
            nFractal->BgColor      = this.BackgroundColor;

            for (int bi = 0; bi < branchCount; bi++)
            {
                nBranches[bi].NormWeight = (UInt32)0x00010000;
            }

            float branchWeightSum = 0.0f;

            for (int bi = 0; bi < branchCount; bi++)
            {
                branchWeightSum += this.Branches[bi].Weight;
            }

            for (int i = 0; i < NativeFractal.MaxBranches * NativeFractal.MaxVariations; i++)
            {
                nVariWeights[i] = 0.0f;
            }

            UInt32 runningSum = 0;

            for (int bi = 0; bi < branchCount; bi++)
            {
                Branch branch = this.Branches[bi];

                runningSum += (UInt32)(branch.Weight / branchWeightSum * 65536.0f);
                if (bi < branchCount - 1)
                {
                    nBranches[bi].NormWeight = runningSum;
                }
                else
                {
                    nBranches[bi].NormWeight = 0x00010000;
                }

                nBranches[bi].ColorWeight   = branch.ColorWeight;
                nBranches[bi].Chroma        = branch.Chroma;
                nBranches[bi].PreTransform  = branch.PreTransform;
                nBranches[bi].PostTransform = branch.PostTransform;

                foreach (Branch.VariEntry ve in branch.Variations)
                {
                    if (ve.Index >= 0 && ve.Index < NativeFractal.MaxVariations)
                    {
                        nVariWeights[bi * NativeFractal.MaxVariations + ve.Index] += ve.Weight;
                    }
                }
            }
        }
Esempio n. 22
0
        private static Branch readBranchNode(XmlNode node)
        {
            Branch branch = new Branch();

            branch.Variations.Clear();

            Affine2D pre            = Affine2D.Identity;
            Affine2D post           = Affine2D.Identity;
            bool     foundPost      = false;
            bool     foundLocalized = false;

            foreach (XmlAttribute attr in node.Attributes)
            {
                if (attr.Name == "weight")
                {
                    readFloatAttr(attr, ref branch.Weight);
                }
                else if (attr.Name == "coefs")
                {
                    try{
                        string[] coefArr = attr.Value.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
                        pre.XAxis.X       = float.Parse(coefArr[0]);
                        pre.XAxis.Y       = float.Parse(coefArr[1]);
                        pre.YAxis.X       = float.Parse(coefArr[2]);
                        pre.YAxis.Y       = float.Parse(coefArr[3]);
                        pre.Translation.X = float.Parse(coefArr[4]);
                        pre.Translation.Y = float.Parse(coefArr[5]);
                    }
                    catch (Exception) {
                        pre = Affine2D.Identity;
                    }
                }
                else if (attr.Name == "post")
                {
                    try{
                        string[] coefArr = attr.Value.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
                        post.XAxis.X       = float.Parse(coefArr[0]);
                        post.XAxis.Y       = float.Parse(coefArr[1]);
                        post.YAxis.X       = float.Parse(coefArr[2]);
                        post.YAxis.Y       = float.Parse(coefArr[3]);
                        post.Translation.X = float.Parse(coefArr[4]);
                        post.Translation.Y = float.Parse(coefArr[5]);
                        foundPost          = true;
                    }
                    catch (Exception) {
                        post = Affine2D.Identity;
                    }
                }
                else if (attr.Name == "vars")              //found old style variations
                {
                    try{
                        string[] varArr = attr.Value.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < varArr.Length && i < 14; i++)
                        {
                            float weight = float.Parse(varArr[i]);
                            if (weight != 0.0f)
                            {
                                branch.Variations.Add(new Branch.VariEntry(i, weight));
                            }
                        }
                    }
                    catch (Exception) {
                    }
                }
                else if (attr.Name == "color")
                {
                    try{
                        string[] colorStr = node.Attributes["color"].Value.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
                        if (colorStr.Length >= 1)
                        {
                            branch.Chroma.X = float.Parse(colorStr[0]);
                        }
                        if (colorStr.Length >= 2)
                        {
                            branch.Chroma.Y = float.Parse(colorStr[1]);
                        }
                    }catch (Exception) {}
                }
                else if (attr.Name == "f9k_color2")
                {
                    readFloatAttr(attr, ref branch.Chroma.Y);
                }
                else if (attr.Name == "f9k_colorweight")
                {
                    readFloatAttr(attr, ref branch.ColorWeight);
                }
                else if (attr.Name == "f9k_localized")
                {
                    int iLocalized = 0;
                    readIntAttr(attr, ref iLocalized);
                    foundLocalized = (iLocalized == 1);
                }
                else
                {
                    //see if the attribute is a known variation name
                    int idx = -1;
                    for (int i = 0; i < Variation.Count; i++)
                    {
                        if (Variation.Variations[i].AttrName == attr.Name)
                        {
                            idx = i;
                        }
                    }

                    //yep, its a known variation
                    if (idx >= 0 && idx < Variation.Count)
                    {
                        float weight = 0;
                        readFloatAttr(attr, ref weight);
                        branch.Variations.Add(new Branch.VariEntry(idx, weight));
                    }
                }
            }

            //figure out whether or not to treat this as a localized branch
            if (foundLocalized)
            {               //the branch is tagged as localized, so this is easy
                branch.Localized = true;
                branch.Transform = pre;
            }
            else if (foundPost)
            {
                Affine2D postInv = post.Inverse;
                if (pre.Equals(postInv, 0.001f))
                {                   //The post transform is roughly the inverse of the pre, so this is probably supposed to be localized
                    branch.Localized = true;
                    branch.Transform = post;
                }
                else
                {                   //The post isn't the inverse of the pre. Discard the post since the current UI can't deal with it.
                    branch.Localized = false;
                    branch.Transform = pre;
                }
            }
            else
            {               //just a plain old non-localized branch.
                branch.Localized = false;
                branch.Transform = pre;
            }

            //if no variations at all could be found, assume linear
            if (branch.Variations.Count == 0)
            {
                branch.Variations.Add(new Branch.VariEntry(0, 1.0f));
            }

            return(branch);
        }