コード例 #1
0
 public virtual RectBox GetRectBox()
 {
     if (_rotation != 0)
     {
         int[] result = MathUtils.GetLimit(_position.GetX(),
                                           _position.GetY(), GetWidth(), GetHeight(),
                                           MathUtils.ToDegrees(_rotation));
         if (temp_rect == null)
         {
             temp_rect = new RectBox(result[0], result[1], result[2],
                                     result[3]);
         }
         else
         {
             temp_rect.SetBounds(result[0], result[1], result[2], result[3]);
         }
     }
     else
     {
         if (temp_rect == null)
         {
             temp_rect = new RectBox(_position.GetX(), _position.GetY(),
                                     GetWidth(), GetHeight());
         }
         else
         {
             temp_rect.SetBounds(_position.GetX(), _position.GetY(),
                                 GetWidth(), GetHeight());
         }
     }
     return(temp_rect);
 }
コード例 #2
0
        public int GetTileIDFromPixels(float sx, float sy)
        {
            float    x = (sx + offset.GetX());
            float    y = (sy + offset.GetY());
            Vector2f tileCoordinates = pixelsToTiles(x, y);

            return(GetTileID(MathUtils.Round(tileCoordinates.GetX()),
                             MathUtils.Round(tileCoordinates.GetY())));
        }
コード例 #3
0
    static public void DrawSquare(Vector2f p, float size, float z = 0f)
    {
        Vector2f p0 = new Vector2f(p.GetX() - size, p.GetY() - size);
        Vector2f p1 = new Vector2f(p.GetX() + size, p.GetY() - size);
        Vector2f p2 = new Vector2f(p.GetX() + size, p.GetY() + size);
        Vector2f p3 = new Vector2f(p.GetX() - size, p.GetY() + size);

        DrawTriangle(p0, p1, p2, new Vector2f(0, 0), z);
        DrawTriangle(p2, p3, p0, new Vector2f(0, 0), z);
    }
コード例 #4
0
    public static Vector2f ReflectAngle(Vector2f v, float wallAngle)
    {
        //normal vector to the wall
        Vector2 n = new Vector2(Mathf.Cos(wallAngle + Mathf.PI / 2), Mathf.Sin(wallAngle + Mathf.PI / 2));

        // p is the projection of V onto the normal
        float dotproduct = v.GetX() * n.x + v.GetY() * n.y;

        // the velocity after hitting the wall is V - 2p, so just subtract 2*p from V
        return(new Vector2f(v.GetX() - 2f * (dotproduct * n.x), v.GetY() - 2f * (dotproduct * n.y)));
    }
コード例 #5
0
    private static void DrawLine_Smooth_Matrix(Pair2f pair, float z = 0f)
    {
        float size = lineWidth;
        float pi2  = Mathf.PI / 2;

        float rot = Vector2f.Atan2(pair.A, pair.B);

        Vector2f A1 = new Vector2f(pair.A);
        Vector2f A2 = new Vector2f(pair.A);
        Vector2f B1 = new Vector2f(pair.B);
        Vector2f B2 = new Vector2f(pair.B);

        A1.Push(rot + pi2, size);
        A2.Push(rot - pi2, size);
        B1.Push(rot + pi2, size);
        B2.Push(rot - pi2, size);

        GL.TexCoord2(0, 0);
        GL.Vertex3(B1.GetX(), B1.GetY(), z);
        GL.TexCoord2(1, 0);
        GL.Vertex3(A1.GetX(), A1.GetY(), z);
        GL.TexCoord2(1, 1);
        GL.Vertex3(A2.GetX(), A2.GetY(), z);
        GL.TexCoord2(0, 1);
        GL.Vertex3(B2.GetX(), B2.GetY(), z);
    }
コード例 #6
0
ファイル: Demo6Manager.cs プロジェクト: crazymarks/ProjectTP
    void Update()
    {
        Vector2f pos = Slicer2DController.GetMousePosition();

        if (Input.GetMouseButtonDown(0))
        {
            GameObject g = Instantiate(bombPrefab);
            g.transform.position = new Vector3(pos.GetX(), pos.GetY(), -5f);
            g.transform.parent   = transform;
        }

        if (Input.GetMouseButtonDown(1))
        {
            GameObject g = Instantiate(bouncerPrefab);
            g.transform.position = new Vector3(pos.GetX(), pos.GetY(), -5f);
            g.transform.parent   = transform;
        }
    }
コード例 #7
0
ファイル: Speed.cs プロジェクト: zx8326123/LGame
        public static Vector2f GetVelocity(Vector2f velocity, Vector2f force,
                                           float mass)
        {
            Vector2f acceleration = new Vector2f(force.GetX() / mass, force.GetY()
                                                 / mass);

            velocity.Add(acceleration);
            return(velocity);
        }
コード例 #8
0
    static public void DrawImage(Material material, Vector2f pos, Vector2f size, float z = 0f)
    {
        GL.PushMatrix();
        material.SetPass(0);
        GL.Begin(GL.QUADS);

        GL.TexCoord2(0, 0);
        GL.Vertex3(pos.GetX() - size.GetX(), pos.GetY() - size.GetY(), z);
        GL.TexCoord2(0, 1);
        GL.Vertex3(pos.GetX() - size.GetX(), pos.GetY() + size.GetY(), z);
        GL.TexCoord2(1, 1);
        GL.Vertex3(pos.GetX() + size.GetX(), pos.GetY() + size.GetY(), z);
        GL.TexCoord2(1, 0);
        GL.Vertex3(pos.GetX() + size.GetX(), pos.GetY() - size.GetY(), z);

        GL.End();
        GL.PopMatrix();
    }
