Hard Light Productions Forums

Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: Wanderer on March 17, 2008, 01:57:34 pm

Title: Oddities with get screencoords function...
Post by: Wanderer on March 17, 2008, 01:57:34 pm
So i tried something with a rather simple script

It took objects position vector and used it to produce screencoordinates after which it draw a bitmap on that spot.

Code: [Select]
#Conditional Hooks

$State: GS_STATE_GAME_PLAY

$On HUD Draw:

[

if mn.getMissionTime() ~= nil then
--here to prevent annoying errors caused by script getting triggered before mission starts

if boolean_radio_init == nil then
   integerWidth = gr.getScreenWidth()
   floatWMult = integerWidth / 1024
   integerHeight = gr.getScreenHeight()
   floatHMult = integerHeight / 768
   bitmapReticle = gr.loadTexture('reticle_dds')
   coordX = 0
   coordY = 0
end

integerWeapons = #mn.Weapons

gr.setColor(255, 100, 100)

for r = 1, integerWeapons do
   objectWeapon = mn.Weapons[r]
   stringWeaponClass = objectWeapon.Class.Name
   if stringWeaponClass == "Harpoon" then
      vectorWepPosition = objectWeapon.Position
      if vectorWepPosition:getScreenCoords() == nil or vectorWepPosition:getScreenCoords() == false then
         --do nothing
      else
         unscaled_coordX,unscaled_coordY = vectorWepPosition:getScreenCoords()
         coordX = (unscaled_coordX * floatWMult) - 128
         coordY = (unscaled_coordY * floatHMult) - 128
         gr.drawMonochromeImage(bitmapReticle, coordX, coordY)
      end
   end
end

end

]

#End

And here are attached screenshots... Using fs2_open_3_6_10_debug-Xt_0306.exe

I wasn't really surprised that the effects got misaligned but that it's centerpoint was not in the aiming reticle was.
Title: Re: Oddities with get screencoords function...
Post by: Wanderer on March 20, 2008, 04:48:03 am
Big kudos to Nuke...

Apparently all that was wrong was the scaling of the get screencoords function. And the effect shouldnt have been drawn over the set draw point but to start from there.

Above script modified to function as it should which should now align the effect perfectly regardless or aspect ratios or resos. The '128's are just the height and width of the image / 2.

[attachment deleted by ninja]
Title: Re: Oddities with get screencoords function...
Post by: WMCoolmon on March 21, 2008, 02:45:31 am
getScreenCoords should directly correspond to the same coordinates used by the draw* functions...I'll Mantis it.
Title: Re: Oddities with get screencoords function...
Post by: Nuke on March 21, 2008, 04:37:04 pm
would be awesome if get screen coords, as well as for the mouse output coords would be at the same scale as the screen res (this would prevent alot of confusion). it would also avoid frequent rescaling of coords in script.
Title: Re: Oddities with get screencoords function...
Post by: WMCoolmon on March 23, 2008, 02:33:50 am
This will be fixed in the next trunk build.