| 08-10-2006, 07:54 PM | #2 |
I heard my triangle function is not as fast as it could be. Dunno about better versions though. I would check if TempGroup exists before destroying it the first time. There is no reason for the triangle function to not work for more than one triangle. I used it in the cone template twice so it must be something else |
| 08-10-2006, 07:59 PM | #3 |
Note: The movement speed modifying native is somewhat screwy. I suggest you use abilities to reduce movespeed. |
| 08-10-2006, 08:23 PM | #4 | ||
Quote:
Quote:
|
| 08-11-2006, 08:53 PM | #5 |
Sorry to double post, am I allowed to? Well I'm updating the information I have on this problem, so I hope so. If not, sorry. OK, so I tried blu's suggestion, and while interesting, it didnt really help. The problem IS that it's not counting the second set of coordinates. So... any ideas on how to fix that? |
| 08-11-2006, 09:53 PM | #6 |
Try playing special effects on the 6 points of the triangle to confirm that the coordinates are correct. |
| 08-11-2006, 10:33 PM | #7 |
Okay Vex, I tried that. It's all correct. However something weird did happen. It's not related to the new triggers, but a few buildings I placed moved... EDIT: Actually. I have no idea why they are doing that. Is there any reasons for buildings to move for no reason? |
| 08-11-2006, 11:25 PM | #8 |
when you play a lot of special effects, weird things like that happen. The only other things I can think about right now are: - Is the second triangle kind of small? It would only count units as being there if their origins are in the triangle, not if their collision size is inside the triangle. - Try updating the triangle function, I remember that an old version didn't work too well. Find the newest at wc3jass.com |
| 08-12-2006, 12:06 AM | #9 |
No, the triangles are (about) each a quarter of the map. Will doa bout the updating thing. Thanks. |
| 08-12-2006, 03:55 AM | #10 |
Okay, sorry to double post again. I tried updating the triangle function, but still no good. This is getting bad. I tried seperating the triggers into 2 triggers, that didnt work. Then I tried working with abilities, that didnt work. Still need help. |
| 08-12-2006, 04:00 AM | #11 |
Try killing the picked units instead of changing the speed (so you can notice if they are really getting picked up) If not then I guess I'll need the map to see if it is actually a bug with the triangle function although I've seen it working with many different triangle variations. |
| 08-12-2006, 04:31 AM | #12 |
found this lying around in my jass folder. different way to check if a point is in a triangle. probably untested. JASS://Uses a lot of real subtraction which the warcraft engine has issues with //x1,y1,x2,y2,x3,y3 define triangle vertices //px,py is the point in question //Computes area of triangle and three sub triangles made from vertices to point //If area of sub triangles is greater than area of test triangle, the point is outside function IsPointInTri takes real x1, real y1, real x2, real y2, real x3, real y3, real px, real py returns boolean // local real ux = x2-x1 //u is vector from 1 to 2 // local real uy = y2-y1 // local real vx = x3-x1 //v is vector from 1 to 3 // local real vy = y3-y1 local real ax = px-x1 //a is vector from p to 1 local real ay = py-y1 local real bx = px-x2 //b is vector from p to 2 local real by = py-y2 local real cx = px-x3 //c is vector from p to 3 local real cy = py-y3 //A = 1/2 | u cross v | //Drop factor of 1/2 since we're doing a comparison local real area_tri = (x2-x1)*(y3-y1)-(y2-y1)*(x3-x1) local real area1 = ax*by-ay*bx //area between 1 2 p local real area2 = bx*cy-by*cx //area between 2 3 p local real area3 = cx*ay-cy*ax //area between 3 1 p if area_tri < 0. then set area_tri = -area_tri endif if area1 < 0. then set area1 = -area1 endif if area2 < 0. then set area2 = -area2 endif if area3 < 0. then set area3 = -area3 endif return area1+area2+area3 <= area_tri*1.001 //some TOL for rounding endfunction |
| 08-12-2006, 04:34 AM | #13 | |
Quote:
Tested. It is definatly not tracking the second triangle. I'll PM you the map if you would like, however I listed all the triggers that would affect it. |
| 08-12-2006, 03:17 PM | #14 |
But I need a testing environment, I cannot test a function by just reading it. So pm me the map |
| 08-13-2006, 03:28 PM | #15 |
Pipedream's method is better and faster so this is a better working version of the triangle function: JASS:function GetRectThatLimitsTriangle takes real x1, real y1, real x2, real y2, real x3, real y3 returns rect local real maxx local real minx if (x1>x2) then if (x2>x3) then //x1>x2>x3 set maxx=x1 set minx=x3 elseif (x3>x1) then //x3>x1>x2 set maxx=x3 set minx=x2 else //x3>x1>x2 set maxx=x1 set minx=x2 endif elseif (x1>x3) then //x2>x1>x3 set maxx=x2 set minx=x3 elseif (x3>x2) then //x3>x2>x1 set maxx=x3 set minx=x1 else //x2>x3>x1 set maxx=x2 set minx=x1 endif if (y1>y2) then if (y2>y3) then //y1>y2>y3 return Rect(minx,y3,maxx,y1) elseif (y3>y1) then //y3>y1>y2 return Rect(minx,y2,maxx,y3) else //y3>y1>y2 return Rect(minx,y2,maxx,y1) endif elseif (y1>y3) then //y2>y1>y3 return Rect(minx,y3,maxx,y2) elseif (y3>y2) then //y3>y2>y1 return Rect(minx,y1,maxx,y3) endif //y2>y3>y1 return Rect(minx,y1,maxx,y2) endfunction //Uses a lot of real subtraction which the warcraft engine has issues with //x1,y1,x2,y2,x3,y3 define triangle vertices //px,py is the point in question //Computes area of triangle and three sub triangles made from vertices to point //If area of sub triangles is greater than area of test triangle, the point is outside function GroupAddUnitsInTriangle takes group whichGroup, real x1, real y1, real x2, real y2, real x3, real y3 returns nothing local rect semi=GetRectThatLimitsTriangle(x1,y1,x2,y2,x3,y3) local group inrect=CreateGroup() local unit picked local real x local real y local real ax //a is vector from p to 1 local real ay local real bx //b is vector from p to 2 local real by local real cx //c is vector from p to 3 local real cy //A = 1/2 | u cross v | //Drop factor of 1/2 since we're doing a comparison local real area_tri = (x2-x1)*(y3-y1)-(y2-y1)*(x3-x1) local real area1 local real area2 local real area3 call GroupEnumUnitsInRect( inrect, semi,null) loop set picked=FirstOfGroup(inrect) exitwhen picked==null if IsUnitInGroup(picked,whichGroup) then else set x=GetUnitX(picked) set y=GetUnitY(picked) set ax=x-x1 set ay=y-y1 set bx=x-x2 set by=y-y2 set cx=x-x3 set cy=y-y3 set area_tri = (x2-x1)*(y3-y1)-(y2-y1)*(x3-x1) set area1 = ax*by-ay*bx //area between 1 2 p set area2 = bx*cy-by*cx //area between 2 3 p set area3 = cx*ay-cy*ax //area between 3 1 p if area_tri < 0. then set area_tri = -area_tri endif if area1 < 0. then set area1 = -area1 endif if area2 < 0. then set area2 = -area2 endif if area3 < 0. then set area3 = -area3 endif if (area1+area2+area3 <= area_tri*1.001) then //some TOL for rounding call GroupAddUnit(whichGroup,picked) endif endif call GroupRemoveUnit(inrect,picked) endloop call RemoveRect(semi) call DestroyGroup(inrect) set whichGroup=null set picked=null set semi=null set inrect=null endfunction |
