About Store Forum Documentation Contact



Post Reply 
My Ps3 Joypad
Author Message
Barthap Offline
Member

Post: #1
My Ps3 Joypad
Hello all grin

Yesterday I managed to connect my Ps3 Controller (DualShock3, Sixaxis) with my computer. It didn't work well, but I found this. It's great! All buttons work perfectly.
Then it was time to add ps3 pads support to Esenthel. I made test application based on Tutorials/Advanced/Misc/Joypad Vibrations. Here it's source code of my Draw() function from that tutorial:
PHP Code:
D.clear(WHITE);
   
   
   if( 
Joypads()<=0                  )D.text(0, -0.4"No Joypads Detected");else
      if(!
Joypad[0].supportsVibrations())D.text(0, -0.4"Joypad #0 doesn't support Vibrations");else
      {
         
D.text(0, -0.9f"Press Keyboard Arrow Keys to Change Applied Force");
         
D.text(0, -0.6f   S+"Applied Force: "+force);
      }
   
   
FREP(32)
   {
        if(
Joypad->b(i))D.text(0,0.9,S+"Button "+i);
   }
   
D.text(00.8S+"Left Axis "+Joypad->dir_a[0]);
    
D.text(00.7S+"Right Axis "+Joypad->dir_a[1]);
    
D.text(00.6S+"DInput rx "+Joypad->dis.rx);
    
D.text(00.5S+"DInput ry "+Joypad->dis.ry);
    
D.text(00.4S+"DInput rz "+Joypad->dis.rz);
    
D.text(00.3S+"DInput slider0 "+Joypad->dis.slider[0]);
    
D.text(00.2S+"DInput slider1 "+Joypad->dis.slider[1]);
    
D.text(00.1S+"DInput x "+Joypad->dis.x);
    
D.text(00.0S+"DInput y "+Joypad->dis.y);
    
D.text(0, -0.1S+"DInput z "+Joypad->dis.z);
    
D.text(0, -0.2S+"Dir "+Joypad->dir); 

Now I'm working at custom Ps3 Controller support class. Current source code (not finished yet, variable and function names can be bad):
PHP Code:
//.h file
enum PS3PAD_AXIS
{
    
AXIS_X_PLUS 20,
    
AXIS_X_MINUS,
    
AXIS_Y_PLUS,
    
AXIS_Y_MINUS,
    
AXIS_NUM
};

class 
Ps3Controller
{
    
JoypadClass &joypad;
    
public:

    
Ps3Controller() : joypad(Joypad[0]) {}

    
//left and right joystick
    
bool Axis(PS3PAD_AXIS Axisbool LeftAxis trueFlt deadZone 0.1f);
    
//buttons
    
bool Btn(int BtnNumberbool Long true);
    
//L2 and R2 buttons
    
bool LR2(bool LeftFlt deadZone 0.2f);

extern Ps3;

//.cpp file
Ps3Controller Ps3;

bool Ps3Controller::AxisPS3PAD_AXIS Axisbool LeftAxis /*= true*/Flt deadZone)
{
    
Vec2 axis = (LeftAxis joypad.dir_a[0] : joypad.dir_a[1]);

    
//in right joystick X and Y axis are replaced (X is Y, Y is X)
        //this code repairs it
    
if(!LeftAxis)axis Vec2(axis.yaxis.x);

    switch(
Axis)
    {
    case 
AXIS_X_PLUS:
        if(
axis.deadZone)return true;
        break;
    case 
AXIS_X_MINUS:
        if(
axis.< -deadZone)return true;
        break;
    case 
AXIS_Y_PLUS:
        if(
axis.deadZone)return true;
        break;
    case 
AXIS_Y_MINUS:
        if(
axis.< -deadZone)return true;
        break;
    }
    return 
false;
}

bool Ps3Controller::Btnint BtnNumberbool Long /*= true*/ )
{
    
bool pressed = (Long joypad.b(BtnNumber) : joypad.bp(BtnNumber));
    return 
pressed;
}

