mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-09 12:16:24 -04:00
Simplify some code using vector operations.
This commit is contained in:
parent
b8b30363d7
commit
fe9c001fd8
@ -626,9 +626,7 @@ pub const Frustum = struct {
|
|||||||
inline for(self.planes) |plane| {
|
inline for(self.planes) |plane| {
|
||||||
var dist: f32 = vec.dot(pos - plane.pos, plane.norm);
|
var dist: f32 = vec.dot(pos - plane.pos, plane.norm);
|
||||||
// Find the most positive corner:
|
// Find the most positive corner:
|
||||||
dist += @max(0, dim[0]*plane.norm[0]);
|
dist += @reduce(.Add, @max(Vec3f{0, 0, 0}, dim*plane.norm));
|
||||||
dist += @max(0, dim[1]*plane.norm[1]);
|
|
||||||
dist += @max(0, dim[2]*plane.norm[2]);
|
|
||||||
if(dist < 0) return false;
|
if(dist < 0) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -1239,22 +1237,17 @@ pub const RenderStructure = struct {
|
|||||||
var curCorner: usize = 0;
|
var curCorner: usize = 0;
|
||||||
for(0..2) |a| {
|
for(0..2) |a| {
|
||||||
for(0..2) |b| {
|
for(0..2) |b| {
|
||||||
|
|
||||||
var cornerVector: Vec3f = undefined;
|
var cornerVector: Vec3f = undefined;
|
||||||
switch(chunk.Neighbors.vectorComponent[neighbor]) {
|
switch(chunk.Neighbors.vectorComponent[neighbor]) {
|
||||||
.x => {
|
.x => {
|
||||||
cornerVector[0] = minVec[0];
|
cornerVector = @select(f32, @Vector(3, bool){true, a == 0, b == 0}, minVec, maxVec);
|
||||||
cornerVector[1] = if(a == 0) minVec[1] else maxVec[1];
|
|
||||||
cornerVector[2] = if(b == 0) minVec[2] else maxVec[2];
|
|
||||||
},
|
},
|
||||||
.y => {
|
.y => {
|
||||||
cornerVector[1] = minVec[1];
|
cornerVector = @select(f32, @Vector(3, bool){a == 0, true, b == 0}, minVec, maxVec);
|
||||||
cornerVector[0] = if(a == 0) minVec[0] else maxVec[0];
|
|
||||||
cornerVector[2] = if(b == 0) minVec[2] else maxVec[2];
|
|
||||||
},
|
},
|
||||||
.z => {
|
.z => {
|
||||||
cornerVector[2] = minVec[2];
|
cornerVector = @select(f32, @Vector(3, bool){a == 0, b == 0, true}, minVec, maxVec);
|
||||||
cornerVector[0] = if(a == 0) minVec[0] else maxVec[0];
|
|
||||||
cornerVector[1] = if(b == 0) minVec[1] else maxVec[1];
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
corners[curCorner] = projRotMat.mulVec(vec.combine(relPosFloat + cornerVector, 1));
|
corners[curCorner] = projRotMat.mulVec(vec.combine(relPosFloat + cornerVector, 1));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user