Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cam"></param>
        /// <param name="frame"></param>
        public void Render(Camera cam, float frame)
        {
            if (frame == -1 && entryAnimation.Count > 0)
            {
                entryAnimation.Clear();
            }

            if (frame == 0)
            {
                entryAnimation.Clear();

                // Load Animation
                foreach (var i in Icons)
                {
                    if (i.AnimJoint == null)
                    {
                        continue;
                    }

                    var a = new JointAnimManager();
                    a.FromAnimJoint(i.AnimJoint);
                    entryAnimation.Add(i, a);
                }
            }

            for (int i = 0; i < Icons.Length; i++)
            {
                var ico = Icons[i];

                if (ico.Joint == null)
                {
                    continue;
                }

                var transform = Matrix4.Identity;

                if (entryAnimation.ContainsKey(ico))
                {
                    transform = entryAnimation[ico].GetAnimatedMatrix(frame, 0, ico.Joint);
                }
                else
                {
                    transform = Matrix4.CreateScale(ico.Joint.SX, ico.Joint.SY, ico.Joint.SZ) *
                                Matrix4.CreateFromQuaternion(Math3D.FromEulerAngles(ico.Joint.RZ, ico.Joint.RY, ico.Joint.RX)) *
                                Matrix4.CreateTranslation(ico.Joint.TX, ico.Joint.TY, ico.Joint.TZ);
                }

                if (IconJOBJManager.JointCount > 0)
                {
                    IconJOBJManager.SetWorldTransform(0, transform);
                    ico.IconTOBJ.Flags = TOBJ_FLAGS.LIGHTMAP_DIFFUSE | TOBJ_FLAGS.COLORMAP_MODULATE | TOBJ_FLAGS.ALPHAMAP_MODULATE;
                    IconJOBJManager.GetJOBJ(0).Child.Dobj.Next.Mobj.Textures = ico.IconTOBJ;
                    IconJOBJManager.Render(cam, false);
                }

                if (sssEditor.SelectedIndices.Contains(i))
                {
                    if (sssEditor.SelectedIndices.Count == 1 && StageNameJOBJManager.JointCount > 0)
                    {
                        ico.NameTOBJ.Flags = TOBJ_FLAGS.LIGHTMAP_DIFFUSE | TOBJ_FLAGS.COLORMAP_MODULATE | TOBJ_FLAGS.ALPHAMAP_MODULATE;
                        StageNameJOBJManager.GetJOBJ(0).Child.Child.Dobj.Mobj.Textures = ico.NameTOBJ;
                    }

                    var rect = ico.ToRectangle();

                    DrawShape.DrawRectangle(rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height, ico.Joint.TZ, 2, MEX_CSSIconEntry.SelectedIconColor);

                    if (Dragging)
                    {
                        DrawShape.Line(new Vector3(-100, rect.Y, 0), new Vector3(100, rect.Y, 0), SnapColor, 1);
                        DrawShape.Line(new Vector3(rect.X, -100, 0), new Vector3(rect.X, 100, 0), SnapColor, 1);
                        DrawShape.Line(new Vector3(-100, rect.Y + rect.Height, 0), new Vector3(100, rect.Y + rect.Height, 0), SnapColor, 1);
                        DrawShape.Line(new Vector3(rect.X + rect.Width, -100, 0), new Vector3(rect.X + rect.Width, 100, 0), SnapColor, 1);
                    }
                }
            }

            StageNameJOBJManager.Render(cam);
        }
Exemplo n.º 2
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);
        }