Пример #1
0
        private void DrawOn2DControl(int numQSteps)
        {
            if (!_lockPositions)
            {
                _marioState = MarioState.CreateMarioState();
            }
            MarioState marioStateCenter   = AirMovementCalculator.ApplyInputRepeatedly(_marioState, RelativeDirection.Center, numQSteps);
            MarioState marioStateForward  = AirMovementCalculator.ApplyInputRepeatedly(_marioState, RelativeDirection.Forward, numQSteps);
            MarioState marioStateBackward = AirMovementCalculator.ApplyInputRepeatedly(_marioState, RelativeDirection.Backward, numQSteps);
            MarioState marioStateLeft     = AirMovementCalculator.ApplyInputRepeatedly(_marioState, RelativeDirection.Left, numQSteps);

            ushort marioAngle = _marioState.MarioAngle;

            (float cx, float cz) = (marioStateCenter.X, marioStateCenter.Z);
            (float fx, float fz) = (marioStateForward.X, marioStateForward.Z);
            (float bx, float bz) = (marioStateBackward.X, marioStateBackward.Z);
            (float lx, float lz) = (marioStateLeft.X, marioStateLeft.Z);

            double sideDist     = MoreMath.GetDistanceBetween(cx, cz, lx, lz);
            double forwardDist  = MoreMath.GetDistanceBetween(cx, cz, fx, fz);
            double backwardDist = MoreMath.GetDistanceBetween(cx, cz, bx, bz);

            (float controlCenterX, float controlCenterZ) = MapUtilities.ConvertCoordsForControlTopDownView(cx, cz, UseRelativeCoordinates);
            List <(float pointX, float pointZ)> controlPoints = Enumerable.Range(0, MapConfig.MapCircleNumPoints2D).ToList()
                                                                .ConvertAll(index => (index / (float)MapConfig.MapCircleNumPoints2D) * 65536)
                                                                .ConvertAll(angle => GetEllipsePoint(cx, cz, sideDist, forwardDist, backwardDist, marioAngle, angle))
                                                                .ConvertAll(point => MapUtilities.ConvertCoordsForControlTopDownView((float)point.x, (float)point.z, UseRelativeCoordinates));

            GL.BindTexture(TextureTarget.Texture2D, -1);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            // Draw circle
            GL.Color4(Color.R, Color.G, Color.B, OpacityByte);
            GL.Begin(PrimitiveType.TriangleFan);
            GL.Vertex2(controlCenterX, controlCenterZ);
            foreach ((float x, float z) in controlPoints)
            {
                GL.Vertex2(x, z);
            }
            GL.Vertex2(controlPoints[0].pointX, controlPoints[0].pointZ);
            GL.End();

            // Draw outline
            if (LineWidth != 0)
            {
                GL.Color4(LineColor.R, LineColor.G, LineColor.B, (byte)255);
                GL.LineWidth(LineWidth);
                GL.Begin(PrimitiveType.LineLoop);
                foreach ((float x, float z) in controlPoints)
                {
                    GL.Vertex2(x, z);
                }
                GL.End();
            }

            GL.Color4(1, 1, 1, 1.0f);
        }
Пример #2
0
        private void DrawOn3DControl(int numQSteps)
        {
            if (!_lockPositions)
            {
                _marioState = MarioState.CreateMarioState();
            }
            MarioState marioStateCenter   = AirMovementCalculator.ApplyInputRepeatedly(_marioState, RelativeDirection.Center, numQSteps);
            MarioState marioStateForward  = AirMovementCalculator.ApplyInputRepeatedly(_marioState, RelativeDirection.Forward, numQSteps);
            MarioState marioStateBackward = AirMovementCalculator.ApplyInputRepeatedly(_marioState, RelativeDirection.Backward, numQSteps);
            MarioState marioStateLeft     = AirMovementCalculator.ApplyInputRepeatedly(_marioState, RelativeDirection.Left, numQSteps);

            ushort marioAngle = _marioState.MarioAngle;

            (float cx, float cz) = (marioStateCenter.X, marioStateCenter.Z);
            (float fx, float fz) = (marioStateForward.X, marioStateForward.Z);
            (float bx, float bz) = (marioStateBackward.X, marioStateBackward.Z);
            (float lx, float lz) = (marioStateLeft.X, marioStateLeft.Z);

            double sideDist     = MoreMath.GetDistanceBetween(cx, cz, lx, lz);
            double forwardDist  = MoreMath.GetDistanceBetween(cx, cz, fx, fz);
            double backwardDist = MoreMath.GetDistanceBetween(cx, cz, bx, bz);

            List <(float x, float y, float z)> points = Enumerable.Range(0, MapConfig.MapCircleNumPoints2D).ToList()
                                                        .ConvertAll(index => (index / (float)MapConfig.MapCircleNumPoints2D) * 65536)
                                                        .ConvertAll(angle => GetEllipsePoint(cx, cz, sideDist, forwardDist, backwardDist, marioAngle, angle))
                                                        .ConvertAll(point => ((float)point.x, (float)marioStateCenter.Y, (float)point.z));

            Map3DVertex[] vertexArrayForSurfaces = points.ConvertAll(
                vertex => new Map3DVertex(new Vector3(
                                              vertex.x, vertex.y, vertex.z), Color4)).ToArray();
            Map3DVertex[] vertexArrayForEdges = points.ConvertAll(
                vertex => new Map3DVertex(new Vector3(
                                              vertex.x, vertex.y, vertex.z), LineColor)).ToArray();

            Matrix4 viewMatrix = GetModelMatrix() * Config.Map3DCamera.Matrix;

            GL.UniformMatrix4(Config.Map3DGraphics.GLUniformView, false, ref viewMatrix);

            {
                int buffer = GL.GenBuffer();
                GL.BindTexture(TextureTarget.Texture2D, MapUtilities.WhiteTexture);
                GL.BindBuffer(BufferTarget.ArrayBuffer, buffer);
                GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertexArrayForSurfaces.Length * Map3DVertex.Size),
                              vertexArrayForSurfaces, BufferUsageHint.DynamicDraw);
                Config.Map3DGraphics.BindVertices();
                GL.DrawArrays(PrimitiveType.Polygon, 0, vertexArrayForSurfaces.Length);
                GL.DeleteBuffer(buffer);
            }

            if (LineWidth != 0)
            {
                int buffer = GL.GenBuffer();
                GL.BindTexture(TextureTarget.Texture2D, MapUtilities.WhiteTexture);
                GL.BindBuffer(BufferTarget.ArrayBuffer, buffer);
                GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertexArrayForEdges.Length * Map3DVertex.Size),
                              vertexArrayForEdges, BufferUsageHint.DynamicDraw);
                GL.LineWidth(LineWidth);
                Config.Map3DGraphics.BindVertices();
                GL.DrawArrays(PrimitiveType.LineLoop, 0, vertexArrayForEdges.Length);
                GL.DeleteBuffer(buffer);
            }
        }