Esempio n. 1
0
        public override void Draw()
        {
            base.Draw();

            if (MyDebugDrawSettings.DEBUG_DRAW_VOICE_CHAT && MyFakes.ENABLE_VOICE_CHAT_DEBUGGING)
            {
                DebugDraw();
            }

            foreach (var pair in m_receivedVoiceData)
            {
                if (pair.Value.SpeakerTimestamp != MyTimeSpan.Zero)
                {
                    var player = Sync.Players.GetPlayerById(new MyPlayer.PlayerId(pair.Key, 0));
                    if (player.Character != null)
                    {
                        var position = player.Character.PositionComp.GetPosition() + new Vector3D(0, 2.2, 0);
                        var color    = Color.White;
                        MyTransparentGeometry.AddPointBillboard("VoiceChatSpeaker", color, position, 0.25f, 0, 0, true);
                    }
                }
            }
        }
Esempio n. 2
0
        private static void DrawGlow()
        {
            if (MyRender.Sun.Direction == Vector3.Zero)
            {
                return;
            }
            if (MyRender.Sun.SunMaterial == null)
            {
                return;
            }


            // this should be computed every time the sector is changed. If it is not initialized, calculate now:
            m_distanceToSun = MyRender.Sun.DistanceToSun;

            m_directionToSunNormalized = -MyRender.Sun.Direction;

            float radius = MyRender.Sun.SunSizeMultiplier * MySunConstants.SUN_SIZE_MULTIPLIER * MySunConstants.RENDER_SUN_DISTANCE / m_distanceToSun;
            //radius = Math.Max(MySunConstants.MIN_SUN_SIZE * MyRender.Sun.SunSizeMultiplier, radius);
            //radius = Math.Min(MySunConstants.MAX_SUN_SIZE * MyRender.Sun.SunSizeMultiplier, radius);

            float sunColorMultiplier = 3;

            sunColorMultiplier *= (1 - MyRender.FogProperties.FogMultiplier * 0.7f);

            m_querySize = .5f * 1800.0f / radius;

            var sunPosition = GetSunPosition();

            radius *= .5f;
            Color color = new Color(.95f * sunColorMultiplier, .65f * sunColorMultiplier, .35f * sunColorMultiplier, 1);

            color = color * 5;

            //var color = new Vector4(sunColorMultiplier * MySector.SunColorWithFog, 1);
            MyTransparentGeometry.AddPointBillboard(MyRender.Sun.SunMaterial, color, sunPosition, radius, 0, cullwithStencil: true);
        }
Esempio n. 3
0
        public override bool Draw()
        {
            if (Visible)
            {
                foreach (var billboardMessage in m_billboards)
                {
                    MyRenderMessageAddLineBillboardLocal lineBillboard = billboardMessage as MyRenderMessageAddLineBillboardLocal;
                    if (lineBillboard != null)
                    {
                        Vector3D position = Vector3.Transform(lineBillboard.LocalPos, WorldMatrix);
                        Vector3D dir      = Vector3.TransformNormal(lineBillboard.LocalDir, WorldMatrix);

                        MyTransparentGeometry.AddLineBillboard(
                            lineBillboard.Material,
                            lineBillboard.Color, position,
                            dir,
                            lineBillboard.Length,
                            lineBillboard.Thickness,
                            lineBillboard.Priority,
                            lineBillboard.Near);
                    }
                    else
                    {
                        MyRenderMessageAddPointBillboardLocal pointBillboard = billboardMessage as MyRenderMessageAddPointBillboardLocal;
                        if (pointBillboard != null)
                        {
                            Vector3D position = Vector3D.Transform(pointBillboard.LocalPos, WorldMatrix);

                            MyTransparentGeometry.AddPointBillboard(pointBillboard.Material, pointBillboard.Color, position, pointBillboard.Radius, pointBillboard.Angle
                                                                    , pointBillboard.Priority, pointBillboard.Colorize, pointBillboard.Near, pointBillboard.Lowres);
                        }
                    }
                }
            }

            return(base.Draw());
        }
Esempio n. 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);
        }
Esempio n. 5
0
        private void DrawReflectorCone()
        {
            var world = Container.Entity.PositionComp.WorldMatrix;

            var      toLocal       = Container.Entity.PositionComp.WorldMatrixNormalizedInv;
            Vector3D position      = Container.Entity.PositionComp.GetPosition();
            Vector3D forwardVector = world.Forward;
            Vector3D leftVector    = world.Left;
            Vector3D upVector      = world.Up;

            if (m_reflectorLight.Light.ReflectorOn)
            {
                m_reflectorLight.Light.ReflectorUp        = upVector;
                m_reflectorLight.Light.ReflectorDirection = Vector3D.TransformNormal(world.Forward, toLocal);
                m_reflectorLight.Light.ReflectorColor     = m_reflectorLight.Color.ToVector4();
                m_reflectorLight.Light.UpdateReflectorRangeAndAngle(m_reflectorLight.ShortReflectorForwardConeAngleDef, m_reflectorLight.ShortReflectorRangeDef);
            }

            float reflectorLength    = 20f;
            float reflectorThickness = m_reflectorLight.IsLargeLight ? 9f : 3f;

            var color = m_reflectorLight.Light.ReflectorColor;

            color.A = 255;

            var   glarePosition          = position + forwardVector * 0.28f;
            var   dot                    = Vector3.Dot(Vector3D.Normalize(MySector.MainCamera.Position - glarePosition), forwardVector);
            float angle                  = 1 - Math.Abs(dot);
            float alphaGlareAlphaBlended = (float)Math.Pow(1 - angle, 2);
            float alphaCone              = (1 - (float)Math.Pow(1 - angle, 30)) * 0.15f;

            float reflectorRadiusForAlphaBlended = MathHelper.Lerp(0.1f, 0.5f, alphaGlareAlphaBlended);

            //  Multiply alpha by reflector level (and not the color), because if we multiply the color and let alpha unchanged, reflector cune will be drawn as very dark cone, but still visible
            var reflectorLevel = CurrentLightPower;

            alphaCone *= reflectorLevel;
            alphaGlareAlphaBlended *= reflectorLevel * 0.3f;

            bool drivenFromFPS = MySession.Static.CameraController is MyCockpit ? ((MyCockpit)MySession.Static.CameraController).IsInFirstPersonView : false;

            if (!drivenFromFPS)
            {
                MyTransparentGeometry.AddLineBillboard(
                    "ReflectorCone",
                    color * alphaCone,
                    position - forwardVector * 0.8f,
                    forwardVector,
                    reflectorLength,
                    reflectorThickness);
            }

            MyTransparentGeometry.AddPointBillboard(
                "ReflectorGlareAlphaBlended",
                color * alphaGlareAlphaBlended,
                glarePosition,
                reflectorRadiusForAlphaBlended,
                0);

            //            VRageRender.MyRenderProxy.DebugDrawAABB(WorldAABB, Vector3.One, 1, 1, false);
        }
