Accelerometer :S

Discussion in 'iPhone/iPad Programming' started by JavaWizKid, Oct 19, 2009.

  1. macrumors 6502a

    Joined:
    Sep 18, 2008
    #1
    I've coded this:
    Code:
    - (void)accelerometer:(UIAccelerometer *)acel didAccelerate:(UIAcceleration *)aceler {
    	
    	if (fabsf(aceler.x) > 0.5)
    	{
    		spaceshipVelocity = CGPointMake(kSpaceshipMovingrX,kSpaceshipY);
    	}
    	if (fabsf(aceler.x) <= 0.5 && fabsf(aceler.x) >= 0)
    	{
    		spaceshipVelocity = CGPointMake(kSpaceshipX,kSpaceshipY);
    	}
    	if (fabsf(aceler.x) < -0.5)
    	{
    		spaceshipVelocity = CGPointMake(kSpaceshipMovinglX,kSpaceshipY);
    	}
    	if (fabsf(aceler.x) >= -0.5 && fabsf(aceler.x) <= 0)
    	{
    		spaceshipVelocity = CGPointMake(kSpaceshipX,kSpaceshipY);
    	}
    }
    and for some reason it doesn't execute the negative commands? Any suggestions as to what is wrong?
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    fabsf() returns an absolute value. Thus, there are no negatives.
     
  3. thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
    #3
    Any workaround?
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Workaround? I'm not sure you're approaching this correctly if you think a workaround is the solution. Maybe do a bit more research into UIAcceleration, UIAccelerationValue and how those work.
     
  5. thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
    #5
    I meant a way to get negative values because tilting one way and only one way seems a bit pointless :)
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    UIAccelerationValue can already contain a negative.
     

Share This Page