Exemplo n.º 1
0
        public static GTAData DumpData(string imageName, List <Weather> capturedWeathers)
        {
            var ret = new GTAData();

            ret.Version          = 3;
            ret.ImageName        = imageName;
            ret.CurrentWeather   = World.Weather;
            ret.CapturedWeathers = capturedWeathers;

            ret.Timestamp    = DateTime.UtcNow;
            ret.LocalTime    = World.CurrentDayTime;
            ret.Pos          = new GTAVector(GameplayCamera.Position);
            ret.CamDirection = new GTAVector(GameplayCamera.Direction);
            ret.CamFOV       = GameplayCamera.FieldOfView;
            ret.ImageWidth   = Game.ScreenResolution.Width;
            ret.ImageHeight  = Game.ScreenResolution.Height;
            //ret.Pos = new GTAVector(Game.Player.Character.Position);

            var peds = World.GetNearbyPeds(Game.Player.Character, 150.0f);
            var cars = World.GetNearbyVehicles(Game.Player.Character, 150.0f);
            //var props = World.GetNearbyProps(Game.Player.Character.Position, 300.0f);

            var constants = VisionNative.GetConstants();

            if (!constants.HasValue)
            {
                return(null);
            }
            var W  = MathNet.Numerics.LinearAlgebra.Single.DenseMatrix.OfColumnMajor(4, 4, constants.Value.world.ToArray()).ToDouble();
            var WV =
                MathNet.Numerics.LinearAlgebra.Single.DenseMatrix.OfColumnMajor(4, 4,
                                                                                constants.Value.worldView.ToArray()).ToDouble();
            var WVP =
                MathNet.Numerics.LinearAlgebra.Single.DenseMatrix.OfColumnMajor(4, 4,
                                                                                constants.Value.worldViewProjection.ToArray()).ToDouble();

            var V = WV * W.Inverse();
            var P = WVP * WV.Inverse();

            ret.ProjectionMatrix = P as DenseMatrix;
            ret.ViewMatrix       = V as DenseMatrix;

            var pedList = from ped in peds
                          where ped.IsHuman && ped.IsOnFoot
                          select new GTADetection(ped);
            var cycles = from ped in peds
                         where ped.IsOnBike
                         select new GTADetection(ped, DetectionType.bicycle);

            var vehicleList = from car in cars
                              select new GTADetection(car);

            ret.Detections = new List <GTADetection>();
            ret.Detections.AddRange(pedList);
            ret.Detections.AddRange(vehicleList);
            //ret.Detections.AddRange(cycles);

            return(ret);
        }
Exemplo n.º 2
0
        public static GTAData DumpData(string imageName, List <Weather> capturedWeathers)
        {
            var ret = new GTAData();

            ret.Version          = 3;
            ret.ImageName        = imageName;
            ret.CurrentWeather   = World.Weather;
            ret.CapturedWeathers = capturedWeathers;

            ret.Timestamp = DateTime.UtcNow;
            ret.LocalTime = World.CurrentDayTime;
            ret.CamPos    = new GTAVector(World.RenderingCamera.Position);
            ret.CamRot    = new GTAVector(World.RenderingCamera.Rotation);
            //getting information about currently driving vehicle model size
            Vector3 gmin;
            Vector3 gmax;

            Game.Player.Character.CurrentVehicle.Model.GetDimensions(out gmin, out gmax);
            ret.CarModelBox =
                new BoundingBox((SharpDX.Vector3) new GTAVector(gmin), (SharpDX.Vector3) new GTAVector(gmax));
            ret.CamDirection = new GTAVector(World.RenderingCamera.Direction);
            ret.CamFOV       = World.RenderingCamera.FieldOfView;
            ret.ImageWidth   = Game.ScreenResolution.Width;
            ret.ImageHeight  = Game.ScreenResolution.Height;
            ret.UIWidth      = UI.WIDTH;
            ret.UIHeight     = UI.HEIGHT;
            ret.playerPos    = new GTAVector(Game.Player.Character.Position);
            ret.velocity     = new GTAVector(Game.Player.Character.Velocity);
            ret.CamNearClip  = World.RenderingCamera.NearClip;
            ret.CamFarClip   = World.RenderingCamera.FarClip;

            var peds = World.GetNearbyPeds(Game.Player.Character, 500.0f);
            var cars = World.GetNearbyVehicles(Game.Player.Character, 500.0f);
            //var props = World.GetNearbyProps(Game.Player.Character.Position, 300.0f);

            var constants = VisionNative.GetConstants();

            if (!constants.HasValue)
            {
                return(null);
            }
            var W = MathNet.Numerics.LinearAlgebra.Single.DenseMatrix
                    .OfColumnMajor(4, 4, constants.Value.world.ToArray()).ToDouble();
            var WV =
                MathNet.Numerics.LinearAlgebra.Single.DenseMatrix.OfColumnMajor(4, 4,
                                                                                constants.Value.worldView.ToArray()).ToDouble();
            var WVP =
                MathNet.Numerics.LinearAlgebra.Single.DenseMatrix.OfColumnMajor(4, 4,
                                                                                constants.Value.worldViewProjection.ToArray()).ToDouble();

            var V = WV * W.Inverse();
            var P = WVP * WV.Inverse();

            ret.ProjectionMatrix = P as DenseMatrix;
            ret.ViewMatrix       = V as DenseMatrix;
            ret.WorldMatrix      = W as DenseMatrix;

            var pedList = from ped in peds
                          where ped.IsHuman && ped.IsOnFoot
//                where ped.IsHuman && ped.IsOnFoot && CheckVisible(ped)
                          select new GTADetection(ped);
            var cycles = from ped in peds
                         where ped.IsOnBike
//                where ped.IsOnBike && CheckVisible(ped)
                         select new GTADetection(ped, DetectionType.bicycle);

            var vehicleList = from car in cars
//                where CheckVisible(car)
                              select new GTADetection(car);

            ret.Detections = new List <GTADetection>();
            ret.Detections.AddRange(pedList);
            ret.Detections.AddRange(vehicleList);
            //ret.Detections.AddRange(cycles);

            return(ret);
        }