public override void Draw() { base.Draw(); if (!ShouldDrawParticles) { return; } var direction = -Vector3.Normalize(ControlledVelocity); float thickness = 0.025f; float speed = ControlledVelocity.Length(); float length = (float)MathHelper.Clamp(speed / 50.0f, 0.0, 1.0); foreach (var particle in m_activeParticles) { if (!particle.Active) { continue; } MyTransparentGeometry.AddLineBillboard(particle.Material, particle.Color, particle.Position, direction, length, thickness); } }
private void RunShrinks(AvShot av) { var s = av.TracerShrinks.Dequeue(); if (av.LastTick != Session.Tick) { if (!av.AmmoDef.Const.OffsetEffect) { if (av.OnScreen != AvShot.Screen.None) { MyTransparentGeometry.AddLineBillboard(av.AmmoDef.Const.TracerTextures[0], s.Color, s.NewFront, av.PointDir, s.Length, s.Thickness); } } else if (av.OnScreen != AvShot.Screen.None) { av.DrawLineOffsetEffect(s.NewFront, -av.PointDir, s.Length, s.Thickness, s.Color); } if (av.Trail != AvShot.TrailState.Off && av.Back) { av.RunGlow(ref s, true); } } if (av.TracerShrinks.Count == 0) { av.ResetHit(); } }
public void DebugDraw() { if (!RailConstants.Debug.DrawSwitchControllers) { return; } if (((IMyUtilities)MyAPIUtilities.Static).IsDedicated) { return; } const float vertOffset = 1f; if (Entity == null || !Entity.InScene) { return; } if (Vector3D.DistanceSquared(MyCameraComponent.ActiveCamera.GetPosition(), Entity.GetPosition()) > 100 * 100) { return; } var intersection = _controller?.Junction; if (intersection == null) { return; } var intersectPos = intersection.Position + intersection.Up * vertOffset + _controller.Tangent * 0.5f; var connection = new LineD(Entity.GetPosition(), intersectPos); MyTransparentGeometry.AddLineBillboard(SquareMaterial, new Vector4(1, 0, 1, 1), connection.From, (Vector3)connection.Direction, (float)connection.Length, 0.05f); }
public void Draw() { // Most of this function was ripped from whiplash141's weapon framework. if (MyRandom.Instance.NextFloat() < Ammo.ProjectileTrailProbability) { float length = 0.6f * 40f * Ammo.ProjectileTrailScale; Vector3D start; if (DrawFullTracer) { start = Position - (Direction * length); } else { float distance = (float)Vector3D.Distance(Origin, Position); if (length <= distance) { DrawFullTracer = true; start = Position - (Direction * length); } else { start = Origin; length = distance; } } float scaleFactor = MyParticlesManager.Paused ? 1f : MyUtils.GetRandomFloat(1f, 2f); float thickness = (MyParticlesManager.Paused ? 0.2f : MyUtils.GetRandomFloat(0.2f, 0.3f)) * Ammo.ProjectileTrailScale; thickness *= MathHelper.Lerp(0.2f, 0.8f, 1f); MyStringId mat = string.IsNullOrWhiteSpace(Ammo.ProjectileTrailMaterial) ? MyStringId.GetOrCompute("ProjectileTrailLine") : MyStringId.GetOrCompute(Ammo.ProjectileTrailMaterial); MyTransparentGeometry.AddLineBillboard(mat, new Vector4(Ammo.ProjectileTrailColor * scaleFactor * 10f, 1f), start, Direction, length, thickness); } }
public void DrawTracer() { if (MyAPIGateway.Utilities.IsDedicated) { return; } // Draw tracer if (_drawTracer) { float scaleFactor = MyParticlesManager.Paused ? 1f : MyUtils.GetRandomFloat(1f, 2f); float lengthMultiplier = 40f * _tracerScale; lengthMultiplier *= /*MyParticlesManager.Paused*/ true ? 0.6f : MyUtils.GetRandomFloat(0.6f, 0.8f); var startPoint = _to - _direction * lengthMultiplier; float thickness = (MyParticlesManager.Paused ? 0.2f : MyUtils.GetRandomFloat(0.2f, 0.3f)) * _tracerScale; thickness *= MathHelper.Lerp(0.2f, 0.8f, 1f); MyTransparentGeometry.AddLineBillboard(_bulletMaterial, new Vector4(_tracerColor * scaleFactor * 10f, 1f), startPoint, _direction, lengthMultiplier, thickness); } // Draw bullet trail if (_drawTrail) { MySimpleObjectDraw.DrawLine(_from, _to, _material, ref _lineColor, _tracerScale * 0.1f); } }
public override void Draw() { base.Draw(); ProfilerShort.Begin("Fireflies.Draw"); var scale = 0.075f; float width = scale / 1.66f; float height = scale; foreach (var particle in m_activeParticles) { if (!particle.Active) { continue; } Vector4 drawColor = particle.Color; var lifeRatio = (float)(MySandboxGame.TotalGamePlayTimeInMilliseconds - particle.BirthTime) / (float)particle.LifeTime; if (lifeRatio < 0.1f) { drawColor = particle.Color * lifeRatio; } else if (lifeRatio > 0.9f) { drawColor = particle.Color * (1.0f - lifeRatio); } var directionVector = Vector3D.CalculatePerpendicularVector(-Vector3D.Normalize(particle.Position - MySector.MainCamera.Position)); MyTransparentGeometry.AddLineBillboard(particle.Material, drawColor, particle.Position, directionVector, height, width); } ProfilerShort.End(); }
public static void Draw(this IEnumerable <LineD> lines, Vector4 color, float thickness, MyStringId?material = null) { foreach (var line in lines) { MyTransparentGeometry.AddLineBillboard(material ?? Square, color, line.From, line.Direction, (float)line.Length, thickness); } }
public void DrawTracer() { //draw bullet float scaleFactor = MyParticlesManager.Paused ? 1f : MyUtils.GetRandomFloat(1f, 2f); float lengthMultiplier = 40f * _tracerScale; lengthMultiplier *= MyParticlesManager.Paused ? 0.6f : MyUtils.GetRandomFloat(0.6f, 0.8f); var startPoint = _position - _direction * lengthMultiplier; float thickness = (MyParticlesManager.Paused ? 0.2f : MyUtils.GetRandomFloat(0.2f, 0.3f)) * _tracerScale; thickness *= MathHelper.Lerp(0.2f, 0.8f, 1f /*MySector.MainCamera.Zoom.GetZoomLevel()*/); if (lengthMultiplier > 0f && !_targetHit && Vector3D.DistanceSquared(_position, _origin) > lengthMultiplier * lengthMultiplier) { MyTransparentGeometry.AddLineBillboard(bulletMaterial, new Vector4(_tracerColor * scaleFactor * 10f, 1f), startPoint, _direction, lengthMultiplier, thickness); } if (_targetHit) { MySimpleObjectDraw.DrawLine(_origin, _hitPosition, material, ref _lineColor, _tracerScale * 0.1f); } else { MySimpleObjectDraw.DrawLine(_origin, _position, material, ref _lineColor, _tracerScale * 0.1f); } }
private void DrawTransparentBox(MatrixD matrix, BoundingBoxD bb, Color?lineColor = null, bool drawBorder = true) { count++; Color color = Color.FromNonPremultiplied(new Vector4(0.1f, 0.1f, 0.1f, 0.7f)); MySimpleObjectDraw.DrawTransparentBox(ref matrix, ref bb, ref color, MySimpleObjectRasterizer.Solid, 1, 0.04f, MyStringId.GetOrCompute("HoneyComb"), null, false); if (!drawBorder) { return; } var setting = NaniteConstructionManager.BeaconTerminalSettings[BeaconBlock.EntityId]; var diff = (float)bb.Max.Max() / NaniteConstructionManager.Settings.AreaBeaconMaxSize; float lineSize = (0.1f * diff) + 0.01f; Color checkLineColor = Color.FromNonPremultiplied(new Vector4(1f, 1f, 1f, 0.7f)); if (lineColor.HasValue) { checkLineColor = lineColor.Value; } foreach (var item in bb.GetLines()) { var to = Vector3D.Transform(item.To, matrix); var from = Vector3D.Transform(item.From, matrix); var dir = Vector3D.Normalize(to - from); var length = (to - from).Length(); MyTransparentGeometry.AddLineBillboard(MyStringId.GetOrCompute("Firefly"), checkLineColor, from, dir, (float)length, lineSize); } }
public override bool Draw(MyRenderObject renderObject) { base.Draw(renderObject); // Draw muzzle flash int deltaTime = MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot; if (deltaTime <= MyMachineGunConstants.MUZZLE_FLASH_MACHINE_GUN_LIFESPAN) { float FAKE_RADIUS = MyMwcUtils.GetRandomFloat(0.5f, 1.5f); float FAKE_THICKNESS = MyMwcUtils.GetRandomFloat(FAKE_RADIUS - 0.1f, FAKE_RADIUS); float FAKE_LENGTH = MyMwcUtils.GetRandomFloat(7, 8); float FAKE_ANGLE = MyMwcUtils.GetRandomFloat(0, MathHelper.PiOver2); //float colorComponent = 1; float colorComponent = 1 - (float)deltaTime / (float)MyMachineGunConstants.MUZZLE_FLASH_MACHINE_GUN_LIFESPAN; colorComponent = 1 - (float)Math.Pow(colorComponent, 5); colorComponent *= 1.3f; //Vector4 color = new Vector4(1.0f, 1.0f, 1.0f, 1); Vector4 color = new Vector4(colorComponent, colorComponent, colorComponent, 1); Vector3 muzzleInWorldSpace = m_positionMuzzleInWorldSpace + WorldMatrix.Up * 0.2f; MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.MuzzleFlashMachineGunSide, color, muzzleInWorldSpace - WorldMatrix.Forward * 1.0f, WorldMatrix.Forward, FAKE_LENGTH, FAKE_THICKNESS); MyTransparentGeometry.AddPointBillboard(MyTransparentMaterialEnum.MuzzleFlashMachineGunFront, color, muzzleInWorldSpace, FAKE_RADIUS, FAKE_ANGLE); } return(true); }
private void DrawLines() { foreach (DrawLine line in _drawLines) { //MySimpleObjectDraw.DrawLine(line.From, line.To, line.Material, ref line.Color, line.Thickness); MyTransparentGeometry.AddLineBillboard(line.Material, line.Color, line.From, line.DirectionNormalized, line.Length, line.Thickness); } }
public static void GenerateMuzzleFlash(Vector3D position, Vector3 dir, uint renderObjectID, ref MatrixD worldToLocal, float radius, float length) { float angle = MyParticlesManager.Paused ? 0f : MyUtils.GetRandomFloat(0f, 1.570796f); float x = 10f; Vector4 color = new Vector4(x, x, x, 1f); MyTransparentGeometry.AddLineBillboard(ID_MUZZLE_FLASH_SIDE, color, position, renderObjectID, ref worldToLocal, dir, length, 0.15f, MyBillboard.BlendTypeEnum.AdditiveBottom, -1, 1f, null); MyTransparentGeometry.AddPointBillboard(ID_MUZZLE_FLASH_FRONT, color, position, renderObjectID, ref worldToLocal, radius, angle, -1, MyBillboard.BlendTypeEnum.AdditiveBottom, 1f, null); }
public static void GenerateMuzzleFlash(Vector3 position, Vector3 dir, float radius, float length, bool near = false) { float angle = MyMwcUtils.GetRandomFloat(0, MathHelper.PiOver2); float colorComponent = 1.3f; Vector4 color = new Vector4(colorComponent, colorComponent, colorComponent, 1); MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.MuzzleFlashMachineGunSide, color, position, dir, length * 2, 0.3f, 0, near); MyTransparentGeometry.AddPointBillboard(MyTransparentMaterialEnum.MuzzleFlashMachineGunFront, color, position, radius, angle, 0, false, near); }
public static void GenerateMuzzleFlash(Vector3D position, Vector3 dir, int renderObjectID, ref MatrixD worldToLocal, float radius, float length, bool near = false) { float angle = MyUtils.GetRandomFloat(0, MathHelper.PiOver2); float colorComponent = 1.3f; Vector4 color = new Vector4(colorComponent, colorComponent, colorComponent, 1); MyTransparentGeometry.AddLineBillboard("MuzzleFlashMachineGunSide", color, position, renderObjectID, ref worldToLocal, dir, length, 0.15f, 0, near); MyTransparentGeometry.AddPointBillboard("MuzzleFlashMachineGunFront", color, position, renderObjectID, ref worldToLocal, radius, angle, 0, false, near); }
public static void GenerateMuzzleFlash(Vector3D position, Vector3 dir, int renderObjectID, ref MatrixD worldToLocal, float radius, float length) { float angle = MyParticlesManager.Paused ? 0 : MyUtils.GetRandomFloat(0, MathHelper.PiOver2); float colorComponent = 1.3f; Vector4 color = new Vector4(colorComponent, colorComponent, colorComponent, 1); MyTransparentGeometry.AddLineBillboard("MuzzleFlashMachineGunSide", color, position, renderObjectID, ref worldToLocal, dir, length, 0.15f, VRageRender.MyBillboard.BlenType.Standard); MyTransparentGeometry.AddPointBillboard("MuzzleFlashMachineGunFront", color, position, renderObjectID, ref worldToLocal, radius, angle); }
private void DrawTransparentBox(MatrixD matrix, BoundingBoxD bb) { count++; Color color = Color.FromNonPremultiplied(new Vector4(0.1f, 0.1f, 0.1f, 0.7f)); MySimpleObjectDraw.DrawTransparentBox(ref matrix, ref bb, ref color, MySimpleObjectRasterizer.Solid, 1, 0.04f, VRage.Utils.MyStringId.GetOrCompute("HoneyComb"), null, false); Vector3D[] vertices = bb.GetCorners(); List <Line> lines = new List <Line>(); // Cuboid Outline lines.Add(new Line(vertices[0], vertices[1], false)); lines.Add(new Line(vertices[1], vertices[2], false)); lines.Add(new Line(vertices[2], vertices[3], false)); lines.Add(new Line(vertices[3], vertices[0], false)); lines.Add(new Line(vertices[0], vertices[4], false)); lines.Add(new Line(vertices[1], vertices[5], false)); lines.Add(new Line(vertices[4], vertices[5], false)); lines.Add(new Line(vertices[5], vertices[6], false)); lines.Add(new Line(vertices[6], vertices[7], false)); lines.Add(new Line(vertices[7], vertices[4], false)); lines.Add(new Line(vertices[2], vertices[6], false)); lines.Add(new Line(vertices[3], vertices[7], false)); // Crosses lines.Add(new Line(vertices[0], vertices[2], false)); lines.Add(new Line(vertices[1], vertices[3], false)); lines.Add(new Line(vertices[4], vertices[6], false)); lines.Add(new Line(vertices[5], vertices[7], false)); lines.Add(new Line(vertices[0], vertices[7], false)); lines.Add(new Line(vertices[3], vertices[4], false)); lines.Add(new Line(vertices[1], vertices[6], false)); lines.Add(new Line(vertices[2], vertices[5], false)); lines.Add(new Line(vertices[0], vertices[5], false)); lines.Add(new Line(vertices[1], vertices[4], false)); lines.Add(new Line(vertices[3], vertices[6], false)); lines.Add(new Line(vertices[2], vertices[7], false)); foreach (var item in lines) { var to = Vector3D.Transform(item.To, matrix); var from = Vector3D.Transform(item.From, matrix); var dir = Vector3D.Normalize(to - from); var length = (to - from).Length(); MyTransparentGeometry.AddLineBillboard(VRage.Utils.MyStringId.GetOrCompute("Firefly"), new Vector4(1f, 1f, 1f, 0.7f), from, dir, (float)length, 0.1f); } }
public static void DrawLine(Vector3 start, Vector3 end, MyTransparentMaterialEnum?material, ref Vector4 color, float thickness) { Vector3 dir = end - start; float len = dir.Length(); if (len > 0.1f) { dir = MyMwcUtils.Normalize(dir); MyTransparentGeometry.AddLineBillboard(material ?? MyTransparentMaterialEnum.ProjectileTrailLine, color, start, dir, len, thickness); } }
public override void Draw() { if (m_on) { Matrix world = WorldMatrix; for (int i = 0; i < m_raysStartPositions.Count; i++) { Vector3 rayPosition = m_raysStartPositions[i]; Vector3 rayStart = Vector3.Transform(rayPosition, world); MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.LightRay, Color, rayStart, world.Right, Size.X, RAY_THICKNESS); } } }
public override void Draw() { base.Draw(); ProfilerShort.Begin("MyThrust.Draw()"); var worldToLocal = MatrixD.Invert(Entity.PositionComp.WorldMatrix); if (m_thrust.CanDraw()) { m_thrust.UpdateThrustFlame(); m_thrust.UpdateThrustColor(); foreach (var f in m_thrust.Flames) { if (m_thrust.CubeGrid.Physics == null) { continue; } Vector3D forward = Vector3D.TransformNormal(f.Direction, Entity.PositionComp.WorldMatrix); var position = Vector3D.Transform(f.Position, Entity.PositionComp.WorldMatrix); float radius = m_thrust.ThrustRadiusRand * f.Radius; float length = m_thrust.ThrustLengthRand * f.Radius; float thickness = m_thrust.ThrustThicknessRand * f.Radius; Vector3D velocityAtNewCOM = Vector3D.Cross(m_thrust.CubeGrid.Physics.AngularVelocity, position - 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 - position), forward)); 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, position - forward * length * 0.25f, GetRenderObjectID(), ref worldToLocal, forward, length, thickness); } if (radius > 0) { MyTransparentGeometry.AddPointBillboard(m_thrust.FlamePointMaterial, m_thrust.ThrustColor, position, GetRenderObjectID(), ref worldToLocal, radius, 0); } } } if (m_thrust.Light != null) { m_thrust.UpdateLight(); } ProfilerShort.End(); }
internal void DrawLineOffsetEffect(Vector3D pos, Vector3D direction, double tracerLength, float beamRadius, Vector4 color) { MatrixD matrix; var up = MatrixD.Identity.Up; var startPos = pos + -(direction * tracerLength); MatrixD.CreateWorld(ref startPos, ref direction, ref up, out matrix); var offsetMaterial = AmmoDef.Const.TracerMaterial; var tracerLengthSqr = tracerLength * tracerLength; var maxOffset = AmmoDef.AmmoGraphics.Lines.OffsetEffect.MaxOffset; var minLength = AmmoDef.AmmoGraphics.Lines.OffsetEffect.MinLength; var maxLength = MathHelperD.Clamp(AmmoDef.AmmoGraphics.Lines.OffsetEffect.MaxLength, 0, tracerLength); double currentForwardDistance = 0; while (currentForwardDistance < tracerLength) { currentForwardDistance += MyUtils.GetRandomDouble(minLength, maxLength); var lateralXDistance = MyUtils.GetRandomDouble(maxOffset * -1, maxOffset); var lateralYDistance = MyUtils.GetRandomDouble(maxOffset * -1, maxOffset); Offsets.Add(new Vector3D(lateralXDistance, lateralYDistance, currentForwardDistance * -1)); } for (int i = 0; i < Offsets.Count; i++) { Vector3D fromBeam; Vector3D toBeam; if (i == 0) { fromBeam = matrix.Translation; toBeam = Vector3D.Transform(Offsets[i], matrix); } else { fromBeam = Vector3D.Transform(Offsets[i - 1], matrix); toBeam = Vector3D.Transform(Offsets[i], matrix); } Vector3 dir = (toBeam - fromBeam); var length = dir.Length(); var normDir = dir / length; MyTransparentGeometry.AddLineBillboard(offsetMaterial, color, fromBeam, normDir, length, beamRadius); if (Vector3D.DistanceSquared(matrix.Translation, toBeam) > tracerLengthSqr) { break; } } Offsets.Clear(); }
internal void update() { lifetime++; var progress = (float)lifetime / maxLifeTime; var range = 3f; var startFrom = from + dir * progress * dist; try { var Material = MyStringId.GetOrCompute("NPC_Rifle_Anim"); MyTransparentGeometry.AddLineBillboard(Material, Color.White.ToVector4(), startFrom, dir, range, 0.1f, BlendTypeEnum.SDR); } catch (NullReferenceException ex) { MyLog.Default.Error("Error while drawing billboard: " + ex); } }
private void DrawReflectorCone() { var world = Container.Entity.PositionComp.WorldMatrix; Vector3D position = Container.Entity.PositionComp.GetPosition(); Vector3D forwardVector = world.Forward; if (m_reflectorLight.Light.ReflectorOn) { m_reflectorLight.Light.ReflectorColor = m_reflectorLight.Color.ToVector4(); m_reflectorLight.Light.UpdateReflectorRangeAndAngle(m_reflectorLight.ShortReflectorForwardConeAngleDef, m_reflectorLight.ReflectorRadius); } float reflectorLength = 20f; float reflectorThickness = m_reflectorLight.IsLargeLight ? 9f : 3f; var color = m_reflectorLight.Light.ReflectorColor; var glarePosition = position + forwardVector * 0.112f * m_reflectorLight.CubeGrid.GridSize; var dot = Vector3.Dot(Vector3D.Normalize(MySector.MainCamera.Position - glarePosition), forwardVector); float angle = 1 - Math.Abs(dot); float alphaCone = (1 - (float)Math.Pow(1 - angle, 30)) * 0.15f; // 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; bool drivenFromFPS = MySession.Static.CameraController is MyCockpit ? ((MyCockpit)MySession.Static.CameraController).IsInFirstPersonView : false; if (!drivenFromFPS) { MyTransparentGeometry.AddLineBillboard( "ReflectorCone", color * alphaCone, position - forwardVector * m_reflectorLight.CubeGrid.GridSize * 0.32f, forwardVector, reflectorLength, reflectorThickness, VRageRender.MyBillboard.BlenType.AdditiveBottom); } }
public static void DrawTransparentPyramid(ref Vector3 start, ref MyQuad backQuad, ref Vector4 vctColor, int divideRatio, float thickness, MyTransparentMaterialEnum?lineMaterial = null) { Vector3 vctZero = Vector3.Zero; m_lineBuffer.Clear(); GenerateLines(start, backQuad.Point0, backQuad.Point1, ref m_lineBuffer, divideRatio); GenerateLines(start, backQuad.Point1, backQuad.Point2, ref m_lineBuffer, divideRatio); GenerateLines(start, backQuad.Point2, backQuad.Point3, ref m_lineBuffer, divideRatio); GenerateLines(start, backQuad.Point3, backQuad.Point0, ref m_lineBuffer, divideRatio); foreach (MyLine line in m_lineBuffer) { Vector3 dir = line.To - line.From; float len = dir.Length(); if (len > 0.1f) { dir = MyMwcUtils.Normalize(dir); MyTransparentGeometry.AddLineBillboard(lineMaterial ?? MyTransparentMaterialEnum.ProjectileTrailLine, vctColor, line.From, dir, len, thickness); } } }
void DrawWaypointEdge(Vector3 position1, Vector3 position2, Color color1, Color color2) { if (MyFakes.MWBUILDER) { MyDebugDraw.DrawText((position1 + position2) / 2, new StringBuilder(Vector3.Distance(position1, position2).ToString("#,###0.000")), Color.White, 1); } if (position1 == position2) { return; } Vector3 direction = position2 - position1; float lineLength = direction.Length(); direction.Normalize(); MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.ProjectileTrailLine, color1.ToVector4(), position1, direction, lineLength, 0.25f); if (MyWayPointGraph.WaypointsIgnoreDepth) { MyDebugDraw.DrawLine3D(position1, position2, color1, color2); } }
public override void Draw() { //if (Droplets.Active.Count >0) Logging.Instance.WriteLine($"droplets: {Droplets.Active.Count}"); var dropletsToDraw = Droplets.Active; if (dropletsToDraw.Count > 0) { for (int i = 0; i < 700; i++) //Switched to hard limit of line per tick { var droplet = dropletsToDraw[MyUtils.GetRandomInt(dropletsToDraw.Count - 1)]; if (droplet == null) { continue; } MyTransparentGeometry.AddLineBillboard(material, droplet.LineColor, droplet.StartPoint, droplet.Direction, droplet.DrawLength, lineThickness); } Droplets.DeallocateAll(); } //DrawLineFromPlayerToPlanetCentre(); //DrawAndLogFrustumBox(); }
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()); }
public override void Draw() { return; base.Draw(); ProfilerShort.Begin("Grassland.Draw"); var scale = 0.075f; float width = scale / 1.66f; float height = scale; foreach (var particle in m_activeParticles) { if (!particle.Active) { continue; } var directionVector = Vector3D.CalculatePerpendicularVector(-Vector3D.Normalize(particle.Position - MySector.MainCamera.Position)); MyTransparentGeometry.AddLineBillboard(particle.Material, particle.Color, particle.Position, directionVector, height, width); } ProfilerShort.End(); }
// 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); } } }
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(); } }
public static void DrawHighlightBox(MatrixD matrix, float scale, float lineWidth, MyStringId material, Color colorFace, Color colorWire, BlendTypeEnum blendType) { // optimized box draw compared to MySimpleObjectDraw.DrawTransparentBox; also allows consistent edge thickness MyQuadD quad; Vector3D p; MatrixD m; var halfScale = (scale * 0.5f); float lineLength = scale; const float ROTATE_90_RAD = (90f / 180f * MathHelper.Pi); // 90deg in radians p = matrix.Translation + matrix.Forward * halfScale; if (IsFaceVisible(p, matrix.Forward)) { MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref matrix); MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType); } p = matrix.Translation + matrix.Backward * halfScale; if (IsFaceVisible(p, matrix.Backward)) { MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref matrix); MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType); } p = matrix.Translation + matrix.Left * halfScale; m = matrix * MatrixD.CreateFromAxisAngle(matrix.Up, ROTATE_90_RAD); if (IsFaceVisible(p, matrix.Left)) { MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref m); MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType); } p = matrix.Translation + matrix.Right * halfScale; if (IsFaceVisible(p, matrix.Right)) { MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref m); MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType); } m = matrix * MatrixD.CreateFromAxisAngle(matrix.Left, ROTATE_90_RAD); p = matrix.Translation + matrix.Up * halfScale; if (IsFaceVisible(p, matrix.Up)) { MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref m); MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType); } p = matrix.Translation + matrix.Down * halfScale; if (IsFaceVisible(p, matrix.Down)) { MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref m); MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType); } var upHalf = (matrix.Up * halfScale); var rightHalf = (matrix.Right * halfScale); var forwardHalf = (matrix.Forward * halfScale); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + upHalf + -rightHalf + matrix.Forward * halfScale, matrix.Backward, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + upHalf + rightHalf + matrix.Forward * halfScale, matrix.Backward, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -upHalf + -rightHalf + matrix.Forward * halfScale, matrix.Backward, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -upHalf + rightHalf + matrix.Forward * halfScale, matrix.Backward, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + forwardHalf + -rightHalf + matrix.Up * halfScale, matrix.Down, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + forwardHalf + rightHalf + matrix.Up * halfScale, matrix.Down, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -forwardHalf + -rightHalf + matrix.Up * halfScale, matrix.Down, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -forwardHalf + rightHalf + matrix.Up * halfScale, matrix.Down, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + forwardHalf + -upHalf + matrix.Right * halfScale, matrix.Left, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + forwardHalf + upHalf + matrix.Right * halfScale, matrix.Left, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -forwardHalf + -upHalf + matrix.Right * halfScale, matrix.Left, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -forwardHalf + upHalf + matrix.Right * halfScale, matrix.Left, lineLength, lineWidth, blendType: blendType); }