Question

I'm using pitch and roll from CMAttitude to control the position of a point in an iPhone Game. As I start the level, I register the reference attitude and during the game I use

[attitude multiplyByInverseOfAttitude:attitudeRef] 

to get the current attitude with regard to the reference, then control the point horizontal position (with the pitch property) and the vertical position (with the roll property).

The problem is, I would like to add a feature to reset only the roll component of the reference attitude attitudeRef to a custom value. CMAttitude euler angles are readonly properties, and I apparently can't create myself a custom CMAttitude object with custom roll and pitch.

How could I do that?

Was it helpful?

Solution

Unfortunately there is no easy way to achieve this. As you stated, CMAttitude doesn't provide any features to manipulate it or to create an instance. That said you have to do the multiplication on your own. Furthermore you will need an additional class for quaternions because CMQuaternion is only a struct.

The good news is that all the code you need is available already in the cocoamath project for example. Take a look at How multiplyByInverseOfAttitude (CMAttitude Class ) is implemented? for some guidance and more links to the basics of quaternion math.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top