Skip to content

Commit

Permalink
wip navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre EVEN committed Nov 16, 2020
1 parent c36fe3d commit 7e49678
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 73 deletions.
24 changes: 12 additions & 12 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Collapsed=0

[Window][Scene outliner]
Pos=1467,39
Size=453,1039
Size=453,580
Collapsed=0
DockId=0x00000004,0

Expand All @@ -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

Expand Down Expand Up @@ -75,7 +75,7 @@ Collapsed=0

[Window][viewport]
Pos=0,39
Size=1465,508
Size=1465,717
Collapsed=0
DockId=0x00000003,0

Expand Down Expand Up @@ -116,7 +116,7 @@ Collapsed=0

[Window][HUD Window]
Pos=-4,-4
Size=1928,1065
Size=1928,1088
Collapsed=0

[Window][Test Window]
Expand Down Expand Up @@ -268,7 +268,7 @@ Collapsed=0

[Window][Level properties]
Pos=1467,39
Size=453,1039
Size=453,580
Collapsed=0
DockId=0x00000004,1

Expand Down Expand Up @@ -336,7 +336,7 @@ Collapsed=0

[Window][Console]
Pos=1467,39
Size=453,1039
Size=453,580
Collapsed=0
DockId=0x00000004,2

Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/coffee3D/core/assets/types/MaterialInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 :
Expand Down
14 changes: 4 additions & 10 deletions src/coffee3D/core/assets/types/StaticMesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/coffee3D/core/assets/types/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/coffee3D/core/controller/DefaultController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
101 changes: 55 additions & 46 deletions src/coffee3D/core/controller/TopViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand All @@ -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));
}
}

Expand All @@ -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
Expand All @@ -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);
}
}
Loading

0 comments on commit 7e49678

Please sign in to comment.