Skip to content

Commit

Permalink
chore(chassis): i did what you asked
Browse files Browse the repository at this point in the history
  • Loading branch information
CallMeEchoCodes committed Nov 2, 2024
1 parent ce0728c commit 67d940b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void init(MechaCore core) {
// each leg determines its own fixed rotation relative to the nose, and adds its chain to the skeleton.
this.legs = new ArrayList<>();
for (int i = 0; i < core.model().legInfo().size(); i++) {
legs.add(new ChassisLeg(core.model().legInfo().get(i), this, i));
legs.add(new ChassisLeg(core.model().legInfo().get(i), this, i, core));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public class MechaEntity extends Entity {
EntityDataSerializers.VECTOR3
);

public static final EntityDataAccessor<List<Vector3f>> JOINT_POSITIONS = SynchedEntityData.defineId(
MechaEntity.class,
ArmisticeEntityDataSerializerRegistrar.VEC3_LIST
);

public static final EntityDataAccessor<List<Vector2f>> BARREL_ROTATIONS = SynchedEntityData.defineId(
MechaEntity.class,
ArmisticeEntityDataSerializerRegistrar.VEC2_LIST
Expand Down Expand Up @@ -96,6 +101,7 @@ public MechaCore core() {
@Override
protected void defineSynchedData(@NotNull SynchedEntityData.Builder builder) {
builder.define(LEG_TICK_TARGETS, List.of());
builder.define(JOINT_POSITIONS, List.of());
builder.define(CLIENT_POS, new Vector3f());
builder.define(CLIENT_DIR, new Vector3f());
builder.define(HEAT, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
import java.util.ArrayList;
import java.util.List;

import static symbolics.division.armistice.mecha.MechaEntity.JOINT_POSITIONS;
import static symbolics.division.armistice.mecha.movement.IKUtil.f2m;
import static symbolics.division.armistice.mecha.movement.IKUtil.m2f;

public class ChassisLeg {

protected final int legIndex;
protected final MechaCore core;
protected ChassisPart chassis;
protected FabrikChain3D chain = new FabrikChain3D();

Expand All @@ -34,12 +36,13 @@ public class ChassisLeg {

private final float tempInitialY = 0;

public ChassisLeg(MechaModelData.LegInfo info, ChassisPart chassis, int index) {
public ChassisLeg(MechaModelData.LegInfo info, ChassisPart chassis, int index, MechaCore core) {
// WARNING: CALIKO ROTATION SYSTEM IS LEFT-HANDED
// THIS MEANS X AXIS IS FLIPPED OVER Z COMPARED TO MINECRAFT

this.chassis = chassis;
this.legIndex = index;
this.core = core;
// model format:
// leg1 -> seg1: yaw bone. get default yaw and limits
// seg1 -> seg2: get x-axis rotation and limits
Expand Down Expand Up @@ -254,9 +257,14 @@ private Vec3 getNearestValidStepTarget(Vec3 goal) {
}

public List<Vec3> jointPositions() {
List<Vec3> joints = new ArrayList<>();
List<Vec3> joints = new ArrayList<>(core.entity().getEntityData().get(JOINT_POSITIONS).stream().map(
vec -> new Vec3(vec.x(), vec.y(), vec.z())
).toList());

chain.getChain().stream().map(bone -> m2w(f2m(bone.getStartLocation()))).forEach(joints::add);
joints.add(m2w(f2m(chain.getChain().getLast().getEndLocation())));

core.entity().getEntityData().set(JOINT_POSITIONS, joints.stream().map(Vec3::toVector3f).toList());
return joints;
}
}

0 comments on commit 67d940b

Please sign in to comment.