bool Ps3Controller::LR2bool LeftFlt deadZone /*= 0.2f*/ )
{
    
bool pressed;
    if(
Left)
    {
        if(
joypad.dis.rx < -deadZone)pressed true;
        else 
pressed false;
    }
    else if(!
Left)
    {
        if(
joypad.dis.rx deadZone)pressed true;
        else 
pressed false;
    }
    return 
pressed;


How to use:
For tests I changed some Player moving code
PHP Code:
                    // turn & move
                
                    //input.turn.x=Kb.b(KB_Q)-Kb.b(KB_E);
                    //input.turn.y=Kb.b(KB_T)-Kb.b(KB_G);
                
                    
input.turn.x=(Ps3.Axis(AXIS_X_PLUSfalse0.3f)-Ps3.Axis(AXIS_X_MINUSfalse0.3f));
                    
input.turn.y=(Ps3.Axis(AXIS_Y_MINUSfalse0.5f)-Ps3.Axis(AXIS_Y_PLUSfalse0.5f));
                    
                    
//input.move.x=Kb.b(KB_D)-Kb.b(KB_A);
                    //input.move.z=Kb.b(KB_W)-Kb.b(KB_S);
                    
input.move.x=Ps3.Axis(AXIS_X_PLUS)-Ps3.Axis(AXIS_X_MINUS);
                    
input.move.z=Ps3.Axis(AXIS_Y_PLUS)-Ps3.Axis(AXIS_Y_MINUS);
                    
input.move.y=Kb.b(KB_SPACE)-Kb.b(KB_LSHIFT);
            
                    
// dodge, crouch, walk, jump
                    
input.dodge Kb.bd(KB_D)-Kb.bd(KB_A);
                    
input.crouchKb.(KB_LSHIFT);
                    
//input.walk  = Kb.b (KB_LCTRL );
                    
input.walk Ps3.Btn(0);
                    
input.jump  =(Kb.bp(KB_SPACE ) ? 3.5f 0); 

If you'd like see some images, I can add some.

Problems:
  • I don't know, how to enable moving detector (sixaxis, g-sensor). SLOVED!
  • Esenthel doesn't support it's vibrations (Joypad.supportVibrations() returns false)

Sorry 4 my English.
(This post was last modified: 12-28-2010 09:57 AM by Barthap.)
12-28-2010 09:42 AM
Find all posts by this user Quote this message in a reply
Barthap Offline
Member

Post: #2
RE: My Ps3 Joypad
Will anyone reply? or I'll delete this topic.

I've changed some code and controller settings (in program from this link http://www.hardcoreware.net/how-to-plays...s-7-vista/) and it's 100% compatible with my requirements smile but 80% compatible with Esenthel, because Force Feedback doesn't work :(

I added to Ps3Controller class support for g-sensor, removed some bugs (for example X and Y axis in right joystick.)
12-28-2010 05:20 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #3
RE: My Ps3 Joypad
I've moved this to code snippets.
12-28-2010 05:47 PM
Find all posts by this user Quote this message in a reply
Shatterstar Offline
Member

Post: #4
RE: My Ps3 Joypad
this is amazing stuff. keep up the good work!
08-03-2012 08:45 PM
Find all posts by this user Quote this message in a reply
gwald Offline
Member

Post: #5
RE: My Ps3 Joypad
Excellent!
Mine had the reversed X/Y second analog stick.
And also having vibration on my joypad but supportsVibrations returns zero :(

"Esenthel doesn't support it's vibrations (Joypad.supportVibrations() returns false)"
How does vibration support work?

Excellent!
Mine had the reversed X/Y second analog stick.
And also having vibration on my joypad but supportsVibrations returns zero :(

"Esenthel doesn't support it's vibrations (Joypad.supportVibrations() returns false)"
How does vibration support work?

My Blog
http://www.esenthel.com/community/showthread.php?tid=6043

I hang out at Esenthel IRC Channel
http://webchat.freenode.net/?channels=#Esenthel
(This post was last modified: 02-25-2013 01:40 PM by gwald.)
02-25-2013 01:39 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply