-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mostly formatting changes, added a few suggestions #4
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Did I miss the performance tests? | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,10 @@ int BBAccelerator::findSplitIndex(size_t startIndex, size_t endIndex, | |
return (startIndex + endIndex) / 2; | ||
} | ||
|
||
std::unique_ptr<BBNode> BBAccelerator::split(size_t startIndex, size_t endIndex, | ||
std::vector<std::pair<BoundingBox, size_t>>& boxes) { | ||
std::unique_ptr<BBNode> BBAccelerator::split( | ||
size_t startIndex, size_t endIndex, | ||
std::vector<std::pair<BoundingBox, size_t>>& boxes) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All brackets go after the function |
||
std::unique_ptr<BBNode> node = std::make_unique<BBNode>(); | ||
if (endIndex - startIndex == 1) { | ||
node->itemIndex = boxes[startIndex].second; | ||
|
@@ -46,12 +48,9 @@ std::unique_ptr<BBNode> BBAccelerator::split(size_t startIndex, size_t endIndex, | |
|
||
float BBAccelerator::pointAxisValue(const Point3& p, const Axis& axis) const { | ||
switch(axis) { | ||
case Axis::X_AXIS: | ||
return p.x; | ||
case Axis::Y_AXIS: | ||
return p.y; | ||
case Axis::Z_AXIS: | ||
return p.z; | ||
case Axis::X_AXIS: return p.x; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intend one tab less to align with switch |
||
case Axis::Y_AXIS: return p.y; | ||
case Axis::Z_AXIS: return p.z; | ||
}; | ||
std::cout << "Warning: Undefined axis, returning X_AXIS" << std::endl; | ||
return p.x; | ||
|
@@ -70,15 +69,23 @@ float BBAccelerator::calculateGapAverage(std::vector<Point3>& midPoints, const A | |
- pointAxisValue(midPoints[0], axis)) / (midPoints.size() - 1); | ||
} | ||
|
||
Axis BBAccelerator::findSortAxis(const std::vector<std::pair<BoundingBox, size_t>>& boxes, | ||
size_t startIndex, size_t endIndex) const { | ||
Axis BBAccelerator::findSortAxis( | ||
const std::vector<std::pair<BoundingBox, size_t>>& boxes, | ||
size_t startIndex, size_t endIndex) const | ||
{ | ||
std::vector<Point3> midPoints; | ||
for (int i = startIndex; i < endIndex; ++i) { | ||
midPoints.push_back(boxes[i].first.mid()); | ||
} | ||
float xavg = calculateGapAverage(midPoints, Axis::X_AXIS); | ||
float yavg = calculateGapAverage(midPoints, Axis::Y_AXIS); | ||
float zavg = calculateGapAverage(midPoints, Axis::Z_AXIS); | ||
// float target_axis = std::max(xavg, yag, zavg) | ||
// | ||
// If the above algorithm is not optimal, just hide it | ||
// in a costum procedure. | ||
// | ||
// map (target_axis -> AXIS) use array? some light map? | ||
if (xavg > yavg) { | ||
if (xavg > zavg) { | ||
return Axis::X_AXIS; | ||
|
@@ -92,15 +99,20 @@ Axis BBAccelerator::findSortAxis(const std::vector<std::pair<BoundingBox, size_t | |
} | ||
|
||
void BBAccelerator::mergeRoots() { | ||
auto sortNodes = [&](const std::unique_ptr<BBNode>& n0, | ||
auto sortNodes = | ||
[&](const std::unique_ptr<BBNode>& n0, | ||
const std::unique_ptr<BBNode>& n1) { | ||
// assign m_boundingBoxes[no->itemIndex.mid().x | ||
// assign m_boundingBoxes[n1->itemIndex.mid().x | ||
return m_boundingBoxes[n0->itemIndex].mid().x < | ||
m_boundingBoxes[n1->itemIndex].mid().x; | ||
}; | ||
|
||
std::sort(m_roots.begin(), m_roots.end(), sortNodes); | ||
while (m_roots.size() > 1) { | ||
int endIndex = m_roots.size() - m_roots.size() % 2; | ||
for (int i = 0; i < endIndex; i += 2) { | ||
// Define what this block does in a new procedure | ||
int nextIndex = m_boundingBoxes.size(); | ||
BoundingBox b; | ||
b.addBoundingBox(m_boundingBoxes[m_roots[i]->itemIndex]); | ||
|
@@ -121,7 +133,9 @@ void BBAccelerator::mergeRoots() { | |
m_root = m_roots[0].get(); | ||
} | ||
|
||
void BBAccelerator::initialize(const std::unique_ptr<Entity>* entities, size_t numberOfEntities, | ||
void BBAccelerator::initialize( | ||
const std::unique_ptr<Entity>* entities, | ||
size_t numberOfEntities, | ||
const std::vector<int>& objects) { | ||
m_entities = entities; | ||
std::vector<std::pair<BoundingBox, size_t>> boxes; | ||
|
@@ -140,19 +154,20 @@ void BBAccelerator::initialize(const std::unique_ptr<Entity>* entities, size_t n | |
} | ||
|
||
bool BBAccelerator::intersects(const Ray& ray, size_t ignoreID, EntityIntersection* result, bool findAny) const { | ||
const BBNode* stack[128]; | ||
int stackBack; | ||
const BBNode* current; | ||
const BBNode* stack[128]; // Move closer to assigment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We just want to allocate the array here |
||
int stackBack; // Join with assignment | ||
const BBNode* current; // Would argue about putting it into the while loop | ||
bool hit = false; | ||
const Vector3 invrDir = ONE_VECTOR / ray.direction; | ||
stack[0] = m_root->left.get(); | ||
stack[1] = m_root->right.get(); | ||
stackBack = 2; | ||
stackBack = 2; // General Suggestion of writting in snake_case | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No |
||
while (stackBack > 0) { | ||
current = stack[--stackBack]; | ||
if (current->isLeaf()) { | ||
if (m_entities[current->itemIndex]->getID() != ignoreID | ||
&& m_entities[current->itemIndex]->intersects(ray, result)) { | ||
// findAny what? Also foundAnyObject... | ||
if (findAny) { | ||
return true; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,7 @@ bool BoundingBox::intersectsAny(const Ray& ray, const Vector3& invDir, float max | |
} | ||
|
||
if (!std::isinf(invDir.x)) { | ||
// Hide the complex conidtion in a procedure | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try to refactor these if you can |
||
if (intersectSide(start.x, ray.origin.x, invDir.x, | ||
ray.origin.z, ray.origin.y, ray.direction.z, | ||
ray.direction.y, start.z, start.y, end.z, end.y, maxT) > 0.0f | ||
|
@@ -116,6 +117,9 @@ bool BoundingBox::intersectsAny(const Ray& ray, const Vector3& invDir, float max | |
} | ||
|
||
if (!std::isinf(invDir.y)) { | ||
// I would argue this is the same condition, | ||
// just with the order of arguments changed | ||
// eg checkCondition (x, y, z), checkCondition (y, z, x)... | ||
if (intersectSide(start.y, ray.origin.y, invDir.y, | ||
ray.origin.x, ray.origin.z, ray.direction.x, | ||
ray.direction.z, start.x, start.z, end.x, end.z, maxT) > 0.0f | ||
|
@@ -127,6 +131,7 @@ bool BoundingBox::intersectsAny(const Ray& ray, const Vector3& invDir, float max | |
} | ||
|
||
if (!std::isinf(invDir.z)) { | ||
// Same here | ||
if (intersectSide(start.z, ray.origin.z, invDir.z, | ||
ray.origin.x, ray.origin.y, ray.direction.x, | ||
ray.direction.y, start.x, start.y, end.x, end.y, maxT) > 0.0f | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ std::vector<FilmBounds> Film::splitToTiles(unsigned int tileSize) const { | |
} | ||
} | ||
|
||
// Remove boolean? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How? |
||
bool shouldPad = false; | ||
|
||
if (filmResW % tileWidth != 0) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,17 @@ CheckerboardImage::CheckerboardImage(int tiles) : Image(tiles * PIXELS_PER_TILE, | |
bool black = true; | ||
int x = 0; | ||
int y = 0; | ||
// Break this loop in two, avoid flag (But optimization issues I assume) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How? |
||
for (int i = 0; i < getHeight(); ++i) { | ||
for (int j = 0; j < getWidth(); ++j) { | ||
// Return color from a procedure? | ||
if (black) { | ||
setPixel(i, j, RGBColor(0.05f, 0.05f, 0.05f)); | ||
} | ||
else { | ||
setPixel(i, j, RGBColor(0.95f, 0.95f, 0.95f)); | ||
} | ||
|
||
x++; | ||
if (x == PIXELS_PER_TILE) { | ||
black = !black; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this file