Skip to content

Commit

Permalink
updated the heat indicator.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauge committed Jul 14, 2024
1 parent 71bd419 commit 0098d16
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 41 deletions.
100 changes: 64 additions & 36 deletions ThermalDynamics/Data/Scripts/Thermodynamics/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Sandbox.ModAPI;
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using VRage.Game;
using VRage.Game.Components;
Expand Down Expand Up @@ -56,34 +57,10 @@ public Color GetTemperatureColor(float temp)
return new Color(red, 0, blue, 255);
}

public void DrawBillboard(ThermalCell c, MatrixD cameraMatrix)
{
Vector3D blockPosition;

c.Block.ComputeWorldCenter(out blockPosition);

Color color = ColorExtensions.HSVtoColor(Tools.GetTemperatureColor(c.Temperature));

Vector3D drawPosition = MyAPIGateway.Session.Camera.WorldToScreen(ref blockPosition);
float distance = 0.00001f;

double blockDistance = (cameraMatrix.Translation - blockPosition).Length();
float scaler = (float)Tools.GetVisualSize(blockDistance, c.Grid.Grid.GridSizeHalf);


MyTransparentGeometry.AddBillboardOriented(
MyStringId.GetOrCompute("Square"), // Texture or material name for the billboard
color, // Color of the billboard
cameraMatrix.Translation + (cameraMatrix.Forward * distance) + (cameraMatrix.Up * drawPosition.Y*distance) + (cameraMatrix.Left * drawPosition.X*distance), // Position of the billboard
cameraMatrix.Left, // Left direction of the billboard
cameraMatrix.Up, // Up direction of the billboard
1f * scaler*distance, // Width of the billboard
1f * scaler*distance // Height of the billboard
);
}

public override void Draw()
{
public override void Simulate()
{
if (Settings.Debug && !MyAPIGateway.Utilities.IsDedicated)
{
//MyAPIGateway.Utilities.ShowNotification($"[Grid] Frequency: {Settings.Instance.Frequency}", 1, "White");
Expand All @@ -109,15 +86,6 @@ public override void Draw()
if (c == null)
return;


DrawBillboard(c, matrix);
for (int i = 0; i < c.Neighbors.Count; i++)
{
ThermalCell n = c.Neighbors[i];
DrawBillboard(n, matrix);
}


MyAPIGateway.Utilities.ShowNotification($"[Env] " +
$"sim: {Settings.Instance.SimulationSpeed.ToString("n2")} " +
$"freq: {Settings.Instance.Frequency.ToString("n2")} " +
Expand Down Expand Up @@ -164,5 +132,65 @@ public override void Draw()
//MyAPIGateway.Utilities.ShowNotification($"[External] {tGrid.Mapper.Blocks.Count} EComplete: {tGrid.Mapper.ExternalRoomUpdateComplete} BComplete: {tGrid.ThermalCellUpdateComplete}", 1, "White");
}
}
}

public override void Draw()
{
if (Settings.Debug && !MyAPIGateway.Utilities.IsDedicated)
{
//MyAPIGateway.Utilities.ShowNotification($"[Grid] Frequency: {Settings.Instance.Frequency}", 1, "White");
MatrixD matrix = MyAPIGateway.Session.Camera.WorldMatrix;

Vector3D start = matrix.Translation;
Vector3D end = start + (matrix.Forward * 15);

IHitInfo hit;
MyAPIGateway.Physics.CastRay(start, end, out hit);
MyCubeGrid grid = hit?.HitEntity as MyCubeGrid;
if (grid == null) return;

Vector3I position = grid.WorldToGridInteger(hit.Position + (matrix.Forward * 0.01f));

ThermalGrid g = grid.GameLogic.GetAs<ThermalGrid>();

IMySlimBlock block = grid.GetCubeBlock(position);

ThermalCell c = g.Get(block.Position);

if (c == null) return;

MyAPIGateway.Utilities.ShowNotification($"Made it to draw", 1);

DrawBillboard(c, matrix);
for (int i = 0; i < c.Neighbors.Count; i++)
{
ThermalCell n = c.Neighbors[i];
DrawBillboard(n, matrix);
}
}
}

public void DrawBillboard(ThermalCell c, MatrixD cameraMatrix)
{
Vector3D position;
c.Block.ComputeWorldCenter(out position);

float averageBlockLength = Vector3I.DistanceManhattan(c.Block.Max + 1, c.Block.Min) * 0.33f;

Color color = ColorExtensions.HSVtoColor(Tools.GetTemperatureColor(c.Temperature));

float distance = 0.01f;
position = cameraMatrix.Translation + (position - cameraMatrix.Translation) * distance;
float scaler = 1.2f * c.Grid.Grid.GridSizeHalf * averageBlockLength * distance;

MyTransparentGeometry.AddBillboardOriented(
MyStringId.GetOrCompute("GaugeThermalTexture"), // Texture or material name for the billboard
color, // Color of the billboard
position,
cameraMatrix.Left, // Left direction of the billboard
cameraMatrix.Up, // Up direction of the billboard
scaler, // Width of the billboard
scaler // Height of the billboard
);
}
}
}
6 changes: 3 additions & 3 deletions ThermalDynamics/Data/Scripts/Thermodynamics/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Settings
public const string Filename = "ThermodynamicsConfig.cfg";
public const string Name = "Thermodynamics";
public const bool Debug = true;
public const bool DebugBlockColors = false;
public const bool DebugBlockColors = true;

public static Settings Instance;

Expand Down Expand Up @@ -75,8 +75,8 @@ public static Settings GetDefaults()
Version = 1,
EnableSolarHeat = true,
EnableDamage = true,
Frequency = 60,
SimulationSpeed = 1,
Frequency = 15,
SimulationSpeed = 4,
SolarEnergy = 1000f,
EnvironmentalRaycastDistance = 5000f,
VaccumeRadiationStrength = 0.05f,
Expand Down
2 changes: 0 additions & 2 deletions ThermalDynamics/Data/Scripts/Thermodynamics/ThermalCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public class ThermalCell
public int ExposedSurfaces = 0;
public List<Vector3I> ExposedSurfaceDirections = new List<Vector3I>();



public ThermalCell(ThermalGrid g, IMySlimBlock b)
{
Grid = g;
Expand Down
18 changes: 18 additions & 0 deletions ThermalDynamics/Data/TransparentMaterials.sbc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<Definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<TransparentMaterials>
<TransparentMaterial>
<Id>
<TypeId>TransparentMaterialDefinition</TypeId>
<SubtypeId>GaugeThermalTexture</SubtypeId>
</Id>
<AlphaMistingEnable>false</AlphaMistingEnable>
<AlphaSaturation>1</AlphaSaturation>
<CanBeAffectedByOtherLights>false</CanBeAffectedByOtherLights>
<IgnoreDepth>false</IgnoreDepth>
<SoftParticleDistanceScale>0.1</SoftParticleDistanceScale>
<Texture>Textures\Particles\GaugeThermalTexture.dds</Texture>
<UseAtlas>false</UseAtlas>
</TransparentMaterial>
</TransparentMaterials>
</Definitions>
Binary file not shown.

0 comments on commit 0098d16

Please sign in to comment.