Post

Replies

Boosts

Views

Activity

Apple Pencil azimuth not working
I have a drawing app that I created and have sold on the App Store since 2018. It requires an Apple Pencil. My app uses the azimuth feature to orient the brush pattern that is drawn on the screen. A user just contacted me and said his azimuth feature is not working. Now it works fine for me, and I have not heard complaints from other users, so this leads me to believe it could be a problem with his Pencil. I wanted to show my code just to rule out that the problem is on my end and also get suggestions on what I should tell this user to do. Should he just contact Apple about it?                      // calculate the pencil direction let vector1 = touch.azimuthUnitVector(in: selectedCanvas) let angle = atan2(vector1.dy, vector1.dx) let azimu = angle - CGFloat(Double.pi) / 2.0 // adjust for wonky azimuth rotation translation if azimu >= -4.5 && azimu <= 0 {       rot = abs(azimu) } else {        rot = 6.2 - azimu } The azimu is then used as a point rotation in a basic Bézier curve and drawn on the screen. If it works on one iPad, it should work on all of them, right? He’s using an iPad Pro and so am I. I asked if he was using an Apple Pencil and he said yes.
0
0
641
Nov ’21
Drawing in multiply blend mode with Metal
I have posted a few questions recently about the drawing app I have been building over the last few years. I consider myself an intermediate coder and am reaching a point where my app is nearing completion. There are just a few things I have been unable to figure out on my own that I need help with. One feature that I was able to achieve with a UIImageView was the ability to draw brushstrokes on the screen in a multiply blend mode. I loved this! However once I decided to switch over to using metal, I have been unable to achieve the same effect. I have tried different variations on the descriptor color attachments because that seems to be where I would make this feature happen. But alas I have been unable to make it work. I am using an MTKView, capturing Apple Pencil touches, drawingPrimitives, and present(currentDrawable). My textures for the brushstrokes are pdf images. Here is the descriptor code I am using in the pipeline setup for regular drawing. It works great: let descriptor = MTLRenderPipelineDescriptor() descriptor.vertexFunction = vertProg descriptor.fragmentFunction = fragProg descriptor.colorAttachments[0].pixelFormat = .bgra8Unorm descriptor.colorAttachments[0].isBlendingEnabled = true descriptor.colorAttachments[0].rgbBlendOperation = MTLBlendOperation.add descriptor.colorAttachments[0].alphaBlendOperation = MTLBlendOperation.add descriptor.colorAttachments[0].sourceRGBBlendFactor = MTLBlendFactor.sourceAlpha descriptor.colorAttachments[0].sourceAlphaBlendFactor = MTLBlendFactor.one descriptor.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactor.oneMinusSourceAlpha descriptor.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactor.oneMinusSourceAlpha
9
0
1.8k
Dec ’20
Drawing to MTKView, then resizing
Learning Swift and Metal has been very challenging for me. It's taken me two years to get this far with my app and I am finally to the point where I'm asking questions. I'm even open to hiring someone who can help me. I have been trying to build a drawing app that uses the Apple Pencil. It is working pretty well, but one feature that I would like to have is the ability to resize and move what I have drawn on screen. I have achieved this by using a pinch and a pan gesture recognizer. This works great, however after resizing, when I continue drawing, I can no longer draw on the entire screen. I can only draw within the boundaries of the now smaller resized MTKView. Is there a way to maintain the screen size on the drawing area but only scale and move the drawing elements? For the drawing process, I am using drawPrimitives and present.currentDrawable with UITouch events.
1
0
614
Dec ’20
Drawing app using Metal slows down as screen fills up
I have been studying Metal and to help, I used an old drawing app and converted the drawing layer to a MTKView. I got textures working using pdf images and they draw very well on the screen using Apple Pencil. The initial FPS is 120. But as I draw on the screen and begin filling it up with brush strokes, the FPS will gradually drop until it is well below 50 FPS. If I clear the canvas, the FPS goes back up to 120 and the issue will repeat. Here is the basic method I am using that I have found in other drawing app code: TouchesBegan I begin the vertices TouchesMoved I append vertices and draw primitives using point with the vertices count, then setNeedsDisplay is called and I present and commit the drawable TouchesEnded is same as moved, but then clear the vertices Why is the FPS drop happening? I presume because it is redrawing the entire view every frame and the textures have alphas. Is there a method I could use to maintain the FPS throughout the life of the drawing?
7
0
1.9k
Nov ’20