xp12camera
Owner: IIIlllIIIllI URL: git@github.com:nyangkosense/xp12camera.git
fix lua
Commit 5fc1150bada5f5fb15a45df8aa2fc39bd6cf5dc1 by SM <seb.michalk@gmail.com> on 2025-06-25 19:50:23 +0200
diff --git a/FLIR_Camera.cpp b/FLIR_Camera.cpp
index fb2266d..9fb294d 100644
--- a/FLIR_Camera.cpp
+++ b/FLIR_Camera.cpp
@@ -486,7 +486,7 @@ static void DrawRealisticThermalOverlay(void)
if (IsLockOnActive()) {
glColor4f(1.0f, 0.0f, 0.0f, 0.9f); // Red when locked
} else {
- glColor4f(0.0f, 1.0f, 0.0f, 0.9f); // Green when scanning
+ glColor4f(0.0f, 1.0f, 0.0f, 0.9f); // Bright green when scanning
}
glLineWidth(2.0f);
diff --git a/FLIR_HUD_Simple.lua b/FLIR_HUD_Simple.lua
new file mode 100644
index 0000000..e7ce5f6
--- /dev/null
+++ b/FLIR_HUD_Simple.lua
@@ -0,0 +1,58 @@
+-- FLIR Camera HUD Display Script for FlyWithLua
+-- Simplified version to prevent engine crashes
+
+-- Global variables
+flir_start_time = flir_start_time or os.time()
+
+function draw_flir_hud()
+ -- Simple check for external view
+ local view_type = XPLMGetDatai(XPLMFindDataRef("sim/graphics/view/view_type"))
+
+ if view_type == 1026 then -- External view
+ -- Get basic data using direct dataref calls
+ local zulu_time = XPLMGetDataf(XPLMFindDataRef("sim/time/zulu_time_sec"))
+ local latitude = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/position/latitude"))
+ local longitude = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/position/longitude"))
+ local altitude_msl = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/position/elevation"))
+ local ground_speed = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/position/groundspeed"))
+ local heading = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/position/psi"))
+
+ -- Convert zulu time to HH:MM format
+ local hours = math.floor(zulu_time / 3600) % 24
+ local minutes = math.floor((zulu_time % 3600) / 60)
+ local time_string = string.format("%02d:%02d UTC", hours, minutes)
+
+ -- Convert altitude to feet
+ local alt_feet = math.floor(altitude_msl * 3.28084)
+
+ -- Convert ground speed to knots
+ local speed_knots = math.floor(ground_speed * 1.94384)
+
+ -- Set text color to FLIR green
+ graphics.set_color(0.0, 1.0, 0.0, 1.0)
+
+ -- Draw HUD text
+ local status_line = string.format("FLIR CAMERA %s LAT:%.4f LON:%.4f ALT:%dft",
+ time_string, latitude, longitude, alt_feet)
+ graphics.draw_string(30, SCREEN_HEIGHT - 40, status_line, "large")
+
+ local nav_line = string.format("HDG:%03d SPD:%d kts GS:%.1f m/s",
+ math.floor(heading), speed_knots, ground_speed)
+ graphics.draw_string(30, SCREEN_HEIGHT - 70, nav_line, "large")
+
+ local mission_time = os.time() - flir_start_time
+ local mission_mins = math.floor(mission_time / 60)
+ local mission_secs = mission_time % 60
+ local mission_line = string.format("MISSION TIME: %02d:%02d", mission_mins, mission_secs)
+ graphics.draw_string(SCREEN_WIDTH - 300, SCREEN_HEIGHT - 40, mission_line, "large")
+
+ graphics.draw_string(SCREEN_WIDTH - 300, SCREEN_HEIGHT - 70, "TGT: SCANNING...", "large")
+ graphics.draw_string(30, 90, "ZOOM: ACTIVE THERMAL: WHT", "large")
+ graphics.draw_string(30, SCREEN_HEIGHT - 100, "MARITIME PATROL AIRCRAFT", "large")
+ end
+end
+
+-- Register drawing function
+do_every_draw("draw_flir_hud()")
+
+logMsg("FLIR HUD Simple Script Loaded")
\ No newline at end of file
diff --git a/FLIR_LockOn.cpp b/FLIR_LockOn.cpp
index fb6e301..9560f1e 100644
--- a/FLIR_LockOn.cpp
+++ b/FLIR_LockOn.cpp
@@ -59,15 +59,17 @@ void SetArbitraryLockPoint(float currentPan, float currentTilt, float distance)
float planeZ = XPLMGetDataf(gPlaneZ);
float planeHeading = XPLMGetDataf(gPlaneHeading);
- // Convert camera angles to radians
- float panRad = (planeHeading + currentPan) * M_PI / 180.0f;
+ // Convert camera angles to radians - fix coordinate system
+ float absoluteHeading = planeHeading + currentPan;
+ float headingRad = absoluteHeading * M_PI / 180.0f;
float tiltRad = currentTilt * M_PI / 180.0f;
- // Calculate world coordinates of the lock point
- // Project forward from camera position based on current pan/tilt
- gLockedWorldX = planeX + distance * sin(panRad) * cos(tiltRad);
- gLockedWorldY = planeY + distance * sin(tiltRad);
- gLockedWorldZ = planeZ + distance * cos(panRad) * cos(tiltRad);
+ // Calculate world coordinates of the lock point using X-Plane coordinate system
+ // X-Plane: X=East, Y=Up, Z=North (opposite of typical)
+ float horizontalDistance = distance * cos(tiltRad);
+ gLockedWorldX = planeX + horizontalDistance * sin(headingRad); // East
+ gLockedWorldY = planeY + distance * sin(tiltRad); // Up
+ gLockedWorldZ = planeZ + horizontalDistance * cos(headingRad); // North
// Store the camera angles at lock time
gLockOnPan = currentPan;
@@ -110,6 +112,7 @@ void UpdateCameraToLockPoint(float* outPan, float* outTilt)
}
// Calculate absolute heading to target (in world coordinates)
+ // X-Plane coordinate system: atan2(East, North)
float targetHeading = atan2(dx, dz) * 180.0f / M_PI;
// Calculate tilt angle to target
diff --git a/FLIR_LockOn.o b/FLIR_LockOn.o
index 4e16b9a..a09039d 100644
Binary files a/FLIR_LockOn.o and b/FLIR_LockOn.o differ
diff --git a/build/FLIR_Camera/win_x64/FLIR_Camera.xpl b/build/FLIR_Camera/win_x64/FLIR_Camera.xpl
index 654763d..6532ea4 100755
Binary files a/build/FLIR_Camera/win_x64/FLIR_Camera.xpl and b/build/FLIR_Camera/win_x64/FLIR_Camera.xpl differ