Wait what? I'm supposed to like math? As a programmer I'd agree up to one point: When you know what the math equation is but not the reasoning behind the math.
What's thrown me off is Unity3D's Orthographic camera settings. I'm going to let those 2 links there sink in for a moment. Ok, now what this is in laymen's terms is turning 3D graphics into 2D ones. A project I'm working on outside of school is using this and we had a problem. We could not equate Unity's Unit measurement to pixels.
See everything in Unity, in terms of size, is measured in Units. For physics and in game distances these units are 1 meter long. Buuuuuuuuuuuuuuuuuut on screen they can have varying sizes due to distance (under the Perspective Camera). Ortho (my shorthand here) fixes this by ignoring perspective. No matter how close or far an object stays the same size.
Same 3 items, but perspective (on left) makes the red look so much bigger! |
Now here's the problem: I've yet to find documentation as to how many screen pixles something takes up based on the Ortho camera and it's size. I did figure out, via trial and error, that the Camera size is half the height of the screen, in units. Reversing, a screen has 2 times the Camera Size Units in height.[1]
Now you noticed I said at the beginning that I go insane when I know the equation but not the reasoning? Yeah, this was blow number 1 to me. The next one happened while I was trying to get some sleep one night. I kept rolling the numbers around in my head and I realized something. Something horrible, mathematically, but sensible when it came to future programming in Unity:
Screen Height (pixels) / (2 x Camera Height (units)) =
The magical Unit to Pixel Ratio
I wrote this down on a whiteboard that is on the wall next to my bed (godsend when you get late night inspirations). I think, however, for the fact that I did that rather than sleep I kind of started going insane. I went around the next day acting like a mad scientist that had discovered a secret zombie formula. I know stress does weird things to people but this was odd even for me.
So I guess I do have secret knowledge now, for what it's worth. So that's been my two weeks, see you next week.
Note [1] : You'll notice I didn't mention width in terms of units. This is determined from the height in units and the ratio (in pixels) between the height and width of the project. In the example I put up about camera size, and 800 by 600 and a camera size of 10 would mean the Unit size is 26.6666 by 20. At least THAT math makes sense.
So I guess I do have secret knowledge now, for what it's worth. So that's been my two weeks, see you next week.
Note [1] : You'll notice I didn't mention width in terms of units. This is determined from the height in units and the ratio (in pixels) between the height and width of the project. In the example I put up about camera size, and 800 by 600 and a camera size of 10 would mean the Unit size is 26.6666 by 20. At least THAT math makes sense.
No comments:
Post a Comment