feat: /point rm i
This commit is contained in:
parent
6c7f9f2e94
commit
1aa618865c
|
@ -49,6 +49,10 @@ public class Camera extends JavaPlugin implements Listener {
|
|||
int nControlPoints = controlPoints.size();
|
||||
curve = new ArrayList<>();
|
||||
|
||||
if (nControlPoints == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (nControlPoints <= 4) {
|
||||
for (float t = 0; t < 1; t += dt) {
|
||||
ArrayList<Location> P = new ArrayList<>(controlPoints);
|
||||
|
@ -63,25 +67,26 @@ public class Camera extends JavaPlugin implements Listener {
|
|||
|
||||
curve.add(P.get(0));
|
||||
}
|
||||
} else {
|
||||
int nBezier = (nControlPoints - 1) / 3;
|
||||
for (int iBezier = 0; iBezier < nBezier; iBezier++) {
|
||||
for (float t = 0; t < 1; t += dt) {
|
||||
ArrayList<Location> P = new ArrayList<>();
|
||||
for (int k = 0; k < 4; k++) {
|
||||
P.add(controlPoints.get(3 * iBezier + k).clone());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int N = P.size();
|
||||
for (int k = N - 1; k > 0; k--) {
|
||||
for (int i = 0; i < k; i++) {
|
||||
P.set(i, P.get(i).clone().multiply(1 - t)
|
||||
.add(P.get(i + 1).clone().multiply(t)));
|
||||
}
|
||||
}
|
||||
|
||||
curve.add(P.get(0));
|
||||
int nBezier = (nControlPoints - 1) / 3;
|
||||
for (int iBezier = 0; iBezier < nBezier; iBezier++) {
|
||||
for (float t = 0; t < 1; t += dt) {
|
||||
ArrayList<Location> P = new ArrayList<>();
|
||||
for (int k = 0; k < 4; k++) {
|
||||
P.add(controlPoints.get(3 * iBezier + k).clone());
|
||||
}
|
||||
|
||||
int N = P.size();
|
||||
for (int k = N - 1; k > 0; k--) {
|
||||
for (int i = 0; i < k; i++) {
|
||||
P.set(i, P.get(i).clone().multiply(1 - t)
|
||||
.add(P.get(i + 1).clone().multiply(t)));
|
||||
}
|
||||
}
|
||||
|
||||
curve.add(P.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,10 +25,8 @@ public class ClearPoints implements CommandExecutor {
|
|||
ListPoints.listPoints();
|
||||
|
||||
Camera.controlPoints = new ArrayList<>();
|
||||
Camera.broadlog("Points cleared !");
|
||||
|
||||
Camera.curve = new ArrayList<>();
|
||||
Camera.broadlog("Path cleared !");
|
||||
Camera.compute();
|
||||
Camera.broadlog("All cleared !");
|
||||
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
for (Entity e : world.getEntities()) {
|
||||
|
|
|
@ -22,9 +22,6 @@ public class NewPoint implements CommandExecutor {
|
|||
case "add":
|
||||
add(args);
|
||||
break;
|
||||
case "ins":
|
||||
ins(args);
|
||||
break;
|
||||
case "rm":
|
||||
rm(args);
|
||||
break;
|
||||
|
@ -40,9 +37,8 @@ public class NewPoint implements CommandExecutor {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (Camera.controlPoints.size() > 0) {
|
||||
Camera.compute(); // update camera path
|
||||
}
|
||||
// Update camera path
|
||||
Camera.compute();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -58,6 +54,12 @@ public class NewPoint implements CommandExecutor {
|
|||
Camera.broadlog("Point n°" + index + " set: " + Camera.prettyLocation(point));
|
||||
}
|
||||
|
||||
public static void rmPoint(int index) {
|
||||
location = Camera.controlPoints.remove(index);
|
||||
ShowCurve.rm(index);
|
||||
Camera.broadlog("Point deleted: " + Camera.prettyLocation(location));
|
||||
}
|
||||
|
||||
public static void add(String[] args) {
|
||||
World world = player.getWorld();
|
||||
location = player.getLocation();
|
||||
|
@ -77,6 +79,7 @@ public class NewPoint implements CommandExecutor {
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void ins(String[] args) {
|
||||
index = Integer.parseInt(args[1]);
|
||||
location = player.getLocation();
|
||||
|
@ -87,10 +90,25 @@ public class NewPoint implements CommandExecutor {
|
|||
|
||||
public static void rm(String[] args) {
|
||||
index = Integer.parseInt(args[1]);
|
||||
location = Camera.controlPoints.get(index);
|
||||
Camera.controlPoints.remove(location);
|
||||
Camera.broadlog("Point deleted: " + Camera.prettyLocation(location));
|
||||
ShowCurve.rm(index);
|
||||
int n = Camera.controlPoints.size();
|
||||
|
||||
if (n <= 4) {
|
||||
rmPoint(index);
|
||||
return;
|
||||
}
|
||||
|
||||
int indMin;
|
||||
if (index == 0 || index == 1) {
|
||||
indMin = 0;
|
||||
} else if (index == n - 1 || index == n - 2) {
|
||||
indMin = n - 3;
|
||||
} else {
|
||||
indMin = (index - 2) / 3 * 3 + 2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
rmPoint(indMin);
|
||||
}
|
||||
}
|
||||
|
||||
public static void set(String[] args) {
|
||||
|
@ -101,59 +119,61 @@ public class NewPoint implements CommandExecutor {
|
|||
|
||||
if (n <= 4) {
|
||||
setPoint(index, location, world);
|
||||
} else {
|
||||
switch (index % 3) {
|
||||
case 0:
|
||||
// Anchor point
|
||||
Location shift = location.clone().subtract(Camera.controlPoints.get(index));
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
setPoint(index + i - 1, Camera.controlPoints.get(index + i - 1).clone().add(shift), world);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// First or last anchor
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
// Control point after an anchor
|
||||
if (index - 2 >= 0) {
|
||||
// Get anchor-location direction
|
||||
Location anchor = Camera.controlPoints.get(index - 1);
|
||||
double currentDistance = anchor.distance(location);
|
||||
Location currentVect = anchor.clone().subtract(location).multiply(1 / currentDistance);
|
||||
|
||||
// Get anchor-corresponding distance
|
||||
Location correspondingControl = Camera.controlPoints.get(index - 2);
|
||||
double correspondingDistance = anchor.distance(correspondingControl);
|
||||
|
||||
// Keep correcponding at the same distance
|
||||
// but along the anchor-location direction
|
||||
setPoint(index - 2, anchor.clone().add(currentVect.multiply(correspondingDistance)), world);
|
||||
}
|
||||
// Move control point
|
||||
setPoint(index, location, world);
|
||||
break;
|
||||
case 2:
|
||||
// Control point before an anchor
|
||||
if (index + 2 < n) {
|
||||
// Get anchor-location direction
|
||||
Location anchor = Camera.controlPoints.get(index + 1);
|
||||
double currentDistance = anchor.distance(location);
|
||||
Location currentVect = anchor.clone().subtract(location).multiply(1 / currentDistance);
|
||||
|
||||
// Get anchor-corresponding distance
|
||||
Location correspondingControl = Camera.controlPoints.get(index + 2);
|
||||
double correspondingDistance = anchor.distance(correspondingControl);
|
||||
|
||||
// Keep correcponding at the same distance
|
||||
// but along the anchor-location direction
|
||||
setPoint(index + 2, anchor.clone().add(currentVect.multiply(correspondingDistance)), world);
|
||||
}
|
||||
// Move control point
|
||||
setPoint(index, location, world);
|
||||
break;
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
switch (index % 3) {
|
||||
case 0:
|
||||
// Anchor point
|
||||
Location shift = location.clone().subtract(Camera.controlPoints.get(index));
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
setPoint(index + i - 1, Camera.controlPoints.get(index + i - 1).clone().add(shift), world);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// First or last anchor
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
// Control point after an anchor
|
||||
if (index - 2 >= 0) {
|
||||
// Get anchor-location direction
|
||||
Location anchor = Camera.controlPoints.get(index - 1);
|
||||
double currentDistance = anchor.distance(location);
|
||||
Location currentVect = anchor.clone().subtract(location).multiply(1 / currentDistance);
|
||||
|
||||
// Get anchor-corresponding distance
|
||||
Location correspondingControl = Camera.controlPoints.get(index - 2);
|
||||
double correspondingDistance = anchor.distance(correspondingControl);
|
||||
|
||||
// Keep correcponding at the same distance
|
||||
// but along the anchor-location direction
|
||||
setPoint(index - 2, anchor.clone().add(currentVect.multiply(correspondingDistance)), world);
|
||||
}
|
||||
// Move control point
|
||||
setPoint(index, location, world);
|
||||
break;
|
||||
case 2:
|
||||
// Control point before an anchor
|
||||
if (index + 2 < n) {
|
||||
// Get anchor-location direction
|
||||
Location anchor = Camera.controlPoints.get(index + 1);
|
||||
double currentDistance = anchor.distance(location);
|
||||
Location currentVect = anchor.clone().subtract(location).multiply(1 / currentDistance);
|
||||
|
||||
// Get anchor-corresponding distance
|
||||
Location correspondingControl = Camera.controlPoints.get(index + 2);
|
||||
double correspondingDistance = anchor.distance(correspondingControl);
|
||||
|
||||
// Keep correcponding at the same distance
|
||||
// but along the anchor-location direction
|
||||
setPoint(index + 2, anchor.clone().add(currentVect.multiply(correspondingDistance)), world);
|
||||
}
|
||||
// Move control point
|
||||
setPoint(index, location, world);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue