FS2_Open
Open source remastering of the Freespace 2 engine
fvi.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 #ifndef _FVI_H
13 #define _FVI_H
14 
15 #include "globalincs/pstypes.h"
16 
17 //finds distance from point to plane
18 float fvi_point_dist_plane(const vec3d *plane_pnt, const vec3d *plane_norm, const vec3d *point);
19 
20 // fvi functions - fvi stands for Find Vector Intersection
21 // fvi_a_b - means find the intersection of something of type a with something of type b
22 // type can be:
23 // ray: a line from p0 through p1 extending to inifinity
24 // segment: a line from p0 stopping at p1
25 // sphere, point, face
26 
27 //--------------------------------------------------------------------
28 // fvi_ray_plane - Finds the point on the specified plane where the
29 // infinite ray intersects.
30 //
31 // Returns scaled-distance plane is from the ray_origin (t), so
32 // P = O + t*D, where P is the point of intersection, O is the ray origin,
33 // and D is the ray's direction. So 0.0 would mean the intersection is
34 // exactly on the ray origin, 1.0 would be on the ray origin plus the ray
35 // direction vector, anything negative would be behind the ray's origin.
36 // If you pass a pointer to the new_pnt, this routine will perform the P=
37 // calculation to calculate the point of intersection and put the result
38 // in *new_pnt.
39 //
40 // If radius is anything other than 0.0, it assumes you want the intersection
41 // point to be that radius from the plane.
42 //
43 // Note that ray_direction doesn't have to be normalized unless you want
44 // the return value to be in units from the ray origin.
45 //
46 // Also note that new_pnt will always be filled in to some valid value,
47 // even if it is a point at infinity.
48 //
49 // If the plane and line are parallel, this will return the largest
50 // negative float number possible.
51 //
52 // So if you want to check a line segment from p0 to p1, you would pass
53 // p0 as ray_origin, p1-p0 as the ray_direction, and there would be an
54 // intersection if the return value is between 0 and 1.
55 
56 float fvi_ray_plane(vec3d *new_pnt,
57  const vec3d *plane_pnt, const vec3d *plane_norm, // Plane description, a point and a normal
58  const vec3d *ray_origin, const vec3d *ray_direction, // Ray description, a point and a direction
59  float rad);
60 
61 
62 //find the point on the specified plane where the line segment intersects
63 //returns true if point found, false if line parallel to plane
64 //new_pnt is the found point on the plane
65 //plane_pnt & plane_norm describe the plane
66 //p0 & p1 are the ends of the line
67 int fvi_segment_plane(vec3d *new_pnt, const vec3d *plane_pnt, const vec3d *plane_norm, const vec3d *p0, const vec3d *p1, float rad);
68 
69 
70 // fvi_point_face
71 // see if a point in inside a face by projecting into 2d. Also
72 // Finds uv's if uvls is not NULL. Returns 0 if point isn't on
73 // face, non-zero otherwise.
74 // From Graphics Gems I, "An efficient Ray-Polygon intersection", p390
75 // checkp - The point to check
76 // nv - how many verts in the poly
77 // verts - the vertives for the polygon
78 // norm1 - the polygon's normal
79 // 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
80 // uvls - a list of uv pairs for each vertex
81 // This replaces the old check_point_to_face & find_hitpoint_uv
82 int fvi_point_face(const vec3d *checkp, int nv, vec3d const *const *verts, const vec3d * norm1, float *u_out, float *v_out, const uv_pair * uvls );
83 
84 
85 //maybe this routine should just return the distance and let the caller
86 //decide it it's close enough to hit
87 //determine if and where a vector intersects with a sphere
88 //vector defined by p0,p1
89 //returns 1 if intersects, and fills in intp
90 //else returns 0
91 int fvi_segment_sphere(vec3d *intp, const vec3d *p0, const vec3d *p1, const vec3d *sphere_pos, float sphere_rad);
92 
93 //determine if and where a ray intersects with a sphere
94 //vector defined by p0,p1
95 //returns 1 if intersects, and fills in intp
96 //else returns 0
97 int fvi_ray_sphere(vec3d *intp, const vec3d *p0, const vec3d *p1, const vec3d *sphere_pos, float sphere_rad);
98 
99 
100 //==============================================================
101 // Finds intersection of a ray and an axis-aligned bounding box
102 // Given a ray with origin at p0, and direction pdir, this function
103 // returns non-zero if that ray intersects an axis-aligned bounding box
104 // from min to max. If there was an intersection, then hitpt will contain
105 // the point where the ray begins inside the box.
106 // Fast ray-box intersection taken from Graphics Gems I, pages 395,736.
107 int fvi_ray_boundingbox(const vec3d *min, const vec3d *max, const vec3d * p0, const vec3d *pdir, vec3d *hitpt );
108 
109 // sphere polygon collision prototypes
110 
111 // Given a polygon vertex list and a moving sphere, find the first contact the sphere makes with the edge, if any
112 int fvi_polyedge_sphereline(vec3d *hit_point, const vec3d *xs0, const vec3d *vs, float Rs, int nv, vec3d const *const *verts, float *hit_time);
113 
114 int fvi_sphere_plane(vec3d *intersect_point, const vec3d *sphere_center_start, const vec3d *sphere_velocity, float sphere_radius,
115  const vec3d *plane_normal, const vec3d *plane_point, float *hit_time, float *delta_time);
116 
117 // finds the point of intersection between two lines or the closest points if lines do not intersect
118 // closest points - line 1: p1 + v1 * s, line 2: p2 + v2 * t
119 // p1 - point on line 1
120 // v1 - vector direction of line 1
121 // p2 - point on line 2
122 // v2 - vector direction of line 2
123 // s - parameter of intersection of line 1
124 // t - parameter of intersection of line 2
125 void fvi_two_lines_in_3space(const vec3d *p1, const vec3d *v1, const vec3d *p2, const vec3d *v2, float *s, float *t);
126 
127 // vec3d mins - minimum extents of bbox
128 // vec3d maxs - maximum extents of bbox
129 // vec3d start - point in bbox reference frame
130 // vec3d box_pt - point in bbox reference frame.
131 // NOTE: if a coordinate of start is *inside* the bbox, it is *not* moved to surface of bbox
132 // return: 1 if inside, 0 otherwise.
133 int project_point_onto_bbox(const vec3d *mins, const vec3d *maxs, const vec3d *start, vec3d *box_pt);
134 
135 #endif
int fvi_ray_sphere(vec3d *intp, const vec3d *p0, const vec3d *p1, const vec3d *sphere_pos, float sphere_rad)
Definition: fvi.cpp:255
float fvi_point_dist_plane(const vec3d *plane_pnt, const vec3d *plane_norm, const vec3d *point)
Definition: fvi.cpp:71
int fvi_segment_sphere(vec3d *intp, const vec3d *p0, const vec3d *p1, const vec3d *sphere_pos, float sphere_rad)
Definition: fvi.cpp:188
Definition: pstypes.h:88
hull_check p0
Definition: lua.cpp:5051
int fvi_point_face(const vec3d *checkp, int nv, vec3d const *const *verts, const vec3d *norm1, float *u_out, float *v_out, const uv_pair *uvls)
Definition: fvi.cpp:419
void fvi_two_lines_in_3space(const vec3d *p1, const vec3d *v1, const vec3d *p2, const vec3d *v2, float *s, float *t)
Definition: fvi.cpp:42
GLfloat GLfloat GLfloat v2
Definition: Glext.h:5640
int fvi_polyedge_sphereline(vec3d *hit_point, const vec3d *xs0, const vec3d *vs, float Rs, int nv, vec3d const *const *verts, float *hit_time)
Definition: fvi.cpp:694
int fvi_sphere_plane(vec3d *intersect_point, const vec3d *sphere_center_start, const vec3d *sphere_velocity, float sphere_radius, const vec3d *plane_normal, const vec3d *plane_point, float *hit_time, float *delta_time)
Definition: fvi.cpp:516
float fvi_ray_plane(vec3d *new_pnt, const vec3d *plane_pnt, const vec3d *plane_norm, const vec3d *ray_origin, const vec3d *ray_direction, float rad)
Definition: fvi.cpp:118
hull_check p1
Definition: lua.cpp:5052
GLdouble s
Definition: Glext.h:5321
int project_point_onto_bbox(const vec3d *mins, const vec3d *maxs, const vec3d *start, vec3d *box_pt)
Definition: fvi.cpp:1107
GLdouble GLdouble t
Definition: Glext.h:5329
int fvi_ray_boundingbox(const vec3d *min, const vec3d *max, const vec3d *p0, const vec3d *pdir, vec3d *hitpt)
Definition: fvi.cpp:321
GLuint start
Definition: Gl.h:1502
GLfloat GLfloat v1
Definition: Glext.h:5639
int fvi_segment_plane(vec3d *new_pnt, const vec3d *plane_pnt, const vec3d *plane_norm, const vec3d *p0, const vec3d *p1, float rad)
Definition: fvi.cpp:162