Esempio n. 6
0
        //  This method doesn't really draw. It just creates billboards that are later drawn in MyParticles.Draw()
        public static void Draw()
        {
            if (IsActive == false)
            {
                return;
            }
            if (IsVisible == false)
            {
                return;
            }

            //float deltaTime = ((float)MyMinerGame.TotalGamePlayTimeInMilliseconds - (float)m_timeStarted) / 1000.0f;
            float   traveledDistance = m_speed * m_deltaTime;
            Vector3 deltaPosition    = m_directionFromSunNormalized * traveledDistance;

            //  Draw LARGE billboards
            for (int x = 0; x < MySunWindConstants.LARGE_BILLBOARDS_SIZE.X; x++)
            {
                for (int y = 0; y < MySunWindConstants.LARGE_BILLBOARDS_SIZE.Y; y++)
                {
                    MySunWindBillboard billboard = m_largeBillboards[x][y];

                    Vector3 actualPosition = billboard.InitialAbsolutePosition + deltaPosition;

                    float   distanceToCamera;
                    Vector3 campos = MyCamera.Position;
                    Vector3.Distance(ref actualPosition, ref campos, out distanceToCamera);
                    float alpha = 1 - MathHelper.Clamp(distanceToCamera / MySunWindConstants.LARGE_BILLBOARD_DISAPEAR_DISTANCE, 0, 1);

                    float distanceToCenterOfSunWind;
                    Vector3.Distance(ref actualPosition, ref campos, out distanceToCenterOfSunWind);

                    if (distanceToCenterOfSunWind < MySunWindConstants.SWITCH_LARGE_AND_SMALL_BILLBOARD_RADIUS)
                    {
                        alpha *= MathHelper.Clamp(distanceToCamera / MySunWindConstants.SWITCH_LARGE_AND_SMALL_BILLBOARD_DISTANCE, 0, 1);
                    }

                    //billboard.Color *= alpha;

                    MyTransparentGeometry.AddPointBillboard(
                        MyTransparentMaterialEnum.Explosion,
                        new Vector4(billboard.Color.X * alpha, billboard.Color.Y * alpha, billboard.Color.Z * alpha, alpha),
                        actualPosition,
                        billboard.Radius,
                        billboard.InitialAngle + billboard.RotationSpeed * m_deltaTime);
                }
            }

            //  Draw SMALL billboards
            //if (m_distanceToSunWind <= MySunWindConstants.SWITCH_LARGE_AND_SMALL_BILLBOARD_DISTANCE)
            //{
            //    if (m_smallBillboardsStarted == false)
            //    {
            //        StartSmallBillboards();
            //        m_smallBillboardsStarted = true;
            //    }

            if (m_smallBillboardsStarted == true)
            {
                for (int x = 0; x < MySunWindConstants.SMALL_BILLBOARDS_SIZE.X; x++)
                {
                    for (int y = 0; y < MySunWindConstants.SMALL_BILLBOARDS_SIZE.Y; y++)
                    {
                        MySunWindBillboardSmall billboard = m_smallBillboards[x][y];

                        Vector3 actualPosition = billboard.InitialAbsolutePosition + deltaPosition;

                        for (int z = 0; z < billboard.TailBillboardsCount; z++)
                        {
                            Vector3 tempPosition = actualPosition - m_directionFromSunNormalized * (z - billboard.TailBillboardsCount / 2) * billboard.TailBillboardsDistance;

                            float   distanceToCamera;
                            Vector3 campos = MyCamera.Position;
                            Vector3.Distance(ref tempPosition, ref campos, out distanceToCamera);

                            //distanceToCamera = Math.Abs(Vector3.Dot(tempPosition - campos, m_directionFromSunNormalized));

                            float alpha = 1 - MathHelper.Clamp((distanceToCamera) / (MySunWindConstants.SWITCH_LARGE_AND_SMALL_BILLBOARD_DISTANCE_HALF), 0, 1);

                            if (alpha > 0)
                            {
                                float distanceFromOrigin;
                                Vector3.Distance(ref tempPosition, ref billboard.InitialAbsolutePosition, out distanceFromOrigin);
                                if (distanceFromOrigin < billboard.MaxDistance)
                                {
                                    MyTransparentGeometry.AddPointBillboard(
                                        MyTransparentMaterialEnum.Explosion,
                                        new Vector4(billboard.Color.X * alpha, billboard.Color.Y * alpha, billboard.Color.Z * alpha, billboard.Color.W * alpha),
                                        tempPosition,
                                        billboard.Radius * billboard.RadiusScales[z],
                                        billboard.InitialAngle + billboard.RotationSpeed * m_deltaTime);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        void DrawSelectionLines(ref MatrixD worldMatrix, ref BoundingBoxD localBB, Color color, float lineWidth)
        {
            #region Selection lines
            const float LineLength = 2f; // directions are half-long

            Vector3D center     = Vector3D.Transform((localBB.Min + localBB.Max) * 0.5, worldMatrix);
            Vector3D halfExtent = (localBB.Max - localBB.Min) * 0.5;
            Vector3D left       = worldMatrix.Left * halfExtent.X;
            Vector3D up         = worldMatrix.Up * halfExtent.Y;
            Vector3D back       = worldMatrix.Backward * halfExtent.Z;

            Vector3D top    = center + up;
            Vector3D bottom = center - up;

            Vector3D cornerTop1 = top + left + back;
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerTop1, -left, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerTop1, -up, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerTop1, -back, LineLength, lineWidth, SelectionBlendType);

            Vector3D cornerTop2 = top - left - back;
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerTop2, left, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerTop2, -up, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerTop2, back, LineLength, lineWidth, SelectionBlendType);

            Vector3D cornerBottom1 = bottom + left - back;
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerBottom1, -left, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerBottom1, up, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerBottom1, back, LineLength, lineWidth, SelectionBlendType);

            Vector3D cornerBottom2 = bottom - left + back;
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerBottom2, left, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerBottom2, up, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerBottom2, -back, LineLength, lineWidth, SelectionBlendType);
            #endregion Selection lines

            #region Selection corners
            float   cornerRadius = lineWidth;
            Vector4 colorCorner  = color;

            MyTransparentGeometry.AddPointBillboard(SelectionCornerMaterial, colorCorner, cornerTop1, cornerRadius, 0, blendType: SelectionBlendType);
            MyTransparentGeometry.AddPointBillboard(SelectionCornerMaterial, colorCorner, cornerTop2, cornerRadius, 0, blendType: SelectionBlendType);
            MyTransparentGeometry.AddPointBillboard(SelectionCornerMaterial, colorCorner, cornerBottom1, cornerRadius, 0, blendType: SelectionBlendType);
            MyTransparentGeometry.AddPointBillboard(SelectionCornerMaterial, colorCorner, cornerBottom2, cornerRadius, 0, blendType: SelectionBlendType);

            Vector3D cornerTop3 = top - left + back;
            MyTransparentGeometry.AddPointBillboard(SelectionCornerMaterial, colorCorner, cornerTop3, cornerRadius, 0, blendType: SelectionBlendType);
            Vector3D cornerTop4 = top + left - back;
            MyTransparentGeometry.AddPointBillboard(SelectionCornerMaterial, colorCorner, cornerTop4, cornerRadius, 0, blendType: SelectionBlendType);

            Vector3D cornerBottom3 = bottom - left - back;
            MyTransparentGeometry.AddPointBillboard(SelectionCornerMaterial, colorCorner, cornerBottom3, cornerRadius, 0, blendType: SelectionBlendType);
            Vector3D cornerBottom4 = bottom + left + back;
            MyTransparentGeometry.AddPointBillboard(SelectionCornerMaterial, colorCorner, cornerBottom4, cornerRadius, 0, blendType: SelectionBlendType);
            #endregion corners

            #region See-through-walls lines
            MatrixD camMatrix = MyAPIGateway.Session.Camera.WorldMatrix;

            const float DepthRatio = 0.01f;
            lineWidth *= DepthRatio * 0.5f; // and half as thin
            color     *= 0.5f;              // half opacity too

            center = camMatrix.Translation + ((center - camMatrix.Translation) * DepthRatio);

            //halfExtent *= DepthRatio;
            left *= DepthRatio;
            up   *= DepthRatio;
            back *= DepthRatio;

            top    = center + up;
            bottom = center - up;

            cornerTop1 = top + left + back;
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerTop1, -left, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerTop1, -up, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerTop1, -back, LineLength, lineWidth, SelectionBlendType);

            cornerTop2 = top - left - back;
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerTop2, left, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerTop2, -up, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerTop2, back, LineLength, lineWidth, SelectionBlendType);

            cornerBottom1 = bottom + left - back;
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerBottom1, -left, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerBottom1, up, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerBottom1, back, LineLength, lineWidth, SelectionBlendType);

            cornerBottom2 = bottom - left + back;
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerBottom2, left, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerBottom2, up, LineLength, lineWidth, SelectionBlendType);
            MyTransparentGeometry.AddLineBillboard(SelectionLineMaterial, color, cornerBottom2, -back, LineLength, lineWidth, SelectionBlendType);
            #endregion
        }
        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();
            }
        }
