]> icculus.org git repositories - taylor/freespace2.git/blob - include/fvi.h
Initial revision
[taylor/freespace2.git] / include / fvi.h
1 /*
2  * $Logfile: /Freespace2/code/Math/Fvi.h $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Prototypes for fvi stuff
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:12  root
11  * Initial revision
12  *
13  * 
14  * 5     8/16/99 8:19a Andsager
15  * Add project_point_onto_bbox() to fvi and include in aicode
16  * 
17  * 4     3/08/99 7:03p Dave
18  * First run of new object update system. Looks very promising.
19  * 
20  * 3     11/13/98 11:10a Andsager
21  * Add fvi_two_lines_in_3space() - returns closest point of intersection
22  * 
23  * 2     10/07/98 10:53a Dave
24  * Initial checkin.
25  * 
26  * 1     10/07/98 10:49a Dave
27  * 
28  * 16    1/12/98 9:20p Andsager
29  * Modify calling procedure to fvi_sphere_plane.  
30  * 
31  * 15    10/19/97 9:42p Andsager
32  * add fvi_sphere_plane to header
33  * 
34  * 14    10/19/97 9:28p Andsager
35  * removed local function from header
36  * 
37  * 13    10/17/97 1:21a Andsager
38  * add new function to check sphere-polgon edge collision
39  * 
40  * 12    10/03/97 5:06p Andsager
41  * added sphere polygon intersection code
42  * 
43  * 11    9/28/97 2:16p Andsager
44  * added fvi_moving_sphere_intersect_plane
45  * 
46  * 10    4/01/97 1:03p John
47  * Changed fvi_ray_plane to take a dir, not two points.
48  * 
49  * 9     3/26/97 10:48a Hoffoss
50  * JAS: Added fvi_ray_sphere
51  * 
52  * 8     3/24/97 3:55p John
53  * renamed fvi functions so rays and segments aren't confusing.
54  * 
55  * 7     3/24/97 3:26p John
56  * Cleaned up and restructured model_collide code and fvi code.  In fvi
57  * made code that finds uvs work..  Added bm_get_pixel to BmpMan.
58  * 
59  * 6     2/17/97 5:18p John
60  * Added a bunch of RCS headers to a bunch of old files that don't have
61  * them.
62  *
63  * $NoKeywords: $
64  */
65
66
67 #ifndef _FVI_H
68 #define _FVI_H
69
70 #include "pstypes.h"
71
72 // fvi functions - fvi stands for Find Vector Intersection
73 // fvi_a_b - means find the intersection of something of type a with something of type b
74 // type can be:
75 // ray:  a line from p0 through p1 extending to inifinity
76 // segment: a line from p0 stopping at p1
77 // sphere, point, face
78
79 //--------------------------------------------------------------------
80 // fvi_ray_plane - Finds the point on the specified plane where the 
81 // infinite ray intersects.
82 //
83 // Returns scaled-distance plane is from the ray_origin (t), so
84 // P = O + t*D, where P is the point of intersection, O is the ray origin,
85 // and D is the ray's direction.  So 0.0 would mean the intersection is 
86 // exactly on the ray origin, 1.0 would be on the ray origin plus the ray
87 // direction vector, anything negative would be behind the ray's origin.
88 // If you pass a pointer to the new_pnt, this routine will perform the P=
89 // calculation to calculate the point of intersection and put the result
90 // in *new_pnt.
91 //
92 // If radius is anything other than 0.0, it assumes you want the intersection
93 // point to be that radius from the plane.
94 //
95 // Note that ray_direction doesn't have to be normalized unless you want
96 // the return value to be in units from the ray origin.
97 //
98 // Also note that new_pnt will always be filled in to some valid value,
99 // even if it is a point at infinity.
100 //
101 // If the plane and line are parallel, this will return the largest 
102 // negative float number possible.
103 //
104 // So if you want to check a line segment from p0 to p1, you would pass
105 // p0 as ray_origin, p1-p0 as the ray_direction, and there would be an
106 // intersection if the return value is between 0 and 1.
107
108 float fvi_ray_plane(vector *new_pnt,
109                     vector *plane_pnt,vector *plane_norm,               // Plane description, a point and a normal
110                     vector *ray_origin,vector *ray_direction,   // Ray description, a point and a direction
111                                                   float rad);
112
113
114 //find the point on the specified plane where the line segment intersects
115 //returns true if point found, false if line parallel to plane
116 //new_pnt is the found point on the plane
117 //plane_pnt & plane_norm describe the plane
118 //p0 & p1 are the ends of the line
119 int fvi_segment_plane(vector *new_pnt, vector *plane_pnt, vector *plane_norm, vector *p0, vector *p1, float rad);
120
121
122 // fvi_point_face
123 // see if a point in inside a face by projecting into 2d. Also
124 // Finds uv's if uvls is not NULL.  Returns 0 if point isn't on
125 // face, non-zero otherwise.
126 // From Graphics Gems I, "An efficient Ray-Polygon intersection", p390
127 // checkp - The point to check
128 // nv - how many verts in the poly
129 // verts - the vertives for the polygon 
130 // norm1 - the polygon's normal
131 // u_out,vout - if not null and v_out not null and uvls not_null and point is on face, the uv's of where it hit
132 // uvls - a list of uv pairs for each vertex
133 // This replaces the old check_point_to_face & find_hitpoint_uv
134 int fvi_point_face(vector *checkp, int nv, vector **verts, vector * norm1, float *u_out, float *v_out, uv_pair * uvls );
135
136
137 //maybe this routine should just return the distance and let the caller
138 //decide it it's close enough to hit
139 //determine if and where a vector intersects with a sphere
140 //vector defined by p0,p1 
141 //returns 1 if intersects, and fills in intp
142 //else returns 0
143 int fvi_segment_sphere(vector *intp, vector *p0, vector *p1, vector *sphere_pos, float sphere_rad);
144
145 //determine if and where a ray intersects with a sphere
146 //vector defined by p0,p1 
147 //returns 1 if intersects, and fills in intp
148 //else returns 0
149 int fvi_ray_sphere(vector *intp, vector *p0, vector *p1, vector *sphere_pos, float sphere_rad);
150
151
152 //==============================================================
153 // Finds intersection of a ray and an axis-aligned bounding box
154 // Given a ray with origin at p0, and direction pdir, this function
155 // returns non-zero if that ray intersects an axis-aligned bounding box
156 // from min to max.   If there was an intersection, then hitpt will contain
157 // the point where the ray begins inside the box.
158 // Fast ray-box intersection taken from Graphics Gems I, pages 395,736.
159 int fvi_ray_boundingbox( vector *min, vector *max, vector * p0, vector *pdir, vector *hitpt );
160
161 // sphere polygon collision prototypes
162
163 // Given a polygon vertex list and a moving sphere, find the first contact the sphere makes with the edge, if any
164 int fvi_polyedge_sphereline(vector *hit_point, vector *xs0, vector *vs, float Rs, int nv, vector **verts, float *hit_time);
165
166 int fvi_sphere_plane(vector *intersect_point, vector *sphere_center_start, vector *sphere_velocity, float sphere_radius, 
167                                                         vector *plane_normal, vector *plane_point, float *hit_time, float *delta_time);
168
169 // finds the point of intersection between two lines or the closest points if lines do not intersect
170 // closest points - line 1:  p1 + v1 * s,  line 2:  p2 + v2 * t
171 // p1 - point on line 1
172 // v1 - vector direction of line 1
173 // p2 - point on line 2
174 // v2 - vector direction of line 2
175 // s - parameter of intersection of line 1
176 // t - parameter of intersection of line 2
177 void fvi_two_lines_in_3space(vector *p1, vector *v1, vector *p2, vector *v2, float *s, float *t);
178
179 // vector mins - minimum extents of bbox
180 // vector maxs - maximum extents of bbox
181 // vector start - point in bbox reference frame
182 // vector box_pt - point in bbox reference frame.
183 // NOTE: if a coordinate of start is *inside* the bbox, it is *not* moved to surface of bbox
184 // return: 1 if inside, 0 otherwise.
185 int project_point_onto_bbox(vector *mins, vector *maxs, vector *start, vector *box_pt);
186
187 #endif
188