diff --git a/src/main.zig b/src/main.zig index 9465582..066c654 100644 --- a/src/main.zig +++ b/src/main.zig @@ -83,9 +83,11 @@ const Particle = struct { self.velocity.a.y += val; } pub fn applyForce(self : *Self,vec : pr.Vec) void { - self.acceleration.a.x += vec.a.x * 0.5; - self.acceleration.a.y += vec.a.y * 0.5; - self.acceleration.a.z += vec.a.z; + self.acceleration.a.x = vec.a.x * 0.8; + self.acceleration.a.y = vec.a.y * 0.8; + self.acceleration.a.z = vec.a.z; + self.velocity.a.x *= 0.999; + self.velocity.a.y *= 0.999; } }; @@ -127,7 +129,7 @@ const Emitter = struct var posx : i32 = 0; var posy : i32 = 0; const att : Attractor = .{.vec = .{.a=.{.x=10,.y=10,.z=10}}}; - const att2 : Attractor = .{.vec = .{.a=.{.x=-100,.y=-100,.z=0}}}; + const att2 : Attractor = .{.vec = .{.a=.{.x=-200,.y=-200,.z=0}}}; att.draw(); att2.draw(); @@ -135,7 +137,7 @@ const Emitter = struct if(p.show == 1) { - p.applyGravity(2); + p.applyGravity(0); p.applyForce(att.attract(p.*)); p.applyForce(att2.attract(p.*)); p.update(); @@ -154,13 +156,15 @@ const Attractor = struct pub fn attract(self:Attractor,particle : Particle) pr.Vec { - var vec = self.vec.sub(particle.position); - if( vec.a.x != 0 and vec.a.y != 0) + const distance = self.vec.sub(particle.position); + var force : pr.Vec = undefined; + if( distance.a.x != 0 and distance.a.y != 0) { - vec.a.x = vec.a.x/200; - vec.a.y = vec.a.y/200; + force.a.x = distance.a.x/200; + force.a.y = distance.a.y/200; + force.a.z = 0; } - return vec; + return force; } pub fn draw(self:Attractor) void { diff --git a/zig-out/bin/raylib-test b/zig-out/bin/raylib-test index cf2e6cd..7ab64c6 100755 Binary files a/zig-out/bin/raylib-test and b/zig-out/bin/raylib-test differ