Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  3D Camera with modern OpenGL  (Read 1484 times)
0 Members and 1 Guest are viewing this topic.
Offline PandaMoniumHUN
« Posted 2013-12-23 20:53:26 »

Hey guys.
First of all merry christmas and happy holidays to everyone on the forum! Cheesy
Currently I'm trying to write my own engine on top of LWJGL to understand modern OpenGL better and get some basics down but I'm stuck at the part of writing a 3D camera.
The only decent tutorial I managed to find on the subject is this: (it's for WebGL but it's really easy to port it to LWJGL).
I've tried to make my own camera class based on the tutorial but it produces weird effects (turns models upside down and such) so I obviously mess up somewhere, the only question is where?! Huh

Here are my classes: - (an instance of the camera class) -
In the vertex shader the vertex position get's calculated as follows: projectionMatrix*viewMatrix*vec4(in_Position, 1.0);
, where in_Position is a vec3 of the vertex's local position. Currently I'm not using model matrices but I will implement that later.

If I understand the tutorial correctly to get the forward vector (or z axis vector) I have to subtract the target vector from the camera position vector, then normalise the result.
To get the right vector (or x axis) I have to take the cross product of my forward vector and a unit vector that points upwards on the Y axis.
To get the real up vector (or y axis) I have to take the cross product of the up and the right vector and voilá.
Of course to get the backward, left and down vectors I just have to negate the appropriate vectors.
After I did this all to apply the transformations I can just fill up a 4x4 matrix with the given data and use it as my view matrix.
However, as you can see in my code I do exactly this and it just doesn't seem to work.
Any help would be very much appreciated since I'm trying to solve this problem for quite a few hours now.

Jumpbutton Studio - INOP Programmer
Can't stress enough: Don't start game development until you haven't got the basics of programming down! Pointing
Offline Slyth2727
« Reply #1 - Posted 2013-12-23 21:56:58 »

Hey, merry christmas to you too  Smiley

I suggest you check out this tutorial here, made by one our members:

I learned it using this article. Honestly you probably just messed up your matrices somewhere, and there's no shame in that.

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline PandaMoniumHUN
« Reply #2 - Posted 2013-12-24 12:28:35 »

Thank you very much, using your link I've managed to get the camera working in just a few minutes. Cheesy
It seems like quite a basic camera, but now that at least I have something to go around with in my scene and observe the models I guess I'll have time to expand it later on. Cool

Jumpbutton Studio - INOP Programmer
Can't stress enough: Don't start game development until you haven't got the basics of programming down! Pointing
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline PandaMoniumHUN
« Reply #3 - Posted 2013-12-25 14:14:29 »

I've added quite a few things to the camera, however I can't seem to figure out how should I move it on the y axis as well (the tutorial you linked moves the camera only on the Z and the X axis).
Of course I'm not talking about increasing the or decreasing the Y value of the camera but when I move forward or backward with the camera I would like my height to increase/decrease depending on my rotation on the X axis. I've tried adding something like this to the move method:

position.y += amount*Math.sin(Math.toRadians(rotation.x+90*direction));

but it obviously doesn't work (I have no idea what I'm doing, damn you trigonometry *sigh*  Emo).
Anyone could help me out on getting this right and hopefully understanding the math behind it? Smiley

Edit: Okay, I've got it working, so far everything seems to be okay. If anyone is interested I did it this way:
if(direction == 1f)
   position.y += amount*Math.sin(Math.toRadians(rotation.x));

This way it only increases the Y value if you're moving on the Z axis (so if you just want to move sideways it won't be modified).
Still pretty much have no idea about the math behind it, I'm pretty much okay with vectors in 2D but when it comes to 3D it just almost always gets too complicated for me.
Probably will pick up a book on algebra and trigonometry. Stare

Jumpbutton Studio - INOP Programmer
Can't stress enough: Don't start game development until you haven't got the basics of programming down! Pointing
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.


Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (12 views)
2014-08-28 18:26:30

CopyableCougar4 (24 views)
2014-08-22 19:31:30

atombrot (37 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (29 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (28 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (33 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!