Exemplo n.º 1
0
        // Generate random point in polygon
        public static GTAVector RandPointInPoly(GTALocation x)
        {
            float maxX = float.MinValue;
            float maxY = float.MinValue;
            float minX = float.MaxValue;
            float minY = float.MaxValue;
            float avgZ = 0f;

            foreach (GTAVector v in x.ROI)
            {
                maxX  = Math.Max(maxX, v.X);
                maxY  = Math.Max(maxY, v.Y);
                minX  = Math.Min(minX, v.X);
                minY  = Math.Min(minY, v.Y);
                avgZ += v.Z;
            }
            avgZ /= x.ROI.Count;
            avgZ += 0.5f;
            while (true)
            {
                GTAVector v = new GTAVector(random.NextFloat(minX, maxX), random.NextFloat(minY, maxY), avgZ);
                if (PointInPoly(x, v))
                {
                    return(v);
                }
            }
        }
Exemplo n.º 2
0
        public static GTAVector Lerp(GTAVector from, GTAVector to, float by)
        {
            var x = from.X * (1 - by) + to.X * by;
            var y = from.Y * (1 - by) + to.Y * by;
            var z = from.Z * (1 - by) + to.Z * by;

            return(new GTAVector(x, y, z));
        }
Exemplo n.º 3
0
        public static bool PointInPoly(GTALocation loc, GTAVector v)
        {
            int   max_point   = loc.ROI.Count - 1;
            float total_angle = GetAngle(loc.ROI[max_point].X, loc.ROI[max_point].Y, v.X, v.Y, loc.ROI[0].X, loc.ROI[0].Y);

            for (int i = 0; i < max_point; i++)
            {
                total_angle += GetAngle(
                    loc.ROI[i].X, loc.ROI[i].Y,
                    v.X, v.Y,
                    loc.ROI[i + 1].X, loc.ROI[i + 1].Y);
            }
            return(Math.Abs(total_angle) > 1);
        }
Exemplo n.º 4
0
 public static void Draw3DLine(GTAVector iniPos, GTAVector finPos, byte col_r = 255, byte col_g = 255, byte col_b = 255, byte col_a = 255)
 {
     Function.Call(Hash.DRAW_LINE, new InputArgument[]
     {
         iniPos.X,
         iniPos.Y,
         iniPos.Z,
         finPos.X,
         finPos.Y,
         finPos.Z,
         (int)col_r,
         (int)col_g,
         (int)col_b,
         (int)col_a
     });
 }
Exemplo n.º 5
0
        public static float PolygonArea(List <GTAVector> ROI)
        {
            int count = ROI.Count;

            GTAVector[] pts = new GTAVector[count + 1];
            ROI.CopyTo(pts, 0);
            pts[count] = ROI[0];

            double area = 0;

            for (int i = 0; i < count; i++)
            {
                area +=
                    (pts[i + 1].X - pts[i].X) *
                    (pts[i + 1].Y + pts[i].Y) / 2;
            }
            return((float)Math.Abs(area));
        }
Exemplo n.º 6
0
        public static Vector2 Convert3dTo2d(GTAVector pos, out bool success)
        {
            OutputArgument tmpResX = new OutputArgument();
            OutputArgument tmpResY = new OutputArgument();

            success = Function.Call <bool>(Hash.GET_SCREEN_COORD_FROM_WORLD_COORD, (InputArgument)pos.X, (InputArgument)pos.Y, (InputArgument)pos.Z, (InputArgument)tmpResX, (InputArgument)tmpResY);

            if (success)
            {
                Vector2 v2;
                v2.X = tmpResX.GetResult <float>();
                v2.Y = tmpResY.GetResult <float>();
                return(v2);
            }
            else
            {
                return(new Vector2(-1f, -1f));
            }
        }
Exemplo n.º 7
0
 public static double EuclideanDistance(GTAVector p1, GTAVector p2)
 {
     return(Math.Sqrt(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Y - p2.Y, 2)));
 }
Exemplo n.º 8
0
        public GTABoundingBox(Entity e)
        {
            var dim = new GTAVector();
            var e1  = new GTAVector();
            var e2  = new GTAVector();
            var e3  = new GTAVector();
            var e4  = new GTAVector();
            var e5  = new GTAVector();
            var e6  = new GTAVector();
            var e7  = new GTAVector();
            var e8  = new GTAVector();

            (var gmin, var gmax) = e.Model.Dimensions;

            var rightVector   = e.ForwardVector;
            var upVector      = e.UpVector;
            var forwardVector = e.RightVector;

            var position = e.Position;

            //Calculate siZe
            dim.X = 0.5f * (gmax.X - gmin.X);
            dim.Y = 0.5f * (gmax.Y - gmin.Y);
            dim.Z = 0.5f * (gmax.Z - gmin.Z);

            e1.X = position.X - dim.Y * rightVector.X - dim.X * forwardVector.X - dim.Z * upVector.X;
            e1.Y = position.Y - dim.Y * rightVector.Y - dim.X * forwardVector.Y - dim.Z * upVector.Y;
            e1.Z = position.Z - dim.Y * rightVector.Z - dim.X * forwardVector.Z - dim.Z * upVector.Z;

            e2.X = e1.X + 2 * dim.Y * rightVector.X;
            e2.Y = e1.Y + 2 * dim.Y * rightVector.Y;
            e2.Z = e1.Z + 2 * dim.Y * rightVector.Z;

            e3.X = e2.X + 2 * dim.Z * upVector.X;
            e3.Y = e2.Y + 2 * dim.Z * upVector.Y;
            e3.Z = e2.Z + 2 * dim.Z * upVector.Z;

            e4.X = e1.X + 2 * dim.Z * upVector.X;
            e4.Y = e1.Y + 2 * dim.Z * upVector.Y;
            e4.Z = e1.Z + 2 * dim.Z * upVector.Z;

            e5.X = position.X + dim.Y * rightVector.X + dim.X * forwardVector.X + dim.Z * upVector.X;
            e5.Y = position.Y + dim.Y * rightVector.Y + dim.X * forwardVector.Y + dim.Z * upVector.Y;
            e5.Z = position.Z + dim.Y * rightVector.Z + dim.X * forwardVector.Z + dim.Z * upVector.Z;

            e6.X = e5.X - 2 * dim.Y * rightVector.X;
            e6.Y = e5.Y - 2 * dim.Y * rightVector.Y;
            e6.Z = e5.Z - 2 * dim.Y * rightVector.Z;

            e7.X = e6.X - 2 * dim.Z * upVector.X;
            e7.Y = e6.Y - 2 * dim.Z * upVector.Y;
            e7.Z = e6.Z - 2 * dim.Z * upVector.Z;

            e8.X = e5.X - 2 * dim.Z * upVector.X;
            e8.Y = e5.Y - 2 * dim.Z * upVector.Y;
            e8.Z = e5.Z - 2 * dim.Z * upVector.Z;

            CornerPoints = new GTAVector[] { e1, e2, e3, e4, e5, e6, e7, e8 };

            foreach (GTAVector v in CornerPoints)
            {
                x_max = Math.Max(x_max, v.X);
                x_min = Math.Min(x_min, v.X);

                y_max = Math.Max(y_max, v.Y);
                y_min = Math.Min(y_min, v.Y);

                z_max = Math.Max(z_max, v.Z);
                z_min = Math.Min(z_min, v.Z);
            }
        }
Exemplo n.º 9
0
 public bool Contains(GTAVector p)
 {
     return((p.X <= x_max && p.X >= x_min) && (p.Y <= y_max && p.Y >= y_min) && (p.Z <= z_max && p.Z >= z_min));
 }