14.03.2014 Views

Scripting Guide - SAS

Scripting Guide - SAS

Scripting Guide - SAS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

464 Three-Dimensional Scenes Chapter 13<br />

Using the mouse<br />

/* after one of the 3 Click2d functions figures out which axis of the model is<br />

represented by the screen X, Y, pass in to this common code */<br />

dragfunc = Function( {x, y, m, ix, iy}, /* ix, iy are the index of the X, Y, or<br />

Z part of the coord in the points matrix */<br />

If( CurrentPoint > 0,<br />

points[CurrentPoint, ix] = (x / boxwide) * (orthoright - ortholeft) +<br />

ortholeft;<br />

points[CurrentPoint, iy] = (y / boxhigh) * (orthotop - orthobottom) +<br />

orthobottom;<br />

makepatch();<br />

)<br />

);<br />

When a 2-D function is called, the arguments are X, Y, M, K.<br />

• X and Y are the coordinates of the mouse.<br />

• M shows the state of the mouse and button. M=0 says that the mouse button is up. M=1 says that the<br />

button was just pressed. M=2 says that the button is down and the mouse is moving. M=3 says that the<br />

button was just released.<br />

• K is related to the keys Shift, Alt, and control. K=1 for the Shift key, K=2 for the Control (command) key,<br />

and K=3 for the Alt (Option) key.<br />

The 3-D function is called similarly. The arguments are X, Y, M, K, hitlist, where hitlist is a list of<br />

matrices<br />

[znear, zfar, id1, id2, id3, ...]<br />

znear, zfar is the Z distance from the camera of the near and far edge of the object. The matrices are<br />

sorted from near to far by the midpoint of znear, zfar. The ids in the list are the pushname, loadname,<br />

and popname values you just put in the display list.<br />

The drag functions use a return value to tell if mouse processing should continue. That is the trailing “1”<br />

you see in the functions. Anything else stops the mouse tracking. This is needed because the 2-D and 3-D<br />

functions do not run in parallel. You might want the 2-D to return 0 and the 3-D to return 1 so the tracking<br />

would happen in 3-D rather than 2-D.<br />

Pick Commands<br />

This SceneBox callback gets the 2-D mouse coordinates, and then uses pick to determine the “named”<br />

object under the mouse. For example, hitlist is a 5x5 pixel pick box around x,y; up to 1000 items<br />

returned, but just the leaf names. The format of the return is determined by the last parameter (1 returns a<br />

simple array, 0 returns a sorted (by depth) list of arrays).<br />

Track2d=function({x, y, m, k},<br />

hitlist = theSceneBox

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!