Example #1
0
        public static void Draw(this MyOrientedBoundingBoxD obb, Color color, MySimpleObjectRasterizer raster = MySimpleObjectRasterizer.Solid, float thickness = 0.5f, MyStringId?material = null)
        {
            var box = new BoundingBoxD(-obb.HalfExtent, obb.HalfExtent);
            var wm  = MatrixD.CreateFromTransformScale(obb.Orientation, obb.Center, Vector3D.One);

            MySimpleObjectDraw.DrawTransparentBox(ref wm, ref box, ref color, raster, 1, thickness, material ?? Square, material ?? Square);
        }
Example #2
0
        public static void DrawBox(MyOrientedBoundingBoxD obb, Color color)
        {
            var box = new BoundingBoxD(-obb.HalfExtent, obb.HalfExtent);
            var wm  = MatrixD.CreateFromTransformScale(obb.Orientation, obb.Center, Vector3D.One);

            MySimpleObjectDraw.DrawTransparentBox(ref wm, ref box, ref color, MySimpleObjectRasterizer.Solid, 1);
        }
        public ShieldRenderer(IMySlimBlock block, ShieldRenderMode mode, ShieldColor color, float shieldStatus, bool deformation)
        {
            m_block        = block;
            m_shieldStatus = shieldStatus;

            MyCubeBlockDefinition blockDefinition = block.BlockDefinition as MyCubeBlockDefinition;


            var blockSize = blockDefinition.Size;

            if (blockDefinition.CubeSize == MyCubeSize.Large)
            {
                m_shieldScale.X = blockDefinition.Size.X + 0.1;
                m_shieldScale.Y = blockDefinition.Size.Y + 0.1;
                m_shieldScale.Z = blockDefinition.Size.Z + 0.1;
            }
            else
            {
                m_shieldScale.X = (blockDefinition.Size.X + 0.1) * 0.2d;
                m_shieldScale.Y = (blockDefinition.Size.Y + 0.1) * 0.2d;
                m_shieldScale.Z = (blockDefinition.Size.Z + 0.1) * 0.2d;
            }

            Vector3D shieldPosition;

            if (block.FatBlock == null)
            {
                shieldPosition = block.CubeGrid.GridIntegerToWorld(block.Position);

                m_matrix = MatrixD.CreateFromTransformScale(Quaternion.CreateFromRotationMatrix(block.CubeGrid.WorldMatrix.GetOrientation()), shieldPosition, m_shieldScale);

                if (EnergyShieldsCore.Config.Effects.PlaySound)
                {
                    m_soundEmitter = new MyEntity3DSoundEmitter((MyEntity)block.CubeGrid);
                }
            }
            else
            {
                shieldPosition = block.FatBlock.WorldMatrix.Translation;

                m_matrix = MatrixD.CreateFromTransformScale(Quaternion.CreateFromRotationMatrix(block.FatBlock.WorldMatrix.GetOrientation()), shieldPosition, m_shieldScale);

                if (EnergyShieldsCore.Config.Effects.PlaySound)
                {
                    m_soundEmitter = new MyEntity3DSoundEmitter((MyEntity)block.FatBlock);
                }
            }

            if (EnergyShieldsCore.Config.Effects.PlaySound)
            {
                m_soundEmitter.SetPosition(shieldPosition);

                if (deformation)
                {
                    m_soundEmitter.CustomVolume = 0.05f;
                }

                m_soundEmitter.PlaySound(new MySoundPair(soundNameNormal + "High"));
            }
        }
 public override void UpdateAfterSimulation()
 {
     if (DEBUG)
     {
         MatrixD weldTransform = MatrixD.CreateFromTransformScale(new Quaternion(), Entity.GetPosition() + Entity.WorldMatrix.Forward * SPHERE_OFFSET, Vector3.One);
         Color   sphereColor   = Color.White;
         MySimpleObjectDraw.DrawTransparentSphere(ref weldTransform, SPHERE_RADIUS, ref sphereColor, MySimpleObjectRasterizer.Solid, 20);
     }
 }
