Skip to content

Commit

Permalink
Restructured the project + new features and fixes:
Browse files Browse the repository at this point in the history
 - Updated docfx (although it might be a bit broken still...)
 - Updated CLI example program
 - Moved docs into it's own folder
 - Split MemArray classes into their own files
 - Implemented MemArrayList for strings and structs
 - Implemented OmsiMovingMapObjInst
 - Added OmsiSetTrigger and OmsiTriggerSound remote methods
 - Added OnActiveVehicleChanged event
 - Other small changes
  • Loading branch information
space928 committed Dec 29, 2023
1 parent eb357e7 commit 72d094f
Show file tree
Hide file tree
Showing 145 changed files with 1,713 additions and 825 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Generate docs
uses: nikeee/docfx-action@v1.0.0
uses: nunit/docfx-action@v2.4.0
with:
args: OmsiHook/docfx.json
args: OmsiHook/docs/docfx.json

# Archive the generated site as an artifact
- name: Archive artifact
Expand Down
1 change: 1 addition & 0 deletions OmsiExtensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Global
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Release|Any CPU.Build.0 = Release|x86
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Release|x64.ActiveCfg = Release|x86
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Release|x86.ActiveCfg = Release|x86
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Release|x86.Build.0 = Release|x86
{28DA0165-EAA7-4171-A065-319409682BD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28DA0165-EAA7-4171-A065-319409682BD1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28DA0165-EAA7-4171-A065-319409682BD1}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down
125 changes: 65 additions & 60 deletions OmsiExtensionsCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ static void Main(string[] args)

Console.SetCursorPosition(0, 0);
Console.WriteLine(($"Read data: x:{pos.x:F3} y:{pos.y:F3} z:{pos.z:F3} " +
$"tile:{playerVehicle?.Kachel??0}").PadRight(Console.WindowWidth - 1));
Console.WriteLine($"Read data: vx:{vel.x:F3} vy:{vel.y:F3} vz:{vel.z:F3}".PadRight(Console.WindowWidth-1));
Console.WriteLine($"Read data: ax:{posa._30:F3} ay:{posa._31:F3} az:{posa._32:F3}".PadRight(Console.WindowWidth-1));
$"tile:{playerVehicle?.Kachel ?? 0}").PadRight(Console.WindowWidth - 1));
Console.WriteLine($"Read data: vx:{vel.x:F3} vy:{vel.y:F3} vz:{vel.z:F3}".PadRight(Console.WindowWidth - 1));
Console.WriteLine($"Read data: ax:{posa._30:F3} ay:{posa._31:F3} az:{posa._32:F3}".PadRight(Console.WindowWidth - 1));

Console.WriteLine($"Read data: map:{map?.Name} path:{map?.Filename} friendly:{map?.FriendlyName}".PadRight(Console.WindowWidth-1));
Console.WriteLine($"Read data: map:{map?.Name} path:{map?.Filename} friendly:{map?.FriendlyName}".PadRight(Console.WindowWidth - 1));
Console.WriteLine($"{omsi.Globals.Time.Day}/{omsi.Globals.Time.Month}/{omsi.Globals.Time.Year} - {omsi.Globals.Time.Hour}:{omsi.Globals.Time.Minute}:{omsi.Globals.Time.Second:F2}");
Console.WriteLine($"Camera data: x:{camPos.x:F3} y:{camPos.y:F3} z:{camPos.z:F3} ".PadRight(Console.WindowWidth - 1));
Console.WriteLine($"{omsi.Globals.Drivers}".PadRight(Console.WindowWidth - 1));
Expand All @@ -56,62 +56,7 @@ static void Main(string[] args)

Console.WriteLine($"[MOUSE] pos: {progMan.MausPos} ray_pos: {progMan.MausLine3DPos} ray_dir: {progMan.MausLine3DDir}".PadRight(Console.WindowWidth - 1));
Console.WriteLine($"[MOUSE] {progMan.MausCrossObjFlat} {progMan.MausCrossObjFlat_ObjHeight} {progMan.Maus_MeshEvent}".PadRight(Console.WindowWidth - 1));
if (meshes != null)
{
int i = 0;
foreach (var mesh in meshes)
{
if(mesh.MausEvent != null)
{
Console.WriteLine($" Mesh '{mesh.Filename_Int}' has event: {mesh.MausEvent}");
i++;
}
if(i > 20)
{
Console.WriteLine(" ...");
break;
}
}
}
OmsiAnimSubMesh clickMesh = null;
OmsiAnimSubMeshInst clickMeshInst = null;
string mouseEventName = "INEO_Click";
if(meshes != null)
clickMesh = meshes.FirstOrDefault(mesh => mesh.MausEvent == mouseEventName);
if (clickMesh != null)
clickMeshInst = meshInsts[meshes.IndexOf(clickMesh)];
if (clickMesh != null && progMan.Maus_MeshEvent == mouseEventName && (progMan.Maus_Clicked))
{
// Work out object space coords of the mouse click
// Note that (if wrapped) we could use D3DXIntersect to find the UV coords given the submesh's d3d mesh

// Transform the mouse ray from world space to object space
Matrix4x4 invMat;
//if (clickMesh.UseCharMatrix)
// invMat = clickMesh.CharMatrixInv;
//else
Matrix4x4.Invert((Matrix4x4)clickMeshInst.Matrix, out invMat);
Matrix4x4.Invert(clickMesh.OriginMatrix, out Matrix4x4 invOriginMat);
invMat = Matrix4x4.Multiply(invMat, invOriginMat);

var rayStart = Vector3.Transform(progMan.MausLine3DPos, invMat);
var rayDir = Vector3.Transform(progMan.MausLine3DDir, invMat);
// Now trace the ray, in our simplification we assume the surface of the mesh we want to hit is coplanar to the xz plane
// Taken from: https://stackoverflow.com/a/18543221
Vector3 planeNrm = new(0, 1, 0);
float planeD = 0;
float dot = Vector3.Dot(planeNrm, rayDir);
var intersect = new Vector3();
if(Math.Abs(dot) > 1e-9)
{
var w = rayStart - planeNrm * planeD;
var fac = -Vector3.Dot(planeNrm, w) / dot;
var u = rayDir * fac;
intersect = rayStart + u;
}

Console.WriteLine($" Clicked on {clickMesh.Filename_Int} at local coords: {(D3DVector)intersect}");
}
CheckClickPos(progMan, meshes, meshInsts);

