-
Notifications
You must be signed in to change notification settings - Fork 106
Animation for closing doors transition #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
e43c3ba
aa3d39f
3cbc9e4
5cb00f6
dda9bf5
b323371
858ed07
1cbd069
6a777a4
dd94336
5922357
6f801be
c04e4fb
52a432b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,8 @@ | ||
| .DS_Store | ||
| .DS_Store | ||
| HMGLTransitions.xcodeproj/project.xcworkspace/contents.xcworkspacedata | ||
|
|
||
| HMGLTransitions.xcodeproj/project.xcworkspace/xcuserdata/kpm.xcuserdatad/UserInterfaceState.xcuserstate | ||
|
|
||
| HMGLTransitions.xcodeproj/xcuserdata/kpm.xcuserdatad/xcschemes/HMGLTransitions.xcscheme | ||
|
|
||
| HMGLTransitions.xcodeproj/xcuserdata/kpm.xcuserdatad/xcschemes/xcschememanagement.plist |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // | ||
| // CubeTransition.h | ||
| // HMGLTransitions | ||
| // | ||
| // Created by Patrick Pietens on 11/14/11. | ||
| // Copyright (c) 2011 PatrickPietens.com. All rights reserved. | ||
| // | ||
|
|
||
| #import <Foundation/Foundation.h> | ||
| #import "HMGLTransition.h" | ||
|
|
||
| typedef enum { | ||
| CubeTransitionRight, | ||
| CubeTransitionLeft | ||
| } CubeTransitionType; | ||
|
|
||
| @interface CubeTransition : HMGLTransition | ||
| { | ||
| CubeTransitionType transitionType; | ||
| GLfloat animationTime; | ||
| } | ||
|
|
||
| @property (nonatomic, assign) CubeTransitionType transitionType; | ||
|
|
||
| @end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // | ||
| // CubeTransition.m | ||
| // HMGLTransitions | ||
| // | ||
| // Created by Patrick Pietens on 11/14/11. | ||
| // Copyright (c) 2011 PatrickPietens.com. All rights reserved. | ||
| // | ||
|
|
||
| #import "CubeTransition.h" | ||
|
|
||
| @implementation CubeTransition | ||
|
|
||
| @synthesize transitionType; | ||
|
|
||
| - (id)init | ||
| { | ||
| if (self = [super init]) | ||
| { | ||
| transitionType = CubeTransitionLeft; | ||
| } | ||
|
|
||
| return self; | ||
| } | ||
|
|
||
|
|
||
| - (void)initTransition | ||
| { | ||
| glMatrixMode(GL_PROJECTION); | ||
| glLoadIdentity(); | ||
| glFrustumf(-0.1, 0.1, -0.1, 0.1, 0.1, 100.0); | ||
|
|
||
| glEnable(GL_DEPTH_TEST); | ||
| glEnable(GL_CULL_FACE); | ||
|
|
||
| glDisable(GL_LIGHTING); | ||
| glColor4f(1.0, 1.0, 1.0, 1.0); | ||
|
|
||
| animationTime = 0; | ||
| } | ||
|
|
||
|
|
||
| - (void)drawWithBeginTexture:(GLuint)beginTexture endTexture:(GLuint)endTexture | ||
| { | ||
| int myDirection = transitionType == CubeTransitionLeft ? -1 : 1; | ||
|
|
||
| glClearColor(0.0, 0.0, 0.0, 1.0); | ||
| glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | ||
|
|
||
| GLfloat vertices[] = { | ||
| -0.5, -0.5, | ||
| 0.5, -0.5, | ||
| -0.5, 0.5, | ||
| 0.5, 0.5, | ||
| }; | ||
|
|
||
| glEnable(GL_TEXTURE_2D); | ||
|
|
||
| glVertexPointer(2, GL_FLOAT, 0, vertices); | ||
| glEnableClientState(GL_VERTEX_ARRAY); | ||
| glTexCoordPointer(2, GL_FLOAT, 0, &basicTexCoords); | ||
| glEnableClientState(GL_TEXTURE_COORD_ARRAY); | ||
|
|
||
| glMatrixMode(GL_MODELVIEW); | ||
| glLoadIdentity(); | ||
|
|
||
| glPushMatrix(); | ||
| // begin view | ||
| glBindTexture(GL_TEXTURE_2D, beginTexture); | ||
| glTranslatef(0, 0, -1.0); | ||
| glRotatef(myDirection * -90 * sin(animationTime), 0, 1, 0); | ||
| glTranslatef(0, 0, 0.5); | ||
| glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | ||
| glPopMatrix(); | ||
|
|
||
| glPushMatrix(); | ||
| // end view | ||
| glBindTexture(GL_TEXTURE_2D, endTexture); | ||
| glTranslatef(0, 0, -1.0 ); | ||
| glRotatef(myDirection * -90 * sin(animationTime), 0, 1, 0); | ||
| glTranslatef(myDirection * 0.5, 0.0, 0); | ||
| glRotatef(myDirection * 90, 0, 1, 0); | ||
| glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | ||
| glPopMatrix(); | ||
| } | ||
|
|
||
|
|
||
| - (BOOL)calc:(NSTimeInterval)frameTime | ||
| { | ||
| animationTime += M_PI * 0.5 * frameTime * 1.5; | ||
| return animationTime > M_PI * 0.5; | ||
| } | ||
|
|
||
| @end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| // Copyright (c) 2010 Hyperbolic Magnetism | ||
| // | ||
| // Modifications for closing doors transition | ||
| // Copyright (c) 2011 Karim-Pierre Maalej | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files (the "Software"), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
|
|
@@ -20,7 +23,9 @@ | |
|
|
||
| #import "DoorsTransition.h" | ||
|
|
||
| @implementation DoorsTransition | ||
| @implementation DoorsTransition { | ||
| GLfloat animationTime; | ||
| } | ||
|
|
||
| @synthesize transitionType; | ||
|
|
||
|
|
@@ -43,17 +48,29 @@ - (void)initTransition { | |
| glDisable(GL_LIGHTING); | ||
| glColor4f(1.0, 1.0, 1.0, 1.0); | ||
|
|
||
| animationTime = 0; | ||
| animationTime = (transitionType == DoorsTransitionTypeOpen)?0:-2*M_PI/3; | ||
| } | ||
|
|
||
| - (void)drawWithBeginTexture:(GLuint)beginTexture endTexture:(GLuint)endTexture { | ||
|
|
||
| if (transitionType == DoorsTransitionTypeClose) { | ||
| GLuint t = endTexture; | ||
| endTexture = beginTexture; | ||
| beginTexture = t; | ||
| } | ||
|
|
||
| GLuint outerTexture, innerTexture; GLfloat sah, depth; | ||
| switch (transitionType) { | ||
| case DoorsTransitionTypeOpen: | ||
| sah = sin(animationTime * 0.5); | ||
| innerTexture = endTexture; | ||
| outerTexture = beginTexture; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assigning "inner" and "outer" textures is clearer for code lisibiity than switching the "begin" and the "end" textures. |
||
| depth = -1.2 + sah * 0.2; | ||
| break; | ||
|
|
||
| case DoorsTransitionTypeClose: | ||
| default: | ||
| sah = -sin(animationTime * 0.5); | ||
| innerTexture = beginTexture; | ||
| outerTexture = endTexture; | ||
| depth = -1.0 + 0.5 * ( (animationTime < - M_PI_2) ? 0.0 : 1/(animationTime-0.25)-1/(-M_PI_2-0.25) ); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lot of trial-and-error to adjust for a proper animation of the inner view. Found that a hyperbolic function, delayed until the doors were at -π/2 (and therefore beginning to show), was the right choice. |
||
| break; | ||
| } | ||
|
|
||
| glClearColor(0.0, 0.0, 0.0, 1.0); | ||
| glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | ||
|
|
||
|
|
@@ -66,7 +83,7 @@ - (void)drawWithBeginTexture:(GLuint)beginTexture endTexture:(GLuint)endTexture | |
| -w, h, | ||
| w, h, | ||
| }; | ||
|
|
||
| GLfloat verticesHalf[] = { | ||
| -w * 0.5, -h, | ||
| w * 0.5, -h, | ||
|
|
@@ -90,38 +107,41 @@ - (void)drawWithBeginTexture:(GLuint)beginTexture endTexture:(GLuint)endTexture | |
|
|
||
| glEnable(GL_TEXTURE_2D); | ||
|
|
||
|
|
||
| glMatrixMode(GL_MODELVIEW); | ||
| glLoadIdentity(); | ||
|
|
||
| GLfloat sah = sin(animationTime * 0.5); | ||
|
|
||
| GLfloat intensity = sah * sah; | ||
|
|
||
| GLfloat intensity = sah * sah; | ||
|
|
||
| // end view | ||
| glVertexPointer(2, GL_FLOAT, 0, vertices); | ||
| glEnableClientState(GL_VERTEX_ARRAY); | ||
| glTexCoordPointer(2, GL_FLOAT, 0, &basicTexCoords); | ||
| glEnableClientState(GL_TEXTURE_COORD_ARRAY); | ||
|
|
||
| glPushMatrix(); | ||
| glBindTexture(GL_TEXTURE_2D, endTexture); | ||
| glTranslatef(0, 0, -1.2 + sah * 0.2); | ||
| glColor4f(intensity, intensity, intensity, 1.0); | ||
| glBindTexture(GL_TEXTURE_2D, innerTexture); | ||
| glTranslatef(0, 0, depth); | ||
| if (transitionType == DoorsTransitionTypeOpen) | ||
| glColor4f(intensity, intensity, intensity, 1.0); | ||
| else | ||
| glColor4f(1.0, 1.0, 1.0, 1.0); | ||
| glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | ||
| glPopMatrix(); | ||
|
|
||
| glColor4f(1.0 - intensity, 1.0 - intensity, 1.0 - intensity, 1.0); | ||
| if (transitionType == DoorsTransitionTypeOpen) | ||
| glColor4f(1.0 - intensity, 1.0 - intensity, 1.0 - intensity, 1.0); | ||
|
|
||
| // left | ||
| glPushMatrix(); | ||
| glBindTexture(GL_TEXTURE_2D, beginTexture); | ||
| glBindTexture(GL_TEXTURE_2D, outerTexture); | ||
| glVertexPointer(2, GL_FLOAT, 0, verticesHalf); | ||
| glEnableClientState(GL_VERTEX_ARRAY); | ||
| glTexCoordPointer(2, GL_FLOAT, 0, texcoords1); | ||
| glEnableClientState(GL_TEXTURE_COORD_ARRAY); | ||
|
|
||
| glTranslatef(-w, 0, -1); | ||
| if (transitionType == DoorsTransitionTypeClose) | ||
| glColor4f(1.0-intensity, 1.0-intensity, 1.0-intensity, 1.0); | ||
| glRotatef(-sah * sah * sah * 90, 0, 1, 0); | ||
| glTranslatef(w * 0.5, 0, 0); | ||
| glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | ||
|
|
@@ -134,6 +154,8 @@ - (void)drawWithBeginTexture:(GLuint)beginTexture endTexture:(GLuint)endTexture | |
| glTexCoordPointer(2, GL_FLOAT, 0, texcoords2); | ||
| glEnableClientState(GL_TEXTURE_COORD_ARRAY); | ||
| glTranslatef(w, 0, -1); | ||
| if (transitionType == DoorsTransitionTypeClose) | ||
| glColor4f(1.0-intensity, 1.0-intensity, 1.0-intensity, 1.0); | ||
| glRotatef(sah * sah * sah * 90, 0, 1, 0); | ||
| glTranslatef(-w * 0.5, 0, 0); | ||
| glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | ||
|
|
@@ -142,15 +164,15 @@ - (void)drawWithBeginTexture:(GLuint)beginTexture endTexture:(GLuint)endTexture | |
|
|
||
| - (BOOL)calc:(NSTimeInterval)frameTime { | ||
|
|
||
| animationTime += M_PI * frameTime * 1.3; | ||
| animationTime += M_PI * frameTime * ((transitionType == DoorsTransitionTypeOpen)?1.3:0.8); | ||
| GLfloat endAnimationTime = (transitionType == DoorsTransitionTypeOpen)?M_PI:0; | ||
|
|
||
| if (animationTime > M_PI) { | ||
| animationTime = M_PI; | ||
| if (animationTime > endAnimationTime) { | ||
| animationTime = endAnimationTime; | ||
| return YES; | ||
| } | ||
|
|
||
| return NO; | ||
|
|
||
| } | ||
|
|
||
| @end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-2π/3 and not -π/2 to smoothen the animation.