LWJGL Forum

Please login or register.

Login with username, password and session length
Pages: 1 [2] 3 4 ... 10
 11 
 on: April 24, 2017, 14:40:05 
Started by Spytrycer - Last post by Kai
I've augmented the FreeCameraDemo with a "third person" view. Toggle with 'T'. Please check, if that is what you want.
Change set: https://github.com/JOML-CI/joml-lwjgl3-demos/commit/c36beed60a3a2181c64fe754b741400703b393cc

 12 
 on: April 24, 2017, 13:08:42 
Started by dzolo - Last post by dzolo
Hi,

I am trying to enable multisampling for a AWTGLCanvas that is places inside a Java Swing JFrame.

Until now I have no success to do so. I found an old thread that solved this within an Applet (http://forum.lwjgl.org/index.php?topic=1889.msg11119). But setting the PixelFormat as described in that post has no effect.

Do you please have any other tips to get the multisampling working?

Thanks
Ondrej

Update: Added code sample.

Code: [Select]
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.gluOrtho2D;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.AWTGLCanvas;
import org.lwjgl.opengl.PixelFormat;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class CanvasTest {

  public static class CustomAWTGLCanvas extends AWTGLCanvas {

    public CustomAWTGLCanvas() throws LWJGLException {
      super(new PixelFormat(8, 8, 0, 4));
    }

    @Override
    public void paintGL() {
      try {
        glViewport(0, 0, getWidth(), getHeight());
        glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D(0.0f, (float) getWidth(), 0.0f, (float) getHeight());
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glColor3f(1f, 1f, 0f);
        glTranslatef(getWidth() / 2.0f, getHeight() / 2.0f, 0.0f);
        glRotatef(51f, 0f, 0f, 1.0f);
        glRectf(-50.0f, -50.0f, 50.0f, 50.0f);
        glPopMatrix();
        swapBuffers();
      } catch (LWJGLException ex) {
        ex.printStackTrace();
      }
    }
  }

  public static void main(String[] args) throws LWJGLException {

    CustomAWTGLCanvas canvas = new CustomAWTGLCanvas();

    JPanel panel = new JPanel(new BorderLayout());
    panel.setMinimumSize(new Dimension(100, 100));
    panel.add(canvas);

    JFrame frame = new JFrame("AWTGLCanvas - multisampling");
    frame.setPreferredSize(new Dimension(640, 480));
    frame.add(panel);
    frame.pack();

    frame.setVisible(true);
  }
}

 13 
 on: April 24, 2017, 12:09:50 
Started by Spytrycer - Last post by Kai
Okay, if you want a "third-person camera" which always follows the player by keeping a fixed distance to the player and always has the same position relative to the player, then do the following:
1. build the view matrix V as usual (like shown in the FreeCamera/FreeCameraDemo)
2. for rendering the player, you need to have: V x V^-1 x T = T
   where:
     - V is the camera matrix built in step 1
     - V^-1 is the inverse of V (can compute with Matrix4f.invert())
     - T is the translation that positions the camera relative to the player
     - 'L x R' means: multiplying 'L' by 'R' (for example via Matrix4f.mul())
3. for rendering everything else, you need to have: T x V x M
   where:
     - T is the same T as above (the position of the camera relative to the player)
     - V again is the camera matrix built in step 1
     - M is the respective object's model transformation

At this point, you need to have a more thorough understanding of coordinate systems and linear algebra (i.e. for transformation matrices).
If you like to start with the basics, you can have a look at Khan's Academy Course "Linear Algebra" (beware: it'll teach you really fundamental and essential stuff which is not focused on computer graphics alone, and is also university-grade, which can be hard to follow at times).
Other good resources are:
- http://www.songho.ca/opengl/gl_transform.html
- https://processing.org/tutorials/transform2d/ (even if it is for 2D, it can be generalized to 3D)
- http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/

 14 
 on: April 24, 2017, 03:53:50 
Started by Spytrycer - Last post by Spytrycer
Ok, thats great help, I implemented the Code for the Positioning and it works perfectly!

And i dont think i want an Arcball Camera, im sorry, i might have spoken too wierd :)

What i want the Camera to do is to follow around the Player in every Movement.
The Player moves like a FreeCamera and the Camera follows behind.
What i dont want is to just move the Camera in the Function i call the Playermovement, i want the camera to move BASED on the players position and Rotation.

And that works just fine, at least for the Rotation. Just the Translation doesnt want to work.

GIF of Movement Example
blob:http://imgur.com/7ff0818b-3cef-4e1a-84a4-c6f8e7cdd6e6

As you see in the Gif, its all working, but the Camera class is not moving.
Or to be precise, it is moving but its being reset everytime, which makes this wobbling and glitching kinda thing.

As i mentioned earlier, i tried a translation of just 1,1,1 and it was doing this glitching back and forth the whole time.

I dont know why it is not translating the Cameras position.
I checked the Values i give into the translation, i even checked if that changes the position i get with your method and the Position doesnt seem to change.

For Position.Z for example it just takes the Value of the Differential Change.
The System.out.print for position.z looks like this:
Code: [Select]
0.13825268
0.11797666
0.17785572
0.15799287
0.13815312
0.11804388
0.17783828
0.1583886
0.13771991
0.11774414
0.17758986
0.15768081
0.13756388
0.117652275
0.17749798
0.15764795
0.13755158
0.11771437
0.17732398
0.15786403
0.13733652
0.11720933
0.18107897
0.15739237
0.1567626
0.13690487
0.11675202
0.17704684
0.15671691
0.13668469
0.11680386
0.1767394
0.16356169
0.16142154
0.11668632
0.17648327
0.15750836
0.13646758
0.11657392
0.17649148
0.15631811
0.13650659
0.116476916

Looks pretty much just like
Code: [Select]
dt * player.linearVel.x
Here is my viewMatrix:

Code: [Select]
public void move(double delta)
{


float dt = (float)delta;

//linearVel.fma(dt, linearAcc);

    //angularVel.fma(dt, angularAcc);
this.angularVel.x = player.angularVel.x;
    this.angularVel.y = -player.angularVel.y;
    this.angularVel.z = player.angularVel.z;

this.Rotation.x += dt*angularVel.x;
    this.Rotation.y += dt*angularVel.y;
    this.Rotation.z += dt*angularVel.z;
   
    linearVel.x = dt * player.linearVel.x;
    linearVel.y = dt * player.linearVel.y;
    linearVel.z = dt * player.linearVel.z;
   

    viewMatrix
    .rotateLocalX((float)Math.toRadians(dt*angularVel.x))
        .rotateLocalY((float)Math.toRadians(dt*angularVel.y))
        .rotateLocalZ((float)Math.toRadians(dt*angularVel.z))
    .translateLocal(linearVel.x,linearVel.y, linearVel.z);

   
    viewMatrix.getTranslation(position); // <- store entity's position

}


And BTW, is there a way to do
Code: [Select]
model.getTranslation(position);
With the Entities or cameras Rotation too?



 15 
 on: April 23, 2017, 19:42:28 
Started by bcbradle - Last post by bcbradle
Sweet thanks for all your help, vulkan in clojure is going to rock :)

 16 
 on: April 23, 2017, 19:37:04 
Started by bcbradle - Last post by spasi
Raw pointers are considered "unsafe" in LWJGL, so methods that accept them are prefixed with 'n'. The method you're looking for is MemoryUtil.nmemFree(long). Example:

Code: [Select]
PointerBuffer pp = ...;
for ( int i = 0; i < pp.remaining(); i++ ) {
    nmemFree(pp.get(i));
}
memFree(pp);

I don't know how memory allocations are done on the native side in lwjgl

The MemoryUtil methods directly call the corresponding method of the native memory allocator. The only utility they have is that the memory allocator is configurable; you can try another implementation without changing your program. By default, if the bindings are available, jemalloc will be used as the memory allocator. Otherwise, the default system allocator is used. I would like to try rpmalloc soon, it'd be nice to have a third option if it's competitive. Btw, you also have the option of using one allocator via MemoryUtil and another by using the corresponding bindings directly (via org.lwjgl.system.libc.LibCStdlib and org.lwjgl.system.jemalloc.*).

 17 
 on: April 23, 2017, 19:18:23 
Started by bcbradle - Last post by bcbradle
Yes, only the pointer is necessary to free an allocation.

how would you do it then?

I mean i know how to free a PointerBuffer instance foo using foo.free(), but what about all the buffers the PointerBuffer instance foo contains?

foo.get() returns a long (presumably the address of the current buffer stored), but can you use that to free anything? I'm looking inside MemoryUtil but can't find anything that would allow me to free an arbitrary address.

I was thinking of maybe doing foo.getByteBuffer().free(), but there isn't any such method (only getByteBuffer(size)). I would have to know the size of the current buffer in bytes in order to free it this way.

It seems kind of odd though. I don't know how memory allocations are done on the native side in lwjgl, but the c function "free" doesn't require a size, only an address (assuming it was previously allocated with malloc, calloc or realloc). So I feel it would be strange if it weren't possible to free memory with just an address in lwjgl, and that is why I'm asking.

 18 
 on: April 23, 2017, 19:02:35 
Started by bcbradle - Last post by spasi
Yes, only the pointer is necessary to free an allocation.

 19 
 on: April 23, 2017, 16:08:44 
Started by bcbradle - Last post by bcbradle
Specifically, without knowing their lengths.

Basically I want to be able to free the pointer buffer and all the things pointed to by it given only the pointer buffer instance.

 20 
 on: April 23, 2017, 12:22:06 
Started by Spytrycer - Last post by Kai
You can separate the translation of your entity from its rotation and compose both together when building the final model transformation matrix. However, when you still want to move an entity along its own local "forward"/"right"/"up" axes, then you need to compute these vectors in world-space first.
Instead, an easier way is to keep everything like it is now, and compute the origin of the entity in world-space via:
Code: [Select]
Matrix4f model = ...; // <- the model transformation matrix of the entity
Vector3f position = new Vector3f(); // <- position will be stored in here
model.getTranslation(position); // <- store entity's position

It sounds that you want to have an "arcball" camera. Is that right?
If that is the case, then have a look at: https://github.com/JOML-CI/joml-camera/blob/master/src/org/joml/camera/ArcBallCamera.java

The important part of it is the order of transformations in the viewMatrix() method:
https://github.com/JOML-CI/joml-camera/blob/master/src/org/joml/camera/ArcBallCamera.java#L67-L70

You can throw all that ArcRotor/ScalarMover stuff out, as it is merely used to "smoothen" the rotation and translation of the arcball camera over time.

Pages: 1 [2] 3 4 ... 10