This method returns the terrain coordinates of a specified pixel on the screen. If the selected pixel is part of an object, and not terrain, its object type and ObjectID is returned. This method should be used in most cases instead of the previous IRender4::ScreenToTerrain().
HRESULT ScreenToWorld(
[in] long ScreenX,
[in] long ScreenY,
[in, out] VARIANT* longObjectType,
[out] VARIANT*doubleWorldX,
[out] VARIANT*doubleWorldHeight,
[out] VARIANT*doubleWorldY,
[out] VARIANT*bstrObjectID)
Parameters:
ScreenX – The X-coordinate of the point whose corresponding terrain coordinate you are seeking. The coordinates are given in screen coordinates, with the origin in the top-left corner of the 3D Window.
ScreenY – The Y-coordinate of the point whose corresponding terrain coordinate you are seeking. The coordinates are given in screen coordinates, with the origin in the top-left corner of the 3D Window.
longObjectType – This determines the types of objects you want to get. To get only terrain coordinates and ignore other objects, set this to zero. When the method returns, this identifies the object type that was found at the given coordinates. Any combination of the following values can be used:
OBJ_TYPE_TERRAIN = 0
OBJ_TYPE_3DOBJECT = 1
OBJ_TYPE_LABEL = 2
OBJ_TYPE_PRIMITIVE = 4
OBJ_TYPE_BUILDING = 16
OBJ_TYPE_SKY = 32
OBJ_TYPE_UNDERGROUND_GRID = 512
Note: The OBJ_TYPE_TERRAIN (0) parameter is used in any combination you select. If you click on the terrain the OBJ_TYPE_TERRAIN value is returned for this parameter and the bstrObjectID parameter is returned with empty value.
doubleWorldX – The terrain X-coordinate that corresponds to the given pixel. If an object was selected, the X-coordinate of the hit point is returned.
doubleWorldHeight – The terrain height value that corresponds to the given pixel. If an object was selected, the height of the object at the hit point is returned.
doubleWorldY – The terrain y-coordinate that corresponds to the given pixel. If an object was selected, the Y-coordinate of the hit point is returned.
bstrObjectID – If an object was selected, the ID of the object is returned.
Return Values:
The return value obtained from the returned HRESULT can be one of the following:
Return value |
Meaning |
S_OK |
Success. |
E_FAIL |
Catastrophic failure. |
TE_E_MPTNOTLOADED |
An MPT file must be loaded in TerraExplorer for this method to work. |