Convert newer API from radians to degrees.

This commit is contained in:
sk89q 2014-07-15 20:10:14 -07:00
parent 9b5c112e5c
commit 9feafcfc30
12 changed files with 36 additions and 35 deletions

View File

@ -78,8 +78,8 @@ final class BukkitAdapter {
return new com.sk89q.worldedit.util.Location( return new com.sk89q.worldedit.util.Location(
adapt(location.getWorld()), adapt(location.getWorld()),
position, position,
(float) Math.toRadians(location.getYaw()), location.getYaw(),
(float) Math.toRadians(location.getPitch())); location.getPitch());
} }
/** /**
@ -94,8 +94,8 @@ final class BukkitAdapter {
return new org.bukkit.Location( return new org.bukkit.Location(
adapt((World) location.getExtent()), adapt((World) location.getExtent()),
position.getX(), position.getY(), position.getZ(), position.getX(), position.getY(), position.getZ(),
(float) Math.toDegrees(location.getYaw()), location.getYaw(),
(float) Math.toDegrees(location.getPitch())); location.getPitch());
} }
/** /**
@ -126,8 +126,8 @@ final class BukkitAdapter {
return new org.bukkit.Location( return new org.bukkit.Location(
world, world,
location.getX(), location.getY(), location.getZ(), location.getX(), location.getY(), location.getZ(),
(float) Math.toDegrees(location.getYaw()), location.getYaw(),
(float) Math.toDegrees(location.getPitch())); location.getPitch());
} }
/** /**

View File

@ -183,8 +183,8 @@ public class BukkitPlayer extends LocalPlayer {
return new com.sk89q.worldedit.util.Location( return new com.sk89q.worldedit.util.Location(
getWorld(), getWorld(),
position, position,
(float) Math.toRadians(nativeLocation.getYaw()), nativeLocation.getYaw(),
(float) Math.toRadians(nativeLocation.getPitch())); nativeLocation.getPitch());
} }
@Nullable @Nullable

View File

@ -65,8 +65,8 @@ class ForgeEntity implements Entity {
@Override @Override
public Location getLocation() { public Location getLocation() {
Vector position = new Vector(entity.posX, entity.posY, entity.posZ); Vector position = new Vector(entity.posX, entity.posY, entity.posZ);
float yaw = (float) Math.toRadians(entity.rotationYaw); float yaw = entity.rotationYaw;
float pitch = (float) Math.toRadians(entity.rotationPitch); float pitch = entity.rotationPitch;
return new Location(ForgeAdapter.adapt(entity.worldObj), position, yaw, pitch); return new Location(ForgeAdapter.adapt(entity.worldObj), position, yaw, pitch);
} }

View File

@ -63,8 +63,8 @@ public class ForgePlayer extends AbstractPlayerActor {
return new Location( return new Location(
ForgeWorldEdit.inst.getWorld(this.player.worldObj), ForgeWorldEdit.inst.getWorld(this.player.worldObj),
position, position,
(float) Math.toRadians(this.player.cameraYaw), this.player.cameraYaw,
(float) Math.toRadians(this.player.cameraPitch)); this.player.cameraPitch);
} }
public WorldVector getPosition() { public WorldVector getPosition() {

View File

@ -414,7 +414,7 @@ public class ForgeWorld extends AbstractWorld {
createdEntity.readFromNBT(tag); createdEntity.readFromNBT(tag);
} }
createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), (float) Math.toDegrees(location.getYaw()), (float) Math.toDegrees(location.getPitch())); createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
world.spawnEntityInWorld(createdEntity); world.spawnEntityInWorld(createdEntity);
return new ForgeEntity(createdEntity); return new ForgeEntity(createdEntity);

View File

@ -600,8 +600,7 @@ public class Vector implements Comparable<Vector> {
* @param translateZ what to add after rotation * @param translateZ what to add after rotation
* @return * @return
*/ */
public Vector transform2D(double angle, public Vector transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
double aboutX, double aboutZ, double translateX, double translateZ) {
angle = Math.toRadians(angle); angle = Math.toRadians(angle);
double x = this.x - aboutX; double x = this.x - aboutX;
double z = this.z - aboutZ; double z = this.z - aboutZ;
@ -667,7 +666,7 @@ public class Vector implements Comparable<Vector> {
double x2 = x * x; double x2 = x * x;
double z2 = z * z; double z2 = z * z;
double xz = Math.sqrt(x2 + z2); double xz = Math.sqrt(x2 + z2);
return (float) Math.atan(-getY() / xz); return (float) Math.toDegrees(Math.atan(-getY() / xz));
} }
} }
@ -683,7 +682,7 @@ public class Vector implements Comparable<Vector> {
double t = Math.atan2(-x, z); double t = Math.atan2(-x, z);
double _2pi = 2 * Math.PI; double _2pi = 2 * Math.PI;
return (float) ((t + _2pi) % _2pi); return (float) Math.toDegrees(((t + _2pi) % _2pi));
} }
/** /**

View File

@ -517,8 +517,7 @@ public class Vector2D {
* @param translateZ what to add after rotation * @param translateZ what to add after rotation
* @return * @return
*/ */
public Vector2D transform2D(double angle, public Vector2D transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
double aboutX, double aboutZ, double translateX, double translateZ) {
angle = Math.toRadians(angle); angle = Math.toRadians(angle);
double x = this.x - aboutX; double x = this.x - aboutX;
double z = this.z - aboutZ; double z = this.z - aboutZ;

View File

@ -190,9 +190,9 @@ public class ClipboardCommands {
ClipboardHolder holder = session.getClipboard(); ClipboardHolder holder = session.getClipboard();
AffineTransform transform = new AffineTransform(); AffineTransform transform = new AffineTransform();
transform = transform.rotateY(-Math.toRadians(yRotate != null ? yRotate : 0)); transform = transform.rotateY(-(yRotate != null ? yRotate : 0));
transform = transform.rotateX(-Math.toRadians(xRotate != null ? xRotate : 0)); transform = transform.rotateX(-(xRotate != null ? xRotate : 0));
transform = transform.rotateZ(-Math.toRadians(zRotate != null ? zRotate : 0)); transform = transform.rotateZ(-(zRotate != null ? zRotate : 0));
holder.setTransform(holder.getTransform().combine(transform)); holder.setTransform(holder.getTransform().combine(transform));
player.print("The clipboard copy has been rotated."); player.print("The clipboard copy has been rotated.");
} }

