示例#1
0
        public static void ShowBoundingBoxes(List <Ped> spawned = null)
        {
            List <Entity> entityList;

            if (spawned == null)
            {
                entityList = GetNearbyEntities(200f).ToList();
            }
            else
            {
                entityList = new List <Entity>();
                foreach (Ped p in spawned)
                {
                    entityList.Add((Entity)p);
                }
            }

            var ppos    = World.RenderingCamera.Position;
            var LinePos = new Vector3(ppos.X, ppos.Y, ppos.Z - 0.5f) + World.RenderingCamera.ForwardVector.Normalized;

            //int cnt = 0;
            //int failed = 0;
            float maxRange = 200f;

            RaycastResult res;
            Entity        hitEntity;

            System.Drawing.Color color;

            foreach (Entity e in entityList)
            {
                if (!HashFunctions.IsOnScreen(e))
                {
                    continue;
                }

                Vector3 ePos      = e.Position;
                float   eDistance = ppos.DistanceTo(ePos);
                if (eDistance < maxRange)
                {
                    int cnt = 0;
                    foreach (EntityBone bone in e.Bones)
                    {
                        try
                        {
                            if (cnt++ % 2 == 0)
                            {
                                continue;
                            }
                            res       = World.Raycast(LinePos, bone.Position, IntersectFlags.Everything, Game.Player.Character);
                            hitEntity = res.HitEntity;
                            color     = System.Drawing.Color.Red;
                            //if (hitEntity == null)
                            //{
                            //    color = System.Drawing.Color.Yellow;
                            //}
                            //else if (hitEntity.Handle == e.Handle)
                            //{
                            //    color = System.Drawing.Color.Green;
                            //}
                            World.DrawLine(LinePos, bone.Position, color);
                        }
                        catch
                        {
                            continue;
                        }
                    }
                }
                else
                {
                    color = System.Drawing.Color.Blue;
                    World.DrawLine(LinePos, e.Position, color);
                }
            }

            //res = World.Raycast(LinePos, bonePosition, (IntersectFlags)287, Game.Player.Character);
            //hitEntity = res.HitEntity;
            //System.Drawing.Color color = System.Drawing.Color.Red;
            //if (hitEntity == null)
            //{
            //    color = System.Drawing.Color.Yellow;
            //}
            //else if (hitEntity.Handle == e.Handle)
            //{
            //    color = System.Drawing.Color.Green;
            //}
            //World.DrawLine(LinePos, bone.Position, color);
            //var gtaBone = new GTABone(bone, isVisible, res);

            //foreach (Entity e in entityList)
            //{
            //    var stopwatch = new Stopwatch();
            //    stopwatch.Start();
            //var boundingBox = new GTABoundingBox(e);
            //var corners = boundingBox.CornerPoints;
            //for (int i = 0; i < corners.Length; ++i)
            //{
            //    for (int j = 0; j < corners.Length; ++j)
            //    {
            //        if (j == i) continue;
            //        var c1 = corners[i];
            //        var c2 = corners[j];
            //        HashFunctions.Draw3DLine(c1, c2, 0, 0, 255);
            //    }
            //}
            //var isLOS = Function.Call<bool>((Hash)0x0267D00AF114F17A, Game.Player.Character, e);
            //World.DrawLine(e.Position, e.Position + e.ForwardVector.Normalized, System.Drawing.Color.Blue);
            //List<int> visibleBones = new List<int>();

            //if (e is Ped p)
            //{
            //    foreach (string name in BoneNames)
            //    {
            //        Bone temp = (Bone)Enum.Parse(typeof(Bone), name, true);
            //        var bone = p.Bones[temp];
            //        if (!bone.IsValid)
            //            continue;
            //        var res = World.Raycast(ppos, bone.Position, (IntersectFlags)287, Game.Player.Character);
            //        Entity hitEntity = res.HitEntity;

            //        if (hitEntity.Handle == p.Handle)
            //        {
            //            int successCounter = 0;
            //            while (true)
            //            {
            //                res = World.Raycast(ppos, bone.Position, (IntersectFlags)287, Game.Player.Character);
            //                hitEntity = res.HitEntity;
            //                if (hitEntity != null && hitEntity.Handle == p.Handle)
            //                {
            //                    successCounter++;
            //                    continue;
            //                }
            //                break;
            //            }
            //            System.IO.File.AppendAllText("F:/datasets/GTA_V_anomaly/log.txt", e.EntityType.ToString() + " : failed after " + successCounter + "raycasts.\n");
            //            return;
            //        }

            //int cnt = 0;
            //while (hitEntity == null && cnt < 10)
            //{
            //    Script.Wait(10);
            //    res = World.Raycast(ppos, bone.Position, (IntersectFlags)287, Game.Player.Character);
            //    hitEntity = res.HitEntity;
            //    cnt += 1;
            //}

            //if (cnt == 10)
            //{
            //    System.IO.File.AppendAllText("F:/datasets/GTA_V_anomaly/log.txt", e.EntityType.ToString() + " : hit entity still null after 10 casts.\n");
            //    continue;
            //}

            //        bool visible = false;

            //        if (hitEntity.Handle == p.Handle)
            //        {
            //            visible = true;
            //            //visibleBones.Add(bone.Index);
            //        }
            //    }
            //    if (failed == 0)
            //    {
            //        HashFunctions.Draw3DLine(linePos, e.Position, 0, 0, 255);
            //    }
            //}
            //else
            //{
            //    continue;
            //}
            //else if (e is Vehicle v)
            //{
            //    foreach (EntityBone bone in v.Bones)
            //    {
            //        var res = World.Raycast(ppos, bone.Position, (IntersectFlags)287, Game.Player.Character);
            //        var hitEntity = res.HitEntity;
            //        bool visible = false;

            //        if (hitEntity != null && hitEntity.Handle == e.Handle)
            //        {
            //            visible = true;
            //            //visibleBones.Add(bone.Index);
            //        }
            //    }
            //}
            //stopwatch.Stop();
            //var elapsed = stopwatch.ElapsedMilliseconds;
            //var count = e.Bones.Count;
            //var visbleCount = visibleBones.Count;
            //System.IO.File.AppendAllText("F:/datasets/GTA_V_anomaly/log.txt", e.EntityType.ToString() + " doesnt have " + string.Join(",", missingBones) + "\n"); ;
            //System.IO.File.AppendAllText("F:/datasets/GTA_V_anomaly/log.txt", Bone.BagBody.ToString() + "\n"); ;
            //else
            //World.DrawMarker(MarkerType.DebugSphere, e.Position, Vector3.Zero, Vector3.Zero, new Vector3(0.5f, 0.5f, 0.5f), System.Drawing.Color.Red);

            //foreach (EntityBone bone in e.Bones)
            //{

            //    if (boundingBox.Contains(bone.Position))
            //        {
            //            //World.DrawMarker(MarkerType.DebugSphere, bone.Position, Vector3.Zero, Vector3.Zero, new Vector3(0.05f, 0.05f, 0.05f), System.Drawing.Color.Green);
            //        }
            //        else
            //        {
            //            World.DrawMarker(MarkerType.DebugSphere, bone.Position, Vector3.Zero, Vector3.Zero, new Vector3(0.05f, 0.05f, 0.05f), System.Drawing.Color.Red);
            //        }
            //}
            //}
            //System.IO.File.AppendAllText("F:/datasets/GTA_V_anomaly/log.txt", cnt + " " + failed + ".\n");
        }
示例#2
0
        private static IEnumerable <Entity> GetNearbyEntities(float radius = 200f)
        {
            var entities = World.GetNearbyEntities(World.RenderingCamera.Position, radius);

            return(from entity in entities
                   where entity != null && (entity.Model.IsBicycle || entity.Model.IsBike || entity.Model.IsVehicle || entity.Model.IsPed) && entity.Handle != Game.Player.Character.Handle && HashFunctions.IsOnScreen(entity)
                   select entity);
        }