Example #5
0
        private void PerformJump(Vector3D jumpTarget)
        {
            m_jumpDirection = jumpTarget - m_grid.WorldMatrix.Translation;

            MyParticleEffect effect;

            if (MyParticlesManager.TryCreateParticleEffect(53, out effect))
            {
                effect.WorldMatrix = MatrixD.CreateFromTransformScale(Quaternion.Identity, m_grid.WorldMatrix.Translation, Vector3D.One);
                effect.UserScale   = (float)m_grid.PositionComp.WorldAABB.HalfExtents.AbsMax() / 25f;
                effect.AutoDelete  = true;
            }

            BoundingBoxD aggregateBox = m_grid.PositionComp.WorldAABB;

            foreach (var grid in m_shipInfo.Keys)
            {
                aggregateBox.Include(grid.PositionComp.WorldAABB);
            }
            MyPhysics.Clusters.EnsureClusterSpace(aggregateBox + m_jumpDirection);

            bool updateSpectator = false;

            if (IsLocalCharacterAffectedByJump())
            {
                updateSpectator = true;
            }

            if (updateSpectator)
            {
                MyThirdPersonSpectator.Static.ResetPosition(0.0, null);
                MyThirdPersonSpectator.Static.ResetDistance();
                MyThirdPersonSpectator.Static.RecalibrateCameraPosition();
            }

            m_jumped = true;

            foreach (var grid in m_shipInfo.Keys)
            {
                MatrixD gridMatrix = grid.WorldMatrix;
                gridMatrix.Translation = grid.WorldMatrix.Translation + m_jumpDirection;
                grid.WorldMatrix       = gridMatrix;
            }

            if (updateSpectator)
            {
                MyThirdPersonSpectator.Static.ResetPosition(0.0, null);
                MyThirdPersonSpectator.Static.ResetDistance();
                MyThirdPersonSpectator.Static.RecalibrateCameraPosition();
            }
        }
Example #6
0
        private void spawnImpactParticle(Vector3D pos, Vector3 dir)
        {
            dir.Normalize();
            var matrix = MatrixD.CreateFromTransformScale(Quaternion.CreateFromForwardUp(-dir, Vector3.Up), pos,
                                                          Vector3D.One);

            MyParticleEffect effect;

            if (MyParticlesManager.TryCreateParticleEffect("MaterialHit_Metal_GatlingGun", ref matrix, ref pos, uint.MaxValue, out effect))
            {
                effect.Play();
                effect.UserScale = 0.2f;
            }
        }
