ARMousePickTerrain

From Blue Mars Developer Guidebook

Jump to: navigation, search
There are security restrictions on this article

This is an Avatar Reality Utilities function.

Function

ARMousePickTerrain()
mouse selection on terrain
return value - vector position of selected point on the terrain

Note

The selection is vertically a bit off when used in the Editor. Should be fine in the Blue Mars client.

Code

This function passes to ARMousePick the arguments appropriate for ray intersection on terrain and then returns the resulting position, if any.

function ARMousePickTerrain()
   local count = ARMousePick(ent_terrain,rwi_stop_at_pierceable+rwi_colltype_any,1);
   if (count>0) then
      return g_HitTable[1].pos;
   end
end

g_HitTable is a protected variable, so if you want more information from the hit results table, e.g. the intersection normal, you'll need to write our own version calling Physics.RayWorldIntersectionAR, like this:

terrainHitTable = {}

function TerrainMousePick()
   local uix,uiy = System.GetWindowMouse();
   if HUD.IsMaskedByFlash(uix,uiy) then
      return 0; -- not hits if blocked by Flash
   end
   local width,height = System.GetScreenSize();
   local s= {x=uix,y=height-uiy,z=1.0};
   local p=System.UnprojectFromScreen(s);
   local vSrc=System.GetViewCameraPos();
   local vDir = DifferenceVectors(p,vSrc);
   return Physics.RayWorldIntersectionAR(vSrc,vDir,1,ent_terrain,rwi_stop_at_pierceable+rwi_colltype_any,nil,terrainHitTable);
end
Problems with this wiki page? Contact us either by: Support Email or Support Ticket System

Blue Mars Guidebook Privacy Policy
Blue Mars Guidebook Community Guidelines

Personal tools