Exemple #1
0
    void CreateBits(CreationType ct, int density)
    {
        Transform container = new GameObject(gameObject.name + " container").transform;

        int bits = density;//qty;

        foreach (StickJoint limb in limbs)
        {
            bool terminating = limb.linked == null;

            for (int i = 0; i < bits; i++)
            {
                float point = (float)i / (float)bits;

                StickJoint linked = limb.linked;
                if (linked == null)
                {
                    linked = limb;
                }
                Floater fl = ct.MakeBit(limb, linked, point);//new Floater(limb, limb.linked ?? limb, newFloater.transform, point);
                limb.floaters.Add(fl);
                fl.floater.transform.SetParent(container);
                fl.floater.gameObject.layer = 2;

                if (terminating)
                {
                    i = bits;
                }
            }
        }
    }
Exemple #2
0
        public static void AssignGlid(StickJoint joint, int i)
        {
            BitmapData raw;
            try
            {
                raw = joint.bitmaps[i].LockBits(new Rectangle(0, 0, joint.bitmaps[i].Width, joint.bitmaps[i].Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            }
            catch(Exception e)
            {
                Console.WriteLine("Adding texture ID Failed! Reason: " + e.Message);
                return;
            }

            joint.textureIDs.Add(GL.GenTexture());
            //Console.WriteLine("Texture ID Added");

            GL.BindTexture(TextureTarget.Texture2D, joint.textureIDs[i]);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, raw.Width, raw.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, raw.Scan0);

            joint.bitmaps[i].UnlockBits(raw);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
        }
Exemple #3
0
    public override void UpdatePosition(StickJoint limb, List <Floater> floaters, float globalScale)
    {
        foreach (Floater fl in floaters)
        {
            if (fl.floater != null)
            {
                Vector3 heading         = fl.start.transform.position - fl.end.transform.position;
                Vector3 desiredPosition = fl.start.transform.position - heading * fl.point;

                Vector3 slerped = Vector3.Slerp(fl.floater.transform.position, desiredPosition + (fl.randomOffset * (noise + 0.01f)), (heading.magnitude * power));
                fl.floater.transform.localScale = Vector3.one * globalScale;
                //                   Debug.Log(heading + " " + desiredPosition + " " + slerped);
                if (!float.IsNaN(slerped.x))
                {
                    if (fl.rb != null)
                    {
                        fl.rb.MovePosition(slerped);
                    }
                    else
                    {
                        fl.floater.position = slerped;
                    }
                }
                fl.floater.rotation = Quaternion.Lerp(fl.floater.rotation, limb.transform.rotation, .66f);
            }
        }
    }
Exemple #4
0
        private static void writeJoint(List<StickJoint> jnts, List<StickJoint> olds, int p, int[] positions)
        {
            if (positions[p] != -1 && jnts[positions[p]] == null)
                writeJoint(jnts, olds, positions[p], positions);

            if (jnts[p] != null && jnts[p].location == olds[p].location)
                return;

            jnts[p] = new StickJoint(olds[p], positions[p] != -1 ? jnts[positions[p]] : null);
        }
Exemple #5
0
        public static Point calcFigureDiff(Point a, StickJoint b)
        {
            int x1 = a.X;
            int y1 = a.Y;

            int x2 = b.location.X;
            int y2 = b.location.Y;

            return new Point(x2 - x1, y2 - y1);
        }
Exemple #6
0
    public Floater(StickJoint start, StickJoint end, Transform floater, float point)
    {
        this.start = start;
        this.end   = end;

        this.floater      = floater;
        this.col          = floater.GetComponent <Collider>();
        this.randomOffset = Random.insideUnitSphere;
        this.point        = Mathf.Clamp(point, 0, 1);
        this.rb           = floater.GetComponent <Rigidbody>();
    }
    public override Floater MakeBit(StickJoint limb, StickJoint linked, float point)
    {
        Floater fl = new Floater(limb, linked, Instantiate(prefab).transform, point);

        Vector3 heading = fl.start.transform.position - fl.end.transform.position;

        fl.floater.transform.position = fl.start.transform.position - heading * fl.point;


        return(fl);
    }
Exemple #8
0
 public void FindLink()
 {
     if (linked == null)
     {
         if (transform.parent.GetComponent <StickJoint>() != null)
         {
             linked = transform.parent.GetComponent <StickJoint>();
         }
         else if (transform.parent.GetComponentInParent <StickJoint>() != null)
         {
             linked = transform.parent.GetComponentInParent <StickJoint>();
         }
     }
 }
Exemple #9
0
    public override void UpdatePosition(StickJoint limb, List <Floater> floaters, float globalScale)
    {
        foreach (Floater fl in floaters)
        {
            if (fl.floater != null)
            {
                Vector3 heading         = fl.start.transform.position - fl.end.transform.position;
                Vector3 desiredPosition = fl.start.transform.position - heading * fl.point;
                fl.floater.transform.localScale = Vector3.one * globalScale;



                fl.floater.RotateAround(desiredPosition, orbitAxis, orbitRotationSpeed * Time.deltaTime);
                Vector3 orbitDesiredPosition = (fl.floater.position - desiredPosition).normalized * orbitRadius + desiredPosition;
                fl.floater.position = Vector3.Slerp(fl.floater.position, orbitDesiredPosition, Time.deltaTime * orbitRadiusCorrectionSpeed);
            }
        }
    }
Exemple #10
0
    public override Floater MakeBit(StickJoint limb, StickJoint linked, float point)
    {
        //Queue<Transform> existing = new Queue<Transform>(GameObject.FindObjectsOfType<Transform>().Where(o => o.gameObject.layer == 8));
        //GameObject sort = new GameObject();
        //foreach (Transform t in existing)
        // {
        //  t.SetParent(sort.transform);
        //}
        GameObject newFloater = new GameObject("Scaler");
        GameObject child      = GameObject.FindObjectsOfType <Transform>().FirstOrDefault(o => o.gameObject.layer == collectFromLayer && o.transform.childCount == 0)?.gameObject; //existing.Dequeue().gameObject;

        if (child != null)
        {
            newFloater.transform.position = child.transform.position;
            child.layer = 0;
            child.transform.SetParent(newFloater.transform);
        }



        return(new Floater(limb, linked, newFloater.transform, point));
    }
    public Vector3 scale = Vector3.one * .3f;//new Vector3(.05f, .05f, .05f);
    public override Floater MakeBit(StickJoint limb, StickJoint linked, float point)
    {
        GameObject child = GameObject.CreatePrimitive(primitive);

        child.transform.localScale = scale;

        if (material != null)
        {
            child.GetComponent <MeshRenderer>().sharedMaterial = material;
        }
        GameObject newFloater = new GameObject("Scaler");

        newFloater.transform.position = child.transform.position;
        child.transform.SetParent(newFloater.transform);

        Floater fl = new Floater(limb, linked, newFloater.transform, point);

        Vector3 heading = fl.start.transform.position - fl.end.transform.position;

        fl.floater.transform.position = fl.start.transform.position - heading * fl.point;


        return(fl);
    }
Exemple #12
0
    public override void UpdatePosition(StickJoint limb, List <Floater> floaters, float globalScale)
    {
        foreach (Floater fl in floaters)
        {
            if (fl.floater != null)
            {
                Vector3 heading         = fl.start.transform.position - fl.end.transform.position;
                Vector3 desiredPosition = fl.start.transform.position - heading * fl.point;

                fl.floater.transform.localScale = Vector3.one * globalScale;

                if (fl.rb != null)
                {
                    fl.rb.MovePosition(desiredPosition);
                }
                else
                {
                    fl.floater.position = desiredPosition;
                }

                fl.floater.rotation = limb.transform.rotation;
            }
        }
    }
Exemple #13
0
 public static int compareDrawOrder(StickJoint x, StickJoint y)
 {
     return x.drawOrder - y.drawOrder;
 }
Exemple #14
0
        private static void writeBitmapBlock(int id, StickJoint j, BinaryWriter bin)
        {
            Stream bitmapStream = new MemoryStream();

            j.bitmaps[id].Save(bitmapStream, System.Drawing.Imaging.ImageFormat.Png);

            bin.Write(id);
            bin.Write(j.Bitmap_names[id]);
            bin.Write(j.Bitmap_Rotations[id]);

            bin.Write(j.Bitmap_Offsets[id].X);
            bin.Write(j.Bitmap_Offsets[id].Y);

            bin.Write(bitmapStream.Length);
            j.bitmaps[id].Save(bin.BaseStream, System.Drawing.Imaging.ImageFormat.Png);
        }
Exemple #15
0
 public override void UpdatePosition(StickJoint limb, List <Floater> floaters, float globalScale)
 {
     //nothing
 }
Exemple #16
0
 public abstract Floater MakeBit(StickJoint limb, StickJoint linked, float point);
 public abstract void UpdatePosition(StickJoint limb, List <Floater> floaters, float globalScale);
Exemple #18
0
        private static void writeBitmapBlock(int id, StickJoint j, List<byte> bin)
        {
            Stream bitmapStream = new MemoryStream();

            j.bitmaps[id].Save(bitmapStream, System.Drawing.Imaging.ImageFormat.Png);

            bin.AddRange(BitConverter.GetBytes(id));
            bin.AddRange(BitConverter.GetBytes(Functions.GetByteCount(j.Bitmap_names[id])));
            bin.AddRange(Functions.GetBytes(j.Bitmap_names[id]));
            bin.AddRange(BitConverter.GetBytes(j.Bitmap_Rotations[id]));

            bin.AddRange(BitConverter.GetBytes(j.Bitmap_Offsets[id].X));
            bin.AddRange(BitConverter.GetBytes(j.Bitmap_Offsets[id].Y));

            bin.AddRange(BitConverter.GetBytes(bitmapStream.Length));

            ImageConverter converter = new ImageConverter();
            bin.AddRange((byte[])converter.ConvertTo(j.bitmaps[id], typeof(byte[])));
        }
Exemple #19
0
        public void ApplyTo(StickJoint j)
        {
            j.bitmaps.Add((Bitmap)bitmap);
            j.Bitmap_names.Add(name);
            j.Bitmap_Offsets.Add(new Point(OffsetX, OffsetY));
            j.Bitmap_Rotations.Add(Rotation);

            Functions.AssignGlid(j, j.bitmaps.IndexOf((Bitmap)bitmap));
        }
Exemple #20
0
        public PolyFrame(int po, bool z, int jointCount)
        {
            type = 6; pos = po;

            double max = 2 * Math.PI;
            double delta = 2 * Math.PI / jointCount;

            //Add all the stick joints to the figure.
            for (double i = 0.0f;i < max;i += delta)
            {
                double x = Math.Sin(i) * 50;
                double y = Math.Cos(i) * 50;

                StickJoint t = new StickJoint("Poly Joint", new Point((int)x, (int)y), 1, Color.Black, Color.Red);
                Joints.Add(t);

                //if (Joints.Count > 1)
                //	t.parent = Joints[Joints.IndexOf(t) - 1];
            }

            //Position them correctly
            Point oldLoc = Joints[0].location;
            Joints[0].location = new Point(222, 195);
            for (int i = 1;i < Joints.Count;i++)
                Joints[i].location = new Point(Joints[0].location.X + Functions.calcFigureDiff(oldLoc, Joints[i]).X, Joints[0].location.Y + Functions.calcFigureDiff(oldLoc, Joints[i]).Y);
        }
Exemple #21
0
        private static void writeJointBlock(BinaryWriter bin, StickCustom figure, StickJoint j)
        {
            bin.Write(j.location.X);
            bin.Write(j.location.Y);

            bin.Write(j.color.ToArgb());
            bin.Write(j.handleColor.ToArgb());
            bin.Write(j.defaultHandleColor.ToArgb());
            bin.Write(j.thickness);
            bin.Write(j.drawState);
            bin.Write(j.drawOrder);
            bin.Write(j.visible);
            bin.Write(j.handleDrawn);

            bin.Write(j.Bitmap_CurrentID);
            bin.Write(j.Bitmap_IDs.Count);
            for (int i = 0;i < j.Bitmap_IDs.Count;i++)
                bin.Write(j.Bitmap_IDs[i]);

            if (!(j.parent == null))
                bin.Write(figure.Joints.IndexOf(j.parent));
            else
                bin.Write(-1);
        }
Exemple #22
0
        public static void AddToList(List<StickJoint> z, LegacyJoint j, LegacyJoint parent = null)
        {
            //foreach(LegacyJoint x in j.children)
            //	recursiveAdd(z, x);
            StickJoint sJoint;
            StickJoint sParent = null;
            if (parent != null)
                sParent = new StickJoint(parent);

            sJoint = new StickJoint(j);
            sJoint.parent = sParent;

            if (!z.Contains(sJoint))
                z.Add(sJoint);
            if (sParent != null)
                z.Add(sParent);
        }
Exemple #23
0
        public static void AddToList(List<StickJoint> z, List<LegacyJoint> j, StickJoint parent = null)
        {
            foreach (LegacyJoint x in j)
            {
                StickJoint sj = new StickJoint(x);

                if (parent != null)
                    sj.parent = parent;
                z.Add(sj);
                AddToList(sj.children, x.children, sj);
            }
        }
Exemple #24
0
        private static void writeJointBlock(List<byte> bin, StickCustom figure, StickJoint j)
        {
            bin.AddRange(BitConverter.GetBytes(j.location.X));
            bin.AddRange(BitConverter.GetBytes(j.location.Y));

            bin.AddRange(BitConverter.GetBytes(j.color.ToArgb()));
            bin.AddRange(BitConverter.GetBytes(j.handleColor.ToArgb()));
            bin.AddRange(BitConverter.GetBytes(j.defaultHandleColor.ToArgb()));
            bin.AddRange(BitConverter.GetBytes(j.thickness));
            bin.AddRange(BitConverter.GetBytes(j.drawState));
            bin.AddRange(BitConverter.GetBytes(j.drawOrder));
            bin.AddRange(BitConverter.GetBytes(j.visible));
            bin.AddRange(BitConverter.GetBytes(j.handleDrawn));

            bin.AddRange((BitConverter.GetBytes(j.Bitmap_CurrentID)));
            bin.AddRange((BitConverter.GetBytes(j.Bitmap_IDs.Count)));
            for (int i = 0;i < j.Bitmap_IDs.Count;i++)
                bin.AddRange((BitConverter.GetBytes(j.Bitmap_IDs[i])));

            if (!(j.parent == null))
                bin.AddRange((BitConverter.GetBytes(figure.Joints.IndexOf(j.parent))));
            else
                bin.AddRange(BitConverter.GetBytes(-1));
        }
Exemple #25
0
        //Debug stuff, and selection of joints. This also causes the canvas to be redrawn on mouse move.
        /// <summary>
        /// Handles the MouseDown event of the Canvas control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>y
        /// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
        private void Canvas_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //If the user isn't holding down the 'ctrl' key..
                if (!(ModifierKeys == Keys.Control))
                {
                    //This prevents a null reference exception when a user left clicks
                    //without an activeFigure being set yet.
                    if (activeFigure == null)
                        return;

                    StickJoint f;

                    //Selects the point at the location that the user clicked, with a
                    //tolerance of about 4 pixels.
                    f = activeFigure.selectPoint(new Point(e.X, e.Y), 6);

                    //if(!hasLockedJoint)
                    //	activeFigure.setAsBase(activeFigure.Joints[(activeFigure.Joints.IndexOf(f) + 1) % activeFigure.Joints.Count]);

                    //Sets the selectedJoint variable to the joint that we just selected.
                    selectedJoint = f;
                    Program.ToolboxForm.updateBitmapList();

                    //This sets the labels in the debug menu.
                    if (selectedJoint != null)
                    {
                        Program.ToolboxForm.lbl_selectedJoint.Text = "Selected Joint: " + f.name;
                        Program.ToolboxForm.lbl_jointLength.Text = "Joint Length: " + f.CalcLength(null).ToString();
                        Program.ToolboxForm.lbl_dbgAngleToParent.Text = "AngleToParent: " + f.AngleToParent;
                    }

                    //This tells the form that the mouse button is being held down, and
                    //that we should redraw the form when it's moved.
                    draw = true;
                }
                else if (ModifierKeys == Keys.Control)
                {
                    try
                    {
                        StickJoint f = null;
                        if (activeFigure != null)
                        {
                            f = activeFigure.selectPoint(new Point(e.X, e.Y), 6);
                            f.state = (f.state == 1) ? f.state = 0 : f.state = 1;
                            hasLockedJoint = !hasLockedJoint;
                            GL_GRAPHICS.Invalidate();
                            selectedJoint = f;
                            Program.ToolboxForm.updateBitmapList();
                            activeFigure.setAsBase(f);
                        }
                    }
                    catch
                    {
                        return;
                    }
                }
            }
            if (e.Button == MouseButtons.Right)
            {
                if (activeFigure == null)
                    return;

                ox = e.X;
                oy = e.Y;
                fx = new List<int>();
                fy = new List<int>();

                for (int i = 0;i < activeFigure.Joints.Count;i++)
                {
                    fx.Add(activeFigure.Joints[i].location.X);
                    fy.Add(activeFigure.Joints[i].location.Y);
                }

                draw = true;
            }
        }
Exemple #26
0
        private static void writePositionsBlock(StickJoint[] j, Stream stream)
        {
            List<byte> bytes = new List<byte>();

            bytes.AddRange(BitConverter.GetBytes((ushort)5));

            bytes.AddRange(BitConverter.GetBytes((ushort)j.Length));

            //This'll get updated to support custom stick figures later.
            foreach (StickJoint s in j)
            {
                bytes.AddRange(BitConverter.GetBytes((short)s.location.X));
                bytes.AddRange(BitConverter.GetBytes((short)s.location.Y));
                bytes.AddRange(BitConverter.GetBytes((short)s.thickness));
                bytes.AddRange(BitConverter.GetBytes((short)s.length));
            }

            bytes.InsertRange(0, BitConverter.GetBytes(bytes.Count));

            stream.Write(bytes.ToArray(), 0, bytes.Count);
        }