Oolite
Loading...
Searching...
No Matches
OOVoxel.m File Reference
import "OOMaths.h"
Include dependency graph for OOVoxel.m:

Go to the source code of this file.

Functions

int checkFace (Vector p, GLfloat rd)
int checkBevel (Vector p, GLfloat rd)
int checkCorner (Vector p, GLfloat rd)
Vector lineIntersectionWithFace (Vector p1, Vector p2, long mask, GLfloat rd)
int checkPoint (Vector p1, Vector p2, GLfloat alpha, long mask, GLfloat rd)
int checkLine (Vector p1, Vector p2, int mask, GLfloat rd)
int lineCubeIntersection (Vector v0, Vector v1, GLfloat rd)

Function Documentation

◆ checkBevel()

int checkBevel ( Vector p,
GLfloat rd )

Definition at line 47 of file OOVoxel.m.

48{
49 GLfloat r2 = rd * 2;
50 int bevels = 0;
51 if (p.x + p.y > r2)
52 bevels |= 0x001;
53 if (p.x - p.y > r2)
54 bevels |= 0x002;
55 if (-p.x + p.y > r2)
56 bevels |= 0x004;
57 if (-p.x - p.y > r2)
58 bevels |= 0x008;
59 if (p.x + p.z > r2)
60 bevels |= 0x010;
61 if (p.x - p.z > r2)
62 bevels |= 0x020;
63 if (-p.x + p.z > r2)
64 bevels |= 0x040;
65 if (-p.x - p.z > r2)
66 bevels |= 0x080;
67 if (p.y + p.z > r2)
68 bevels |= 0x100;
69 if (p.y - p.z > r2)
70 bevels |= 0x200;
71 if (-p.y + p.z > r2)
72 bevels |= 0x400;
73 if (-p.y - p.z > r2)
74 bevels |= 0x800;
75 return bevels;
76}
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34

References Vector::x, Vector::y, and Vector::z.

Referenced by lineCubeIntersection().

Here is the caller graph for this function:

◆ checkCorner()

int checkCorner ( Vector p,
GLfloat rd )

Definition at line 78 of file OOVoxel.m.

79{
80 GLfloat r3 = rd * 3;
81 int corners = 0;
82 if ((p.x + p.y + p.z) > r3)
83 corners |= 0x01;
84 if ((p.x + p.y - p.z) > r3)
85 corners |= 0x02;
86 if ((p.x - p.y + p.z) > r3)
87 corners |= 0x04;
88 if ((p.x - p.y - p.z) > r3)
89 corners |= 0x08;
90 if ((-p.x + p.y + p.z) > r3)
91 corners |= 0x10;
92 if ((-p.x + p.y - p.z) > r3)
93 corners |= 0x20;
94 if ((-p.x - p.y + p.z) > r3)
95 corners |= 0x40;
96 if ((-p.x - p.y - p.z) > r3)
97 corners |= 0x80;
98 return corners;
99}

References Vector::x, Vector::y, and Vector::z.

Referenced by lineCubeIntersection().

Here is the caller graph for this function:

◆ checkFace()

int checkFace ( Vector p,
GLfloat rd )

Definition at line 29 of file OOVoxel.m.

30{
31 int faces = 0;
32 if (p.x > rd)
33 faces |= CUBE_FACE_RIGHT; // right
34 if (p.x < -rd)
35 faces |= CUBE_FACE_LEFT; // left
36 if (p.y > rd)
37 faces |= CUBE_FACE_TOP; // above
38 if (p.y < -rd)
39 faces |= CUBE_FACE_BOTTOM; // below
40 if (p.z > rd)
41 faces |= CUBE_FACE_FRONT; // ahead
42 if (p.z < -rd)
43 faces |= CUBE_FACE_BACK; // behind
44 return faces;
45}
#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

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

Referenced by checkPoint(), and lineCubeIntersection().

Here is the caller graph for this function:

◆ checkLine()

int checkLine ( Vector p1,
Vector p2,
int mask,
GLfloat rd )

Definition at line 144 of file OOVoxel.m.

145{
146 int result = 0;
147 if ((CUBE_FACE_RIGHT & mask) && (p1.x > p2.x) && (checkPoint(p1, p2, (rd - p1.x) / (p2.x - p1.x), 0x3f - CUBE_FACE_RIGHT, rd) == 0)) // right
148 result |= CUBE_FACE_RIGHT;
149 if ((CUBE_FACE_LEFT & mask) && (p1.x < p2.x) && (checkPoint(p1, p2, (-rd - p1.x) / (p2.x - p1.x), 0x3f - CUBE_FACE_LEFT, rd) == 0)) // left
150 result |= CUBE_FACE_LEFT;
151 if ((CUBE_FACE_TOP & mask) && (p1.y > p2.y) && (checkPoint(p1, p2, (rd - p1.y) / (p2.y - p1.y), 0x3f - CUBE_FACE_TOP, rd) == 0)) // above
152 result |= CUBE_FACE_TOP;
153 if ((CUBE_FACE_BOTTOM & mask) && (p1.y < p2.y) && (checkPoint(p1, p2, (-rd - p1.y) / (p2.y - p1.y), 0x3f - CUBE_FACE_BOTTOM, rd) == 0)) // below
154 result |= CUBE_FACE_BOTTOM;
155 if ((CUBE_FACE_FRONT & mask) && (p1.z > p2.z) && (checkPoint(p1, p2, (rd - p1.z) / (p2.z - p1.z), 0x3f - CUBE_FACE_FRONT, rd) == 0)) // ahead
156 result |= CUBE_FACE_FRONT;
157 if ((CUBE_FACE_BACK & mask) && (p1.z < p2.z) && (checkPoint(p1, p2, (-rd - p1.z) / (p2.z - p1.z), 0x3f - CUBE_FACE_BACK, rd) == 0)) // behind
158 result |= CUBE_FACE_BACK;
159 return result;
160}
int checkPoint(Vector p1, Vector p2, GLfloat alpha, long mask, GLfloat rd)
Definition OOVoxel.m:135

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

Referenced by lineCubeIntersection().

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

◆ checkPoint()

int checkPoint ( Vector p1,
Vector p2,
GLfloat alpha,
long mask,
GLfloat rd )

Definition at line 135 of file OOVoxel.m.

136{
137 Vector pp;
138 pp.x = p1.x + alpha * (p2.x - p1.x);
139 pp.y = p1.y + alpha * (p2.y - p1.y);
140 pp.z = p1.z + alpha * (p2.z - p1.z);
141 return (checkFace(pp, rd) & mask);
142}
float y
float x
int checkFace(Vector p, GLfloat rd)
Definition OOVoxel.m:29

References checkFace(), Vector::x, Vector::y, and Vector::z.

Referenced by checkLine().

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

◆ 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

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

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: