I want to rotate my Libgdx Perspective Camera like the device, so that I can put 3d Objects on specific points in my room and when I rotate my device my perspective camera should do the same.
I found this code in the internet:
//update camera rotation
//get rotation matrix
Matrix4 mat4 = new Matrix4();
Gdx.input.getRotationMatrix(mat4.val);
//set new rotation
camera.up.set(mat4.val[Matrix4.M11], mat4.val[Matrix4.M12], mat4.val[Matrix4.M10]);
camera.direction.set(-mat4.val[Matrix4.M21], -mat4.val[Matrix4.M22], -mat4.val[Matrix4.M20]);
camera.update();
Andthis seems to work with portrait mode, but I use landscape mode. Does anyone know how to rotate the matrix correctly ?
Hm... I use the same code, my world has y up. However it does not work in portrait mode, but only in landscape mode.
I'd also like to know how to get that working in portrait mode. Of course, it would be best if it would not matter if I hold the phone in portrait or landscape mode or even in a 45° angle. Is this possible ?
Related
TLDR: I want to rotate camera but render sprites in regards to their world position not camera position.
Howdy,
I'm currently using LibGDX and have come across an issue in regards to camera/object rotation.
Say I have my camera with a rotation of 0 and I have an object(sprite) to the left of the camera's center.
i.e.
Camera Normal (0 degrees rotation)
The sprite renders fine when given a standard world coordinate, however once I rotate my camera, that world coordinate differs from the camera's new (x, y) values.
If I then rotate my camera smoothly 90 degrees to the right(clockwise so that the up direction is facing to the right like the picture below), the object(sprite) that used to be on the left should have simulated a left rotation in regards to the camera (the rotation happens via the camera, the sprite just needs to update position) and now be below the camera's center point.
i.e.
Camera Rotated (90 degrees clockwise)
I'm confused as to how I would calculate the sprite's new locations/positions during the smooth rotation.
Cheers,
Solist.
After looking everywhere for a solution to this problem for 3 weeks it was merely a matter of me needing to call the method
batch.setProjectionMatrix(camera.combined);
in order to update the sprites to their new position in regards to the changing camera rotation.
This link here explains how the Projection Matrix works.
I have an existing iPad app (XCode 4.6, iOS 6.2, ARC and Storyboards). It is currently in the App Store in Portrait mode only; I have had several requests for landscape mode. Unfortunately, all of the lines, etc are drawn using CG methods, controlled mathematically. This is what it looks like in portrait mode:
and this is what it looks like in landscape mode:
My question is: where can I find some good docs that will give me the basic steps I need to convert this app for both modes, knowing that the drawing is controlled mathematically?
If it is controlled mathematically, the best way is to refer all coordinates to the dimensions of the parent view, specifically to the property self.view.bounds that changes with the rotation of the device.
Then you have to redraw the interface when the orientation has been changed. A good way to do it is inside the method:
-(void)viewWillLayoutSubviews
If did some custom views in the past with CG methods and the best way is to refer everything to the bounds. In that way when you change the screen size, either by rotating or by using it on the iPhone it works without modifications.
update
Imagine that you have a point at (76.8, 512.0) this is precisely in an iPad and portrait orientation, a 10% of the width and a 50% of the height.
So for every pair of coordinates instead of using them with absolute numbers you have to replace them by fractions of the dimensions of the parent view:
// old drawing method
CGPoint oldPoint = CGPointMake(76.8, 512.0);
// new drawing method
CGFloat W = self.view.bounds.size.width;
CGFloat H = self.view.bounds.size.height;
CGPoint newPoint = CGPointMake(0.1 * W, 0.5 * H) // 76.8 = 0.1 * 768; 512 = 0.5 * 1024
In this second case; when you change the orientation so will the bounds change and the coordinate will get new values, but the proprotion will be the same as in the other orientation, 10% in horizontal and 50% in vertical.
You get the idea.
I'm working on PocketWallet application in which I'm taking any type of card rear and front images and then save them in Database. My problem is that when I take image in portrait mode the rotation of images showing well in my resulting view. But when I take image in landscape mode then the images rotate in 90 degrees. How can I set the rotation of the image in portrait mode after taking in landscape.
I'm using UIimagePickerCamera for taking image.
please help me......thanks in advance
If you want to find out if your image was taken in landscape mode, take a look at the imageOrientation property of UIImage. The UIImagePickerCamera will set that flag correctly. It sounds like your app simply needs to make a correction to it. This post gives you a method for how to do that.
I have a little iPad app which shows a MKMapView instance (map). In order to save the state I try saving the map.region to the NSUserDefaults. This works very well storing only the single values as doubles. On launching, the app combines the numbers and produces a valid MKCoordinateRegion. This happens in application:didFinishLaunchingWithOptions:. Now there are several problems.
1) Imagine: You leave the app in landscape orientation. The app saves the corresponding MKCoordinateRegion. The app is terminated. Now, holding the iPad landscape, launching the app, the map doesn't show the same state as before leaving the app. And no, this is not a problem of regionThatFits:. I tracked it down and this is what happens: Also when it isn't visible to the user, the app starts in portrait mode. The app restores his state. After that the map is rotated into landscape mode.
With other words the app saves the landscape state but restores it to portrait. If you repeat these steps the map zooms out with every launch. Not the best UX.
2) Even if problem one would be solved by restoring in the right orientation there is still the problem that the launching orientation could differ from the leaving orientation. I think one of the better ways to solve this is to store always the values for the portrait orientation also when the user leaves in landscape. By doing this the state would be restored properly because the app is launched initially in portrait by the system.
One possible way would be to change the latitude/longitude values if the app is left in landscape. But this would be too inaccurate because CLLocationDegrees differ if they are latitude or longitude.
An other way (and I think this would be the best way) would be to "simulate" a rotation of the mapview or to calculate the visible region for the portrait mode when the app is left. But I really don't know how to do this. Here is the point where I need your help and your ideas.
I appreciate every ray of hope. :) — And please tell me if I think into a wrong direction.
Hmm. If I understand your question correctly, you're saving the MKMapView's region (that is, its center and span), and would like to use these values to restore the map's center and zoom level, independently of whether the user rotates the device between sessions.
Have you tried calculating the width-to-height ratio of your map rectangle, and then multiplying out the changes to the span? That is, if your map has bounds of size 800 x 600 in landscape mode, then you'd multiply the longitudeDelta by 600/800 (0.75) and the latitudeDelta by 800/600 (1.33) to get the appropriate span for a 600 x 800 rectangle in portrait mode.
I was wondering if anyone else has used the following in their iOS applications.
https://github.com/elc/ELCImagePickerController
Basically it is a clone of the UIImagePicker using the using the AssetsLibrary that is available with iOS 4.0.
For the most part I like it, but I ran into two issues.
1) When on a device, it take quite a while when there are more that 200 images in a Library. While it works when once it loads, it takes quite a bit longer than I would ideally like.
2) When selecting some images, it brings it over with a different orientation that is shown on the screen. (looks like that happens most with pictures I took from the iPhone) I even seen it turn an image upside down.
I am just curious if anyone else has used this, and if so, were they able to overcome these issues.
Regarding orientation you can use the "ALAssetPropertyOrientation" and get the image orientation and than get any orientation that you may need.
Below are the orientation that iOS support
typedef enum {
UIImageOrientationUp, // default orientation
UIImageOrientationDown, // 180 deg rotation
UIImageOrientationLeft, // 90 deg CCW
UIImageOrientationRight, // 90 deg CW
UIImageOrientationUpMirrored, // as above but image mirrored along other axis. horizontal flip
UIImageOrientationDownMirrored, // horizontal flip
UIImageOrientationLeftMirrored, // vertical flip
UIImageOrientationRightMirrored, // vertical flip
} UIImageOrientation;
1) Load first 100 images, update GUI and load other in background.
2) UIImage have property imageOrientation