Game Development Community

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?)

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.

#1
02/18/2007 (9:55 am)
The camera would be related to your conversion from screen coords to world coords. The camera is unrelated to world coords themselves though. World coords are determined by an unchangeable coordinate system. The scale of world coords is dependent on the size of your graphics. World coords are related to that grid you see in TGBX.