So it's rendering pretty much perfectly in the XYZ+ range but things break
down when I start hitting negative values. I have a feeling this is going to be a lot of trial and error. Oh well
This commit is contained in:
68
src/Ray.cpp
68
src/Ray.cpp
@@ -15,6 +15,7 @@ Ray::Ray(
|
||||
this->map = map;
|
||||
origin = camera_position;
|
||||
direction = ray_direction;
|
||||
|
||||
dimensions = map->getDimensions();
|
||||
}
|
||||
|
||||
@@ -50,12 +51,21 @@ sf::Color Ray::Cast(){
|
||||
//if (direction.x <= 0.0f || direction.x >= 3.14f) {
|
||||
// voxel_step.x *= -1;
|
||||
//}
|
||||
if (direction.y > 0.0f || direction.y < PI/2) {
|
||||
voxel_step.y *= -1;
|
||||
|
||||
// Up down
|
||||
//if (direction.y < 0.0f) {
|
||||
// voxel_step.z *= -1;
|
||||
//}
|
||||
if (direction.y > PI * 2 + PI / 2 || direction.y < -1 *PI * 2 + PI / 2) {
|
||||
voxel_step.x *= -1;
|
||||
}
|
||||
if (direction.z <= 0.0f || direction.z >= 3.14f) {
|
||||
voxel_step.z *= -1;
|
||||
// Left right
|
||||
if (direction.z > 1.57) {
|
||||
//voxel_step.z *= -1;
|
||||
}
|
||||
//if (direction.z <= 3.14f + 1.57f && direction.z > 0.0f + 1.57f) {
|
||||
// voxel_step.z *= -1;
|
||||
//}
|
||||
|
||||
int dist = 0;
|
||||
|
||||
@@ -77,23 +87,51 @@ sf::Color Ray::Cast(){
|
||||
intersection_t.z = intersection_t.z + delta_t.z;
|
||||
}
|
||||
}
|
||||
|
||||
// If the voxel went out of bounds
|
||||
if (voxel.z > dimensions.z || voxel.x > dimensions.x || voxel.y > dimensions.x){
|
||||
return sf::Color::Blue;;
|
||||
if (voxel.z >= dimensions.z){
|
||||
return sf::Color(0, 0, 255, 50);
|
||||
}
|
||||
else if ( voxel.x < 0 || voxel.y < 0 || voxel.z < 0){
|
||||
return sf::Color::Green;
|
||||
if (voxel.x >= dimensions.x){
|
||||
return sf::Color(0, 0, 255, 100);
|
||||
}
|
||||
if (voxel.y >= dimensions.x){
|
||||
return sf::Color(0, 0, 255, 150);
|
||||
}
|
||||
|
||||
if (voxel.x < 0) {
|
||||
return sf::Color(0, 255, 0, 150);
|
||||
}
|
||||
if (voxel.y < 0) {
|
||||
return sf::Color(0, 255, 0, 100);
|
||||
}
|
||||
if (voxel.z < 0) {
|
||||
return sf::Color(0, 255, 0, 50);
|
||||
}
|
||||
// If we found a voxel
|
||||
// Registers hit on non-zero
|
||||
else if (map->list[voxel.x + dimensions.x * (voxel.y + dimensions.z * voxel.z)] != 0){
|
||||
|
||||
//TODO: Switch that assigns color on voxel data
|
||||
return sf::Color::Red;
|
||||
}
|
||||
else {
|
||||
dist++;
|
||||
|
||||
switch (map->list[voxel.x + dimensions.x * (voxel.y + dimensions.z * voxel.z)]) {
|
||||
case 1:
|
||||
return sf::Color::Red;
|
||||
case 2:
|
||||
return sf::Color::Magenta;
|
||||
case 3:
|
||||
return sf::Color::Yellow;
|
||||
case 4:
|
||||
return sf::Color(40, 230, 96, 200);
|
||||
case 5:
|
||||
return sf::Color(80, 120, 96, 100);
|
||||
case 6:
|
||||
return sf::Color(150, 80, 220, 200);
|
||||
}
|
||||
//else if (map->list[voxel.x + dimensions.x * (voxel.y + dimensions.z * voxel.z)] != 0){
|
||||
//
|
||||
// //TODO: Switch that assigns color on voxel data
|
||||
// return sf::Color::Red;
|
||||
//}
|
||||
dist++;
|
||||
|
||||
|
||||
} while(dist < 200);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user