Forum Discussion
danishdragon
11 years agoHonored Guest
Make an object appear right in front of you (UNITY)
Hey! First of - sorry if this is the wrong place to ask the question, I'm new here.
I'm currently working on a project where you walk around and can pick up a lot of objects, and inspect them. But I'm in need of a way to make an item appear up close for the player, so they would be able to read text on the object or similar. My problem is that the objects are different sizes, and I'm still a newbie who can't figure out how to solve this simple question.
So: How can I make an object appear in front of the cameras so you can inspect them in full detail with size taking in regards.
Imaginary bonus points if the approach can make me able to zoom it in and out whilst inspecting.
Thanks!
Edit: Forgot to point out I'm doing this in Unity
I'm currently working on a project where you walk around and can pick up a lot of objects, and inspect them. But I'm in need of a way to make an item appear up close for the player, so they would be able to read text on the object or similar. My problem is that the objects are different sizes, and I'm still a newbie who can't figure out how to solve this simple question.
So: How can I make an object appear in front of the cameras so you can inspect them in full detail with size taking in regards.
Imaginary bonus points if the approach can make me able to zoom it in and out whilst inspecting.
Thanks!
Edit: Forgot to point out I'm doing this in Unity
4 Replies
- jhericoAdventurerYou render the object right in front of you.
It may seem like a flip answer, but it's not. Typically when you're rendering items, you have a number of matrices involved:- the view matrix, which establishes the camera position relative to the world
- the model matrix, which establishes the position of a given object or 'model' relative to the world
- the projection matrix, which gives you a perspective view with a given field of view and aspect ratio.
Usually, the first two matrices are combined together into a 'modelview' matrix. By putting the inverse of the camera transformation on the stack first, and then pushing the transformation of a given object onto the stack before you render it, objects automatically appear in the correct position relative to the camera.
For a variety of reasons that I will explain in detail in my book (and possibly a blog post at some point), my first example for testing a given implementation of the Oculus Rift rendering is to render a small cube with a different color on each side of the cube. The width of the cube is set to exactly the width of the inter-pupillary distance, and the distance from the viewer is set to about 4-5 times the inter-pupillary distance. The reason I choose these values is that inspecting such a cube makes it really easy to detect errors in either the modelview matrix or the projection matrix, or the Rift specific offsets that are applied to give a sensation of depth and correctly center the images under the lens axis.
You can see an example of how I'm doing this here. This code is relying on my own OpenGL wrappers and matrix stack implementation, but they're also available in the repository. - danishdragonHonored GuestJherico, thanks for the lengthy response - but it seems that I forgot to point out that I'm using Unity (Doh! :oops: ).
And my problem lies more within how to implement it in unity in such a manner that it takes the size of the object in regards. - jhericoAdventurer
"danishdragon" wrote:
Jherico, thanks for the lengthy response - but it seems that I forgot to point out that I'm using Unity (Doh! :oops: ).
And my problem lies more within how to implement it in unity in such a manner that it takes the size of the object in regards.
Well, there's a unity specific forum that might be able to offer more specific advice. However, as regards to 'taking the size into account', I'm not certain what you mean, but it seems like you're suggesting that regardless of the object size you want it to be small enough to render as if it were a model you could place in front of you (or alternatively size up a very small object so it's large enough to inspect).
If you have a given object and can find a bounding box for it, then it's a simple matter of finding the length of the longest axis of the bounding box, and then using that to create a scaling factor to scale the object to the size you want for the items you're inspecting. Assume you want objects to be no more than 30 cm in size, then this pseudo-code block is basically what you're trying to do:
const float targetSize = 0.3f;
float modelSize = getLargestDimension(getBoundingBox(object));
float scaleFactor = targetSize / modelSize;
scaleObject(object, scaleFactor);
This will only scale the object though, it makes no effort to position it directly in front of you. I don't have enough Unity experience to talk in more detail about how to implement the functions or do the positioning. - 82rossExplorerYou could look into using an additional camera to view a game object and layers to "overlay" your object on the second camera over the main camera layer.
Imagine a place in your scene which cannot normally be seen. When you "pickup" your object you create an instance of your object there where the second camera is waiting. Scale the bounding box as already suggested. Overlay this cameras view over your current view (using layers). Create controls whilst in this view to rotate and scale/zoom the object. Basically a GUI in 3D. You could also apply effects to darken the main camera layer in the background etc. Then hide/destroy the object and hide the additional camera layer when you "put it down".
Or you could just transform the object from its worldspace to a fixed position relative to the main camera. You could control the transition instead of it just "popping up" in front of you. Keeping its original position saved for the return transition.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 1 year ago
- 3 years ago