diff --git a/src/main.zig b/src/main.zig index e6e3740..4b846fb 100644 --- a/src/main.zig +++ b/src/main.zig @@ -113,6 +113,18 @@ const Emitter = struct { if(at.init_done != 1) { at.init(.{.a=.{.x=@floatFromInt(rl.getMouseX() - screenWidth / 2),.y=@floatFromInt(rl.getMouseY() - screenHeight / 2),.z=0}}); + at.mode = 1; + break; + } + } + } + if (rl.isMouseButtonPressed(rl.MouseButton.mouse_button_middle)) { + for (att) |*at| + { + if(at.init_done != 1) + { + at.init(.{.a=.{.x=@floatFromInt(rl.getMouseX() - screenWidth / 2),.y=@floatFromInt(rl.getMouseY() - screenHeight / 2),.z=0}}); + at.mode = 0; break; } } @@ -127,8 +139,14 @@ const Emitter = struct { //p.applyGravity(2); for (att) |at| { - //std.debug.print("force:{}\n",.{at.attract(p.*)}); - p.applyForce(at.repel(p.*)); + if(at.mode == 0) + { + p.applyForce(at.attract(p.*)); + } + else + { + p.applyForce(at.repel(p.*)); + } } p.update(); @@ -150,6 +168,7 @@ const Emitter = struct { const Attractor = struct { vec: pr.Vec, init_done : u8 = 0, + mode : u8 = 0, pub fn init(self : *Attractor, vec : pr.Vec) void { self.vec = vec; @@ -161,8 +180,8 @@ const Attractor = struct { const distance = self.vec.sub(particle.position); var force: pr.Vec = undefined; if (distance.a.x != 0 and distance.a.y != 0) { - force.a.x = distance.a.x / 1000; - force.a.y = distance.a.y / 1000; + force.a.x = distance.a.x * @abs(1/distance.a.x); + force.a.y = distance.a.y * @abs(1/distance.a.y); force.a.z = 0; } return force; @@ -178,8 +197,8 @@ const Attractor = struct { const distance = self.vec.sub(particle.position); var force: pr.Vec = undefined; if (distance.a.x != 0 and distance.a.y != 0) { - force.a.x = -distance.a.x / 1000; - force.a.y = -distance.a.y / 1000; + force.a.x = -distance.a.x * @abs(1/distance.a.x); + force.a.y = -distance.a.y * @abs(1/distance.a.y); force.a.z = 0; } return force; @@ -273,8 +292,6 @@ pub fn main() anyerror!void { _ = rg.guiSlider(rectangle(10, 170, 600, 10), "-3", "3", &value2, ItoF(-100), ItoF(100)); _ = rg.guiSlider(rectangle(10, 190, 600, 10), "-3", "3", &value3, -100, 100); _ = rg.guiColorPicker(rectangle(10,200,300,100),"Choose Color", &color); - - } else { diff --git a/zig-out/bin/raylib-test b/zig-out/bin/raylib-test index cff453c..13cfb31 100755 Binary files a/zig-out/bin/raylib-test and b/zig-out/bin/raylib-test differ