PDA

View Full Version : Accelerometer :S




JavaWizKid
Oct 19, 2009, 05:14 PM
I've coded this:
- (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?



dejo
Oct 19, 2009, 05:19 PM
fabsf() returns an absolute value. Thus, there are no negatives.

JavaWizKid
Oct 19, 2009, 05:25 PM
Any workaround?

dejo
Oct 19, 2009, 05:35 PM
Any workaround?
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.

JavaWizKid
Oct 19, 2009, 05:41 PM
I meant a way to get negative values because tilting one way and only one way seems a bit pointless :)

dejo
Oct 19, 2009, 05:47 PM
I meant a way to get negative values because tilting one way and only one way seems a bit pointless :)
UIAccelerationValue (http://developer.apple.com/IPhone/library/documentation/UIKit/Reference/UIAcceleration_Class/Reference/UIAcceleration.html#//apple_ref/doc/uid/TP40006901-CH3-SW9) can already contain a negative.