Esempio n. 9
0
        private void DrawJetpackThrusts(bool updateCalled)
        {
            if (m_character.CanDrawThrusts() == false)
            {
                return;
            }

            //VRageRender.MyRenderProxy.DebugDrawLine3D(WorldMatrix.Translation, WorldMatrix.Translation + Physics.LinearAcceleration, Color.White, Color.Green, false);

            foreach (MyJetpackThrust thrust in m_jetpackThrusts)
            {
                float    strength     = 0;
                Vector3D position     = Vector3D.Zero;
                var      worldToLocal = MatrixD.Invert(Container.Entity.PositionComp.WorldMatrix);

                if (m_character.JetpackEnabled && m_character.IsJetpackPowered() && !m_character.IsInFirstPersonView)
                {
                    var      thrustMatrix = (MatrixD)thrust.ThrustMatrix * Container.Entity.PositionComp.WorldMatrix;
                    Vector3D forward      = Vector3D.TransformNormal(thrust.Forward, thrustMatrix);
                    position  = thrustMatrix.Translation;
                    position += forward * thrust.Offset;

                    float flameScale = 0.05f;
                    if (updateCalled)
                    {
                        thrust.ThrustRadius = MyUtils.GetRandomFloat(0.9f, 1.1f) * flameScale;
                    }
                    strength = Vector3.Dot(forward, -Container.Entity.Physics.LinearAcceleration);
                    strength = MathHelper.Clamp(strength * 0.5f, 0.1f, 1f);

                    if (strength > 0 && thrust.ThrustRadius > 0)
                    {
                        float angle     = 1 - Math.Abs(Vector3.Dot(MyUtils.Normalize(MySector.MainCamera.Position - position), forward));
                        float alphaCone = (1 - (float)Math.Pow(1 - angle, 30)) * 0.5f;

                        if (updateCalled)
                        {
                            thrust.ThrustLength    = strength * 10 * MyUtils.GetRandomFloat(0.6f, 1.0f) * flameScale;
                            thrust.ThrustThickness = MyUtils.GetRandomFloat(thrust.ThrustRadius * 0.90f, thrust.ThrustRadius);
                        }

                        //  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(thrust.ThrustMaterial, thrust.Light.Color * alphaCone, position /*- forward * thrust.ThrustLength * 0.25f*/,
                                                               GetRenderObjectID(), ref worldToLocal, forward, thrust.ThrustLength, thrust.ThrustThickness);
                    }

                    if (thrust.ThrustRadius > 0)
                    {
                        MyTransparentGeometry.AddPointBillboard(thrust.ThrustMaterial, thrust.Light.Color, position, GetRenderObjectID(), ref worldToLocal, thrust.ThrustRadius, 0);
                    }
                }
                else
                {
                    if (updateCalled || (m_character.IsUsing != null))
                    {
                        thrust.ThrustRadius = 0;
                    }
                }

                if (thrust.Light != null)
                {
                    if (thrust.ThrustRadius > 0)
                    {
                        thrust.Light.LightOn   = true;
                        thrust.Light.Intensity = 1.3f + thrust.ThrustLength * 1.2f;

                        thrust.Light.Range = thrust.ThrustRadius * 7f + thrust.ThrustLength / 10;

                        thrust.Light.Position = Vector3D.Transform(position, MatrixD.Invert(Container.Entity.PositionComp.WorldMatrix));
                        thrust.Light.ParentID = GetRenderObjectID();

                        thrust.Light.GlareOn = true;

                        thrust.Light.GlareIntensity = 0.5f + thrust.ThrustLength * 4;

                        thrust.Light.GlareMaterial = "GlareJetpack";
                        thrust.Light.GlareType     = VRageRender.Lights.MyGlareTypeEnum.Normal;

                        thrust.Light.GlareSize = (thrust.ThrustRadius * 2.4f + thrust.ThrustLength * 0.2f) * thrust.ThrustGlareSize;

                        thrust.Light.GlareQuerySize = 0.3f;
                        thrust.Light.UpdateLight();
                    }
                    else
                    {
                        thrust.Light.GlareOn = false;
                        thrust.Light.LightOn = false;
                        thrust.Light.UpdateLight();
                    }
                }
            }
        }
        //  This method doesn't really draw. It just creates billboards that are later drawn in MyParticles.Draw()
        public static void Draw()
        {
            if (!MySector.ParticleDustProperties.Enabled)
            {
                return;
            }
            if (MinerWars.AppCode.Game.Render.MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                return;
            }
            // if (MyRender.CurrentRenderSetup.CallerID.Value != MyRenderCallerEnum.Main)
            //   return;
            if ((int)MySector.ParticleDustProperties.DustFieldCountInDirectionHalf == 0)
            {
                return;
            }

            MyRender.GetRenderProfiler().StartProfilingBlock("Dust changed");

            if ((m_lastDustBillboardRadius != MySector.ParticleDustProperties.DustBillboardRadius)
                ||
                m_lastDustFieldCountInDirectionHalf != (int)MySector.ParticleDustProperties.DustFieldCountInDirectionHalf)
            {
                m_lastDustBillboardRadius           = MySector.ParticleDustProperties.DustBillboardRadius;
                m_lastDustFieldCountInDirectionHalf = (int)MySector.ParticleDustProperties.DustFieldCountInDirectionHalf;
                m_distanceBetweenHalf       = MySector.ParticleDustProperties.DistanceBetween / 2.0f;
                m_dustFieldCountInDirection = (int)MySector.ParticleDustProperties.DustFieldCountInDirectionHalf * 2 + 1;

                //  Bounding frustum is based on camer's bounding frustun, but far plane isn't in such distance, because then bounding box is too large
                //  IMPORTANT: Near plane can't be 0.001 or something small like that. Because than bounding box is weird.
                m_helperProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MyCamera.FieldOfView, MyCamera.ForwardAspectRatio,
                                                                               MyCamera.NEAR_PLANE_DISTANCE,
                                                                               Math.Max(MySector.ParticleDustProperties.DistanceBetween * MySector.ParticleDustProperties.DustFieldCountInDirectionHalf, MyCamera.NEAR_PLANE_DISTANCE + 0.01f));
                m_helperBoundingFrustum = new BoundingFrustum(Matrix.Identity);



                //  Fill 3D array with random values from interval <0..1>
                m_random = new float[m_dustFieldCountInDirection][][];
                for (int x = 0; x < m_random.Length; x++)
                {
                    m_random[x] = new float[m_dustFieldCountInDirection][];

                    for (int y = 0; y < m_random.Length; y++)
                    {
                        m_random[x][y] = new float[m_dustFieldCountInDirection];

                        for (int z = 0; z < m_random.Length; z++)
                        {
                            m_random[x][y][z] = MyMwcUtils.GetRandomFloat(0, 1);
                        }
                    }
                }
            }

            MyRender.GetRenderProfiler().StartNextBlock("computations");

            //  If sun wind is active, we make particle dust more transparent
            float alphaBecauseSunWind = (MySunWind.IsActive == true) ? MySunWind.GetParticleDustFieldAlpha() : 1;

            Vector3 center = MyCamera.Position;
            //Vector3 center = MySession.PlayerShip.GetPosition();

            MyMwcVector3Int cameraCoord = GetMetersToDustFieldCoord(ref center);
            MyMwcVector3Int minCoord    = new MyMwcVector3Int(cameraCoord.X - (int)MySector.ParticleDustProperties.DustFieldCountInDirectionHalf, cameraCoord.Y - (int)MySector.ParticleDustProperties.DustFieldCountInDirectionHalf, cameraCoord.Z - (int)MySector.ParticleDustProperties.DustFieldCountInDirectionHalf);
            MyMwcVector3Int maxCoord    = new MyMwcVector3Int(cameraCoord.X + (int)MySector.ParticleDustProperties.DustFieldCountInDirectionHalf, cameraCoord.Y + (int)MySector.ParticleDustProperties.DustFieldCountInDirectionHalf, cameraCoord.Z + (int)MySector.ParticleDustProperties.DustFieldCountInDirectionHalf);

            //  Update helper frustum and then its bounding box
            //  Bounding frustum is based on camer's bounding frustun, but far plane isn't in such distance, because then bounding box is too large
            m_helperBoundingFrustum.Matrix = MyCamera.ViewMatrix * m_helperProjectionMatrix;
            BoundingBox helperBoundingBox = BoundingBoxHelper.InitialBox;

            //BoundingBoxHelper.AddFrustum(ref m_helperBoundingFrustum, ref helperBoundingBox);
            BoundingBoxHelper.AddSphere(new BoundingSphere(MyCamera.Position, 1000), ref helperBoundingBox);
            MyMwcVector3Int frustumBoundingBoxMinCoord = GetMetersToDustFieldCoord(ref helperBoundingBox.Min);
            MyMwcVector3Int frustumBoundingBoxMaxCoord = GetMetersToDustFieldCoord(ref helperBoundingBox.Max);

            //MyMwcVector3Int frustumBoundingBoxMinCoord = GetMetersToDustFieldCoord(ref MyCamera.BoundingBox.Min);
            //MyMwcVector3Int frustumBoundingBoxMaxCoord = GetMetersToDustFieldCoord(ref MyCamera.BoundingBox.Max);

            //  This is fix for particles that will be near the frustum boundary (or on its other side, but still should be visible)
            //  Think about it like this: particle is defined by its center, but it overlaps spherical area, so we are interested
            //  in particles that are outisde of the frustum (but near it)
            frustumBoundingBoxMinCoord.X--;
            frustumBoundingBoxMinCoord.Y--;
            frustumBoundingBoxMinCoord.Z--;
            frustumBoundingBoxMaxCoord.X++;
            frustumBoundingBoxMaxCoord.Y++;
            frustumBoundingBoxMaxCoord.Z++;

            //  Fix min/max coordinates, so only billboards in frustum are traversed and drawn
            if (minCoord.X < frustumBoundingBoxMinCoord.X)
            {
                minCoord.X = frustumBoundingBoxMinCoord.X;
            }
            if (minCoord.Y < frustumBoundingBoxMinCoord.Y)
            {
                minCoord.Y = frustumBoundingBoxMinCoord.Y;
            }
            if (minCoord.Z < frustumBoundingBoxMinCoord.Z)
            {
                minCoord.Z = frustumBoundingBoxMinCoord.Z;
            }
            if (maxCoord.X > frustumBoundingBoxMaxCoord.X)
            {
                maxCoord.X = frustumBoundingBoxMaxCoord.X;
            }
            if (maxCoord.Y > frustumBoundingBoxMaxCoord.Y)
            {
                maxCoord.Y = frustumBoundingBoxMaxCoord.Y;
            }
            if (maxCoord.Z > frustumBoundingBoxMaxCoord.Z)
            {
                maxCoord.Z = frustumBoundingBoxMaxCoord.Z;
            }

            Matrix rotationMatrix = Matrix.CreateRotationY(animXSpeed);

            animXSpeed += MySector.ParticleDustProperties.AnimSpeed;

            MyRender.GetRenderProfiler().StartNextBlock("for for for + draw");

            MyMwcVector3Int tempCoord;

            for (tempCoord.X = minCoord.X; tempCoord.X <= maxCoord.X; tempCoord.X++)
            {
                for (tempCoord.Y = minCoord.Y; tempCoord.Y <= maxCoord.Y; tempCoord.Y++)
                {
                    for (tempCoord.Z = minCoord.Z; tempCoord.Z <= maxCoord.Z; tempCoord.Z++)
                    {
                        //  Position of this particle
                        Vector3 position;
                        position.X = tempCoord.X * MySector.ParticleDustProperties.DistanceBetween;
                        position.Y = tempCoord.Y * MySector.ParticleDustProperties.DistanceBetween;
                        position.Z = tempCoord.Z * MySector.ParticleDustProperties.DistanceBetween;

                        //  Get pseudo-random number. It's randomness is based on 3D position, so values don't change between draw calls.
                        float pseudoRandomVariationMod = m_random[Math.Abs(tempCoord.X) % m_random.Length][Math.Abs(tempCoord.Y) % m_random.Length][Math.Abs(tempCoord.Z) % m_random.Length];

                        //  Alter position by randomness
                        position.X += MathHelper.Lerp(-m_distanceBetweenHalf, +m_distanceBetweenHalf, pseudoRandomVariationMod);
                        position.Y += MathHelper.Lerp(-m_distanceBetweenHalf, +m_distanceBetweenHalf, pseudoRandomVariationMod);
                        position.Z += MathHelper.Lerp(-m_distanceBetweenHalf, +m_distanceBetweenHalf, pseudoRandomVariationMod);

                        //  Distance to particle
                        float distance;
                        Vector3.Distance(ref center, ref position, out distance);


                        Vector3 delta = position - MyCamera.Position;

                        // delta = Vector3.Transform(delta, rotationMatrix);
                        position = MyCamera.Position + delta;

                        //  Pseudo-random color and alpha
                        float pseudoRandomColor = MathHelper.Lerp(0.1f, 0.2f, pseudoRandomVariationMod); //MathHelper.Lerp(0.2f, 0.3f, pseudoRandomVariationMod);
                        //float pseudoRandomAlpha = 0.5f; //0.4f;  // 0.2f;// MathHelper.Lerp(0.2f, 0.3f, pseudoRandomVariationMod);

                        //  Dust color
                        var sectorDustColor = CustomColor.HasValue ? CustomColor.Value : MySector.ParticleDustProperties.Color;

                        //if (MyGuiScreenGamePlay.Static.ResultDustColor != Vector4.Zero)
                        //{
                        //    sectorDustColor = MyGuiScreenGamePlay.Static.ResultDustColor;
                        //}

                        Vector4 color = sectorDustColor.ToVector4();

                        /*
                         * Vector4 color = new Vector4(
                         * pseudoRandomColor * sectorDustColor.X,
                         * pseudoRandomColor * sectorDustColor.Y,
                         * pseudoRandomColor * sectorDustColor.Z,
                         * sectorDustColor.W);
                         */
                        //color = Vector4.One; new Vector4(0.0f, 0.0f, 0.0f, 1.0f);

                        //color = new Vector4(MinerWars.AppCode.Game.World.MySector.FogProperties.FogColor.X, MinerWars.AppCode.Game.World.MySector.FogProperties.FogColor.Y, MinerWars.AppCode.Game.World.MySector.FogProperties.FogColor.Z, 1);

                        //  Color+Alpha based on distance to camera (we use pre-multiplied alpha)
                        float maxDistance    = MySector.ParticleDustProperties.DustFieldCountInDirectionHalf * MySector.ParticleDustProperties.DistanceBetween;
                        float DistanceAlpha1 = 0.7f * maxDistance;
                        float DistanceAlpha2 = 0.85f * maxDistance;
                        float DistanceAlpha3 = 1.0f * maxDistance;
                        if (distance < DistanceAlpha1)
                        {
                            color *= 0;
                        }
                        else if ((distance >= DistanceAlpha1) && (distance < DistanceAlpha2))
                        {
                            color *= MathHelper.Clamp((distance - DistanceAlpha1) / (DistanceAlpha2 - DistanceAlpha1), 0, 1);
                        }
                        else if ((distance >= DistanceAlpha2) && (distance < DistanceAlpha3))
                        {
                            color *= 1 - MathHelper.Clamp((distance - DistanceAlpha2) / (DistanceAlpha3 - DistanceAlpha2), 0, 1);
                        }
                        else
                        {
                            color *= 0;
                        }

                        //  Sun wind influence
                        color *= alphaBecauseSunWind;

                        //  Do not draw totaly transparent particles
                        if ((color.X <= 0) && (color.Y <= 0) && (color.Z <= 0) && (color.W <= 0))
                        {
                            continue;
                        }

                        //if (color.W <= 0) continue;

                        //  Radius
                        //float radius = DUST_BILLBOARD_RADIUS;
                        //float radius = MathHelper.Lerp(1, 30, pseudoRandomVariationMod);
                        float radius = MySector.ParticleDustProperties.DustBillboardRadius;// MathHelper.Lerp(100, 200, pseudoRandomVariationMod);

                        //  Angle - see comments, I tried to do some rotation based on time
                        //angle += pseudoRandomVariationMod * ((MyMinerGame.TotalGamePlayTimeInMilliseconds % 10000.0f) / 1000.0f);
                        //angle += pseudoRandomVariationMod * (MyMinerGame.TotalGamePlayTimeInMilliseconds / 10000.0f);
                        float angle = pseudoRandomVariationMod + animXSpeed;

                        color *= 2;

                        //color = Vector4.One;

                        //MyTransparentGeometry.AddPointBillboard(MyTransparentMaterialEnum.Stardust, color, position, radius, angle);
                        MyTransparentGeometry.AddPointBillboard(MySector.ParticleDustProperties.Texture, color, position, radius, angle, 0, false, false, true);
                    }
                }
            }

            MyRender.GetRenderProfiler().EndProfilingBlock();
        }
