Permalink
Browse files

added degrading to the spin.

git-svn-id: svn://mediocresoft.com/iPhone/GLTouches@32 208a7e66-6d34-4273-bd12-10793e77ea72
  • Loading branch information...
1 parent bdb7d2e commit 3a54cd072995f1cd30e64f47596a1d481e884e64 jamie committed Feb 12, 2009
View
9 Classes/EGLView.h
@@ -10,6 +10,7 @@
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
+#import "MachTimer.h"
@interface EGLView : UIView {
@@ -29,15 +30,17 @@
NSTimer* viewUpdateTimer;
NSTimeInterval viewUpdateTimerInterval;
CGPoint currentSpinRotation;
+ MachTimer* degradingTimer;
}
-@property(nonatomic) CGPoint currentSpinVector;
+//@property(nonatomic) CGPoint currentSpinVector;
@property(nonatomic) CGFloat zoomFactor;
-(void)updateView;
--(void)setCubeTexture:(UIImage *)image;
+-(void)setCubeTexture:(UIImage *)anImage;
-(void)renderEAGL;
--(int)nearestPowerOfTwo:(int)num;
+-(int)nearestPowerOfTwo:(int)aNumber;
+-(void)setCurrentSpinVector:(CGPoint)aVector;
@end
View
31 Classes/EGLView.m
@@ -13,7 +13,7 @@ - (void)destroyBuffers;
@implementation EGLView
-@synthesize currentSpinVector;
+//@synthesize currentSpinVector;
@synthesize zoomFactor;
+ (Class) layerClass
@@ -110,7 +110,8 @@ - (id)initWithCoder:(NSCoder*)coder
currentSpinVector = CGPointMake(1.0f,0.25f);
currentSpinRotation = CGPointMake(0.0f,0.0f);
zoomFactor = 0.5f;
-
+ degradingTimer = [[MachTimer alloc] init];
+ [degradingTimer start];
// Get the layer
CAEAGLLayer *eaglLayer = (CAEAGLLayer*) self.layer;
// set it up
@@ -160,10 +161,24 @@ - (void)drawRect:(CGRect)rect {
}
- (void)updateView{
- float secondsElapsed = 1.0f;
- currentSpinRotation.x += currentSpinVector.x * secondsElapsed;
- currentSpinRotation.y += currentSpinVector.y * secondsElapsed;
- [self renderEAGL];
+ float degradingFactor = [degradingTimer elapsedSeconds] / 5;
+ NSLog(@"currentSpinVector.x = %f",currentSpinVector.x);
+ if(degradingFactor > 1.0)
+ {
+ currentSpinVector.x = 0;
+ currentSpinVector.y = 0;
+ }
+ else{
+ currentSpinRotation.x += currentSpinVector.x / ([degradingTimer elapsedSeconds] / 5);
+ currentSpinRotation.y += currentSpinVector.y / ([degradingTimer elapsedSeconds] / 5);
+ }
+ [self renderEAGL];
+}
+
+-(void)setCurrentSpinVector:(CGPoint)aVector{
+ NSLog(@"%f new spin vector = ",aVector);
+ currentSpinVector = aVector;
+ [degradingTimer start];
}
- (void)renderEAGL{
@@ -256,9 +271,9 @@ -(int)nearestPowerOfTwo:(int)n{
}
--(void)setCubeTexture:(UIImage *)image{
+-(void)setCubeTexture:(UIImage *)anImage{
- CGImageRef textureImage = image.CGImage;
+ CGImageRef textureImage = anImage.CGImage;
size_t width = CGImageGetWidth(textureImage);
size_t height = CGImageGetHeight(textureImage);
if(textureImage){
View
24 Classes/GLTouchesViewController.m
@@ -27,6 +27,7 @@ -(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
case 1: //Single Tap.
{
[precisionTimer start];
+ beginPoint = [touch locationInView:[self view]];
//Start a timer for 2 seconds.
//timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self
// selector:@selector(showAlertView:) userInfo:nil repeats:NO];
@@ -103,18 +104,19 @@ -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
NSLog(@"%f = [precisionTimer elapsedSeconds]", [precisionTimer elapsedSeconds]);
UITouch *touch = [[event allTouches] anyObject];
endPoint = [touch locationInView:[touch view]];
- CGPoint vector = CGPointMake(endPoint.x - beginPoint.x, beginPoint.y - endPoint.y);
- NSLog(@"%f, %f = vector x, vector y", vector.x, vector.y);
- float speed = (sqrt((vector.x * vector.x) + (vector.y * vector.y)) / [precisionTimer elapsedSeconds]);
- NSLog(@"%f = speed", speed);
- float m = sqrt((vector.x * vector.x) + (vector.y * vector.y));
- if(0.0f != m){
- float f = (speed / 100.0f) / m;
- vector.x *= f;
- vector.y *= f;
+ if(((endPoint.x - beginPoint.x) > 10) || ((beginPoint.y - endPoint.y) > 10)){
+ CGPoint vector = CGPointMake(endPoint.x - beginPoint.x, beginPoint.y - endPoint.y);
+ NSLog(@"%f, %f = vector x, vector y", vector.x, vector.y);
+ float speed = (sqrt((vector.x * vector.x) + (vector.y * vector.y)) / [precisionTimer elapsedSeconds]);
+ NSLog(@"%f = speed", speed);
+ float m = sqrt((vector.x * vector.x) + (vector.y * vector.y));
+ if(0.0f != m){
+ float f = (speed / 100.0f) / m;
+ vector.x *= f;
+ vector.y *= f;
+ }
+ [eglView setCurrentSpinVector:vector];
}
- [eglView setCurrentSpinVector:vector];
-
}
break;
View
BIN build/Debug-iphonesimulator/GLTouches.app/GLTouches
Binary file not shown.

0 comments on commit 3a54cd0

Please sign in to comment.