CLColorPicker: User friendly color picker for Mac apps

Here is implementation of color picker control which is similar to one that used in original Mac applications like Numbers, Pages, Keynote. Original one has lots of small pictures. This control based on NSSegmentedControl and have numbers of useful thinks to know, so it's not just implementation but also good place to look: - how to subclass NSSegmentedCell - how is working NSTrackingArea - create NSPopover CLColorPicker Easy to use. Just create view and add on your master view: CLColorPicker *control = [CLColorPicker alloc] initWithFrame:NSMakeRect(100,100, 70, 24)]; [self.view addSubview:control]; To get selected color: NSColor *color = control.selectedColor; Or set color: [control setSelectedColor:yourColor];

command atos

Very useful command `atos`.

A stripped, optimized version of Sketch was built as an x86_64 position-independent executable (PIE) into /BuildProducts/Release. Full debug symbol information is available in, which sits alongside When was run, the Sketch binary (which was built at 0x100000000) was loaded at 0x10acde000. Running 'sample Sketch' showed 3 addresses that we want to get symbol informa-tion information tion for -- 0x10acea1d3, 0x10ace4bea, and 0x10ace4b7a. First notice that the .dSYM is next to the .app: % ls -1 /BuildProducts/Release/ Now, to symbolicate, we run atos with the -o flag specifying the path to the actual Sketch executable (not the .app wrapper), the -arch x86_64 flag, and the -l _x1_acde___ flag to specify the load address. % atos -o /BuildProducts/Release/ -arch x86_64 -l 0x10acde000 0x10acea1d3 0x10ace4bea 0x10ace4b7a -[SKTGraphicView drawRect:] (in Sketch) (SKTGraphicView.m:445) -[SKTGraphic drawHandlesInView:] (in Sketch) (NSGeometry.h:110) -[SKTGraphic drawHandleInView:atPoint:] (in Sketch) (SKTGraphic.m:490)

zNear and zFar plane Size

Following math works for perspective projection. aEwwS Height of zNear, another words it's height of near plane: [code lang="c"] float H_near = 2*near*tan(fovy/2);[/code] And the same for zFar, to get height of far plane: [code lang="c"] float H_far = 2*far*tan(fovy/2);[/code] To get width, just multiple on aspect ratio of your screen. What is Perspective Projection? Perspective projection is a form of pictorial drawing that gives the illusion of depth onto a flat surface, very similar to that of viewing of the object through the human eye. In comparison to other types of projection systems, for example orthographic and oblique, the spectator is viewing the object from infinity. The projection rays radiate parallel to each other from the object back to the spectator, compared to perspective projection where the projected rays radiate from the object to a single point at a given distance from the object. source Very good material about perspective projection. A computer monitor is a 2D surface. A 3D scene rendered by OpenGL must be projected onto the computer screen as a 2D image. GL_PROJECTION matrix is used for this projection transformation. First, it transforms all vertex data from the eye coordinates to the clip coordinates. Then, these clip coordinates are also transformed to the normalized device coordinates (NDC) by dividing with w component of the clip coordinates. About Perspective Projection + code

Charts control with animations for iOS

Almost half year ago I've made this control. For one idea, but then I found that my idea does not good enough to be implemented. It has just 2 classes VBPieChart, superclass UIView, and VBPiePiece, superclass CAShapeLayer. And really used just VBPieChart. All chart based on CALayer's and depends to QuartzCore. Example: VBPieChart *_chart = [[VBPieChart alloc] init]; [self.view addSubview:_chart]; [_chart setFrame:CGRectMake(10, 50, 300, 300)]; [_chart setEnableStrokeColor:YES]; _chart.length = M_PI; _chart.startAngle = M_PI; [_chart.layer setShadowOffset:CGSizeMake(2, 2)]; [_chart.layer setShadowRadius:3]; [_chart.layer setShadowColor:[UIColor blackColor].CGColor]; [_chart.layer setShadowOpacity:0.7]; [_chart setHoleRadiusPrecent:0.3]; NSDictionary *chartValues = @{ @"data one": @{@"value":@35 }, @"data two": @{@"value":@20 }, @"data tree": @{@"value":@10 }, @"first ": @{@"value":@40}, @"second": @20, @"third": @40, @"fourth": @10, }; [_chart setChartValues:chartValues animation:YES]; chartValues contains items of chart. 1. name of piece 2. dictionary with NSNumber or parameters: - value actually size of piece - color, UIColor - accent, bool value to show this item with shift VBPieChart has 5 different types of animations. Cocoacontrols logo
cocoapods logo

Share source code of my app

