-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
DisplayViewController.m
executable file
·98 lines (71 loc) · 2.92 KB
/
DisplayViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#import "DisplayViewController.h"
@interface DisplayViewController ()
@end
@implementation DisplayViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[renderer release];
[super dealloc];
}
- (void)loadView
{
CGRect mainScreenFrame = [[UIScreen mainScreen] applicationFrame];
GPUImageView *primaryView = [[[GPUImageView alloc] initWithFrame:mainScreenFrame] autorelease];
self.view = primaryView;
renderer = [[ES2Renderer alloc] initWithSize:[primaryView sizeInPixels]];
textureInput = [[GPUImageTextureInput alloc] initWithTexture:renderer.outputTexture size:[primaryView sizeInPixels]];
filter = [[GPUImagePixellateFilter alloc] init];
[(GPUImagePixellateFilter *)filter setFractionalWidthOfAPixel:0.01];
// filter = [[GPUImageGaussianBlurFilter alloc] init];
// [(GPUImageGaussianBlurFilter *)filter setBlurSize:3.0];
[textureInput addTarget:filter];
[filter addTarget:primaryView];
[renderer setNewFrameAvailableBlock:^{
float currentTimeInMilliseconds = [[NSDate date] timeIntervalSinceDate:startTime] * 1000.0;
[textureInput processTextureWithFrameTime:CMTimeMake((int)currentTimeInMilliseconds, 1000)];
}];
[renderer startCameraCapture];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)drawView:(id)sender
{
[renderer renderByRotatingAroundX:0 rotatingAroundY:0];
}
#pragma mark -
#pragma mark Touch-handling methods
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSMutableSet *currentTouches = [[[event touchesForView:self.view] mutableCopy] autorelease];
[currentTouches minusSet:touches];
// New touches are not yet included in the current touches for the view
lastMovementPosition = [[touches anyObject] locationInView:self.view];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
{
CGPoint currentMovementPosition = [[touches anyObject] locationInView:self.view];
[renderer renderByRotatingAroundX:(currentMovementPosition.x - lastMovementPosition.x) rotatingAroundY:(lastMovementPosition.y - currentMovementPosition.y)];
lastMovementPosition = currentMovementPosition;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSMutableSet *remainingTouches = [[[event touchesForView:self.view] mutableCopy] autorelease];
[remainingTouches minusSet:touches];
lastMovementPosition = [[remainingTouches anyObject] locationInView:self.view];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
// Handle touches canceled the same as as a touches ended event
[self touchesEnded:touches withEvent:event];
}
@end