Test with skew

This commit is contained in:
Retera 2020-03-01 14:41:53 -06:00
parent f776a602f9
commit ec3fa06e01
3 changed files with 34 additions and 3 deletions

View File

@ -3,5 +3,5 @@ package com.etheller.warsmash.util;
public class WarsmashConstants {
public static final int MAX_PLAYERS = 16;
public static final int REPLACEABLE_TEXTURE_LIMIT = 64;
public static final float SIMULATION_STEP_TIME = 1 / 20f;
public static final float SIMULATION_STEP_TIME = 1 / 60f;
}

View File

@ -3,6 +3,8 @@ package com.etheller.warsmash.viewer5.handlers.w3x.rendersim;
import java.util.List;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Quaternion;
import com.badlogic.gdx.math.Vector3;
import com.etheller.warsmash.parsers.mdlx.Sequence;
import com.etheller.warsmash.viewer5.handlers.mdx.MdxComplexInstance;
import com.etheller.warsmash.viewer5.handlers.mdx.MdxModel;
@ -12,6 +14,9 @@ import com.etheller.warsmash.viewer5.handlers.w3x.War3MapViewer;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.projectile.CAttackProjectile;
public class RenderAttackProjectile {
private static final Quaternion pitchHeap = new Quaternion();
private static final Vector3 skewVector = new Vector3();
private final CAttackProjectile simulationProjectile;
private final MdxComplexInstance modelInstance;
private float x;
@ -56,7 +61,27 @@ public class RenderAttackProjectile {
this.z = this.z + ((speed * simDz) / simD);
}
this.modelInstance.setLocation(this.x, this.y, this.z);
final float dxToTarget = this.simulationProjectile.getTarget().getX() - this.x;
final float dyToTarget = this.simulationProjectile.getTarget().getY() - this.y;
final float dzToTarget = this.simulationProjectile.getTarget().getFlyHeight() - this.z;
final float d2DToTarget = (float) Math.sqrt((dxToTarget * dxToTarget) + (dyToTarget * dyToTarget));
final float yaw = (float) Math.atan2(dxToTarget, dyToTarget);
final float pitch = (float) Math.atan2(dzToTarget, d2DToTarget);
final float arcCurrentHeight = this.simulationProjectile.getArcCurrentHeight();
final float oppositeYaw = yaw + (float) Math.PI;
skewVector.set((float) (Math.cos(oppositeYaw) * Math.cos(Math.PI / 4)),
(float) (Math.sin(oppositeYaw) * Math.cos(Math.PI / 4)), (float) (Math.sin(Math.PI / 4)));
final float skewX = arcCurrentHeight * skewVector.x;
final float skewY = arcCurrentHeight * skewVector.y;
final float skewZ = arcCurrentHeight * skewVector.z;
this.modelInstance.setLocation(this.x + skewX, this.y + skewY, this.z + skewZ);
// this.modelInstance.localRotation.setFromAxisRad(0, 0, 1, yaw);
this.modelInstance.localRotation.setFromAxisRad(0, -1, 0, pitch);
// this.modelInstance.rotateLocal(pitchHeap.setFromAxisRad(0, -1, 0, pitch));
war3MapViewer.worldScene.grid.moved(this.modelInstance);
final boolean everythingDone = this.simulationProjectile.isDone() && this.modelInstance.sequenceEnded;

View File

@ -19,6 +19,7 @@ public class CAttackProjectile {
private boolean done;
private final CUnit source;
private final int damage;
private float arcCurrentHeight;
public CAttackProjectile(final float x, final float y, final float z, final float speed, final float arc,
final CWidget target, final CUnit source, final int damage) {
@ -71,7 +72,8 @@ public class CAttackProjectile {
float firstTerm = ((1 / this.halfStartingDistance) * (this.totalTravelDistance - this.halfStartingDistance));
firstTerm = firstTerm * firstTerm;
this.z = this.startingHeight + ((-firstTerm + 1) * this.arcPeakHeight) + dz;
this.arcCurrentHeight = (-firstTerm + 1) * this.arcPeakHeight;
this.z = this.startingHeight + dz;
return this.done;
}
@ -99,4 +101,8 @@ public class CAttackProjectile {
public boolean isDone() {
return this.done;
}
public float getArcCurrentHeight() {
return this.arcCurrentHeight;
}
}