added relative camera controls, now handles like an actual fly cam.

This commit is contained in:
MitchellHansen
2016-09-22 21:48:38 -07:00
parent 92aee8c4ca
commit e13280bb07
7 changed files with 185 additions and 35 deletions

View File

@@ -59,7 +59,9 @@ int CL_Wrapper::acquire_platform_and_device(){
// falling back to the cpu with the fastest clock if we weren't able to find one
device current_best_device;
current_best_device.type = -1; // Set this to -1 so the first run always selects a new device
current_best_device.type = 0; // Set this to 0 so the first run always selects a new device
current_best_device.clock_frequency = 0;
current_best_device.comp_units = 0;
for (auto kvp: plt_ids){
@@ -86,7 +88,7 @@ int CL_Wrapper::acquire_platform_and_device(){
platform_id = current_best_device.platform;
device_id = current_best_device.id;
return 0;
return 1;
};
int CL_Wrapper::create_shared_context() {
@@ -272,7 +274,6 @@ int CL_Wrapper::store_buffer(cl_mem buffer, std::string buffer_name){
int CL_Wrapper::run_kernel(std::string kernel_name, const int work_size){
const int WORKER_SIZE = 10;
size_t global_work_size[1] = { static_cast<size_t>(work_size) };
cl_kernel kernel = kernel_map.at(kernel_name);

View File

@@ -19,15 +19,42 @@ int Camera::set_position(sf::Vector3f position) {
this->position = position;
return 1;
}
int Camera::add_static_impulse(sf::Vector3f impulse) {
movement += impulse;
return 1;
}
int Camera::add_relative_impulse(DIRECTION impulse_direction) {
// No sense in doing fancy dot products, adding Pi's will suffice
// Always add PI/2 to X initially to avoid negative case
sf::Vector2f dir;
SphereToCart(direction);
switch (impulse_direction) {
case DIRECTION::UP:
dir = sf::Vector2f(direction.y, direction.x + PI);
break;
case DIRECTION::DOWN:
dir = sf::Vector2f(direction.y, direction.x);
break;
case DIRECTION::LEFT:
dir = sf::Vector2f(direction.y + PI + PI / 2, PI / 2);
break;
case DIRECTION::RIGHT:
dir = sf::Vector2f(direction.y + PI / 2, PI / 2);
break;
case DIRECTION::FORWARD:
dir = sf::Vector2f(direction.y, direction.x + PI / 2);
break;
case DIRECTION::REARWARD:
dir = sf::Vector2f(direction.y + PI, (direction.x * -1) + PI / 2 );
break;
}
movement += SphereToCart(dir);
return 1;
}
@@ -37,20 +64,30 @@ int Camera::slew_camera(sf::Vector2f input) {
return 1;
}
int Camera::update() {
int Camera::update(double delta_time) {
position += movement;
// so vector multiplication broke?
// have to do it component wise
double multiplier = 50;
position.x += movement.x * delta_time * multiplier;
position.y += movement.y * delta_time * multiplier;
position.z += movement.z * delta_time * multiplier;
movement *= friction_coefficient;
movement *= (float)(friction_coefficient * delta_time * multiplier);
return 1;
}
void* Camera::get_direction_pointer() {
sf::Vector2f* Camera::get_direction_pointer() {
return &direction;
}
void* Camera::get_position_pointer() {
sf::Vector3f* Camera::get_movement_pointer() {
return &movement;
}
sf::Vector3f* Camera::get_position_pointer() {
return &position;
}

View File

@@ -22,9 +22,6 @@ void Map::moveLight(sf::Vector2f in) {
}
//void Map::GenerateFloor(){
//}

View File

@@ -65,6 +65,12 @@ sf::Texture window_texture;
int main() {
//Map m(sf::Vector3i (50, 50, 50));
//return 1;
sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML");
@@ -137,8 +143,8 @@ int main() {
sf::Vector2f(0.0f, 1.00f)
);
c.create_buffer("cam_dir_buffer", sizeof(float) * 4, camera.get_direction_pointer(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR);
c.create_buffer("cam_pos_buffer", sizeof(float) * 4, camera.get_position_pointer(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR);
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'}
float light[] = { 0.4, 0.8, 0.1, 1, 50, 50, 50, 1.1, 0.4, 0.7};
@@ -211,7 +217,15 @@ int main() {
RayCaster ray_caster(map, map_dim, view_res);
sf::Vector2f *dp = camera.get_direction_pointer();
debug_text cam_text_x(1, 30, &dp->x, "X: ");
debug_text cam_text_y(2, 30, &dp->y, "Y: ");
sf::Vector3f *mp = camera.get_movement_pointer();
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_z(6, 30, &mp->y, "Z: ");
//debug_text cam_text_z(3, 30, &p->z);
// ===============================================================================
// Mouse capture
@@ -245,22 +259,25 @@ int main() {
cam_vec.z = 0;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) {
cam_vec.z = 1;
camera.add_relative_impulse(Camera::DIRECTION::DOWN);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::E)) {
cam_vec.z = -1;
camera.add_relative_impulse(Camera::DIRECTION::UP);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
cam_vec.y = 1;
camera.add_relative_impulse(Camera::DIRECTION::FORWARD);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
cam_vec.y = -1;
camera.add_relative_impulse(Camera::DIRECTION::REARWARD);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
cam_vec.x = 1;
camera.add_relative_impulse(Camera::DIRECTION::LEFT);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
cam_vec.x = -1;
camera.add_relative_impulse(Camera::DIRECTION::RIGHT);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::T)) {
camera.set_position(sf::Vector3f(20, 20, 20));
}
camera.add_static_impulse(cam_vec);
@@ -288,13 +305,12 @@ int main() {
while ((accumulator_time - step_size) >= step_size) {
accumulator_time -= step_size;
// ==== DELTA TIME LOCKED ====
camera.update();
}
// ==== FPS LOCKED ====
camera.update(delta_time);
// Run the raycast
error = clEnqueueAcquireGLObjects(c.getCommandQueue(), 1, &image_buff, 0, 0, 0);
@@ -320,6 +336,15 @@ int main() {
fps.frame(delta_time);
fps.draw(&window);
cam_text_x.draw(&window);
cam_text_y.draw(&window);
cam_text_mov_x.draw(&window);
cam_text_mov_y.draw(&window);
cam_text_mov_z.draw(&window);
//cam_text_z.draw(&window);
window.display();
}