Example #7
0
        public override void Draw()
        {
            base.Draw();
            foreach (var line in m_lines)
            {
                MyRenderProxy.DebugDrawLine3D(line.From, line.To, line.ColorFrom, line.ColorTo, line.DepthRead);
            }

            if (ShowDebugDrawTests)
            {
                Vector3D position = new Vector3D(1000000000.0, 1000000000.0, 1000000000.0);
                MyRenderProxy.DebugDrawLine3D(position, position + Vector3D.Up, Color.Red, Color.Blue, true);
                position += Vector3D.Left;
                MyRenderProxy.DebugDrawLine3D(position, position + Vector3D.Up, Color.Red, Color.Blue, false);

                MyRenderProxy.DebugDrawLine2D(new Vector2(10, 10), new Vector2(50, 50), Color.Red, Color.Blue);

                position += Vector3D.Left;
                MyRenderProxy.DebugDrawPoint(position, Color.White, true);
                position += Vector3D.Left;
                MyRenderProxy.DebugDrawPoint(position, Color.White, false);

                position += Vector3D.Left;
                MyRenderProxy.DebugDrawSphere(position, 0.5f, Color.White, 1.0f, true);

                position += Vector3D.Left;
                MyRenderProxy.DebugDrawAABB(new BoundingBoxD(position - Vector3D.One * 0.5, position + Vector3D.One * 0.5), Color.White, 1.0f, 1.0f, true);

                position += Vector3D.Left;
                //MyRenderProxy.DebugDrawCone(position, Vector3D.Up, Vector3D.One, Color.Yellow, true);
                position += Vector3D.Left;
                MyRenderProxy.DebugDrawAxis(MatrixD.CreateFromTransformScale(Quaternion.Identity, position, Vector3D.One * 0.5), 1.0f, true);
                position += Vector3D.Left;
                MyRenderProxy.DebugDrawOBB(new MyOrientedBoundingBoxD(position, Vector3D.One * 0.5, Quaternion.Identity), Color.White, 1.0f, true, false);
                position += Vector3D.Left;
                MyRenderProxy.DebugDrawCylinder(MatrixD.CreateFromTransformScale(Quaternion.Identity, position, Vector3D.One * 0.5), Color.White, 1.0f, true, true);
                position += Vector3D.Left;
                MyRenderProxy.DebugDrawTriangle(position, position + Vector3D.Up, position + Vector3D.Left, Color.White, true, true);
                position += Vector3D.Left;
                var msg = MyRenderProxy.PrepareDebugDrawTriangles();
                msg.AddTriangle(position, position + Vector3D.Up, position + Vector3D.Left);
                msg.AddTriangle(position, position + Vector3D.Left, position - Vector3D.Up);
                MyRenderProxy.DebugDrawTriangles(msg, MatrixD.Identity, Color.White, true, true);
                position += Vector3D.Left;
                MyRenderProxy.DebugDrawCapsule(position, position + Vector3D.Up, 0.5f, Color.White, true);
                MyRenderProxy.DebugDrawText2D(new Vector2(100, 100), "text", Color.Green, 1.0f);
                position += Vector3D.Left;
                MyRenderProxy.DebugDrawText3D(position, "3D Text", Color.Blue, 1.0f, true);
            }
        }
Example #8
0
        /// <summary>
        /// Move the grabbed entity to the current target position.
        /// </summary>
        public void MoveGrabbed()
        {
            if (!(grabbedEntity?.Closed ?? true) && !(character?.Closed ?? true))
            {
                //Calculate the rotation amount and new translation for the grabbed entity.
                MatrixD  deltaOrientation  = MatrixD.Transpose(iCamOrient) * HeadTransform.GetOrientation();
                Vector3D targetTranslation = HeadTransform.Translation + Vector3D.Transform(grabVector, deltaOrientation);

                var worldGrabPos = Vector3D.Transform(localGrabPos, grabbedEntity.WorldMatrix);

                //Calculate target force direction and magnitude
                var posError      = targetTranslation - worldGrabPos;
                var distanceRatio = posError.LengthSquared() / 625f;

                if (distanceRatio > 1f)
                {
                    ReleaseGrabbed();
                    return;
                }

                var velError = character.Physics.LinearVelocity - grabbedEntity.Physics.LinearVelocity;

                var totalError = posError + velError;
                var forceMag   = (float)Math.Pow(totalError.Length() * grabbedEntity.Physics.Mass, Settings.Instance.ForceMult);

                if (forceMag > 100000)
                {
                    forceMag = 100000;
                }

                var force = Vector3D.Normalize(posError) * forceMag;

                grabbedEntity.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, force, worldGrabPos, null);

                //Graphics stuff
                if (!Extensions.HasGui())
                {
                    var lineColor = Vector4.Lerp(Color.LimeGreen, Color.Red, (float)distanceRatio);
                    lineColor.W = Settings.Instance.Opacity;
                    var grabMatrix   = MatrixD.CreateFromTransformScale(Quaternion.Identity, worldGrabPos, Vector3D.One);
                    var targetMatrix = MatrixD.CreateFromTransformScale(Quaternion.Identity, targetTranslation, Vector3D.One);
                    var sphereColor  = (Color)lineColor;
                    MySimpleObjectDraw.DrawTransparentSphere(ref grabMatrix, 0.2f, ref sphereColor, MySimpleObjectRasterizer.Solid, 20);
                    MySimpleObjectDraw.DrawTransparentSphere(ref targetMatrix, 0.2f, ref sphereColor, MySimpleObjectRasterizer.Solid, 20);
                    MySimpleObjectDraw.DrawLine(targetTranslation, worldGrabPos, "SquareFullColor", ref lineColor, 0.2f * (forceMag / 100000f));
                }
            }
        }
