Skip to content

Commit

Permalink
simple animations
Browse files Browse the repository at this point in the history
  • Loading branch information
ianterrell committed Jul 20, 2011
1 parent 113971b commit 9bf384a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Cube/ColorfulCube.h
Expand Up @@ -10,11 +10,12 @@
#import <GLKit/GLKit.h>

@interface ColorfulCube : NSObject {
GLKVector3 position, rotation, scale;
GLKVector3 position, rotation, scale, rps;
}

@property GLKVector3 position, rotation, scale;
@property GLKVector3 position, rotation, scale, rps;

- (void)draw;
- (void)updateRotations:(NSTimeInterval)dt;

@end
6 changes: 5 additions & 1 deletion Cube/ColorfulCube.m
Expand Up @@ -18,7 +18,7 @@

@implementation ColorfulCube

@synthesize position, rotation, scale;
@synthesize position, rotation, scale, rps;

- (id)init
{
Expand Down Expand Up @@ -116,4 +116,8 @@ - (void)draw
glDisableVertexAttribArray(GLKVertexAttribColor);
}

- (void)updateRotations:(NSTimeInterval)dt {
rotation = GLKVector3Add(rotation, GLKVector3MultiplyScalar(rps, dt));
}

@end
5 changes: 5 additions & 0 deletions Cube/CubeAppDelegate.m
Expand Up @@ -37,18 +37,23 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
cube.position = GLKVector3Make(0.25, 0.25, 0.0);
cube.scale = GLKVector3Make(0.5, 0.5, 0.5);
cube.rotation = GLKVector3Make(1.0/8*M_TAU, 1.0/8*M_TAU, 0);
cube.rps = GLKVector3Make(0.5, 0.4, 0.3);
[cubes addObject:cube];

ColorfulCube *cube2 = [[ColorfulCube alloc] init];
cube2.position = GLKVector3Make(-0.5, -0.25, 0.0);
cube2.scale = GLKVector3Make(0.4, 0.4, 0.4);
cube2.rotation = GLKVector3Make(1.0/8*M_TAU, 0, 1.0/8*M_TAU);
cube2.rps = GLKVector3Make(0.3, 0.5, 0.4);
[cubes addObject:cube2];

return YES;
}

- (void)glkViewControllerUpdate:(GLKViewController *)controller {
NSTimeInterval dt = [controller timeSinceLastDraw];
for (id cube in cubes)
[((ColorfulCube *)cube) updateRotations:dt];
}

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {
Expand Down

0 comments on commit 9bf384a

Please sign in to comment.