Turned off experimental phong lighting in the kernel

fixed all compiler errors thrown by MSVC
Switched experimental octree map back to the old map
Refactored old map system, prettied it up
master
MitchellHansen 8 years ago
parent 391dc63ec8
commit 561c07c602

@ -31,8 +31,8 @@ public:
private: private:
float friction_coefficient = 0.1; float friction_coefficient = 0.1f;
float default_impulse = 1.0; float default_impulse = 1.0f;
// 3D vector // 3D vector
sf::Vector3f movement; sf::Vector3f movement;

@ -0,0 +1,42 @@
#pragma once
#include <SFML/System/Vector3.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/Graphics/Color.hpp>
#include <random>
#include <iostream>
#include <functional>
#include <cmath>
#define _USE_MATH_DEFINES
#include <math.h>
#include <deque>
class Old_Map {
public:
Old_Map(sf::Vector3i dim);
~Old_Map();
void generate_terrain();
sf::Vector3i getDimensions();
char* get_voxel_data();
protected:
private:
double* height_map;
char *voxel_data;
sf::Vector3i dimensions;
void set_voxel(sf::Vector3i position, int val);
double sample(int x, int y);
void set_sample(int x, int y, double value);
void sample_square(int x, int y, int size, double value);
void sample_diamond(int x, int y, int size, double value);
void diamond_square(int stepsize, double scale);
};

@ -36,7 +36,7 @@ public:
private: private:
CL_Wrapper *cl; CL_Wrapper *cl;
bool sharing_supported = False; bool sharing_supported = false;
sf::Uint8 *drawing_surface; sf::Uint8 *drawing_surface;
sf::RenderWindow* window; sf::RenderWindow* window;

@ -64,7 +64,7 @@ public:
else { else {
t.setFont(f); t.setFont(f);
t.setCharacterSize(20); t.setCharacterSize(20);
t.setPosition(20, slot * pixel_spacing); t.setPosition(static_cast<float>(20), static_cast<float>(slot * pixel_spacing));
} }
} }
@ -140,11 +140,11 @@ inline float AngleBetweenVectors(sf::Vector3f a, sf::Vector3f b){
} }
inline float DegreesToRadians(float in) { inline float DegreesToRadians(float in) {
return in * PI / 180.0f; return static_cast<float>(in * PI / 180.0f);
} }
inline float RadiansToDegrees(float in) { inline float RadiansToDegrees(float in) {
return in * 180.0f / PI; return static_cast<float>(in * 180.0f / PI);
} }
inline std::string read_file(std::string file_name){ inline std::string read_file(std::string file_name){

@ -16,7 +16,13 @@ float4 white_light(float4 input, float3 light, int3 mask) {
// 0 1 2 3 4 5 6 7 8 9 // 0 1 2 3 4 5 6 7 8 9
// {r, g, b, i, x, y, z, x', y', z'} // {r, g, b, i, x, y, z, x', y', z'}
float4 cast_light_rays(float3 eye_direction, float3 ray_origin, float4 voxel_color, float3 voxel_normal, global float* lights, global int* light_count) { float4 cast_light_rays(
float3 eye_direction,
float3 ray_origin,
float4 voxel_color,
float3 voxel_normal,
global float* lights,
global int* light_count) {
// set the ray origin to be where the initial ray intersected the voxel // set the ray origin to be where the initial ray intersected the voxel
// which side z, and the x and y position // which side z, and the x and y position
@ -183,10 +189,10 @@ __kernel void min_kern(
write_imagef(image, pixel, (float4)(.25, .00, .25, 1.00)); write_imagef(image, pixel, (float4)(.25, .00, .25, 1.00));
return; return;
case 5: case 5:
{
//write_imagef(image, pixel, (float4)(.00, .00, + 0.5, 1.00));
//write_imagef(image, pixel, white_light((float4)(.35, .00, ((1.0 - 0) / (128 - 0) * (voxel.z - 128)) + 1, 0.2), (float3)(lights[7], lights[8], lights[9]), mask));
//write_imagef(image, pixel, (float4)(.00, .00, + 0.5, 1.00));
write_imagef(image, pixel, white_light((float4)(.35, .00, ((1.0 - 0) / (128 - 0) * (voxel.z - 128)) + 1, 0.2), (float3)(lights[7], lights[8], lights[9]), mask));
return;
float3 vox = convert_float3(voxel); float3 vox = convert_float3(voxel);
float3 norm = normalize(convert_float3(mask) * convert_float3(voxel_step)); float3 norm = normalize(convert_float3(mask) * convert_float3(voxel_step));
@ -204,13 +210,13 @@ __kernel void min_kern(
)); ));
return; return;
}
case 6: case 6:
write_imagef(image, pixel, (float4)(.30, .80, .10, 1.00)); write_imagef(image, pixel, (float4)(.30, .80, .10, 1.00));
return; return;
default: default:
write_imagef(image, pixel, (float4)(.30, .80, .10, 1.00)); //write_imagef(image, pixel, (float4)(.30, .10, .10, 1.00));
return; continue;
} }
} }

