Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  2 Axises 1 Degree?  (Read 500 times)
0 Members and 2 Guests are viewing this topic.
Offline CyanPrime

JGO Ninja
***

Posts: 683
Medals: 7



« on: 2010-04-30 18:42:37 »

I'm using Jinput and I'm trying to learn how to use my controllers joysticks. Now each one seems to give me two axises but I don't know how to turn the axis numbers uinto a degree.  Can anyone please help me?
Online Nate

JGO Neuromancer
****

Posts: 1062
Medals: 30


mooooo


« Reply #1 on: 2010-04-30 20:12:02 »

I believe Component#getPollData gives you a float between -1 and 1. Joysticks don't know about degrees, just percentage of maximum deflection.

FWIW, here is a class I use for an Xbox 360 controller:
http://code.google.com/p/pg3b/source/browse/trunk/Java/src/com/esotericsoftware/controller/input/JInputXboxController.java
Maybe you can make some use of it or borrow some code. Other classes in that project can access the Xbox controller through the XInput Windows API.

Offline CyanPrime

JGO Ninja
***

Posts: 683
Medals: 7



« Reply #2 on: 2010-04-30 22:46:01 »

Alright, Thanks ^_^ I think I got it: (Math.toDegrees(Math.atan2(-axisa2, axisa1)) + 180)
Games published by our own members! Go get 'em!
Offline Markus_Persson

JGO Kernel
*****

Posts: 2092
Medals: 10


Mojang Specifications


« Reply #3 on: 2010-05-01 03:43:55 »

Math.toDegrees(Math.atan2(-axisa2, axisa1)) + 180

is the same as

Math.toDegrees(Math.atan2(axisa2, -axisa1))

Play Minecraft!
Offline JuddMan

Sr. Member
**

Posts: 285


Your Ad Here


« Reply #4 on: 2010-05-01 06:07:15 »

Also

C2 = A2 + B2

Gives you how far the stick is tilted in its current direction.

dist = sqrt(axisx * axisx) + (axisy * axisy)

See, high school math is useful in the real world...
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.098 seconds with 19 queries.