diff --git a/src/main.zig b/src/main.zig index 6ddb484..f34f923 100644 --- a/src/main.zig +++ b/src/main.zig @@ -83,8 +83,8 @@ const Emitter = struct { var yrnr = randMinMaxFloat(-0.5, 0.5); self.particles = try allocator.alloc(Particle, 10000); for (self.particles) |*p| { - xrnr = randMinMaxFloat(0, 2); - yrnr = randMinMaxFloat(0, 2); + xrnr = randMinMaxFloat(-2, 2); + yrnr = randMinMaxFloat(-2, 2); p.* = Particle{ .velocity = .{ .a = .{ .x = 0, .y = 0 } }, .acceleration = .{ .a = .{ .x = xrnr, .y = yrnr } } }; } } @@ -115,7 +115,6 @@ 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}}); - std.debug.print("attractor allocated\n",.{}); break; } @@ -128,9 +127,10 @@ const Emitter = struct { } for (self.particles) |*p| { if (p.show == 1) { - p.applyGravity(0); + //p.applyGravity(2); for (att) |at| { + //std.debug.print("force:{}\n",.{at.attract(p.*)}); p.applyForce(at.attract(p.*)); } p.update(); @@ -153,19 +153,29 @@ const Attractor = struct { self.init_done = 1; } pub fn attract(self: Attractor, particle: Particle) pr.Vec { - 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 / 200; - force.a.y = distance.a.y / 200; - force.a.z = 0; + if(self.init_done == 1) + { + 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 / 100; + force.a.y = distance.a.y / 100; + force.a.z = 0; + } + return force; + } + else + { + return .{.a=.{.x=0,.y=0,.z=0}}; } - return force; } pub fn draw(self: Attractor) void { const posx: i32 = @intFromFloat(screenWidth / 2 + self.vec.a.x); const posy: i32 = @intFromFloat(screenHeight / 2 + self.vec.a.y); - rl.drawRectangle(posx, posy, 10, 10, rl.Color{ .r = 10, .g = 10, .b = 120, .a = 255 }); + if (self.init_done == 1) + { + rl.drawRectangle(posx, posy, 10, 10, rl.Color{ .r = 10, .g = 10, .b = 120, .a = 255 }); + } } }; fn ItoF(x: i32) f32 { @@ -233,8 +243,6 @@ pub fn main() anyerror!void { emitter.emit(@as(u32, @intFromFloat(value)), value2, value3); } - - plotStr = try std.fmt.bufPrint(&plotStrBuf,"{d}, {d}, {d}, {d}\n",.{emitter.particles[0].acceleration.a.x,emitter.particles[0].position.a.x,emitter.particles[0].velocity.a.x,emitter.particles[0].show}); try plot.log(file,plotStr); diff --git a/zig-out/bin/raylib-test b/zig-out/bin/raylib-test index 7d8b213..af627a6 100755 Binary files a/zig-out/bin/raylib-test and b/zig-out/bin/raylib-test differ