//
//  ThreeDTransformAppDelegate.m
//  ThreeDTransform
//
//  Created by Bill Dudney on 7/7/08.
//  Copyright Gala Factory 2008. All rights reserved.
//
//
//  Licensed with the Apache 2.0 License
//  http://apache.org/licenses/LICENSE-2.0
//

#import "ThreeDTransformViewController.h"

@implementation ThreeDTransformViewController

@synthesize basketBall;

- (void)viewDidLoad {
	[super viewDidLoad];
  self.basketBall = [CALayer layer];
  self.basketBall.contents = (id)[[UIImage imageNamed:@"basketBall.png"] CGImage];
  self.basketBall.bounds = CGRectMake(0.0f, 0.0f, 125.0f, 125.0f);
  self.basketBall.contentsGravity = kCAGravityResizeAspect;
  self.basketBall.position = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds));
  [self.view.layer addSublayer:self.basketBall];
}

//START: code.3dtransform.touchesEnded
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  CAKeyframeAnimation *animation = [CAKeyframeAnimation 
                                    animationWithKeyPath:@"transform"];
  NSValue *initial = [NSValue valueWithCATransform3D:
                      CATransform3DMakeRotation(0.0, 1.0f, -1.0f, 0.0f)];
  NSValue *middle = [NSValue valueWithCATransform3D:
                     CATransform3DMakeRotation(M_PI, 1.0f, -1.0f, 0.0f)];
  NSValue *final = [NSValue valueWithCATransform3D:
                    CATransform3DMakeRotation(0.0, 1.0f, -1.0f, 0.0f)];
  animation.values = [NSArray arrayWithObjects:initial, 
                      middle, final, nil];
  animation.duration = 2.0f;
  [self.basketBall addAnimation:animation forKey:@"transform"];
}
//END: code.3dtransform.touchesEnded

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	// Return YES for supported orientations
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
	[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
	// Release anything that's not essential, such as cached data
}


- (void)dealloc {
	[super dealloc];
}

@end
