Add BinaryReader LGS rotation extension

This commit is contained in:
Jarrod Doyle 2024-09-07 12:20:13 +01:00
parent dd2fd3f37b
commit 23b5400eae
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
3 changed files with 9 additions and 4 deletions

View File

@ -79,11 +79,11 @@ public class BrList : IChunk
flags = reader.ReadSByte(); flags = reader.ReadSByte();
position = reader.ReadVec3(); position = reader.ReadVec3();
size = reader.ReadVec3(); size = reader.ReadVec3();
angle = new Vector3(reader.ReadUInt16(), reader.ReadUInt16(), reader.ReadUInt16()); angle = reader.ReadRotation();
currentFaceIndex = reader.ReadInt16(); currentFaceIndex = reader.ReadInt16();
gridLineSpacing = reader.ReadSingle(); gridLineSpacing = reader.ReadSingle();
gridPhaseShift = reader.ReadVec3(); gridPhaseShift = reader.ReadVec3();
gridOrientation = new Vector3(reader.ReadUInt16(), reader.ReadUInt16(), reader.ReadUInt16()); gridOrientation = reader.ReadRotation();
gridEnabled = reader.ReadBoolean(); gridEnabled = reader.ReadBoolean();
numFaces = reader.ReadByte(); numFaces = reader.ReadByte();
edgeSelected = reader.ReadSByte(); edgeSelected = reader.ReadSByte();

View File

@ -6,6 +6,12 @@ namespace KeepersCompound.LGS;
public static class Extensions public static class Extensions
{ {
public static Vector3 ReadRotation(this BinaryReader reader)
{
var raw = new Vector3(reader.ReadUInt16(), reader.ReadUInt16(), reader.ReadUInt16());
return raw * 360 / (ushort.MaxValue + 1);
}
public static Vector3 ReadVec3(this BinaryReader reader) public static Vector3 ReadVec3(this BinaryReader reader)
{ {
return new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); return new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

View File

@ -264,8 +264,7 @@ public partial class Mission : Node3D
// Let's try and place an object :) // Let's try and place an object :)
var modelName = modelNameProp.value + ".bin"; var modelName = modelNameProp.value + ".bin";
var pos = brush.position.ToGodotVec3(); var pos = brush.position.ToGodotVec3();
var rawRot = brush.angle; var rot = brush.angle.ToGodotVec3(false);
var rot = new Vector3(rawRot.Y, rawRot.Z, rawRot.X) * 360 / (ushort.MaxValue + 1);
var scale = scaleProp == null ? Vector3.One : scaleProp.value.ToGodotVec3(false); var scale = scaleProp == null ? Vector3.One : scaleProp.value.ToGodotVec3(false);
var model = Timing.TimeStage("Get Models", () => var model = Timing.TimeStage("Get Models", () =>
{ {