@ -0,0 +1,32 @@
// TODO
/*
OpenCL:
- Add phong lighting / fix the current implementation
- Switch to switch lighting models
- Separate out into a part of the rendering module
Map:
- Reimplement the old map, put it into an old_map structure
- Implement the new octree structure
- storing the pre-octree volumetric data
- determining when to load volumetric data into the in-memory structure
- building the octree from that raw volumetric data
- combining with other octree nodes to allow streaming of leafs
- passing that data into the renderer
- renderer needs to then traverse the octree
- Terrain generation for real this time
- Loader of 3rd party voxel data
Renderer:
- Determine when to switch between the cpu and gpu rendering
- call to the map to make sure that the gpu/cpu has an up to date copy
of the volumetric data
*/

@ -34,22 +34,22 @@ int Camera::add_relative_impulse(DIRECTION impulse_direction, float speed) {
switch (impulse_direction) { switch (impulse_direction) {
case DIRECTION::UP: case DIRECTION::UP:
dir = sf::Vector2f(direction.y, direction.x + PI); dir = sf::Vector2f(direction.y, direction.x + PI_F);
break; break;
case DIRECTION::DOWN: case DIRECTION::DOWN:
dir = sf::Vector2f(direction.y, direction.x); dir = sf::Vector2f(direction.y, direction.x);
break; break;
case DIRECTION::LEFT: case DIRECTION::LEFT:
dir = sf::Vector2f(direction.y + PI + PI / 2, PI / 2); dir = sf::Vector2f(direction.y + PI_F + PI_F / 2, PI_F / 2);
break; break;
case DIRECTION::RIGHT: case DIRECTION::RIGHT:
dir = sf::Vector2f(direction.y + PI / 2, PI / 2); dir = sf::Vector2f(direction.y + PI_F / 2, PI_F / 2);
break; break;
case DIRECTION::FORWARD: case DIRECTION::FORWARD:
dir = sf::Vector2f(direction.y, direction.x + PI / 2); dir = sf::Vector2f(direction.y, direction.x + PI_F / 2);
break; break;
case DIRECTION::REARWARD: case DIRECTION::REARWARD:
dir = sf::Vector2f(direction.y + PI, (direction.x * -1) + PI / 2 ); dir = sf::Vector2f(direction.y + PI_F, (direction.x * -1) + PI_F / 2 );
break; break;
} }

@ -27,30 +27,30 @@ struct block {
void Map::generate_octree() { void Map::generate_octree() {
char* arr[8192]; char* arr[8192];
for (int i = 0; i < 8192; i++) { for (int i = 0; i < 8192; i++) {
arr[i] = 0; arr[i] = 0;
} }
int* dataset = new int[32 * 32 * 32]; int* dataset = new int[32 * 32 * 32];
for (int i = 0; i < 32 * 32 * 32; i++) { for (int i = 0; i < 32 * 32 * 32; i++) {
dataset[0] = i; dataset[0] = i;
} }
int level = log2(32); int level = static_cast<int>(log2(32));
leaf top_node; leaf top_node;
top_node.level = level; top_node.level = level;
for (int i = 0; i < 16 * 16 * 16; i++){ for (int i = 0; i < 16 * 16 * 16; i++) {
for (int i = 0; i < 8 * 8 * 8; i++){ for (int i = 0; i < 8 * 8 * 8; i++) {
for (int i = 0; i < 4 * 4 * 4; i++){ for (int i = 0; i < 4 * 4 * 4; i++) {
for (int i = 0; i < 2 * 2 * 2; i++){ for (int i = 0; i < 2 * 2 * 2; i++) {
} }
} }
} }
} }
@ -73,7 +73,7 @@ void Map::generate_octree() {
std::cout << BitCount(parent & leafmask); std::cout << BitCount(parent & leafmask);
unsigned int children[8] = {0, 0, 0, 0, 0, 0, 0, 0}; unsigned int children[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
} }

@ -0,0 +1,225 @@
#pragma once
#include <iostream>
#include <SFML/System/Vector3.hpp>
#include <SFML/System/Vector2.hpp>
#include "util.hpp"
#include <Old_map.h>
Old_Map::Old_Map(sf::Vector3i dim) {
dimensions = dim;
}
Old_Map::~Old_Map() {
}
void Old_Map::generate_terrain() {
std::mt19937 gen;
std::uniform_real_distribution<double> dis(-1.0, 1.0);
auto f_rand = std::bind(dis, gen);
voxel_data = new char[dimensions.x * dimensions.y * dimensions.z];
height_map = new double[dimensions.x * dimensions.y];
for (int i = 0; i < dimensions.x * dimensions.y * dimensions.z; i++) {
voxel_data[i] = 0;
}
for (int i = 0; i < dimensions.x * dimensions.y; i++) {
height_map[i] = 0;
}
//size of grid to generate, note this must be a
//value 2^n+1
int DATA_SIZE = dimensions.x + 1;
//an initial seed value for the corners of the data
double SEED = rand() % 25 + 25;
//seed the data
set_sample(0, 0, SEED);
set_sample(0, dimensions.y, SEED);
set_sample(dimensions.x, 0, SEED);
set_sample(dimensions.x, dimensions.y, SEED);
double h = 30.0;//the range (-h -> +h) for the average offset
//for the new value in range of h
//side length is distance of a single square side
//or distance of diagonal in diamond
for (int sideLength = DATA_SIZE - 1;
//side length must be >= 2 so we always have
//a new value (if its 1 we overwrite existing values
//on the last iteration)
sideLength >= 2;
//each iteration we are looking at smaller squares
//diamonds, and we decrease the variation of the offset
sideLength /= 2, h /= 2.0) {
//half the length of the side of a square
//or distance from diamond center to one corner
//(just to make calcs below a little clearer)
int halfSide = sideLength / 2;
//generate the new square values
for (int x = 0; x < DATA_SIZE - 1; x += sideLength) {
for (int y = 0; y < DATA_SIZE - 1; y += sideLength) {
//x, y is upper left corner of square
//calculate average of existing corners
double avg = sample(x, y) + //top left
sample(x + sideLength, y) +//top right
sample(x, y + sideLength) + //lower left
sample(x + sideLength, y + sideLength);//lower right
avg /= 4.0;
//center is average plus random offset
set_sample(x + halfSide, y + halfSide,
//We calculate random value in range of 2h
//and then subtract h so the end value is
//in the range (-h, +h)
avg + (f_rand() * 2 * h) - h);
}
}
//generate the diamond values
//since the diamonds are staggered we only move x
//by half side
//NOTE: if the data shouldn't wrap then x < DATA_SIZE
//to generate the far edge values
for (int x = 0; x < DATA_SIZE - 1; x += halfSide) {
//and y is x offset by half a side, but moved by
//the full side length
//NOTE: if the data shouldn't wrap then y < DATA_SIZE
//to generate the far edge values
for (int y = (x + halfSide) % sideLength; y < DATA_SIZE - 1; y += sideLength) {
//x, y is center of diamond
//note we must use mod and add DATA_SIZE for subtraction
//so that we can wrap around the array to find the corners
double avg =
sample((x - halfSide + DATA_SIZE) % DATA_SIZE, y) + //left of center
sample((x + halfSide) % DATA_SIZE, y) + //right of center
sample(x, (y + halfSide) % DATA_SIZE) + //below center
sample(x, (y - halfSide + DATA_SIZE) % DATA_SIZE); //above center
avg /= 4.0;
//new value = average plus random offset
//We calculate random value in range of 2h
//and then subtract h so the end value is
//in the range (-h, +h)
avg = avg + (f_rand() * 2 * h) - h;
//update value for center of diamond
set_sample(x, y, avg);
//wrap values on the edges, remove
//this and adjust loop condition above
//for non-wrapping values.
if (x == 0) set_sample(DATA_SIZE - 1, y, avg);
if (y == 0) set_sample(x, DATA_SIZE - 1, avg);
}
}
}
for (int x = 0; x < dimensions.x; x++) {
for (int y = 0; y < dimensions.y; y++) {
if (height_map[x + y * dimensions.x] > 0) {
int z = static_cast<int>(height_map[x + y * dimensions.x]);
while (z > 0) {
voxel_data[x + dimensions.x * (y + dimensions.z * z)] = 5;
z--;
}
}
}
}
for (int x = 0; x < dimensions.x / 10; x++) {
for (int y = 0; y < dimensions.y / 10; y++) {
for (int z = 0; z < dimensions.z; z++) {
if (rand() % 1000 < 1)
voxel_data[x + dimensions.x * (y + dimensions.z * z)] = rand() % 6;
}
}
}
}
void Old_Map::set_voxel(sf::Vector3i position, int val) {
voxel_data[position.x + dimensions.x * (position.y + dimensions.z * position.z)] = val;
}
sf::Vector3i Old_Map::getDimensions() {
return dimensions;
}
char* Old_Map::get_voxel_data() {
return voxel_data;
}
double Old_Map::sample(int x, int y) {
return height_map[(x & (dimensions.x - 1)) + (y & (dimensions.y - 1)) * dimensions.x];
}
void Old_Map::set_sample(int x, int y, double value) {
height_map[(x & (dimensions.x - 1)) + (y & (dimensions.y - 1)) * dimensions.x] = value;
}
void Old_Map::sample_square(int x, int y, int size, double value) {
int hs = size / 2;
// a b
//
// x
//
// c d
double a = sample(x - hs, y - hs);
double b = sample(x + hs, y - hs);
double c = sample(x - hs, y + hs);
double d = sample(x + hs, y + hs);
set_sample(x, y, ((a + b + c + d) / 4.0) + value);
}
void Old_Map::sample_diamond(int x, int y, int size, double value) {
int hs = size / 2;
// c
//
//a x b
//
// d
double a = sample(x - hs, y);
double b = sample(x + hs, y);
double c = sample(x, y - hs);
double d = sample(x, y + hs);
set_sample(x, y, ((a + b + c + d) / 4.0) + value);
}
void Old_Map::diamond_square(int stepsize, double scale) {
std::mt19937 generator;
std::uniform_real_distribution<double> uniform_distribution(-1.0, 1.0);
auto f_rand = std::bind(uniform_distribution, std::ref(generator));
int halfstep = stepsize / 2;
for (int y = halfstep; y < dimensions.y + halfstep; y += stepsize) {
for (int x = halfstep; x < dimensions.x + halfstep; x += stepsize) {
sample_square(x, y, stepsize, f_rand() * scale);
}
}
for (int y = 0; y < dimensions.y; y += stepsize) {
for (int x = 0; x < dimensions.x; x += stepsize) {
sample_diamond(x + halfstep, y, stepsize, f_rand() * scale);
sample_diamond(x, y + halfstep, stepsize, f_rand() * scale);
}
}
}

@ -30,9 +30,9 @@ sf::Color Ray::Cast() {
// Setup the voxel coords from the camera origin // Setup the voxel coords from the camera origin
voxel = sf::Vector3<int>( voxel = sf::Vector3<int>(
floorf(origin.x), static_cast<int>(floorf(origin.x)),
floorf(origin.y), static_cast<int>(floorf(origin.y)),
floorf(origin.z) static_cast<int>(floorf(origin.z))
); );
// Delta T is the units a ray must travel along an axis in order to // Delta T is the units a ray must travel along an axis in order to
@ -113,18 +113,18 @@ sf::Color Ray::Cast() {
if (face == 0) { if (face == 0) {
alpha = AngleBetweenVectors(sf::Vector3f(1, 0, 0), map->global_light); alpha = AngleBetweenVectors(sf::Vector3f(1, 0, 0), map->global_light);
alpha = fmod(alpha, 0.785) * 2; alpha = static_cast<float>(fmod(alpha, 0.785) * 2);
} else if (face == 1) { } else if (face == 1) {
alpha = AngleBetweenVectors(sf::Vector3f(0, 1, 0), map->global_light); alpha = AngleBetweenVectors(sf::Vector3f(0, 1, 0), map->global_light);
alpha = fmod(alpha, 0.785) * 2; alpha = static_cast<float>(fmod(alpha, 0.785) * 2);
} else if (face == 2){ } else if (face == 2){
//alpha = 1.57 / 2; //alpha = 1.57 / 2;
alpha = AngleBetweenVectors(sf::Vector3f(0, 0, 1), map->global_light); alpha = AngleBetweenVectors(sf::Vector3f(0, 0, 1), map->global_light);
alpha = fmod(alpha, 0.785) * 2; alpha = static_cast<float>(fmod(alpha, 0.785) * 2);
} }
alpha *= 162; alpha *= 162;

@ -1,9 +1,3 @@
#include <iostream>
#include <chrono>
#include <fstream>
#include <sstream>
#include <SFML/Graphics.hpp>
#ifdef linux #ifdef linux
#include <CL/cl.h> #include <CL/cl.h>
#include <CL/opencl.h> #include <CL/opencl.h>
@ -25,7 +19,14 @@
#include <OpenCL/cl_ext.h> #include <OpenCL/cl_ext.h>
#endif #endif
#include "Map.h"
#include <iostream>
#include <chrono>
#include <fstream>
#include <sstream>
#include <SFML/Graphics.hpp>
#include "Old_Map.h"
#include "Curses.h" #include "Curses.h"
#include "util.hpp" #include "util.hpp"
#include "RayCaster.h" #include "RayCaster.h"
@ -52,7 +53,7 @@ float elap_time(){
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now(); std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_time = now - start; std::chrono::duration<double> elapsed_time = now - start;
return elapsed_time.count(); return static_cast<float>(elapsed_time.count());
} }
sf::Sprite window_sprite; sf::Sprite window_sprite;
@ -64,299 +65,296 @@ sf::Texture window_texture;
int main() { int main() {
sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML");
CL_Wrapper c; CL_Wrapper c;
//Map m(sf::Vector3i (50, 50, 50)); if (c.compile_kernel("../kernels/ray_caster_kernel.cl", true, "min_kern") < 0) {
//m.generate_octree(); std::cin.get();
return 1; return -1;
}
//sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML");
std::cout << "map...";
//if (c.compile_kernel("../kernels/ray_caster_kernel.cl", true, "min_kern") < 0) { sf::Vector3i map_dim(MAP_X, MAP_Y, MAP_Z);
// std::cin.get(); Old_Map* map = new Old_Map(map_dim);
// return -1; map->generate_terrain();
//}
// c.create_buffer("map_buffer", sizeof(char) * map_dim.x * map_dim.y * map_dim.z, map->get_voxel_data());
//std::cout << "map..."; c.create_buffer("dim_buffer", sizeof(int) * 3, &map_dim);
// sf::Vector3i map_dim(MAP_X, MAP_Y, MAP_Z);
// Map* map = new Map(map_dim); sf::Vector2i view_res(WINDOW_X, WINDOW_Y);
// c.create_buffer("res_buffer", sizeof(int) * 2, &view_res);
//c.create_buffer("map_buffer", sizeof(char) * map_dim.x * map_dim.y * map_dim.z, map->list);
//c.create_buffer("dim_buffer", sizeof(int) * 3, &map_dim);
double y_increment_radians = DegreesToRadians(50.0f / view_res.y);
//sf::Vector2i view_res(WINDOW_X, WINDOW_Y); double x_increment_radians = DegreesToRadians(80.0f / view_res.x);
//c.create_buffer("res_buffer", sizeof(int) * 2, &view_res);
// std::cout << "view matrix...";
// double y_increment_radians = DegreesToRadians(50.0 / view_res.y); sf::Vector4f* view_matrix = new sf::Vector4f[WINDOW_X * WINDOW_Y * 4];
// double x_increment_radians = DegreesToRadians(80.0 / view_res.x);
for (int y = -view_res.y / 2; y < view_res.y / 2; y++) {
//std::cout << "view matrix..."; for (int x = -view_res.x / 2; x < view_res.x / 2; x++) {
//
//sf::Vector4f* view_matrix = new sf::Vector4f[WINDOW_X * WINDOW_Y * 4]; // The base ray direction to slew from
sf::Vector3f ray(1, 0, 0);
// for (int y = -view_res.y / 2; y < view_res.y / 2; y++) {
// for (int x = -view_res.x / 2; x < view_res.x / 2; x++) { // Y axis, pitch
ray = sf::Vector3f(
// // The base ray direction to slew from static_cast<float>(ray.z * sin(y_increment_radians * y) + ray.x * cos(y_increment_radians * y)),
// sf::Vector3f ray(1, 0, 0); static_cast<float>(ray.y),
static_cast<float>(ray.z * cos(y_increment_radians * y) - ray.x * sin(y_increment_radians * y))
// // Y axis, pitch );
// ray = sf::Vector3f(
// ray.z * sin(y_increment_radians * y) + ray.x * cos(y_increment_radians * y),
// ray.y, // Z axis, yaw
// ray.z * cos(y_increment_radians * y) - ray.x * sin(y_increment_radians * y) ray = sf::Vector3f(
// ); static_cast<float>(ray.x * cos(x_increment_radians * x) - ray.y * sin(x_increment_radians * x)),
static_cast<float>(ray.x * sin(x_increment_radians * x) + ray.y * cos(x_increment_radians * x)),
static_cast<float>(ray.z)
// // Z axis, yaw );
// ray = sf::Vector3f(
// ray.x * cos(x_increment_radians * x) - ray.y * sin(x_increment_radians * x), int index = (x + view_res.x / 2) + view_res.x * (y + view_res.y / 2);
// ray.x * sin(x_increment_radians * x) + ray.y * cos(x_increment_radians * x), ray = Normalize(ray);
// ray.z
// ); view_matrix[index] = sf::Vector4f(
// ray.x,
// int index = (x + view_res.x / 2) + view_res.x * (y + view_res.y / 2); ray.y,
// ray = Normalize(ray); ray.z,
0
// view_matrix[index] = sf::Vector4f( );
// ray.x, }
// ray.y, }
// ray.z,
// 0 c.create_buffer("view_matrix_buffer", sizeof(float) * 4 * view_res.x * view_res.y, view_matrix);
// );
// } Camera camera(
// } sf::Vector3f(70, 60, 50),
sf::Vector2f(0.0f, 1.00f)
//c.create_buffer("view_matrix_buffer", sizeof(float) * 4 * view_res.x * view_res.y, view_matrix); );
//Camera camera( c.create_buffer("cam_dir_buffer", sizeof(float) * 4, (void*)camera.get_direction_pointer(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR);
// sf::Vector3f(70, 60, 50), c.create_buffer("cam_pos_buffer", sizeof(float) * 4, (void*)camera.get_position_pointer(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR);
// sf::Vector2f(0.0f, 1.00f)
//); int light_count = 2;
// c.create_buffer("light_count_buffer", sizeof(int), &light_count);
//c.create_buffer("cam_dir_buffer", sizeof(float) * 4, (void*)camera.get_direction_pointer(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR);
//c.create_buffer("cam_pos_buffer", sizeof(float) * 4, (void*)camera.get_position_pointer(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR); // {r, g, b, i, x, y, z, x', y', z'}
// sf::Vector3f v = Normalize(sf::Vector3f(1.0f, 0.0f, 0.0f));
//int light_count = 2; sf::Vector3f v2 = Normalize(sf::Vector3f(1.1f, 0.4f, 0.7f));
//c.create_buffer("light_count_buffer", sizeof(int), &light_count); float light[] = { 0.4f, 0.8f, 0.1f, 1.0f, 50.0f, 50.0f, 50.0f, v.x, v.y, v.z,
0.4f, 0.8f, 0.1f, 1.0f, 50.0f, 50.0f, 50.0f, v2.x, v2.y, v2.z};
//// {r, g, b, i, x, y, z, x', y', z'} c.create_buffer("light_buffer", sizeof(float) * 10 * light_count, light, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR);
//sf::Vector3f v = Normalize(sf::Vector3f(1.0, 0.0, 0.0));
//sf::Vector3f v2 = Normalize(sf::Vector3f(1.1, 0.4, 0.7)); // The drawing canvas
//float light[] = { 0.4, 0.8, 0.1, 1, 50, 50, 50, v.x, v.y, v.z, unsigned char* pixel_array = new sf::Uint8[WINDOW_X * WINDOW_Y * 4];
// 0.4, 0.8, 0.1, 1, 50, 50, 50, v2.x, v2.y, v2.z};
//c.create_buffer("light_buffer", sizeof(float) * 10 * light_count, light, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR); for (int i = 0; i < WINDOW_X * WINDOW_Y * 4; i += 4) {
//// The drawing canvas pixel_array[i] = 255; // R?
// unsigned char* pixel_array = new sf::Uint8[WINDOW_X * WINDOW_Y * 4]; pixel_array[i + 1] = 255; // G?
pixel_array[i + 2] = 255; // B?
// for (int i = 0; i < WINDOW_X * WINDOW_Y * 4; i += 4) { pixel_array[i + 3] = 100; // A?
}
// pixel_array[i] = 255; // R?
// pixel_array[i + 1] = 255; // G? sf::Texture t;
// pixel_array[i + 2] = 255; // B? t.create(WINDOW_X, WINDOW_Y);
// pixel_array[i + 3] = 100; // A? t.update(pixel_array);
// }
int error;
//sf::Texture t; cl_mem image_buff = clCreateFromGLTexture(
// t.create(WINDOW_X, WINDOW_Y); c.getContext(), CL_MEM_WRITE_ONLY, GL_TEXTURE_2D,
// t.update(pixel_array); 0, t.getNativeHandle(), &error);
// int error; if (c.assert(error, "clCreateFromGLTexture"))
// cl_mem image_buff = clCreateFromGLTexture( return -1;
// c.getContext(), CL_MEM_WRITE_ONLY, GL_TEXTURE_2D,
// 0, t.getNativeHandle(), &error); c.store_buffer(image_buff, "image_buffer");
// if (c.assert(error, "clCreateFromGLTexture")) c.set_kernel_arg("min_kern", 0, "map_buffer");
// return -1; c.set_kernel_arg("min_kern", 1, "dim_buffer");
c.set_kernel_arg("min_kern", 2, "res_buffer");
// c.store_buffer(image_buff, "image_buffer"); c.set_kernel_arg("min_kern", 3, "view_matrix_buffer");
c.set_kernel_arg("min_kern", 4, "cam_dir_buffer");
// c.set_kernel_arg("min_kern", 0, "map_buffer"); c.set_kernel_arg("min_kern", 5, "cam_pos_buffer");
// c.set_kernel_arg("min_kern", 1, "dim_buffer"); c.set_kernel_arg("min_kern", 6, "light_buffer");
// c.set_kernel_arg("min_kern", 2, "res_buffer"); c.set_kernel_arg("min_kern", 7, "light_count_buffer");
// c.set_kernel_arg("min_kern", 3, "view_matrix_buffer"); c.set_kernel_arg("min_kern", 8, "image_buffer");
// c.set_kernel_arg("min_kern", 4, "cam_dir_buffer");
// c.set_kernel_arg("min_kern", 5, "cam_pos_buffer"); sf::Sprite s;
//c.set_kernel_arg("min_kern", 6, "light_buffer"); s.setTexture(t);
//c.set_kernel_arg("min_kern", 7, "light_count_buffer"); s.setPosition(0, 0);
//c.set_kernel_arg("min_kern", 8, "image_buffer");
// The step size in milliseconds between calls to Update()
//sf::Sprite s; // Lets set it to 16.6 milliseonds (60FPS)
//s.setTexture(t); float step_size = 0.0166f;
//s.setPosition(0, 0);
// Timekeeping values for the loop
// // The step size in milliseconds between calls to Update() double frame_time = 0.0,
// // Lets set it to 16.6 milliseonds (60FPS) elapsed_time = 0.0,
// float step_size = 0.0166f; delta_time = 0.0,
accumulator_time = 0.0,
// // Timekeeping values for the loop current_time = 0.0;
// double frame_time = 0.0,
// elapsed_time = 0.0, fps_counter fps;
// delta_time = 0.0,
// accumulator_time = 0.0, // ============================= RAYCASTER SETUP ==================================
// current_time = 0.0;
// Setup the sprite and texture
// fps_counter fps; window_texture.create(WINDOW_X, WINDOW_Y);
window_sprite.setPosition(0, 0);
//// ============================= RAYCASTER SETUP ==================================
// State values
//// Setup the sprite and texture
//window_texture.create(WINDOW_X, WINDOW_Y); sf::Vector3f cam_vec(0, 0, 0);
//window_sprite.setPosition(0, 0);
//// State values
//sf::Vector3f cam_vec(0, 0, 0);
//RayCaster ray_caster(map, map_dim, view_res); //RayCaster ray_caster(map, map_dim, view_res);
//sf::Vector2f *dp = camera.get_direction_pointer(); sf::Vector2f *dp = camera.get_direction_pointer();
//debug_text cam_text_x(1, 30, &dp->x, "X: "); debug_text cam_text_x(1, 30, &dp->x, "X: ");
//debug_text cam_text_y(2, 30, &dp->y, "Y: "); debug_text cam_text_y(2, 30, &dp->y, "Y: ");
//sf::Vector3f *mp = camera.get_movement_pointer(); sf::Vector3f *mp = camera.get_movement_pointer();
//debug_text cam_text_mov_x(4, 30, &mp->x, "X: "); debug_text cam_text_mov_x(4, 30, &mp->x, "X: ");
//debug_text cam_text_mov_y(5, 30, &mp->y, "Y: "); debug_text cam_text_mov_y(5, 30, &mp->y, "Y: ");
//debug_text cam_text_mov_z(6, 30, &mp->y, "Z: "); debug_text cam_text_mov_z(6, 30, &mp->y, "Z: ");
////debug_text cam_text_z(3, 30, &p->z); //debug_text cam_text_z(3, 30, &p->z);
//debug_text light_x(7, 30, &light[7], "X: "); debug_text light_x(7, 30, &light[7], "X: ");
//debug_text light_y(8, 30, &light[8], "Y: "); debug_text light_y(8, 30, &light[8], "Y: ");
//debug_text light_z(9, 30, &light[9], "Z: "); debug_text light_z(9, 30, &light[9], "Z: ");
//// =============================================================================== // ===============================================================================
//// Mouse capture // Mouse capture
//sf::Vector2i deltas; sf::Vector2i deltas;
//sf::Vector2i fixed(window.getSize()); sf::Vector2i fixed(window.getSize());
//bool mouse_enabled = true; bool mouse_enabled = true;
//sf::Vector3f cam_mov_vec; sf::Vector3f cam_mov_vec;
//while (window.isOpen()) { while (window.isOpen()) {
// // Poll for events from the user // Poll for events from the user
// sf::Event event; sf::Event event;
// while (window.pollEvent(event)) { while (window.pollEvent(event)) {
// // If the user tries to exit the application via the GUI // If the user tries to exit the application via the GUI
// if (event.type == sf::Event::Closed) if (event.type == sf::Event::Closed)
// window.close(); window.close();
// if (event.type == sf::Event::KeyPressed) { if (event.type == sf::Event::KeyPressed) {
// if (event.key.code == sf::Keyboard::Space) { if (event.key.code == sf::Keyboard::Space) {
// if (mouse_enabled) if (mouse_enabled)
// mouse_enabled = false; mouse_enabled = false;
// else else
// mouse_enabled = true; mouse_enabled = true;
// } }
// } }
// } }
// cam_vec.x = 0; cam_vec.x = 0;
// cam_vec.y = 0; cam_vec.y = 0;
// cam_vec.z = 0; cam_vec.z = 0;
// float speed = 1.0f; float speed = 1.0f;
// if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) {
// speed = 0.2f; speed = 0.2f;
// } }
// if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) {
// camera.add_relative_impulse(Camera::DIRECTION::DOWN, speed); camera.add_relative_impulse(Camera::DIRECTION::DOWN, speed);
// } }
// if (sf::Keyboard::isKeyPressed(sf::Keyboard::E)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::E)) {
// camera.add_relative_impulse(Camera::DIRECTION::UP, speed); camera.add_relative_impulse(Camera::DIRECTION::UP, speed);
// } }
// if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
// camera.add_relative_impulse(Camera::DIRECTION::FORWARD, speed); camera.add_relative_impulse(Camera::DIRECTION::FORWARD, speed);
// } }
// if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
// camera.add_relative_impulse(Camera::DIRECTION::REARWARD, speed); camera.add_relative_impulse(Camera::DIRECTION::REARWARD, speed);
// } }
// if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
// camera.add_relative_impulse(Camera::DIRECTION::LEFT, speed); camera.add_relative_impulse(Camera::DIRECTION::LEFT, speed);
// } }
// if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
// camera.add_relative_impulse(Camera::DIRECTION::RIGHT, speed); camera.add_relative_impulse(Camera::DIRECTION::RIGHT, speed);
// } }
// if (sf::Keyboard::isKeyPressed(sf::Keyboard::T)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::T)) {
// camera.set_position(sf::Vector3f(50, 50, 50)); camera.set_position(sf::Vector3f(50, 50, 50));
// } }
// camera.add_static_impulse(cam_vec); camera.add_static_impulse(cam_vec);
// if (mouse_enabled) { if (mouse_enabled) {
// deltas = fixed - sf::Mouse::getPosition(); deltas = fixed - sf::Mouse::getPosition();
// if (deltas != sf::Vector2i(0, 0) && mouse_enabled == true) { if (deltas != sf::Vector2i(0, 0) && mouse_enabled == true) {
// // Mouse movement // Mouse movement
// sf::Mouse::setPosition(fixed); sf::Mouse::setPosition(fixed);
// camera.slew_camera(sf::Vector2f( camera.slew_camera(sf::Vector2f(
// deltas.y / 300.0f, deltas.y / 300.0f,
// deltas.x / 300.0f deltas.x / 300.0f
// )); ));
// } }
// } }
// // Time keeping // Time keeping
// elapsed_time = elap_time(); elapsed_time = elap_time();
// delta_time = elapsed_time - current_time; delta_time = elapsed_time - current_time;
// current_time = elapsed_time; current_time = elapsed_time;
// if (delta_time > 0.2f) if (delta_time > 0.2f)
// delta_time = 0.2f; delta_time = 0.2f;
// accumulator_time += delta_time; accumulator_time += delta_time;
// while ((accumulator_time - step_size) >= step_size) { while ((accumulator_time - step_size) >= step_size) {
// accumulator_time -= step_size; accumulator_time -= step_size;
// // ==== DELTA TIME LOCKED ==== // ==== DELTA TIME LOCKED ====
// } }
// float l[] = { float l[] = {
// light[9] * sin(delta_time / 1) + light[7] * cos(delta_time / 1), static_cast<float>(light[9] * sin(delta_time / 1) + light[7] * cos(delta_time / 1)),
// light[8], static_cast<float>(light[8]),
// light[9] * cos(delta_time / 1) - light[7] * sin(delta_time / 1) static_cast<float>(light[9] * cos(delta_time / 1) - light[7] * sin(delta_time / 1))
// }; };
// float l2[] = { float l2[] = {
// l[0] * cos(delta_time) - l[2] * sin(delta_time), static_cast<float>(l[0] * cos(delta_time) - l[2] * sin(delta_time)),
// l[0] * sin(delta_time) + l[2] * cos(delta_time), static_cast<float>(l[0] * sin(delta_time) + l[2] * cos(delta_time)),
// l[2] static_cast<float>(l[2])
// }; };
// light[7] = l[0]; light[7] = l[0];
// light[8] = l[1]; light[8] = l[1];
// light[9] = l[2]; light[9] = l[2];
// // ==== FPS LOCKED ==== // ==== FPS LOCKED ====
// camera.update(delta_time); camera.update(delta_time);
// // Run the raycast // Run the raycast
// c.run_kernel("min_kern", WORK_SIZE); c.run_kernel("min_kern", WORK_SIZE);
//
// // ==== RENDER ==== // ==== RENDER ====
// window.clear(sf::Color::Black); window.clear(sf::Color::Black);
// window.draw(s); window.draw(s);
// // Give the frame counter the frame time and draw the average frame time // Give the frame counter the frame time and draw the average frame time
// fps.frame(delta_time); fps.frame(delta_time);
// fps.draw(&window); fps.draw(&window);
// cam_text_x.draw(&window); cam_text_x.draw(&window);
// cam_text_y.draw(&window); cam_text_y.draw(&window);
// cam_text_mov_x.draw(&window); cam_text_mov_x.draw(&window);
// cam_text_mov_y.draw(&window); cam_text_mov_y.draw(&window);
// cam_text_mov_z.draw(&window); cam_text_mov_z.draw(&window);
// light_x.draw(&window); light_x.draw(&window);
// light_y.draw(&window); light_y.draw(&window);
// light_z.draw(&window); light_z.draw(&window);
//
// window.display(); window.display();
//} }
return 0; return 0;
} }

Loading…
Cancel
Save