Jump to content

Programming a CCIP indicator in Lua (scripts now available)


Recommended Posts

Hi,

I am experimenting with different systems in DCS and I'm currently trying to get a constantly computed impact point (CCIP) indicator/reticle or "pipper" working for air to ground weapons.

I think I got the basic prediction calculations right, like flight time and x,y,z coordinates of the launch and landing points, and factoring in gravity and altitude above ground.

The problem I have is turning it into a HUD element. The left/right movement (azimuth) seems to be OK, but the up/down movement (elevation) isn't working right. The main problem I have is this: when maintaining a downward pitch angle, the dot should move up on the HUD but never be above the nose. Maybe there's some equation or factor I'm missing or I'm doing something wrong, but I don't know.

Examples of something similar in other games seem to place the indicator in the actual 3D environment, which is not possible in DCS to my knowledge. Also, the two community mods that have CCIP functionality (A-29 Super Tucano and T-45 Goshawk) seem to do the calculations in a .dll file for which the source code has not been shared. 

Any ideas or suggestions are welcome, and code snippets will be greatly appreciated!


Edited by Sérvalpilot
Kind-of complete
Link to comment
Share on other sites

I managed to get a little further, now I'm trying to incorporate drag.

Here's a breakdown of some of the code I have so far.

rpx, rpy, rpz = self.getSelfCoordinates() -- Release point coordinates, lat, alt, lon
vx, vy, vz = self.getSelfVelocity() -- Release point component velocities, lat, alt, lon
g = -9.81 -- Gravity

t = (-vy - math.sqrt(vy * vy - 2 * g * (math.abs(h))))/g -- Flight time to impact

ipx = rpx + (vx * t) -- Impact point x coordinate 
ipy = self.getBarometricAltitude() - self.getRadarAltitude() -- Ground level
ipz = rpz + (vz * t) -- Impact point z coordinate 

dx = -ipx + rpx -- Distance along x axis
dy = -ipy + rpy    -- This should be radar altitude
dz = -ipz + rpz -- Distance along z axis

dist = math.sqrt(dx * dx + dy * dy + dz * dz) -- Total distance scalar
horiz_dist = math.sqrt(dx * dx + dz * dz) -- Horizontal distance scalar

hdg = pi - self.getHeading()
ip_azimuth = (math.atan2(dz, dx) - hdg) % (2 * pi)
if ip_azimuth > pi then ip_azimuth = ip_azimuth - 2 * pi end

ip_elevation = -math.atan2(dy, horiz_dist)

-- Some stuff to correct for roll and pitch
cos_roll = math.cos(roll)
sin_roll = math.sin(roll)

azimuth_correction = ip_azimuth * cos_roll - ip_elevation * sin_roll
elevation_correction = ip_elevation * cos_roll + azimuth_correction * sin_roll

-- Final corrections, sent as parameters for HUD
ccip_x = azimuth_correction + pitch * sin_roll
ccip_y = elevation_correction - pitch * cos_roll

I tested this by making a custom gun that shot bullets with almost no mass or drag and it was very accurate.


Now the challenge is adding drag. Any ideas?

Link to comment
Share on other sites

16 hours ago, Luiz Renault said:

This doesn't really work. The reticle's movement seems delayed compared to my method, and its also inaccurate like mine. 

I saw the latest A-29's weapon_system file has lines like this:

local valid, az, el, travel_dist = Calculate()

The calculations themselves seem to be done in avSimplest.dll, not in the Lua environment.

I thought you meant there was some built-in function in avSimpleWeaponSystem, similar to "WS_IR_MISSILE_LOCK" or "WS_GUN_PIPER_AZIMUTH" but specifically for CCIP. 

On the topic of drag, I tried several equations which didn't work, so I'll try using the Runge-Kutta method next.

Link to comment
Share on other sites

Quote

Examples of something similar in other games seem to place the indicator in the actual 3D environment

You want to place elements on hud right? what you mean in "actual 3D environment"?

If you already have a 3d impact coordinate, and it is accurate,. You can just directly use view and projection transformation matrices to convert any 3D coord to your relative 2D coord in the Hud view plane.If you have vectors, then you can use rotation matrix transform vectors.

Hud is no different than another other view plane/screen. View transform is the most basic and direct approach in 3D world to local grid coordinate conversion.

 

