Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added a pyramid

  • Loading branch information...
commit 1338787cd86910618e9398c9b0f8cf216a5080f9 1 parent 9380e1c
@ssoper authored
View
9 Cube.xcodeproj/project.pbxproj
@@ -17,6 +17,7 @@
3CD22C1F13D5ED53001844CD /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CD22C1E13D5ED53001844CD /* GLKit.framework */; };
3CD22C2113D5ED58001844CD /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CD22C2013D5ED58001844CD /* QuartzCore.framework */; };
3CD22C2813D65C4C001844CD /* ColorfulCube.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CD22C2713D65C4B001844CD /* ColorfulCube.m */; };
+ 8DE6BA031514E60700E1480E /* ColorfulPyramid.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DE6BA021514E60700E1480E /* ColorfulPyramid.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -35,6 +36,8 @@
3CD22C2013D5ED58001844CD /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
3CD22C2613D65C4B001844CD /* ColorfulCube.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorfulCube.h; sourceTree = "<group>"; };
3CD22C2713D65C4B001844CD /* ColorfulCube.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ColorfulCube.m; sourceTree = "<group>"; };
+ 8DE6BA011514E60700E1480E /* ColorfulPyramid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorfulPyramid.h; sourceTree = "<group>"; };
+ 8DE6BA021514E60700E1480E /* ColorfulPyramid.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ColorfulPyramid.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -91,6 +94,8 @@
3CD22C1513D5EBFF001844CD /* CubeAppDelegate.m */,
3CD22C2613D65C4B001844CD /* ColorfulCube.h */,
3CD22C2713D65C4B001844CD /* ColorfulCube.m */,
+ 8DE6BA011514E60700E1480E /* ColorfulPyramid.h */,
+ 8DE6BA021514E60700E1480E /* ColorfulPyramid.m */,
3CD22C0C13D5EBFF001844CD /* Supporting Files */,
);
path = Cube;
@@ -133,7 +138,7 @@
3CD22BF813D5EBFF001844CD /* Project object */ = {
isa = PBXProject;
attributes = {
- ORGANIZATIONNAME = "Ian Terrell";
+ ORGANIZATIONNAME = "";
};
buildConfigurationList = 3CD22BFB13D5EBFF001844CD /* Build configuration list for PBXProject "Cube" */;
compatibilityVersion = "Xcode 3.2";
@@ -171,6 +176,7 @@
3CD22C1213D5EBFF001844CD /* main.m in Sources */,
3CD22C1613D5EBFF001844CD /* CubeAppDelegate.m in Sources */,
3CD22C2813D65C4C001844CD /* ColorfulCube.m in Sources */,
+ 8DE6BA031514E60700E1480E /* ColorfulPyramid.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -276,6 +282,7 @@
3CD22C1B13D5EBFF001844CD /* Release */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
View
1  Cube/ColorfulCube.m
@@ -110,6 +110,7 @@ - (void)draw
glEnableVertexAttribArray(GLKVertexAttribColor);
glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, 0, triangleColors);
+// NSLog(@"size %lu", sizeof(triangleVertices)/sizeof(GLKVector3));
glDrawArrays(GL_TRIANGLES, 0, 36);
glDisableVertexAttribArray(GLKVertexAttribPosition);
View
21 Cube/ColorfulPyramid.h
@@ -0,0 +1,21 @@
+//
+// ColorfulPyramid.h
+// Cube
+//
+// Created by Sean Soper on 3/17/12.
+// Copyright (c) 2012. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import <GLKit/GLKit.h>
+
+@interface ColorfulPyramid : NSObject {
+ GLKVector3 position, rotation, scale, rps;
+}
+
+@property GLKVector3 position, rotation, scale, rps;
+
+- (void)draw;
+- (void)updateRotations:(NSTimeInterval)dt;
+
+@end
View
111 Cube/ColorfulPyramid.m
@@ -0,0 +1,111 @@
+//
+// ColorfulPyramid.m
+// Cube
+//
+// Created by Sean Soper on 3/17/12.
+// Copyright (c) 2012. All rights reserved.
+//
+
+#import "ColorfulPyramid.h"
+#define M_TAU (2*M_PI)
+
+static BOOL initialized = NO;
+static GLKVector3 vertices[5];
+static GLKVector4 colors[5];
+static GLKVector3 triangleVertices[18];
+static GLKVector4 triangleColors[18];
+static GLKBaseEffect *effect;
+
+@implementation ColorfulPyramid
+
+@synthesize position, rotation, scale, rps;
+
+- (id)init
+{
+ self = [super init];
+ if (self) {
+ position = GLKVector3Make(0,0,0);
+ rotation = GLKVector3Make(0,0,0);
+ scale = GLKVector3Make(1,1,1);
+ }
+
+ return self;
+}
+
++ (void)initialize {
+ if (!initialized) {
+ vertices[0] = GLKVector3Make(-0.5, -0.5, 0.5); // Left bottom front
+ vertices[1] = GLKVector3Make( 0.5, -0.5, 0.5); // Right bottom front
+ vertices[2] = GLKVector3Make( 0.0, 0.5, 0.0); // Top front
+ vertices[3] = GLKVector3Make(-0.5, -0.5, -0.5); // Left bottom back
+ vertices[4] = GLKVector3Make( 0.5, -0.5, -0.5); // Right bottom back
+
+ colors[0] = GLKVector4Make(1.0, 0.0, 0.0, 1.0); // Red
+ colors[1] = GLKVector4Make(0.0, 1.0, 0.0, 1.0); // Green
+ colors[2] = GLKVector4Make(0.0, 0.0, 1.0, 1.0); // Blue
+ colors[3] = GLKVector4Make(0.0, 0.0, 0.0, 1.0); // Black
+ colors[4] = GLKVector4Make(0.0, 0.0, 1.0, 1.0); // Blue
+
+ int vertexIndices[18] = {
+ // Front
+ 0, 1, 2,
+ // Right
+ 1, 4, 2,
+ // Back
+ 4, 3, 2,
+ // Left
+ 3, 0, 2,
+ // Bottom
+ 3, 4, 1,
+ 3, 1, 0,
+ };
+
+ for (int i = 0; i < 18; i++) {
+ triangleVertices[i] = vertices[vertexIndices[i]];
+ triangleColors[i] = colors[vertexIndices[i]];
+ }
+
+ effect = [[GLKBaseEffect alloc] init];
+
+ initialized = YES;
+ }
+}
+
+- (void)draw
+{
+ GLKMatrix4 xRotationMatrix = GLKMatrix4MakeXRotation(rotation.x);
+ GLKMatrix4 yRotationMatrix = GLKMatrix4MakeYRotation(rotation.y);
+ GLKMatrix4 zRotationMatrix = GLKMatrix4MakeZRotation(rotation.z);
+ GLKMatrix4 scaleMatrix = GLKMatrix4MakeScale(scale.x, scale.y, scale.z);
+ GLKMatrix4 translateMatrix = GLKMatrix4MakeTranslation(position.x, position.y, position.z);
+
+ GLKMatrix4 modelMatrix = GLKMatrix4Multiply(translateMatrix,GLKMatrix4Multiply(scaleMatrix,GLKMatrix4Multiply(zRotationMatrix, GLKMatrix4Multiply(yRotationMatrix, xRotationMatrix))));
+
+ GLKMatrix4 viewMatrix = GLKMatrix4MakeLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0);
+ effect.transform.modelviewMatrix = GLKMatrix4Multiply(viewMatrix, modelMatrix);
+
+ effect.transform.projectionMatrix = GLKMatrix4MakePerspective(0.125*M_TAU, 2.0/3.0, 2, -1);
+
+ [effect prepareToDraw];
+
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);
+
+ glEnableVertexAttribArray(GLKVertexAttribPosition);
+ glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 0, triangleVertices);
+
+ glEnableVertexAttribArray(GLKVertexAttribColor);
+ glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, 0, triangleColors);
+
+// NSLog(@"size %lu", sizeof(triangleVertices)/sizeof(GLKVector3));
+ glDrawArrays(GL_TRIANGLES, 0, 18);
+
+ glDisableVertexAttribArray(GLKVertexAttribPosition);
+ glDisableVertexAttribArray(GLKVertexAttribColor);
+}
+
+- (void)updateRotations:(NSTimeInterval)dt {
+ rotation = GLKVector3Add(rotation, GLKVector3MultiplyScalar(rps, dt));
+}
+
+@end
View
38 Cube/CubeAppDelegate.m
@@ -8,6 +8,7 @@
#import "CubeAppDelegate.h"
#import "ColorfulCube.h"
+#import "ColorfulPyramid.h"
#define M_TAU (2*M_PI)
@@ -36,23 +37,28 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
cubes = [[NSMutableArray alloc] init];
srandom(time(NULL));
- [self addCube];
-
+// [self addCube];
+
+ ColorfulPyramid *shape = [[ColorfulPyramid alloc] init];
+ shape.position = GLKVector3Make(0.25, 0.25, 0.0);
+ shape.scale = GLKVector3Make(0.5, 0.5, 0.5);
+ shape.rotation = GLKVector3Make(1.0/8*M_TAU, 1.0/8*M_TAU, 0);
+ shape.rps = GLKVector3Make(0.5, 0.4, 0.3);
+ [cubes addObject:shape];
/*
- ColorfulCube *cube = [[ColorfulCube alloc] init];
- 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];
- */
+ ColorfulCube *cube = [[ColorfulCube alloc] init];
+ 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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.