Exemple #1
0
        public override void BeforeStart()
        {
            base.BeforeStart();
            Camera = MyAPIGateway.Session.Camera;
            var aspectRatio = Camera.ViewportSize.X / Camera.ViewportSize.Y;

            customProjectionMatrix = MatrixD.CreatePerspectiveFieldOfView(Camera.FovWithZoom, aspectRatio, 0.1f, 70.0f);
        }
        public void Prepare()
        {
            var vs = MyAPIGateway.Session.Camera.ViewportSize;

            _leftTop             = MyAPIGateway.Session.Camera.WorldLineFromScreen(Vector2.Zero).GetPoint(0.01);
            _leftBottom          = MyAPIGateway.Session.Camera.WorldLineFromScreen(new Vector2(0, vs.Y - 1)).GetPoint(0.01);
            _rightTop            = MyAPIGateway.Session.Camera.WorldLineFromScreen(new Vector2(vs.X - 1, 0)).GetPoint(0.01);
            _leftToRight         = _rightTop - _leftTop;
            _topToBottom         = _leftBottom - _leftTop;
            _origin              = MyAPIGateway.Session.Camera.Position;
            _camera              = MyAPIGateway.Session.Camera;
            _matrix              = _camera.WorldMatrix;
            ViewProjectionMatrix = _camera.ViewMatrix * _camera.ProjectionMatrix;
        }
Exemple #3
0
 public PersonViewModel(IPersonService personService, IMyCamera _myCam, ICustomAlert alert)
 {
     this.personService = personService;
     myCamera           = _myCam;
     customAlert        = alert;
 }
Exemple #4
0
        bool UpdateParticles(bool spawn)
        {
            if (!Main.Settings.sprayParticles)
            {
                return(false);
            }

            IMyCamera camera = MyAPIGateway.Session?.Camera;

            if (camera == null)
            {
                return(false);
            }

            MatrixD matrix = Rifle.WorldMatrix;

            if (Vector3D.DistanceSquared(camera.WorldMatrix.Translation, matrix.Translation) > SprayMaxViewDistSq)
            {
                return(false);
            }

            bool paused = Main.IsPaused;

            if (!paused && spawn)
            {
                Particle particle = Main.ToolHandler.GetPooledParticle();
                particle.Init(matrix, ParticleColor);
                Particles.Add(particle);
            }

            if (Particles.Count > 0)
            {
                //const double NozzlePosX = 0.06525;
                //const double NozzlePosZ = 0.16;
                //Vector3D muzzleWorldPos = matrix.Translation + matrix.Up * NozzlePosX + matrix.Forward * NozzlePosZ;
                Vector3D muzzleWorldPos = Rifle.GetMuzzlePosition();

                for (int i = Particles.Count - 1; i >= 0; i--)
                {
                    Particle p = Particles[i];

                    MyTransparentGeometry.AddPointBillboard(SprayMaterial, p.Color, muzzleWorldPos + p.RelativePosition, p.Radius, p.Angle, blendType: SprayBlendType);

                    if (!paused)
                    {
                        if (--p.Life <= 0 || p.Color.A <= 0)
                        {
                            Particles.RemoveAtFast(i);
                            Main.ToolHandler.ReturnParticleToPool(p);
                            continue;
                        }

                        if (p.Angle > 0)
                        {
                            p.Angle += (p.Life * 0.001f);
                        }
                        else
                        {
                            p.Angle -= (p.Life * 0.001f);
                        }

                        p.RelativePosition += p.VelocityPerTick;
                        p.VelocityPerTick  *= 1.3f;
                        p.Radius           *= MyUtils.GetRandomFloat(1.25f, 1.45f);

                        if (p.Life <= 20)
                        {
                            p.Color *= 0.7f;
                        }
                    }
                }
            }

            return(true);
        }
Exemple #5
0
 public static bool IsInFrustum(this IMyCamera cam, ref Vector3D point)
 {
     return(cam.WorldToScreen(ref point).AbsMax() <= 1);
 }
Exemple #6
0
        public override void UpdateBeforeSimulation()
        {
            if (MyAPIGateway.Session == null)
            {
                return;
            }
            if (MyAPIGateway.Utilities.IsDedicated)
            {
                return;
            }

            if (!m_initialize)
            {
                Initialize();
            }

            if (nearEffects.Count + farEffects.Count > 0)
            {
                IMyCamera cam        = MyAPIGateway.Session.Camera;
                Vector3D  pos        = cam.Position;
                Vector3D  vel        = (pos - lastCamPos) / (DateTime.Now - lastCamTime).TotalSeconds;
                Vector3D  camForward = cam.WorldMatrix.Forward;
                Vector3D  camLeft    = cam.WorldMatrix.Left;
                Vector3D  camUp      = cam.WorldMatrix.Up;

                lastCamTime = DateTime.Now;
                lastCamPos  = pos;

                pos += vel;
                Vector3D grav = new Vector3D(0);
                {
                    var planets = new List <IMyVoxelBase>();
                    MyAPIGateway.Session.VoxelMaps.GetInstances(planets, v => v is MyPlanet);
                    foreach (IMyVoxelBase planet in planets)
                    {
                        MyGravityProviderComponent gravC = planet.Components.Get <MyGravityProviderComponent>();
                        if (gravC != null)
                        {
                            grav += gravC.GetWorldGravity(pos);
                        }
                    }
                }
                Vector3D up = -grav;
                up.Normalize();
                Vector3D forward = Vector3D.Cross(Vector3D.Cross(up, camForward), up);
                forward.Normalize();
                Random r      = new Random();
                double tanFOV = Math.Tan(Math.PI * cam.FieldOfViewAngle / 360.0);
                foreach (MyParticleEffect effect in nearEffects)
                {
                    double   dist    = (2 * r.NextDouble() - 1) * 10;
                    double   theta   = r.NextDouble() * Math.PI * 2;
                    double   lrField = Math.Abs(tanFOV * dist) + 5;
                    Vector3D refPos  = pos + (camForward * Math.Cos(theta) * dist) + (camLeft * dist * Math.Sin(theta)) + (lrField * camUp * (r.NextDouble() * 2 - 1));
                    effect.WorldMatrix = MatrixD.CreateWorld(refPos, forward, up);
                }
                foreach (MyParticleEffect effect in farEffects)
                {
                    double   dist    = 10 + r.NextDouble() * 50;
                    double   lrMod   = (r.NextDouble() * 2) - 1;
                    double   lrField = Math.Abs(tanFOV * dist);
                    Vector3D refPos  = pos + (camForward * dist) + (lrMod * lrField * camLeft) + (lrField * camUp * (r.NextDouble() * 2 - 1));
                    effect.WorldMatrix = MatrixD.CreateWorld(refPos, forward, up);
                }
            }

            //Logging.Instance.Log("Did a thing");
        }