Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
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
23 changes: 1 addition & 22 deletions Classes/HMGLTransitions/ClothTransition.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,6 @@
#import <Foundation/Foundation.h>
#import "HMGLTransition.h"

@interface ClothTransition : HMGLTransition {

CGFloat width;
CGFloat height;

GLfloat oglWidth;
GLfloat oglHeight;

float *velocities;
GLfloat *normals;
GLfloat *vertices;
GLfloat *texCoords;
GLushort *indices;
GLsizei indicesCount;

GLfloat friction;
GLfloat velocityStrength;

float remainingCalcTime;

float animationTime;
}
@interface ClothTransition : HMGLTransition

@end
30 changes: 28 additions & 2 deletions Classes/HMGLTransitions/ClothTransition.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
GLfloat x, y, z;
} Vector3;

Vector3 substractVectors(Vector3 v1, Vector3 v2);
void addVectors(Vector3 *v1, Vector3 v2);
void multiplyVector(Vector3 *v, GLfloat a);
GLfloat vectorLength(Vector3 v);

Vector3 substractVectors(Vector3 v1, Vector3 v2) {
Vector3 r;
r.x = v1.x - v2.x;
Expand All @@ -55,7 +60,29 @@ GLfloat vectorLength(Vector3 v) {
return sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);
}

@interface ClothTransition()
@interface ClothTransition() {

CGFloat width;
CGFloat height;

GLfloat oglWidth;
GLfloat oglHeight;

float *velocities;
GLfloat *normals;
GLfloat *vertices;
GLfloat *texCoords;
GLushort *indices;
GLsizei indicesCount;

GLfloat friction;
GLfloat velocityStrength;

float remainingCalcTime;

float animationTime;
}


- (void)punchAtPoint:(CGPoint)punchPoint withTime:(NSTimeInterval)frameTime;

Expand Down Expand Up @@ -500,7 +527,6 @@ - (void)dealloc {
free(velocities);
free(vertices);
free(indices);
[super dealloc];
}

@end
25 changes: 25 additions & 0 deletions Classes/HMGLTransitions/CubeTransition.h
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
93 changes: 93 additions & 0 deletions Classes/HMGLTransitions/CubeTransition.m
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
10 changes: 4 additions & 6 deletions Classes/HMGLTransitions/DoorsTransition.h
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
Expand All @@ -26,12 +29,7 @@ typedef enum {
DoorsTransitionTypeClose
} DoorsTransitionType;

@interface DoorsTransition : HMGLTransition {

GLfloat animationTime;

DoorsTransitionType transitionType;
}
@interface DoorsTransition : HMGLTransition

@property (nonatomic, assign) DoorsTransitionType transitionType;

Expand Down
70 changes: 46 additions & 24 deletions Classes/HMGLTransitions/DoorsTransition.m
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
Expand All @@ -20,7 +23,9 @@

#import "DoorsTransition.h"

@implementation DoorsTransition
@implementation DoorsTransition {
GLfloat animationTime;
}

@synthesize transitionType;

Expand All @@ -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;
Copy link
Author

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.

}

- (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;
Copy link
Author

Choose a reason for hiding this comment

The 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) );
Copy link
Author

Choose a reason for hiding this comment

The 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);

Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
7 changes: 1 addition & 6 deletions Classes/HMGLTransitions/FlipTransition.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ typedef enum {
FlipTransitionLeft
} FlipTransitionType;

@interface FlipTransition : HMGLTransition {

FlipTransitionType transitionType;

GLfloat animationTime;
}
@interface FlipTransition : HMGLTransition

@property (nonatomic, assign) FlipTransitionType transitionType;

Expand Down
Loading