added features for local editing of some stuff

This commit is contained in:
peterino2 2025-09-21 01:09:49 -07:00
parent 2046b1d7c8
commit eaf1d2bcb7
3 changed files with 41 additions and 18 deletions

View File

@ -141,6 +141,8 @@ pub const ParticleEmitter = struct {
emitterMaxLife: f64 = 0.0,
emitterShape: EmitterShape = .{ .spherical = .{} },
useLocalScene: bool = false,
_showDebug: bool = false,
entity: core.Entity = undefined,
@ -180,18 +182,20 @@ pub const ParticleEmitter = struct {
}
}
switch (self.emitterShape) {
.spherical => |spherical| {
i = 0;
while (i < self.particlesPVA.items.len) : (i += 1) {
if (positionLength(self.particlesPVA.items[i].position) > spherical.radius) {
self.removeParticle(i);
if (self.useLocalScene) {
switch (self.emitterShape) {
.spherical => |spherical| {
i = 0;
while (i < self.particlesPVA.items.len) : (i += 1) {
if (positionLength(self.particlesPVA.items[i].position) > spherical.radius) {
self.removeParticle(i);
}
}
}
},
.conal => {
@panic("not implemented");
},
},
.conal => {
@panic("not implemented");
},
}
}
}
@ -237,7 +241,7 @@ pub const ParticleEmitter = struct {
const v = core.Vectorf{ .x = oneRand.getRange(), .y = oneRand.getRange(), .z = oneRand.getRange() };
const v2 = v.normalize();
const pva: ParticlePVA = .{
var pva: ParticlePVA = .{
.velocity = v2.fmul(self.particleVelocity.getRange()).toZm(),
.position = .{
radius.getRange(),
@ -247,6 +251,11 @@ pub const ParticleEmitter = struct {
},
.acceleration = v2.fmul(self.particleAcceleration.getRange()).toZm(),
};
if (!self.useLocalScene) {
const scenePos = core.zm.mul(pva.position, self.entity.fetch(core.Scene).?.getPosRot().toTransform());
pva.position = scenePos;
}
return pva;
},
.conal => |conal| {
@ -291,13 +300,20 @@ pub const ParticleEmitter = struct {
}
pub fn updateFinals(self: *@This()) void {
const scene = self.entity.fetch(core.Scene).?;
const transform = scene.getPosRot().toTransform();
if (self.useLocalScene) {
const scene = self.entity.fetch(core.Scene).?;
const transform = scene.getPosRot().toTransform();
for (self.particlesPVA.items, 0..) |pva, i| {
const p = core.zm.translationV(pva.position);
for (self.particlesPVA.items, 0..) |pva, i| {
const p = core.zm.translationV(pva.position);
self.finals.items[i] = core.zm.mul(p, transform);
self.finals.items[i] = core.zm.mul(p, transform);
}
} else {
for (self.particlesPVA.items, 0..) |pva, i| {
const p = core.zm.translationV(pva.position);
self.finals.items[i] = p;
}
}
}

View File

@ -217,6 +217,14 @@ pub const ExternGameObject = struct {
.mass_properties_override = .{ .mass = 12 },
.override_mass_properties = .calc_inertia,
});
const particle = box2.addComponent(rend.ParticleEmitter).?;
particle.start();
particle.gravity = .{ .y = 1.0 };
particle.particleVelocity = .{ .min = 0.6, .max = 1.2 };
particle.particleLife = .{ .min = 5, .max = 6 };
var name = core.MakeName("t_pixelSmoke");
particle.texture = rend.getTexture(&name).?;
}
fn onAltFire(ctx: ?*anyopaque, _: core.ActionEvent) void {

View File

@ -128,7 +128,6 @@ pub const ParticleObject = struct {
const e = try core.createEntity();
const particle = e.addComponent(rend.ParticleEmitter).?;
particle._showDebug = true;
particle.start();
particle.gravity = .{ .y = -9.8 };
var name = core.MakeName("t_pixelSmoke");