Beispiel #1
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();
                    }
                }
            }
        }