I've uploaded source code of my app on Github under MIT license. App and code is free, you can do with it where you want. If you will want add some improvements for app, I may will release them in next version ;) Thanks P.S.: Code not cleaned and lack of comments.

Rotate model with GLKit - Quaternions and Matrices math

I was looking for algorithm to apply additional rotation to model with current rotation matrix, and found this: GLKVector3 up = GLKVector3Make(0.f, 1.f, 0.f); up = GLKQuaternionRotateVector3( GLKQuaternionInvert(quarternion), up ); GLKQuaternion quarternion = GLKQuaternionMultiply(quarternion, GLKQuaternionMakeWithAngleAndVector3Axis(delta.x * RADIANS_PER_PIXEL, up)); It's from this small tutorial about rotation: A bit modified code, source here Under code a bit more text and links #define RADIANS_PER_PIXEL (M_PI / 320.f) /** * do this in viewDidLoad * * these are class variables: CGPoint iniLocation; GLKQuaternion quarternion; */ - (void) initArcBall { quarternion = GLKQuaternionMake(0.f, 0.f, 0.f, 1.f); iniLocation = CGPointMake(0.f, 0.f); } /** * do this in update // skip auto rotation //baseModelViewMatrix = GLKMatrix4Rotate(baseModelViewMatrix, _rotation, 0.0f, 1.0f, 0.0f); // rotate with quaternion instead baseModelViewMatrix = [self rotateMatrix:baseModelViewMatrix]; */ - (GLKMatrix4) rotateMatrix:(GLKMatrix4)matrix { GLKVector3 axis = GLKQuaternionAxis(quarternion); float angle = GLKQuaternionAngle(quarternion); if( angle != 0.f ) { matrix = GLKMatrix4Rotate(matrix, angle, axis.x, axis.y, axis.z); } return matrix; } // ------------------------------------------------------------------------------------------ - (void) rotateQuaternionWithVector:(CGPoint)delta { GLKVector3 up = GLKVector3Make(0.f, 1.f, 0.f); GLKVector3 right = GLKVector3Make(-1.f, 0.f, 0.f); up = GLKQuaternionRotateVector3( GLKQuaternionInvert(quarternion), up ); quarternion = GLKQuaternionMultiply(quarternion, GLKQuaternionMakeWithAngleAndVector3Axis(delta.x * RADIANS_PER_PIXEL, up)); right = GLKQuaternionRotateVector3( GLKQuaternionInvert(quarternion), right ); quarternion = GLKQuaternionMultiply(quarternion, GLKQuaternionMakeWithAngleAndVector3Axis(delta.y * RADIANS_PER_PIXEL, right)); } - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInView:self.view]; iniLocation = location; } - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInView:self.view]; // get touch delta CGPoint delta = CGPointMake(location.x - iniLocation.x, -(location.y - iniLocation.y)); iniLocation = location; // rotate [self rotateQuaternionWithVector:delta]; }
But that not all what's need to do for applying additional rotation for matrix with rotation. I have modelViewMatrix from which need to extract rotation matrix and then transform this matrix to quaternion and normalise received quaternion. Then apply additional rotation, like at the top. So we will get quaternion with rotations and now we need transform it to matrix back. Get axis and angle with quaternion functions and create new rotation matrix. Remove old rotation from modelViewMatrix and apply new. It's how I did it. May it can be more easy, but I did it in this way. I have function for decompose rotation matrix from transformation matrix. And Quaternion from rotation matrix: inline void CalculateRotation( Quaternion& q ) const { float trace = a[0][0] + a[1][1] + a[2][2]; // I removed + 1.0f; see discussion with Ethan if( trace > 0 ) {// I changed M_EPSILON to 0 float s = 0.5f / sqrtf(trace+ 1.0f); q.w = 0.25f / s; q.x = ( a[2][1] - a[1][2] ) * s; q.y = ( a[0][2] - a[2][0] ) * s; q.z = ( a[1][0] - a[0][1] ) * s; } else { if ( a[0][0] > a[1][1] && a[0][0] > a[2][2] ) { float s = 2.0f * sqrtf( 1.0f + a[0][0] - a[1][1] - a[2][2]); q.w = (a[2][1] - a[1][2] ) / s; q.x = 0.25f * s; q.y = (a[0][1] + a[1][0] ) / s; q.z = (a[0][2] + a[2][0] ) / s; } else if (a[1][1] > a[2][2]) { float s = 2.0f * sqrtf( 1.0f + a[1][1] - a[0][0] - a[2][2]); q.w = (a[0][2] - a[2][0] ) / s; q.x = (a[0][1] + a[1][0] ) / s; q.y = 0.25f * s; q.z = (a[1][2] + a[2][1] ) / s; } else { float s = 2.0f * sqrtf( 1.0f + a[2][2] - a[0][0] - a[1][1] ); q.w = (a[1][0] - a[0][1] ) / s; q.x = (a[0][2] + a[2][0] ) / s; q.y = (a[1][2] + a[2][1] ) / s; q.z = 0.25f * s; } } } Useful links: More about quaternions, iDevGames - Quaternions. Arcball rotation Decompose matrix, functions for GLKit Decomposing and composing a 3×3 rotation matrix Maths - Conversion Matrix to Quaternion

Force change interface orientation in iOS

Found on Stackoverflow interesting hack for interface orientation fix. [self presentViewController:[UIViewController new] animated:NO completion:NULL]; [self dismissViewControllerAnimated:NO completion:NULL]; Some more detail in this answer. My answer on similar question.

ClipMaker - первое приложение в App store ради опыта.

Не судите меня строго, но на порыве популярности #selfie решил сделать приложение :) Хочется посмотреть, выйдет ли что-то из этого. Сам же таким не страдаю и нравится использовать приложение для других целей. Написал за нескольно дней и поэтому не может подвергаться критике ;) Доступно со вчерашнего дня и бесплатно. Всю собранную статистику опубликую. Download_on_the_App_Store_Badge_US-UK_135x40 Страничка на сайте Мне больше нравится делать видео, следующего содержания:

YouTube share controller like in iOS 7

Designed Youtube share controller like in iOS 7. Not finished and has some issues. Use it for your fear and risk. Or just make tests and fix it :) All fixes are appreciated. github-logo-80px

