integrating software renderer
[retroray] / src / gaw / polyclip.h
1 /*
2 RetroRay - integrated standalone vintage modeller/renderer
3 Copyright (C) 2023  John Tsiombikas <nuclear@mutantstargoat.com>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 #ifndef POLYCLIP_H_
19 #define POLYCLIP_H_
20
21 #include "polyfill.h"
22
23 struct cplane {
24         float x, y, z;
25         float nx, ny, nz;
26 };
27
28 enum {
29         CLIP_LEFT, CLIP_RIGHT,
30         CLIP_BOTTOM, CLIP_TOP,
31         CLIP_NEAR, CLIP_FAR
32 };
33
34 /* Generic polygon clipper
35  * returns:
36  *  1 -> fully inside, not clipped
37  *  0 -> straddling the plane and clipped
38  * -1 -> fully outside, not clipped
39  * in all cases, vertices are copied to vout, and the vertex count is written
40  * to wherever voutnum is pointing
41  */
42 int clip_poly(struct vertex *vout, int *voutnum,
43                 const struct vertex *vin, int vnum, struct cplane *plane);
44
45 /* only checks if the polygon would be clipped by the plane, and classifies it
46  * as inside/outside/straddling, without actually producing a clipped polygon.
47  * return values are the same as clip_poly.
48  */
49 int check_clip_poly(const struct vertex *v, int vnum, struct cplane *plane);
50
51 /* Special-case frustum clipper (might be slightly faster) */
52 int clip_frustum(struct vertex *vout, int *voutnum,
53                 const struct vertex *vin, int vnum, int fplane);
54
55 #endif  /* POLYCLIP_H_ */