diff --git a/README.md b/README.md index 340f5af..fd11065 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,6 @@ Featuring... * Shadowing * Textures - +![alt tag](https://www.youtube.com/watch?v=DHcg2ZKend0) ![alt tag](https://github.com/MitchellHansen/voxel-raycaster/blob/master/assets/screenshot1.png) ![alt tag](https://github.com/MitchellHansen/voxel-raycaster/blob/master/assets/screenshot.PNG) diff --git a/include/LightHandle.h b/include/LightHandle.h index e0995c2..1846c5a 100644 --- a/include/LightHandle.h +++ b/include/LightHandle.h @@ -2,6 +2,7 @@ #include #include #include +#include "Pub_Sub.h" // Light Handle : @@ -31,7 +32,7 @@ struct LightPrototype; class LightController; struct PackedData; -class LightHandle { +class LightHandle : public VrEventSubscriber{ public: @@ -51,7 +52,10 @@ public: void set_direction(sf::Vector3f direction); void set_rgbi(sf::Vector4f rgbi); - // void update(double delta_time); + + virtual void recieve_event(VrEventPublisher* publisher, std::unique_ptr event) override; + + void update(double delta_time); private: diff --git a/src/Camera.cpp b/src/Camera.cpp index 0e1ec42..4bc4e11 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -75,7 +75,7 @@ void Camera::set_camera(sf::Vector3f input) { int Camera::update(double delta_time) { - double multiplier = 40; + double multiplier = 80; position.x += static_cast(movement.x * delta_time * multiplier); position.y += static_cast(movement.y * delta_time * multiplier); diff --git a/src/LightHandle.cpp b/src/LightHandle.cpp index 685c9bf..3bc9653 100644 --- a/src/LightHandle.cpp +++ b/src/LightHandle.cpp @@ -63,3 +63,35 @@ void LightHandle::set_rgbi(sf::Vector4f rgbi) } +void LightHandle::recieve_event(VrEventPublisher* publisher, std::unique_ptr event) +{ + if (event->type == vr::Event::JoystickMoved) { + + vr::JoystickMoved *joystick_event = static_cast(event.get()); + + if (joystick_event->axis == sf::Joystick::Axis::X) { + movement.x = -joystick_event->position / 5; + //add_relative_impulse(Camera::DIRECTION::FORWARD, joystick_event->position); + } + else if (joystick_event->axis == sf::Joystick::Axis::Y) { + movement.y = joystick_event->position / 5; + //add_relative_impulse(Camera::DIRECTION::RIGHT, joystick_event->position); + } + //else if (joystick_event->axis == sf::Joystick::Axis::Z) { + // add_relative_impulse(Camera::DIRECTION::DOWN, joystick_event->position); + //} + } +} + +void LightHandle::update(double delta_time) { + + double multiplier = 40; + + data_reference->position.x += static_cast(movement.x * delta_time * multiplier); + data_reference->position.y += static_cast(movement.y * delta_time * multiplier); + data_reference->position.z += static_cast(movement.z * delta_time * multiplier); + + //movement *= static_cast(friction_coefficient * delta_time * multiplier); + +} + diff --git a/src/NetworkInput.cpp b/src/NetworkInput.cpp index 050addb..6697140 100644 --- a/src/NetworkInput.cpp +++ b/src/NetworkInput.cpp @@ -116,7 +116,7 @@ void NetworkInput::threaded_client_listener(int port) { event_queue.push_back(std::make_unique(vr::JoystickMoved(sf::Joystick::Axis::Y, 0, y))); event_queue.push_back(std::make_unique(vr::JoystickMoved(sf::Joystick::Axis::Z, 0, z))); - std::cout << "X: " << x << " Y: " << y << " Z: " << z << std::endl; + //std::cout << "X: " << x << " Y: " << y << " Z: " << z << std::endl; } } } diff --git a/src/Old_Map.cpp b/src/Old_Map.cpp index a24265b..4d383a5 100644 --- a/src/Old_Map.cpp +++ b/src/Old_Map.cpp @@ -184,6 +184,17 @@ void Old_Map::generate_terrain() { } } + for (int x = 100; x < 150; x += 10) { + for (int y = 100; y < 150; y += 10) { + for (int z = 0; z < 10; z += 1) { + + voxel_data[x + dimensions.x * (y + dimensions.z * z)] = 5; + + } + } + } + + for (int x = 0; x < dimensions.x; x++) { for (int y = 0; y < dimensions.y; y++) { diff --git a/src/main.cpp b/src/main.cpp index d186a72..9b927f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,8 +39,8 @@ #include "LightController.h" #include "LightHandle.h" -const int WINDOW_X = 1000; -const int WINDOW_Y = 1000; +const int WINDOW_X = 1440; +const int WINDOW_Y = 900; const int WORK_SIZE = WINDOW_X * WINDOW_Y; const int MAP_X = 256; @@ -114,13 +114,11 @@ int main() { &window ); - - // *link* the camera to the GPU raycaster->assign_camera(camera); // Generate and send the viewport to the GPU. Also creates the viewport texture - raycaster->create_viewport(WINDOW_X, WINDOW_Y, 50.0f, 50.0f); + raycaster->create_viewport(WINDOW_X, WINDOW_Y, 0.625f * 90.0f, 90.0f); float w = 60.0; float h = 90.0; @@ -128,7 +126,7 @@ int main() { LightController light_controller(raycaster); LightPrototype prototype( - sf::Vector3f(256.0f, 256.0f, 256.0f), + sf::Vector3f(100.0f, 100.0f, 30.0f), sf::Vector3f(-1.0f, -1.0f, -1.5f), sf::Vector4f(1.0f, 1.0f, 1.0f, 1.0f) ); @@ -183,6 +181,7 @@ int main() { camera->subscribe_to_publisher(&input_handler, vr::Event::EventType::KeyPressed); camera->subscribe_to_publisher(&input_handler, vr::Event::EventType::MouseMoved); //camera->subscribe_to_publisher(&ni, vr::Event::EventType::JoystickMoved); + handle->subscribe_to_publisher(&ni, vr::Event::EventType::JoystickMoved); WindowHandler win_hand(&window); win_hand.subscribe_to_publisher(&input_handler, vr::Event::EventType::Closed); @@ -194,7 +193,7 @@ int main() { input_handler.consume_sf_events(&window); input_handler.handle_held_keys(); input_handler.dispatch_events(); - //ni.dispatch_events(); + ni.dispatch_events(); if (sf::Keyboard::isKeyPressed(sf::Keyboard::F11)) { @@ -257,6 +256,7 @@ int main() { // ==== FPS LOCKED ==== camera->update(delta_time); + handle->update(delta_time); window.clear(sf::Color::Black);