Configuring and compiling VTK 6.1 on Mac OS X 10.9.2 + simple example of VTK usage

Hello. In this short post I will explain how to build static libraries of VTK. Main reason why it needs: Because official "How to" has just 2 lines without any explanations. And by default will be builded dynamic libraries. With which I had a problem like link to vtkCocoaGLView was not found, but it actually was in a library. Let's start. You will need CMake to build and VTK sources. - Launch CMake from your Application folder. In main menu go to "Tool" -> "Install for Command Line Use", in case if you did not install yet. - Unpack VTK to some directory, working place. - Enter to VTK directory and create directory with name build Now you can configure and generate makefile or Xcode project file from console or User interface of CMake application. If you would like to build with makefile in terminal go to next steps, if not jump to Build with Xcode section.

Build in Terminal

- Open Terminal. - Go to build directory of VTK. Copy and past next line: ccmake .. -G "UNIX Makefiles" -DVTK_USE_QVTK:BOOL=ON -DVTK_USE_COCOA:BOOL=ON -DVTK_USE_CARBON:BOOL=OFF -DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 -DCMAKE_INSTALL_PREFIX=/path/to/folder -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=OFF Note: Path to directories should be full without "~". If you change your mind about makefile and Xcode, so you can easily replace "UNIX Makefiles" on "Xcode". In result you will get Xcode project. - DVTK_USE_COCOA and DVTK_USE_CARBON Choose on of UI's, Cocoa or Carbon. Better for latest Mac OS X applications is Cocoa. - DCMAKE_OSX_ARCHITECTURES In my case it's just x86_64, but if you need i386 as well, just replace x86_64 on "i386;x86_64" - DCMAKE_INSTALL_PREFIX Folder to which will be copied result libraries and headers. Create some folder to which you would like install. Or install to system /usr/local. With this option says build dynamic = ON or static = OFF - DBUILD_SHARED_LIBS For deployment target, for example 10.7: -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7 Press enter and you will see configuration panel: 1. press c on keyboard and wait until finish. If it's shows error, press e and press c again. 2. press g 3. check if "Makefile" was generated and located in build directory 4. build with command "make -j 4", 4 - is number of threads which you want to use. 5. and final "make install"

Build with Xcode

1. Open CMake application 2. write path to sources code 3. write path to build directory which is located in VTK source folder 4. press "Generate" button and choose "Xcode" option 5. turn on "Advanced" checkbox 6. find and specify next options: VTK_USE_COCOA - yes VTK_USE_CARBON - no BUILD_SHARED_LIBS - no CMAKE_OSX_ARCHITECTURES - i386;x84_64 7. press Generate button Note: if you have got *.dylib dynamic libraries in product of Xcode project. Delete generated Xcode project and press Configure and Generate buttons again. Now you can open Xcode project and build libraries. Text got quite big, so in next post I will show example of VTK usage. Or you can go to Example directory and try to launch something by yourself if can't wait. :) Enjoy! UPD: One more thing. In configuration you can choose Qt UI, VTK_Group_Qt. A bit old tutorial, I will try to do it late.