Esempio n. 11
0
        public override void UpdateAfterSimulation()
        {
            try
            {
                if (Range < RANGE_OFF_EXCLUSIVE)
                {
                    return;
                }

                bool applyForce = false;
                if (++skipTicks >= APPLY_FORCE_SKIP_TICKS)
                {
                    skipTicks  = 0;
                    applyForce = true;
                }

                if (!applyForce && MyAPIGateway.Utilities.IsDedicated)
                {
                    return;
                }

                var  conePos     = block.WorldMatrix.Translation + (block.WorldMatrix.Forward * -offset);
                bool inViewRange = false;

                if (!MyAPIGateway.Utilities.IsDedicated)
                {
                    var cameraMatrix = MyAPIGateway.Session.Camera.WorldMatrix;
                    inViewRange = Vector3D.DistanceSquared(cameraMatrix.Translation, conePos) <= MAX_VIEW_RANGE_SQ;

                    if (inViewRange && DrawCone)
                    {
                        DrawInfluenceCone(conePos);
                    }
                }

                if (!applyForce && !inViewRange)
                {
                    return;
                }

                if (floatingObjects.Count == 0)
                {
                    UpdateEmissive();
                    return;
                }

                var collectPos = block.WorldMatrix.Translation + (block.WorldMatrix.Forward * offset);
                var blockVel   = block.CubeGrid.Physics.GetVelocityAtPoint(collectPos);
                var rangeSq    = Range * Range;
                int pulling    = 0;

                for (int i = (floatingObjects.Count - 1); i >= 0; --i)
                {
                    var floatingObject = floatingObjects[i];

                    if (floatingObject.MarkedForClose || !floatingObject.Physics.Enabled)
                    {
                        continue; // it'll get removed by FindFloatingObjects()
                    }
                    var objPos = floatingObject.GetPosition();
                    var distSq = Vector3D.DistanceSquared(collectPos, objPos);

                    if (distSq > rangeSq)
                    {
                        continue; // too far from cone
                    }
                    var dirNormalized = Vector3D.Normalize(objPos - conePos);
                    var angle         = Math.Acos(MathHelper.Clamp(Vector3D.Dot(block.WorldMatrix.Forward, dirNormalized), -1, 1));

                    if (angle > coneAngle)
                    {
                        continue; // outside of the cone's FOV
                    }
                    if (applyForce)
                    {
                        var collectDir = Vector3D.Normalize(objPos - collectPos);

                        var vel   = floatingObject.Physics.LinearVelocity - blockVel;
                        var stop  = vel - (collectDir * collectDir.Dot(vel));
                        var force = -(stop + collectDir) * Math.Min(floatingObject.Physics.Mass * MASS_MUL, MAX_MASS) * StrengthMul;

                        force *= APPLY_FORCE_SKIP_TICKS; // multiplied by how many ticks were skipped

                        //MyTransparentGeometry.AddLineBillboard(Mod.MATERIAL_SQUARE, Color.Yellow, objPos, force, 1f, 0.1f);

                        floatingObject.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, force, null, null);
                    }

                    if (inViewRange)
                    {
                        var mul    = (float)Math.Sin(DateTime.UtcNow.TimeOfDay.TotalMilliseconds * 0.01);
                        var radius = floatingObject.Model.BoundingSphere.Radius * MinMaxPercent(0.75f, 1.25f, mul);

                        MyTransparentGeometry.AddPointBillboard(Mod.MATERIAL_DOT, Color.LightSkyBlue * MinMaxPercent(0.2f, 0.4f, mul), objPos, radius, 0);
                    }

                    pulling++;
                }

                if (applyForce)
                {
                    UpdateEmissive(pulling > 0);
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Esempio n. 12
0
        private void Draw()
        {
            if (target == null)
            {
                return;
            }
            if (mergeblock == null)
            {
                return;
            }
            if (MyAPIGateway.Session?.Player?.Controller?.ControlledEntity?.Entity == null)
            {
                return;
            }
            if (MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetTopMostParent() != mergeblock.GetTopMostParent())
            {
                return;
            }
            if (DockCore.instance.DrawHud != true)
            {
                return;
            }

            DockCore.instance.DrawCenterDot();            //draw the center dot
            MatrixD mergepoint = new MatrixD(mergeblock.WorldMatrix);

            mergepoint.Translation = target.WorldMatrix.Translation + (MathHelper.Clamp(Vector3D.Distance(mergeblock.WorldMatrix.Translation, target.WorldMatrix.Translation), 5d, double.MaxValue) * target.WorldMatrix.Right);

            MyTransparentGeometry.AddPointBillboard(MyStringId.GetOrCompute("WhiteDot"), Color.Green.ToVector4(), mergeblock.WorldMatrix.Translation + mergeblock.WorldMatrix.Right * mergeblock.CubeGrid.GridSize / 2, 1, 0.0f);

            Vector2D dotpos = DockCore.instance.DrawOtherDot(CorrectRot(mergepoint), target.WorldAABB.Center, DockCore.DotObject.Rotate);

            MatrixD targetpoint = new MatrixD(target.WorldMatrix);

            targetpoint.Translation += targetpoint.Right * mergeblock.CubeGrid.GridSize / 2;
            MyTransparentGeometry.AddPointBillboard(MyStringId.GetOrCompute("WhiteDot"), Color.Purple.ToVector4(), targetpoint.Translation, 1, 0.0f);

            Vector2D anglepos = DockCore.instance.DrawOtherDot(CorrectRot(targetpoint), mergeblock.WorldAABB.Center, DockCore.DotObject.Translate);

            var roll = Vector3D.Dot(-target.WorldMatrix.Forward, mergeblock.WorldMatrix.Forward) - 1;

            roll *= -180;
            int i_roll = (int)roll;

            i_roll %= 90;
            if (i_roll > 45)
            {
                i_roll = 90 - i_roll;
            }
            DockCore.instance.SetDistanceMessage(string.Format("    <color=teal>Distance: {0:N}\n    <color=teal>Roll Alignment:{1:N0}", Vector3D.Distance(target.WorldMatrix.Translation, mergeblock.WorldMatrix.Translation), i_roll));
            if (dotpos.Length() > 0.05)
            {
                DockCore.instance.DrawArrow(dotpos);
                DockCore.instance.SetAngleMessage();
            }
            else
            {
                if (anglepos.Length() > 0.05)
                {
                    DockCore.instance.DrawArrow(anglepos);
                    DockCore.instance.SetTranslationMessage();
                }
                else
                {
                    DockCore.instance.HideArrow();
                    DockCore.instance.SetApproachMessage();
                }
            }
            //DockCore.instance.TextAPI.Send(new HUDTextNI.HUDMessage(4, 20, new Vector2D(-0.4,-0.4),1,true, true, Color.Black, string.Format("{0}<color=teal>Roll Alignment:{1:N0}", instruction, i_roll)));
        }
Esempio n. 13
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();
            }
        }
