From 9bf384ad62915fd57a4ba194d24bed6313fc9fb5 Mon Sep 17 00:00:00 2001 From: Ian Terrell Date: Tue, 19 Jul 2011 22:27:45 -0400 Subject: [PATCH] simple animations --- Cube/ColorfulCube.h | 5 +++-- Cube/ColorfulCube.m | 6 +++++- Cube/CubeAppDelegate.m | 5 +++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Cube/ColorfulCube.h b/Cube/ColorfulCube.h index 3eb1435..8dc2ce2 100644 --- a/Cube/ColorfulCube.h +++ b/Cube/ColorfulCube.h @@ -10,11 +10,12 @@ #import @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 diff --git a/Cube/ColorfulCube.m b/Cube/ColorfulCube.m index 1a1faaf..8106018 100644 --- a/Cube/ColorfulCube.m +++ b/Cube/ColorfulCube.m @@ -18,7 +18,7 @@ @implementation ColorfulCube -@synthesize position, rotation, scale; +@synthesize position, rotation, scale, rps; - (id)init { @@ -116,4 +116,8 @@ - (void)draw glDisableVertexAttribArray(GLKVertexAttribColor); } +- (void)updateRotations:(NSTimeInterval)dt { + rotation = GLKVector3Add(rotation, GLKVector3MultiplyScalar(rps, dt)); +} + @end diff --git a/Cube/CubeAppDelegate.m b/Cube/CubeAppDelegate.m index 7516cd3..521b3bd 100644 --- a/Cube/CubeAppDelegate.m +++ b/Cube/CubeAppDelegate.m @@ -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 {