ARMousePick

From Blue Mars Developer Guidebook

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

This is an Avatar Reality Utilities function.

Function

ARMousePick(type, flags, num)
general mouse picking function
return value - integer number of intersections
type - type of objects to intersect under mouse position
flags - intersection flags
num - maximum number of intersections

Examples

ARPrintPick gives an idea of the results table contents.

ARMousePickTerrain and ARMousePickEntity are simple wrappers for common cases.

Code

  1. Find the mouse position using System.GetWindowMouse
  2. Check if that position is covered by a HUD element, using HUD.IsMaskedByFlash
  3. Transform the mouse position to a 3D world coordinate using System.UnprojectFromScreen
  4. Perform a raycast from the camera position to the transformed mouse point using Physics.RayWorldIntersectionAR
  5. Return the raycast result, which is the number of intersections found (the actual results are in the reusable global table g_HitTable).
function ARMousePick(type,flags,num)
   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,num,type,flags,nil,g_HitTable);
end

Note that g_HitTable is a protected global variable, so you won't be able to inspect it directly in your own scripts. Very likely you will want to copy this function and modify it for your purposes, passing in your own hit table, like this:

myHitTable = {}

function MyMousePick(type,flags,num)
   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,num,type,flags,nil,myHitTable);
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