Example #9
0
        public void Update()
        {
            if (!leftHit.IsValid || !rightHit.IsValid || IsBroken)
            {
                return;
            }

            if (leftHit.GrabbedObject == rightHit.GrabbedObject)
            {
                Break();
                return;
            }

            var displacement = leftHit.WorldPosition - rightHit.WorldPosition;
            var forceMag     = (displacement.Length() - targetLength) * springConstant;

            if (forceMag > breakForce)
            {
                Break();
                return;
            }

            if (leftHit.PhysicsEntity != rightHit.PhysicsEntity)
            {
                var force = Vector3D.Normalize(displacement) * forceMag;

                if (direction <= 0)
                {
                    leftHit.PhysicsEntity.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, -force, leftHit.WorldPosition, null);
                }
                if (direction >= 0)
                {
                    rightHit.PhysicsEntity.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, force, rightHit.WorldPosition, null);
                }
            }

            if (Extensions.HasGui())
            {
                var lineColor = Vector4.Lerp(Color.LimeGreen, Color.Red, (float)(forceMag / breakForce));
                lineColor.W = Settings.Instance.Opacity;
                var leftMatrix  = MatrixD.CreateFromTransformScale(Quaternion.Identity, leftHit.WorldPosition, Vector3D.One);
                var rightMatrix = MatrixD.CreateFromTransformScale(Quaternion.Identity, rightHit.WorldPosition, Vector3D.One);
                var sphereColor = (Color)lineColor;
                MySimpleObjectDraw.DrawTransparentSphere(ref leftMatrix, 0.2f, ref sphereColor, MySimpleObjectRasterizer.Solid, 20);
                MySimpleObjectDraw.DrawTransparentSphere(ref rightMatrix, 0.2f, ref sphereColor, MySimpleObjectRasterizer.Solid, 20);
                MySimpleObjectDraw.DrawLine(leftHit.WorldPosition, rightHit.WorldPosition, "SquareFullColor", ref lineColor, 0.2f);
            }
        }
Example #10
0
        private static void PreloadCrashingData()
        {
            MyParticleEffect effect;

            if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Collision_Meteor, out effect))
            {
                effect.WorldMatrix = MatrixD.CreateFromTransformScale(Quaternion.Identity, Vector3D.Zero, Vector3D.One);
            }

            ListReader <MyDebrisDefinition> debrisDefinitions = MyDefinitionManager.Static.GetDebrisDefinitions();

            foreach (var definition in debrisDefinitions)
            {
                VRage.Game.Models.MyModels.GetModelOnlyData(definition.Model);
            }
        }
Example #11
0
        private void PlayParticleEffect()
        {
            if (m_effectPlayed)
            {
                return;
            }

            m_effectPlayed = true;
            MyParticleEffect effect;

            if (MyParticlesManager.TryCreateParticleEffect(53, out effect))
            {
                effect.WorldMatrix = MatrixD.CreateFromTransformScale(Quaternion.Identity, m_grid.WorldMatrix.Translation, Vector3D.One);
                effect.UserScale   = (float)m_grid.PositionComp.WorldAABB.HalfExtents.AbsMax() / 25f;
                effect.AutoDelete  = true;
            }
        }
        /// <summary>
        /// Updates (or creates a new, if the contact was previously not
        /// visible) the marker on a track
        /// </summary>
        /// <param name="t"></param>
        private void AddUpdateTrackMarker(Track t)
        {
            string title = $"~Track {t.trackId} ({(int)t.xsec}m²)~";

            if (t.marker == null)
            {
                // If the entity is not null, attach the marker directly to it
                // Otherwise create one in space and we'll update it manually
                if (t.ent != null)
                {
                    t.marker = new MyAreaMarker(
                        new MyPositionAndOrientation(t.ent.LocalAABB.Center, Vector3.Forward, Vector3.Up),
                        new MyAreaMarkerDefinition()
                    {
                        DisplayNameEnum = MyStringId.GetOrCompute(title),
                    });
                    t.marker.AddHudMarker();
                }
                else
                {
                    t.marker = new MyAreaMarker(
                        new MyPositionAndOrientation(MatrixD.CreateFromTransformScale(
                                                         Quaternion.Identity,
                                                         t.position,
                                                         new Vector3D(1, 1, 1))),
                        new MyAreaMarkerDefinition()
                    {
                        DisplayNameEnum = MyStringId.GetOrCompute(title),
                    });
                    t.marker.AddHudMarker();
                    t.marker.Save      = false;
                    t.marker.SyncFlag  = false;
                    t.marker.IsPreview = true;
                }
            }
            else
            {
                //_logger.debugLog("Updating existing GPS marker", "AddUpdateTrackMarker");
                if (t.ent == null)
                {
                    t.marker.PositionComp.SetPosition(t.position);
                    t.marker.DisplayName = title;
                }
            }
        }
