Created
October 4, 2013 18:14
-
-
Save jquave/6830213 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void) applySmudgeWithOrigin: (CGPoint)origin: (CGPoint)direction { | |
| CGPoint oldOrigin; | |
| oldOrigin.x=origin.x; | |
| oldOrigin.y=origin.y; | |
| origin.x= invModelViewMatrix2d.a*oldOrigin.x+ | |
| invModelViewMatrix2d.c*oldOrigin.y+ | |
| invModelViewMatrix2d.tx; | |
| origin.y= invModelViewMatrix2d.b*oldOrigin.x+ | |
| invModelViewMatrix2d.d*oldOrigin.y+ | |
| invModelViewMatrix2d.ty; | |
| CGPoint oldDirection; | |
| oldDirection.x=direction.x; | |
| oldDirection.y=direction.y; | |
| //apply the inverse of the orientation matrix to the direction | |
| direction.x = invOrientationMatrix2d.a*oldDirection.x+ | |
| invOrientationMatrix2d.c*oldDirection.y+ | |
| invOrientationMatrix2d.tx; | |
| direction.y = invOrientationMatrix2d.b*oldDirection.x+ | |
| invOrientationMatrix2d.d*oldDirection.y+ | |
| invOrientationMatrix2d.ty; | |
| for(int smudgeIndex=0; smudgeIndex<coordCount; smudgeIndex+=2) { | |
| GLfloat x = posCoords[smudgeIndex]; | |
| GLfloat y = posCoords[smudgeIndex+1]; | |
| float xdist = x - origin.x; | |
| float ydist = y - origin.y; | |
| float distToCenter = pow(xdist,2)+pow(ydist,2); | |
| if(self.activeTool==toolSmudge) { | |
| } | |
| else if(self.activeTool==toolPinch) { | |
| direction.x = -xdist*self.toolIntensity; | |
| direction.y = -ydist*self.toolIntensity; | |
| } | |
| else if(self.activeTool==toolPunch) { | |
| direction.x = xdist*self.toolIntensity; | |
| direction.y = ydist*self.toolIntensity; | |
| } | |
| CGPoint distortionVector = [self getDistortionFromDistance2D:distToCenter:CGPointZero:direction]; | |
| x += distortionVector.x; | |
| y += distortionVector.y; | |
| posCoords[smudgeIndex] = x; | |
| posCoords[smudgeIndex+1] = y; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment