How to move around camera in JOGL 2.0?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

How to move around camera in JOGL 2.0?

Lawa
Hi ,
I'm creating a 3D room using JOGL 2.0 ( as I said before in my previous post I know it is absolute and everything but I have to do it with this version as its the only available option ) anyways , I have created some objects using GL_QUADS and textured them , but the problem begins when I try to navigate through them with the camera , I made this based on a tutorial from a book , but I can't do the same for my objects , as in my program I have to use ( glEnable(GL2.GL_DEPTH_TEST) ) and ( gl.glEnable(GL2.GL_TEXTURE_2D) ) in init() method for my objects to appear but when I enable DEPTH_TEST and TEXTURE_2D everything goes black and it does not show anything else..
I'm trying to make something like this (youtube demo video) and I can't find any sources on JOGL on how to do (at least) the camera movement or make the objects move towards you when you press W and back away when pressing S and so.

any help would be appreciated & in JOGL 2.0 please , I know it is deprecated but as I said it is my only option to do it, so suggesting "upgrading" the version will not be a solution for me.

P.S / I've done a lot of work onto it but the codes that I've written are useless and messy (as I used multiple classes) that's why I haven't uploaded them.

Thanks.
-Lawa
Reply | Threaded
Open this post in threaded view
|

Re: How to move around camera in JOGL 2.0?

jmaasing
I used this tutorial when learning modern OpenGL, it has some chapters about moving things (like the camera).
https://web.archive.org/web/20150215073105/http://arcsynthesis.org/gltut/
Reply | Threaded
Open this post in threaded view
|

Re: How to move around camera in JOGL 2.0?

gouessej
Administrator
In reply to this post by Lawa
Hi

I can help you to update your code which is mandatory as you won't get any help by using an obsolete version. Imagine that something doesn't work because you are bothered by a bug already fixed in the latest version, you will just uselessly stick to an old version with its old bugs and we'll be unable to help you except by ... telling you to switch to the latest version. It's not difficult, some classes have been moved from javax.media to com.jogamp, it's not the end of the world.

You can use this source code, it should work with JOGL 2.0 but I have to update it to work with JOGL 2.3.2 tonight:
http://stackoverflow.com/a/35093118
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How to move around camera in JOGL 2.0?

Lawa
In reply to this post by jmaasing
Thank you for the reply that helped me with understating the basics
Reply | Threaded
Open this post in threaded view
|

Re: How to move around camera in JOGL 2.0?

Lawa
In reply to this post by gouessej
Thank you for the offer , well I had to upgrade my JOGL version finally I noticed few minor changes which were some class changes as you mentioned such as replacing com.sun.opengl.util with com.jogamp.opengl.util and so , and thank god now the camera problem is solved, however I'm currently working on creating a skybox for the world around the room or the objects I'm trying to create , is there any tutorials about that ?
Reply | Threaded
Open this post in threaded view
|

Re: How to move around camera in JOGL 2.0?

gouessej
Administrator
It's explained here:
https://www.opengl.org/wiki/Skybox
http://ogldev.atspace.co.uk/www/tutorial25/tutorial25.html
https://en.wikipedia.org/wiki/Cube_mapping

You have to move the skybox with the player so that it's always visible.

You can use a cube map or just draw 6 quads like here:
http://www.java-forums.org/java-gaming/50498-skybox-opengl.html
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How to move around camera in JOGL 2.0?

Lawa
Thanks for the quick reply !
so as I read in the links you provided I have to create 6 different sides ( make a cube out of quads ) , but then they have to be on the farthest point that the camera won't be able to reach right? then if this is my working code for the camera, and now I want to build/show the objects into this class : https://codeshare.io/D95Oz
which points should be the point to create the quads into ? and why does the skybox have to move with the player (if you create it at the farthest point? )

Thanks!

Reply | Threaded
Open this post in threaded view
|

Re: How to move around camera in JOGL 2.0?

elect
This sample demonstrate the same in modern OpenGL
Reply | Threaded
Open this post in threaded view
|

Re: How to move around camera in JOGL 2.0?

Lawa
well seems like even the updated version of my JOGL can't recognize that .. http://i.imgur.com/2N41ivv.png

Can you suggest another example or how to apply this to my code (which I posted in the reply above) ?
Reply | Threaded
Open this post in threaded view
|

Re: How to move around camera in JOGL 2.0?

gouessej
Administrator
His example uses JOGL + his framework (including jgli).
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How to move around camera in JOGL 2.0?

elect
In reply to this post by Lawa
Yep, if you want it run, you have to include jglm and jgli, otherwise just look at the most important parts for you, that are:

- the sampler init (if you don't plan to use a sampler, you need to set all those parameters on the textures itself)

- the texture allocation and loading

- the fragment shader, here you have to pass a vec4 representing the direction you are looking at.

To calculate the direction you are looking at, you have to do something similar in the vertex shader. After calculating the well known and mandatory gl_Position, you should

 vec3 p = mv3x3 * vec3(position, 0.0);

here you do the almost the same, you need the position in world space, so your mv3x3 is

mat3 mv3x3 = mat3(transform.mv);

and you need just the orientation, so a mat3 is sufficient. Then he plays with the reflection, but this has no interest for your case. Just calculate the vector you are looking at in the i-th vertex as

normalize(p - transform.camera);

and pass it directly to the fragment shader

and you are done ;)