Various tweaks and modifications

Some preliminary testing of map
This commit is contained in:
MitchellHansen
2016-12-10 01:12:30 -08:00
parent c98adefa3a
commit 51a08fc0bb
11 changed files with 296 additions and 48 deletions

View File

@@ -71,11 +71,11 @@ int Camera::update(double delta_time) {
// have to do it component wise
double multiplier = 40;
position.x += movement.x * delta_time * multiplier;
position.y += movement.y * delta_time * multiplier;
position.z += movement.z * delta_time * multiplier;
position.x += static_cast<float>(movement.x * delta_time * multiplier);
position.y += static_cast<float>(movement.y * delta_time * multiplier);
position.z += static_cast<float>(movement.z * delta_time * multiplier);
movement *= (float)(friction_coefficient * delta_time * multiplier);
movement *= static_cast<float>(friction_coefficient * delta_time * multiplier);
return 1;
}

View File

@@ -4,10 +4,10 @@ GL_Testing::GL_Testing() {
GLfloat tmp[] = {
1, 0, 0, 0,
0, cos(1), sin(1), 0,
0, -sin(1), cos(1), 0,
0, 0, 0, 1
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, static_cast<float>(cos(1.0f)), static_cast<float>(sin(1.0f)), 0.0f,
0.0f, static_cast<float>(-sin(1.0f)), static_cast<float>(cos(1.0f)), 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
@@ -132,10 +132,10 @@ void GL_Testing::rotate(double delta) {
GLfloat tmp[] = {
1, 0, 0, 0,
0, cos(counter), sin(counter), 0,
0, -sin(counter), cos(counter), 0,
0, 0, 0, 1
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, static_cast<float>(cos(counter)), static_cast<float>(sin(counter)), 0.0f,
0.0f, static_cast<float>(-sin(counter)), static_cast<float>(cos(counter)), 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};

View File

@@ -37,9 +37,10 @@ int Hardware_Caster::init() {
}
srand(NULL);
int seed = rand();
create_buffer("seed", sizeof(int), &seed);
int *seed_memory = new int[1920*1080];
create_buffer("seed", sizeof(int) * 1920 * 1080, seed_memory);
return 1;
@@ -87,7 +88,7 @@ void Hardware_Caster::validate()
set_kernel_arg("raycaster", 8, "image");
set_kernel_arg("raycaster", 9, "seed");
print_kernel_arguments();
//print_kernel_arguments();
}
@@ -180,7 +181,7 @@ void Hardware_Caster::assign_lights(std::vector<Light> lights) {
this->lights = std::vector<Light>(lights);
light_count = lights.size();
light_count = static_cast<int>(lights.size());
create_buffer("lights", sizeof(float) * 10 * light_count, this->lights.data(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR);
@@ -229,7 +230,7 @@ int Hardware_Caster::acquire_platform_and_device() {
if (assert(error, "clGetDeviceIDs"))
return OPENCL_ERROR;
for (int q = 0; q < deviceIdCount; q++) {
for (unsigned int q = 0; q < deviceIdCount; q++) {
device d;

View File

@@ -1,8 +1,63 @@
#include "Map.h"
// root
//
// a1
// a2
//
// b1
// b1
//
// c1
// c1
//
// a2
// a2
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
Map::Map(sf::Vector3i position) {
load_unload(position);
for (int i = 0; i < 8192; i++) {
block[i] = 0;
}
}
int BitCount(unsigned int u) {
@@ -12,6 +67,30 @@ int BitCount(unsigned int u) {
return ((uCount + (uCount >> 3)) & 030707070707) % 63;
}
void SetBit(int position, char* c) {
*c |= 1 << position;
}
void FlipBit(int position, char* c) {
*c ^= 1 << position;
}
int GetBit(int position, char* c) {
return (*c >> position) & 1;
}
void SetBit(int position, int64_t* c) {
*c |= 1 << position;
}
void FlipBit(int position, int64_t* c) {
*c ^= 1 << position;
}
int GetBit(int position, int64_t* c) {
return (*c >> position) & 1;
}
struct leaf {
leaf *children;
char leaf_mask;
@@ -24,6 +103,103 @@ struct block {
double* data = new double[1000];
};
int64_t generate_children_at_raw() {
int64_t t;
// count the raw data and insert via bit masks or whatever into the valid field
// Set the child pointer blank and the leaf mask blank as well
// Return the single value
return t;
}
int64_t Map::generate_children(sf::Vector3i pos, int dim) {
sf::Vector3i t1 = sf::Vector3i(pos.x, pos.y, pos.z);
sf::Vector3i t2 = sf::Vector3i(pos.x + dim, pos.y, pos.z);
sf::Vector3i t3 = sf::Vector3i(pos.x, pos.y + dim, pos.z);
sf::Vector3i t4 = sf::Vector3i(pos.x + dim, pos.y + dim, pos.z);
sf::Vector3i t5 = sf::Vector3i(pos.x, pos.y, pos.z + dim);
sf::Vector3i t6 = sf::Vector3i(pos.x + dim, pos.y, pos.z + dim);
sf::Vector3i t7 = sf::Vector3i(pos.x, pos.y + dim, pos.z + dim);
sf::Vector3i t8 = sf::Vector3i(pos.x + dim, pos.y + dim, pos.z + dim);
std::vector<int64_t> cps;
int64_t tmp = 0;
if (dim == 1) {
if (getVoxel(t1))
SetBit(16, &tmp);
if (getVoxel(t2))
SetBit(16, &tmp);
if (getVoxel(t3))
SetBit(16, &tmp);
if (getVoxel(t4))
SetBit(16, &tmp);
if (getVoxel(t5))
SetBit(16, &tmp);
if (getVoxel(t6))
SetBit(16, &tmp);
if (getVoxel(t7))
SetBit(16, &tmp);
if (getVoxel(t8))
SetBit(16, &tmp);
cps.push_back(tmp);
}
else {
// Generate all 8 sub trees accounting for each of their unique positions
int curr_stack_pos = stack_position;
tmp = generate_children(t1, dim / 2);
if (tmp != 0)
cps.push_back(tmp);
tmp = generate_children(t2, dim / 2);
if (tmp != 0)
cps.push_back(tmp);
tmp = generate_children(t3, dim / 2);
if (tmp != 0)
cps.push_back(tmp);
tmp = generate_children(t4, dim / 2);
if (tmp != 0)
cps.push_back(tmp);
tmp = generate_children(t5, dim / 2);
if (tmp != 0)
cps.push_back(tmp);
tmp = generate_children(t6, dim / 2);
if (tmp != 0)
cps.push_back(tmp);
tmp = generate_children(t7, dim / 2);
if (tmp != 0)
cps.push_back(tmp);
tmp = generate_children(t8, dim / 2);
if (tmp != 0)
cps.push_back(tmp);
}
memcpy(&block[stack_position], cps.data(), cps.size() * sizeof(int64_t));
stack_position += cps.size();
return 0;
}
void Map::generate_octree() {
@@ -34,19 +210,40 @@ void Map::generate_octree() {
int* dataset = new int[32 * 32 * 32];
for (int i = 0; i < 32 * 32 * 32; i++) {
dataset[0] = i;
dataset[0] = rand() % 2;
}
int level = static_cast<int>(log2(32));
// levels defines how many levels to traverse before we hit raw data
// Will be the map width I presume. Will still need to handle how to swap in and out data.
// Possible have some upper static nodes that will stay full regardless of contents?
int levels = static_cast<int>(log2(64));
leaf top_node;
top_node.level = level;
for (int i = 0; i < 16 * 16 * 16; i++) {
for (int i = 0; i < 8 * 8 * 8; i++) {
for (int i = 0; i < 4 * 4 * 4; i++) {
int t_level = -1;
int b_level = 0;
for (int i1 = 0; i1 < 2 * 2 * 2; i1++) {
int b_level = 1;
for (int i2 = 0; i2 < 2 * 2 * 2; i2++) {
int b_level = 2;
for (int i3 = 0; i3 < 2 * 2 * 2; i3++) {
int b_level = 3;
leaf l1;
l1.children = nullptr;
l1.leaf_mask = 0;
l1.valid_mask = 0;
for (int i = 0; i < 2 * 2 * 2; i++) {
//int x =
//if (dataset[]
}
}
}
@@ -127,6 +324,11 @@ void Map::setVoxel(sf::Vector3i world_position, int val) {
}
char Map::getVoxel(sf::Vector3i pos){
return voxel_data[pos.x + OCT_DIM * (pos.y + OCT_DIM * pos.z)];
}
void Chunk::set(int type) {
for (int i = 0; i < CHUNK_DIM * CHUNK_DIM * CHUNK_DIM; i++) {
voxel_data[i] = 0;

View File

@@ -136,14 +136,14 @@ void Old_Map::generate_terrain() {
}
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;
}
}
}
//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;
// }
// }
//}
}

View File

@@ -130,20 +130,12 @@ sf::Color Ray::Cast() {
alpha *= 162;
switch (voxel_data) {
case 1:
// AngleBew0 - 1.57 * 162 = 0 - 255
return sf::Color(255, 0, 0, alpha);
case 2:
return sf::Color(255, 10, 0, alpha);
case 3:
return sf::Color(255, 0, 255, alpha);
case 4:
return sf::Color(80, 0, 150, alpha);
case 5:
return sf::Color(255, 120, 255, alpha);
case 6:
return sf::Color(150, 80, 220, alpha);
default:
return sf::Color(150, 80, 220, alpha);
}
dist++;

View File

@@ -1,5 +1,6 @@
#include "GL_Testing.h"
#include <vulkan/vulkan.h>
#include <vulkan/vk_sdk_platform.h>
#ifdef linux
#include <CL/cl.h>
#include <CL/opencl.h>
@@ -66,6 +67,15 @@ sf::Texture window_texture;
int main() {
Map _map(sf::Vector3i(0, 0, 0));
_map.generate_octree();
glewInit();
sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML");
GL_Testing t;