-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Create, place and edit multiple navmeshs on world
-Added prepass and render pass for every components
- Loading branch information
1 parent
7e49678
commit c0b72fe
Showing
21 changed files
with
294 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: coffee3D.MainGame | ||
Main-Class: coffee3D.Main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: coffee3D.MainGame | ||
Main-Class: coffee3D.Main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
package coffee3D.core.navigation; | ||
|
||
import coffee3D.core.maths.MathLibrary; | ||
import coffee3D.core.renderer.RenderMode; | ||
import coffee3D.core.renderer.RenderUtils; | ||
import coffee3D.core.renderer.Window; | ||
import coffee3D.core.renderer.debug.DebugRenderer; | ||
import coffee3D.core.renderer.scene.RenderScene; | ||
import coffee3D.core.renderer.scene.Scene; | ||
import coffee3D.core.renderer.scene.SceneComponent; | ||
import coffee3D.core.types.Color; | ||
import coffee3D.core.types.SphereBound; | ||
import coffee3D.core.types.TypeHelper; | ||
import org.joml.Quaternionf; | ||
import org.joml.Vector2i; | ||
import org.joml.Vector3f; | ||
import org.lwjgl.glfw.GLFW; | ||
|
||
import static org.lwjgl.opengl.GL11.*; | ||
|
||
public class NavmeshComponent extends SceneComponent { | ||
|
||
private static final long serialVersionUID = -4773537143224102110L; | ||
|
||
protected int _sizeX; | ||
protected int _sizeY; | ||
protected float _cellSize; | ||
private NavMeshGrid _navmesh; | ||
private transient SphereBound bounds; | ||
|
||
public NavmeshComponent(Vector3f position, Quaternionf rotation, Vector3f scale) { | ||
super(position, rotation, scale); | ||
_sizeX = 100; | ||
_sizeY = 40; | ||
_cellSize = 1f; | ||
newNavmesh(); | ||
} | ||
|
||
@Override | ||
protected void draw(Scene context) {} | ||
|
||
@Override | ||
public void postDraw(Scene context) { | ||
super.draw(context); | ||
|
||
if (_cellSize != _navmesh.getCellSize() || | ||
_sizeX != _navmesh.getGridSize().x || | ||
_sizeY != _navmesh.getGridSize().y | ||
) newNavmesh(); | ||
|
||
_navmesh.getNavmeshLocation().set(getWorldPosition()); | ||
if (isSelected()) { | ||
visualize((RenderScene) context); | ||
edit((RenderScene) context); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public SphereBound getBound() { | ||
if (bounds == null) { | ||
bounds = new SphereBound(); | ||
} | ||
bounds.radius = _cellSize * Math.max(_sizeX, _sizeY); | ||
bounds.position.set(getWorldPosition()); | ||
return bounds; | ||
} | ||
|
||
private void newNavmesh() { | ||
_navmesh = new NavMeshGrid(getWorldPosition(), new Vector2i(_sizeX, _sizeY), _cellSize); | ||
} | ||
|
||
private transient Vector3f _center; | ||
private transient Vector3f _worldPosA; | ||
private transient Vector3f _worldPosB; | ||
private transient Vector3f _worldPosC; | ||
private transient Vector3f _worldPosD; | ||
private transient Color navigableColor; | ||
private transient Color notNavigableColor; | ||
private transient Color selectionColor; | ||
|
||
private void visualize(RenderScene context) { | ||
|
||
if (_center == null) _center = new Vector3f(); | ||
if (_worldPosA == null) _worldPosA = new Vector3f(); | ||
if (_worldPosB == null) _worldPosB = new Vector3f(); | ||
if (_worldPosC == null) _worldPosC = new Vector3f(); | ||
if (_worldPosD == null) _worldPosD = new Vector3f(); | ||
if (navigableColor == null) navigableColor = new Color(0, 1, 0, 0.8f); | ||
if (notNavigableColor == null) notNavigableColor = new Color(1, 0, 0, 0.2f); | ||
if (selectionColor == null) selectionColor = new Color(1, 1, 0, 0.5f); | ||
|
||
if (RenderUtils.RENDER_MODE == RenderMode.Select) { | ||
RenderUtils.getPickMaterialDrawList()[0].use(context); | ||
RenderUtils.getPickMaterialDrawList()[0].getResource().setIntParameter("pickId", getComponentIndex() + 1); | ||
RenderUtils.getPickMaterialDrawList()[0].getResource().setModelMatrix(TypeHelper.getMat4().identity()); | ||
|
||
_worldPosA.set(getWorldPosition()); | ||
_worldPosB.set(_worldPosA).add(_sizeX * _cellSize, 0, 0); | ||
_worldPosC.set(_worldPosA).add(_sizeX * _cellSize, _sizeY * _cellSize, 0); | ||
_worldPosD.set(_worldPosA).add(0, _sizeY * _cellSize, 0); | ||
|
||
glMatrixMode(GL_MODELVIEW); | ||
glBegin(GL_QUADS); | ||
{ | ||
glVertex3f(_worldPosA.x, _worldPosA.y, _worldPosA.z); | ||
glVertex3f(_worldPosB.x, _worldPosB.y, _worldPosB.z); | ||
glVertex3f(_worldPosC.x, _worldPosC.y, _worldPosC.z); | ||
glVertex3f(_worldPosD.x, _worldPosD.y, _worldPosD.z); | ||
} | ||
glEnd(); | ||
} | ||
|
||
if (RenderUtils.RENDER_MODE != RenderMode.Color) return; | ||
|
||
DebugRenderer.DrawDebugBox(context, getWorldPosition(), _worldPosA.set(getWorldPosition()).add(_sizeX * _cellSize, _sizeY * _cellSize, 0), Color.BLUE); | ||
|
||
glEnable(GL_BLEND); | ||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||
float halfGridSize = _navmesh.getCellSize() / 2; | ||
RenderUtils.getDebugMaterial().getResource().setModelMatrix(TypeHelper.getMat4().identity()); | ||
|
||
for (NavmeshPoint _points : _navmesh.getNavmesh()) { | ||
_navmesh.localToWorld(_points.location, _center); | ||
_worldPosA.set(_center).add(-halfGridSize, -halfGridSize, 0); | ||
_worldPosB.set(_center).add(halfGridSize, -halfGridSize, 0); | ||
_worldPosC.set(_center).add(halfGridSize, halfGridSize, 0); | ||
_worldPosD.set(_center).add(-halfGridSize, halfGridSize, 0); | ||
|
||
RenderUtils.getDebugMaterial().use(context); | ||
RenderUtils.getDebugMaterial().setColor(_points.isNavigable ? navigableColor : notNavigableColor); | ||
glMatrixMode(GL_MODELVIEW); | ||
glBegin(GL_QUADS); | ||
{ | ||
glVertex3f(_worldPosA.x, _worldPosA.y, _worldPosA.z); | ||
glVertex3f(_worldPosB.x, _worldPosB.y, _worldPosB.z); | ||
glVertex3f(_worldPosC.x, _worldPosC.y, _worldPosC.z); | ||
glVertex3f(_worldPosD.x, _worldPosD.y, _worldPosD.z); | ||
} | ||
glEnd(); | ||
} | ||
glDisable(GL_BLEND); | ||
} | ||
|
||
private static final Vector3f Inter = new Vector3f(); | ||
private static final Vector3f up = new Vector3f(0, 0, 1); | ||
private static final Vector3f camDir = new Vector3f(0); | ||
private static final Vector2i local = new Vector2i(0); | ||
|
||
private void edit(RenderScene scene) { | ||
|
||
if (GLFW.glfwGetMouseButton(Window.GetPrimaryWindow().getGlfwWindowHandle(), GLFW.GLFW_MOUSE_BUTTON_1) == GLFW.GLFW_PRESS) { | ||
scene.getCursorSceneDirection(camDir); | ||
MathLibrary.LinePlaneIntersection(getWorldPosition(), up, camDir, scene.getCamera().getWorldPosition(), Inter); | ||
_navmesh.worldToLocal(Inter, local); | ||
if (_navmesh.getPoint(local) != null) { | ||
_navmesh.getPoint(local).isNavigable = GLFW.glfwGetKey(Window.GetPrimaryWindow().getGlfwWindowHandle(), GLFW.GLFW_KEY_LEFT_SHIFT) != GLFW.GLFW_PRESS; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.