コード例 #9
0
 static public void DrawLine(Vector2f p0, Vector2f p1, float z = 0f)
 {
     if (setBorder == true)
     {
         Color tmcColor = setColor;
         float tmpWidth = lineWidth;
         SetColor(Color.black);
         lineWidth = tmpWidth * 2f;
         DrawLinef(p0.GetX(), p0.GetY(), p1.GetX(), p1.GetY(), z);
         SetColor(tmcColor);
         lineWidth = tmpWidth;
         DrawLinef(p0.GetX(), p0.GetY(), p1.GetX(), p1.GetY(), z);
         lineWidth = tmpWidth;
     }
     else
     {
         DrawLinef(p0.GetX(), p0.GetY(), p1.GetX(), p1.GetY(), z);
     }
 }
コード例 #10
0
        public float GetValue(float t)
        {
            Vector2f p0 = (Vector2f)curve[0];

            for (int i = 1; i < curve.Count; i++)
            {
                Vector2f p1 = (Vector2f)curve[i];

                if (t >= p0.GetX() && t <= p1.GetX())
                {
                    float st = (t - p0.GetX()) / (p1.GetX() - p0.GetX());
                    float r  = p0.GetY() + st * (p1.GetY() - p0.GetY());
                    return(r);
                }

                p0 = p1;
            }
            return(0);
        }
コード例 #11
0
ファイル: Speed.cs プロジェクト: zx8326123/LGame
        public static Vector2f ElasticForce(Vector2f displacement,
                                            float forceConstant)
        {
            float forceX = -forceConstant *displacement.GetX();

            float forceY = -forceConstant *displacement.GetY();

            Vector2f theForce = new Vector2f(forceX, forceY);

            return(theForce);
        }
コード例 #12
0
 private static int GetQuad(Vector2f axis, Vector2f vert)
 {
     if (vert.GetX() < axis.GetX())
     {
         if (vert.GetY() < axis.GetY())
         {
             return(1);
         }
         return(4);
     }
     if (vert.GetY() < axis.GetY())
     {
         return(2);
     }
     return(3);
 }
コード例 #13
0
 /// <summary>
 /// Angle between two given 2D coordinates
 /// </summary>
 public static float Atan2(Vector2f a, Vector2f b)
 {
     return(Mathf.Atan2(a.GetY() - b.GetY(), a.GetX() - b.GetX()));
 }
コード例 #14
0
 static public void DrawTriangle(Vector2f p0, Vector2f p1, Vector2f p2, Vector2f offset, float z = 0f)
 {
     DrawTrianglef(p0.GetX(), p0.GetY(), p1.GetX(), p1.GetY(), p2.GetX(), p2.GetY(), offset, z);
 }
コード例 #15
0
 /// <summary>
 /// Set x and y components of an existing 2D vector
 /// </summary>
 public void Set(Vector2f point)
 {
     vector.Set(point.GetX(), point.GetY());
 }
コード例 #16
0
 private static void DrawTriangle_Matrix(float x0, float y0, float x1, float y1, float x2, float y2, Vector2f offset, float z = 0f)
 {
     GL.Vertex3(x0 + offset.GetX(), y0 + offset.GetY(), z);
     GL.Vertex3(x1 + offset.GetX(), y1 + offset.GetY(), z);
     GL.Vertex3(x2 + offset.GetX(), y2 + offset.GetY(), z);
 }
コード例 #17
0
 static public void DrawLineSquare(Vector2f p, float size, float z = 0f)
 {
     DrawLineRectf(p.GetX() - size / 2f, p.GetY() - size / 2f, size, size, z);
 }
コード例 #18
0
 public void UpdateLocation(Vector2f vector)
 {
     this.SetX(MathUtils.Round(vector.GetX()));
     this.SetY(MathUtils.Round(vector.GetY()));
 }
コード例 #19
0
ファイル: LObject.cs プロジェクト: vb0067/LGame
 public virtual int X()
 {
     return((int)location.GetX());
 }
コード例 #20
0
 /// <summary>
 /// Representation of 2D points
 /// </summary>
 public Vector2f(Vector2f point)
 {
     vector = new Vector2(point.GetX(), point.GetY());
 }
コード例 #21
0
    public static bool PointInPoly(Vector2f point, List <Vector2f> xy)
    {
        if (xy.Count < 3)
        {
            return(false);
        }

        int total = 0;
        int diff  = 0;

        foreach (Pair2f id in Pair2f.GetList(xy))
        {
            diff = (GetQuad(point, id.A) - GetQuad(point, id.B));

            switch (diff)
            {
            case -2:
            case 2:
                if ((id.B.GetX() - (((id.B.GetY() - point.GetY()) * (id.A.GetX() - id.B.GetX())) / (id.A.GetY() - id.B.GetY()))) < point.GetX())
                {
                    diff = -diff;
                }

                break;

            case 3:
                diff = -1;
                break;

            case -3:
                diff = 1;
                break;

            default:
                break;
            }

            total += diff;
        }

        return(Mathf.Abs(total) == 4);
    }