JOGL - FPS and Fly Through Code

I took the following First Person Shooter (FPS) OpenGL control code and converted it to JOGL (with some limits) and also expanded it a bit.

http://www.codesampler.com/oglsrc/oglsrc_5.htm#ogl_fps_controls

I did not implement the “speed” based portion of the FPS control in the code above but it should be easy for someone to add it if they like. I actually expanded the code a little bit passed just FPS use. In FPS, you pretty much assume you have a flat world and you can fly up and down in the world along the look/view vector but in the code your up vector is pretty much always aligned with the world vertical - this means you have some limitations like the inability to roll around the view axis, etc. I added this to the code and basically got rid of the world vertical axis and made every local to the “camera” that you are moving around in the system. This means you can roll around and when you’ve rolled your mouse and keyboard motions are always relative to the new look and up vectors. Any way…check out the code - I’ll attach it in 2 parts because of the limit of attachments per post.

NOTE: There are 6 files to download…the other 2 are in the second post.

The other 2 files and a control summary:

Controls are:
Keyboard F - toggle between FPS and Modified FPS modes

Keyboard UP - moves the camera into the screen
Keyboard DOWN - moves the camera back
Keyboard LEFT - moves the camera to the left (teapot goes to the right)
Keyboard RIGHT - moves the camera to the right (teapot to left)
Keyboard PAGE_UP - moves the camera up along global Y axis (teapot goes down) (not “current” y axis of the view)
Keyboard PAGE_DOWN - moves the camera down along global Y axis

Keyboard COMMA - roll left (valid only in the modified FPS view)
Keyboard PERIOD - roll right (valid only in the modified FPS view)

Mouse Controls - Click and Hold left mouse button to orient the view vector.

Combination of holding down mouse button and keyboard up/down/left/right keys makes you fly through the scene.

If you rotate the view in the FPS mode then the left-right mouse motion causes a rotation about the fixed vertical axis of the original scene.

If you rotate the view in the Modified FPS mode then the left-right mouse motion causes a rotation about the current UP vector of the view…this lets you basically fly through the scene and rotate in all different directions…it is awesome (I think)

I’d appreciate any comments you have…if people are interested I can provide some updates that I made, such as removing the restriction for page up/down motion to be along the global vertical axis, and also I added the capability to hold down two keys (eg left and fwd) so that motion can be coupled. Anyway, if this is helpful then let me know.

Why don’t you explicitly enable double buffering and hardware acceleration when creating a GLCapability instance?

Pretty cool! Can you put it in .java files and then a .jar instead of a bunch of .txt files?

I couldn’t attach .java or .jar files…basically, take the .txt files and rename them all to .java and put them under the same project and you should be able to compile and run it without a problem…don’t forget to include the JOGL jars.

Probably because I actually don’t know what I’m doing … can you elaborate and suggest what I need to do? Did I just miss a ‘capability’ flag that would improve the speed of my code? I’m not surprised if I did because I started working with an example JOGL code at some point that probably didn’t have the necessary bits set and I never went back to check, thank you for finding improvements…but please do post your suggestion so I can add it. Thanks.

Since I posted the code above I have made some improvements…namely I created a Camera class to handle the camera and added other functionality… so if anyone is interested, an improvement version of the code is available here for download:

http://www.zaczek.com/jogl/TestFPS_Camera/TestFPS_Camera.zip

If you want to run a slightly previous version of the code you can use this java webstart: http://www.zaczek.com/jogl/TestFPS_Camera.jnlp...the major difference between the two is that the zip file contains slight improvements and some extra testing things like 3D spheres in the view, etc…nothing major.

Look at my source code, in the class main.GameController, in the constructor, then you will see what I mean.

Thanks…got them:


	    capabilities.setDoubleBuffered(true);//enables double buffering
	    capabilities.setHardwareAccelerated(true);//enables hardware acceleration

hopefully this speeds up my current tools.

Fine ;D
Don’t forget that my source code is under GPL license. As you have used a part of it and GPL has a viral clause, you have to put your own code into GPL too, except if you don’t want to release your source code anymore and then to keep it for you.

Please don’t spread GPL-covered code in this unfair fashion. Tell about GPL beforehand. I don’t have anything against GPL, I use GPL programs, I create them, I just don’t like the unfair behaviour to promote it.

Also remember that people can freely look into GPL code and learn how things are done and then use that knowledge (not any code) to write their own applications without need to use GPL for their work, GPL doesn’t and can’t protect that. From the code fragment above, it would be very very hard to enforce GPL, as it’s just two very simple calls to another library.

BTW, why are you limiting to GPLv2 only? It’s pretty bad thing for future (and present too, when GPLv3 is already available for long time), for example I can’t use any of your code in my GPLv3 application at all.

WOW… Talk about trying to sucker someone into using your license…

I have nothing against GPL v3. Vincent Stahl’s code was under GPL v2, I have kept the same license but I might go to GPLv3 in some months as it offers a better protection.

