WPF How to disable rotation of some elements while screen rotate? - wpf

I am currently creating Win 8.1 universal app. It should have both landscape and portrait view. But only difference between these two states is, that some elements just "turn" to proper direction, while main grid will not rotate.
I don't have enough reputation so here is link to picture of my notion
Is there any way to disable state change rotation only within some elements or do I have to detect the screen orientation and just rotate the desired elements?

This is rather a simple issue and you should implement your second method:
Identify the elements that should not rotate
Rotate them the opposite direction to the screen

Related

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.

Force a box2d scene to Landscape orientation using XCode

Im developing a game using BOX2D. The plist file is set to support just the Portrait orientation. Game starts in the Portrait mode fine. Im using CCLayer for subclassing. Inorder to switch views or scenes i use the below code.
[[CCDirector sharedDirector] pushScene:[ scene]];
So all I want is to change orientation when loading the views/scenes.
1st View/Scene -> Portrait Mode
2nd View/Scene -> Landscape Mode
3rd View/Scene -> Portrait Mode
Tried few sources but was not of good help. Please help me with this. Any suggestion would be appreciated. Thank You.
It seems to me that you want to rotate the entire scene to 90 degree (- or +) to achieve portrait and landscape for your views. One simple way to do this and not getting sucked into is to create a very small layer as a pivot point that holds all your views at the center of the screen.
Create a very small CCLayer that will act as a viewport. lets call this viewportLayer.
set the position of the viewportLayer to the center of the screen.
add the 1st , 2nd and 3rd view scenes as child of viewportLayer.
after you done the above, whenever you need to go for portrait or landscape mode, all you have to do is rotate the viewportLayer by 90 degree (- or +).
as an additional bonus, zooming in and out becomes an easy solution too. to achieve zooming, all you have to do is scale the viewportLayer and not worry about the children. all the calculations for collision will still work nicely because calculations for those would most likely to be done in child layers therefore not getting effected by the parent transformations.

How to easily change the layout of the screen from Portrait to Landscape and vice versa in WPF

Let's suppose we have the designed the layout of some WPF application to be used on standard Full HD screen 1920x1080. Then we need to rotate the screen and install it in a box that is mounted on kiosk PC but in Portrait orientation.
I need to find a way on how to rotate the screen easily or at least in some more elegant way.
I tried to use use RenderTransform and RotateTransform applied to the contents of the window but this rotates the image and of course not the layout.
The controls remain of the same width and height.
Is there a way to do it automatically or should I take each control and change it properties one by one ?
The problem is present for TextBlocks and TextBoxes. They are intended to be used horizontally. You can rotate it but the layout is calculated based to it's horizontal width.
BTW. Rotation of the entire window is not allowed. It throws an exception.
It looks like that I have found the solution myself. If we choose the Layout transform instead of RenderTransform then the visual system does the arrangement and measurement of the layout automatically before the rendering.
The WPF framework does the job in this order
LayoutTransform
Measure
Arrange
RenderTransform
Render
This is best described here LAYOUTTRANSFORM VS. RENDERTRANSFORM - WHAT'S THE DIFFERENCE?

How to Change the Position of a Canvas'es Origin Point

I'm working on a project that allows users to drawing something, and save it in the database.
Basically, the user draws on a canvas, the canvas is 5 time bigger than the screen size, and the canvas is still in the center of the screen (or the screen is in the center of the canvas).
In order to make it flexible for the canvas size (we want to change the size of the canvas in the future), we want to set the center of the canvas as the Origin Point, that is, (0, 0) is in the center of the canvas. So when the mouse clicks somewhere, the point I get is measured based on the center of the canvas.
Maybe you would say:
Canvas.RenderTransformOrigin = (.5,.5). But I'm not asking the rotating center, so it's not the solution.
Canvas.RenderTransform = TranslateTransform (Canvas.Width/2.0, Canvas.Height/2.0). But this just move all the objects on the canvas to the center.
You may also say that, why don't we just translate the MouseClick points with an offset Canvas.Width/2.0, Canvas.Height/2.0, and then translate them back when rendering. We could do that, but too much effort, because we have a lot of other operations to be implemented, so every time we have to translate back and forth.
It looks like you have thought of almost every possible approach to this problem, however, I will see if I can add just one more!
The Canvas properties, Left and Top, which dictate an elements position are attached properties. You could create your own attached properties, OffsetLeft, OffsetTop which allow you to position elements based on the origin you require. These would be simple to implement, when they are get / set, just handle their change event to set the respective Canvas attached properties.

WP7: 3D Perspective Camera Depth Effect

Lets say I have a Canvas with one Image centered on the screen. When I move the image away from the center, lets say to the upper right corner, I want it to be skewed as if the Canvas was a perspective 3d-camera with a certain FOV. Can this be done somehow? Im playing around with the Perspective-property in Silverlight for WP7 but I cant get the effect Im after.
I believe this may be what you're looking for: How to Set this Kind of Perspective Transform in Matrix3D?

Resources