I dig little bit about T-45 dll file, the CCIP_v is a lua-c callCCIP_v C++ function is just a partial rotation transform/projection the length of line between aircraft vector and bomb impact point on the Hud verical axis ( y ).

View and rotate transform involve lots of products and trigonometrics, which is kinda compute expensive via Lua, and Lua you cant directly get vel vector(need a extra rotation transform use sensor_data pitch/roll/yaw).  That's why they do it in C++. In lua It's expensive, but doable. 

there is a sample code i found long time draw a "locking box/file" on he HUD using the view transform . it converts object/aircrafts 3D coord to 2D hud coordinates, it's not the CCIP but you get the idea. 

But i cant find it in my browsing histories..


Edited by Insonia
  • Like 1
Link to comment
Share on other sites

  • 1 month later...

UPDATE:

I finally managed to get something!
It's not perfect, and I still don't how the drag coefficient table works, but it's definitely usable.

The script I made essentially "simulates" the projectile's motion with all the physics calculations along a series of time steps.
It's fairly CPU intensive and there might be a better way to do it, but this works well for now.

I'll clean it up, add annotations, then probably share it at some point soon!


Edited by Sérvalpilot
Link to comment
Share on other sites

  • Sérvalpilot changed the title to Programming a CCIP indicator in Lua
  • 1 month later...
On 1/12/2024 at 9:47 PM, Sérvalpilot said:

UPDATE:

I finally managed to get something!
It's not perfect, and I still don't how the drag coefficient table works, but it's definitely usable.

The script I made essentially "simulates" the projectile's motion with all the physics calculations along a series of time steps.
It's fairly CPU intensive and there might be a better way to do it, but this works well for now.

I'll clean it up, add annotations, then probably share it at some point soon!

 

Could you tell me what variable "h" was in this? 

t = (-vy - math.sqrt(vy * vy - 2 * g * (math.abs(h))))/g -- Flight time to impact
Link to comment
Share on other sites

@Sérvalpilot I could actually use something like this for a mod I'm working on.  Is it to the point where you'd like to share it yet?

Website (DCS Content): https://sites.google.com/view/spinossimulationsite/home?authuser=0

YouTube: https://www.youtube.com/@SpinosSimulations

System Specs: Ryzen 7 5800X, RTX 3060, 32GB DDR4-3200 RAM

DCS Wishlist: F-8E/J Crusader, Kola Peninsula Map, F-14B(U), F-14D/ST-21 Super Tomcat

Link to comment
Share on other sites

  • 2 weeks later...
Posted (edited)
On 3/10/2024 at 4:06 AM, bigcomputerman said:

Could you tell me what variable "h" was in this? 

t = (-vy - math.sqrt(vy * vy - 2 * g * (math.abs(h))))/g -- Flight time to impact

h is altitude above the surface, so radar altitude.

 

On 3/17/2024 at 3:11 PM, Spino said:

@Sérvalpilot I could actually use something like this for a mod I'm working on.  Is it to the point where you'd like to share it yet?

Soon™.

It's pretty much done, I'm just doing some testing and documentation.


Edited by Sérvalpilot
Link to comment
Share on other sites

  • 3 weeks later...

At last, here is a script!

CCIP_simple.lua

This is the simple CCIP method with no drag or wind is taken into account.

It works fairly well with light low-drag bombs like the Mk-82 and FAB-100 and with little to no wind.

Like with manual bombing, it's more accurate with steeper dive angles but it works pretty well at 10 degrees.

 

About the advanced method that does incorporate drag, it's taking a while to release because there's still some stuff to figure out.

The main thing is that it's computationally very heavy so I'm looking at ways to optimize it so it doesn't stress the CPU.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...

Here is the advanced script!

CCIP_advanced.lua

 

This method "simulates" the motion of a bomb along a series of time steps until it hits the ground, calculating the acceleration then velocity and position at each time step. It also incorporates drag into the physics calculations.

This method is, as you might expect, more computationally expensive than the simple method. If you encounter performance issues, please let me know.

In theory this can also be expanded to work with guns, rockets, and high-drag bombs. I experimented with those types of weapons with little success.

Feedback is always welcome!


Edited by Sérvalpilot
Slight mistake fixed
Link to comment
Share on other sites

  • Sérvalpilot changed the title to Programming a CCIP indicator in Lua (scripts now available)
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...