コード例 #1
0
ファイル: Map.cs プロジェクト: minalear/IronCore
        public void Draw(ShapeRenderer renderer)
        {
            renderer.SetTransform(Matrix4.Identity);

            //Draw water
            for (int i = 0; i < WaterBodies.Count; i++)
            {
                renderer.FillShape(WaterBodies[i].VertexData, new Color4(0, 174, 239, 60));
                renderer.DrawShape(WaterBodies[i].VertexData, new Color4(0, 174, 239, 255));
            }

            //Draw map entities
            for (int i = 0; i < entities.Count; i++)
            {
                entities[i].Draw(renderer);
            }

            //TODO: Consider rendering static geometry to a texture for performant rendering
            //Or put all of the static geometry into one VBO and render it in one shot, rather than
            //depend on the shape renderer

            //Draw static geometry
            for (int i = 0; i < StaticGeometry.Count; i++)
            {
                renderer.FillShape(StaticGeometry[i].VertexData, Color4.Black);
                renderer.DrawShape(StaticGeometry[i].VertexData, Color4.LimeGreen);
            }

            //Simulate world
            World.Step(0.01f);
        }
コード例 #2
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit);
            shapeRenderer.Begin();

            float   cameraScale    = 2f;
            Vector2 rocketPosition = ConvertUnits.ToDisplayUnits(rocket.Position);
            Vector2 cameraCenter   = -rocketPosition + new Vector2(400f, 225f) / cameraScale;

            //Set camera
            shapeRenderer.SetCamera(
                Matrix4.CreateTranslation(cameraCenter.X, cameraCenter.Y, 0f) *
                Matrix4.CreateScale(cameraScale));

            //Draw world geometry
            shapeRenderer.SetTransform(Matrix4.Identity);
            foreach (Shape shape in geometry)
            {
                shapeRenderer.DrawShape(shape.Data, Color4.Black);
            }

            //Draw player rocket
            shapeRenderer.SetTransform(
                Matrix4.CreateRotationZ(rocket.Rotation) *
                Matrix4.CreateTranslation(rocketPosition.X, rocketPosition.Y, 0f));
            shapeRenderer.DrawShape(rocketShape.Data, Color4.Red);

            shapeRenderer.End();
            SwapBuffers();
        }
コード例 #3
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit);

            shapeRenderer.Begin();

            //Create matrix transforms based on the body's rotation and position
            Vector2 body01Position = (body01.Position * unitToPixel) - new Vector2(25f, 25f);

            shapeRenderer.SetTransform(
                Matrix4.CreateRotationZ(body01.Rotation) *
                Matrix4.CreateTranslation(body01Position.X + 25f, body01Position.Y + 25f, 0f));
            shapeRenderer.FillShape(body01Shape, Color4.Red);
            shapeRenderer.DrawShape(body01Shape, Color4.Black);

            Vector2 body02Position = (body02.Position * unitToPixel) - new Vector2(400f, 25f);

            shapeRenderer.SetTransform(
                Matrix4.CreateRotationZ(body02.Rotation) *
                Matrix4.CreateTranslation(body02Position.X + 400f, body02Position.Y + 25f, 0f));
            shapeRenderer.FillShape(body02Shape, Color4.Blue);
            shapeRenderer.DrawShape(body02Shape, Color4.Black);
            shapeRenderer.End();

            SwapBuffers();
        }
