how to input joystick simply?

This is a discussion on how to input joystick simply? within the C++ Programming forums, part of the General Programming Boards category; Hi all, I want to input joystick to my code,which is very simple smile.gif.I searched the net but find out ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    1

    how to input joystick simply?

    Hi all,
    I want to input joystick to my code,which is very simple smile.gif.I searched the net but find out that people use DirectInput , etc... but i want a very simple application, for example like when you pull right, a variable in the code changes from 0 to 10,whne you pull left another variable changes from 2 to 8, etc... I use VC++ v6.0, no .NET,no C# please. here i send a sample code I wrote in which i wanna input joystick for some try. thank you everyone.

    Code:
    #include <time.h>
    #include <iostream>
    
    using namespace std;
    
    void wait ( double seconds )
    {
    clock_t endwait;
    endwait = clock () + seconds * CLK_TCK ;
    while (clock() < endwait) {}
    }
    
    int main()
    {
    
    double t;
    double delt;
    double delf;
    double function;
    
    cout<< "Derivative of the function : "<<endl;
    cin>>delf ;
    cout<< "Time deviation : "<<endl;
    cin>>delt;
    
    t=0.0;
    function=0.0;
    
    do {
    
    function = function+ delf*delt ;
    
    // here i want to add joystick reading here
    // joy1= ....???
    //joy2= .....???
    // like : when i move left,it reads 5 for joy1, and when i move right it reads 3 for joy2, etc...
    // moreover,it eould be superb if also i can read the value as how much i move joystick,
    //for example, when i move it from center to left end,joy1 value increases from 0 to 8.
    // PLEASE HELP //
    
    wait (delt);
    t=t+delt;
    cout<<" Function is "<<function<<endl;
    // modifed function with joystick input :
    //function=
    
    } while (t <= 40);
    return 0;
    }

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    1) Indent.
    2) Code is not always nice, and that's a fact of life.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Are you opposed to using DirectInput because of it's complexity? I'd say you should think of a better reason. A relatively simple wrapper class VC6 project, DX8, can be found right here: http://www.csh.rit.edu/~jon/projects/joystick/ manutd,[mod edit]please don't say anything[/mod edit] if you don't have anything substantial to say.
    Last edited by Ken Fitlike; 12-02-2006 at 06:43 AM. Reason: the profanity filter exists for a very good reason

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    you can use the plattformindependet SDL library, it handles joysticks too:
    http://docs.mandragor.org/files/Comm.../joystick.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input redirection
    By sashaKap in forum C Programming
    Replies: 6
    Last Post: 06-25-2009, 02:59 AM
  2. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 01:22 AM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 04:42 PM
  4. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 12:09 PM
  5. Custom Made Safe Input Function
    By Beast() in forum C Programming
    Replies: 6
    Last Post: 08-21-2004, 11:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21