Creating a cross (X) with SFXs ? :S

Komaqtion

You can change this now in User CP.
Reaction score
469
Hello !

Ok, so I would simply like to know:
How do I go about creating a simple cross (X) using special effects ? :S

What do I need to know to make it ? (If I want to make a function with arguments for it :D)

Center X/Y, width and height ?
Is that about it ?
 

Executor

I see you
Reaction score
57
Well thats relativly easy I think.

Best way would be packing the effects in a struct for clean and nice code.

Code:
X      X
  X   X
    X
  X   X
X       X

JASS:
struct Cross[20]
   private static string MODEL = " .......... "
   effect array sfx[9]
   static method create takes real x, real y returns thistype 
      local thistype this = thistype.allocate()
      local integer i 
      
      set .sfx[0] = AddSpecialEffect(...,.MODEL,...)
 
      // here one loop for the first line

      // here one loop for the second line
   endmethod
endstruct


If you need further help, tell us.

I'd say you could include a "real angle" var in the create method to variate the angle of the lines.
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
like Executor said, using effect array it's pretty easy

something like this:

JASS:
function PolarX takes real dist, real angle returns real
      return dist * Cos(angle * 0.0174)
endfunction

function PolarY takes real dist, real angle returns real
      return dist * Sin(angle * 0.0174)
endfunction

