Code: Select all
for (int i = 0; i < 8;i++)
{
offset.x = ((i & 1) ? step : -step);
offset.y = ((i & 2) ? step : -step);
offset.z = ((i & 4) ? step : -step);
pNode->pChild[i] = BuildOctree(center + offset, step, stopDepth - 1);
}
Code: Select all
for (int i = 0; i < 8;i++)
{
offset.x = ((i & 1) ? step : -step);
offset.y = ((i & 2) ? step : -step);
offset.z = ((i & 4) ? step : -step);
pNode->pChild[i] = BuildOctree(center + offset, step, stopDepth - 1);
}
That's just how bitwise and works. 4 translates to 0100 in binary so it'll get the third bit. 3 translates to 0011 which will get the first and second. We only want the third bit here so 4 makes more senseYumtard wrote:seems to me that i & 4 should be replaced with i & 3 tho
Code: Select all
for( size_t i = 0; i < count; ++i )
{
// using % modulo
if( i % 2 == 0 )
// using & bit and
if( i & 2 == 0 )
}
Code: Select all
for i = 0 to vert_count, i++
j = i & 3
triangle[j].vertex[i] = vertex[i]
end
Code: Select all
for i = 0 to vertex_count, i++
j = i % 3
triangle[j].vertex[i] = vertex[i]
end
// or
for j = 0 to vertex_count / 3, j++
i = j * 3
triangle[j].vertex[i] = vertex[i++] // i = j + 0
triangle[j].vertex[i] = vertex[i++] // i = j + 1
triangle[j].vertex[i] = vertex[i] // i = j + 2
end
cyboryxmen wrote:That's just how bitwise and works. 4 translates to 0100 in binary so it'll get the third bit. 3 translates to 0011 which will get the first and second. We only want the third bit here so 4 makes more senseYumtard wrote:seems to me that i & 4 should be replaced with i & 3 tho