Esempio n. 14
0
        public static float UpdateDecalEmissivity(MyDecalTriangle decalTriangle, float alpha, MyRenderObject renderObject)
        {
            float emisivity = 0;

            if (decalTriangle.Emissivity > 0)
            {
                //emisivity = (float)(Math.Sin(decalTriangle.RandomOffset + decalTriangle.RandomOffset * MySandboxGame.TotalGamePlayTimeInMilliseconds / 1000.0f)) * 0.4f + 0.7f;

                // 2 seconds default, more emissive lit longer
                float stableLength = 2000 * decalTriangle.Emissivity;
                if ((MyRender.RenderTimeInMS - decalTriangle.RandomOffset) < stableLength)
                {
                    emisivity = 1;
                }
                else
                {
                    emisivity = (float)(500 - (MyRender.RenderTimeInMS - stableLength - decalTriangle.RandomOffset)) / 500.0f;
                    if (emisivity < 0)
                    {
                        emisivity = 0;
                    }
                }

                emisivity *= decalTriangle.Emissivity;

                if (emisivity > 0)
                {
                    Color color = MyDecalsConstants.PROJECTILE_DECAL_COLOR;

                    Vector3D position;
                    MyRenderTransformObject transformObject = renderObject as MyRenderTransformObject;
                    if (transformObject != null)
                    {
                        position = Vector3D.Transform(decalTriangle.Position, transformObject.WorldMatrix);
                    }
                    else
                    if (renderObject is MyManualCullableRenderObject)
                    {
                        position = Vector3D.Transform(decalTriangle.Position, (renderObject as MyManualCullableRenderObject).WorldMatrix);
                    }
                    else
                    {
                        position = decalTriangle.Position;
                    }

                    MyTransparentGeometry.AddPointBillboard(
                        "DecalGlare",
                        color * alpha,
                        (Vector3)position,
                        1.5f * emisivity,
                        0);

                    if (decalTriangle.Light != null)
                    {
                        decalTriangle.Light.Color = color;
                        decalTriangle.Light.SetPosition(position);

                        float range = Math.Max(3 * emisivity * alpha, 0.1f);
                        decalTriangle.Light.Range = range;
                    }
                }
            }

            return(emisivity);
        }
