diff --git a/imgui.ini b/imgui.ini index 27f0bc4..77f2593 100644 --- a/imgui.ini +++ b/imgui.ini @@ -21,7 +21,7 @@ Collapsed=0 [Window][Scene outliner] Pos=1467,39 -Size=453,1039 +Size=453,580 Collapsed=0 DockId=0x00000004,0 @@ -31,14 +31,14 @@ Size=709,885 Collapsed=0 [Window][Content browser] -Pos=0,549 -Size=1465,529 +Pos=0,758 +Size=1465,320 Collapsed=0 DockId=0x00000005,0 [Window][component inspector] -Pos=1467,608 -Size=453,447 +Pos=1467,621 +Size=453,457 Collapsed=0 DockId=0x00000006,0 @@ -75,7 +75,7 @@ Collapsed=0 [Window][viewport] Pos=0,39 -Size=1465,508 +Size=1465,717 Collapsed=0 DockId=0x00000003,0 @@ -116,7 +116,7 @@ Collapsed=0 [Window][HUD Window] Pos=-4,-4 -Size=1928,1065 +Size=1928,1088 Collapsed=0 [Window][Test Window] @@ -268,7 +268,7 @@ Collapsed=0 [Window][Level properties] Pos=1467,39 -Size=453,1039 +Size=453,580 Collapsed=0 DockId=0x00000004,1 @@ -336,7 +336,7 @@ Collapsed=0 [Window][Console] Pos=1467,39 -Size=453,1039 +Size=453,580 Collapsed=0 DockId=0x00000004,2 @@ -863,10 +863,10 @@ Collapsed=0 [Docking][Data] DockNode ID=0x00000007 Pos=581,216 Size=620,657 Selected=0xA80D9FF3 DockNode ID=0x0000000A Pos=270,302 Size=836,688 Selected=0xED1E1CDE -DockSpace ID=0x05CF85F3 Pos=0,39 Size=1920,1039 Split=X Selected=0x3B8B7B67 +DockSpace ID=0x05CF85F3 Window=0xD4F6B0F2 Pos=0,39 Size=1920,1039 Split=X Selected=0x3B8B7B67 DockNode ID=0x00000001 Parent=0x05CF85F3 SizeRef=1465,1019 Split=Y Selected=0x602D6EAE - DockNode ID=0x00000003 Parent=0x00000001 SizeRef=1520,508 CentralNode=1 HiddenTabBar=1 Selected=0x602D6EAE - DockNode ID=0x00000005 Parent=0x00000001 SizeRef=1520,529 HiddenTabBar=1 Selected=0xF8AE6B2B + DockNode ID=0x00000003 Parent=0x00000001 SizeRef=1520,717 CentralNode=1 HiddenTabBar=1 Selected=0x602D6EAE + DockNode ID=0x00000005 Parent=0x00000001 SizeRef=1520,320 HiddenTabBar=1 Selected=0xF8AE6B2B DockNode ID=0x00000002 Parent=0x05CF85F3 SizeRef=453,1019 Split=Y Selected=0xDAA2F35E DockNode ID=0x00000004 Parent=0x00000002 SizeRef=390,579 Selected=0xDAA2F35E DockNode ID=0x00000006 Parent=0x00000002 SizeRef=390,456 HiddenTabBar=1 Selected=0xAB6613CF diff --git a/src/coffee3D/core/assets/types/MaterialInterface.java b/src/coffee3D/core/assets/types/MaterialInterface.java index dba2621..00156a8 100644 --- a/src/coffee3D/core/assets/types/MaterialInterface.java +++ b/src/coffee3D/core/assets/types/MaterialInterface.java @@ -2,7 +2,6 @@ import coffee3D.core.assets.Asset; import coffee3D.core.assets.AssetReference; -import coffee3D.core.io.log.Log; import coffee3D.core.renderer.RenderUtils; import coffee3D.core.renderer.scene.RenderScene; import coffee3D.core.renderer.scene.Scene; @@ -15,7 +14,6 @@ import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D; import static org.lwjgl.opengl.GL11.glBindTexture; -import static org.lwjgl.opengl.GL13.*; /** * usage : diff --git a/src/coffee3D/core/assets/types/StaticMesh.java b/src/coffee3D/core/assets/types/StaticMesh.java index eec16a8..931ec46 100644 --- a/src/coffee3D/core/assets/types/StaticMesh.java +++ b/src/coffee3D/core/assets/types/StaticMesh.java @@ -6,7 +6,6 @@ import coffee3D.core.resources.factories.ImportZAxis; import coffee3D.core.resources.factories.MeshFactory; import coffee3D.core.io.log.Log; -import coffee3D.core.io.settings.EngineSettings; import coffee3D.core.renderer.debug.DebugRenderer; import coffee3D.core.renderer.scene.Scene; import coffee3D.core.resources.types.MeshResource; @@ -96,12 +95,7 @@ public MaterialInterface[] getMaterials() { for (int i = 0; i < _materials.size(); ++i) { MaterialInterface foundMat = _materials.get(i).get(); - if (foundMat != null) { - materialRefs[i] = foundMat; - } - else { - materialRefs[i] = null; - } + materialRefs[i] = foundMat; } return materialRefs; } @@ -157,12 +151,12 @@ public SphereBound getBound() { public void drawBound(Scene context) { if (_sections != null) { - for (int i = 0; i < _sections.length; ++i) { - Vector3f pos = TypeHelper.getVector3(_sections[i].getStaticBounds().position); + for (MeshResource section : _sections) { + Vector3f pos = TypeHelper.getVector3(section.getStaticBounds().position); _modelMatrix.transformPosition(pos); Vector3f scale = TypeHelper.getVector3(); _modelMatrix.getScale(scale); - DebugRenderer.DrawDebugSphere(context, pos, _sections[i].getStaticBounds().radius * Math.max(scale.x, Math.max(scale.y, scale.z)), 20, Color.GREEN); + DebugRenderer.DrawDebugSphere(context, pos, section.getStaticBounds().radius * Math.max(scale.x, Math.max(scale.y, scale.z)), 20, Color.GREEN); } Vector3f myPos = TypeHelper.getVector3(getBound().position); Vector3f myScale = TypeHelper.getVector3(); diff --git a/src/coffee3D/core/assets/types/World.java b/src/coffee3D/core/assets/types/World.java index 999435b..af26b1a 100644 --- a/src/coffee3D/core/assets/types/World.java +++ b/src/coffee3D/core/assets/types/World.java @@ -5,12 +5,11 @@ import coffee3D.core.types.Color; import java.io.File; -import java.util.Random; public class World extends Asset { private static final long serialVersionUID = 243302515535612352L; private transient static final Color worldAssetColor = new Color(197/255f, 159/255f, 53/255f, 1); - private transient static String[] extensions = {"map"}; + private transient static final String[] extensions = {"map"}; private transient Scene _linkedScene; public World(String name, File sourcePath, File assetPath, Scene linkedScene) { diff --git a/src/coffee3D/core/controller/DefaultController.java b/src/coffee3D/core/controller/DefaultController.java index 04de40c..e7be5a8 100644 --- a/src/coffee3D/core/controller/DefaultController.java +++ b/src/coffee3D/core/controller/DefaultController.java @@ -19,6 +19,10 @@ public DefaultController(RenderScene scene) { super(scene); } + public float getMouseSensitivity() { return _mouseSensitivity; } + public void setMouseSensitivity(float sensitivity) { _mouseSensitivity = sensitivity; } + + @Override public void update() { double deltaTime = Window.GetPrimaryWindow().getDeltaTime(); diff --git a/src/coffee3D/core/controller/TopViewController.java b/src/coffee3D/core/controller/TopViewController.java index 9f891ca..2934a25 100644 --- a/src/coffee3D/core/controller/TopViewController.java +++ b/src/coffee3D/core/controller/TopViewController.java @@ -10,50 +10,61 @@ public class TopViewController extends IGameController { - private static final Vector3f defaultOffset = new Vector3f(0,0,5); - private float distance = 10; - private float wantedDistance = 10; - private float yaw = 0; - private float wantedYaw = 0; - private float pitch = 40; - private Vector2f currentSpeed; + private static final Vector3f _defaultOffset = new Vector3f(0,0,5); + private final Vector2f _currentSpeed = new Vector2f(0); + private final Vector3f _targetPosition = new Vector3f(0); + private final Vector3f _cameraPosition = new Vector3f(0); + private float _distance = 10; + private float _wantedDistance = 10; + private float _yaw = 0; + private float _wantedYaw = 0; + private float _pitch = 40; private float _speed = 200f; private float _mouseSensitivity = .18f; - private final Vector3f targetPosition; - private final Vector3f cameraPosition; - private float borderDetection = 200f; + private float _borderDetection = 200f; + + public void setDistance(float distance) { + _wantedDistance = distance; + if (_wantedDistance > 200) _wantedDistance = 200; + if (_wantedDistance < 5) _wantedDistance = 5; + } + + public float getSpeed() { return _speed; } + public void setSpeed(float speed) { _speed = speed; } + public Vector3f getCameraPosition() { return _cameraPosition; } + public void setBorderDistance(float distance) { _borderDetection = distance; } + public float getBorderDistance() { return _borderDetection; } + public float getSensitivity() { return _mouseSensitivity; } + public void setSensitivity(float sensitivity) { _mouseSensitivity = sensitivity;} + public TopViewController(RenderScene scene) { super(scene); - distance = 10; - currentSpeed = new Vector2f(0,0); - targetPosition = new Vector3f(0); - cameraPosition = new Vector3f(0); } @Override public void update() { float deltaTime = (float) Window.GetPrimaryWindow().getDeltaTime(); - float movementSpeed = _speed * deltaTime * Math.max(.5f, distance / 20); + float movementSpeed = _speed * deltaTime * Math.max(.5f, _distance / 20); - currentSpeed.mul(Math.max(0, 1 - (deltaTime * 10))); + _currentSpeed.mul(Math.max(0, 1 - (deltaTime * 10))); keyboardMovements(deltaTime, movementSpeed); mouseMovements(movementSpeed * 1.5f); - yaw = Interpolation.FInterpTo(yaw, wantedYaw, 10); - pitch = Interpolation.FInterpTo(pitch, Math.max(20, Math.min(40, distance * .75f + 10)), 5); - distance = Interpolation.FInterpTo(distance, wantedDistance, 10); + _yaw = Interpolation.FInterpTo(_yaw, _wantedYaw, 10); + _pitch = Interpolation.FInterpTo(_pitch, Math.max(20, Math.min(40, _distance * .75f + 10)), 5); + _distance = Interpolation.FInterpTo(_distance, _wantedDistance, 10); - getScene().getCamera().setPitchInput(pitch); - getScene().getCamera().setYawInput(yaw); + getScene().getCamera().setPitchInput(_pitch); + getScene().getCamera().setYawInput(_yaw); - cameraPosition.set(getScene().getCamera().getForwardVector()); - cameraPosition.mul(distance * -1); - cameraPosition.add(targetPosition).add(defaultOffset); + _cameraPosition.set(getScene().getCamera().getForwardVector()); + _cameraPosition.mul(_distance * -1); + _cameraPosition.add(_targetPosition).add(_defaultOffset); - getScene().getCamera().setRelativePosition(cameraPosition); + getScene().getCamera().setRelativePosition(_cameraPosition); } @@ -66,17 +77,17 @@ private void mouseMovements(float movementSpeed) { if (distLeft < 0 || distBottom < 0 ||distTop < 0 || distRight < 0) return; - if (distRight < borderDetection) { - currentSpeed.y -= movementSpeed * Math.min(1, (1 - distRight / borderDetection)); + if (distRight < _borderDetection) { + _currentSpeed.y -= movementSpeed * Math.min(1, (1 - distRight / _borderDetection)); } - if (distLeft < borderDetection) { - currentSpeed.y += movementSpeed * Math.min(1, (1 - distLeft / borderDetection)); + if (distLeft < _borderDetection) { + _currentSpeed.y += movementSpeed * Math.min(1, (1 - distLeft / _borderDetection)); } - if (distTop < borderDetection) { - currentSpeed.x += movementSpeed * Math.min(1, (1 - distTop / borderDetection)); + if (distTop < _borderDetection) { + _currentSpeed.x += movementSpeed * Math.min(1, (1 - distTop / _borderDetection)); } - if (distBottom < borderDetection) { - currentSpeed.x -= movementSpeed * Math.min(1, (1 - distBottom / borderDetection)); + if (distBottom < _borderDetection) { + _currentSpeed.x -= movementSpeed * Math.min(1, (1 - distBottom / _borderDetection)); } } @@ -85,40 +96,40 @@ private void keyboardMovements(float deltaTime, float movementSpeed) { if (GLFW.glfwGetKey(windowHandle, GLFW.GLFW_KEY_W) == GLFW.GLFW_PRESS || GLFW.glfwGetKey(windowHandle, GLFW.GLFW_KEY_UP) == GLFW.GLFW_PRESS) { - currentSpeed.x += movementSpeed; + _currentSpeed.x += movementSpeed; } if (GLFW.glfwGetKey(windowHandle, GLFW.GLFW_KEY_S) == GLFW.GLFW_PRESS || GLFW.glfwGetKey(windowHandle, GLFW.GLFW_KEY_DOWN) == GLFW.GLFW_PRESS) { - currentSpeed.x -= movementSpeed; + _currentSpeed.x -= movementSpeed; } if (GLFW.glfwGetKey(windowHandle, GLFW.GLFW_KEY_A) == GLFW.GLFW_PRESS || GLFW.glfwGetKey(windowHandle, GLFW.GLFW_KEY_RIGHT) == GLFW.GLFW_PRESS) { - currentSpeed.y += movementSpeed; + _currentSpeed.y += movementSpeed; } if (GLFW.glfwGetKey(windowHandle, GLFW.GLFW_KEY_D) == GLFW.GLFW_PRESS || GLFW.glfwGetKey(windowHandle, GLFW.GLFW_KEY_LEFT) == GLFW.GLFW_PRESS) { - currentSpeed.y -= movementSpeed; + _currentSpeed.y -= movementSpeed; } if (GLFW.glfwGetKey(windowHandle, GLFW.GLFW_KEY_Q) == GLFW.GLFW_PRESS || GLFW.glfwGetKey(windowHandle, GLFW.GLFW_KEY_DELETE) == GLFW.GLFW_PRESS) { - wantedYaw += deltaTime * 200; + _wantedYaw += deltaTime * 200; } if (GLFW.glfwGetKey(windowHandle, GLFW.GLFW_KEY_E) == GLFW.GLFW_PRESS || GLFW.glfwGetKey(windowHandle, GLFW.GLFW_KEY_PAGE_DOWN) == GLFW.GLFW_PRESS) { - wantedYaw -= deltaTime * 200; + _wantedYaw -= deltaTime * 200; } Vector3f forward = TypeHelper.getVector3(getScene().getCamera().getForwardVector()); forward.z = 0; forward.normalize(); - forward.mul(currentSpeed.x * deltaTime); + forward.mul(_currentSpeed.x * deltaTime); Vector3f right = TypeHelper.getVector3(getScene().getCamera().getRightVector()); right.z = 0; right.normalize(); - right.mul(currentSpeed.y * deltaTime); - targetPosition.add(forward); - targetPosition.add(right); + right.mul(_currentSpeed.y * deltaTime); + _targetPosition.add(forward); + _targetPosition.add(right); } @Override @@ -137,8 +148,6 @@ public void mouseButtonCallback(int button, int action, int mods) {} @Override public void scrollCallback(double xOffset, double yOffset) { - if (yOffset != 0) wantedDistance *= (-yOffset) / 4 + 1; - if (wantedDistance > 200) wantedDistance = 200; - if (wantedDistance < 5) wantedDistance = 5; + if (yOffset != 0) setDistance(_wantedDistance *= (-yOffset) / 4 + 1); } } \ No newline at end of file diff --git a/src/coffee3D/core/navigation/NavMeshGrid.java b/src/coffee3D/core/navigation/NavMeshGrid.java new file mode 100644 index 0000000..56bee2b --- /dev/null +++ b/src/coffee3D/core/navigation/NavMeshGrid.java @@ -0,0 +1,85 @@ +package coffee3D.core.navigation; + +import coffee3D.core.io.log.Log; +import org.joml.Vector2i; +import org.joml.Vector3f; + +import java.util.ArrayList; + +public class NavMeshGrid { + private final NavmeshPoint[] _navMesh; + private final Vector3f _navmeshLocation; + private final Vector2i _size; + private final float _cellSize; + + + public NavMeshGrid(Vector3f navMeshLocation, NavmeshPoint[] navMesh, Vector2i navmeshSize, float cellSize) { + _navMesh = navMesh; + _navmeshLocation = navMeshLocation; + _size = navmeshSize; + _cellSize = cellSize; + if (navMesh.length != navmeshSize.x * navmeshSize.y) Log.Fail("invalid navmesh values"); + for (int i = 0; i < _navMesh.length; ++i) { + _navMesh[i].location.set(i % _size.x, i / _size.y); + } + } + + + public NavigationPath findPathToLocation(Vector3f from, Vector3f to) { + NavmeshPoint start = findClosestNavmeshPoint(from); + NavmeshPoint end = findClosestNavmeshPoint(to); + ArrayList pathPoints = new ArrayList<>(); + + + return new NavigationPath(null); + } + + public NavmeshPoint findClosestNavmeshPoint(Vector3f worldPosition) { + NavmeshPoint closestPoint = null; + Vector2i searchPoint = new Vector2i(); + worldToLocal(worldPosition, searchPoint); + float closestDistance = 0; + for (NavmeshPoint point : _navMesh) { + if (closestPoint == null) { + closestPoint = point; + closestDistance = (float) point.location.gridDistance(searchPoint); + continue; + } + float dist = (float) point.location.gridDistance(searchPoint); + if (dist < closestDistance) { + closestPoint = point; + closestDistance = dist; + } + } + return closestPoint; + } + + public void worldToLocal(Vector3f world, Vector2i local) { + local.set( + (int) ((world.x - _navmeshLocation.x) * _cellSize), + (int) ((world.y - _navmeshLocation.y) * _cellSize) + ); + } + + public void localToWorld(Vector2i local, Vector3f world) { + world.set( + (local.x / _cellSize) + _navmeshLocation.x, + (local.y / _cellSize) + _navmeshLocation.y, + _navmeshLocation.z + ); + } + + public boolean isLocationInNavmesh(Vector2i location) { + return location.x >= 0 && location.y >= 0 && location.x < _size.x && location.y < _size.y; + } + + public boolean isLocationNavigable(Vector2i location) { + NavmeshPoint point = getPoint(location); + return point != null && point.isNavigable; + } + + public NavmeshPoint getPoint(Vector2i position) { + if (!isLocationInNavmesh(position)) return null; + return _navMesh[position.x + position.y * _size.x]; + } +} diff --git a/src/coffee3D/core/navigation/NavigableActor.java b/src/coffee3D/core/navigation/NavigableActor.java new file mode 100644 index 0000000..9dda631 --- /dev/null +++ b/src/coffee3D/core/navigation/NavigableActor.java @@ -0,0 +1,13 @@ +package coffee3D.core.navigation; + +import coffee3D.core.renderer.scene.SceneComponent; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +public class NavigableActor extends SceneComponent { + + + public NavigableActor(Vector3f position, Quaternionf rotation, Vector3f scale) { + super(position, rotation, scale); + } +} diff --git a/src/coffee3D/core/navigation/NavigationPath.java b/src/coffee3D/core/navigation/NavigationPath.java new file mode 100644 index 0000000..eecaa61 --- /dev/null +++ b/src/coffee3D/core/navigation/NavigationPath.java @@ -0,0 +1,12 @@ +package coffee3D.core.navigation; + +import org.joml.Vector3f; + +public class NavigationPath { + + private final Vector3f[] _pathPoints; + + NavigationPath(Vector3f[] pathPoints) { + _pathPoints = pathPoints; + } +} diff --git a/src/coffee3D/core/navigation/NavmeshPoint.java b/src/coffee3D/core/navigation/NavmeshPoint.java new file mode 100644 index 0000000..2e04d3e --- /dev/null +++ b/src/coffee3D/core/navigation/NavmeshPoint.java @@ -0,0 +1,8 @@ +package coffee3D.core.navigation; + +import org.joml.Vector2i; + +public class NavmeshPoint { + public boolean isNavigable = false; + public final Vector2i location = new Vector2i(); +} diff --git a/src/coffee3D/core/navigation/navmeshComponent.java b/src/coffee3D/core/navigation/navmeshComponent.java new file mode 100644 index 0000000..5933ee5 --- /dev/null +++ b/src/coffee3D/core/navigation/navmeshComponent.java @@ -0,0 +1,14 @@ +package coffee3D.core.navigation; + +import coffee3D.core.renderer.scene.SceneComponent; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +public class navmeshComponent extends SceneComponent { + + public navmeshComponent(Vector3f position, Quaternionf rotation, Vector3f scale) { + super(position, rotation, scale); + } + + +} diff --git a/src/coffee3D/core/renderer/scene/DrawList.java b/src/coffee3D/core/renderer/scene/DrawList.java index eca5586..3da180c 100644 --- a/src/coffee3D/core/renderer/scene/DrawList.java +++ b/src/coffee3D/core/renderer/scene/DrawList.java @@ -1,7 +1,6 @@ package coffee3D.core.renderer.scene; import coffee3D.core.assets.types.StaticMesh; -import coffee3D.core.io.log.Log; import coffee3D.core.renderer.scene.Components.StaticMeshComponent; import org.joml.FrustumIntersection; import org.joml.Matrix4f;