1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-09 08:52:51 +00:00

Created CharacterTemplate object for all classes

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-14 16:39:33 -03:00
parent d8d561688b
commit e886165b89
137 changed files with 6472 additions and 97 deletions

View File

@@ -1,4 +1,6 @@
package com.l2jserver.util;
package com.l2jserver.util.dimensional;
import org.apache.commons.math.geometry.Vector3D;
/**
* Represents an coordinate in the game world.
@@ -8,18 +10,12 @@ package com.l2jserver.util;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Coordinate {
private static final long serialVersionUID = 1L;
/**
* The X point
* The backing vector of this Coordinate
*/
private final int x;
/**
* The Y point
*/
private final int y;
/**
* The Z point
*/
private final int z;
protected final Vector3D vector;
/**
* Creates a new coordinate
@@ -32,30 +28,19 @@ public class Coordinate {
* the z point
*/
protected Coordinate(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
this.vector = new Vector3D(x, y, z);
}
/**
* @return the x point
*/
public int getX() {
return x;
return (int) vector.getX();
}
/**
* @return the y point
*/
public int getY() {
return y;
return (int) vector.getY();
}
/**
* @return the z point
*/
public int getZ() {
return z;
return (int) vector.getZ();
}
/**
@@ -63,12 +48,11 @@ public class Coordinate {
* <tt>other</tt>
*
* @param other
* the other coodinate
* @return the computed distance
* the other coordinate
* @return the calculated distance
*/
public int getDistance(Coordinate other) {
// TODO calculation
return x + y + z;
public double getDistance(Coordinate other) {
return Vector3D.distance(vector, other.vector);
}
/**

View File

@@ -0,0 +1,142 @@
package com.l2jserver.util.dimensional;
import org.apache.commons.math.geometry.Rotation;
/**
* An point is composed of an Coordinate and an angle. The angle represents the
* facing angle of the point, that is, the direction the point is "looking".
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Point {
/**
* The point coordinate
*/
protected final Coordinate coordinate;
/**
* Te point rotation
*/
protected final Rotation rotation;
/**
* Creates a new point
*
* @param coordinate
* the coordinate
* @param angle
* the angle
*/
public Point(Coordinate coordinate, double angle) {
this.coordinate = coordinate;
this.rotation = new Rotation(coordinate.vector, angle);
}
/**
* @return the x
* @see com.l2jserver.util.dimensional.Coordinate#getX()
*/
public int getX() {
return coordinate.getX();
}
/**
* @return the y
* @see com.l2jserver.util.dimensional.Coordinate#getY()
*/
public int getY() {
return coordinate.getY();
}
/**
* @return the z
* @see com.l2jserver.util.dimensional.Coordinate#getZ()
*/
public int getZ() {
return coordinate.getZ();
}
/**
* @param other
* the other coordinate
* @return the distance
* @see com.l2jserver.util.dimensional.Coordinate#getDistance(com.l2jserver.util.dimensional.Coordinate)
*/
public double getDistance(Coordinate other) {
return coordinate.getDistance(other);
}
/**
* @param other
* the other point
* @return the distance
* @see com.l2jserver.util.dimensional.Coordinate#getDistance(com.l2jserver.util.dimensional.Coordinate)
*/
public double getDistance(Point other) {
return coordinate.getDistance(other.coordinate);
}
/**
* @return the angle
* @see org.apache.commons.math.geometry.Rotation#getAngle()
*/
public double getAngle() {
return rotation.getAngle();
}
/**
* @param other
* the other point
* @return the angle difference between the two points
* @see org.apache.commons.math.geometry.Rotation#distance(Rotation,
* Rotation)
*/
public double getAngleDifference(Point other) {
return Rotation.distance(this.rotation, other.rotation);
}
/**
* @return the coordinate
*/
public Coordinate getCoordinate() {
return coordinate;
}
/**
* @return the rotation
*/
public Rotation getRotation() {
return rotation;
}
/**
* Creates a new instance from the 3 points and an angle
*
* @param x
* the x point
* @param y
* the y point
* @param z
* the z point
* @param angle
* the angle
* @return the new {@link Point} object created
*/
public static Point fromXYZA(int x, int y, int z, double angle) {
return new Point(Coordinate.fromXYZ(x, y, z), angle);
}
/**
* Creates a new instance from the 3 points. The angle will be zero.
*
* @param x
* the x point
* @param y
* the y point
* @param z
* the z point
* @return the new {@link Point} object created
*/
public static Point fromXYZ(int x, int y, int z) {
return fromXYZA(x, y, z, 0);
}
}