View File

@ -206,8 +206,8 @@ public class SchematicWriter implements ClipboardWriter {
private Tag writeRotation(Location location, String name) { private Tag writeRotation(Location location, String name) {
List<FloatTag> list = new ArrayList<FloatTag>(); List<FloatTag> list = new ArrayList<FloatTag>();
list.add(new FloatTag("", (float) Math.toDegrees(location.getYaw()))); list.add(new FloatTag("", location.getYaw()));
list.add(new FloatTag("", (float) Math.toDegrees(location.getPitch()))); list.add(new FloatTag("", location.getPitch()));
return new ListTag(name, FloatTag.class, list); return new ListTag(name, FloatTag.class, list);
} }

View File

@ -244,6 +244,7 @@ public class AffineTransform implements Transform {
} }
public AffineTransform rotateX(double theta) { public AffineTransform rotateX(double theta) {
theta = Math.toRadians(theta);
double cot = Math.cos(theta); double cot = Math.cos(theta);
double sit = Math.sin(theta); double sit = Math.sin(theta);
return concatenate( return concatenate(
@ -254,6 +255,7 @@ public class AffineTransform implements Transform {
} }
public AffineTransform rotateY(double theta) { public AffineTransform rotateY(double theta) {
theta = Math.toRadians(theta);
double cot = Math.cos(theta); double cot = Math.cos(theta);
double sit = Math.sin(theta); double sit = Math.sin(theta);
return concatenate( return concatenate(
@ -264,6 +266,7 @@ public class AffineTransform implements Transform {
} }
public AffineTransform rotateZ(double theta) { public AffineTransform rotateZ(double theta) {
theta = Math.toRadians(theta);
double cot = Math.cos(theta); double cot = Math.cos(theta);
double sit = Math.sin(theta); double sit = Math.sin(theta);
return concatenate( return concatenate(

View File

@ -97,8 +97,8 @@ public class Location {
* @param x the X coordinate * @param x the X coordinate
* @param y the Y coordinate * @param y the Y coordinate
* @param z the Z coordinate * @param z the Z coordinate
* @param yaw the yaw, in radians * @param yaw the yaw, in degrees
* @param pitch the pitch, in radians * @param pitch the pitch, in degrees
*/ */
public Location(Extent extent, double x, double y, double z, float yaw, float pitch) { public Location(Extent extent, double x, double y, double z, float yaw, float pitch) {
this(extent, new Vector(x, y, z), yaw, pitch); this(extent, new Vector(x, y, z), yaw, pitch);
@ -122,8 +122,8 @@ public class Location {
* *
* @param extent the extent * @param extent the extent
* @param position the position vector * @param position the position vector
* @param yaw the yaw, in radians * @param yaw the yaw, in degrees
* @param pitch the pitch, in radians * @param pitch the pitch, in degrees
*/ */
public Location(Extent extent, Vector position, float yaw, float pitch) { public Location(Extent extent, Vector position, float yaw, float pitch) {
checkNotNull(extent); checkNotNull(extent);
@ -154,9 +154,9 @@ public class Location {
} }
/** /**
* Get the yaw in radians. * Get the yaw in degrees.
* *
* @return the yaw in radians * @return the yaw in degrees
*/ */
public float getYaw() { public float getYaw() {
return yaw; return yaw;
@ -173,9 +173,9 @@ public class Location {
} }
/** /**
* Get the pitch in radians. * Get the pitch in degrees.
* *
* @return the pitch in radians * @return the pitch in degrees
*/ */
public float getPitch() { public float getPitch() {
return pitch; return pitch;
@ -208,8 +208,8 @@ public class Location {
* @return the direction vector * @return the direction vector
*/ */
public Vector getDirection() { public Vector getDirection() {
double yaw = this.getYaw(); double yaw = Math.toRadians(this.getYaw());
double pitch = this.getPitch(); double pitch = Math.toRadians(this.getPitch());
double xz = Math.cos(pitch); double xz = Math.cos(pitch);
return new Vector( return new Vector(
-xz * Math.sin(yaw), -xz * Math.sin(yaw),

View File

@ -52,7 +52,7 @@ public final class NBTConversions {
return new Location( return new Location(
extent, extent,
positionTag.asDouble(0), positionTag.asDouble(1), positionTag.asDouble(2), positionTag.asDouble(0), positionTag.asDouble(1), positionTag.asDouble(2),
((float) Math.toRadians(directionTag.asDouble(0))), ((float) Math.toRadians(directionTag.asDouble(1)))); (float) directionTag.asDouble(0), (float) directionTag.asDouble(1));
} }
} }