Ejemplo n.º 1
0
 public override void Debug(StringBuilder sb)
 {
     base.Debug(sb);
     sb.Append("Lazing=").Append(IsShooting).Append(" ");
     sb.Append("BeamPower=").Append(_energyThroughput.ToString("F2")).Append("kW ");
     sb.Append("BeamColor=").AppendFormat("[{0:F2} {1:F2} {2:F2} {3:F2}] ", _beamColor.X, _beamColor.Y,
                                          _beamColor.Z, _beamColor.W);
     sb.Append("BeamThickness=")
     .Append(BeamController.BeamWidth(_energyThroughput)
             .ToString("F2")).Append("m ");
     sb.Append("Energy=").Append(_capacitorEnergy.ToString("F0")).Append("kJ ");
     sb.Append("Distance=")
     .Append(
         ((_raycastResult?.Fraction ?? float.PositiveInfinity) * Definition.MaxLazeDistance).ToString("F1"))
     .Append(" ");
 }
Ejemplo n.º 2
0
        public void Draw()
        {
            var fire = IsShooting;

            var result = _raycastResult;
            var matrix = _dummy.Dummy.WorldMatrix;
            var origin = matrix.Translation;
            var dir    = matrix.Forward;


            if (fire)
            {
                var from = origin;
                var to   = from + dir * Definition.MaxLazeDistance;

                if (result.HasValue)
                {
                    // if hitting a grid go an extra quarter block.  Otherwise go an extra fourth of the bounding box
                    var extraDist = (float)Math.Abs((result.Value.Root as IMyCubeGrid)?.GridSize ??
                                                    result.Value.Root?.PositionComp?.WorldAABB.HalfExtents
                                                    .Dot(dir) ??
                                                    0f) / 4f;
                    if (result.Value.Root is IMyVoxelBase)
                    {
                        extraDist = 0.1f;
                    }

                    to = result.Value.HitPosition + extraDist * dir;
                }

                var thickness = BeamController.BeamWidth(_energyThroughput);
                var color     = BeamController.BeamColor(_beamColor, _energyThroughput);
                MySimpleObjectDraw.DrawLine(from, to, BeamController.LaserMaterial, ref color, thickness);
            }

            if (!string.IsNullOrEmpty(Definition?.FxImpactName))
            {
                _fxImpactCount = Math.Max(_fxImpactCount - 1, 0);
                if (fire)
                {
                    _fxImpactCount = Math.Min(_fxImpactCount + Definition.FxImpactBirthRate,
                                              Definition.FxImpactMaxCount);
                }
                if (_fxImpactCount > 0 && result.HasValue)
                {
                    if (_fxImpactParticles == null)
                    {
                        var up    = (Vector3)dir;
                        var fwd   = Vector3.Normalize(Vector3.Cross(up, new Vector3(up.Y, up.Z, up.X)));
                        var world = MatrixD.CreateWorld(result.Value.HitPosition, fwd, up);
//                        MyParticlesManager.TryCreateParticleEffect(Definition?.FxImpactName, world, out _fxImpactParticles);
                        MyParticlesManager.TryCreateParticleEffect(Definition.FxImpactName, out _fxImpactParticles);
                    }

                    if (_fxImpactParticles != null)
                    {
                        {
                            var up  = (Vector3)dir;
                            var fwd = Vector3.Normalize(Vector3.Cross(up, new Vector3(up.Y, up.Z, up.X)));
                            _fxImpactParticles.WorldMatrix = MatrixD.CreateWorld(result.Value.HitPosition, fwd, up);
                            _fxImpactParticles.UserScale   = Definition.FxImpactScale;
                            _fxImpactParticles.Velocity    =
                                result.Value.Root?.Physics?.GetVelocityAtPoint(result.Value.HitPosition) ??
                                Vector3.Zero;
                        }

                        _fxImpactParticles.UserBirthMultiplier = _fxImpactCount;
                    }
                }
                else
                {
                    _fxImpactParticles?.StopEmitting();
                    if (_fxImpactParticles != null)
                    {
                        MyParticlesManager.RemoveParticleEffect(_fxImpactParticles);
                    }
                    _fxImpactParticles = null;
                }
            }
        }