Example #13
0
        private void spawnLaunchParticle(Vector3D pos, Vector3D dir)
        {
            dir.Normalize();
            var matrix = MatrixD.CreateFromTransformScale(Quaternion.CreateFromForwardUp(dir, Vector3.Up), pos,
                                                          Vector3D.One);

            if (!((MyAPIGateway.Session.Player.GetPosition() - pos).Length() < 150))
            {
                return;
            }

            MyParticleEffect effect;

            if (MyParticlesManager.TryCreateParticleEffect("Muzzle_Flash_NPC", ref matrix, ref pos, uint.MaxValue, out effect))
            {
                effect.Play();
                //effect.Loop = false;
            }
        }
Example #14
0
        private void moveChute()
        {
            if (chute == null || chute.Closed || chute.MarkedForClose)
            {
                deployStage = 0;
                step        = 0;

                return;
            }

            if (block.Parent.Physics.LinearVelocity.Length() > 2)
            {
                lastvector = block.Parent.Physics.LinearVelocity;
                cutstep    = 0;
            }
            else
            {
                lastvector = Vector3.Lerp(lastvector, -gravity, 0.05f);
                if (Vector3.Distance(lastvector, -gravity) < 0.05d)
                {
                    cutstep++;
                    if (cutstep > 60)
                    {
                        cutChute();
                    }
                }
            }


            Vector3D lvNorm = Vector3D.Normalize(lastvector);

            rotstep++;
            var        rotmat = Matrix.CreateFromDir(lvNorm, new Vector3(0, 1, 0));
            Quaternion rot    = Quaternion.CreateFromRotationMatrix(rotmat.GetOrientation());         //Quaternion.FromVector4(new Vector4(Vector3.Normalize(block.WorldMatrix.Forward), 0));

            rot = Quaternion.Lerp(lastrot, rot, 0.02f);
            var newscale = new Vector3D(scalex, scaley, scalez * 10);

            newscale = Vector3D.Lerp(lastscale, newscale, 0.02d);
            radius   = newscale.X / 2;          //this will always be true ;)
            if (radius <= 0.0d)
            {
                return;
            }
            MatrixD mat = MatrixD.CreateFromTransformScale(rot, block.WorldMatrix.Translation + (block.WorldMatrix.Up * (block.CubeGrid.GridSize / 2d)), newscale);            //

            lastscale = newscale;
            lastrot   = rot;
            chute.SetWorldMatrix(mat);
            var cgrid = (IMyCubeGrid)chute;

            if (block.Parent.Physics.LinearVelocity.Length() <= 1)
            {
                return;
            }
            if (atmosphere < 0.2d)
            {
                return;
            }
            Vector3D drag = -lvNorm;
            double   a    = Math.PI * radius * radius;
            double   c    = (2.5d * (atmosphere * 1.225d) * lastvector.LengthSquared() * a);

            if (c > 0d)
            {
                block.CubeGrid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, Vector3D.Multiply(drag, c), block.WorldMatrix.Translation, Vector3.Zero);
            }
        }
