xp12camera

Owner: IIIlllIIIllI URL: git@github.com:nyangkosense/xp12camera.git

rm black/white filter, add white lines, fix lua script

Commit 3961c247e74518b50f444f4ca3a1903ae5d25dda by SM <seb.michalk@gmail.com> on 2025-06-26 09:50:49 +0200
diff --git a/FLIR_Camera.cpp b/FLIR_Camera.cpp
index ab4a8e1..72d4867 100644
--- a/FLIR_Camera.cpp
+++ b/FLIR_Camera.cpp
@@ -407,11 +407,8 @@ static void FocusLockCallback(void* inRefcon)
          gLastMouseX = mouseX;
          gLastMouseY = mouseY;
      } else {
-         // Use enhanced tracking algorithm like X-Plane's built-in system
-         CalculateEnhancedTrackingCamera(&gCameraPan, &gCameraTilt,
-                                       planeX, planeY, planeZ,
-                                       planeHeading,
-                                       outCameraPosition->x, outCameraPosition->y, outCameraPosition->z);
+         // Use locked camera angles (camera movement frozen)
+         GetLockedAngles(&gCameraPan, &gCameraTilt);
      }
      
      // Camera orientation (pan/tilt relative to aircraft heading)
diff --git a/FLIR_Camera.o b/FLIR_Camera.o
index 1d8af99..454cd12 100644
Binary files a/FLIR_Camera.o and b/FLIR_Camera.o differ
diff --git a/FLIR_HUD.lua b/FLIR_HUD.lua
index 2efa88c..998f182 100644
--- a/FLIR_HUD.lua
+++ b/FLIR_HUD.lua
@@ -1,81 +1,91 @@
 -- FLIR Camera HUD Display Script for FlyWithLua
--- Place this file in X-Plane/Resources/plugins/FlyWithLua/Scripts/
--- Only shows HUD when FLIR camera is actually active
+-- Auto-toggles based on camera view with realistic military HUD
 
 -- Global variables
 flir_start_time = flir_start_time or os.time()
-
--- Dataref variables (declared once to prevent stack overflow)
-local view_type_ref = dataref_table("sim/graphics/view/view_type")
-local manipulator_ref = dataref_table("sim/operation/prefs/misc/manipulator_disabled")
-local zulu_time_ref = dataref_table("sim/time/zulu_time_sec")
-local latitude_ref = dataref_table("sim/flightmodel/position/latitude") 
-local longitude_ref = dataref_table("sim/flightmodel/position/longitude")
-local altitude_ref = dataref_table("sim/flightmodel/position/elevation")
-local ground_speed_ref = dataref_table("sim/flightmodel/position/groundspeed")
-local heading_ref = dataref_table("sim/flightmodel/position/psi")
+flir_hud_enabled = flir_hud_enabled or true
+flir_last_view_type = 0
 
 function draw_flir_hud()
