Author Topic: Oddities with get screencoords function...  (Read 3225 times)

0 Members and 1 Guest are viewing this topic.

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Oddities with get screencoords function...
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.
« Last Edit: March 20, 2008, 04:50:21 am by Wanderer »
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: Oddities with get screencoords function...
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]
« Last Edit: March 20, 2008, 04:54:24 am by Wanderer »
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Oddities with get screencoords function...
getScreenCoords should directly correspond to the same coordinates used by the draw* functions...I'll Mantis it.
-C

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Oddities with get screencoords function...
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.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

  

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Oddities with get screencoords function...
This will be fixed in the next trunk build.
-C