Ejemplo n.º 1
0
        public Vector3 RotatePoint(Player p, RawPart raw, Vector3 pos)
        {
            float angleX = ModelAnim.Animate(p, raw.XAnim);
            float angleY = ModelAnim.Animate(p, raw.YAnim);
            float angleZ = ModelAnim.Animate(p, raw.ZAnim);

            float cosX = (float)Math.Cos(-angleX), sinX = (float)Math.Sin(-angleX);
            float cosY = (float)Math.Cos(-angleY), sinY = (float)Math.Sin(-angleY);
            float cosZ = (float)Math.Cos(-angleZ), sinZ = (float)Math.Sin(-angleZ);
            float x = raw.RotX / 16f, y = raw.RotY / 16f, z = raw.RotZ / 16f;

            Vector3 loc = new Vector3(pos.X - x, pos.Y - y, pos.Z - z);

            loc = Utils.RotateZ(loc.X, loc.Y, loc.Z, cosZ, sinZ);
            loc = Utils.RotateY(loc.X, loc.Y, loc.Z, cosY, sinY);
            loc = Utils.RotateX(loc.X, loc.Y, loc.Z, cosX, sinX);

            return(Utils.RotateY(loc.X + x, loc.Y + y, loc.Z + z, cosA, sinA) + this.pos);
        }
Ejemplo n.º 2
0
        public static void ExportCode(List <RawPart> parts, Stream stream)
        {
            StreamWriter w = new StreamWriter(stream);

            w.WriteLine("// Skeleton implementation exported from ModelPreviewer");
            w.WriteLine("// You still need to implement rest of IModel yourself");
            w.WriteLine("// I recommend you press Ctrl + I in your IDE to format this");

            w.WriteLine("using System;");
            w.WriteLine("using ClassicalSharp");
            w.WriteLine("using ClassicalSharp.Entities;");
            w.WriteLine("using ClassicalSharp.Model;");
            w.WriteLine("using ClassicalSharp.Physics;");
            w.WriteLine("using OpenTK;");

            w.WriteLine();
            w.WriteLine("namespace MyModels {");
            w.WriteLine("\tpublic class MyModel : IModel {");
            w.WriteLine();
            w.WriteLine("\t\tpublic MyModel(Game window) : base(window) { }");
            w.WriteLine();

            w.WriteLine("\t\tpublic override void CreateParts() {");
            w.WriteLine("\t\t\tvertices = new ModelVertex[boxVertices * " + parts.Count + "];");

            foreach (RawPart part in parts)
            {
                w.Write("\t\t\t" + part.Name + " = ");
                if (part.Rotated)
                {
                    w.Write("BuildRotatedBox(MakeRotatedBoxBounds(");
                }
                else
                {
                    w.Write("BuildBox(MakeBoxBounds(");
                }

                w.Write(part.X1 + ", " + part.Y1 + ", " + part.Z1 + ", ");
                w.Write(part.X2 + ", " + part.Y2 + ", " + part.Z2 + ")");
                w.WriteLine();

                w.WriteLine(".TexOrigin(" + part.TexX + ", " + part.TexY + ")");
                w.WriteLine(".RotOrigin(" + part.RotX + ", " + part.RotY + ", " + part.RotZ + "));");
            }
            w.WriteLine("\t\t}");

            w.WriteLine();
            w.WriteLine("\t\tpublic override void DrawModel(Entity p) {");
            w.WriteLine("\t\t\tgame.Graphics.BindTexture(GetTexture(p));");
            w.WriteLine();

            bool alphaTest = true;

            foreach (RawPart part in parts)
            {
                if (part.AlphaTest != alphaTest)
                {
                    w.WriteLine("\t\t\tgame.Graphics.AlphaTest = " + (part.AlphaTest ? "true;" : "false;"));
                    alphaTest = part.AlphaTest;
                }

                if (part.XAnim == "" && part.YAnim == "" && part.ZAnim == "")
                {
                    w.WriteLine("\t\t\tDrawPart(" + part.Name + ");");
                }
                else
                {
                    w.WriteLine("\t\t\tDrawRotate(" + ModelAnim.Format(part.XAnim) + ", "
                                + ModelAnim.Format(part.YAnim) + ", " + ModelAnim.Format(part.ZAnim) + ", "
                                + part.Name + ", " + (part.Name.ToLower() == "head" ? "true" : "false") + ")");
                }
            }

            w.WriteLine("\t\t\tUpdateVB()");
            if (!alphaTest)
            {
                w.WriteLine("\t\t\tgame.Graphics.AlphaTest = true;");
            }
            w.WriteLine("\t\t}");

            w.WriteLine("\t}");
            w.WriteLine("}");
            w.Flush();
        }