Test not positif
This commit is contained in:
parent
443b3a319d
commit
7c7dddde5e
9 changed files with 286 additions and 32 deletions
|
|
@ -83,7 +83,7 @@ namespace Map3DRendering.Common {
|
|||
|
||||
// Get the projection matrix using the same method we have used up until this point
|
||||
public Matrix4 GetProjectionMatrix() {
|
||||
return Matrix4.CreatePerspectiveFieldOfView(_fov, AspectRatio, 0.01f, 1000f);
|
||||
return Matrix4.CreatePerspectiveFieldOfView(_fov, AspectRatio, 0.01f, 5000f);
|
||||
}
|
||||
|
||||
// This function is going to update the direction vertices using some of the math learned in the web tutorials.
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ namespace Map3DRendering {
|
|||
public static class Program {
|
||||
private static void Main() {
|
||||
var nativeWindowSettings = new NativeWindowSettings() {
|
||||
Size = new Vector2i(800, 600),
|
||||
ClientSize = new Vector2i(800, 600),
|
||||
Title = "LearnOpenTK - Map AC2",
|
||||
Vsync = VSyncMode.On,
|
||||
// This is needed to run on macos
|
||||
Flags = ContextFlags.ForwardCompatible,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Map3DRendering {
|
|||
|
||||
private readonly Vector3 _lightPos = new Vector3(0x10, 0, 0x10);
|
||||
|
||||
private MapRender mapRender;
|
||||
private WorldMapRender mapRender;
|
||||
private AxesGizmo axesGizmo;
|
||||
|
||||
private Shader _shader;
|
||||
|
|
@ -33,7 +33,7 @@ namespace Map3DRendering {
|
|||
public Window(GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings)
|
||||
: base(gameWindowSettings, nativeWindowSettings) {
|
||||
|
||||
mapRender = new MapRender();
|
||||
mapRender = new WorldMapRender();
|
||||
|
||||
GL.GetInteger(GetPName.MaxTextureImageUnits, out maxTextures);
|
||||
}
|
||||
|
|
@ -88,7 +88,7 @@ namespace Map3DRendering {
|
|||
GL.LineWidth(5.0f);
|
||||
|
||||
_shader.SetVector3("viewPos", _camera.Position);
|
||||
mapRender.UpdateBlocks(_camera.Position, _shader);
|
||||
//mapRender.UpdateBlocks(_camera.Position, _shader);
|
||||
mapRender.Render(_shader);
|
||||
|
||||
axesGizmo.Render(Size.X, Size.Y, _camera);
|
||||
|
|
|
|||
67
Map3DRendering/WorldMapRender.cs
Normal file
67
Map3DRendering/WorldMapRender.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using LandblockExtraction.DatEngine;
|
||||
using LandblockExtraction.WorldMap;
|
||||
using Map3DRendering.Common;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK.Mathematics;
|
||||
|
||||
|
||||
namespace Map3DRendering;
|
||||
public class WorldMapRender {
|
||||
private PortalEngine portalEngine;
|
||||
private CellEngine cellEngine;
|
||||
private WorldMap worldMap;
|
||||
|
||||
public int _vertexArrayObject;
|
||||
public int _vertexBufferObject;
|
||||
public int _elementBufferObject;
|
||||
|
||||
public int indicesLength;
|
||||
|
||||
public WorldMapRender() {
|
||||
portalEngine = new PortalEngine();
|
||||
cellEngine = new CellEngine();
|
||||
|
||||
worldMap = new WorldMap(portalEngine, cellEngine);
|
||||
worldMap.LoadRegion(0x5F, 0x9F);
|
||||
}
|
||||
public void OnLoad(Shader _shader) {
|
||||
InitializeMap(_shader);
|
||||
}
|
||||
private void InitializeMap(Shader _shader) {
|
||||
int lenghPacket = 7;
|
||||
var vertices = worldMap.GetAllVertices();
|
||||
var indices = worldMap.GenerateRegionIndices(0x5F, 0x9F);
|
||||
indicesLength = indices.Length;
|
||||
// Initialisez le VAO, VBO et EBO pour le bloc à (x, y)...
|
||||
// Utilisez le code de votre méthode OnLoad originale pour configurer le VAO, VBO et EBO.
|
||||
int tempVertexArray = GL.GenVertexArray();
|
||||
GL.BindVertexArray(tempVertexArray);
|
||||
_vertexArrayObject = tempVertexArray;
|
||||
|
||||
int tmpVertexBuffer = GL.GenBuffer();
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, tmpVertexBuffer);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw);
|
||||
_vertexBufferObject = tmpVertexBuffer;
|
||||
|
||||
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 0);
|
||||
|
||||
int tmpElementBuffer = GL.GenBuffer();
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, tmpElementBuffer);
|
||||
GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(int), indices, BufferUsageHint.StaticDraw);
|
||||
_elementBufferObject = tmpElementBuffer;
|
||||
|
||||
var vertexLocation = _shader.GetAttribLocation("aPos");
|
||||
GL.EnableVertexAttribArray(vertexLocation);
|
||||
GL.VertexAttribPointer(vertexLocation, 3, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 0);
|
||||
|
||||
var colorLocation = _shader.GetAttribLocation("aColor");
|
||||
GL.EnableVertexAttribArray(colorLocation);
|
||||
GL.VertexAttribPointer(colorLocation, 4, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 6 * sizeof(float));
|
||||
}
|
||||
public void Render(Shader shader) {
|
||||
var model = Matrix4.Identity;//CreateTranslation(x * BlockSize, 0, y * BlockSize); // Ajustez selon votre système de coordonnées
|
||||
shader.SetMatrix4("model", model);
|
||||
GL.BindVertexArray(_vertexArrayObject);
|
||||
GL.DrawElements(PrimitiveType.Triangles, indicesLength, DrawElementsType.UnsignedInt, 0);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue