Permalink
Browse files

Uncommenting blur stuff... trying to fix mouse motion stuff and

failing
  • Loading branch information...
gabriel committed Apr 28, 2012
1 parent 4892fbd commit 7a78065cc75dcff53fae0463f6b926b7195e49ef
View
@@ -23,17 +23,17 @@
GHGLProgram *_progFluidP;
GHGLProgram *_progFluidDiv;
- //GHGLProgram *_progBlurHorizontal;
- //GHGLProgram *_progBlurVertical;
+ GHGLProgram *_progBlurHorizontal;
+ GHGLProgram *_progBlurVertical;
GLuint _frameBuffers[2];
GLuint _fluidPFrameBuffer;
GLuint _fluidVFrameBuffer;
GLuint _fluidStoreFrameBuffer;
GLuint _fluidBackBuffer;
- //GLuint _helperFrameBuffers[6];
- //GLuint _blurFrameBuffers[6];
+ GLuint _helperFrameBuffers[6];
+ GLuint _blurFrameBuffers[6];
GLuint _textureMainN;
GLuint _textureMain2N;
@@ -45,8 +45,8 @@
GLuint _textureFluidStore;
GLuint _textureFluidBackBuffer;
- //GLuint _textureHelper[6];
- //GLuint _textureBlur[6];
+ GLuint _textureHelper[6];
+ GLuint _textureBlur[6];
GLuint _verticesID;
View
@@ -81,7 +81,6 @@ - (void)fluidInit:(GLuint)fbo {
glFlush();
}
-/*
- (void)calculateBlurTexture:(GLuint)sourceTex targetTex:(GLuint)targetTex targetFBO:(GLuint)targetFBO helperTex:(GLuint)helperTex helperFBO:(GLuint)helperFBO scale:(GLfloat)scale {
// copy source
glViewport(0, 0, SizeX / scale, SizeY / scale);
@@ -122,15 +121,14 @@ - (void)calculateBlurTextures {
[self calculateBlurTexture:_textureBlur[3] targetTex:_textureBlur[4] targetFBO:_blurFrameBuffers[4] helperTex:_textureHelper[4] helperFBO:_helperFrameBuffers[4] scale:16.0f];
[self calculateBlurTexture:_textureBlur[4] targetTex:_textureBlur[5] targetFBO:_blurFrameBuffers[5] helperTex:_textureHelper[5] helperFBO:_helperFrameBuffers[5] scale:32.0f];
}
- */
- (BOOL)loadShaders {
_prog = [[self programForShaderName:@"Shader-Default"] retain];
_progCopy = [[self programForShaderName:@"Shader-Copy"] retain];
_progComposite = [[self programForShaderName:@"Shader-DefaultComposite"] retain];
- //_progBlurHorizontal = [[self programForShaderName:@"Shader-BlurHorizontal"] retain];
- //_progBlurVertical = [[self programForShaderName:@"Shader-BlurVertical"] retain];
+ _progBlurHorizontal = [[self programForShaderName:@"Shader-BlurHorizontal"] retain];
+ _progBlurVertical = [[self programForShaderName:@"Shader-BlurVertical"] retain];
_progFluidInit = [[self programForShaderName:@"Shader-FluidInit"] retain];
_progFluidAddMotion = [[self programForShaderName:@"Shader-FluidAddMotion"] retain];
@@ -173,13 +171,11 @@ - (BOOL)loadShaders {
NSMutableData *pixels = [NSMutableData data];
NSMutableData *simPixels = [NSMutableData data];
- /*
NSMutableData *pixels2 = [NSMutableData data];
NSMutableData *pixels3 = [NSMutableData data];
NSMutableData *pixels4 = [NSMutableData data];
NSMutableData *pixels5 = [NSMutableData data];
NSMutableData *pixels6 = [NSMutableData data];
- */
for (int i = 0; i < SizeY; i++) {
for (int j = 0; j < SizeX; j++) {
@@ -193,7 +189,6 @@ - (BOOL)loadShaders {
}
}
- /*
for (int i = 0; i < SizeX; i++) {
for (int j = 0; j < SizeY; j++) {
@@ -219,7 +214,6 @@ - (BOOL)loadShaders {
}
}
}
- */
glGenFramebuffers(2, _frameBuffers);
[self createAndBindTexture:&_textureMainN pixels:pixels scale:1.0f fbo:_frameBuffers[0] filter:GL_NEAREST];
@@ -237,7 +231,6 @@ - (BOOL)loadShaders {
[self createAndBindSimulationTexture:&_textureFluidStore pixels:simPixels fbo:_fluidStoreFrameBuffer];
[self createAndBindSimulationTexture:&_textureFluidBackBuffer pixels:simPixels fbo:_fluidBackBuffer];
- /*
glGenFramebuffers(6, _helperFrameBuffers);
[self createAndBindTexture:&_textureHelper[0] pixels:pixels scale:1.0f fbo:_helperFrameBuffers[0] filter:GL_NEAREST];
[self createAndBindTexture:&_textureHelper[1] pixels:pixels2 scale:2.0f fbo:_helperFrameBuffers[1] filter:GL_NEAREST];
@@ -266,7 +259,6 @@ - (BOOL)loadShaders {
glBindTexture(GL_TEXTURE_2D, _textureBlur[4]);
glActiveTexture(GL_TEXTURE7);
glBindTexture(GL_TEXTURE_2D, _textureBlur[5]);
- */
glActiveTexture(GL_TEXTURE10);
glBindTexture(GL_TEXTURE_2D, _textureFluidV);
@@ -282,7 +274,7 @@ - (BOOL)loadShaders {
_frameCounter = 0;
_frameTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(_timer) userInfo:nil repeats:YES];
- //[self calculateBlurTextures];
+ [self calculateBlurTextures];
[self fluidInit:_fluidVFrameBuffer];
[self fluidInit:_fluidPFrameBuffer];
@@ -15,7 +15,8 @@ @implementation TFAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowWillCloseNotification:) name:NSWindowWillCloseNotification object:nil];
[_GLView start];
- [self toggleFullScreen:nil];
+
+ //[self toggleFullScreen:nil];
}
- (IBAction)toggleFullScreen:(id)sender {
View
@@ -14,9 +14,13 @@
CVDisplayLinkRef _displayLink;
CGDirectDisplayID _viewDisplayID;
- CGPoint _mouse[16];
- CGPoint _mouseD[16];
- CGPoint _oldMouse[16];
+ CGPoint _mouseKinect[16];
+ CGPoint _mouseDKinect[16];
+ CGPoint _oldMouseKinect[16];
+
+ CGPoint _mouse;
+ CGPoint _mouseD;
+ CGPoint _oldMouse;
TFShader *_shader;
//TFFluidShader *_shader;
@@ -101,29 +101,41 @@ - (CVReturn)drawWithTime:(const CVTimeStamp *)outputTime {
CGLLockContext(contextObj);
[[self openGLContext] makeCurrentContext];
-
- [self _openNI];
- Vector2D mouseToUse = {0, 0};
- Vector2D mouseDToUse = {0, 0};
+ if (IsOpenNIEnabled) {
+ [self _openNI];
+
+ Vector2D mouseToUse = {0, 0};
+ Vector2D mouseDToUse = {0, 0};
- for (int i = 0; i < 16; i++) {
- Vector2D mouse = { _mouse[i].x, _mouse[i].y };
- Vector2D mouseD = { _mouseD[i].x, _mouseD[i].y };
- Vector2D oldMouse = { _oldMouse[i].x, _oldMouse[i].y };
+ for (int i = 0; i < 16; i++) {
+ Vector2D mouse = { _mouseKinect[i].x, _mouseKinect[i].y };
+ Vector2D mouseD = { _mouseDKinect[i].x, _mouseDKinect[i].y };
+ Vector2D oldMouse = { _oldMouseKinect[i].x, _oldMouseKinect[i].y };
- if (oldMouse.x != 0 && oldMouse.y != 0) {
- mouseD.x = (mouse.x - oldMouse.x) * self.frame.size.width;
- mouseD.y = (mouse.y - oldMouse.y) * self.frame.size.height;
+ if (oldMouse.x != 0 && oldMouse.y != 0) {
+ mouseD.x = (mouse.x - oldMouse.x) * self.frame.size.width;
+ mouseD.y = (mouse.y - oldMouse.y) * self.frame.size.height;
+ }
+
+ if (Vector2DDistance(mouseD, mouse) > Vector2DDistance(mouseDToUse, mouseToUse)) {
+ mouseToUse = mouse;
+ mouseDToUse = mouseD;
+ }
}
-
- if (Vector2DDistance(mouseD, mouse) > Vector2DDistance(mouseDToUse, mouseToUse)) {
- mouseToUse = mouse;
- mouseDToUse = mouseD;
+ _shader.mouse = CGPointMake(mouseToUse.x, mouseToUse.y);
+ _shader.mouseD = CGPointMake(mouseDToUse.x, mouseDToUse.y);
+ } else {
+ if (_oldMouse.x != 0 && _oldMouse.y != 0) {
+ _mouseD.x = (_mouse.x - _oldMouse.x) * self.frame.size.width;
+ _mouseD.y = (_mouse.y - _oldMouse.y) * self.frame.size.height;
+ }
+ _shader.mouse = _mouse;
+ _shader.mouseD = _mouseD;
+ if (_mouseD.x > 0 || _mouseD.y > 0) {
+ NSLog(@"Debug %0.1f, %0.1f", _mouseD.x, _mouseD.y);
}
}
- _shader.mouse = CGPointMake(mouseToUse.x, mouseToUse.y);
- _shader.mouseD = CGPointMake(mouseDToUse.x, mouseDToUse.y);
[_shader draw];
@@ -137,12 +149,12 @@ - (CVReturn)drawWithTime:(const CVTimeStamp *)outputTime {
- (void)mouseDragged:(NSEvent *)event {
NSPoint p = [event locationInWindow];
- _oldMouse[0] = _mouse[0];
- _mouse[0] = CGPointMake(p.x / self.frame.size.width, p.y / self.frame.size.height);
+ _oldMouse = _mouse;
+ _mouse = CGPointMake(p.x / self.frame.size.width, p.y / self.frame.size.height);
}
- (void)mouseUp:(NSEvent *)event {
- _oldMouse[0] = _mouse[0];
+ _oldMouse = _mouse;
}
- (BOOL)_openNI {
@@ -178,16 +190,16 @@ - (BOOL)_openNI {
for (int i = 0; i < 16; i++) {
if (locations[i].X != -1) {
- _oldMouse[i] = _mouse[i];
+ _oldMouseKinect[i] = _mouseKinect[i];
// Translate
locations[i].Y = (-locations[i].Y + 480);
locations[i].Y *= 2;
- _mouse[i] = CGPointMake(locations[i].X / 640, locations[i].Y / 480);
+ _mouseKinect[i] = CGPointMake(locations[i].X / 640, locations[i].Y / 480);
} else {
- _oldMouse[i] = _mouse[i];
- _mouse[i] = CGPointZero;
+ _oldMouseKinect[i] = _mouseKinect[i];
+ _mouseKinect[i] = CGPointZero;
}
}
}
@@ -119,7 +119,6 @@
00E7808214F322B000FC4550 /* GHGLProgram.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHGLProgram.m; sourceTree = "<group>"; };
00E7808314F322B000FC4550 /* GHGLTexture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHGLTexture.h; sourceTree = "<group>"; };
00E7808414F322B000FC4550 /* GHGLTexture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHGLTexture.m; sourceTree = "<group>"; };
- 00E7808514F322B000FC4550 /* GHGLUCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHGLUCommon.h; sourceTree = "<group>"; };
00E7808614F322B000FC4550 /* GHGLUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHGLUtils.h; sourceTree = "<group>"; };
00E7808714F322B000FC4550 /* GHGLUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHGLUtils.m; sourceTree = "<group>"; };
00E7808814F322B000FC4550 /* GHQuaternion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHQuaternion.h; sourceTree = "<group>"; };
@@ -268,7 +267,6 @@
00E7808214F322B000FC4550 /* GHGLProgram.m */,
00E7808314F322B000FC4550 /* GHGLTexture.h */,
00E7808414F322B000FC4550 /* GHGLTexture.m */,
- 00E7808514F322B000FC4550 /* GHGLUCommon.h */,
00E7808614F322B000FC4550 /* GHGLUtils.h */,
00E7808714F322B000FC4550 /* GHGLUtils.m */,
00E7808814F322B000FC4550 /* GHQuaternion.h */,

0 comments on commit 7a78065

Please sign in to comment.