This commit is contained in:
jonathan santis 2024-11-27 14:48:10 +01:00
parent 3149c01bc1
commit 8544978351
2 changed files with 14 additions and 10 deletions

View File

@ -83,9 +83,11 @@ const Particle = struct {
self.velocity.a.y += val; self.velocity.a.y += val;
} }
pub fn applyForce(self : *Self,vec : pr.Vec) void { pub fn applyForce(self : *Self,vec : pr.Vec) void {
self.acceleration.a.x += vec.a.x * 0.5; self.acceleration.a.x = vec.a.x * 0.8;
self.acceleration.a.y += vec.a.y * 0.5; self.acceleration.a.y = vec.a.y * 0.8;
self.acceleration.a.z += vec.a.z; 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 posx : i32 = 0;
var posy : i32 = 0; var posy : i32 = 0;
const att : Attractor = .{.vec = .{.a=.{.x=10,.y=10,.z=10}}}; 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(); att.draw();
att2.draw(); att2.draw();
@ -135,7 +137,7 @@ const Emitter = struct
if(p.show == 1) if(p.show == 1)
{ {
p.applyGravity(2); p.applyGravity(0);
p.applyForce(att.attract(p.*)); p.applyForce(att.attract(p.*));
p.applyForce(att2.attract(p.*)); p.applyForce(att2.attract(p.*));
p.update(); p.update();
@ -154,13 +156,15 @@ const Attractor = struct
pub fn attract(self:Attractor,particle : Particle) pr.Vec pub fn attract(self:Attractor,particle : Particle) pr.Vec
{ {
var vec = self.vec.sub(particle.position); const distance = self.vec.sub(particle.position);
if( vec.a.x != 0 and vec.a.y != 0) var force : pr.Vec = undefined;
if( distance.a.x != 0 and distance.a.y != 0)
{ {
vec.a.x = vec.a.x/200; force.a.x = distance.a.x/200;
vec.a.y = vec.a.y/200; force.a.y = distance.a.y/200;
force.a.z = 0;
} }
return vec; return force;
} }
pub fn draw(self:Attractor) void pub fn draw(self:Attractor) void
{ {

Binary file not shown.