1 /* Copyright (C) 1992-1998 The Geometry Center
2  * Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips
3  *
4  * This file is part of Geomview.
5  *
6  * Geomview is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published
8  * by the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * Geomview is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Geomview; see the file COPYING.  If not, write
18  * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
19  * USA, or visit http://www.gnu.org.
20  */
21 
22 
23 /* Authors: Charlie Gunn, Stuart Levy, Tamara Munzner, Mark Phillips */
24 
25 #ifndef PICKDEF
26 #define	PICKDEF
27 
28 /*
29  * Public definitions for Geom Picking.
30  */
31 
32 typedef struct Pick Pick;
33 
34 				/* Things to look for while picking
35 				 * Specify PW_VERT|PW_EDGE|PW_FACE for all,
36 				 * or a subset for more specific picks.
37 				 * PW_VISIBLE checks Appearance to see what's
38 				 * actually visible.
39 				 */
40 #define	PW_VERT	1
41 #define	PW_EDGE	2
42 #define	PW_FACE	4
43 #define	PW_VISIBLE 8
44 
45 #define	PA_END		100
46 #define	PA_THRESH	101	/* float; x/y threshold (in projected space) */
47 #define	PA_POINT	102	/* Point3 *; Picked 3D point (object space) */
48 			    /* Note PA_POINT gives a Point3, not an HPoint3! */
49 #define	PA_DEPTH	103	/* float; depth (== PA_POINT's screen z component) */
50 
51 #define	PA_GPRIM	104	/* Geom *; geometric primitive picked if any */
52 #define	PA_TPRIM	105	/* Transform; from PA_GPRIM to
53 				   PA_POINT, PA_VERT, etc. */
54 #define	PA_TPRIMN	128	/* TransformN; from PA_GPRIM to
55 				   PA_POINT, PA_VERT, etc. */
56 #define	PA_TWORLD	111	/* Transform; from PA_POINT, PA_VERT, etc. to
57 				 *  world coords */
58 #define	PA_TWORLDN	129	/* Transform; from PA_POINT, PA_VERT, etc. to
59 				 *  world coords */
60 
61 #define	PA_WANT		106	/* int; bitmask of desirable values */
62 #define PA_VERT		107	/* HPoint3 v; picked vertex, if any */
63 #define PA_EDGE		108	/* HPoint3 e[2]; endpoints of picked
64 				   edge, if any */
65 #define PA_FACE		109	/* HPoint3 *f; pointer to array of vertices of
66 				   picked face, if any */
67 #define PA_FACEN	110	/* number of elements in PA_FACE array; NOTE:
68 				   when setting PA_FACE you must also set
69 				   PA_FACEN. */
70 
71 	/* Stuff to specify via PickSet() to allow
72 	 * INSTs with "location" fields to be pickable.
73 	 */
74 #define	PA_TC2N		112	/* Tfm camera coords to NDC (-1..+1) */
75 #define	PA_TW2N		113	/* Tfm global coords to NDC */
76 #define	PA_TS2N		114	/* Tfm screen (pixels; 0,0=lower left) to NDC */
77 
78 extern Pick *PickSet( Pick *, int attr, ... );
79 extern int   PickGet( Pick *, int attr, void *attrp );
80 extern void  PickDelete( Pick * );
81 
82 /*
83  * Geometric Picking routines.
84  * GeomMousePick() is intended for normal use by application programs.
85  *   g is the root of the Geom tree
86  *   p is the Pick structure created by PickSet(), etc., or NULL for default;
87  *	If p!=NULL, it is modified in place, so results of the pick can be
88  *	retrieved by later PickGet() calls.
89  *   ap is the Appearance in effect when g is drawn, used to determine
90  *	visibility of features if PW_VISIBLE is set;
91  *   Tproj is the complete object-to-screen projection matrix;
92  *	it normally maps world coordinates in g's space to
93  *	the unit cube -1 <= {x, y, z} <= 1,
94  *	with z = -1 at the near and z = +1 at the far clipping plane,
95  *	x = y = 0 at the center of the screen;
96  *   xpick and ypick are the relative (-1 <= {x,y} <= 1) window
97  *	coordinates of the pick.
98  *
99  * Typical use:
100  *   Point3 rawpt, pickworld, pickprim;
101  *   double mousex, mousey;	( each reduced to range -1 .. +1; 0=center )
102  *   Geom *world, *g;
103  *   Pick *p = PickSet(NULL, PA_END);
104  *   Transform Tworld2screen, Tpick2world, Tpick2prim;
105  *   CamView( camera, Tworld2screen );	( camera's world to screen )
106  *
107  *   g = GeomMousePick( world, p, ap, Tworld2screen, mousex, mousey );
108  *   if(g != NULL) {			(then g == world)
109  *	PickGet(p, PA_POINT, &rawpt);
110  *	PickGet(p, PA_TWORLD, Tpick2world);
111  *      Pt3Transform(Tpick2world, &rawpt, &pickworld);  (in "world"'s coords)
112  *
113  *	PickGet(p, PA_TPRIM, Tpick2prim);
114  *	Pt3Transform(Tpick2prim, &rawpt, &pickprim);	(in leaf-level gprim's coords)
115  *    }
116  */
117 extern Geom *GeomMousePick(Geom *g, Pick *p, Appearance *ap,
118 			   Transform Tproj, TransformN *TNproj, int *axes,
119 			   double xpick, double ypick );
120 
121 /*
122  * GeomPick() is an internal routine:
123  *	g, p, ap are as above for GeomMousePick.
124  *	T is adapted for convenience in pick calculations;
125  *	it is translated such that the pick goes through (x,y) = (0,0).
126  */
127 extern Geom *GeomPick(Geom *g, Pick *p, Appearance *ap,
128 		      Transform T, TransformN *TN, int *axes);
129 
130 #endif /*PICKDEF*/
131