This commit is contained in:
jonathan santis 2024-11-28 15:14:41 +01:00
parent 009bb10175
commit b569e2fc23
2 changed files with 18 additions and 1 deletions

View File

@ -131,7 +131,7 @@ const Emitter = struct {
for (att) |at|
{
//std.debug.print("force:{}\n",.{at.attract(p.*)});
p.applyForce(at.attract(p.*));
p.applyForce(at.repel(p.*));
}
p.update();
@ -169,6 +169,23 @@ const Attractor = struct {
return .{.a=.{.x=0,.y=0,.z=0}};
}
}
pub fn repel(self: Attractor, particle: Particle) pr.Vec {
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 / 1000;
force.a.y = -distance.a.y / 1000;
force.a.z = 0;
}
return force;
}
else
{
return .{.a=.{.x=0,.y=0,.z=0}};
}
}
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);

Binary file not shown.