I know people have asked about this before but I can’t see any answers almost.
Has anyone here made something like this? I have come pretty close by doing the following:
I move the camera in x and y using the arrow keys
I offset the perspective using this sample from the unity docs:
At first I though I only needed to offset the perspective to get the effect but it seems I must also move the camera.
Now the tricky part is I have no idea how to calculate how much I should offset the perspective based on how much I move the camera sideways and up. So far I have found these values by trial and error.
Does anyone have more information about how to get this effect in Unity? When finished I want to have an effect where you can see dices laying on a table and when you tilt your device (iPhone, Android etc) I want to get that hologram effect.
I know you could just rotate the camera and so on but it doesn’t give the same nice effect really and it looks wrong when both tilting the device sideways and up.
In this video another game called MachDice does this in a beautiful way, take a look at 1.17. It seems something is done to the perspective rather than just rotating a camera or rotating the dices.
There are several threads about this subject (search the forum for anaglyph if you want to find them). The proper way of setting up your projection matrices is described in this thread (I suggest reading the entire thread, as the earlier posts have some incorrect solutions): http://forum.unity3d.com/threads/11775-Stereo-Anagylph-Rendering-HELP!!!-)/page3
Note that the full solution posted there may not work for you, as it won’t run on the iphone, but the matrix math is solid ;).
Hmmm ok so I have read through this thread a couple of times now but I still think it is hard to really understand what to do here (for me atleast).
My first attempt at doing this involved just moving the camera to the left and right and using a lookat (where I would look at the center). It looked ok but not as good as other examples (such as HoloToy and MachDice). I then started reading about projection matrixes.
Am I correct when I say that I set the projection matrix because I want to compensate for the distortion caused when looking at my iPhone screen when it is tilted? The same thing that would happen in a headtracking scenario when looking at a monitor or tv from the side? Because when just moving the camera and using lookat I don’t really get that 3d “pop” feeling.
The thing I still struggle with is the kind of formula I should use to get this projection matrix, I see all kind off different formulas for this involving the position of the camera, the aspect ratio and so on. But when trying these it doesn’t seem to work like I imagine it.
I basically want to simulate an effect where the iphones screen would have “sunken into the glass” like if the screen was a window to a box extending inwards from this location. When tilting the device it should look like i’m looking at more of the sides of this box rather than a plane that is tilting as the device is tilting.
Does this make any sense to you all Look at HoloToy or iDesktopVR to see what I mean.
So what I really need is a clue to.
How should I move the camera? Left to right, should lookat be used?
How to calculate the projection matrix given what is used in 1.)
EDIT:
After looking more at some tilt perspective dice games it seems many do something similair to:
Moving the camera to the left or right when the device tilts
Then offseting the whole camera rendering so that the base of the object jumps back to its original position.
It’s like if you glued the bottom of the dice to the ground and instead of moving the camera to the left or right only the top of the dice is moved, some kind of perspective shearing. That is what I am trying to achive.
You are on the right track, and definitely will use the Camera.projectionMatrix method and work from that example.
You do not rotate the camera at all - it should stay perpendicular with what you would consider the screen plane.
If you use the Camera.projectionMatrix example and view the result with the camera selected in the scene view, you can see the offset view frustum.
The trick is to make the view frustum lock into place while the camera instead moves on the x, y, and z axes relative to the screen or the plane of the far clipping plane. If you set the far clipping plane to something low like 20, you can visualize this better.
I got this to work for a cave-like head tracking system. It was a bit of a kludge because it was done through trial and error with hardcoded values based on the screen dimension and aspect ratio, but basically if you experiment with the offsets of the left and right planes, etc, as shown in the unity page example, and then have those values counteract the left and right motion of the camera, that will get you there.
There is of course other hefty matrix math equations that will do it too.
Thank you for the info! Everything you say is exactly what my tests seem to indicate. And yes you are right I shouldn’t rotate the cameras just move the perspective around. What made it difficult for me though was that I hoped that only the perspective vanishing point would move around but unfortunately the whole frustrum get’s offset also. Just as you did I tried to move the camera to offset everything back so that the frustrums left, top, right, bottom is located at the same position they where before the perspective offset. Just like you did this was done through trial and error. I wish I somehow could calculate what this offset should be but maybe the math is very difficult as you seem to point out?
Thank you for your input and links but I am actually not trying to get stereo cameras to work here. What I am trying to do is to create the effect of looking through a window where everything gets tilted etc as I move my device (in this case iPhone) around. So it’s like headtracking but with tilt instead of real headtracking.
Finally I actually got some help on this from the guy that created MachDice. He told me he used OpenGL and the glFrustum command together with offsetting the camera. Big thanks to him btw! Here is his homepage: MachWerx » Mach Dice
I’m no OpenGL expert but what would be the difference between using glFrustum and changing the projection matrix. When reading the doc I almost get the impression you can position the frustrum more easily with glFrustrum than with the projection matrix in Unity?
Anyway I’m going to continue testing this tonight, what would be great now was if someone knew more about how to move the frustrum around while still locking the far plane in place (without too much trial and error). Also what would be the difference between locking to the far plane or near plane? I’m guessing MachDice locks to the far plane and HoloToy to the near plane?