It is not unfair, I have put some lines at the beginning of each file to explain that I use the GPL. If someone look at my source code, he can’t miss it.

I don’t hide anything, it is easy to see that my source code is under GPL. Therefore, don’t use the word “sucker” to speak about me. My project is on sourceforge; when you see this, it is logical that I might use an open source license that might be viral and as I said above, there is a short explanation in the beginning of each file to show the chosen license, it is absolutely clear, I don’t try to sucker anyone!!!

Ah sorry, I should’ve explained it more. I’m comfortable with either version. What disturbs me (and there are other softwares out there with this), when someone clears the “either version 2 of the License, or (at your option) any later version.” sentence. This is required to allow usage of code under newer versions of GPL, especially when the code contains many contributions, it complicates changing license by original author to newer version.

Yes, it’s clearly visible, that’s not issue and it’s well done. I just had bad impression when you said to look into your source codes and when the original poster found it useful, you “catched” him with GPL.

On the surface that would look bad to have done that, but I don’t believe he did - I believe he was joking. I don’t know licenses and I really don’t care, but the 2 lines that I retrieved from him are nothing more than simple, common and accepted practices in JOGL and in general in OPENGL. So I don’t believe one can claim that GPL xxx code was really used (or whatever it is) and if that is the case, and that is the way things are then I will simply remove that code. If that was gouessej intent to trap someone or catch someone into using GPL then that is a low way to do it on a forum such as this where we are here to help people…that is why I posted my code for everyone to see instead of just hiding it away.

So, now that I posted the two lines of code, though they are trivial and found in many JOGL codes not under license, is anyone reading this post and reading the associated license discussion bound by the GPL license - especially if they didn’t have those capabilities set and go now and set them in their code? Sigh…I wish people would just help others and not expect something in return in the form of acknowledgement, royalty, etc, etc, etc.

[quote]Yes, it’s clearly visible, that’s not issue and it’s well done. I just had bad impression when you said to look into your source codes and when the original poster found it useful, you “catched” him with GPL.
[/quote]
My thoughts exactly…

[quote]So, now that I posted the two lines of code, though they are trivial and found in many JOGL codes not under license, is anyone reading this post and reading the associated license discussion bound by the GPL license - especially if they didn’t have those capabilities set and go now and set them in their code? Sigh…I wish people would just help others and not expect something in return in the form of acknowledgement, royalty, etc, etc, etc.
[/quote]
Agreed. People should offer advice for the sake of helping one another and thats it…

I agree that his comment was very funny lol ;D

Please try to understand the story of TUER. In 2002, Jonathan Thomas wrote Java Maze and put the source code under GPL. In 2004, Vincent Stahl reused the source code of Java Maze to create Art Attack. In october 2006, Julien Gouesse (me ;D) began the project TUER by reusing the source code of Art Attack. We have used the GPL license to protect the freedom of anyone to reuse freely our source code, not to earn money, nor for glory neither for royalties, we want to prevent anyone from confiscating the right to reuse our source code, it is a copyleft, we don’t force anyone to mention our names, we only want to prevent anyone from preventing us to share our knowledge, that’s why we use the GPL license, that is a way of protecting our solidarity. Is there anything wrong with this?

I have no problem with you wanting to protect your code, I think I have a problem more with GPL and what little I understand of it and what little I care to understand of it. My problem is with a license that forces one to release all of their code just because they made an addition to it from another licensed code. What would stop someone from making a generic and barebones java class template and putting that under GPL and posting it to the net and then anyone who happened to create a java class that looked remotely like that template would be forced to then open up all of their code!!! That would never ever fly…I’m guessing that is not what the GPL license forces upon people and if it does then that is very scary.

Regarding the lines of code I got from you…you can have them back. It seems like you were more serious than joking in your statement that I have to release my code and in that case I wish to not use your code and instead I will find other open-source solutions - which likely will look EXACTLY the same, but where I won’t be forced into a crazy licensing issue…hmm, I’m guessing the Javadocs would be a good source that I should have tried first instead of using someones code only to be “trapped” into a licensing fight. I actually believed that you were only joking about the licensing because the lines I used were trivial in both the literal and legal sense but your comments since then seem to imply that you were being fully serious and wanting me to comply with the licensing…sorry, I don’t play that. And, as a result of this issue, I believe that we should explicitly put forth some forum requirement that forces any posts to be license free or else you don’t post here…especially in a section called “Shared Code”

Relax, please relax :slight_smile: GPL is not that viral, it even can’t be. The code must be derived from it, and it mustn’t be trivial or widely used like your example or the specific code fragment we talk about… you can read more about GPL in the license itself (doh!) or check GPL FAQ.

As a side note, if you wish to fear, there are always the software patents :P, that allows these scary things like you’ve mentioned (patenting obvious things or things that are easily “invented” by many people). In reality there is no other chance than to ignore them unless you’re big corporation, because even with simple program you might infringe many of them and you can’t even know which ones.