transform - Simulating an image floating effect using CoreMotion/DeviceMotion on the iPhone -


There is a series of images within my visual controller.

I am "floating" by changing them to individual layers:

  img.layer.transform = CATransform3DMakeTranslation (0.0f, 0.0f, myZ);   

This gives the effect of floating layers on top of the screen - in the simulator, there will be no visual effect (which is correct).

What I want to do is an effect where a device runs left / right / forward / or behind It is easily visible as layers are floating when you tilt the device to the left, Should be angle on the right. From this, you feel that the device appears around you at the corners - that is, it will give a feeling that the images are actually running above the screen because they will run on different rates (depending on their z-index) .

I have created a test project () in which there is a sample project that demodes it.

My problem is that I am not a mathematical person, so the best way to emulate is the subtle temporary effect, I've got the listener for device motion, which then:

  self.view.layer.sublayerTransform = CATransform3DMakeRotation (20.0f * M_PI / 180.0f, 2 * motion.attitude. Pitch, -2 * proposition.axide.roll, 0);   

This is very close to what I want, but it is not perfect.

I think this effect will be something that can be used in many different applications. I am hoping to expand it to a friend and I am working with the face detection (hence it will move the view of the parents on the basis of a person's face movement - even if that phone / Device still completely)

I realized that people will have to answer "Use of OpenGL". It is not an answer for me - unless you show a part of the code that is integrated into this project. Does. (I am not looking for new problems to solve.) -

Again, the whole project is here () which wants to see any effect because it is just fine. (When it is working, I will leave the project completed here for the fate.)

I think I have found it! Use: << p>

  [appDelegate.motionager_start_eviceMotionUpdatesToQueue: [NSOperationQueue currentQueue] with Handler: ^ (CMDeviceMotion * Proposal, NSError * error) {CATransform3D conversion; Transform = cateresform 3mmacrotation (speed.editTouch.pitch, 1, 0, 0); Transform = cateresform 3 rotate (change, speed.exide.roll, 0, 1, 0); Self.view.layer.sublayerTransform = transform; }];   

Works like a charm for me, if you want to flip the axes, just add the zeros mark in front of those 1.

Comments