i've been working on ar framework while , trying update uiaccelerometer (deprecated) cmmotionmanager running efficiency problems?
basically seems cmmotionmanager larger , slower uiaccelerometer is. has experienced performance issues cmmotionmanager before?
as can see here, had this:
accelerometer = [uiaccelerometer sharedaccelerometer]; accelerometer.updateinterval = 0.01; [accelerometer setdelegate:self];
and
-(void)accelerometer:(uiaccelerometer *)accelerometer didaccelerate:(uiacceleration *)acceleration { rollingz = (acceleration.z * kfilteringfactor) + (rollingz * (1.0 - kfilteringfactor)); rollingx = (acceleration.y * kfilteringfactor) + (rollingx * (1.0 - kfilteringfactor)); if (rollingz > 0.0) currentinclination = inc_avg(atan(rollingx / rollingz) + m_pi / 2.0); else if (rollingz < 0.0) currentinclination = inc_avg(atan(rollingx / rollingz) - m_pi / 2.0); else if (rollingx < 0) currentinclination = inc_avg(m_pi/2.0); else if (rollingx >= 0) currentinclination = inc_avg(3 * m_pi/2.0); }
and works great on "older" devices iphone 4 (not old yea...).
but when trying exact same code cmmotionmanager:
motionmanager = [[cmmotionmanager alloc] init];
with
[motionmanager setaccelerometerupdateinterval:0.01]; [motionmanager startaccelerometerupdatestoqueue:[nsoperationqueue currentqueue] withhandler: ^(cmaccelerometerdata *accelerometerdata, nserror *error){ rollingz = (accelerometerdata.acceleration.z * kfilteringfactor) + (rollingz * (1.0 - kfilteringfactor)); rollingx = (accelerometerdata.acceleration.y * kfilteringfactor) + (rollingx * (1.0 - kfilteringfactor)); if (rollingz > 0.0) currentinclination = inc_avg(atan(rollingx / rollingz) + m_pi / 2.0); else if (rollingz < 0.0) currentinclination = inc_avg(atan(rollingx / rollingz) - m_pi / 2.0); else if (rollingx < 0) currentinclination = inc_avg(m_pi/2.0); else if (rollingx >= 0) currentinclination = inc_avg(3 * m_pi/2.0); }];
the math seems slow crap out of it..! because when remove math part works great.
an iphone 5 work alright iphone 4s show signs of lag , iphone 4 freeze...
(i can give more details if want relatively complicated explain)
i having same problem, , wouldn't know it, solution in documentation ;)
the problem block format. of tutorials seem favor method, apple recommends periodic polling of cmmotionmanager
more performance oriented approach. block format adds overhead.
from cmmotionmanager
class reference:
to handle motion data periodic sampling, app calls “start” method taking no arguments , periodically accesses motion data held property given type of motion data. approach recommended approach apps such games. handling accelerometer data in block introduces additional overhead, , game apps interested latest sample of motion data when render frame.
so want do, docs again:
call startaccelerometerupdates begin updates , periodically access cmaccelerometerdata objects reading accelerometerdata property.
something along these lines
cmmotionmanager *mmanager = [(appdelegate *)[[uiapplication sharedapplication] delegate] sharedmanager]; [mmanager startaccelerometerupdates];
then, in sort of periodically updating method of choosing:
cmmotionmanager *mmanager = [(sepappdelegate *)[[uiapplication sharedapplication] delegate] sharedmanager]; cmaccelerometerdata *adata = mmanager.accelerometerdata;
this solution appears work uiaccelerometer
on iphone 4 limited testing i've done.
Comments
Post a Comment