| 1 | /* $Id: general_clip.h,v 1.1 2000-02-29 00:48:31 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Mesa 3-D graphics library
|
|---|
| 5 | * Version: 3.1
|
|---|
| 6 | *
|
|---|
| 7 | * Copyright (C) 1999 Brian Paul All Rights Reserved.
|
|---|
| 8 | *
|
|---|
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a
|
|---|
| 10 | * copy of this software and associated documentation files (the "Software"),
|
|---|
| 11 | * to deal in the Software without restriction, including without limitation
|
|---|
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|---|
| 13 | * and/or sell copies of the Software, and to permit persons to whom the
|
|---|
| 14 | * Software is furnished to do so, subject to the following conditions:
|
|---|
| 15 | *
|
|---|
| 16 | * The above copyright notice and this permission notice shall be included
|
|---|
| 17 | * in all copies or substantial portions of the Software.
|
|---|
| 18 | *
|
|---|
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|---|
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|---|
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|---|
| 22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|---|
| 23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|---|
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|---|
| 25 | */
|
|---|
| 26 |
|
|---|
| 27 | /*
|
|---|
| 28 | * New (3.1) transformation code written by Keith Whitwell.
|
|---|
| 29 | */
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | /*
|
|---|
| 34 | * Clip against +X
|
|---|
| 35 | *
|
|---|
| 36 | * The if conditions are known at compile time.
|
|---|
| 37 | */
|
|---|
| 38 | #define PLANE (CLIP_RIGHT_BIT)
|
|---|
| 39 | #define INSIDE(K) (X(K) <= W(K))
|
|---|
| 40 | #define COMPUTE_INTERSECTION( in, out, new ) \
|
|---|
| 41 | dx = X(out)-X(in); \
|
|---|
| 42 | dw = W(out)-W(in); \
|
|---|
| 43 | t = (X(in)-W(in)) / (dw-dx); \
|
|---|
| 44 | neww = W(in) + t * dw; \
|
|---|
| 45 | X(new) = neww; \
|
|---|
| 46 | Y(new) = Y(in) + t * (Y(out) - Y(in)); \
|
|---|
| 47 | if (SIZE>=3) coord[new][2] = Z(in) + t * (Z(out) - Z(in)); \
|
|---|
| 48 | if (SIZE==4) coord[new][3] = neww;
|
|---|
| 49 |
|
|---|
| 50 | GENERAL_CLIP
|
|---|
| 51 |
|
|---|
| 52 | #undef INSIDE
|
|---|
| 53 | #undef PLANE
|
|---|
| 54 | #undef COMPUTE_INTERSECTION
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 | /*
|
|---|
| 58 | * Clip against -X
|
|---|
| 59 | */
|
|---|
| 60 | #define PLANE (CLIP_LEFT_BIT)
|
|---|
| 61 | #define INSIDE(K) (X(K) >= -W(K))
|
|---|
| 62 | #define COMPUTE_INTERSECTION( in, out, new ) \
|
|---|
| 63 | dx = X(out)-X(in); \
|
|---|
| 64 | dw = W(out)-W(in); \
|
|---|
| 65 | t = -(X(in)+W(in)) / (dw+dx); \
|
|---|
| 66 | neww = W(in) + t * dw; \
|
|---|
| 67 | X(new) = -neww; \
|
|---|
| 68 | Y(new) = Y(in) + t * (Y(out) - Y(in)); \
|
|---|
| 69 | if (SIZE>=3) coord[new][2] = Z(in) + t * (Z(out) - Z(in)); \
|
|---|
| 70 | if (SIZE==4) coord[new][3] = neww;
|
|---|
| 71 |
|
|---|
| 72 | GENERAL_CLIP
|
|---|
| 73 |
|
|---|
| 74 | #undef INSIDE
|
|---|
| 75 | #undef PLANE
|
|---|
| 76 | #undef COMPUTE_INTERSECTION
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 | /*
|
|---|
| 80 | * Clip against +Y
|
|---|
| 81 | */
|
|---|
| 82 | #define PLANE (CLIP_TOP_BIT)
|
|---|
| 83 | #define INSIDE(K) (Y(K) <= W(K))
|
|---|
| 84 | #define COMPUTE_INTERSECTION( in, out, new ) \
|
|---|
| 85 | dy = Y(out)-Y(in); \
|
|---|
| 86 | dw = W(out)-W(in); \
|
|---|
| 87 | t = (Y(in)-W(in)) / (dw-dy); \
|
|---|
| 88 | neww = W(in) + t * dw; \
|
|---|
| 89 | X(new) = X(in) + t * (X(out) - X(in)); \
|
|---|
| 90 | Y(new) = neww; \
|
|---|
| 91 | if (SIZE>=3) coord[new][2] = Z(in) + t * (Z(out) - Z(in)); \
|
|---|
| 92 | if (SIZE==4) coord[new][3] = neww;
|
|---|
| 93 |
|
|---|
| 94 | GENERAL_CLIP
|
|---|
| 95 |
|
|---|
| 96 | #undef INSIDE
|
|---|
| 97 | #undef PLANE
|
|---|
| 98 | #undef COMPUTE_INTERSECTION
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 | /*
|
|---|
| 102 | * Clip against -Y
|
|---|
| 103 | */
|
|---|
| 104 | #define PLANE (CLIP_BOTTOM_BIT)
|
|---|
| 105 | #define INSIDE(K) (Y(K) >= -W(K))
|
|---|
| 106 | #define COMPUTE_INTERSECTION( in, out, new ) \
|
|---|
| 107 | dy = Y(out)-Y(in); \
|
|---|
| 108 | dw = W(out)-W(in); \
|
|---|
| 109 | t = -(Y(in)+W(in)) / (dw+dy); \
|
|---|
| 110 | neww = W(in) + t * dw; \
|
|---|
| 111 | X(new) = X(in) + t * (X(out) - X(in)); \
|
|---|
| 112 | Y(new) = -neww; \
|
|---|
| 113 | if (SIZE>=3) coord[new][2] = Z(in) + t * (Z(out) - Z(in)); \
|
|---|
| 114 | if (SIZE==4) coord[new][3] = neww;
|
|---|
| 115 |
|
|---|
| 116 | GENERAL_CLIP
|
|---|
| 117 |
|
|---|
| 118 | #undef INSIDE
|
|---|
| 119 | #undef PLANE
|
|---|
| 120 | #undef COMPUTE_INTERSECTION
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 | /*
|
|---|
| 125 | * Clip against +Z
|
|---|
| 126 | */
|
|---|
| 127 | #define PLANE (CLIP_FAR_BIT)
|
|---|
| 128 | #define INSIDE(K) (Z(K) <= W(K))
|
|---|
| 129 | #define COMPUTE_INTERSECTION( in, out, new ) \
|
|---|
| 130 | dz = Z(out)-Z(in); \
|
|---|
| 131 | dw = W(out)-W(in); \
|
|---|
| 132 | t = (Z(in)-W(in)) / (dw-dz); \
|
|---|
| 133 | neww = W(in) + t * dw; \
|
|---|
| 134 | X(new) = X(in) + t * (X(out) - X(in)); \
|
|---|
| 135 | Y(new) = Y(in) + t * (Y(out) - Y(in)); \
|
|---|
| 136 | coord[new][2] = neww; \
|
|---|
| 137 | if (SIZE==4) coord[new][3] = neww;
|
|---|
| 138 |
|
|---|
| 139 | if (SIZE>=3) {
|
|---|
| 140 | GENERAL_CLIP
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | #undef INSIDE
|
|---|
| 144 | #undef PLANE
|
|---|
| 145 | #undef COMPUTE_INTERSECTION
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 | /*
|
|---|
| 149 | * Clip against -Z
|
|---|
| 150 | */
|
|---|
| 151 | #define PLANE (CLIP_NEAR_BIT)
|
|---|
| 152 | #define INSIDE(K) (Z(K) >= -W(K))
|
|---|
| 153 | #define COMPUTE_INTERSECTION( in, out, new ) \
|
|---|
| 154 | dz = Z(out)-Z(in); \
|
|---|
| 155 | dw = W(out)-W(in); \
|
|---|
| 156 | t = -(Z(in)+W(in)) / (dw+dz); \
|
|---|
| 157 | neww = W(in) + t * dw; \
|
|---|
| 158 | X(new) = X(in) + t * (X(out) - X(in)); \
|
|---|
| 159 | Y(new) = Y(in) + t * (Y(out) - Y(in)); \
|
|---|
| 160 | coord[new][2] = -neww; \
|
|---|
| 161 | if (SIZE==4) coord[new][3] = neww;
|
|---|
| 162 |
|
|---|
| 163 | if (SIZE>=3) {
|
|---|
| 164 | GENERAL_CLIP
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | #undef INSIDE
|
|---|
| 168 | #undef PLANE
|
|---|
| 169 | #undef COMPUTE_INTERSECTION
|
|---|
| 170 | #undef GENERAL_CLIP
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|