repel1+
This commit is contained in:
parent
009bb10175
commit
b569e2fc23
19
src/main.zig
19
src/main.zig
@ -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.
Loading…
Reference in New Issue
Block a user