diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Aeronautics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Aeronautics.java new file mode 100644 index 00000000..494171f5 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Aeronautics.java @@ -0,0 +1,52 @@ +package com.minelittlepony.unicopia.entity.player; + +import net.minecraft.util.math.Vec3d; + +// X - forward +// Y - vertical +// Z - sideways +public class Aeronautics { + + public double rollAngle; + public double pitchAngle; + + /** + * Gets the normalized direction vector + */ + private Vec3d getMomentVector() { + Vec3d bankVector = new Vec3d(0, Math.sin(rollAngle), Math.cos(rollAngle)); + Vec3d climbVector = new Vec3d(Math.cos(pitchAngle), Math.sin(pitchAngle), 0); + + return bankVector.crossProduct(climbVector).normalize(); + } + + /** + * Returns the acceleration vector due to gravity in the direction of + * the incline described by the roll and pitch components. + * + * @param gravity The global gravitation constant C + */ + public Vec3d calcGravitationalAccelleration(double gravity) { + return getMomentVector().multiply(-gravity); + } + + /** + * Gets the added thrust vector for the given forwards motion + * and velocity projected against the direction of incline. + * + * @param forwards The forwards thrust speed + * @param velocity The current motion vector + */ + public Vec3d calcThrustVelocity(double forwards, Vec3d velocity) { + velocity = velocity.normalize().multiply(forwards); + + return getMomentVector().multiply(velocity.x, velocity.y, 0).multiply(getDrag()); + } + + /** + * The drag due to air resistance. + */ + public double getDrag() { + return 0.0078; // magic number until I figure out what tf I'm doing + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java index 8b3e132a..50bafdf7 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -147,22 +147,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti } if (isRainbooming || (entity.isSneaking() && isRainboom())) { - float forward = 0.5F * flightExperience / MAXIMUM_FLIGHT_EXPERIENCE; - - velocity.x += - forward * MathHelper.sin(entity.yaw * 0.017453292F); - velocity.z += forward * MathHelper.cos(entity.yaw * 0.017453292F); - velocity.y += forward * MathHelper.sin(entity.pitch * 0.017453292F); - - if (!isRainbooming || entity.world.random.nextInt(5) == 0) { - entity.playSound(SoundEvents.ENTITY_LIGHTNING_BOLT_THUNDER, 1, 1); - } - - if (flightExperience > 0) { - flightExperience -= 13; - isRainbooming = true; - } else { - isRainbooming = false; - } + performRainboom(entity, velocity); } } @@ -207,6 +192,25 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti return pony.getSpecies() == Race.CHANGELING ? USounds.CHANGELING_BUZZ : USounds.WING_FLAP; } + protected void performRainboom(Entity entity, MutableVector velocity) { + float forward = 0.5F * flightExperience / MAXIMUM_FLIGHT_EXPERIENCE; + + velocity.x += - forward * MathHelper.sin(entity.yaw * 0.017453292F); + velocity.z += forward * MathHelper.cos(entity.yaw * 0.017453292F); + velocity.y += forward * MathHelper.sin(entity.pitch * 0.017453292F); + + if (!isRainbooming || entity.world.random.nextInt(5) == 0) { + entity.playSound(SoundEvents.ENTITY_LIGHTNING_BOLT_THUNDER, 1, 1); + } + + if (flightExperience > 0) { + flightExperience -= 13; + isRainbooming = true; + } else { + isRainbooming = false; + } + } + protected void moveFlying(Entity player, MutableVector velocity) { float forward = 0.000015F * flightExperience * (float)Math.sqrt(getHorizontalMotion(player)); @@ -260,8 +264,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti double motionX = e.getX() - lastTickPosX; double motionZ = e.getZ() - lastTickPosZ; - return (motionX * motionX) - + (motionZ * motionZ); + return (motionX * motionX) + (motionZ * motionZ); } protected SoundEvent getFallSound(int distance) {