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 {
|
||||
|
||||
public:
|
||||
static const int WINDOW_X = 1366;
|
||||
static const int WINDOW_Y = 768;
|
||||
// static const int WINDOW_X = 1920;
|
||||
// static const int WINDOW_Y = 1080;
|
||||
// static const int WINDOW_X = 1366;
|
||||
// static const int WINDOW_Y = 768;
|
||||
static const int WINDOW_X = 1920;
|
||||
static const int WINDOW_Y = 1080;
|
||||
static const int MAP_X;
|
||||
static const int MAP_Y;
|
||||
static const int MAP_Z;
|
||||
|
||||
@@ -47,8 +47,8 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
float friction_coefficient = 0.1f;
|
||||
float default_impulse = 0.3f;
|
||||
float friction_coefficient = 0.001f;
|
||||
float default_impulse = 0.1f;
|
||||
|
||||
// 3D vector
|
||||
sf::Vector3f movement;
|
||||
|
||||
@@ -466,21 +466,21 @@ __kernel void raycaster(
|
||||
constant int vox_dim = OCTDIM;
|
||||
|
||||
// If we hit a voxel
|
||||
if (voxel.x < (*map_dim).x && voxel.y < (*map_dim).x && voxel.z < (*map_dim).x){
|
||||
if (get_oct_vox(
|
||||
voxel,
|
||||
octree_descriptor_buffer,
|
||||
octree_attachment_lookup_buffer,
|
||||
octree_attachment_buffer,
|
||||
settings_buffer
|
||||
)){
|
||||
voxel_data = 5;
|
||||
} else {
|
||||
voxel_data = 0;
|
||||
}
|
||||
} else {
|
||||
// if (voxel.x < (*map_dim).x && voxel.y < (*map_dim).x && voxel.z < (*map_dim).x){
|
||||
// if (get_oct_vox(
|
||||
// voxel,
|
||||
// octree_descriptor_buffer,
|
||||
// octree_attachment_lookup_buffer,
|
||||
// octree_attachment_buffer,
|
||||
// settings_buffer
|
||||
// )){
|
||||
// voxel_data = 5;
|
||||
// } else {
|
||||
// voxel_data = 0;
|
||||
// }
|
||||
// } else {
|
||||
voxel_data = map[voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * (voxel.z))];
|
||||
}
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,9 +7,12 @@ CLCaster::~CLCaster() {
|
||||
//release_map();
|
||||
//release_camera();
|
||||
//release_octree();
|
||||
release_viewport();
|
||||
//clReleaseKernel(kernel_map.at("raycaster"));
|
||||
// clReleaseProgram()
|
||||
//release_viewport();
|
||||
|
||||
delete[] viewport_matrix;
|
||||
delete[] viewport_image;
|
||||
delete[] viewport_image;
|
||||
|
||||
camera.reset();
|
||||
@@ -864,7 +867,6 @@ bool CLCaster::release_buffer(std::string buffer_name) {
|
||||
|
||||
if (buffer_map.count(buffer_name) > 0) {
|
||||
|
||||
clFinish(command_queue);
|
||||
int error = clReleaseMemObject(buffer_map.at(buffer_name));
|
||||
|
||||
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.z = val;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -79,8 +81,16 @@ int Camera::update(double delta_time) {
|
||||
position.y += static_cast<float>(movement.y * 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;
|
||||
}
|
||||
|
||||
@@ -117,6 +127,8 @@ void Camera::recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Even
|
||||
else if (held_event->code == sf::Keyboard::D) {
|
||||
add_relative_impulse(Camera::DIRECTION::RIGHT, default_impulse);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
else
|
||||
mouse_enabled = true;
|
||||
} else if (key_event->code == sf::Keyboard::Space) {
|
||||
movement.z = 0.25f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user