And also made the camera react to gravity, not fall through the floor
This commit is contained in:
@@ -41,10 +41,10 @@ class CLCaster;
|
|||||||
class Application {
|
class Application {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const int WINDOW_X = 1366;
|
// static const int WINDOW_X = 1366;
|
||||||
static const int WINDOW_Y = 768;
|
// static const int WINDOW_Y = 768;
|
||||||
// static const int WINDOW_X = 1920;
|
static const int WINDOW_X = 1920;
|
||||||
// static const int WINDOW_Y = 1080;
|
static const int WINDOW_Y = 1080;
|
||||||
static const int MAP_X;
|
static const int MAP_X;
|
||||||
static const int MAP_Y;
|
static const int MAP_Y;
|
||||||
static const int MAP_Z;
|
static const int MAP_Z;
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
float friction_coefficient = 0.1f;
|
float friction_coefficient = 0.001f;
|
||||||
float default_impulse = 0.3f;
|
float default_impulse = 0.1f;
|
||||||
|
|
||||||
// 3D vector
|
// 3D vector
|
||||||
sf::Vector3f movement;
|
sf::Vector3f movement;
|
||||||
|
|||||||
@@ -466,21 +466,21 @@ __kernel void raycaster(
|
|||||||
constant int vox_dim = OCTDIM;
|
constant int vox_dim = OCTDIM;
|
||||||
|
|
||||||
// If we hit a voxel
|
// If we hit a voxel
|
||||||
if (voxel.x < (*map_dim).x && voxel.y < (*map_dim).x && voxel.z < (*map_dim).x){
|
// if (voxel.x < (*map_dim).x && voxel.y < (*map_dim).x && voxel.z < (*map_dim).x){
|
||||||
if (get_oct_vox(
|
// if (get_oct_vox(
|
||||||
voxel,
|
// voxel,
|
||||||
octree_descriptor_buffer,
|
// octree_descriptor_buffer,
|
||||||
octree_attachment_lookup_buffer,
|
// octree_attachment_lookup_buffer,
|
||||||
octree_attachment_buffer,
|
// octree_attachment_buffer,
|
||||||
settings_buffer
|
// settings_buffer
|
||||||
)){
|
// )){
|
||||||
voxel_data = 5;
|
// voxel_data = 5;
|
||||||
} else {
|
// } else {
|
||||||
voxel_data = 0;
|
// voxel_data = 0;
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
voxel_data = map[voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * (voxel.z))];
|
voxel_data = map[voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * (voxel.z))];
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,12 @@ CLCaster::~CLCaster() {
|
|||||||
//release_map();
|
//release_map();
|
||||||
//release_camera();
|
//release_camera();
|
||||||
//release_octree();
|
//release_octree();
|
||||||
release_viewport();
|
//clReleaseKernel(kernel_map.at("raycaster"));
|
||||||
|
// clReleaseProgram()
|
||||||
|
//release_viewport();
|
||||||
|
|
||||||
delete[] viewport_matrix;
|
delete[] viewport_matrix;
|
||||||
|
delete[] viewport_image;
|
||||||
delete[] viewport_image;
|
delete[] viewport_image;
|
||||||
|
|
||||||
camera.reset();
|
camera.reset();
|
||||||
@@ -864,7 +867,6 @@ bool CLCaster::release_buffer(std::string buffer_name) {
|
|||||||
|
|
||||||
if (buffer_map.count(buffer_name) > 0) {
|
if (buffer_map.count(buffer_name) > 0) {
|
||||||
|
|
||||||
clFinish(command_queue);
|
|
||||||
int error = clReleaseMemObject(buffer_map.at(buffer_name));
|
int error = clReleaseMemObject(buffer_map.at(buffer_name));
|
||||||
|
|
||||||
if (cl_assert(error)) {
|
if (cl_assert(error)) {
|
||||||
|
|||||||
@@ -53,7 +53,9 @@ int Camera::add_relative_impulse(DIRECTION impulse_direction, float speed) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float val = movement.z;
|
||||||
movement += SphereToCart(dir) * speed;
|
movement += SphereToCart(dir) * speed;
|
||||||
|
movement.z = val;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -79,8 +81,16 @@ int Camera::update(double delta_time) {
|
|||||||
position.y += static_cast<float>(movement.y * delta_time * multiplier);
|
position.y += static_cast<float>(movement.y * delta_time * multiplier);
|
||||||
position.z += static_cast<float>(movement.z * delta_time * multiplier);
|
position.z += static_cast<float>(movement.z * delta_time * multiplier);
|
||||||
|
|
||||||
movement *= static_cast<float>(friction_coefficient * delta_time * multiplier);
|
movement.x *= static_cast<float>(friction_coefficient * delta_time * multiplier);
|
||||||
|
movement.y *= static_cast<float>(friction_coefficient * delta_time * multiplier);
|
||||||
|
|
||||||
|
if (position.z < 3.0f){
|
||||||
|
position.z = 3.0f;
|
||||||
|
movement.z = -0.1;
|
||||||
|
} else {
|
||||||
|
// gravity
|
||||||
|
movement.z -= 0.7f * delta_time;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +127,8 @@ void Camera::recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Even
|
|||||||
else if (held_event->code == sf::Keyboard::D) {
|
else if (held_event->code == sf::Keyboard::D) {
|
||||||
add_relative_impulse(Camera::DIRECTION::RIGHT, default_impulse);
|
add_relative_impulse(Camera::DIRECTION::RIGHT, default_impulse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (event->type == vr::Event::KeyPressed) {
|
else if (event->type == vr::Event::KeyPressed) {
|
||||||
@@ -128,6 +140,8 @@ void Camera::recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Even
|
|||||||
mouse_enabled = false;
|
mouse_enabled = false;
|
||||||
else
|
else
|
||||||
mouse_enabled = true;
|
mouse_enabled = true;
|
||||||
|
} else if (key_event->code == sf::Keyboard::Space) {
|
||||||
|
movement.z = 0.25f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,20 +212,20 @@ void Camera::render_gui() {
|
|||||||
|
|
||||||
ImGui::Begin("Camera");
|
ImGui::Begin("Camera");
|
||||||
|
|
||||||
ImGui::Columns(2);
|
ImGui::Columns(2);
|
||||||
|
|
||||||
ImGui::Text("Camera Inclination");
|
ImGui::Text("Camera Inclination");
|
||||||
ImGui::Text("Camera Azimuth");
|
ImGui::Text("Camera Azimuth");
|
||||||
ImGui::Text("Camera Pos_X");
|
ImGui::Text("Camera Pos_X");
|
||||||
ImGui::Text("Camera Poz_Y");
|
ImGui::Text("Camera Poz_Y");
|
||||||
ImGui::Text("Camera Poz_Z");
|
ImGui::Text("Camera Poz_Z");
|
||||||
|
|
||||||
ImGui::NextColumn();
|
ImGui::NextColumn();
|
||||||
|
|
||||||
ImGui::Text("%f", direction.x);
|
ImGui::Text("%f", direction.x);
|
||||||
ImGui::Text("%f", direction.y);
|
ImGui::Text("%f", direction.y);
|
||||||
ImGui::Text("%f", position.x);
|
ImGui::Text("%f", position.x);
|
||||||
ImGui::Text("%f", position.y);
|
ImGui::Text("%f", position.y);
|
||||||
ImGui::Text("%f", position.z);
|
ImGui::Text("%f", position.z);
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|||||||
Reference in New Issue
Block a user