Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  JOGL - FPS and Fly Through Code  (Read 11794 times)
0 Members and 1 Guest are viewing this topic.
Offline Z-Knight

Senior Devvie


Medals: 2



« Posted 2008-07-14 00:30:54 »

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.
Offline Z-Knight

Senior Devvie


Medals: 2



« Reply #1 - Posted 2008-07-14 00:32:09 »

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.
Offline gouessej
« Reply #2 - Posted 2008-09-30 07:44:04 »

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #3 - Posted 2008-09-30 16:24:25 »

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

See my work:
OTC Software
Offline Z-Knight

Senior Devvie


Medals: 2



« Reply #4 - Posted 2008-10-02 15:33:57 »

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.


Offline Z-Knight

Senior Devvie


Medals: 2



« Reply #5 - Posted 2008-10-02 15:41:15 »

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

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.
Offline Z-Knight

Senior Devvie


Medals: 2



« Reply #6 - Posted 2008-10-02 16:14:26 »

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.
Offline gouessej
« Reply #7 - Posted 2008-10-02 18:13:52 »

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.
Look at my source code, in the class main.GameController, in the constructor, then you will see what I mean.

Offline Z-Knight

Senior Devvie


Medals: 2



« Reply #8 - Posted 2008-10-02 18:22:05 »

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

Thanks...got them:

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


hopefully this speeds up my current tools.
Offline gouessej
« Reply #9 - Posted 2008-10-03 05:46:54 »

Thanks...got them:

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


hopefully this speeds up my current tools.
Fine  Grin
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.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jezek2
« Reply #10 - Posted 2008-10-03 09:16:18 »

Fine  Grin
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.
Offline Majick

Senior Newbie





« Reply #11 - Posted 2008-10-03 12:23:32 »

WOW..... Talk about trying to sucker someone into using your license........
Offline gouessej
« Reply #12 - Posted 2008-10-03 12:34:23 »

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.
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.

Please don't spread GPL-covered code in this unfair fashion.
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.

WOW..... Talk about trying to sucker someone into using your license........
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!!!

Offline jezek2
« Reply #13 - Posted 2008-10-03 14:34:43 »

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.
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.

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.
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.
Offline Z-Knight

Senior Devvie


Medals: 2



« Reply #14 - Posted 2008-10-03 14:46:58 »

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.

Offline Majick

Senior Newbie





« Reply #15 - Posted 2008-10-03 16:46:08 »

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.

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.

Agreed.   People should offer advice for the sake of helping one another and thats it....
Offline irreversible_kev

Junior Devvie





« Reply #16 - Posted 2008-10-03 18:50:09 »

On the surface that would look bad to have done that, but I don't believe he did - I believe he was joking.

I agree that his comment was very funny lol  Grin
Offline gouessej
« Reply #17 - Posted 2008-10-03 20:05:53 »

I wish people would just help others and not expect something in return in the form of acknowledgement, royalty, etc, etc, etc.
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 Grin) 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?

Offline Z-Knight

Senior Devvie


Medals: 2



« Reply #18 - Posted 2008-10-03 20:40:33 »

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 Grin) 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"
Offline jezek2
« Reply #19 - Posted 2008-10-03 21:12:24 »

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.   

Relax, please relax Smiley 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 Tongue, 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.
Offline gouessej
« Reply #20 - Posted 2008-10-03 21:24:03 »

It seems like you were more serious than joking in your statement
No it was a joke but I use it as an occasion to explain why I use the GPL license.

GPL is viral in that way:
Quote
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force.

As it is not clear, I explain it again, I use GPL to encourage people to share. In France, some corporations have been prosecuted because they violated this license. I'm not going to bother someone for 2 lines. If I share some source code, I expect that people that use it will share them too, I would find it unfair if someone uses an open source code to write a closed source code.

Offline Z-Knight

Senior Devvie


Medals: 2



« Reply #21 - Posted 2008-10-03 21:28:03 »

I'm completely relaxed...I don't have any problems or concerns here.  Probably because I don't believe in licenses but I do believe in ethics.  If I use a code I will give credit.  If the code is non-trivial then I would adhere to the wishes of the originator and then likely go forth and develop my own code without having to use the original and hence I will not give any credit to the inspiration.  If the code is trivial I will still give credit but I will not feel obligated to anyone.

In my opinion, software licenses are what stifle development and progress....but I understand the need for some protection and I don't have any better alternatives.

Can we end this now...my original FPS code post is now a damn licensing post.
Offline gouessej
« Reply #22 - Posted 2008-10-03 21:38:03 »

Can we end this now...my original FPS code post is now a damn licensing post.
Yes, your source code is beautiful, keep the 2 lines; even for a non trivial code, I don't ask anyone to quote me.

About your source code, do you think it is slower to build the model-view matrix by yourself rather than using gluLookAt? One of my teachers asked me this question some years ago.

Offline Z-Knight

Senior Devvie


Medals: 2



« Reply #23 - Posted 2008-10-03 21:46:06 »

hmm...I don't know...tough question since I've never looked at the gluLookAt code to see how they implement things.  You'd have to add up the various math calculations that are required for each of the two methods. 
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.

rwatson462 (33 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (51 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (45 views)
2014-12-05 12:39:02

SHC (59 views)
2014-12-03 16:27:13

CopyableCougar4 (58 views)
2014-11-29 21:32:03

toopeicgaming1999 (123 views)
2014-11-26 15:22:04

toopeicgaming1999 (114 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
java-gaming.org 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‑gaming.org
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!