Oolite
Loading...
Searching...
No Matches
OOVoxel.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CUBE_FACE_RIGHT   0x01
#define CUBE_FACE_LEFT   0x02
#define CUBE_FACE_TOP   0x04
#define CUBE_FACE_BOTTOM   0x08
#define CUBE_FACE_FRONT   0x10
#define CUBE_FACE_BACK   0x20

Functions

Vector lineIntersectionWithFace (Vector p1, Vector p2, long mask, GLfloat rd) CONST_FUNC
int lineCubeIntersection (Vector v0, Vector v1, GLfloat rd) CONST_FUNC

Macro Definition Documentation

◆ CUBE_FACE_BACK

#define CUBE_FACE_BACK   0x20

Definition at line 34 of file OOVoxel.h.

Referenced by checkFace(), checkLine(), Octree::isHitByLine, and lineIntersectionWithFace().

◆ CUBE_FACE_BOTTOM

#define CUBE_FACE_BOTTOM   0x08

Definition at line 32 of file OOVoxel.h.

Referenced by checkFace(), checkLine(), Octree::isHitByLine, and lineIntersectionWithFace().

◆ CUBE_FACE_FRONT

#define CUBE_FACE_FRONT   0x10

Definition at line 33 of file OOVoxel.h.

Referenced by checkFace(), checkLine(), Octree::isHitByLine, and lineIntersectionWithFace().

◆ CUBE_FACE_LEFT

#define CUBE_FACE_LEFT   0x02

Definition at line 30 of file OOVoxel.h.

Referenced by checkFace(), checkLine(), Octree::isHitByLine, and lineIntersectionWithFace().

◆ CUBE_FACE_RIGHT

#define CUBE_FACE_RIGHT   0x01

Definition at line 29 of file OOVoxel.h.

Referenced by checkFace(), checkLine(), Octree::isHitByLine, and lineIntersectionWithFace().

◆ CUBE_FACE_TOP

#define CUBE_FACE_TOP   0x04

Definition at line 31 of file OOVoxel.h.

Referenced by checkFace(), checkLine(), Octree::isHitByLine, and lineIntersectionWithFace().

Function Documentation

◆ lineCubeIntersection()

int lineCubeIntersection ( Vector v0,
Vector v1,
GLfloat rd )

Definition at line 164 of file OOVoxel.m.

165{
166 int v0_test, v1_test;
167
168 // compare both vertexes with all six face-planes
169 //
170 if ((v0_test = checkFace(v0, rd)) == 0)
171 return -1; // v0 is inside the cube
172 if ((v1_test = checkFace(v1, rd)) == 0)
173 return -1; // v1 is inside the cube
174
175 // check they're not both outside one face-plane
176 //
177 if ((v0_test & v1_test) != 0)
178 return 0; // both v0 and v1 are outside the same face of the cube
179
180 // Now do the same test for the 12 edge planes
181 //
182 v0_test |= checkBevel(v0, rd) << 8;
183 v1_test |= checkBevel(v1, rd) << 8;
184 if ((v0_test & v1_test) != 0)
185 return 0; // v0 and v1 outside of the same bevel
186
187 // Now do the same test for the 8 corner planes
188 //
189 v0_test |= checkCorner(v0, rd) << 24;
190 v1_test |= checkCorner(v1, rd) << 24;
191 if ((v0_test & v1_test) != 0)
192 return 0; // v0 and v1 outside of same corner
193
194 // see if the v0-->v1 line intersects the cube.
195 //
196 return checkLine(v0, v1, v0_test | v1_test, rd);
197}
int checkCorner(Vector p, GLfloat rd)
Definition OOVoxel.m:78
int checkLine(Vector p1, Vector p2, int mask, GLfloat rd)
Definition OOVoxel.m:144
int checkBevel(Vector p, GLfloat rd)
Definition OOVoxel.m:47
int checkFace(Vector p, GLfloat rd)
Definition OOVoxel.m:29

References checkBevel(), checkCorner(), checkFace(), and checkLine().

Referenced by Octree::isHitByLine.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lineIntersectionWithFace()

Vector lineIntersectionWithFace ( Vector p1,
Vector p2,
long mask,
GLfloat rd )

Definition at line 101 of file OOVoxel.m.

102{
103 if (CUBE_FACE_RIGHT & mask)
104 return make_vector(rd,
105 p1.y + (p2.y - p1.y) * (rd - p1.x) / (p2.x - p1.x),
106 p1.z + (p2.z - p1.z) * (rd - p1.x) / (p2.x - p1.x));
107
108 if (CUBE_FACE_LEFT & mask)
109 return make_vector(-rd,
110 p1.y + (p2.y - p1.y) * (-rd - p1.x) / (p2.x - p1.x),
111 p1.z + (p2.z - p1.z) * (-rd - p1.x) / (p2.x - p1.x));
112
113 if (CUBE_FACE_TOP & mask)
114 return make_vector(p1.x + (p2.x - p1.x) * (rd - p1.y) / (p2.y - p1.y),
115 rd,
116 p1.z + (p2.z - p1.z) * (rd - p1.y) / (p2.y - p1.y));
117
118 if (CUBE_FACE_BOTTOM & mask)
119 return make_vector(p1.x + (p2.x - p1.x) * (-rd - p1.y) / (p2.y - p1.y),
120 -rd,
121 p1.z + (p2.z - p1.z) * (-rd - p1.y) / (p2.y - p1.y));
122
123 if (CUBE_FACE_FRONT & mask)
124 return make_vector(p1.x + (p2.x - p1.x) * (rd - p1.z) / (p2.z - p1.z),
125 p1.y + (p2.y - p1.y) * (rd - p1.z) / (p2.z - p1.z),
126 rd);
127
128 if (CUBE_FACE_BACK & mask)
129 return make_vector(p1.x + (p2.x - p1.x) * (-rd - p1.z) / (p2.z - p1.z),
130 p1.y + (p2.y - p1.y) * (-rd - p1.z) / (p2.z - p1.z),
131 -rd);
132 return p1;
133}
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149
#define CUBE_FACE_FRONT
Definition OOVoxel.h:33
#define CUBE_FACE_LEFT
Definition OOVoxel.h:30
#define CUBE_FACE_RIGHT
Definition OOVoxel.h:29
#define CUBE_FACE_TOP
Definition OOVoxel.h:31
#define CUBE_FACE_BOTTOM
Definition OOVoxel.h:32
#define CUBE_FACE_BACK
Definition OOVoxel.h:34
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34

References CUBE_FACE_BACK, CUBE_FACE_BOTTOM, CUBE_FACE_FRONT, CUBE_FACE_LEFT, CUBE_FACE_RIGHT, CUBE_FACE_TOP, make_vector(), Vector::x, Vector::y, and Vector::z.

Referenced by Octree::isHitByLine.

Here is the call graph for this function:
Here is the caller graph for this function: