summaryrefslogtreecommitdiff
path: root/Box2d/Assets/Program/Test/ApplicationMain.cs
blob: bec45405d2676a0732a63a8093ae74c4dc68ffd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Box2DX;
using Box2DX.Dynamics;
using Box2DX.Collision;
using Box2DX.Common;

public class ApplicationMain : MonoBehaviour
{


    public Material material;

    void OnPostRender()
    {
        //绘制正四边形,提供的坐标必须是顺时针或者逆时针
        Draw(100, 100, 100, 200, 200, 200, 200, 100);
        //绘制无规则四边形
        Draw(15, 5, 10, 115, 95, 110, 90, 10);
    }

    //绘制四边形,四个点坐标
    void Draw(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
    {
        GL.PushMatrix();
        //material.SetPass(0);//设置该材质通道,0为默认值
        GL.LoadOrtho();//设置绘制2d图像
        GL.Begin(GL.QUADS);//绘制类型为四边形

        GL.Vertex3(x1 / Screen.width, y1 / Screen.height, 0);
        GL.Vertex3(x2 / Screen.width, y2 / Screen.height, 0);
        GL.Vertex3(x3 / Screen.width, y3 / Screen.height, 0);
        GL.Vertex3(x4 / Screen.width, y4 / Screen.height, 0);

        GL.End();
        GL.PopMatrix();
    }

}