• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Creating a rect towards unit facing

Status
Not open for further replies.
Level 13
Joined
Nov 22, 2006
Messages
1,260
Enum units problem

Hi everyone.

I have a problem, I don't know how to enum units opposite of unit facing. Explanation: just look at the pic, I'm not in the mood to explain.
 

Attachments

  • Rect.jpg
    Rect.jpg
    23.1 KB · Views: 145
Last edited:
Level 13
Joined
Nov 22, 2006
Messages
1,260
Enum an area.

You do know that the unit will have to be facing either 90 degrees or 270 degrees, right?

This is because you can't create a rect that goes diagonal or in any shape other than a straight square/rectangle. I'm not sure if this would work too well because of this.

Oh, I forgot about that. Well can't the rect go outside map bounds?

If this isn't what you need
http://www.wc3campaigns.net/attachme...chmentid=28614
then you don't know what you need.

Yep, that is what I need.
 
Level 11
Joined
Aug 25, 2006
Messages
971
This is what you do. First you take the 'unit facing' angle and subtract 180 from it. Then you feed it into this kind of function
JASS:
function CorrecTAngle takes real Angle returns real
local real NewAngle = Angle

if NewAngle > 360 then
    loop
    exitwhen NewAngle < 360
        set NewAngle = NewAngle - 360
    endloop
endif
if NewAngle < 0 then
    loop
    exitwhen NewAngle > 0
        set NewAngle = NewAngle + 360
    endloop
endif        
return NewAngle
endfunction

That'll make sure the angle is between 0 - 360 (and will fix it if its not) Then you do some fancy (Depends on your Math grade) calculations to get the 4 points (of the rect). From there just feed them into that system I posted.
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Well it's those fancy calculations I'm looking for, checking if the angle is between 0-360 is the least of my problems. What good does the function do without the calculations? If I knew them, I wouldn't be posting, would I?

I think you can't create a rect that is an irregular tetragon, can you? What do those parameters in Rect function represent anyways?
 
Level 11
Joined
Aug 25, 2006
Messages
971
Ok heres what I made. I haven't test it'd it, but you should give it a go. I'm going to draw up a diagram in a moment. Actually, forget the diagram. I'll draw it up, but only if you need it. I think these functions are pretty simple to understand.
JASS:
function CorrecTAngle takes real Angle returns real
local real NewAngle = Angle

if NewAngle > 360 then
    loop
    exitwhen NewAngle < 360
        set NewAngle = NewAngle - 360
    endloop
endif
if NewAngle < 0 then
    loop
    exitwhen NewAngle > 0
        set NewAngle = NewAngle + 360
    endloop
endif        
return NewAngle
endfunction

function DoSomething takes nothing returns nothing
local real Width //width of rectangle
local real Leng //length of rectangle
local real StartPointX //Starting point
local real StartPointY //Second starting point
local real StartAngle //Angle of rectangle
local real Point1X = StartPointX + (1/2 * Width) * Cos(CorrecTAngle(StartAngle + 90) * bj_DEGTORAD)
local real Point1Y = StartPointY + (1/2 * Width) * Sin(CorrecTAngle(StartAngle + 90) * bj_DEGTORAD)
local real Point2X = StartPointX + (1/2 * Width) * Cos(CorrecTAngle(StartAngle - 90) * bj_DEGTORAD)
local real Point2Y = StartPointY + (1/2 * Width) * Sin(CorrecTAngle(StartAngle - 90) * bj_DEGTORAD)
local real Point3X = Point1X + Leng * Cos(StartAngle * bj_DEGTORAD)
local real Point3Y = Point1Y + Leng * Sin(StartAngle * bj_DEGTORAD)
local real Point4X = Point2X + Leng * Cos(StartAngle * bj_DEGTORAD)
local real Point4Y = Point2Y + Leng * Sin(StartAngle * bj_DEGTORAD)
//Point 1 2 3 4 make up the rectangle but NOT in that order. Order going counterclockwise: 1, 2, 4, 3
endfunction

Wait do you want to enum the rect behind or in front of the unit? This will make the rect face the angle its inputed with. (Not actually making a rect, only a series of points which could be used for w/e)

I just realized, the link I provided before was only a picture of the system. I just fixed the link so it led to the system. Heres the link again
http://www.wc3campaigns.net/showthread.php?t=96543
 
