You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently started a similar project and wrote a different algorithm for finding removal/placing blocks than you in your one-week challenge. If you want you can take this code:
boolcompare(float one, float two, bool less) {
if (less) {
return one < two;
} else {
return two < one;
}
}
// Get Position
glm::vec3 &pos = camera.Position;
// Get Direction
glm::vec3 &direction = camera.Front;
Ray ray(pos, direction);
// Get current chunkblockfloat posX = pos.x;
float posY = pos.y;
float posZ = pos.z;
// Get potential penetrating blocks// Get end point
glm::vec3 endPoint = pos + (direction * RAY_LEN);
bool xDirPositive = direction.x > 0;
bool yDirPositive = direction.y > 0;
bool zDirPositive = direction.z > 0;
float xIncr = xDirPositive ? 1 : -1;
float yIncr = yDirPositive ? 1 : -1;
float zIncr = zDirPositive ? 1 : -1;
std::vector<std::array<glm::vec3, 2>> boxesToCheck;
for (float x = posX; compare(x, endPoint.x, xDirPositive); x += xIncr) {
for (float y = posY; compare(y, endPoint.y, yDirPositive); y += yIncr) {
for (float z = posZ; compare(z, endPoint.z, zDirPositive); z += zIncr) {
int intX = static_cast<int>(x);
int intY = static_cast<int>(y);
int intZ = static_cast<int>(z);
glm::vec3 intVec { intX, intY, intZ };
int intCeilX = intX + (x < 0 ? -1 : 1);
int intCeilY = intY + (y < 0 ? -1 : 1);
int intCeilZ = intZ + (z < 0 ? -1 : 1);
glm::vec3 intCeilVec { intCeilX, intCeilY, intCeilZ };
boxesToCheck.push_back( { intVec, intCeilVec });
}
}
}
// Your AABB intersection checks
The text was updated successfully, but these errors were encountered:
Hi,
I recently started a similar project and wrote a different algorithm for finding removal/placing blocks than you in your one-week challenge. If you want you can take this code:
The text was updated successfully, but these errors were encountered: