Beispiel #1
0
    void DrawLocalPosition(Game game)
    {
        if (DRAW_POSITION)
        {
            GamePlatform p = m.GetPlatform();

            float heading = (((m.GetLocalOrientationY()) % (2 * Game.GetPi())) / (2 * Game.GetPi())) * 256;
            float pitch   = (((m.GetLocalOrientationX() + Game.GetPi()) % (2 * Game.GetPi())) / (2 * Game.GetPi())) * 256;

            // Y and Z axis are swapped for display as Z axis depicts height
            PositionLines[0] = p.StringFormat("X: {0}", p.IntToString(game.MathFloor(m.GetLocalPositionX())));
            PositionLines[1] = p.StringFormat("Y: {0}", p.IntToString(game.MathFloor(m.GetLocalPositionZ())));
            PositionLines[2] = p.StringFormat("Z: {0}", p.IntToString(game.MathFloor(m.GetLocalPositionY())));
            PositionLines[3] = p.StringFormat("Heading: {0}", p.IntToString(Game.IntToByte(p.FloatToInt(heading))));
            PositionLines[4] = p.StringFormat("Pitch: {0}", p.IntToString(Game.IntToByte(p.FloatToInt(pitch))));

            m.OrthoMode();
            for (int i = 0; i < PositionLinesCount; i++)
            {
                m.Draw2dText(PositionLines[i], 20, m.GetWindowHeight() - 100 + 1.5f * i * displayFont.size, displayFont);
            }
            m.PerspectiveMode();
        }
    }
Beispiel #2
0
    public override bool OnClientCommand(Game game, ClientCommandArgs args)
    {
        if (args.command == "cam")
        {
            IntRef   argumentsLength = new IntRef();
            string[] arguments       = p.StringSplit(args.arguments, " ", argumentsLength);
            if (p.StringTrim(args.arguments) == "")
            {
                m.DisplayNotification("&6AutoCamera help.");
                m.DisplayNotification("&6.cam p&f - add a point to path");
                m.DisplayNotification("&6.cam start [real seconds]&f - play the path");
                m.DisplayNotification("&6.cam rec [real seconds] [video seconds]&f - play and record to .avi file");
                m.DisplayNotification("&6.cam stop&f - stop playing and recording");
                m.DisplayNotification("&6.cam clear&f - remove all points from path");
                m.DisplayNotification("&6.cam save&f - copy path points to clipboard");
                m.DisplayNotification("&6.cam load [points]&f - load path points");
                return(true);
            }
            if (arguments[0] == "p")
            {
                m.DisplayNotification("Point defined.");
                CameraPoint point = new CameraPoint();
                point.positionGlX    = m.GetLocalPositionX();
                point.positionGlY    = m.GetLocalPositionY();
                point.positionGlZ    = m.GetLocalPositionZ();
                point.orientationGlX = m.GetLocalOrientationX();
                point.orientationGlY = m.GetLocalOrientationY();
                point.orientationGlZ = m.GetLocalOrientationZ();
                cameraPoints[cameraPointsCount++] = point;
            }
            if (arguments[0] == "start" || arguments[0] == "play" || arguments[0] == "rec")
            {
                if (!m.IsFreemoveAllowed())
                {
                    m.DisplayNotification("Free move not allowed.");
                    return(true);
                }
                if (cameraPointsCount == 0)
                {
                    m.DisplayNotification("No points defined. Enter points with \".cam p\" command.");
                    return(true);
                }
                playingSpeed = 1;
                float totalRecTime = -1;
                if (arguments[0] == "rec")
                {
                    if (argumentsLength.value >= 3)
                    {
                        // video time
                        totalRecTime = p.FloatParse(arguments[2]);
                    }
                    avi = m.AviWriterCreate();
                    avi.Open(p.StringFormat("{0}.avi", p.Timestamp()), framerate, m.GetWindowWidth(), m.GetWindowHeight());
                }
                if (argumentsLength.value >= 2)
                {
                    // play time
                    float totalTime = p.FloatParse(arguments[1]);
                    playingSpeed = TotalDistance() / totalTime;

                    if (totalRecTime == -1)
                    {
                        recspeed = 10;
                    }
                    else
                    {
                        recspeed = totalTime / totalRecTime;
                    }
                }
                playingTime          = 0;
                firstFrameDone       = false;
                previousPositionX    = m.GetLocalPositionX();
                previousPositionY    = m.GetLocalPositionY();
                previousPositionZ    = m.GetLocalPositionZ();
                previousOrientationX = m.GetLocalOrientationX();
                previousOrientationY = m.GetLocalOrientationY();
                previousOrientationZ = m.GetLocalOrientationZ();
                m.ShowGui(0);
                previousFreemove = m.GetFreemove();
                m.SetFreemove(FreemoveLevelEnum.Noclip);
                m.EnableCameraControl(false);
            }
            if (arguments[0] == "stop")
            {
                m.DisplayNotification("Camera stopped.");
                Stop();
            }
            if (arguments[0] == "clear")
            {
                m.DisplayNotification("Camera points cleared.");
                cameraPointsCount = 0;
                Stop();
            }
            if (arguments[0] == "save")
            {
                string s = "1,";
                for (int i = 0; i < cameraPointsCount; i++)
                {
                    CameraPoint point = cameraPoints[i];
                    s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.positionGlX * 100)));
                    s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.positionGlY * 100)));
                    s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.positionGlZ * 100)));
                    s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.orientationGlX * 1000)));
                    s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.orientationGlY * 1000)));
                    s = p.StringFormat2("{0}{1}", s, p.IntToString(p.FloatToInt(point.orientationGlZ * 1000)));
                    if (i != cameraPointsCount - 1)
                    {
                        s = p.StringFormat("{0},", s);
                    }
                }
                p.ClipboardSetText(s);
                m.DisplayNotification("Camera points copied to clipboard.");
            }
            if (arguments[0] == "load")
            {
                IntRef   pointsLength = new IntRef();
                string[] points       = p.StringSplit(arguments[1], ",", pointsLength);
                int      n            = (pointsLength.value - 1) / 6;
                cameraPointsCount = 0;
                for (int i = 0; i < n; i++)
                {
                    CameraPoint point = new CameraPoint();
                    point.positionGlX    = one * p.IntParse(points[1 + i * 6 + 0]) / 100;
                    point.positionGlY    = one * p.IntParse(points[1 + i * 6 + 1]) / 100;
                    point.positionGlZ    = one * p.IntParse(points[1 + i * 6 + 2]) / 100;
                    point.orientationGlX = one * p.IntParse(points[1 + i * 6 + 3]) / 1000;
                    point.orientationGlY = one * p.IntParse(points[1 + i * 6 + 4]) / 1000;
                    point.orientationGlZ = one * p.IntParse(points[1 + i * 6 + 5]) / 1000;
                    cameraPoints[cameraPointsCount++] = point;
                }
                m.DisplayNotification(p.StringFormat("Camera points loaded: {0}", p.IntToString(n)));
            }
            return(true);
        }
        return(false);
    }