FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál
  • ✇Recent Questions - Game Development Stack Exchange
  • LWJGL and JOML rotation issuesPjRock
    I'm making a scene builder in LWJGL. Objects in the scene have positions and rotations. Like most scene builders/modelers, I have colors handles to show the objects orientation. I have a typical setup, red points in the positive x direction, blue in the positive z. The problem is the handles don't point in the correct direction. I have attached a screenshot showing the issue. The cube on the right has a rotation of 0, 0, 0, and the handles are correct. The cube on the left has a rotation o
     

LWJGL and JOML rotation issues

I'm making a scene builder in LWJGL. Objects in the scene have positions and rotations. Like most scene builders/modelers, I have colors handles to show the objects orientation. I have a typical setup, red points in the positive x direction, blue in the positive z.

The problem is the handles don't point in the correct direction. I have attached a screenshot showing the issue. The cube on the right has a rotation of 0, 0, 0, and the handles are correct. The cube on the left has a rotation of 0, 30, 0. Where I'm confused is why is the blue handle rotated 30 degrees clockwise, and the mesh is 30 degrees COUNTER-clockwise?

enter image description here

I compute the cube's rotation with

public Matrix4f getLocalMatrix() {
    // I update the position, rotation and scale directly, so I recalculate the matrix every time.
    return this.localMatrix.translationRotateScale(this.position, this.rotation, this.scale);
}

And to draw the handles I use

Matrix4f m = gameObject.getLocalMatrix();
gizmos.drawRay(gameObject.position, m.positiveZ(new Vector3f()));

...

public void drawRay(Vector3f start, Vector3f direction) {
    glBegin(GL_LINES);
    glVertex3f(start.x, start.y, start.z);
    glVertex3f(start.x + direction.x, start.y + direction.y, start.z + direction.z);
    glEnd();
}

I use a simple vertex shader, I don't think that's the issue,

layout (location=0) in vec3 inPosition;
layout (location=1) in vec2 texCoord;

out vec2 outTextCoord;

uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;

void main() {
    gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(inPosition, 1.0);
    outTextCoord = texCoord;
}

The uniforms are being set correctly (I'm assuming). modelMatrix is set to gameObject.getLocalMatrix());

The only thing I can think of is some of my code is using right handed coordinates, and some is left handed?

  • ✇Recent Questions - Game Development Stack Exchange
  • How do I fix java.lang.ClassNotFoundException: org.lwjgl.glfw.GLFWDoggo4
    I have not used Java in a while and thought I might try LWJGL with OpenGL and GLFW. I am using Apache Maven as a Build System. It lets me compile the program, but when I run it, it says: Exception in thread "main" java.lang.NoClassDefFoundError: org.lwjgl/glfw/GLFW at com.OpenGLTest.app.Main.main(Main.java:25) Caused by: java.lang.ClassNotFoundException: org.lwjgl.glfw.GLFW at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java.641) at java.base/jdk.int
     

How do I fix java.lang.ClassNotFoundException: org.lwjgl.glfw.GLFW

I have not used Java in a while and thought I might try LWJGL with OpenGL and GLFW. I am using Apache Maven as a Build System. It lets me compile the program, but when I run it, it says:

Exception in thread "main" java.lang.NoClassDefFoundError: org.lwjgl/glfw/GLFW
    at com.OpenGLTest.app.Main.main(Main.java:25)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.glfw.GLFW
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java.641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
    ... 1 more

My code is:

// Main.java
package com.OpenGLTest.app;

import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.system.*;

import java.nio.*;

import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;

public class Main {

  private static long window;
  private static final int WIDTH = 800;
  private static final int HEIGHT = 600;
  private static final String TITLE = "OpenGL Window";

  public static void main(String[] args) {
    // CHECK
    if (!glfwInit()) {
      System.err.println("ERROR: GLFW IS NOT INSTALLED");
      System.exit(-1);
    }
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

    glfwWindowHint(GLFW_VISIBLE, 0);
    glfwWindowHint(GLFW_RESIZABLE, 0);

    window = glfwCreateWindow(WIDTH, HEIGHT, TITLE, NULL, NULL);
    if (window == NULL) {
      System.err.println("ERROR: FAILED TO CREATE GLFW WINDOW");
    }

    glfwMakeContextCurrent(window);

    glfwShowWindow(window);
  }
}

My LWJGL version is 3.3.3 My JRE is 17

I am sorry if the answer is obvious. Somehow the only kinda answer I found on the internet is http://forum.lwjgl.org/index.php?topic=6994.0:

https://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java

How to solve this entirely depends on how you invoke the java command, whether you use an >IDE and which one you use, whether you use the Java 9+ Module System or the classpath and >whether you use a Java build system (like Maven, Gradle, Ant+Ivy).

❌
❌