Esempio n. 15
0
        private void DrawJetpackThrusts(bool updateCalled)
        {
            MyCharacter skinnedEntity = base.m_skinnedEntity as MyCharacter;

            if ((skinnedEntity != null) && (skinnedEntity.GetCurrentMovementState() != MyCharacterMovementEnum.Died))
            {
                MyCharacterJetpackComponent jetpackComp = skinnedEntity.JetpackComp;
                if ((jetpackComp != null) && jetpackComp.CanDrawThrusts)
                {
                    MyEntityThrustComponent component2 = base.Container.Get <MyEntityThrustComponent>();
                    if (component2 != null)
                    {
                        MatrixD worldToLocal = MatrixD.Invert(base.Container.Entity.PositionComp.WorldMatrix);
                        foreach (MyJetpackThrust thrust in this.m_jetpackThrusts)
                        {
                            Vector3D zero = Vector3D.Zero;
                            if ((!jetpackComp.TurnedOn || !jetpackComp.IsPowered) || ((skinnedEntity.IsInFirstPersonView && ReferenceEquals(skinnedEntity, MySession.Static.LocalCharacter)) && !MyAnsel.IsAnselSessionRunning))
                            {
                                if (updateCalled || (skinnedEntity.IsUsing != null))
                                {
                                    thrust.ThrustRadius = 0f;
                                }
                            }
                            else
                            {
                                MatrixD  matrix   = thrust.ThrustMatrix * base.Container.Entity.PositionComp.WorldMatrix;
                                Vector3D vectord2 = Vector3D.TransformNormal(thrust.Forward, matrix);
                                zero = matrix.Translation + (vectord2 * thrust.Offset);
                                float num = 0.05f;
                                if (updateCalled)
                                {
                                    thrust.ThrustRadius = MyUtils.GetRandomFloat(0.9f, 1.1f) * num;
                                }
                                float   num2    = MathHelper.Clamp((float)(Vector3.Dot((Vector3)vectord2, (Vector3)(-Vector3.Transform(component2.FinalThrust, base.Entity.WorldMatrix.GetOrientation()) / ((double)skinnedEntity.BaseMass))) * 0.09f), (float)0.1f, (float)1f);
                                Vector4 color   = Vector4.Zero;
                                Vector4 vector2 = Vector4.Zero;
                                if ((num2 > 0f) && (thrust.ThrustRadius > 0f))
                                {
                                    float num4 = (1f - ((float)Math.Pow((double)(1f - (1f - Math.Abs(Vector3.Dot((Vector3)MyUtils.Normalize(MySector.MainCamera.Position - zero), (Vector3)vectord2)))), 30.0))) * 0.5f;
                                    if (updateCalled)
                                    {
                                        thrust.ThrustLength    = ((num2 * 12f) * MyUtils.GetRandomFloat(1.6f, 2f)) * num;
                                        thrust.ThrustThickness = MyUtils.GetRandomFloat(thrust.ThrustRadius * 1.9f, thrust.ThrustRadius);
                                    }
                                    color = thrust.Light.Color.ToVector4() * new Vector4(1f, 1f, 1f, 0.4f);
                                    MyTransparentGeometry.AddLineBillboard(thrust.ThrustLengthMaterial, color, zero + (vectord2 * JETPACK_THRUST_OFFSET), base.GetRenderObjectID(), ref worldToLocal, (Vector3)vectord2, thrust.ThrustLength * JETPACK_THRUST_LENGTH, thrust.ThrustThickness * JETPACK_THRUST_THICKNESS, MyBillboard.BlendTypeEnum.Standard, -1, num4 * (JETPACK_THRUST_INTENSITY_BASE + (num2 * JETPACK_THRUST_INTENSITY)), null);
                                }
                                if (thrust.ThrustRadius > 0f)
                                {
                                    vector2 = thrust.Light.Color.ToVector4() * new Vector4(1f, 1f, 1f, 0.4f);
                                    MyTransparentGeometry.AddPointBillboard(thrust.ThrustPointMaterial, vector2, zero, base.GetRenderObjectID(), ref worldToLocal, thrust.ThrustRadius * JETPACK_THRUST_THICKNESS, 0f, -1, MyBillboard.BlendTypeEnum.Standard, JETPACK_THRUST_INTENSITY_BASE + (num2 * JETPACK_THRUST_INTENSITY), null);
                                }
                            }
                            if (thrust.Light != null)
                            {
                                if (thrust.ThrustRadius <= 0f)
                                {
                                    thrust.Light.GlareOn = false;
                                    thrust.Light.LightOn = false;
                                    thrust.Light.UpdateLight();
                                }
                                else
                                {
                                    thrust.Light.LightOn        = true;
                                    thrust.Light.Intensity      = JETPACK_LIGHT_INTENSITY_BASE + (thrust.ThrustLength * JETPACK_LIGHT_INTENSITY_LENGTH);
                                    thrust.Light.Range          = (thrust.ThrustRadius * JETPACK_LIGHT_RANGE_RADIUS) + (thrust.ThrustLength * JETPACK_LIGHT_RANGE_LENGTH);
                                    thrust.Light.Position       = Vector3D.Transform(zero, base.Container.Entity.PositionComp.WorldMatrixNormalizedInv);
                                    thrust.Light.ParentID       = this.m_cullRenderId;
                                    thrust.Light.GlareOn        = true;
                                    thrust.Light.GlareIntensity = (JETPACK_GLARE_INTENSITY_BASE + (thrust.ThrustLength * JETPACK_GLARE_INTENSITY_LENGTH)) * this.m_flareJetpack.Intensity;
                                    thrust.Light.GlareType      = MyGlareTypeEnum.Normal;
                                    thrust.Light.GlareSize      = (this.m_flareJetpack.Size * ((thrust.ThrustRadius * JETPACK_GLARE_SIZE_RADIUS) + (thrust.ThrustLength * JETPACK_GLARE_SIZE_LENGTH))) * thrust.ThrustGlareSize;
                                    thrust.Light.SubGlares      = this.m_flareJetpack.SubGlares;
                                    thrust.Light.GlareQuerySize = 0.1f;
                                    thrust.Light.UpdateLight();
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 16
0
        public override void Draw()
        {
            base.Draw();

            UpdateCharacterSkeleton();

            VRageRender.MyRenderProxy.SetCharacterTransforms(RenderObjectIDs[0], m_character.BoneRelativeTransforms);

            Matrix headMatrix = m_character.GetHeadMatrix(false);


            Vector3 position      = m_light.Position;
            Vector3 forwardVector = m_light.ReflectorDirection;
            Vector3 leftVector    = headMatrix.Left;
            Vector3 upVector      = headMatrix.Up;

            float reflectorLength    = MyCharacter.REFLECTOR_BILLBOARD_LENGTH * 0.4f * 0.16f;
            float reflectorThickness = MyCharacter.REFLECTOR_BILLBOARD_THICKNESS * 0.08f;
            //float reflectorRadiusForAdditive = 0.25f;//0.65f;

            Vector3 color = new Vector3(m_light.ReflectorColor);

            Vector3 glarePosition          = position + forwardVector * 0.28f;
            var     dot                    = Vector3.Dot(Vector3.Normalize(MySector.MainCamera.Position - glarePosition), forwardVector);
            float   angle                  = 1 - Math.Abs(dot);
            float   alphaGlareAlphaBlended = (float)Math.Pow(1 - angle, 2);
            float   alphaGlareAdditive     = (float)Math.Pow(1 - angle, 2);
            float   alphaCone              = (1 - (float)Math.Pow(1 - angle, 30)) * 0.5f;

            float reflectorRadiusForAlphaBlended = MathHelper.Lerp(0.1f, 0.5f, alphaGlareAlphaBlended); //3.5f;

            //  Multiply alpha by reflector level (and not the color), because if we multiply the color and let alpha unchanged, reflector cune will be drawn as very dark cone, but still visible
            var reflectorLevel = m_character.CurrentLightPower;

            m_light.ReflectorIntensity = reflectorLevel;

            alphaCone *= reflectorLevel * 0.2f;
            alphaGlareAlphaBlended *= reflectorLevel * 0.1f;
            alphaGlareAdditive     *= reflectorLevel * 0.8f;

            float distance = Vector3.Distance(m_character.PositionComp.GetPosition(), MySector.MainCamera.Position);

            if (!m_character.IsInFirstPersonView && distance < MyCharacter.LIGHT_GLARE_MAX_DISTANCE && reflectorLevel > 0)
            {
                float alpha = MathHelper.Clamp((MyCharacter.LIGHT_GLARE_MAX_DISTANCE - 10.0f) / distance, 0, 1);

                if (reflectorLength > 0 && reflectorThickness > 0)
                {
                    if (m_leftGlare != null)
                    {
                        MyTransparentGeometry.AddLineBillboard("ReflectorConeCharacter", new Vector4(color, 1.0f) * alphaCone * alpha,
                                                               m_leftGlare.Position,
                                                               m_leftGlare.ReflectorDirection, reflectorLength, reflectorThickness);
                    }

                    if (m_rightGlare != null)
                    {
                        MyTransparentGeometry.AddLineBillboard("ReflectorConeCharacter", new Vector4(color, 1.0f) * alphaCone * alpha,
                                                               m_rightGlare.Position,
                                                               m_rightGlare.ReflectorDirection, reflectorLength, reflectorThickness);
                    }
                }

                if (m_leftGlare != null)
                {
                    MyTransparentGeometry.AddPointBillboard("ReflectorGlareAlphaBlended", new Vector4(color, 1.0f) * alphaGlareAlphaBlended * alpha,
                                                            m_leftGlare.Position, reflectorRadiusForAlphaBlended * 0.3f, 0);
                }

                if (m_rightGlare != null)
                {
                    MyTransparentGeometry.AddPointBillboard("ReflectorGlareAlphaBlended", new Vector4(color, 1.0f) * alphaGlareAlphaBlended * alpha,
                                                            m_rightGlare.Position, reflectorRadiusForAlphaBlended * 0.3f, 0);
                }
            }

            DrawJetpackThrusts(m_character.UpdateCalled());

            if (m_character.Hierarchy.Parent != null)
            {
                if (m_leftGlare != null && m_leftGlare.LightOn == true)
                {
                    m_leftGlare.LightOn = false;
                    m_leftGlare.GlareOn = false;
                    m_leftGlare.UpdateLight();
                }

                if (m_rightGlare != null && m_rightGlare.LightOn == true)
                {
                    m_rightGlare.LightOn = false;
                    m_rightGlare.GlareOn = false;
                    m_rightGlare.UpdateLight();
                }
            }
            else
            {
                if (m_leftGlare != null && m_leftGlare.LightOn == false)
                {
                    m_leftGlare.LightOn = true;
                    m_leftGlare.GlareOn = true;
                    m_leftGlare.UpdateLight();
                }

                if (m_rightGlare != null && m_rightGlare.LightOn == true)
                {
                    m_rightGlare.LightOn = true;
                    m_rightGlare.GlareOn = true;
                    m_rightGlare.UpdateLight();
                }
            }

            if (MySession.ControlledEntity == m_character)
            {
                if (m_character.IsDead && m_character.CurrentRespawnCounter > 0)
                {
                    DrawBlood(1);
                }

                if (!m_character.IsDead && m_currentHitIndicatorCounter > 0)
                {
                    m_currentHitIndicatorCounter -= MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

                    if (m_currentHitIndicatorCounter < 0)
                    {
                        m_currentHitIndicatorCounter = 0;
                    }

                    float alpha = m_currentHitIndicatorCounter / HIT_INDICATOR_LENGTH;

                    DrawBlood(alpha);
                }

                if (m_character.StatComp != null)
                {
                    var healthRatio = m_character.StatComp.HealthRatio;
                    if (healthRatio <= MyCharacterStatComponent.LOW_HEALTH_RATIO && !m_character.IsDead)
                    {
                        float alpha = MathHelper.Clamp(MyCharacterStatComponent.LOW_HEALTH_RATIO - healthRatio, 0, 1) / MyCharacterStatComponent.LOW_HEALTH_RATIO + 0.3f;
                        DrawBlood(alpha);
                    }
                }
            }

            //DebugDraw();
        }
Esempio n. 17
0
        private void Draw()
        {
            if (target == null)
            {
                return;
            }
            if (connector == null)
            {
                return;
            }
            if (MyAPIGateway.Session?.Player?.Controller?.ControlledEntity?.Entity == null)
            {
                return;
            }
            if (MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetTopMostParent() != connector.GetTopMostParent())
            {
                return;
            }
            if (DockCore.instance.DrawHud != true)
            {
                return;
            }

            DockCore.instance.DrawCenterDot();            //draw the center dot
            MatrixD mergepoint = new MatrixD(connector.WorldMatrix);

            mergepoint.Translation = target.WorldMatrix.Translation + (MathHelper.Clamp(Vector3D.Distance(connector.WorldMatrix.Translation, target.WorldMatrix.Translation), 5d, double.MaxValue) * target.WorldMatrix.Forward);
            MyTransparentGeometry.AddPointBillboard(DockCore.WHITEDOT, Color.Green.ToVector4(), connector.WorldMatrix.Translation + (connector.WorldMatrix.Forward * connector.CubeGrid.GridSize / 2), 1, 0.0f);

            Vector2D dotpos = DockCore.instance.DrawOtherDot(CorrectRot(mergepoint), target.WorldAABB.Center, DockCore.DotObject.Rotate);

            DockCore.instance.SetDistanceMessage(string.Format("    <color=teal>Distance: {0:N}", Vector3D.Distance(target.WorldMatrix.Translation, connector.WorldMatrix.Translation)));

            MatrixD targetpoint = new MatrixD(target.WorldMatrix);

            targetpoint.Translation += targetpoint.Forward * connector.CubeGrid.GridSize / 2;
            MyTransparentGeometry.AddPointBillboard(DockCore.WHITEDOT, Color.Purple.ToVector4(), targetpoint.Translation, 1, 0.0f);

            Vector2D anglepos = DockCore.instance.DrawOtherDot(CorrectRot(targetpoint), connector.WorldAABB.Center, DockCore.DotObject.Translate);

            //var dot = Vector3D.Dot(-target.WorldMatrix.Right, connector.WorldMatrix.Right) - 1;

            if (dotpos.Length() > 0.05)
            {
                DockCore.instance.DrawArrow(dotpos);
                DockCore.instance.SetAngleMessage();
            }
            else
            {
                if (anglepos.Length() > 0.05)
                {
                    DockCore.instance.DrawArrow(anglepos);
                    DockCore.instance.SetTranslationMessage();
                }
                else
                {
                    DockCore.instance.HideArrow();
                    DockCore.instance.SetApproachMessage();
                }
            }
            //DockCore.instance.TextAPI.Send(new HUDTextNI.HUDMessage(4, 20, new Vector2D(-0.4, -0.4),1,true, true, Color.Black, string.Format("{0}<color=teal>", instruction)));
        }
        public override void Draw()
        {
            base.Draw();

            MyCharacter character     = m_skinnedEntity as MyCharacter;
            Vector3     position      = m_light.Position;
            Vector3     forwardVector = m_light.ReflectorDirection;

            float reflectorLength    = MyCharacter.REFLECTOR_BILLBOARD_LENGTH * 0.4f * 0.16f;
            float reflectorThickness = MyCharacter.REFLECTOR_BILLBOARD_THICKNESS * 0.08f;

            Vector3 color = new Vector3(m_light.ReflectorColor);

            Vector3 glarePosition          = position + forwardVector * 0.28f;
            var     dot                    = Vector3.Dot(Vector3.Normalize(MySector.MainCamera.Position - glarePosition), forwardVector);
            float   angle                  = 1 - Math.Abs(dot);
            float   alphaGlareAlphaBlended = (float)Math.Pow(1 - angle, 2);
            float   alphaCone              = (1 - (float)Math.Pow(1 - angle, 30)) * 0.5f;

            float reflectorRadiusForAlphaBlended = MathHelper.Lerp(0.1f, 0.5f, alphaGlareAlphaBlended); //3.5f;

            //  Multiply alpha by reflector level (and not the color), because if we multiply the color and let alpha unchanged, reflector cune will be drawn as very dark cone, but still visible
            var reflectorLevel = character.CurrentLightPower;

            alphaCone *= reflectorLevel * 0.2f;
            alphaGlareAlphaBlended *= reflectorLevel * 0.1f;

            float distance = Vector3.Distance(character.PositionComp.GetPosition(), MySector.MainCamera.Position);

            if ((character != MySession.Static.LocalCharacter || !character.IsInFirstPersonView) &&
                distance < MyCharacter.LIGHT_GLARE_MAX_DISTANCE && reflectorLevel > 0 &&
                m_leftLightIndex != -1 && m_rightLightIndex != -1)
            {
                float alpha = MathHelper.Clamp((MyCharacter.LIGHT_GLARE_MAX_DISTANCE - 10.0f) / distance, 0, 1);

                if (reflectorLength > 0 && reflectorThickness > 0 && alpha > 0)
                {
                    MyTransparentGeometry.AddLineBillboard("ReflectorConeCharacter", new Vector4(color, 1.0f) * alphaCone * alpha,
                                                           m_leftGlarePosition, m_light.ReflectorDirection, reflectorLength, reflectorThickness, MyBillboard.BlenType.AdditiveBottom);
                    MyTransparentGeometry.AddLineBillboard("ReflectorConeCharacter", new Vector4(color, 1.0f) * alphaCone * alpha,
                                                           m_rightGlarePosition, m_light.ReflectorDirection, reflectorLength, reflectorThickness, MyBillboard.BlenType.AdditiveBottom);
                }

                if (dot > 0)
                {
                    MyTransparentGeometry.AddPointBillboard("ReflectorGlareAlphaBlended", new Vector4(color, 1.0f) * alphaGlareAlphaBlended * alpha,
                                                            m_leftGlarePosition, reflectorRadiusForAlphaBlended * 0.3f, 0, -1, MyBillboard.BlenType.AdditiveTop);
                    MyTransparentGeometry.AddPointBillboard("ReflectorGlareAlphaBlended", new Vector4(color, 1.0f) * alphaGlareAlphaBlended * alpha,
                                                            m_rightGlarePosition, reflectorRadiusForAlphaBlended * 0.3f, 0, -1, MyBillboard.BlenType.AdditiveTop);
                }
            }

            DrawJetpackThrusts(character.UpdateCalled());

            //Maybe this check is not needed at all? In every case we want the DrawBlood effect when damaged
            if (MySession.Static.ControlledEntity == character ||
                MySession.Static.ControlledEntity is MyCockpit && ((MyCockpit)MySession.Static.ControlledEntity).Pilot == character ||
                MySession.Static.ControlledEntity is MyLargeTurretBase && ((MyLargeTurretBase)MySession.Static.ControlledEntity).Pilot == character
                )
            {
                if (character.IsDead && character.CurrentRespawnCounter > 0)
                {
                    DrawBlood(1);
                }

                if (!character.IsDead && m_currentHitIndicatorCounter > 0)
                {
                    m_currentHitIndicatorCounter -= VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

                    if (m_currentHitIndicatorCounter < 0)
                    {
                        m_currentHitIndicatorCounter = 0;
                    }

                    float alpha = m_currentHitIndicatorCounter / HIT_INDICATOR_LENGTH;

                    DrawBlood(alpha);
                }

                if (character.StatComp != null)
                {
                    var healthRatio = character.StatComp.HealthRatio;
                    if (healthRatio <= MyCharacterStatComponent.LOW_HEALTH_RATIO && !character.IsDead)
                    {
                        float alpha = MathHelper.Clamp(MyCharacterStatComponent.LOW_HEALTH_RATIO - healthRatio, 0, 1) / MyCharacterStatComponent.LOW_HEALTH_RATIO + 0.3f;
                        DrawBlood(alpha);
                    }
                }
            }

            //DebugDraw();
        }
        private void DrawJetpackThrusts(bool updateCalled)
        {
            MyCharacter character = m_skinnedEntity as MyCharacter;

            if (character == null || character.GetCurrentMovementState() == MyCharacterMovementEnum.Died)
            {
                return;
            }

            var jetpack = character.JetpackComp;

            if (jetpack == null || !jetpack.CanDrawThrusts)
            {
                return;
            }

            var thrustComponent = Container.Get <MyEntityThrustComponent>();

            if (thrustComponent == null)
            {
                return;
            }

            //VRageRender.MyRenderProxy.DebugDrawLine3D(WorldMatrix.Translation, WorldMatrix.Translation + Physics.LinearAcceleration, Color.White, Color.Green, false);

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

            foreach (MyJetpackThrust thrust in m_jetpackThrusts)
            {
                Vector3D position = Vector3D.Zero;

                if ((jetpack.TurnedOn && jetpack.IsPowered) && (!character.IsInFirstPersonView || character != MySession.Static.LocalCharacter))
                {
                    var      thrustMatrix = (MatrixD)thrust.ThrustMatrix * Container.Entity.PositionComp.WorldMatrix;
                    Vector3D forward      = Vector3D.TransformNormal(thrust.Forward, thrustMatrix);
                    position  = thrustMatrix.Translation;
                    position += forward * thrust.Offset;

                    float flameScale = 0.05f;
                    if (updateCalled)
                    {
                        thrust.ThrustRadius = MyUtils.GetRandomFloat(0.9f, 1.1f) * flameScale;
                    }

                    float strength = Vector3.Dot(forward, -Vector3.Transform(thrustComponent.FinalThrust, Entity.WorldMatrix.GetOrientation()) / Entity.Physics.Mass);

                    strength = MathHelper.Clamp(strength * 0.09f, 0.1f, 1f);

                    if (strength > 0 && thrust.ThrustRadius > 0)
                    {
                        float angle     = 1 - Math.Abs(Vector3.Dot(MyUtils.Normalize(MySector.MainCamera.Position - position), forward));
                        float alphaCone = (1 - (float)Math.Pow(1 - angle, 30)) * 0.5f;

                        if (updateCalled)
                        {
                            thrust.ThrustLength    = strength * 10 * MyUtils.GetRandomFloat(0.6f, 1.0f) * flameScale;
                            thrust.ThrustThickness = MyUtils.GetRandomFloat(thrust.ThrustRadius * 0.90f, thrust.ThrustRadius);
                        }

                        //  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(thrust.ThrustMaterial, thrust.Light.Color * alphaCone * strength, position,
                                                               GetRenderObjectID(), ref worldToLocal, forward, thrust.ThrustLength, thrust.ThrustThickness, MyBillboard.BlenType.AdditiveBottom);
                    }

                    if (thrust.ThrustRadius > 0)
                    {
                        MyTransparentGeometry.AddPointBillboard(thrust.ThrustMaterial, thrust.Light.Color, position, GetRenderObjectID(), ref worldToLocal,
                                                                thrust.ThrustRadius, 0, -1, MyBillboard.BlenType.AdditiveBottom);
                    }
                }
                else
                {
                    if (updateCalled || (character.IsUsing != null))
                    {
                        thrust.ThrustRadius = 0;
                    }
                }

                if (thrust.Light != null)
                {
                    if (thrust.ThrustRadius > 0)
                    {
                        thrust.Light.LightOn   = true;
                        thrust.Light.Intensity = JETPACK_LIGHT_INTENSITY_BASE + thrust.ThrustLength * JETPACK_LIGHT_INTENSITY_LENGTH;

                        thrust.Light.Range    = thrust.ThrustRadius * JETPACK_LIGHT_RANGE_RADIUS + thrust.ThrustLength * JETPACK_LIGHT_RANGE_LENGTH;
                        thrust.Light.Position = Vector3D.Transform(position, MatrixD.Invert(Container.Entity.PositionComp.WorldMatrix));
                        thrust.Light.ParentID = GetRenderObjectID();

                        thrust.Light.GlareOn = true;

                        thrust.Light.GlareIntensity = JETPACK_GLARE_INTENSITY_BASE + thrust.ThrustLength * JETPACK_GLARE_INTENSITY_LENGTH;

                        thrust.Light.GlareMaterial = "GlareJetpack";
                        thrust.Light.GlareType     = VRageRender.Lights.MyGlareTypeEnum.Normal;

                        thrust.Light.GlareSize = (thrust.ThrustRadius * JETPACK_GLARE_SIZE_RADIUS + thrust.ThrustLength * JETPACK_GLARE_SIZE_LENGTH) * thrust.ThrustGlareSize;

                        thrust.Light.GlareQuerySize = 0.1f;
                        thrust.Light.UpdateLight();
                    }
                    else
                    {
                        thrust.Light.GlareOn = false;
                        thrust.Light.LightOn = false;
                        thrust.Light.UpdateLight();
                    }
                }
            }
        }
Esempio n. 20
0
        //  Draw the projectile but only if desired polyline trail distance can fit in the trajectory (otherwise we will see polyline growing from the origin and it's ugly).
        //  Or draw if this is last draw of this projectile (useful for short-distance shots).
        public void Draw()
        {
            const float PROJECTILE_POLYLINE_DESIRED_LENGTH = 120;

            float trajectoryLength = Vector3.Distance(m_position, m_origin);

            if ((trajectoryLength > 0) || (m_state == MyProjectileStateEnum.KILLED))
            {
                if (m_state == MyProjectileStateEnum.KILLED)
                {
                    m_state = MyProjectileStateEnum.KILLED_AND_DRAWN;
                }

                if (!m_positionChecked)
                {
                    return;
                }



                //  If we calculate previous position using normalized direction (insted of velocity), projectile trails will
                //  look like coming from cannon, and that is desired. Even during fast movement, acceleration, rotation or changes in movement directions.
                //Vector3 previousPosition = m_position - m_directionNormalized * projectileTrailLength * 1.05f;
                Vector3 previousPosition = m_position - m_directionNormalized * PROJECTILE_POLYLINE_DESIRED_LENGTH * MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                //Vector3 previousPosition = m_previousPosition;
                //Vector3 previousPosition = m_initialSunWindPosition - MyMwcUtils.Normalize(m_desiredVelocity) * projectileTrailLength;

                Vector3 direction = Vector3.Normalize(m_position - previousPosition);

                float projectileTrailLength = 40 * LengthMultiplier;// PROJECTILE_POLYLINE_DESIRED_LENGTH;

                projectileTrailLength *= MyMwcUtils.GetRandomFloat(0.6f, 0.8f);

                if (trajectoryLength < projectileTrailLength)
                {
                    projectileTrailLength = trajectoryLength;
                }

                previousPosition = m_position - projectileTrailLength * direction;
                if (m_externalAddition >= 1.0f)
                {
                    m_externalAddition = 0.5f;
                }


                //float color = MyMwcUtils.GetRandomFloat(1, 2);
                float color     = MyMwcUtils.GetRandomFloat(1, 2);
                float thickness = m_thicknessMultiplier * MyMwcUtils.GetRandomFloat(0.2f, 0.3f);

                //  Line particles (polyline) don't look good in distance. Start and end aren't rounded anymore and they just
                //  look like a pieces of paper. Especially when zoom-in.
                thickness *= MathHelper.Lerp(0.2f, 0.8f, MyCamera.Zoom.GetZoomLevel());

                float alphaCone  = 1;
                float alphaGlare = 1;

                if (BlendByCameraDirection)
                {
                    float angle = 1 - Math.Abs(Vector3.Dot(MyMwcUtils.Normalize(MyCamera.ForwardVector), direction));
                    alphaGlare = (float)Math.Pow(1 - angle, 2);
                    alphaCone  = (1 - (float)Math.Pow(1 - angle, 30));
                }

                MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.ProjectileTrailLine, new Vector4(m_ammoProperties.TrailColor * color, 1) * alphaCone,
                                                       previousPosition, direction, projectileTrailLength, thickness);

                if (FrontBillboardMaterial.HasValue)
                {
                    MyTransparentGeometry.AddPointBillboard(FrontBillboardMaterial.Value, new Vector4(m_ammoProperties.TrailColor * color, 1) * alphaGlare, m_position, 0.8f * FrontBillboardSize, 0);
                }
            }
        }
        /// <summary>
        /// Render method is called directly by renderer. Depending on stage, post process can do various things
        /// </summary>
        /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights()
        public static void Draw()
        {
            switch (m_State)
            {
            case NuclearState.FADE_IN:
                m_flashIntensity = (MyMinerGame.TotalGamePlayTimeInMilliseconds - m_StartMilliseconds) / FADE_IN_TIME;
                if (m_flashIntensity >= 1.0f)
                {
                    m_State             = NuclearState.FLASH;
                    m_StartMilliseconds = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                }
                break;

            case NuclearState.FLASH:
                m_flashIntensity = 1.0f;
                if (MyMinerGame.TotalGamePlayTimeInMilliseconds > (m_StartMilliseconds + FLASH_TIME))
                {
                    m_StartMilliseconds = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                    m_State             = NuclearState.FLASH_IN;
                }
                break;

            case NuclearState.FLASH_IN:
                //m_flashIntensity = 1.0f - ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_StartMilliseconds) / 2000.0f/*MyFlashBombConstants.FADE_OUT_TIME*/);
                m_flashIntensity = 1 + 10 * (MyMinerGame.TotalGamePlayTimeInMilliseconds - m_StartMilliseconds) / FLASH_IN_TIME;
                if (m_flashIntensity >= 11.0f)
                {
                    if (m_burningCue != null && m_burningCue.Value.IsPlaying)
                    {
                        m_burningCue.Value.Stop(SharpDX.XACT3.StopFlags.Release);
                    }

                    if (OnExplosionMax != null)
                    {
                        OnExplosionMax();
                    }

                    m_State             = NuclearState.FADE_OUT;
                    m_StartMilliseconds = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                }
                break;

            case NuclearState.FADE_OUT:
                m_flashIntensity = 1 + MAX_FLASH_INTENSITY * (1.0f - ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_StartMilliseconds) / FADE_OUT_TIME));
                if (m_flashIntensity <= 0)
                {
                    m_StartMilliseconds = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                    m_State             = NuclearState.INACTIVE;

                    MyPostProcessGodRays godRays = (MyPostProcessGodRays)MyRender.GetPostProcess(MyPostProcessEnum.GodRays);
                    godRays.Enabled = m_godRaysState;
                    MySector.GodRaysProperties.Enabled = false;

                    m_preallocatedExplosionLines.DeallocateAll();
                    m_flashIntensity = 0;

                    if (OnExplosionDone != null)
                    {
                        OnExplosionDone();
                    }
                }
                break;
            }

            if (m_State != NuclearState.INACTIVE)
            {
                MyRender.Sun.Direction = Vector3.Normalize(MyCamera.Position - m_explosionCenter);
                MyRender.Sun.Intensity = 10 * m_flashIntensity;
                MyRender.Sun.Color     = Vector4.One;

                MinerWars.AppCode.Game.Managers.Session.MySession.PlayerShip.DoDamage(m_flashIntensity * MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS, 0, 0, MyDamageType.Radioactivity, MyAmmoType.None, null);
                MinerWars.AppCode.Game.Managers.Session.MySession.PlayerShip.IncreaseHeadShake(MathHelper.Clamp(2f * m_flashIntensity, 3, 10));

                UpdateExplosionLines();

                MyTransparentGeometry.AddPointBillboard(MyTransparentMaterialEnum.SunDisk, Vector4.One, m_explosionCenter, Math.Max(m_flashIntensity * 5000, 1), 0);

                foreach (LinkedListNode <ExplosionLine> explosionLine in m_preallocatedExplosionLines)
                {
                    MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.Smoke_square_unlit, Vector4.One, m_explosionCenter, explosionLine.Value.ActualDir, 10000, 100);
                }

                MySector.GodRaysProperties.Exposition = 0.5f * m_flashIntensity; //0.077f
                MySector.GodRaysProperties.Weight     = 2.5f * m_flashIntensity; //1.27f
            }
        }