What are the world units scale?
by Alex Okafor · in Torque X 3D · 02/17/2007 (12:37 pm) · 1 replies
I've got a few objects that are in set (1024X768) screen coordinate space and I'd like to transform them to world coordinates. I can't seem to find what the scale of the world units are. Is this based on the camera's extent? If so, doesn't that mean the world units scale if the camera zooms in/out?
Right now I have this code to get an object in the world transformed to screen space (for mouse interaction), The reverse (ie wanting to add an object into the world space based on mouse position) I'd multiply instead of divide in the end and add in the camera's position.
The following was adopted from another post (I believe DevBoy?)
My question is, is there a 'set' conversion for transforming to world units so I do not have to query the camera? I just don't feel safe asking the camera for conversion units since it could be zoomed in/out to any extent. Reason I ask is there seems to be some set world unit because if I change the camera size in the editor, all objects keep their original x/y coordinates.
Right now I have this code to get an object in the world transformed to screen space (for mouse interaction), The reverse (ie wanting to add an object into the world space based on mouse position) I'd multiply instead of divide in the end and add in the camera's position.
The following was adopted from another post (I believe DevBoy?)
int viewWidth = Game.Instance.GraphicsDeviceManager.GraphicsDevice.Viewport.Width; int viewHeight = Game.Instance.GraphicsDeviceManager.GraphicsDevice.Viewport.Height; //ao: couldn't camera's extent be used here? float pixelWidth = (float)(_txCamera.SceneMax.X - _txCamera.SceneMin.X) / (float)viewWidth; float pixelHeight = (float)(_txCamera.SceneMax.Y - _txCamera.SceneMin.Y) / (float)viewHeight; return new Vector2(_txCamera.Position.X / pixelWidth, _txCamera.Position.Y / pixelHeight);
My question is, is there a 'set' conversion for transforming to world units so I do not have to query the camera? I just don't feel safe asking the camera for conversion units since it could be zoomed in/out to any extent. Reason I ask is there seems to be some set world unit because if I change the camera size in the editor, all objects keep their original x/y coordinates.
Torque Owner Ben R Vesco