Radians

Status
Not open for further replies.

Chaosy

Tutorial Reviewer
Level 41
Joined
Jun 9, 2011
Messages
13,288
Decided to work directly with radians instead of converting to degrees.

My intention is to form a circle of dummies but the circle does not get completed. The tenth dummy is always missing.
I tried changing the loop to while(i < num + 6) but the tenth dummy still didn't appear, so it's a math problem with the angle, I assume.
4a0b20f4a8594a4ddc31eea9045476ab.png


JASS:
//! zinc
	library PrisonAbility requires Table, Missile
	{
		public struct PrisonCore
		{
			Table t;
			real x, y;
			
			method DummyCircle(integer num, real height)
			{
				real interval = (bj_PI*2)/num;
				real angle;
				real nx;
				real ny;
				integer i = 0;
				Missile m;
				while(i < num)
				{
					angle = i*interval;
					nx = this.x + 250 * Cos(angle);
					ny = this.y + 250 * Sin(angle);
					m = Missile.create(nx, ny, height, 0, 0, height);
					m.model = "Abilities\\Weapons\\FireBallMissile\\FireBallMissile.mdl";
					i += 1;
				}
			}
		
			static method create(real x, real y) -> thistype
			{
				thistype this = thistype.allocate();
				this.x = x;
				this.y = y;
				this.DummyCircle(10, 50);
				return this;
			}
		}
	}
//! endzinc
 
Mine works fine
JASS:
//! zinc
    library Test
    {   
        function onInit()
        {
            integer num = 10;
            real interval = 2*bj_PI/num;
            integer i = 0;
            real angle;
            real x = 0;
            real y = 0;
            FogMaskEnable(false);
            FogEnable(false);
            while(i < num)
            {
                angle = i*interval;
                AddSpecialEffect("Abilities\\Weapons\\FireBallMissile\\FireBallMissile.mdl", x + 250*Cos(angle), y + 250*Sin(angle));
                i += 1;
            }
        }
    }
//! endzinc

Maybe it must have something to do with the Missile library?
 

Attachments

I don't know what fixed it but it randomly started to work properly.

edit: And then it stopped working again.
images


edit2: I added a debug message. It shows 0-8 despite it being supposed to loop to 18 in this case.
Something in the loop breaks the code somehow.
JASS:
			method DummyCircle(integer num, real height, real speed)
			{
				real interval = (bj_PI*2)/num;
				real nx, ny, angle;
				integer i = 0;
				integer h;
				Missile m;
				while(i < num + 9)
				{
					angle = i*interval;
					nx = this.x + 250 * Cos(angle);
					ny = this.y + 250 * Sin(angle);
					m = Missile.create(nx, ny, height, 0, 0, height);
					m.model = "Abilities\\Weapons\\FireBallMissile\\FireBallMissile.mdl";
					GroupAddUnit(g, m.dummy);
					h = GetHandleId(m.dummy);
					t[0].real[h] = interval;
					t[1].real[h] = speed;
					t[2].real[h] = angle;
					t[3].real[h] = this.x;
					t[4].real[h] = this.y;
					BJDebugMsg(I2S(i));
					i += 1;
				}
			}
 
Status
Not open for further replies.
Back
Top