remove debug messages, fix some physical errors

This commit is contained in:
jonathan santis 2024-12-04 11:17:53 +01:00
parent 7fbd24b85d
commit ec5fc69ae5
2 changed files with 25 additions and 8 deletions

View File

@ -113,6 +113,18 @@ const Emitter = struct {
if(at.init_done != 1) if(at.init_done != 1)
{ {
at.init(.{.a=.{.x=@floatFromInt(rl.getMouseX() - screenWidth / 2),.y=@floatFromInt(rl.getMouseY() - screenHeight / 2),.z=0}}); at.init(.{.a=.{.x=@floatFromInt(rl.getMouseX() - screenWidth / 2),.y=@floatFromInt(rl.getMouseY() - screenHeight / 2),.z=0}});
at.mode = 1;
break;
}
}
}
if (rl.isMouseButtonPressed(rl.MouseButton.mouse_button_middle)) {
for (att) |*at|
{
if(at.init_done != 1)
{
at.init(.{.a=.{.x=@floatFromInt(rl.getMouseX() - screenWidth / 2),.y=@floatFromInt(rl.getMouseY() - screenHeight / 2),.z=0}});
at.mode = 0;
break; break;
} }
} }
@ -127,8 +139,14 @@ const Emitter = struct {
//p.applyGravity(2); //p.applyGravity(2);
for (att) |at| for (att) |at|
{ {
//std.debug.print("force:{}\n",.{at.attract(p.*)}); if(at.mode == 0)
p.applyForce(at.repel(p.*)); {
p.applyForce(at.attract(p.*));
}
else
{
p.applyForce(at.repel(p.*));
}
} }
p.update(); p.update();
@ -150,6 +168,7 @@ const Emitter = struct {
const Attractor = struct { const Attractor = struct {
vec: pr.Vec, vec: pr.Vec,
init_done : u8 = 0, init_done : u8 = 0,
mode : u8 = 0,
pub fn init(self : *Attractor, vec : pr.Vec) void pub fn init(self : *Attractor, vec : pr.Vec) void
{ {
self.vec = vec; self.vec = vec;
@ -161,8 +180,8 @@ const Attractor = struct {
const distance = self.vec.sub(particle.position); const distance = self.vec.sub(particle.position);
var force: pr.Vec = undefined; var force: pr.Vec = undefined;
if (distance.a.x != 0 and distance.a.y != 0) { if (distance.a.x != 0 and distance.a.y != 0) {
force.a.x = distance.a.x / 1000; force.a.x = distance.a.x * @abs(1/distance.a.x);
force.a.y = distance.a.y / 1000; force.a.y = distance.a.y * @abs(1/distance.a.y);
force.a.z = 0; force.a.z = 0;
} }
return force; return force;
@ -178,8 +197,8 @@ const Attractor = struct {
const distance = self.vec.sub(particle.position); const distance = self.vec.sub(particle.position);
var force: pr.Vec = undefined; var force: pr.Vec = undefined;
if (distance.a.x != 0 and distance.a.y != 0) { if (distance.a.x != 0 and distance.a.y != 0) {
force.a.x = -distance.a.x / 1000; force.a.x = -distance.a.x * @abs(1/distance.a.x);
force.a.y = -distance.a.y / 1000; force.a.y = -distance.a.y * @abs(1/distance.a.y);
force.a.z = 0; force.a.z = 0;
} }
return force; return force;
@ -273,8 +292,6 @@ pub fn main() anyerror!void {
_ = rg.guiSlider(rectangle(10, 170, 600, 10), "-3", "3", &value2, ItoF(-100), ItoF(100)); _ = rg.guiSlider(rectangle(10, 170, 600, 10), "-3", "3", &value2, ItoF(-100), ItoF(100));
_ = rg.guiSlider(rectangle(10, 190, 600, 10), "-3", "3", &value3, -100, 100); _ = rg.guiSlider(rectangle(10, 190, 600, 10), "-3", "3", &value3, -100, 100);
_ = rg.guiColorPicker(rectangle(10,200,300,100),"Choose Color", &color); _ = rg.guiColorPicker(rectangle(10,200,300,100),"Choose Color", &color);
} }
else else
{ {

Binary file not shown.