Graphics Reference
In-Depth Information
//set lighting layer opacity
CGFloat shadow = 1 + dotProduct - AMBIENT_LIGHT ;
UIColor *color = [ UIColor colorWithWhite : 0 alpha :shadow];
layer. backgroundColor = color. CGColor ;
}
- ( void )addFace:( NSInteger )index withTransform:( CATransform3D )transform
{
//get the face view and add it to the container
UIView *face = self . faces [index];
[ self . containerView addSubview :face];
//center the face view within the container
CGSize containerSize = self . containerView . bounds . size ;
face. center = CGPointMake (containerSize. width / 2.0 ,
containerSize. height / 2.0 );
//apply the transform
face. layer . transform = transform;
//apply lighting
[ self applyLightingToFace :face. layer ];
}
- ( void )viewDidLoad
{
[ super viewDidLoad ];
//set up the container sublayer transform
CATransform3D perspective = CATransform3DIdentity ;
perspective. m34 = - 1.0 / 500.0 ;
perspective = CATransform3DRotate (perspective, - M_PI_4 , 1 , 0 , 0 );
perspective = CATransform3DRotate (perspective, - M_PI_4 , 0 , 1 , 0 );
self . containerView . layer . sublayerTransform = perspective;
//add cube face 1
CATransform3D transform = CATransform3DMakeTranslation ( 0 , 0 , 100 );
[ self addFace : 0 withTransform :transform];
//add cube face 2
transform = CATransform3DMakeTranslation ( 100 , 0 , 0 );
transform = CATransform3DRotate (transform, M_PI_2 , 0 , 1 , 0 );
[ self addFace : 1 withTransform :transform];
//add cube face 3
transform = CATransform3DMakeTranslation ( 0 , - 100 , 0 );
Search WWH ::




Custom Search