Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cam"></param>
        /// <param name="windowWidth"></param>
        /// <param name="windowHeight"></param>
        public void Draw(Camera cam, int windowWidth, int windowHeight)
        {
            // store previous hitbox state info
            Dictionary <int, Vector3> previousPosition = CalculatePreviousState();

            // reset model parts
            if (ModelPartsIndices != null)
            {
                for (int i = 0; i < ModelPartsIndices.Length; i++)
                {
                    ModelPartsIndices[i].AnimIndex = -1;
                }
            }

            // process ftcmd
            SubactionProcess.SetFrame(viewport.Frame);

            // update display info
            JointManager.DOBJManager.OverlayColor = SubactionProcess.OverlayColor;
            JointManager._settings.RenderBones    = bonesToolStripMenuItem.Checked;

            // apply model animations
            JointManager.Frame = viewport.Frame;
            JointManager.UpdateNoRender();

            // character invisibility
            if (!SubactionProcess.CharacterInvisibility && modelToolStripMenuItem.Checked)
            {
                JointManager.Render(cam, false);
            }

            // hurtbox collision
            if (hurtboxesToolStripMenuItem.Checked)
            {
                HurtboxRenderer.Render(JointManager, Hurtboxes, null, SubactionProcess.BoneCollisionStates, SubactionProcess.BodyCollisionState);
            }

            // hitbox collision
            foreach (var hb in SubactionProcess.Hitboxes)
            {
                var boneID = hb.BoneID;
                if (boneID == 0)
                {
                    if (JointManager.GetJOBJ(1).Child == null) // special case for character like mewtwo with a leading bone
                    {
                        boneID = 2;
                    }
                    else
                    {
                        boneID = 1;
                    }
                }

                var transform = Matrix4.CreateTranslation(hb.Point1) * JointManager.GetWorldTransform(boneID);

                transform = transform.ClearScale();

                float   alpha   = 0.4f;
                Vector3 hbColor = HitboxColor;

                if (hb.Element == 8)
                {
                    hbColor = GrabboxColor;
                }

                // drawing a capsule takes more processing power, so only draw it if necessary
                if (interpolationToolStripMenuItem.Checked && previousPosition != null && previousPosition.ContainsKey(hb.ID))
                {
                    var pos = Vector3.TransformPosition(Vector3.Zero, transform);
                    var cap = new Capsule(pos, previousPosition[hb.ID], hb.Size);
                    cap.Draw(Matrix4.Identity, new Vector4(hbColor, alpha));
                }
                else
                {
                    DrawShape.DrawSphere(transform, hb.Size, 16, 16, hbColor, alpha);
                }

                // draw hitbox angle
                if (hitboxInfoToolStripMenuItem.Checked)
                {
                    if (hb.Angle != 361)
                    {
                        DrawShape.DrawAngleLine(cam, transform, hb.Size, MathHelper.DegreesToRadians(hb.Angle));
                    }
                    else
                    {
                        DrawShape.DrawSakuraiAngle(cam, transform, hb.Size);
                    }
                    GLTextRenderer.RenderText(cam, hb.ID.ToString(), transform, StringAlignment.Center, true);
                }
            }

            // environment collision
            if (ECB != null)
            {
                var topN = JointManager.GetWorldTransform(1).ExtractTranslation();

                var bone1 = Vector3.TransformPosition(Vector3.Zero, JointManager.GetWorldTransform(ECB.ECBBone1));
                var bone2 = Vector3.TransformPosition(Vector3.Zero, JointManager.GetWorldTransform(ECB.ECBBone2));
                var bone3 = Vector3.TransformPosition(Vector3.Zero, JointManager.GetWorldTransform(ECB.ECBBone3));
                var bone4 = Vector3.TransformPosition(Vector3.Zero, JointManager.GetWorldTransform(ECB.ECBBone4));
                var bone5 = Vector3.TransformPosition(Vector3.Zero, JointManager.GetWorldTransform(ECB.ECBBone5));
                var bone6 = Vector3.TransformPosition(Vector3.Zero, JointManager.GetWorldTransform(ECB.ECBBone6));

                var minx = float.MaxValue;
                var miny = float.MaxValue;
                var maxx = float.MinValue;
                var maxy = float.MinValue;

                foreach (var p in new Vector3[] { bone1, bone2, bone3, bone4, bone5, bone6 })
                {
                    minx = Math.Min(minx, p.Z);
                    maxx = Math.Max(maxx, p.Z);
                    miny = Math.Min(miny, p.Y);
                    maxy = Math.Max(maxy, p.Y);
                }

                // ecb diamond
                if (eCBToolStripMenuItem.Checked)
                {
                    DrawShape.DrawECB(topN, minx, miny, maxx, maxy, groundECH.Checked);
                }

                // ledge grav
                if (ledgeGrabBoxToolStripMenuItem.Checked)
                {
                    var correct = Math.Abs(minx - maxx) / 2;

                    //behind
                    DrawShape.DrawLedgeBox(
                        topN.Z,
                        topN.Y + ECB.VerticalOffsetFromTop - ECB.VerticalScale / 2,
                        topN.Z - (correct + ECB.HorizontalScale),
                        topN.Y + ECB.VerticalOffsetFromTop + ECB.VerticalScale / 2,
                        Color.Red);

                    // in front
                    DrawShape.DrawLedgeBox(
                        topN.Z,
                        topN.Y + ECB.VerticalOffsetFromTop - ECB.VerticalScale / 2,
                        topN.Z + correct + ECB.HorizontalScale,
                        topN.Y + ECB.VerticalOffsetFromTop + ECB.VerticalScale / 2,
                        Color.Blue);
                }
            }

            // throw dummy
            if (throwModelToolStripMenuItem.Checked && !SubactionProcess.ThrownFighter && ThrowDummyManager.JointCount > 0)
            {
                if (viewport.Frame < ThrowDummyManager.Animation.FrameCount)
                {
                    ThrowDummyManager.Frame = viewport.Frame;
                }
                ThrowDummyManager.SetWorldTransform(4, JointManager.GetWorldTransform(JointManager.JointCount - 2));
                ThrowDummyManager.Render(cam, false);

                DrawShape.DrawSphere(ThrowDummyManager.GetWorldTransform(35), 1.5f, 16, 16, ThrowDummyColor, 0.5f);
                DrawShape.DrawSphere(ThrowDummyManager.GetWorldTransform(4), 1.5f, 16, 16, ThrowDummyColor, 0.5f);
                DrawShape.DrawSphere(ThrowDummyManager.GetWorldTransform(10), 1f, 16, 16, ThrowDummyColor, 0.5f);
                DrawShape.DrawSphere(ThrowDummyManager.GetWorldTransform(15), 1f, 16, 16, ThrowDummyColor, 0.5f);
                DrawShape.DrawSphere(ThrowDummyManager.GetWorldTransform(22), 1f, 16, 16, ThrowDummyColor, 0.5f);
                DrawShape.DrawSphere(ThrowDummyManager.GetWorldTransform(40), 1f, 16, 16, ThrowDummyColor, 0.5f);
            }

            // sword trail
            //AfterImageRenderer.RenderAfterImage(JointManager, viewport.Frame, after_desc);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cam"></param>
        /// <param name="windowWidth"></param>
        /// <param name="windowHeight"></param>
        public void Draw(Camera cam, int windowWidth, int windowHeight)
        {
            // if model not loaded do nothing
            if (JointManager == null)
            {
                return;
            }

            // store previous hitbox state info
            CalculatePreviousState();

            // reset model parts
            if (ModelPartsIndices != null)
            {
                for (int i = 0; i < ModelPartsIndices.Length; i++)
                {
                    ModelPartsIndices[i].AnimIndex = -1;
                }
            }

            // process ftcmd
            SubactionProcess.SetFrame(viewport.Frame);

            // update display info
            JointManager.DOBJManager.OverlayColor = SubactionProcess.OverlayColor;
            JointManager._settings.RenderBones    = bonesToolStripMenuItem.Checked;

            // apply model animations
            JointManager.Frame = viewport.Frame;
            JointManager.UpdateNoRender();

            // character invisibility
            if (!SubactionProcess.CharacterInvisibility && modelToolStripMenuItem.Checked)
            {
                JointManager.Render(cam, false);
            }

            // hurtbox collision
            if (hurtboxesToolStripMenuItem.Checked)
            {
                HurtboxRenderer.Render(JointManager, Hurtboxes, null, SubactionProcess.BoneCollisionStates, SubactionProcess.BodyCollisionState);
            }

            // hitbox collision
            int  hitboxId         = 0;
            bool isHitboxSelected = false;

            foreach (var hb in SubactionProcess.Hitboxes)
            {
                if (!hb.Active)
                {
                    hitboxId++;
                    continue;
                }

                float   alpha   = 0.4f;
                Vector3 hbColor = HitboxColor;

                var worldPosition  = hb.GetWorldPosition(JointManager);
                var worldTransform = Matrix4.CreateTranslation(worldPosition);

                if (hb.Element == 8)
                {
                    hbColor = GrabboxColor;
                }

                if (subActionList.SelectedIndices.Count == 1 && hb.CommandIndex == subActionList.SelectedIndex)
                {
                    hbColor                = HitboxSelectedColor;
                    isHitboxSelected       = true;
                    _transWidget.Transform = hb.GetWorldTransform(JointManager);
                }

                // drawing a capsule takes more processing power, so only draw it if necessary
                if (hb.Interpolate &&
                    interpolationToolStripMenuItem.Checked)
                {
                    capsule.SetParameters(worldPosition, PreviousPositions[hitboxId], hb.Size);
                    capsule.Draw(Matrix4.Identity, new Vector4(hbColor, alpha));
                }
                else
                {
                    DrawShape.DrawSphere(worldTransform, hb.Size, 16, 16, hbColor, alpha);
                }

                // draw hitbox angle
                if (hitboxInfoToolStripMenuItem.Checked)
                {
                    if (hb.Angle != 361)
                    {
                        DrawShape.DrawAngleLine(cam, worldTransform, hb.Size, MathHelper.DegreesToRadians(hb.Angle));
                    }
                    else
                    {
                        DrawShape.DrawSakuraiAngle(cam, worldTransform, hb.Size);
                    }

                    GLTextRenderer.RenderText(cam, hitboxId.ToString(), worldTransform, StringAlignment.Center, true);
                }
                hitboxId++;
            }

            // draw shield during guard animation
            if (DisplayShieldSize > 0)
            {
                DrawShape.DrawSphere(JointManager.GetWorldTransform(JointManager.JointCount - 2), DisplayShieldSize, 16, 16, ShieldColor, 0.5f);
            }

            // gfx spawn indicator
            foreach (var gfx in SubactionProcess.GFXOnFrame)
            {
                var boneID = gfx.Bone;
                if (boneID == 0)
                {
                    if (JointManager.GetJOBJ(1) != null && JointManager.GetJOBJ(1).Child == null) // special case for character like mewtwo with a leading bone
                    {
                        boneID = 2;
                    }
                    else
                    {
                        boneID = 1;
                    }
                }
                var transform = Matrix4.CreateTranslation(gfx.Position) * JointManager.GetWorldTransform(boneID);
                transform = transform.ClearScale();

                DrawShape.DrawSphere(transform, 1f, 16, 16, ThrowDummyColor, 0.5f);
            }

            // environment collision
            if (ECB != null)
            {
                var topN = JointManager.GetWorldTransform(1).ExtractTranslation();

                var bone1 = Vector3.TransformPosition(Vector3.Zero, JointManager.GetWorldTransform(ECB.ECBBone1));
                var bone2 = Vector3.TransformPosition(Vector3.Zero, JointManager.GetWorldTransform(ECB.ECBBone2));
                var bone3 = Vector3.TransformPosition(Vector3.Zero, JointManager.GetWorldTransform(ECB.ECBBone3));
                var bone4 = Vector3.TransformPosition(Vector3.Zero, JointManager.GetWorldTransform(ECB.ECBBone4));
                var bone5 = Vector3.TransformPosition(Vector3.Zero, JointManager.GetWorldTransform(ECB.ECBBone5));
                var bone6 = Vector3.TransformPosition(Vector3.Zero, JointManager.GetWorldTransform(ECB.ECBBone6));

                var minx = float.MaxValue;
                var miny = float.MaxValue;
                var maxx = float.MinValue;
                var maxy = float.MinValue;

                foreach (var p in new Vector3[] { bone1, bone2, bone3, bone4, bone5, bone6 })
                {
                    minx = Math.Min(minx, p.Z);
                    maxx = Math.Max(maxx, p.Z);
                    miny = Math.Min(miny, p.Y);
                    maxy = Math.Max(maxy, p.Y);
                }

                // ecb diamond
                if (eCBToolStripMenuItem.Checked)
                {
                    DrawShape.DrawECB(topN, minx, miny, maxx, maxy, groundECH.Checked);
                }

                // ledge grav
                if (ledgeGrabBoxToolStripMenuItem.Checked)
                {
                    var correct = Math.Abs(minx - maxx) / 2;

                    //behind
                    DrawShape.DrawLedgeBox(
                        topN.Z,
                        topN.Y + ECB.VerticalOffsetFromTop - ECB.VerticalScale / 2,
                        topN.Z - (correct + ECB.HorizontalScale),
                        topN.Y + ECB.VerticalOffsetFromTop + ECB.VerticalScale / 2,
                        Color.Red);

                    // in front
                    DrawShape.DrawLedgeBox(
                        topN.Z,
                        topN.Y + ECB.VerticalOffsetFromTop - ECB.VerticalScale / 2,
                        topN.Z + correct + ECB.HorizontalScale,
                        topN.Y + ECB.VerticalOffsetFromTop + ECB.VerticalScale / 2,
                        Color.Blue);
                }
            }

            // throw dummy
            if (ThrowDummyManager.Animation.NodeCount != 0 &&
                throwModelToolStripMenuItem.Checked &&
                !SubactionProcess.ThrownFighter &&
                ThrowDummyManager.JointCount > 0)
            {
                if (viewport.Frame < ThrowDummyManager.Animation.FrameCount)
                {
                    ThrowDummyManager.Frame = viewport.Frame;
                }

                ThrowDummyManager.SetWorldTransform(4, JointManager.GetWorldTransform(JointManager.JointCount - 2));
                ThrowDummyManager.Render(cam, false);

                if (ThrowDummyLookupTable.Count == 0)
                {
                    DrawShape.DrawSphere(ThrowDummyManager.GetWorldTransform(35), 1.5f, 16, 16, ThrowDummyColor, 0.5f);
                    DrawShape.DrawSphere(ThrowDummyManager.GetWorldTransform(4), 1.5f, 16, 16, ThrowDummyColor, 0.5f);
                    DrawShape.DrawSphere(ThrowDummyManager.GetWorldTransform(10), 1f, 16, 16, ThrowDummyColor, 0.5f);
                    DrawShape.DrawSphere(ThrowDummyManager.GetWorldTransform(15), 1f, 16, 16, ThrowDummyColor, 0.5f);
                    DrawShape.DrawSphere(ThrowDummyManager.GetWorldTransform(22), 1f, 16, 16, ThrowDummyColor, 0.5f);
                    DrawShape.DrawSphere(ThrowDummyManager.GetWorldTransform(40), 1f, 16, 16, ThrowDummyColor, 0.5f);
                }
            }

            if (isHitboxSelected)
            {
                _transWidget.Render(cam);
            }

            // sword trail
            //AfterImageRenderer.RenderAfterImage(JointManager, viewport.Frame, after_desc);
        }