Я практикуюсь делать проект на воксельном движке, и у меня возникает ошибка при запуске программы, я смоделировал физику на камеру и сгенерировал чанк в положении камеры, но время от времени камера проваливается пустота, у меня есть галочка активировать движение к камере только тогда, когда чанк под ней сгенерирован, но все равно работает неправильно. Я использую lwjgl 2.9.1.
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector3f;
import chunks.Chunk;
import chunks.ChunkMesh;
import entities.Camera;
import entities.Entity;
import entities.Pointer;
import fisics.CollisionHandler;
import models.CubeModel;
import models.RawModel;
import models.TexturedModel;
import render_engine.DisplayManager;
import render_engine.Loader;
import render_engine.MasterRenderer;
import shaders.StaticShader;
import textures.Modeltexture;
/**
* The MainGameLoop class is the entry point of the JuanCraft game application.
* It initializes the display, prepares the rendering engine, and enters the
* main game loop where rendering occurs until the display is closed.
*/
public class MainGameLoop {
// Static references for loader and shader for use throughout the application.
public static Loader loader1 = null; // Loader instance for model loading
public static StaticShader shader1 = null; // Shader instance for rendering
// List of chunks to be rendered in the game world.
public static List chunks = new CopyOnWriteArrayList();
// Vector representing the position of the camera.
static Vector3f camPos = new Vector3f(0, 0, 0);
// List of positions that have been used for placing entities to avoid duplication.
static List usedPos = new ArrayList();
static List entities = new ArrayList();
// Defines the size of the world (distance from the camera in each direction).
static final int WORLD_SIZE = 9 * 32; // World size is 288 units (9 chunks of 32 units each).
/**
* The main method that starts the game. It initializes the display, creates a
* MasterRenderer for rendering, and enters the game loop.
*
* @param args Command line arguments (not used in this application).
*/
@SuppressWarnings("unused")
public static void main(String[] args) {
// Create and initialize the display window for the game.
DisplayManager.createDisplay();
// Create a Loader instance for loading models and shaders.
Loader loader = new Loader();
loader1 = loader; // Store the loader instance for potential future use.
StaticShader shader = new StaticShader();
shader1 = shader; // Store the shader instance for potential future use.
// Set properties for the pointer entity.
Pointer.setSize(20.0f);
Pointer.setColor(1.0f, 0.0f, 0.0f); // Set pointer color to red.
// Instantiate the MasterRenderer to handle rendering operations.
MasterRenderer renderer = new MasterRenderer();
// Load the vertices, indices, and UV coordinates into a RawModel for a cube.
RawModel model = loader.loadToVao(CubeModel.vertices, CubeModel.indices, CubeModel.uv);
// Load a texture from the specified file and create a Modeltexture object.
Modeltexture texture = new Modeltexture(loader.loadTexture("DefaultPack"));
// Create a TexturedModel object using the loaded texture and the 3D model.
TexturedModel texturedModel = new TexturedModel(model, texture);
// Create a Camera object positioned at the origin with no rotation.
Camera camera = new Camera(new Vector3f(0, 2, 0), 0, 0, 0);
// Create a new thread to manage entity creation in the positive X and Z quadrant.
new Thread(new Runnable() {
@Override
public void run() {
// Generate the chunk where the camera is located.
Chunk.generateChunkAtCameraPosition(camPos, usedPos);
// Generate nearby chunks in a separate thread.
while (!Display.isCloseRequested()) {
// Loop to generate chunks around the camera in a 32x32 area.
for (int x = (int) (camPos.x - WORLD_SIZE) / 32; x < (camPos.x + WORLD_SIZE) / 32; x++) {
for (int z = (int) (camPos.z - WORLD_SIZE) / 32; z < (camPos.z + WORLD_SIZE) / 32; z++) {
// Avoid generating already used chunks.
if (!usedPos.contains(new Vector3f(x * 32, 0, z * 32))) {
Chunk.generateChunkAt(x, z, usedPos); // Generate the chunk.
}
}
}
try {
Thread.sleep(1); // Sleep to prevent overloading the loop.
} catch (InterruptedException e) {
Thread.currentThread().interrupt(); // Restore interrupted state.
}
}
}
}).start();
// Main game loop, which runs continuously until the display requests to close.
int index = 0; // Index for tracking chunks to be loaded.
boolean showDebugInfo = false; // Toggle for debug information display.
while (!Display.isCloseRequested()) {
// Check if the chunk below the camera is ready before applying gravity
if (Chunk.isChunkAtCameraReady) {
if (CollisionHandler.isGroundBelowCamera(camera)) {
camera.applyGravity(); // Apply gravity only when ground exists below the camera
}
camera.move();
}
// Get the current camera position for entity placement logic.
camPos = camera.getPosition();
// Apply gravity if there is no ground below the camera.
if (!CollisionHandler.isGroundBelowCamera(camera)) {
camera.applyGravity();
}
// Load chunks into the world until we reach the limit.
if (index < chunks.size()) {
// Load the chunk's mesh data into a RawModel.
RawModel model123 = loader.loadToVao(chunks.get(index).positions, chunks.get(index).uvs);
// Create a textured model for the chunk using the loaded texture.
TexturedModel texModel = new TexturedModel(model123, texture);
// Create an entity for the chunk, placed at the chunk's origin.
Entity entity = new Entity(texModel, chunks.get(index).chunck.getOrigin(), 0, 0, 0, 1);
entities.add(entity); // Add the new entity to the list of entities.
// Clean up chunk data to free memory.
chunks.get(index).positions = null;
chunks.get(index).uvs = null;
chunks.get(index).normals = null;
index++; // Move to the next chunk.
}
// Render each chunk entity that is within the specified world size.
for (int i = 0; i < entities.size(); i++) {
Vector3f origin = entities.get(i).getPosition(); // Get the position of the entity.
// Calculate the distance from the camera to the chunk along the X and Z axes.
int distX = Math.abs((int) (camPos.x - origin.x));
int distZ = Math.abs((int) (camPos.z - origin.z));
// If the chunk is within the world size range, render its blocks.
if (distX
Подробнее здесь: [url]https://stackoverflow.com/questions/79127950/error-when-applying-physics-in-lwjgl-2-9-1[/url]
Я практикуюсь делать проект на воксельном движке, и у меня возникает ошибка при запуске программы, я смоделировал физику на камеру и сгенерировал чанк в положении камеры, но время от времени камера проваливается пустота, у меня есть галочка активировать движение к камере только тогда, когда чанк под ней сгенерирован, но все равно работает неправильно. Я использую lwjgl 2.9.1. [code]import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList;
/** * The MainGameLoop class is the entry point of the JuanCraft game application. * It initializes the display, prepares the rendering engine, and enters the * main game loop where rendering occurs until the display is closed. */ public class MainGameLoop {
// Static references for loader and shader for use throughout the application. public static Loader loader1 = null; // Loader instance for model loading public static StaticShader shader1 = null; // Shader instance for rendering
// List of chunks to be rendered in the game world. public static List chunks = new CopyOnWriteArrayList();
// Vector representing the position of the camera. static Vector3f camPos = new Vector3f(0, 0, 0);
// List of positions that have been used for placing entities to avoid duplication. static List usedPos = new ArrayList();
static List entities = new ArrayList();
// Defines the size of the world (distance from the camera in each direction). static final int WORLD_SIZE = 9 * 32; // World size is 288 units (9 chunks of 32 units each).
/** * The main method that starts the game. It initializes the display, creates a * MasterRenderer for rendering, and enters the game loop. * * @param args Command line arguments (not used in this application). */ @SuppressWarnings("unused") public static void main(String[] args) { // Create and initialize the display window for the game. DisplayManager.createDisplay();
// Create a Loader instance for loading models and shaders. Loader loader = new Loader(); loader1 = loader; // Store the loader instance for potential future use. StaticShader shader = new StaticShader(); shader1 = shader; // Store the shader instance for potential future use.
// Set properties for the pointer entity. Pointer.setSize(20.0f); Pointer.setColor(1.0f, 0.0f, 0.0f); // Set pointer color to red.
// Instantiate the MasterRenderer to handle rendering operations. MasterRenderer renderer = new MasterRenderer();
// Load the vertices, indices, and UV coordinates into a RawModel for a cube. RawModel model = loader.loadToVao(CubeModel.vertices, CubeModel.indices, CubeModel.uv);
// Load a texture from the specified file and create a Modeltexture object. Modeltexture texture = new Modeltexture(loader.loadTexture("DefaultPack"));
// Create a TexturedModel object using the loaded texture and the 3D model. TexturedModel texturedModel = new TexturedModel(model, texture);
// Create a Camera object positioned at the origin with no rotation. Camera camera = new Camera(new Vector3f(0, 2, 0), 0, 0, 0);
// Create a new thread to manage entity creation in the positive X and Z quadrant. new Thread(new Runnable() { @Override public void run() { // Generate the chunk where the camera is located. Chunk.generateChunkAtCameraPosition(camPos, usedPos);
// Generate nearby chunks in a separate thread. while (!Display.isCloseRequested()) { // Loop to generate chunks around the camera in a 32x32 area. for (int x = (int) (camPos.x - WORLD_SIZE) / 32; x < (camPos.x + WORLD_SIZE) / 32; x++) { for (int z = (int) (camPos.z - WORLD_SIZE) / 32; z < (camPos.z + WORLD_SIZE) / 32; z++) { // Avoid generating already used chunks. if (!usedPos.contains(new Vector3f(x * 32, 0, z * 32))) { Chunk.generateChunkAt(x, z, usedPos); // Generate the chunk. } } }
// Main game loop, which runs continuously until the display requests to close. int index = 0; // Index for tracking chunks to be loaded. boolean showDebugInfo = false; // Toggle for debug information display. while (!Display.isCloseRequested()) {
// Check if the chunk below the camera is ready before applying gravity if (Chunk.isChunkAtCameraReady) { if (CollisionHandler.isGroundBelowCamera(camera)) { camera.applyGravity(); // Apply gravity only when ground exists below the camera } camera.move(); }
// Get the current camera position for entity placement logic. camPos = camera.getPosition();
// Apply gravity if there is no ground below the camera. if (!CollisionHandler.isGroundBelowCamera(camera)) { camera.applyGravity(); }
// Load chunks into the world until we reach the limit. if (index < chunks.size()) { // Load the chunk's mesh data into a RawModel. RawModel model123 = loader.loadToVao(chunks.get(index).positions, chunks.get(index).uvs);
// Create a textured model for the chunk using the loaded texture. TexturedModel texModel = new TexturedModel(model123, texture);
// Create an entity for the chunk, placed at the chunk's origin. Entity entity = new Entity(texModel, chunks.get(index).chunck.getOrigin(), 0, 0, 0, 1); entities.add(entity); // Add the new entity to the list of entities.
// Clean up chunk data to free memory. chunks.get(index).positions = null; chunks.get(index).uvs = null; chunks.get(index).normals = null;
index++; // Move to the next chunk. }
// Render each chunk entity that is within the specified world size. for (int i = 0; i < entities.size(); i++) { Vector3f origin = entities.get(i).getPosition(); // Get the position of the entity.
// Calculate the distance from the camera to the chunk along the X and Z axes. int distX = Math.abs((int) (camPos.x - origin.x)); int distZ = Math.abs((int) (camPos.z - origin.z));
// If the chunk is within the world size range, render its blocks. if (distX
Я пытаюсь добавить движок физики пуль в свой проект Vulkan.
Я создаю куб (коробку в пуле) вот так
btRigidBody* createBox(float x, float y, float z, float mass) {
btTransform t;
t.setIdentity();
t.setOrigin(btVector3(x, y, z));
btBoxShape* box = new...
Я делаю игру в Unity с резиновым мячом для одного из объектов. Я просмотрел различные доступные активы с мягкой физикой тела, и никто из них не смотрит, особенно то, что я ищу. Я хочу запрограммировать мяч, который будет подпрыгнуть, и своего рода...
У меня есть класс Mesh и класс Renderer. Я создаю сетку, и когда я использую метод Renderer.renderMesh(), он ничего не делает. Я получаю ошибку OpenGL 1282.
Это работает в учебнике пятилетней давности в Windows. А я использую MacOS.
Когда я получаю...
Это бросает фатальную ошибку, когда я пытаюсь создать шейдер.
Вот код
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
введите здесь описание изображения
У меня проблема с lwjgl, я понятия не имею, как поместить библиотеки lwjgl 3 (с maven) в IDE apache netBeans. Я поместил библиотеки в IDE и получаю эту ошибку, вот код.
Спасибо за помощь c: