Thursday, 2024-05-02, 10:32 PM


Main
Registration
Login
Welcome Guest | RSS  
[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
Forum moderator: Hanky, Fireeye  
Clan NgO Forums » Discussions » Junk Yard » [JASS] Field Check (Function)
[JASS] Field Check
HankyDate: Friday, 2008-08-01, 10:30 PM | Message # 1
Lieutenant colonel
Group: Moderators
Messages: 116
Reputation: 9
Status: Offline
This is a old function I found in a map from me, maybe it can be usefull for you. The function check if something is in a field however the shape of the object is. With the function you can for example prove if a unit is in a triangle or if a unit is in a hexagon or whatever. Note the function is just 2D not 3D.

There's the vJass code:

Code
library Field initializer init
globals
        private constant integer max=5                 //Enter the number of the corners
        private real array FieldX
        private real array FieldY
endglobals

function FieldInside takes real x,real y returns boolean
        local integer i        = 0
        local integer j        = max
        local boolean hit      = false

        loop
          exitwhen i > max
          if (FieldY[i] < y and FieldY[j] >= y) or (FieldY[j] < y and FieldY[i] >= y) then
             if (FieldX[i]+(y-FieldY[i])/(FieldY[j]-FieldY[i])*(FieldX[j]-FieldX[i]) < x) then
                set hit=not hit
             endif
          endif
          set j = i
          set i = i + 1
        endloop

        return hit
endfunction

// In the init function enter the corners of the object.

private function init takes nothing returns nothing
        set FieldX[0]=- 113.8
        set FieldX[1]=- 367.8
        set FieldX[2]=- 391.2
        set FieldX[3]=- 70.9       
        set FieldX[4]=  330.0
        set FieldX[5]=  396.9
              
        set FieldY[0]=  245.2
        set FieldY[1]=  72.6
        set FieldY[2]=- 287.1
        set FieldY[3]=- 434.6
        set FieldY[4]=- 318.4
        set FieldY[5]=  55.2
endfunction
endlibrary

If you don't like vJass I also have a normal Jass code in the example map.

Attachments: TestField.w3x (13.8 Kb)



Made by Smoe reworked by GiR aka Darkt3mpl3r
 
Clan NgO Forums » Discussions » Junk Yard » [JASS] Field Check (Function)
  • Page 1 of 1
  • 1
Search:

Clan NgO © 2024Powered by uCoz