Example #15
0
        public override void Draw()
        {
            base.Draw();

            //var worldToLocal = MatrixD.Normalize(MatrixD.Invert(Container.Entity.PositionComp.WorldMatrix));

            if (m_thrust.CanDraw())
            {
                m_thrust.UpdateThrustFlame();
                m_thrust.UpdateThrustColor();

                foreach (var flame in m_thrust.Flames)
                {
                    if (m_thrust.CubeGrid.Physics == null)
                    {
                        continue;
                    }

                    MyCubeBlock cubeBlock      = Container.Entity as MyCubeBlock;
                    float       scale          = cubeBlock != null ? cubeBlock.CubeGrid.GridScale : 1.0f;
                    var         flameDirection = Vector3D.TransformNormal(flame.Direction, Container.Entity.PositionComp.WorldMatrix);
                    var         flamePosition  = Vector3D.Transform(flame.Position, Container.Entity.PositionComp.WorldMatrix);
                    float       radius         = m_thrust.ThrustRadiusRand * flame.Radius * scale;
                    float       length         = m_thrust.ThrustLengthRand * flame.Radius * scale;
                    float       thickness      = m_thrust.ThrustThicknessRand * flame.Radius * scale;

                    //Vector3D velocityAtNewCOM = Vector3D.Cross(m_thrust.CubeGrid.Physics.AngularVelocity, flamePosition - m_thrust.CubeGrid.Physics.CenterOfMassWorld);
                    //var velocity = m_thrust.CubeGrid.Physics.LinearVelocity + velocityAtNewCOM;

                    if (m_thrust.CurrentStrength > 0 && length > 0)
                    {
                        float angle     = 1 - Math.Abs(Vector3.Dot(MyUtils.Normalize(MySector.MainCamera.Position - flamePosition), flameDirection));
                        float alphaCone = (1 - (float)Math.Pow(1 - angle, 30)) * 0.5f;
                        //  We move polyline particle backward, because we are stretching ball texture and it doesn't look good if stretched. This will hide it.
                        MyTransparentGeometry.AddLineBillboard(m_thrust.FlameLengthMaterial, m_thrust.ThrustColor * alphaCone,
                                                               flamePosition - (Vector3D)flameDirection * length * 0.25f,
                                                               -1, ref MatrixD.Identity, flameDirection, length, thickness, MyBillboard.BlenType.AdditiveBottom);
                    }

                    if (radius > 0)
                    {
                        MyTransparentGeometry.AddPointBillboard(m_thrust.FlamePointMaterial, m_thrust.ThrustColor, flamePosition, -1,
                                                                ref MatrixD.Identity, radius, 0, -1, MyBillboard.BlenType.AdditiveBottom);
                    }

                    if (m_landingEffectUpdateCounter-- <= 0)
                    {
                        m_landingEffectUpdateCounter = (int)Math.Round(m_landingEffectUpdateInterval * (0.8f + MyRandom.Instance.NextFloat() * 0.4f));

                        m_lastHitInfo = m_thrust.ThrustLengthRand <= MyMathConstants.EPSILON ? null : MyPhysics.CastRay(flamePosition,
                                                                                                                        flamePosition + flameDirection * m_thrust.ThrustLengthRand * 2.5f * flame.Radius,
                                                                                                                        MyPhysics.CollisionLayers.DefaultCollisionLayer);
                    }

                    var voxelBase = m_lastHitInfo.HasValue ? m_lastHitInfo.Value.HkHitInfo.GetHitEntity() as MyVoxelPhysics : null;
                    if (voxelBase == null)
                    {
                        if (m_landingEffect != null)
                        {
                            m_landingEffect.Stop();
                            m_landingEffect = null;
                            --m_landingEffectCount;
                        }
                        continue;
                    }

                    if (m_landingEffect == null && m_landingEffectCount < m_maxNumberLandingEffects && MyParticlesManager.TryCreateParticleEffect(54, out m_landingEffect))
                    {
                        ++m_landingEffectCount;
                    }

                    if (m_landingEffect == null)
                    {
                        continue;
                    }

                    m_landingEffect.UserScale   = m_thrust.CubeGrid.GridSize;
                    m_landingEffect.WorldMatrix = MatrixD.CreateFromTransformScale(Quaternion.CreateFromForwardUp(-m_lastHitInfo.Value.HkHitInfo.Normal, Vector3.CalculatePerpendicularVector(m_lastHitInfo.Value.HkHitInfo.Normal)), m_lastHitInfo.Value.Position, Vector3D.One);
                    MatrixD.Rescale(m_landingEffect.WorldMatrix, scale);
                }
            }
            else if (m_landingEffect != null)
            {
                m_landingEffect.Stop();
                m_landingEffect = null;
                --m_landingEffectCount;
            }

            if (m_thrust.Light != null)
            {
                m_thrust.UpdateLight();
            }
        }
        public override void Draw()
        {
            base.Draw();

            var worldToLocal = MatrixD.Invert(Container.Entity.PositionComp.WorldMatrix);

            if (m_thrust.CanDraw())
            {
                m_thrust.UpdateThrustFlame();
                m_thrust.UpdateThrustColor();

                foreach (var flame in m_thrust.Flames)
                {
                    if (m_thrust.CubeGrid.Physics == null)
                    {
                        continue;
                    }

                    var flameDirection = Vector3D.TransformNormal(flame.Direction, Container.Entity.PositionComp.WorldMatrix);
                    var flamePosition  = Vector3D.Transform(flame.Position, Container.Entity.PositionComp.WorldMatrix);

                    float radius    = m_thrust.ThrustRadiusRand * flame.Radius;
                    float length    = m_thrust.ThrustLengthRand * flame.Radius;
                    float thickness = m_thrust.ThrustThicknessRand * flame.Radius;

                    Vector3D velocityAtNewCOM = Vector3D.Cross(m_thrust.CubeGrid.Physics.AngularVelocity, flamePosition - m_thrust.CubeGrid.Physics.CenterOfMassWorld);
                    var      velocity         = m_thrust.CubeGrid.Physics.LinearVelocity + velocityAtNewCOM;

                    if (m_thrust.CurrentStrength > 0 && length > 0)
                    {
                        float angle     = 1 - Math.Abs(Vector3.Dot(MyUtils.Normalize(MySector.MainCamera.Position - flamePosition), flameDirection));
                        float alphaCone = (1 - (float)Math.Pow(1 - angle, 30)) * 0.5f;
                        //  We move polyline particle backward, because we are stretching ball texture and it doesn't look good if stretched. This will hide it.
                        MyTransparentGeometry.AddLineBillboard(m_thrust.FlameLengthMaterial, m_thrust.ThrustColor * alphaCone, flamePosition - flameDirection * length * 0.25f,
                                                               GetRenderObjectID(), ref worldToLocal, flameDirection, length, thickness);
                    }

                    if (radius > 0)
                    {
                        MyTransparentGeometry.AddPointBillboard(m_thrust.FlamePointMaterial, m_thrust.ThrustColor, flamePosition, GetRenderObjectID(), ref worldToLocal, radius, 0);
                    }

                    if (m_landingEffectUpdateCounter-- <= 0)
                    {
                        m_landingEffectUpdateCounter = (int)Math.Round(m_landingEffectUpdateInterval * (0.8f + MyRandom.Instance.NextFloat() * 0.4f));

                        m_lastHitInfo = MyPhysics.CastRay(flamePosition,
                                                          flamePosition + flameDirection * m_thrust.ThrustLengthRand * (m_thrust.CubeGrid.GridSizeEnum == MyCubeSize.Large ? 5.0f : 3.0f) * flame.Radius,
                                                          MyPhysics.ObjectDetectionCollisionLayer);
                    }

                    if (m_landingEffect != null)
                    {
                        m_landingEffect.Stop(true);
                        m_landingEffect = null;
                        --m_landingEffectCount;
                    }
                    continue;

                    if (m_landingEffect == null && m_landingEffectCount < m_maxNumberLandingEffects && MyParticlesManager.TryCreateParticleEffect(54, out m_landingEffect))
                    {
                        ++m_landingEffectCount;
                    }

                    if (m_landingEffect == null)
                    {
                        continue;
                    }

                    m_landingEffect.UserScale   = m_thrust.CubeGrid.GridSize;
                    m_landingEffect.WorldMatrix = MatrixD.CreateFromTransformScale(Quaternion.CreateFromForwardUp(-m_lastHitInfo.Value.HkHitInfo.Normal, Vector3.CalculatePerpendicularVector(m_lastHitInfo.Value.HkHitInfo.Normal)), m_lastHitInfo.Value.Position, Vector3D.One);
                }
            }
            else if (m_landingEffect != null)
            {
                m_landingEffect.Stop(true);
                m_landingEffect = null;
                --m_landingEffectCount;
            }

            if (m_thrust.Light != null)
            {
                m_thrust.UpdateLight();
            }
        }
