Example #1
0
        public void DrawCharacter(AnimationState animstate, Vector3 pos, byte heading, byte pitch, bool moves, float dt, int playertexture, AnimationHint animationhint)
        {
            if (animationhint.InVehicle)
            {
                moves = false;
            }
            pos += animationhint.DrawFix;
            if (animstate.data == null)
            {
                Dictionary<string, object> d = new Dictionary<string, object>();
                animstate.data = d;
            }
            var variables = (Dictionary<string, object>)animstate.data;
            if (moves)
            {
                animstate.interp += dt;
            }
            else
            {
                float f = Normalize(animstate.interp, (float)animperiod / 2);
                if (Math.Abs(f) < 0.02f)
                {
                    animstate.interp = 0;
                }
                else
                {
                    animstate.interp += dt;
                }
            }

            GL.PushMatrix();
            GL.Translate(pos);

            variables["heading"] = (double)heading;
            variables["pitch"] = (double)pitch;
            variables["headingdeg"] = ((double)heading / 256) * 360;
            variables["pitchdeg"] = ((double)pitch / 256) * 360;
            variables["updown"] = (double)UpDown(animstate.interp, (float)animperiod);
            variables["limbrotation1"] = (double)LeftLegRotation(animstate.interp, (float)animperiod);
            variables["limbrotation2"] = (double)RightLegRotation(animstate.interp, (float)animperiod);
            variables["skin"] = (double)playertexture;
            variables["dt"] = (double)dt;
            variables["time"] = (double)animstate.interp;
            variables["anim"] = (double)currentanim;
            string[] animations = Animations();
            for (int i = 0; i < animations.Length; i++)
            {
                variables[animations[i]] = (double)i;
            }
            int skinsizex = 64;
            int skinsizey = 32;
            int pc = 0;
            for (; ; )
            {
                if (pc >= code.Count)
                {
                    break;
                }
                string[] ss = code[pc];
                if (ss.Length > 0)
                {
                    switch (ss[0])
                    {
                        case "set":
                            {
                                variables[ss[1]] = getval(ss[2], variables);
                            }
                            break;
                        case "pushmatrix":
                            {
                                GL.PushMatrix();
                            }
                            break;
                        case "popmatrix":
                            {
                                GL.PopMatrix();
                            }
                            break;
                        case "mul":
                            {
                                variables[ss[1]] = (double)variables[ss[1]] * getval(ss[2], variables);
                            }
                            break;
                        case "add":
                            {
                                variables[ss[1]] = (double)variables[ss[1]] + getval(ss[2], variables);
                            }
                            break;
                        case "rotate":
                            {
                                GL.Rotate(
                                    getval(ss[1], variables),
                                    getval(ss[2], variables),
                                    getval(ss[3], variables),
                                    getval(ss[4], variables));
                            }
                            break;
                        case "translate":
                            {
                                GL.Translate(
                                    getval(ss[1], variables),
                                    getval(ss[2], variables),
                                    getval(ss[3], variables));
                            }
                            break;
                        case "scale":
                            {
                                GL.Scale(
                                    getval(ss[1], variables),
                                    getval(ss[2], variables),
                                    getval(ss[3], variables));
                            }
                            break;
                        case "makecoords":
                            {
                                RectangleF[] coords = MakeCoords(
                                   (float)getval(ss[2], variables),
                                   (float)getval(ss[3], variables),
                                   (float)getval(ss[4], variables),
                                   (float)getval(ss[5], variables),
                                   (float)getval(ss[6], variables));
                                MakeTextureCoords(coords, skinsizex, skinsizey);
                                variables[ss[1]] = coords;
                            }
                            break;
                        case "drawcuboid":
                            {
                                DrawCuboid(
                                   new Vector3((float)getval(ss[1], variables),
                                    (float)getval(ss[2], variables),
                                    (float)getval(ss[3], variables)),
                                   new Vector3((float)getval(ss[4], variables),
                                    (float)getval(ss[5], variables),
                                    (float)getval(ss[6], variables)),
                                   (int)getval(ss[7], variables),
                                   (RectangleF[])variables[ss[8]]
                                    );
                            }
                            break;
                        case "skinsize":
                            {
                                skinsizex = (int)getval(ss[1], variables);
                                skinsizey = (int)getval(ss[2], variables);
                            }
                            break;
                        case "dim":
                            {
                                if (!variables.ContainsKey(ss[1]))
                                {
                                    variables[ss[1]] = getval(ss[2], variables);
                                }
                            }
                            break;
                        case "fun":
                            {
                                if (ss[2] == "tri")
                                {
                                    variables[ss[1]] = (double)TriWave(getval(ss[3], variables));
                                }
                                if (ss[2] == "sin")
                                {
                                    variables[ss[1]] = (double)Math.Sin(getval(ss[3], variables));
                                }
                                if (ss[2] == "abs")
                                {
                                    variables[ss[1]] = (double)Math.Abs(getval(ss[3], variables));
                                }
                            }
                            break;
                        case "ifeq":
                            {
                                if (variables.ContainsKey(ss[1])
                                    && (double)variables[ss[1]] != getval(ss[2], variables))
                                {
                                    //find endif
                                    for (int i = pc; i < code.Count; i++)
                                    {
                                        if (code[i][0] == "endif")
                                        {
                                            pc = i;
                                            goto next;
                                        }
                                    }
                                }
                            }
                            break;
                    }
                }
                pc++;
            next:
                ;
            }
            GL.PopMatrix();
        }
 //private void DrawCharacter(AnimationState animstate, Vector3 pos, Vector3 dir, bool moves, float dt, int playertexture)
 //{
 //    DrawCharacter(animstate, pos,
 //        (byte)(((Vector3.CalculateAngle(new Vector3(1, 0, 0), dir) + 90) / (2 * (float)Math.PI)) * 256), 0, moves, dt, playertexture);
 //}
 private void DrawCharacter(AnimationState animstate, Vector3 pos, byte heading, byte pitch, bool moves, float dt, int playertexture, AnimationHint animationhint)
 {
     characterdrawer.SetAnimation("walk");
     characterdrawer.DrawCharacter(animstate, pos, (byte)(-heading - 256 / 4), pitch, moves, dt, playertexture, animationhint);
 }