- Home /
Understanding 3d world and GUI camera space
Im quite new to 3D programming. Im using NGUI as well. Ive realized that while i can understand answers to my questions and look up solutions i have a fundamental lack for understanding what the difference is between the 3D world and the 2D gui screen. I dont even know where to start. For example i want to make a Ngui object draggable so i give it the position of the mouse when dragged but the object dissapears far away.
What should i read up on?
Answer by robhuhn · Dec 04, 2013 at 02:32 PM
The screen dimensions are measured in pixels whereas the world measurement is in meters. If you want to convert screen positions to world positions, you need to use a specific camera for the projection - in most cases it's the active camera. E.g. attaching a 3D object in the world to your mouse on the screen depends on the distance from the 3d object to the projecting camera.
For every application that uses graphics, a viewport needs to be defined. The viewport is a rectangular viewing region of the screen where the 3D scene is projected. It is nothing more than mapping the 3 dimensional objects to the 2 dimensional plane.
The following image shows a typical 3D scene with a perspective projection.
The eye is where the camera is and the viewport is the plane where all the objects found in the view frustum are projected to.
The view frustum is a pyramid with two clipping planes. Objects or parts of objects found outside the frustum, won't be rendered. It is not possible to define a near clipping plane closer to the observer than the viewport.
When the human eye looks at a scene, objects in the distance appear smaller than objects close by. This is called perspective and this is used for 3D games and applications. Perspective projection is the final image rendered onto the viewport with the objects scaled according to their distance from the observation point.
Orthogonal projection on the other hand, ignores the scaling effect and projects objects to the viewport maintaining their original size.
The following diagram shows the orthogonal projection.
Source: https://code.google.com/p/libgdx/wiki/GraphicsFundamentalsViewport
A nice explanation here. I feel I should add that the near clipping plane need not be the same as viewport (and indeed this is rarely the case, as it causes z-fighting). The viewport is the plane on which the 3D scene is projected (it essentially acts as the position of the "screen"), while the near clipping plane is a boundary that ensures only objects in front of it are rendered (this prevents objects behind the camera from being drawn). The viewport and near clipping plane should be as close together as possible, but they aren't necessarily identical.
Answer by GeoBlazer · Dec 04, 2013 at 02:23 PM
If your looking for something to read, maybe you should read the Unity Manual. It covers all the basic stuff you need to know. It helped me too! :)
Unity Manual Link: http://docs.unity3d.com/Documentation/Manual/index.html
I read sections of it to understand specific things i deal with at the moment. Do you want to recommend me a specific chapter?
Your answer
Follow this Question
Related Questions
Camera being disabled by any GUI button 2 Answers
Problem making a ruler 1 Answer
It is possible to have a Camera rect on TOP of a GUI 0 Answers
Disabled Camera acts strangely outside of editor (solved) 0 Answers
Camera in Interface 1 Answer