private struct data
      effect array [20]

      static method CreateCross takes real x, real y, real dist, string EFFECT_TYPE returns data
           local data d = data.allocate()
           local real offset = dist
           local integer i = 0

           loop
                set d.<i> = AddSpecialEffect(EFFECT_TYPE, x + PolarX(offset, 45), y + PolarY(offset, 45)
                set offset = offset - 100. //depends on the size of the effect, if you use 100. make the dist a multiplier of 100 for best result

                set i = i + 1
                exitwhen offset &lt; dist * -2
           endloop
          
           set offset = dist
              
           loop
                set d.<i> = AddSpecialEffect(EFFECT_TYPE, x + PolarX(offset, 135), y + PolarY(offset, 135)
                set offset = offset - 100. //depends on the size of the effect, if you use 100. make the dist a multiplier of 100 for best result

                set i = i + 1
                exitwhen offset &lt; dist * -2
           endloop

           return d
      endfunction

endstruct</i></i>


dist being the distance between the center of the cross and it's end

EDIT: try the edited code
 

Komaqtion

You can change this now in User CP.
Reaction score
469
What if the dimensions of the square the box is supposed to be in isn't an exact square ?
Like if one side is longer than the other, so you want to adapt the cross to that ? :S
 

Executor

I see you
Reaction score
57
Is it that hard? I mean you have the 4 corner points of the rect.

Code:
A                B
       rect
D                C

______________

A(minX/maxY) 
B(maxX/maxY)
C(maxX/minY)
D(minX/minY)

And you have the functions:

JASS:
function PolarProjectionBJ takes location source, real dist, real angle returns location
    local real x = GetLocationX(source) + dist * Cos(angle * bj_DEGTORAD)
    local real y = GetLocationY(source) + dist * Sin(angle * bj_DEGTORAD)
    return Location(x, y)
endfunction

function AngleBetweenPoints takes location locA, location locB returns real
    return bj_RADTODEG * Atan2(GetLocationY(locB) - GetLocationY(locA), GetLocationX(locB) - GetLocationX(locA))
endfunction

function DistanceBetweenPoints takes location locA, location locB returns real
    local real dx = GetLocationX(locB) - GetLocationX(locA)
    local real dy = GetLocationY(locB) - GetLocationY(locA)
    return SquareRoot(dx * dx + dy * dy)
endfunction


For each line, you calculate the distance (A to C, or B to D) and divide it by the number of effects you want to use for each line.

step = Distance(A,C) / number of effects
a = Angle(A,C)

loop
x = PolarProjection( Ax, step, a)
y = PolarProjection( Ay, step, a)
CreateEffect(x,y)
i = i + 1
exitwhen i > number of effects
endloop
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
////////////////////////
//  
//   Functions :
//   XCandy.create(string path, real posX, real posY, real AoE, real Interval) -&gt; struct
//  &lt;vars&gt;.destroy()
//
//  Normal Jass Syntax :
//  XCandy_Create(string path, real posX, real posY, real AoE, real Interval) -&gt; struct
//  XCandy_Destroy(&lt;vars&gt;)
//
////////////////////////

library XCandy
    
    private struct EffectStruct
        effect eff
        thistype prev
        thistype next
        
        method onDestroy takes nothing returns nothing
            call DestroyEffect(.eff)
        endmethod
    endstruct
    
    struct XCandy
        private EffectStruct left
        private EffectStruct right
        
        static method create takes string path, real x, real y, real size, real interval returns thistype
            local thistype this = .allocate()
            local real sizex = size / 2
            local integer tick = R2I(size / interval)
            local real cosA = interval * Cos(5.25)
            local real sinA = interval * Sin(5.25)
            local real cosB = interval * Cos(4.2)
            local real sinB = interval * Sin(4.2)
            local real xA = x + sizex * Cos(2.1)
            local real yA = y + sizex * Sin(2.1)
            local real xB = x + sizex * Cos(7.35)
            local real yB = y + sizex * Sin(7.35)
            local EffectStruct temp
            set .left = EffectStruct.create()
            set .left.eff = AddSpecialEffect(path,xA,yA)
            set .left.prev = .left
            set .left.next = .left
            set .right = EffectStruct.create()
            set .right.eff = AddSpecialEffect(path,xB,yB)
            set .right.prev = .right
            set .right.next = .right
            
            loop
            exitwhen tick == 0
                set xA = xA + cosA
                set yA = yA + sinA
                set temp = EffectStruct.create()
                set temp.eff = AddSpecialEffect(path,xA,yA)
                set temp.prev = left.prev
                set temp.next = left
                set left.prev.next = temp
                set left.prev = temp
                
                set xB = xB + cosB
                set yB = yB + sinB
                set temp = EffectStruct.create()
                set temp.eff = AddSpecialEffect(path,xB,yB)
                set temp.prev = right.prev
                set temp.next = right
                set right.prev.next = temp
                set right.prev = temp
                
                set tick = tick - 1
            endloop
            
            return this
        endmethod
        
        method onDestroy takes nothing returns nothing
            local EffectStruct left = .left.next
            local EffectStruct right = .right.next
            loop
            exitwhen left == .left and .right == .right
                call left.destroy()
                call right.destroy()
                set left = left.next
                set right = right.next
            endloop
            call .left.destroy()
            call .right.destroy()
        endmethod
        
    endstruct
    
    public function Create takes string path, real x, real y, real size, real interval returns XCandy
        return XCandy.create(path,x,y,size,interval)
    endfunction
    
    public function Destroy takes XCandy i returns nothing
        call i.destroy()
    endfunction
    
endlibrary


Better version with Linked List. Generally the number of effect array is depends on the size of X you need. Both examples on top will break when the size of X is enough big. But my version of X creation library does not. The number of effect array is dynamic for each struct, it will not break even your X is very big.
 

jig7c

Stop reading me...-statement
Reaction score
123
can you please explain to me in simple terms on how to use the above code?
I'm very new to jass, so i have hard time picking things up...

can someone give me an example.. lets say i have to create flamestrike model file in an X pattern..

i know how to get X,Y of a unit

local unit u = GetTriggerUnit
local integer x = GetUnitX(u)
local integer y = GetUnitY(u)

how would i used the above code?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
local XCandy fx = XCandy_Create(&quot;Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl&quot;,x,y,600.,200.)
call TriggerSleepAction(2.)
call XCandy_Destroy(fx) //Destroy it after 2 seconds.
//You must destroy the effect else it will leak.

Example.
 

Executor

I see you
Reaction score
57
JASS:

////////////////////////
//  
//   Functions :
//   XCandy.create(string path, real posX, real posY, real AoE, real Interval) -&gt; struct
//  &lt;vars&gt;.destroy()
//
//  Normal Jass Syntax :
//  XCandy_Create(string path, real posX, real posY, real AoE, real Interval) -&gt; struct
//  XCandy_Destroy(&lt;vars&gt;)
//
////////////////////////

library XCandy
    
    private struct EffectStruct
        effect eff
        thistype prev
        thistype next
        
        method onDestroy takes nothing returns nothing
            call DestroyEffect(.eff)
        endmethod
    endstruct
    
    struct XCandy
        private EffectStruct left
        private EffectStruct right
        
        static method create takes string path, real x, real y, real size, real interval returns thistype
            local thistype this = .allocate()
            local real sizex = size / 2
            local integer tick = R2I(size / interval)
            local real cosA = interval * Cos(5.25)
            local real sinA = interval * Sin(5.25)
            local real cosB = interval * Cos(4.2)
            local real sinB = interval * Sin(4.2)
            local real xA = x + sizex * Cos(2.1)
            local real yA = y + sizex * Sin(2.1)
            local real xB = x + sizex * Cos(7.35)
            local real yB = y + sizex * Sin(7.35)
            local EffectStruct temp
            set .left = EffectStruct.create()
            set .left.eff = AddSpecialEffect(path,xA,yA)
            set .left.prev = .left
            set .left.next = .left
            set .right = EffectStruct.create()
            set .right.eff = AddSpecialEffect(path,xB,yB)
            set .right.prev = .right
            set .right.next = .right
            
            loop
            exitwhen tick == 0
                set xA = xA + cosA
                set yA = yA + sinA
                set temp = EffectStruct.create()
                set temp.eff = AddSpecialEffect(path,xA,yA)
                set temp.prev = left.prev
                set temp.next = left
                set left.prev.next = temp
                set left.prev = temp
                
                set xB = xB + cosB
                set yB = yB + sinB
                set temp = EffectStruct.create()
                set temp.eff = AddSpecialEffect(path,xB,yB)
                set temp.prev = right.prev
                set temp.next = right
                set right.prev.next = temp
                set right.prev = temp
                
                set tick = tick - 1
            endloop
            
            return this
        endmethod
        
        method onDestroy takes nothing returns nothing
            local EffectStruct left = .left.next
            local EffectStruct right = .right.next
            loop
            exitwhen left == .left and .right == .right
                call left.destroy()
                call right.destroy()
                set left = left.next
                set right = right.next
            endloop
            call .left.destroy()
            call .right.destroy()
        endmethod
        
    endstruct
    
    public function Create takes string path, real x, real y, real size, real interval returns XCandy
        return XCandy.create(path,x,y,size,interval)
    endfunction
    
    public function Destroy takes XCandy i returns nothing
        call i.destroy()
    endfunction
    
endlibrary


Better version with Linked List. Generally the number of effect array is depends on the size of X you need. Both examples on top will break when the size of X is enough big. But my version of X creation library does not. The number of effect array is dynamic for each struct, it will not break even your X is very big.

What if the dimensions of the square the box is supposed to be in isn't an exact square ?
Like if one side is longer than the other, so you want to adapt the cross to that ? :S
.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
What if the dimensions of the square the box is supposed to be in isn't an exact square ?
Like if one side is longer than the other, so you want to adapt the cross to that ? :S

My library does not create exact-squared X, if you tested it.
 

Executor

I see you
Reaction score
57
What if the dimensions of the square the box is supposed to be in isn't an exact square ?
Like if one side is longer than the other, so you want to adapt the cross to that ? :S

My library does not create exact-squared X, if you tested it.

Yes indeed, thats the point. As I understand him, he wants a 'X' to be created in and adapted to a given rect. This means the angle has to be calculated dynamically dependend on the relation of height and width.
 
General chit-chat
Help Users
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top