From c4a2093d9a350c135c1702d7df24308be873e558 Mon Sep 17 00:00:00 2001 From: Adraas Date: Sun, 22 Sep 2019 21:34:15 +0400 Subject: [PATCH 01/14] feat(server side): add a new ignore case for the Git --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 75cb4b76..94e57207 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.idea/* + ServerSide/.idea/* ServerSide/*.iml From 2f81bc8c0512eac0752077ac9a33a9b703096dbb Mon Sep 17 00:00:00 2001 From: Adraas Date: Sun, 22 Sep 2019 21:36:10 +0400 Subject: [PATCH 02/14] refactor(server side): delete an unnecessary component --- .../gameserver/ecs/ComponentManagerImpl.java | 1 - .../ecs/components/ComponentType.java | 1 - .../gameserver/ecs/components/Direction.java | 27 ------------------- 3 files changed, 29 deletions(-) delete mode 100644 ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/components/Direction.java diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/ComponentManagerImpl.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/ComponentManagerImpl.java index b74b1acf..3f69e8ba 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/ComponentManagerImpl.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/ComponentManagerImpl.java @@ -29,7 +29,6 @@ public ComponentManagerImpl() { components.put(ComponentType.MASS_COMPONENT, new Mass()); components.put(ComponentType.HEALTH_COMPONENT, new Health()); components.put(ComponentType.LOCATION_COMPONENT, new Location()); - components.put(ComponentType.DIRECTION_COMPONENT, new Direction()); components.put(ComponentType.SPEED_COMPONENT, new Speed()); } diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/components/ComponentType.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/components/ComponentType.java index d75b6ad6..1b661705 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/components/ComponentType.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/components/ComponentType.java @@ -20,6 +20,5 @@ public enum ComponentType { HEALTH_COMPONENT, LOCATION_COMPONENT, MASS_COMPONENT, - DIRECTION_COMPONENT, SPEED_COMPONENT } diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/components/Direction.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/components/Direction.java deleted file mode 100644 index aea9658a..00000000 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/components/Direction.java +++ /dev/null @@ -1,27 +0,0 @@ -package ru.servers.gameserver.ecs.components; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import ru.servers.gameserver.math.algebra.vectors.Vector3; - -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -public class Direction implements Component { - - private Vector3 route; - - @Override - public Direction clone() { - try { - return (Direction)super.clone(); - } - catch (CloneNotSupportedException e) { - throw new InternalError(); - } - } - -} From 734ca21915c143201158b2b9b0ec45d9c1d44833 Mon Sep 17 00:00:00 2001 From: Adraas Date: Mon, 23 Sep 2019 20:36:53 +0400 Subject: [PATCH 03/14] refactor(server side): rename method The method getComponents was renamed to getIteratorComponents. --- .../main/java/ru/servers/gameserver/ecs/entities/Entity.java | 2 +- .../main/java/ru/servers/gameserver/ecs/entities/Vehicle.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Entity.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Entity.java index 8dd751bb..db3b43f9 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Entity.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Entity.java @@ -30,7 +30,7 @@ public interface Entity { Iterator> getComponents(); - int getCountComponents(); + public abstract Iterator> getIteratorComponents(); void removeComponent(ComponentType componentType); diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java index c202934e..7473c587 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java @@ -44,8 +44,8 @@ public Component getComponent(ComponentType componentType) { } @Override - public Iterator> getComponents() { - return components.entrySet().iterator(); + public Iterator> getIteratorComponents() { + return getComponents().entrySet().iterator(); } @Override From f951c9d8c4a17ea442f60582681e6fb90d9d265a Mon Sep 17 00:00:00 2001 From: Adraas Date: Mon, 23 Sep 2019 20:44:15 +0400 Subject: [PATCH 04/14] feat(server side): add metadata as parameters for enums --- .../gameserver/ecs/components/ComponentType.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/components/ComponentType.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/components/ComponentType.java index 1b661705..2f331c71 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/components/ComponentType.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/components/ComponentType.java @@ -16,9 +16,17 @@ package ru.servers.gameserver.ecs.components; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter public enum ComponentType { - HEALTH_COMPONENT, - LOCATION_COMPONENT, - MASS_COMPONENT, - SPEED_COMPONENT + + HEALTH_COMPONENT(Health.class), + LOCATION_COMPONENT(Location.class), + MASS_COMPONENT(Mass.class), + SPEED_COMPONENT(Speed.class); + + private Class componentClass; } From 924cf4780c72dc83d49729f6682c82f3f360dd85 Mon Sep 17 00:00:00 2001 From: Adraas Date: Mon, 23 Sep 2019 20:57:56 +0400 Subject: [PATCH 05/14] feat(server side): add checking for the types --- .../main/java/ru/servers/gameserver/ecs/entities/Entity.java | 4 +++- .../main/java/ru/servers/gameserver/ecs/entities/Vehicle.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Entity.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Entity.java index db3b43f9..51c4a209 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Entity.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Entity.java @@ -24,7 +24,9 @@ public interface Entity { - void addComponent(ComponentType componentType, Component component); + protected boolean componentTypeIsCorrect(ComponentType componentType, Component component) { + return componentType.getComponentClass().equals(component.getClass()); + } Component getComponent(ComponentType componentType); diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java index 7473c587..8aa35473 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java @@ -35,7 +35,9 @@ public class Vehicle implements Entity{ @Override public void addComponent(ComponentType componentType, Component component) { - components.put(componentType, component); + if (componentTypeIsCorrect(componentType, component)) { + getComponents().put(componentType, component); + } } @Override From d48aa82613850636c70a1f4a8307e3202c253dd0 Mon Sep 17 00:00:00 2001 From: Adraas Date: Mon, 23 Sep 2019 20:59:09 +0400 Subject: [PATCH 06/14] refactor(server side): make Entity as abstract class The Entity now is an abstract class with the stateful. --- .../gameserver/ecs/entities/Entity.java | 20 +++++++++++++++---- .../gameserver/ecs/entities/Vehicle.java | 18 +++++++---------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Entity.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Entity.java index 51c4a209..dd7f8bfd 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Entity.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Entity.java @@ -16,24 +16,36 @@ package ru.servers.gameserver.ecs.entities; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; import ru.servers.gameserver.ecs.components.Component; import ru.servers.gameserver.ecs.components.ComponentType; import java.util.Iterator; import java.util.Map; -public interface Entity { +@AllArgsConstructor +@Getter +@ToString +@EqualsAndHashCode +public abstract class Entity { + + private Map components; protected boolean componentTypeIsCorrect(ComponentType componentType, Component component) { return componentType.getComponentClass().equals(component.getClass()); } - Component getComponent(ComponentType componentType); + public abstract void addComponent(ComponentType componentType, Component component); - Iterator> getComponents(); + public abstract Component getComponent(ComponentType componentType); public abstract Iterator> getIteratorComponents(); - void removeComponent(ComponentType componentType); + public abstract int getCountComponents(); + + public abstract void removeComponent(ComponentType componentType); } diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java index 8aa35473..474ed72c 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java @@ -16,9 +16,6 @@ package ru.servers.gameserver.ecs.entities; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -import lombok.ToString; import ru.servers.gameserver.ecs.components.Component; import ru.servers.gameserver.ecs.components.ComponentType; @@ -26,12 +23,11 @@ import java.util.Iterator; import java.util.Map; -@ToString -@EqualsAndHashCode -@NoArgsConstructor -public class Vehicle implements Entity{ +public class Vehicle extends Entity{ - private Map components = new HashMap<>(); + public Vehicle() { + super(new HashMap<>()); + } @Override public void addComponent(ComponentType componentType, Component component) { @@ -42,7 +38,7 @@ public void addComponent(ComponentType componentType, Component component) { @Override public Component getComponent(ComponentType componentType) { - return components.get(componentType); + return getComponents().get(componentType); } @Override @@ -52,12 +48,12 @@ public Iterator> getIteratorComponents() { @Override public int getCountComponents() { - return components.size(); + return getComponents().size(); } @Override public void removeComponent(ComponentType componentType) { - components.remove(componentType); + getComponents().remove(componentType); } } From f053b6977622f116f4de8c8af97af686bab85370 Mon Sep 17 00:00:00 2001 From: Adraas Date: Mon, 23 Sep 2019 21:12:09 +0400 Subject: [PATCH 07/14] feat(server side): implement the MoveSystem as the System --- .../main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java index b9f164d9..1dd6053f 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java @@ -16,4 +16,4 @@ package ru.servers.gameserver.ecs.systems; -public class MoveSystem { } +public class MoveSystem implements System { } From 33c0b8e3d839fece6d090b612413e1f85d39865b Mon Sep 17 00:00:00 2001 From: Adraas Date: Mon, 23 Sep 2019 21:15:10 +0400 Subject: [PATCH 08/14] style(server side): add the missed whitespace --- .../main/java/ru/servers/gameserver/ecs/entities/Vehicle.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java index 474ed72c..6ecc44a5 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/entities/Vehicle.java @@ -23,7 +23,7 @@ import java.util.Iterator; import java.util.Map; -public class Vehicle extends Entity{ +public class Vehicle extends Entity { public Vehicle() { super(new HashMap<>()); From cc3a8becf65e5945d4143fde16a771d792704bc6 Mon Sep 17 00:00:00 2001 From: Adraas Date: Sat, 28 Sep 2019 12:24:48 +0400 Subject: [PATCH 09/14] feat(server side): add abstract functional definition for the System --- .../ru/servers/gameserver/ecs/systems/System.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/System.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/System.java index 9eb58891..d764a20f 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/System.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/System.java @@ -16,4 +16,16 @@ package ru.servers.gameserver.ecs.systems; -public interface System { } +import ru.servers.gameserver.ecs.entities.Entity; + +import java.util.HashSet; +import java.util.Set; + +public interface System { + + Set entities = new HashSet<>(); + + void execute(long milliseconds); + + Set getFilteredEntities(); +} From d2314e12411240a0e27c82766cfabec5a1b44bdd Mon Sep 17 00:00:00 2001 From: Adraas Date: Sat, 28 Sep 2019 12:26:29 +0400 Subject: [PATCH 10/14] feat(server side): add System functional implementation The System functional implementation for the MoveSystem class was added with a some omission. --- .../gameserver/ecs/systems/MoveSystem.java | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java index 1dd6053f..4453e949 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java @@ -16,4 +16,64 @@ package ru.servers.gameserver.ecs.systems; -public class MoveSystem implements System { } +import ru.servers.gameserver.ecs.components.Component; +import ru.servers.gameserver.ecs.components.ComponentType; +import ru.servers.gameserver.ecs.components.Location; +import ru.servers.gameserver.ecs.components.Speed; +import ru.servers.gameserver.ecs.entities.Entity; +import ru.servers.gameserver.math.algebra.vectors.Vector3; +import ru.servers.gameserver.math.algebra.vectors.VectorsUtil; + +import java.util.Set; +import java.util.stream.Collectors; + +public class MoveSystem implements System { + + @Override + public void execute(long milliseconds) { + getFilteredEntities() + .forEach(entity -> { + Speed speed = (Speed) entity.getComponent(ComponentType.SPEED_COMPONENT); + Location location = (Location) entity.getComponent(ComponentType.LOCATION_COMPONENT); + double angleWithXVector = VectorsUtil.getAngleBetweenVectors(location.getDirection(), + new Vector3(location.getDirection().getX(), 0, 0)); + double angleWithYVector = VectorsUtil.getAngleBetweenVectors(location.getDirection(), + new Vector3(0, location.getDirection().getY(), 0)); + double angleWithZVector = VectorsUtil.getAngleBetweenVectors(location.getDirection(), + new Vector3(0, 0, location.getDirection().getZ())); + double oldSpeed = speed.getSpeed(); + speed.setSpeed(speed.getSpeed() + speed.getAcceleration() * milliseconds); + double distanceX = getDistanceByAxis(angleWithXVector, speed, oldSpeed); + double distanceY = getDistanceByAxis(angleWithYVector, speed, oldSpeed); + double distanceZ = getDistanceByAxis(angleWithZVector, speed, oldSpeed); + Vector3 deltaPositionVector3 = new Vector3(distanceX, distanceY, distanceZ); + Vector3 deltaDirectionVector3 = location.getPosition(); + deltaDirectionVector3.sub(location.getDirection()); + double angleForDeltaPositionVector = + VectorsUtil.getAngleBetweenVectors(deltaPositionVector3, deltaDirectionVector3); + // TODO: rotation for the deltaPositionVector3 by means angleForDeltaPositionVector + deltaDirectionVector3.add(deltaDirectionVector3); + deltaDirectionVector3.add(deltaPositionVector3); + location.getDirection().add(deltaDirectionVector3); + }); + } + + @Override + public Set getFilteredEntities() { + return System.entities.stream() + .filter(entity -> { + Component component = entity.getComponent(ComponentType.SPEED_COMPONENT); + if (component != null) { + return ((Speed) component).getSpeed() != 0; + } + return false; + }) + .collect(Collectors.toSet()); + } + + private double getDistanceByAxis(double angleWithSpecifyVector, Speed speed, double oldSpeed) { + return (Math.pow(Math.cos(angleWithSpecifyVector) * speed.getSpeed(), 2) + - Math.pow(Math.cos(angleWithSpecifyVector) * oldSpeed, 2)) + / (2 * speed.getAcceleration()); + } +} From 6aae78646dcef3df5c39b64309293512b2e7d4e0 Mon Sep 17 00:00:00 2001 From: Adraas Date: Sun, 29 Sep 2019 12:14:43 +0400 Subject: [PATCH 11/14] refactor(server side): delete wrong action --- .../main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java | 1 - 1 file changed, 1 deletion(-) diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java index 4453e949..8f5e9b4e 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java @@ -52,7 +52,6 @@ public void execute(long milliseconds) { double angleForDeltaPositionVector = VectorsUtil.getAngleBetweenVectors(deltaPositionVector3, deltaDirectionVector3); // TODO: rotation for the deltaPositionVector3 by means angleForDeltaPositionVector - deltaDirectionVector3.add(deltaDirectionVector3); deltaDirectionVector3.add(deltaPositionVector3); location.getDirection().add(deltaDirectionVector3); }); From 1b6ca06f90c8e3d2124284cdce6396b22cfd25b6 Mon Sep 17 00:00:00 2001 From: Adraas Date: Sun, 29 Sep 2019 12:30:02 +0400 Subject: [PATCH 12/14] perf(server side): delete unnecessary intermediate variables --- .../gameserver/ecs/systems/MoveSystem.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java index 8f5e9b4e..f9b9228e 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java @@ -35,18 +35,16 @@ public void execute(long milliseconds) { .forEach(entity -> { Speed speed = (Speed) entity.getComponent(ComponentType.SPEED_COMPONENT); Location location = (Location) entity.getComponent(ComponentType.LOCATION_COMPONENT); - double angleWithXVector = VectorsUtil.getAngleBetweenVectors(location.getDirection(), - new Vector3(location.getDirection().getX(), 0, 0)); - double angleWithYVector = VectorsUtil.getAngleBetweenVectors(location.getDirection(), - new Vector3(0, location.getDirection().getY(), 0)); - double angleWithZVector = VectorsUtil.getAngleBetweenVectors(location.getDirection(), - new Vector3(0, 0, location.getDirection().getZ())); double oldSpeed = speed.getSpeed(); speed.setSpeed(speed.getSpeed() + speed.getAcceleration() * milliseconds); - double distanceX = getDistanceByAxis(angleWithXVector, speed, oldSpeed); - double distanceY = getDistanceByAxis(angleWithYVector, speed, oldSpeed); - double distanceZ = getDistanceByAxis(angleWithZVector, speed, oldSpeed); - Vector3 deltaPositionVector3 = new Vector3(distanceX, distanceY, distanceZ); + Vector3 deltaPositionVector3 = new Vector3( + getDistanceByAxis(VectorsUtil.getAngleBetweenVectors(location.getDirection(), + new Vector3(location.getDirection().getX(), 0, 0)), speed, oldSpeed), + getDistanceByAxis(VectorsUtil.getAngleBetweenVectors(location.getDirection(), + new Vector3(0, location.getDirection().getY(), 0)), speed, oldSpeed), + getDistanceByAxis(VectorsUtil.getAngleBetweenVectors(location.getDirection(), + new Vector3(0, 0, location.getDirection().getZ())), speed, oldSpeed) + ); Vector3 deltaDirectionVector3 = location.getPosition(); deltaDirectionVector3.sub(location.getDirection()); double angleForDeltaPositionVector = From af8929eb0e9da3b0e54a984bb1cc3ad7dc0eb4da Mon Sep 17 00:00:00 2001 From: Adraas Date: Sun, 29 Sep 2019 15:51:44 +0400 Subject: [PATCH 13/14] fix(server side): change assignment to creating Now the new Vector3 object is created by means the old Vector3 object data. --- .../java/ru/servers/gameserver/ecs/systems/MoveSystem.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java index f9b9228e..3e74838a 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java @@ -45,7 +45,11 @@ public void execute(long milliseconds) { getDistanceByAxis(VectorsUtil.getAngleBetweenVectors(location.getDirection(), new Vector3(0, 0, location.getDirection().getZ())), speed, oldSpeed) ); - Vector3 deltaDirectionVector3 = location.getPosition(); + Vector3 deltaDirectionVector3 = new Vector3( + location.getPosition().getX(), + location.getPosition().getY(), + location.getPosition().getZ() + ); deltaDirectionVector3.sub(location.getDirection()); double angleForDeltaPositionVector = VectorsUtil.getAngleBetweenVectors(deltaPositionVector3, deltaDirectionVector3); From 72db7987a01c913108aa16d6e64c48c06ed8d49d Mon Sep 17 00:00:00 2001 From: Adraas Date: Sun, 29 Sep 2019 15:55:07 +0400 Subject: [PATCH 14/14] feat(server side): implement the vector rotation --- .../gameserver/ecs/systems/MoveSystem.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java index 3e74838a..4a44be6f 100644 --- a/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java +++ b/ServerSide/gameserver/src/main/java/ru/servers/gameserver/ecs/systems/MoveSystem.java @@ -21,6 +21,7 @@ import ru.servers.gameserver.ecs.components.Location; import ru.servers.gameserver.ecs.components.Speed; import ru.servers.gameserver.ecs.entities.Entity; +import ru.servers.gameserver.math.algebra.Quaternion; import ru.servers.gameserver.math.algebra.vectors.Vector3; import ru.servers.gameserver.math.algebra.vectors.VectorsUtil; @@ -51,9 +52,8 @@ public void execute(long milliseconds) { location.getPosition().getZ() ); deltaDirectionVector3.sub(location.getDirection()); - double angleForDeltaPositionVector = - VectorsUtil.getAngleBetweenVectors(deltaPositionVector3, deltaDirectionVector3); - // TODO: rotation for the deltaPositionVector3 by means angleForDeltaPositionVector + deltaPositionVector3 = rotateVector(deltaPositionVector3, + VectorsUtil.getAngleBetweenVectors(deltaPositionVector3, deltaDirectionVector3)); deltaDirectionVector3.add(deltaPositionVector3); location.getDirection().add(deltaDirectionVector3); }); @@ -77,4 +77,16 @@ private double getDistanceByAxis(double angleWithSpecifyVector, Speed speed, dou - Math.pow(Math.cos(angleWithSpecifyVector) * oldSpeed, 2)) / (2 * speed.getAcceleration()); } + + private Vector3 rotateVector(Vector3 vector3, double angle) { + Quaternion quaternion = new Quaternion(Math.cos(angle / 2), vector3); + Vector3 reversedVector3 = new Vector3(vector3.getX(), vector3.getY(), vector3.getZ()); + reversedVector3.mul(-1); + Quaternion conjugatedQuaternion = new Quaternion(quaternion.getW(), reversedVector3); + double normal = Math.pow(vector3.getX(), 2) + Math.pow(vector3.getY(), 2) + Math.pow(vector3.getZ(), 2); + conjugatedQuaternion.mul(1 / normal); + quaternion.mul(new Quaternion(0, vector3)); + quaternion.mul(conjugatedQuaternion); + return quaternion.getVector(); + } }