Skip to content

Commit

Permalink
feat: flat models list
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceh121 committed Oct 3, 2023
1 parent 0e63406 commit 497c25c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.vinceh121.wanderer.building;

import java.util.LinkedList;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
Expand Down Expand Up @@ -30,7 +32,7 @@ public class InConstructionBuilding extends AbstractBuilding {
public InConstructionBuilding(final Wanderer game, final AbstractBuildingMeta meta) {
super(game, meta);

for (final DisplayModel m : this.getModels()) {
for (final DisplayModel m : this.getFlatModels()) {
m.addTextureAttribute(ColorAttribute.createEmissive(new Color(0f, 0.8f, 1f, 0f)));
m.addTextureAttribute(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_DST_COLOR, 0.5f));
m.addTextureAttribute(new NoLightningAttribute());
Expand Down Expand Up @@ -63,9 +65,11 @@ public void tick(final float delta) {
public void render(final ModelBatch batch, final Environment env) {
super.render(batch, env);

final LinkedList<DisplayModel> flatModels = this.getFlatModels();

for (int i = 0; i < this.curves.size; i++) {
final Bezier<Vector3> bezier = this.curves.get(i);
final DisplayModel model = this.getModels().get(i);
final DisplayModel model = flatModels.get(i);

// / 5: slows down the animation
// % 1: repeats the curve progress between 0.0 and 1.0
Expand Down
21 changes: 20 additions & 1 deletion core/src/me/vinceh121/wanderer/entity/AbstractEntity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.vinceh121.wanderer.entity;

import java.util.LinkedList;
import java.util.Objects;
import java.util.function.Consumer;

Expand Down Expand Up @@ -150,7 +151,7 @@ public void render(final ModelBatch batch, final Environment env) {
}

public void animateParts(final String animationChannel, final Consumer<Matrix4> transformation) {
for (final DisplayModel m : this.models) {
for (final DisplayModel m : this.getFlatModels()) {
if (animationChannel.equals(m.getAnimationChannel())) {
transformation.accept(m.getRelativeTransform());
m.updateTransform(this.getTransform());
Expand Down Expand Up @@ -281,6 +282,24 @@ public Array<DisplayModel> getModels() {
return this.models;
}

public LinkedList<DisplayModel> getFlatModels() {
LinkedList<DisplayModel> flatModels = new LinkedList<>();

for (DisplayModel root : this.models) {
this.recurseFlatModels(flatModels, root);
}

return flatModels;
}

private void recurseFlatModels(LinkedList<DisplayModel> flatModels, DisplayModel mdl) {
flatModels.add(mdl);

for (DisplayModel child : mdl.getChildren()) {
this.recurseFlatModels(flatModels, child);
}
}

public Array<SoundEmitter3D> getSoundEmitters() {
return this.soundEmitters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public void fire() {
for (final MachineGunTurret turret : this.turrets) {
this.fireTurret(turret);
}
this.animateParts("barrelSpin", trans -> trans.rotate(Vector3.Z, 1));

this.animateParts("barrelSpin", trans -> trans.rotateRad(Vector3.Z, 1));

this.fireSoundEmitter.play();
this.fireTimeout = 0.085f; // FIXME should be in meta
Expand Down

0 comments on commit 497c25c

Please sign in to comment.