Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 328 times)
0 Members and 1 Guest are viewing this topic.
Offline wreed12345

JGO Knight


Medals: 24
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« 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 (https://github.com/libgdx/libgdx/wiki/Compass) I also managed to find this page http://www.badlogicgames.com/wordpress/?p=1490 but the CompassTest is no longer in the libgdx project for some reason. I managed to find http://stackoverflow.com/questions/5274514/how-do-i-use-the-android-compass-orientation-to-aim-an-opengl-camera 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.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
//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);
   camera.update();
   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
  camera.update();
   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: 24
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« 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  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

BurntPizza (22 views)
2014-09-19 03:14:18

Dwinin (35 views)
2014-09-12 09:08:26

Norakomi (62 views)
2014-09-10 13:57:51

TehJavaDev (89 views)
2014-09-10 06:39:09

Tekkerue (44 views)
2014-09-09 02:24:56

mitcheeb (65 views)
2014-09-08 06:06:29

BurntPizza (47 views)
2014-09-07 01:13:42

Longarmx (35 views)
2014-09-07 01:12:14

Longarmx (40 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
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
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!