Calculate the distance between the iPhone and a door, knowing their physical widths - iphone

I have this scenario:
I know the physical (not only in pixel) size of the screen of the iPhone.
Also I know the width of a door.
Now, if I have the iPhone camera on (with UIImagePicker or whatever), and I am in the position where the width of the door fits perfectly in the width of the camera, and the iPhone stands perfectly vertical, is it possible to know the distance between the iPhone and the door?

It would depend on the camera specs which vary between devices. For this reason I would try to sample some data with a ruler - for instance take a 3' wide plank, align the edges perfectly and measure distance. Do this with varying widths on different devices and you'll have a formula per device (basic algebra)

Related

How to make responsible camera for multiplie resolutions?

I m working and some 2d game for mobile phones relate to chess, and I have a trouble with show board for different resolutions of mobile screens.
Here u can see how it must be on 9:16 resolution:
https://drive.google.com/open?id=1MFt-FtEtqkk7QWQC2oAtMBA0WAgOIV4h
And how it looks on smaller screen:
https://drive.google.com/open?id=11WLYZwHEa9ijXbekzUbE5ZbjbEnjZ6Lb
How can I protect my chess board from cropping?
Answer: it depends on how you want it to look.
If you just want it to fit perfectly horizontally, you need to perform 3 steps:
Evaluate the width of the Sprite (with Sprite.bounds)
Evaluate the width of the current screen (with Screen.width and using the main Camera)
Scale the Sprite to fit the screen
If you are using UI elements, you can do the same thing but you won't need to use Camera, just scaling according to the Screen width (look for RectTransform.deltaSize to give you the size of a UI element).
If you are using UI, also consider using layout groups, they help you with fitting the content to screen size.
Anyway, in a device with small width, maybe the table will get too small and you might have to think about better options to display the board instead of just scaling with screen width.

Gamekit multiplayer and different screen sizes

I am very new to gamekit, so I am starting with a basic game. 2 players on the screen and allow them to just move around at this point.
I am testing the game with an ipad and a phone, so I am quickly realizing the ipad user has a lot more real estate instead of the same space being resized.
How do I setup the level to be the same amount of space on any device, but just magnified accordingly?
Try this for all the nodes that you want to be resized use the .setScale() method:
let scale = frame.width/667
node.setScale(scale)
667 is the approximate width of an iPhone 6. Feel free to play around with the number 667 to get the right magnification.
Basically what this does is it scales the node according to the size of the screen.
Note: Scaling may decrease resolution of any sprites used.

Unity game scene is not in full screen on mobile

I'am having problem making my app be full screen on all device. on my device, w/c is a low end Jelly bean phone doesn't give me the right resolution I want.
Here is my desired output:
this is still in editor, resolution 1080px by 1920px in Portrait mode
here is the output on my device:
as you can see, you can see a blue part on the screen.
Thanks in advance.
It looks like your background is visible from behind your geometry, the aspect ratio of two screenshot is different. It looks like you designed the game in a 278x490 resolution (aspect 1:1.762) and displaying it in a 480x800 resolution (aspect ratio 1:1.666).
You should always design for the lowest possible aspect ratio, then you don't have this problem.
You have two solutions:
You should add some walls/roofs to make margins that will be visible on wider devices
You can shorten the length of the corridor by scaling the game field up so the width fits.

Calculate the distance between the iPhone and an object, knowing their physical widths (of the iPhone as well)

if you check this thread started from me (Calculate the distance between the iPhone and a door, knowing their physical widths) I accepted an answer, that states, correctly, that if you do not know focal lens data of the camera of the iPhone, there is no easy way to calculate the distance between an iPhone and, let's say, a door, knowing its width.
I have to start another thread now asking:
I know the physical (not only in pixel) size of the screen of the iPhone (for iPhone 5 is 2.31 inches)
Also I know the width of a door.
Now, if I am in the position where the width of the door fits perfectly in the width of the iPhone itself (not of the camera), and the iPhone stands perfectly vertical, is it possible to know the distance between the iPhone and the door in that moment?
Thank you for your kind help!
I assume you mean that there is some outside image capturing device (be it a human eye or another camera) and the image capturing device, the phone, and the door are all in a line such that the phone appears to be the same width as the door.
In this case, you still need a) the distance between the image capturing device and the phone and b) the optical information (such as focal length) of the image capturing device. Just sit down with a pen and paper and draw out the geometry for a little bit and you'll see that.
This is going to involve a trigonometric calculation. I think you might have done R&D on Gyroscope, if not then surely you should refer it.
1) Find angle your phone is making with ground. Like when you point the device's camera to bottom of the object.
2) Now you are having one angle and you are making 90 degree with ground. So basically you are forming a right angled triangle. And you had just found one of your angle near your hand.
3) You can approximate distance of your phone from surface to your hand. So you got one side of triangle and one angle. Thus you can find second side i.e distance between you and object.
Hope this helps. :)

What's the difference between position and positionInPixels

In the past I always see that the property called position and positionInPixels are the same. This time position * 2 == positionInPixels. Who can tell me what's the difference between these 2 properties or when their value will be different?
position is in points and positionInPixels is in pixels. On non-retina device 1 point = 1 pixel. On retina device like iPhone 4/4S and the New iPad, 1 point = 2 pixels.
Per iOS Human Interface Guidelines:
Note: Pixel is the appropriate unit of measurement to use when discussing the size of a device screen or the size of an icon you create in an image-editing application. Point is the appropriate unit of measurement to use when discussing the size of an area that is drawn onscreen.
On a standard-resolution device screen, one point equals one pixel, but other resolutions might dictate a different relationship. On a Retina display, for example, one point equals two pixels.
See "Points Versus Pixels" in View Programming Guide for iOS for a complete discussion of this concept.
position gives you a position in points, whereas positionInPixels gives you the position in pixels. On an iPhone 4, e.g., position can range from (0,0) to (320, 480) (in portrait mode); positionInPixels can range from (0,0) to (640, 960) to reflect the higher resolution its retina display.
Basically, they are different on retina display devices; they are the same on non retina display devices.
Hope this helps...
When you use Retina display your canvas still consists of 320x480 points but each point is composed of 2 pixels. In the standard display each point is one pixel. This is why retina display is more detailed as more pixel data can be used in textures. So position in pixels refers to the position on a specific pixel. (i.e. point 0 can be pixel 0 or pixel 1 in high retina display)