-    -- Only draw HUD when in external view (camera view)
-    if view_type_ref[0] == 1026 then  -- External view
-        -- Get basic aircraft data safely using pre-declared datarefs
-        local zulu_time = zulu_time_ref[0]
-        local latitude = latitude_ref[0]
-        local longitude = longitude_ref[0]
-        local altitude_msl = altitude_ref[0]
-        local ground_speed = ground_speed_ref[0]
-        local heading = heading_ref[0]
-        
-        -- 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 and bigger size
-        graphics.set_color(0.0, 1.0, 0.0, 1.0)
-        
-        -- Use bigger font size for better visibility
-        local font_size = 1.5  -- Scale factor for larger text
-        
-        -- Top status line (bigger 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")
-        
-        -- Navigation data (bigger)
-        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")
-        
-        -- Mission timer (bigger)
-        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")
-        
-        -- Target status (bigger)
-        graphics.draw_string(SCREEN_WIDTH - 300, SCREEN_HEIGHT - 70, "TGT: SCANNING...", "large")
-        
-        -- Camera status (bigger, bottom)
-        graphics.draw_string(30, 90, "ZOOM: ACTIVE  THERMAL: WHT", "large")
-        
-        -- Aircraft identification (bigger)
-        graphics.draw_string(30, SCREEN_HEIGHT - 100, "MARITIME PATROL AIRCRAFT", "large")
-        
+    -- Auto-toggle based on camera view
+    local view_type = XPLMGetDatai(XPLMFindDataRef("sim/graphics/view/view_type"))
+    
+    -- Auto-enable when entering camera view, disable when leaving
+    if view_type == 1026 and flir_last_view_type ~= 1026 then
+        flir_hud_enabled = true
+        logMsg("FLIR HUD: Auto-enabled (Camera view active)")
+    elseif view_type ~= 1026 and flir_last_view_type == 1026 then
+        flir_hud_enabled = false
+        logMsg("FLIR HUD: Auto-disabled (Camera view inactive)")
+    end
+    flir_last_view_type = view_type
+    
+    -- Only draw if HUD is enabled and in camera view
+    if not flir_hud_enabled or view_type ~= 1026 then
+        return
+    end
+    
+    -- Get aircraft data
+    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 values
+    local hours = math.floor(zulu_time / 3600) % 24
+    local minutes = math.floor((zulu_time % 3600) / 60)
+    local time_string = string.format("%02d:%02d Z", hours, minutes)
+    local alt_feet = math.floor(altitude_msl * 3.28084)
+    local speed_knots = math.floor(ground_speed * 1.94384)
+    
+    -- Set FLIR green color
+    graphics.set_color(0.0, 1.0, 0.0, 1.0)
+    
+    -- Top status bar - realistic military format
+    local status_line = string.format("▶ FLIR-25HD  %s  %.4f°N %.4f°W  MSL:%dft", 
+                                     time_string, latitude, longitude, alt_feet)
+    graphics.draw_string(20, SCREEN_HEIGHT - 25, status_line, "large")
+    
+    -- Navigation data
+    local nav_line = string.format("▲ HDG:%03d°  SPD:%03d kts  TRK:%03d°  VSI:+0000 fpm", 
+                                  math.floor(heading), speed_knots, math.floor(heading))
+    graphics.draw_string(20, SCREEN_HEIGHT - 50, nav_line, "large")
+    
+    -- Mission timer (top right)
+    local mission_time = os.time() - flir_start_time
+    local mission_hours = math.floor(mission_time / 3600)
+    local mission_mins = math.floor((mission_time % 3600) / 60)
+    local mission_secs = mission_time % 60
+    local mission_line = string.format("REC: %02d:%02d:%02d", mission_hours, mission_mins, mission_secs)
+    graphics.draw_string(SCREEN_WIDTH - 180, SCREEN_HEIGHT - 25, mission_line, "large")
+    
+    -- Target info (top right)
+    graphics.draw_string(SCREEN_WIDTH - 180, SCREEN_HEIGHT - 50, "TGT: SCANNING", "large")
+    
+    -- System status (bottom left)
+    graphics.draw_string(20, 80, "◆ SYS: NOMINAL  STAB: ON  IR: WHT", "large")
+    graphics.draw_string(20, 105, "● ZOOM: 1.0x  FOV: WIDE  FOCUS: AUTO", "large")
+    
+    -- Aircraft ID (bottom)
+    graphics.draw_string(20, SCREEN_HEIGHT - 75, "✈ MARITIME PATROL A319", "large")
+end
+
+-- Toggle function for manual override
+function toggle_flir_hud()
+    flir_hud_enabled = not flir_hud_enabled
+    if flir_hud_enabled then
+        logMsg("FLIR HUD: Manually enabled")
+    else
+        logMsg("FLIR HUD: Manually disabled")
     end
 end
 
--- Register the drawing function (safe method)
+-- Register drawing function
 do_every_draw("draw_flir_hud()")
 
--- Add macro to reset mission timer
-add_macro("FLIR: Reset Mission Timer", "flir_start_time = os.time()", "", "activate")
+-- Add macro for manual toggle (backup)
+add_macro("FLIR: Toggle HUD", "toggle_flir_hud()", "", "activate")
 
-logMsg("FLIR HUD Display Script Loaded (Safe Version)")
\ No newline at end of file
+logMsg("FLIR HUD Script Loaded - Auto-toggles with camera view, manual toggle available")
diff --git a/FLIR_SimpleLock.cpp b/FLIR_SimpleLock.cpp
index b441117..9eb0568 100644
--- a/FLIR_SimpleLock.cpp
+++ b/FLIR_SimpleLock.cpp
@@ -19,97 +19,37 @@
 #include "XPLMUtilities.h"
 #include "FLIR_SimpleLock.h"
 
-// Enhanced lock-on state
+// Simple lock-on state
 static int gLockActive = 0;
-static float gLockedPan = 0.0f;     // Pan angle relative to aircraft when locked
-static float gLockedTilt = 0.0f;    // Tilt angle when locked
-static float gTargetX = 0.0f;       // World coordinates of locked target
-static float gTargetY = 0.0f;
-static float gTargetZ = 0.0f;
-static int gUseEnhancedTracking = 1; // Use X-Plane style tracking algorithm
+static float gLockedPan = 0.0f;     // Pan angle when locked (for display only)
+static float gLockedTilt = 0.0f;    // Tilt angle when locked (for display only)
 
 void InitializeSimpleLock()
 {
     gLockActive = 0;
-    gUseEnhancedTracking = 1;
-    XPLMDebugString("FLIR Enhanced Lock: Initialized with X-Plane tracking algorithms\n");
+    XPLMDebugString("FLIR Simple Lock: Initialized\n");
 }
 
 void LockCurrentDirection(float currentPan, float currentTilt)
 {
-    // Store the current camera angles for enhanced tracking
+    // Simple lock - just store angles for display and freeze camera movement
     gLockedPan = currentPan;
     gLockedTilt = currentTilt;
     gLockActive = 1;
     
-    // Calculate target position in world coordinates using X-Plane's algorithm
-    // This creates a stable target point that the camera will track
-    float headingRad = (currentPan) * M_PI / 180.0f;
-    float pitchRad = currentTilt * M_PI / 180.0f;
-    
-    // Project locked direction into world space at far distance
-    float targetDistance = 10000.0f; // Far target for stable tracking
-    gTargetX = targetDistance * sin(headingRad) * cos(pitchRad);
-    gTargetY = targetDistance * sin(pitchRad);
-    gTargetZ = targetDistance * cos(headingRad) * cos(pitchRad);
-    
     char msg[256];
-    sprintf(msg, "FLIR Enhanced Lock: Locked at Pan=%.1f°, Tilt=%.1f° (Target: %.1f,%.1f,%.1f)\n", 
-            gLockedPan, gLockedTilt, gTargetX, gTargetY, gTargetZ);
+    sprintf(msg, "FLIR Camera Lock: Engaged at Pan=%.1f°, Tilt=%.1f°\n", 
+            gLockedPan, gLockedTilt);
     XPLMDebugString(msg);
 }
 
-void CalculateEnhancedTrackingCamera(float* outPan, float* outTilt, 
-                                   float aircraftX, float aircraftY, float aircraftZ,
-                                   float aircraftHeading, float cameraX, float cameraY, float cameraZ)
-{
-    if (!gLockActive) {
-        return;
-    }
-    
-    if (!gUseEnhancedTracking) {
-        // Fallback to simple angle lock
-        *outPan = gLockedPan;
-        *outTilt = gLockedTilt;
-        return;
-    }
-    
-    // Enhanced tracking using X-Plane's algorithm
-    // Transform target from aircraft-relative to world coordinates
-    float headingRad = (aircraftHeading + gLockedPan) * M_PI / 180.0f;
-    float pitchRad = gLockedTilt * M_PI / 180.0f;
-    
-    // Calculate world target position relative to current aircraft position
-    float targetDistance = 10000.0f;
-    float worldTargetX = aircraftX + targetDistance * sin(headingRad) * cos(pitchRad);
-    float worldTargetY = aircraftY + targetDistance * sin(pitchRad);
-    float worldTargetZ = aircraftZ + targetDistance * cos(headingRad) * cos(pitchRad);
-    
-    // Calculate camera orientation to track target (X-Plane's method)
-    float deltaX = worldTargetX - cameraX;
-    float deltaY = worldTargetY - cameraY;
-    float deltaZ = worldTargetZ - cameraZ;
-    
-    // Convert to pan/tilt angles
-    float targetHeading = atan2(deltaX, deltaZ) * 180.0f / M_PI;
-    float targetPitch = atan2(deltaY, sqrt(deltaX*deltaX + deltaZ*deltaZ)) * 180.0f / M_PI;
-    
-    // Calculate relative to aircraft heading
-    *outPan = targetHeading - aircraftHeading;
-    *outTilt = targetPitch;
-    
-    // Normalize pan angle
-    while (*outPan > 180.0f) *outPan -= 360.0f;
-    while (*outPan < -180.0f) *outPan += 360.0f;
-}
-
 void GetLockedAngles(float* outPan, float* outTilt)
 {
     if (!gLockActive) {
         return;
     }
     
-    // Legacy support - return stored angles
+    // Return stored angles - camera movement is frozen
     *outPan = gLockedPan;
     *outTilt = gLockedTilt;
 }
@@ -117,7 +57,7 @@ void GetLockedAngles(float* outPan, float* outTilt)
 void DisableSimpleLock()
 {
     gLockActive = 0;
-    XPLMDebugString("FLIR Enhanced Lock: Disabled\n");
+    XPLMDebugString("FLIR Camera Lock: Disabled\n");
 }
 
 int IsSimpleLockActive()
@@ -128,12 +68,11 @@ int IsSimpleLockActive()
 void GetSimpleLockStatus(char* statusBuffer, int bufferSize)
 {
     if (!gLockActive) {
-        strncpy(statusBuffer, "TRACK: OFF", bufferSize - 1);
+        strncpy(statusBuffer, "LOCK: OFF", bufferSize - 1);
         statusBuffer[bufferSize - 1] = '\0';
         return;
     }
     
-    const char* mode = gUseEnhancedTracking ? "ENH" : "SIM";
-    snprintf(statusBuffer, bufferSize, "TRACK: %s %.1f°/%.1f°", mode, gLockedPan, gLockedTilt);
+    snprintf(statusBuffer, bufferSize, "LOCK: ON %.1f°/%.1f°", gLockedPan, gLockedTilt);
     statusBuffer[bufferSize - 1] = '\0';
 }
\ No newline at end of file
diff --git a/FLIR_SimpleLock.h b/FLIR_SimpleLock.h
index 9e748da..0d0e67b 100644
--- a/FLIR_SimpleLock.h
+++ b/FLIR_SimpleLock.h
@@ -18,10 +18,6 @@ void InitializeSimpleLock();
 // Lock to current camera direction (enhanced algorithm)
 void LockCurrentDirection(float currentPan, float currentTilt);
 
-// Calculate enhanced tracking camera position
-void CalculateEnhancedTrackingCamera(float* outPan, float* outTilt, 
-                                   float aircraftX, float aircraftY, float aircraftZ,
-                                   float aircraftHeading, float cameraX, float cameraY, float cameraZ);
 
 // Get locked camera angles (legacy support)
 void GetLockedAngles(float* outPan, float* outTilt);
diff --git a/FLIR_SimpleLock.o b/FLIR_SimpleLock.o
index 6699040..acc523a 100644
Binary files a/FLIR_SimpleLock.o and b/FLIR_SimpleLock.o differ
diff --git a/FLIR_VisualEffects.cpp b/FLIR_VisualEffects.cpp
index c9243ed..4e6ec1b 100644
--- a/FLIR_VisualEffects.cpp
+++ b/FLIR_VisualEffects.cpp
@@ -106,10 +106,7 @@ void RenderVisualEffects(int screenWidth, int screenHeight)
         RenderThermalEffects(screenWidth, screenHeight);
     }
     