Last edited:
Level 11
Joined
Aug 25, 2006
Messages
971
Ok I used the guys system to enum points in a polygon.
I fixed a bug in my script. Somehow doing the 1/2 * Width caused it to calculate incorrectly.
JASS:
function half takes real k returns real
return k/2
endfunction
function DoSomething takes nothing returns nothing
local real Width //width of rectangle
local real Leng //length of rectangle
local real StartPointX //Starting point
local real StartPointY //Second starting point
local real StartAngle //Angle of rectangle
local real Point1X = StartPointX + half(Width) * Cos(CorrecTAngle(StartAngle + 90) * bj_DEGTORAD)
local real Point1Y = StartPointY + half(Width) * Sin(CorrecTAngle(StartAngle + 90) * bj_DEGTORAD)
local real Point2X = StartPointX + half(Width) * Cos(CorrecTAngle(StartAngle - 90) * bj_DEGTORAD)
local real Point2Y = StartPointY + half(Width) * Sin(CorrecTAngle(StartAngle - 90) * bj_DEGTORAD)
local real Point3X = Point1X + Leng * Cos(StartAngle * bj_DEGTORAD)
local real Point3Y = Point1Y + Leng * Sin(StartAngle * bj_DEGTORAD)
local real Point4X = Point2X + Leng * Cos(StartAngle * bj_DEGTORAD)
local real Point4Y = Point2Y + Leng * Sin(StartAngle * bj_DEGTORAD)
//Point 1 2 3 4 make up the rectangle but NOT in that order. Order: 1, 2, 4, 3
endfunction

This link goes to the system I used http://www.wc3campaigns.net/showthread.php?t=96543

The map on the bottom is my mod to his system to meet what you need. Its only to show what my jass function can do. It leaks like a waterfall. I doubt I'll be on for 10+ days. Hope this works for you! vJass REQUIRED!! (If you don't have vJass just play it)
 

Attachments

  • ShowMap.w3x
    28 KB · Views: 54
Last edited:
Level 13
Joined
Nov 22, 2006
Messages
1,260
Thank you very much! But.........I don't have wc3 :).

vJass REQUIRED!! (If you don't have vJass just play it)

No worries, I use vJass all the time, every jasser should.

Arghhhh!! I'm trying to make the darn code for fucking 4 hours, I'm just too stupid! There are always some barriers I can't get across! For example, The enum area doesn't have to be always a tetragon, it can be a triangle or a pentagon, now I have to put tons of if/then/elses! The quadrants are also fucked up, I need to change signs (because min y and min x of playable map area are negative) so I can do deltas normally ("distance" between two numbers)!!
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
If you want to program something that does a bit of algebra, it would be really easy; project a line of y=(the point's y) from (the point's x) and onwards, and see how many lines it intersects with of the bounds of this generic polygon. If it's odd, it's inside the shape. If it's even, it's outside the shape. (Then you would just enum a circle to get the units to test)
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Could you maybe put a drawing or something? It's kinda hard to understand this way.......

It's not the "enum units in tetragon" I'm worried about, it's generating the points of that tetraedar. The problem is that it doesn't always have to be a tetraedar (which I said before), and there are to many if/then/elses I must use (and I still can't get it).
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Yeah I know what regular polygon means :), but the enum area will never be a regular polygon.

If you want to program something that does a bit of algebra, it would be really easy; project a line of y=(the point's y) from (the point's x) and onwards, and see how many lines it intersects with of the bounds of this generic polygon. If it's odd, it's inside the shape. If it's even, it's outside the shape. (Then you would just enum a circle to get the units to test)

I'm doing that method, but it's kinda screwy (with signs, quadrants and that crap). But I'll get it eventually and then I'll need you to test it. Btw, forgot about that Jump func again? ;)
 
Level 11
Joined
Aug 25, 2006
Messages
971
Did you test the map I gave you? It does what you want doesnt it? (I can't look very often at this sight because I'm on vacation)
 
Know this is a Necro, but wanted to post a solution I found here that doesn't require substantial jass funcs (esp since wc3c is now down).

Use the Breath of Frost ability as your base. Set the starting area and ending area to be the same width. These are the two sides of your rectangle. Next, modify the buff on this ability to have no visible effect and last for a very short duration say (0.25) seconds. Next add this ability to a dummy and trigger the dummy to cast this ability whenever you need rectangle detection.

Once the dummy casts the ability in-game, fire another trigger that selects all units from the ability cast point using a radius that is much greater than the width of the rectangle. Add any units that have the short-term buff to a unit group, and bam you have units of any size rectangle you want in a unit group.

Spell Example.png

Edit: Note the small black circle is the caster dummy, casting the Breath of Frost spell
 
Last edited:
Status
Not open for further replies.
Top