コード例 #4
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit);

            shapeRenderer.Begin();

            //Create matrix transforms based on the body's rotation and position
            Vector2 ballPosition = ball.Position * unitToPixel;

            shapeRenderer.SetTransform(
                Matrix4.CreateRotationZ(ball.Rotation) *
                Matrix4.CreateTranslation(ballPosition.X, ballPosition.Y, 0f));
            shapeRenderer.DrawShape(rocketShape, Color4.Black);

            shapeRenderer.ClearTransform();
            shapeRenderer.DrawRect(new Vector2(0f, 425f), new Vector2(800f, 25f), Color4.Red);

            foreach (Body box in boxes)
            {
                Vector2 boxPos = (box.Position * unitToPixel) - new Vector2(25f);
                shapeRenderer.SetTransform(
                    Matrix4.CreateTranslation(-boxPos.X - 25f, -boxPos.Y - 25f, 0f) *
                    Matrix4.CreateRotationZ(box.Rotation) *
                    Matrix4.CreateTranslation(boxPos.X + 25f, boxPos.Y + 25f, 0f));
                shapeRenderer.DrawRect(boxPos, new Vector2(50f), Color4.Brown);
            }

            shapeRenderer.End();

            SwapBuffers();
        }
コード例 #5
0
    void Update()
    {
        var bottomLeft  = m_inputArea.GetBottomLeftCorner();
        var topRight    = m_inputArea.GetTopRightCorner();
        var topLeft     = new Vector3(bottomLeft.x, topRight.y, 0.0f);
        var bottomRight = new Vector3(topRight.x, bottomLeft.y, 0.0f);

        var pointAOppositeEdges = new List <Line>()
        {
            new Line(topLeft, topRight), new Line(topRight, bottomRight)
        };

        m_rectShapePoint = new ShapePoint(bottomLeft, pointAOppositeEdges);

        var pointBOppositeEdges = new List <Line>()
        {
            new Line(bottomLeft, bottomRight), new Line(bottomRight, topRight)
        };

        m_circleShapePoint = new ShapePoint(topLeft, pointBOppositeEdges);

        var pointCOppositeEdges = new List <Line>()
        {
            new Line(bottomRight, bottomLeft), new Line(bottomLeft, topLeft)
        };

        m_hexShapePoint = new ShapePoint(topRight, pointCOppositeEdges);

        var pointDOppositeEdges = new List <Line>()
        {
            new Line(bottomLeft, topLeft), new Line(topLeft, topRight)
        };

        m_starShapePoint = new ShapePoint(bottomRight, pointDOppositeEdges);

        m_weightRect   = m_rectShapePoint.GetWeight(m_inputArea.CursorPosition);
        m_weightCircle = m_circleShapePoint.GetWeight(m_inputArea.CursorPosition);
        m_weightHex    = m_hexShapePoint.GetWeight(m_inputArea.CursorPosition);
        m_weightStar   = m_starShapePoint.GetWeight(m_inputArea.CursorPosition);

        float norm = 1.0f / (m_weightRect + m_weightCircle + m_weightHex + m_weightStar);

        m_weightRect   *= norm;
        m_weightCircle *= norm;
        m_weightHex    *= norm;
        m_weightStar   *= norm;

        ShapeMorpher morpher = new ShapeMorpher();

        morpher.AddShape(m_shapeRectangle.Points, m_weightRect);
        morpher.AddShape(m_shapeCircle.Points, m_weightCircle);
        morpher.AddShape(m_shapeHex.Points, m_weightHex);
        morpher.AddShape(m_shapeStar.Points, m_weightStar);

        m_shapeRenderer.DrawShape(morpher.Points, 5.0f);


        // m_inputArea.m_cursor2.position = m_inputArea.GetBottomLeftCorner() + (m_inputArea.CursorPosition - m_inputArea.GetBottomLeftCorner()).normalized * m_weightRect;
    }
コード例 #6
0
ファイル: Player.cs プロジェクト: minalear/IronCore
        public override void Draw(ShapeRenderer renderer)
        {
            Vector2 position = ConvertUnits.ToDisplayUnits(physicsBody.Position);

            renderer.SetTransform(
                Matrix4.CreateRotationZ(PhysicsBody.Rotation) *
                Matrix4.CreateTranslation(position.X, position.Y, 0f));
            renderer.DrawShape(shape.VertexData, ColorUtils.Blend(Color4.Red, Color4.Green, currentHealth / 100f));
            renderer.ClearTransform();
        }