/*Console.WriteLine("".PadRight(Console.WindowWidth-1));
try
Expand All @@ -130,6 +75,63 @@ static void Main(string[] args)
Thread.Sleep(20);
}
}

private static void CheckClickPos(OmsiProgMan progMan, MemArrayList<OmsiAnimSubMesh> meshes, MemArrayList<OmsiAnimSubMeshInst> meshInsts)
{
// A small experiment, with the aim of being able to determine where the user clicks on an object in local space.
if (meshes != null)
{
int i = 0;
foreach (var mesh in meshes)
{
if (mesh.MausEvent != null)
{
Console.WriteLine($" Mesh '{mesh.Filename_Int}' has event: {mesh.MausEvent}");
i++;
}
if (i > 20)
{
Console.WriteLine(" ...");
break;
}
}
}
OmsiAnimSubMesh clickMesh = null;
OmsiAnimSubMeshInst clickMeshInst = null;
string mouseEventName = "INEO_Click";
if (meshes != null)
clickMesh = meshes.FirstOrDefault(mesh => mesh.MausEvent == mouseEventName);
if (clickMesh != null)
clickMeshInst = meshInsts[meshes.IndexOf(clickMesh)];
if (clickMesh != null && progMan.Maus_MeshEvent == mouseEventName && (progMan.Maus_Clicked))
{
// Work out object space coords of the mouse click
// Note that (if wrapped) we could use D3DXIntersect to find the UV coords given the submesh's d3d mesh

// Transform the mouse ray from world space to object space
Matrix4x4.Invert((Matrix4x4)clickMeshInst.Matrix, out Matrix4x4 invMat);
Matrix4x4.Invert(clickMesh.OriginMatrix, out Matrix4x4 invOriginMat);
invMat = Matrix4x4.Multiply(invMat, invOriginMat);

var rayStart = Vector3.Transform(progMan.MausLine3DPos, invMat);
var rayDir = Vector3.Transform(progMan.MausLine3DDir, invMat);
// Now trace the ray, in our simplification we assume the surface of the mesh we want to hit is coplanar to the xz plane
// Taken from: https://stackoverflow.com/a/18543221
Vector3 planeNrm = new(0, 1, 0);
float planeD = 0;
float dot = Vector3.Dot(planeNrm, rayDir);
var intersect = new Vector3();
if (Math.Abs(dot) > 1e-9)
{
var w = rayStart - planeNrm * planeD;
var fac = -Vector3.Dot(planeNrm, w) / dot;
var u = rayDir * fac;
intersect = rayStart + u;
}

Console.WriteLine($" Clicked on {clickMesh.Filename_Int} at local coords: {(D3DVector)intersect}");
}
}
}

public class DXTests
Expand Down Expand Up @@ -182,6 +184,9 @@ public void CreateTexture()

public void UpdateTexture()
{
// Note that writing texture data like this is very slow, if possible, try to use SIMD accelerated
// operations (such as those in System.Numerics) or if you need to copy data into a texture buffer
// System.Buffer.BlockCopy() is extremely fast.
for (int y = 0; y < texHeight; y++)
for(int x = 0; x < texWidth; x++)
{
Expand Down
2 changes: 1 addition & 1 deletion OmsiHook/CustomAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public OmsiObjPtrAttribute(Type objType)
}

/// <summary>
/// Marks a field to be converted from an <c>int</c> to an <seealso cref="OmsiObject[]"/>.<para/>
/// Marks a field to be converted from an <c>int</c> to an <c>OmsiObject[]</c>.<para/>
/// Used by <seealso cref="Memory.MarshalStruct{OutStruct, InStruct}(InStruct)"/>
/// </summary>
[System.AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
Expand Down
Loading

0 comments on commit 72d094f

Please sign in to comment.