Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (710)
Games in Android Showcase (212)
games submitted by our members
Games in WIP (784)
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  
  Rotating libgdx Camera based off of Azimuth, Pitch and Roll  (Read 1744 times)
0 Members and 1 Guest are viewing this topic.
Offline wreed12345

JGO Knight

Medals: 28
Projects: 3
Exp: 2 years

« Posted 2014-03-28 23:01:12 »

Hey guys! I wanted to create a little app / game based off of the way the user is holding the phone (sort of like an augmented reality to help you understand what I am trying to do) and that from my research will depend largely on the compass ( I also managed to find this page but the CompassTest is no longer in the libgdx project for some reason. I managed to find which shows sort of how to do what I am asking but a lot of it is left unexplained and I know the 3d part of libgdx has changed greatly since the time that the post was written. If this code is possibly helpful I would appreciate it if someone could explain it or point me in the direction to rotate a PerspectiveCamera based off the compass. Since it wasn't for me this is what I came up with:

From my research and testing I have come up with this but it only seems to work if I want to use one axis at a time.
//azimuth example
float deltaAzimuth, lastAzimuth;

public void render(float delta){
    //the actual drawing stuff is here
   deltaAzimuth = (Gdx.input.getAzimuth() - lastAzimuth);
   camera.rotate(camera.up, -deltaAzimuth);
   lastAzimuth = Gdx.input.getAzimuth();

//roll example
float deltaRoll, lastRoll;

public void render(float delta){
   deltaRoll = (Gdx.input.getRoll() - lastRoll);
   camera.rotate(new Vector3(camera.up).crs(camera.direction).nor(), deltaRoll); //creates right vector
   lastRoll = Gdx.input.getRoll();

If I choose one to use it seems to work very well. But when I combine both azimuth and roll it does not work so well... That may be because I am missing the pitch in this. I attempted to implement pitch with the same deltaPitch and lastPitch aproach but the values appear to be in the range of [-90, 90] rather then the azimuth and roll which have the range of [-180,180]. If I combine both roll and azimuth and I shake my android phone things sort of seem to spin around which is hard to describe. All I know is that shaking my phone should not cause this effect. I figured it may be a problem with the cross product calculation but so far no luck with anything. If you see anything apparent or have suggestions please let me know. Thanks!

p.s. Once I finish this I plan on documenting everything and releasing a public source code git repo since everything has been rather difficult for me to find and I would rather other people not to go through this

Offline wreed12345

JGO Knight

Medals: 28
Projects: 3
Exp: 2 years

« Reply #1 - Posted 2014-03-28 23:21:40 »

I just tried combining azimuth and pitch which has an interesting result. I know the pitch doesnt exactly work to begin with with this implementation as described above but the shaking bug thing does not occur when these are combined. When using pitch i rotate along the camera.direction axis which leads me to further believe that the cross product calculation in the roll example above is causing something to go wrong and the spinning effect once the phone is shaken...

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

theagentd (111 views)
2017-02-18 13:42:33

theagentd (115 views)
2017-02-18 13:35:16

h.pernpeintner (1279 views)
2017-01-24 22:39:11

h.pernpeintner (1267 views)
2017-01-24 22:38:32

Galdo (1827 views)
2017-01-12 13:44:09

Archive (1931 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2469 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2301 views)
2016-12-15 21:50:57

Lunch (2380 views)
2016-12-06 16:01:40

ral0r2 (2156 views)
2016-11-23 16:08:26
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 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!