Example #17
0
        private void UpdateJumpDriveSystem()
        {
            // Using this instead of game time because it cannot be affected by sim speed
            float jumpTime = (float)(TimeUtil.LocalTime - m_jumpStartTime).TotalMilliseconds;

            float warmupTime    = 10000f;
            float startJumpTime = 1500f;
            float endJumpTime   = 500f;

            if (m_isJumping)
            {
                if (jumpTime < warmupTime)
                {
                    int prevTimeInt = (int)(m_prevJumpTime / 1000);
                    int timeInt     = (int)(jumpTime / 1000);
                    if (prevTimeInt != timeInt)
                    {
                        if (IsLocalCharacterAffectedByJump())
                        {
                            var notification     = new MyHudNotification(MySpaceTexts.NotificationJumpWarmupTime, 500);
                            int secondsRemaining = (int)(Math.Round((warmupTime - jumpTime) / 1000));
                            notification.SetTextFormatArguments(secondsRemaining);
                            MyHud.Notifications.Add(notification);
                        }
                    }
                }
                else if (jumpTime < startJumpTime + warmupTime)
                {
                    if (m_soundEmitter.SoundId != m_jumpOutSound.SoundId)
                    {
                        m_soundEmitter.PlaySound(m_jumpOutSound);
                    }
                    UpdateJumpEffect(MathHelper.SmoothStep(1f, 0f, (jumpTime - warmupTime) / startJumpTime));
                }
                else if (!m_jumped)
                {
                    MyParticleEffect effect;
                    if (MyParticlesManager.TryCreateParticleEffect(53, out effect))
                    {
                        effect.WorldMatrix = MatrixD.CreateFromTransformScale(Quaternion.Identity, m_grid.WorldMatrix.Translation, Vector3D.One);
                        effect.UserScale   = (float)m_grid.PositionComp.WorldAABB.HalfExtents.AbsMax() / 25f;
                        effect.AutoDelete  = true;
                    }

                    MyThirdPersonSpectator.Static.ResetPosition(0.0, null);
                    MyThirdPersonSpectator.Static.ResetDistance();
                    MyThirdPersonSpectator.Static.RecalibrateCameraPosition();

                    m_jumped = true;

                    var keys = m_shipInfo.Keys.ToList();
                    foreach (var key in keys)
                    {
                        MatrixD gridMatrix = key.WorldMatrix;
                        gridMatrix.Translation = m_shipInfo[key];
                        key.WorldMatrix        = gridMatrix;
                    }

                    UpdateJumpEffect(0f);
                    MyThirdPersonSpectator.Static.ResetPosition(0.0, null);
                    MyThirdPersonSpectator.Static.ResetDistance();
                    MyThirdPersonSpectator.Static.RecalibrateCameraPosition();
                }
                else if (jumpTime < startJumpTime + endJumpTime + warmupTime)
                {
                    if (m_soundEmitter.SoundId != m_jumpInSound.SoundId)
                    {
                        m_soundEmitter.PlaySound(m_jumpInSound);
                    }
                    UpdateJumpEffect(MathHelper.SmoothStep(0f, 1f, (jumpTime - startJumpTime - warmupTime) / (endJumpTime)));
                }
                else
                {
                    UpdateJumpEffect(1f);
                    m_jumped    = false;
                    m_isJumping = false;
                }
            }
            m_prevJumpTime = jumpTime;
        }