Render only part of the SCNView - scenekit

I have a scene in which only some rectangular region in the SCNView is changing. How can I instruct SceneKit to only render that dirty rectangle (thus, culling nodes outside that region)?
I tried calling setNeedsDisplay on my SCNView with a dirty rectangle but that didn't cause SceneKit to render.
SCNRenderer.render takes a viewport parameter. Can I somehow use that without having to abandon SCNView and its conveniences?

Related

How do you have a panel `ClipToBounds` without clipping children?

I have a custom Panel implementation that renders objects relative to a physical space (think like a floor plan). The panel allows the following actions:
Zoom in/out
Pan up/down/left/right
and more that isn't relevant to this question
The panel lives in with several other elements on screen, and I need to make sure the custom panel's graphics don't spill over the navigation and other controls.
The problem is this:
If the panel is set to clip, it clips the children before arranging them.
Let's say I have a circle in the floor plan and the user zooms in enough to make the circle bigger than the parent control. The panel applies clipping to the circle as if it were placed dead center, then arranges the circle where it is supposed to be. The end result is that the circle no longer looks like a circle and I have gaps in the image.
I need the clipping to be applied after arranging the elements, or only applied to the overall image as compiled by the children. How can I do this?
It turns out I had the opposite problem of the question the OP had in his letter to Dr. WPF where ClipToBounds = "Maybe"
If I override the GetLayoutClip() method in my control and return null, I essentially turn off clipping for the element. However, since ClipToBounds is still true for my panel, the rendered item doesn't spill over the rest of the application.
In the base class for all items that will be added to my custom panel I have this:
protected override Geometry GetLayoutClip(Size layoutSlotSize)
{
return null;
}
In my case this is exactly what I want. I honestly want my layout clip to be based on the parent panel and not the child size (with no sense of location within the panel).

Zoom in and out of a scene?

What is the correct way to zoom in and out of a scene in SceneKit?
So when I enable the standard camera control in a scene and pinch in and out the scene gets bigger and smaller. What is that pinch really doing?
Is it changing the scale of the whole scene? Is it moving the camera closer?
I want to implement the same effect but programmatically.
What should I do to obtain the same effect?
When you pinch it's the field of view (xFox and yFov properties) of your camera that's changed. Changing the field of view is not the best way to zoom because it can dramatically change the perspective.
Moving the camera closer to your object is a good solution.
Also note that the "free camera" behavior is suitable for 3D viewers (such as Preview.app) but will rapidly become frustrating in any other app. At this point you might want to implement your own camera controller.
At any given point the camera has a position in space, it has a rotation for each of its own axis compared to each of the world axis, to have a zoom in and zoom out, you have to move the camera in the +z/-z axis direction.
Along the Cameras own Z/-Z axis.
For those on OSX, I used this in my SCNView subclass:
override func scrollWheel(theEvent: NSEvent) {
let cam = pointOfView!.camera
cam!.xFov = cam!.xFov - Double(theEvent.deltaY)
cam!.yFov = cam!.yFov - Double(theEvent.deltaY)
}
There are two (minor) problems that could be addressed with a little extra code. One is that the values can go negative, at which point the image is flipped inside-out. The other is that mouse acceleration can cause the zoom level to go too fast if you really spin the wheel. Limits on both of these would be a good idea, but in my app the behaviour was fine as it is above.

Resize custom UITableViewCells (SubViews) on Orientation iOS6

# I have a UITableView with custom UITableViewCells. My views are autorotated on orientation as I have implemented the ios6 orientation methods.
# I am not using xib file and drawing all the contents programmatically (imageView,label).
When I rotate my device the tableView and Cells are rotated but cell subviews are not proper in terms of size and position.
# So how to resize the current cells being drawn on the TableView. As the cells are drawn asynchronously and not all at once, how to apply resizing ?
# Do I need to apply AutoResizingMasks or NSLayoutConstraint ? My TabBar and NavigationBar are properly resized but cells are not.
***Plz note: I have not added any block of code, bcoz I simply dnt understand how to proceed as for already drawn cells and those being drawn dynamically after objectForRowAtIndexPath.
I have found the answer. As for orientation in ios6, there are many links for implementing new methods.
Initially my views were not supporting rotation till I found that my tabBarController was a RootViewController for the app so I added (BOOL)shouldAutorotate
{return YES;
} in my subclassed TabBarController class
and in my info.plist added key value pairs for supported interface orientations, this values will be global to the application unless you specify exceptions in current UIViewController via - (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
For implementing rotation in UITableView, I called reloadData(); via using - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self.tableView reloadData];
}
Its not necessary to write a custom UITableViewCell Class, as you can redraw cells in – tableView:cellForRowAtIndexPath: method. As I already had a custom UITableViewCell Class I draw new cells in layoutSubviews(); by getting [[UIApplication sharedApplication] statusBarOrientation] method. If you have any custom UIViews inside the cell you need to redraw the rect to support the landscape mode. Basically I am also supporting ios5 so I am not using AutoLayout via XIB. You can also use autoresizing masks to each subviews as per your layout frames.
reloadData(); is not expensive to memory as you don't call for all the cells # the same time and only the visible cells in the UITableView are redrawn and cells are reused as before.

How to keep an MKAnnotation View Image fixed on the center of the map as the user pans and moves the map around (iOS 6)?

using iOS 6 MapKit, I would like to define an MKAnnotation (such as a pin, or a custom one) that remains fixed on the center of the map view as the user moves the map around. Once the user stops moving the map, I would like to be able to read the new coordinates of the annotation. How can I do this?
Thanks
The easiest way is to simply add your custom UIView to your MKMapView as a subview. This means when your user moves the map it will stay fixed. You will most likely have to pass through the touch events so that users can move over your custom view but worry about that later.
When your map view stops moving take its center coordinate. The MKMapView can calculate its coordinate based on its center etc [mapView centerCoordinate];
I know this is a bit old but I recommend you DSCenterPinMapView
It is a custom MapView with an animated and customizable center pin useful for selecting locations in map.
You should install the Pod and then, as a solution to your question you should implement the delegate so that you can get the location where pin drops.
pinMapView.delegate = self
extension MyViewController: DSCenterPinMapViewDelegate {
func didStartDragging() {
// My custom actions
}
func didEndDragging() {
// My custom actions
selectedLocation = pinMapView.mapview.centerCoordinate
}
}

How to move elements within picturebox?

Is there any simple way to move picture parts (any stuff created with DrawImage or DrawString)?
My smart idea:
Override DrawImage(DrawString) method adding ability to store width, height, left, top, of drawn image (and may be boolean variable 'sizable' if I use DrawImage method) to a list of objects. Attach function "WhatToMove" to PictureBox's MouseMove event, which walks through a list of stored rectangle objects, detects what rectangle cursor is over, in case of resizeable rectangle detect if cursor is over any of rectangle's borders and pass this stuff as parameters to the MouseDown function, when I click. Then MouseDown function will attach new function "MoverResizer" to MouseMove event, which redraws picture box with moved or resized parts of image, updates proper rectangle object in list, and also detachs "WhatToMove" from MouseMove. On MouseUp and Leave events of PictureBox detach "MoverResizer" and attach "WhatToMove".
If you think this idea can live you will really help me if tell me how to override DrawImage.
My dumb idea:
Create Labels without text and with borders and locate them over PictureBox right over proper image parts. Then make them draggable and sizeable with their own events. Then translate positions of labels to positions of parts of picture and redraw picturebox. This is simply but I think not so perfect as method above.

Resources