-    // Apply IR black/white filter
-    if (gIREnabled) {
-        RenderIRFilter(screenWidth, screenHeight);
-    }
+    // IR black/white filter removed - was not realistic
     
     // Add camera noise/grain
     if (gNoiseEnabled) {
@@ -161,6 +158,19 @@ void RenderMonochromeFilter(int screenWidth, int screenHeight)
     glVertex2f(screenWidth, screenHeight);
     glVertex2f(0, screenHeight);
     glEnd();
+    
+    // Add white temperature scale lines (like thermal mode)
+    glColor4f(1.0f, 1.0f, 1.0f, 0.8f);
+    glLineWidth(1.0f);
+    
+    glBegin(GL_LINES);
+    // Temperature scale on left
+    for (int i = 0; i < 10; i++) {
+        float y = 50 + i * (screenHeight - 100) / 10.0f;
+        glVertex2f(10, y);
+        glVertex2f(25, y);
+    }
+    glEnd();
 }
 
 void RenderThermalEffects(int screenWidth, int screenHeight)
@@ -301,7 +311,7 @@ void RenderIRFilter(int screenWidth, int screenHeight)
 void CycleVisualModes()
 {
     static int mode = 0;
-    mode = (mode + 1) % 5;
+    mode = (mode + 1) % 4; // Only 4 modes now
     
     switch (mode) {
         case 0: // Standard
@@ -331,23 +341,16 @@ void CycleVisualModes()
             XPLMDebugString("FLIR Visual Effects: Thermal Mode\n");
             break;
             
-        case 3: // IR Black/White
-            SetMonochromeFilter(0);
-            SetThermalMode(0);
-            SetIRMode(1);
-            gNoiseEnabled = 1;
-            gScanLinesEnabled = 1;
-            XPLMDebugString("FLIR Visual Effects: IR Mode\n");
-            break;
-            
-        case 4: // Enhanced
+        case 3: // Enhanced Monochrome
             SetMonochromeFilter(1);
-            SetThermalMode(1);
+            SetThermalMode(0);
             SetIRMode(0);
             gNoiseEnabled = 1;
             gScanLinesEnabled = 1;
-            XPLMDebugString("FLIR Visual Effects: Enhanced Mode\n");
+            XPLMDebugString("FLIR Visual Effects: Enhanced Monochrome\n");
             break;
+            
+        // case 4 removed - now case 3 is the last mode
     }
 }
 
@@ -357,7 +360,6 @@ void GetVisualEffectsStatus(char* statusBuffer, int bufferSize)
     if (gMonochromeEnabled && gThermalEnabled) mode = "ENHANCED";
     else if (gThermalEnabled) mode = "THERMAL";
     else if (gMonochromeEnabled) mode = "MONO";
-    else if (gIREnabled) mode = "IR B/W";
     
     snprintf(statusBuffer, bufferSize, "VFX: %s", mode);
     statusBuffer[bufferSize - 1] = '\0';
diff --git a/FLIR_VisualEffects.o b/FLIR_VisualEffects.o
index ec43597..9b5a39b 100644
Binary files a/FLIR_VisualEffects.o and b/FLIR_VisualEffects.o differ
diff --git a/build/FLIR_Camera/win_x64/FLIR_Camera.xpl b/build/FLIR_Camera/win_x64/FLIR_Camera.xpl
index c6c1850..1d6799b 100755
Binary files a/build/FLIR_Camera/win_x64/FLIR_Camera.xpl and b/build/FLIR_Camera/win_x64/FLIR_Camera.xpl differ