getting started on the lights

This commit is contained in:
MitchellHansen
2017-02-02 22:37:27 -08:00
parent 03a7ee43fd
commit 3f0a99a435
8 changed files with 291 additions and 100 deletions

View File

@@ -221,6 +221,7 @@ int Hardware_Caster::debug_quick_recompile()
}
validate();
return 1;
}
void Hardware_Caster::test_edit_viewport(int width, int height, float v_fov, float h_fov)

138
src/Light.cpp Normal file
View File

@@ -0,0 +1,138 @@
#pragma once
#include "Light.h"
#include "Pub_Sub.h"
Light::Light() {
}
Light::Light(sf::Vector3f position, sf::Vector3f direction) :
position(position), direction_cartesian(direction_cartesian)
{
}
Light::~Light() {
}
int Light::set_position(sf::Vector3f position) {
this->position = position;
return 1;
}
int Light::add_static_impulse(sf::Vector3f impulse) {
movement += impulse;
return 1;
}
int Light::add_relative_impulse(DIRECTION impulse_direction, float speed) {
// 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;
switch (impulse_direction) {
case DIRECTION::FORWARD:
dir = sf::Vector2f(direction_cartesian.y, direction_cartesian.x);
break;
case DIRECTION::REARWARD:
dir = sf::Vector2f(direction_cartesian.y, direction_cartesian.x + PI_F);
break;
case DIRECTION::LEFT:
dir = sf::Vector2f(direction_cartesian.y + PI_F + PI_F / 2, PI_F / 2);
break;
case DIRECTION::RIGHT:
dir = sf::Vector2f(direction_cartesian.y + PI_F / 2, PI_F / 2);
break;
case DIRECTION::UP:
dir = sf::Vector2f(direction_cartesian.y, direction_cartesian.x + PI_F / 2);
break;
case DIRECTION::DOWN:
dir = sf::Vector2f(direction_cartesian.y + PI_F, (direction_cartesian.x * -1) + PI_F / 2);
break;
}
movement += SphereToCart(dir);
movement *= speed;
return 1;
}
int Light::slew_camera(sf::Vector3f input) {
direction_cartesian -= input;
return 1;
}
void Light::set_camera(sf::Vector3f input) {
direction_cartesian = input;
}
int Light::update(double delta_time) {
double multiplier = 40;
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 *= static_cast<float>(1.0f * delta_time * multiplier);
return 1;
}
void Light::recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Event> event) {
if (event.get()->type == vr::Event::KeyHeld) {}
else if (event->type == vr::Event::KeyPressed) {}
else if (event->type == vr::Event::MouseMoved) {}
else if (event->type == vr::Event::JoystickMoved) {
vr::JoystickMoved *joystick_event = static_cast<vr::JoystickMoved*>(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 Light::look_at_center() {
//direction_cartesian = CartToNormalizedSphere(sf::Vector3f(75, 75, 75) - position);
}
sf::Vector3f* Light::get_direction_pointer() {
return &direction_cartesian;
}
sf::Vector3f* Light::get_movement_pointer() {
return &movement;
}
sf::Vector3f* Light::get_position_pointer() {
return &position;
}
sf::Vector3f Light::get_movement() {
return movement;
}
sf::Vector3f Light::get_position() {
return position;
}
sf::Vector3f Light::get_direction() {
return direction_cartesian;
}

View File

@@ -186,49 +186,49 @@ void Old_Map::generate_terrain() {
}
//for (int x = 0; x < dimensions.x; x++) {
// for (int y = 0; y < dimensions.y; y++) {
for (int x = 0; x < dimensions.x; x++) {
for (int y = 0; y < dimensions.y; y++) {
// if (height_map[x + y * dimensions.x] > 0) {
//
// int z = static_cast<int>(height_map[x + y * dimensions.x]);
if (height_map[x + y * dimensions.x] > 0) {
int z = static_cast<int>(height_map[x + y * dimensions.x]);
// while (z > 0) {
// voxel_data[x + dimensions.x * (y + dimensions.z * z)] = 5;
// z--;
// }
while (z > 0) {
voxel_data[x + dimensions.x * (y + dimensions.z * z)] = 5;
z--;
}
}
}
}
for (int x = dimensions.x / 2; x < dimensions.x / 2 + dimensions.x / 64; x++) {
for (int y = dimensions.x / 2; y < dimensions.y / 2 + dimensions.x / 64; y++) {
for (int z = 0; z < 5; z++) {
voxel_data[x + dimensions.x * (y + dimensions.z * z)] = 6;
}
}
}
for (int x = 0; x < dimensions.x; x++) {
for (int y = 0; y < dimensions.y; y++) {
// for (int z = 0; z < dimensions.z; z++) {
//if (rand() % 1000 < 1)
voxel_data[x + dimensions.x * (y + dimensions.z * 1)] = 6;
// }
}
}
// }
//}
//for (int x = dimensions.x / 2; x < dimensions.x / 2 + dimensions.x / 64; x++) {
// for (int y = dimensions.x / 2; y < dimensions.y / 2 + dimensions.x / 64; y++) {
// for (int z = 0; z < 5; z++) {
// voxel_data[x + dimensions.x * (y + dimensions.z * z)] = 6;
// }
// }
//}
//for (int x = 0; x < dimensions.x; x++) {
// for (int y = 0; y < dimensions.y; y++) {
//// for (int z = 0; z < dimensions.z; z++) {
// //if (rand() % 1000 < 1)
// voxel_data[x + dimensions.x * (y + dimensions.z * 1)] = 6;
//// }
// }
//}
//for (int x = 30; x < 60; x++) {
// //for (int y = 0; y < dimensions.y; y++) {
// for (int z = 0; z < 25; z++) {
// voxel_data[x + dimensions.x * (50 + dimensions.z * z)] = 6;
// }
// //}
//}
for (int x = 30; x < 60; x++) {
//for (int y = 0; y < dimensions.y; y++) {
for (int z = 0; z < 25; z++) {
voxel_data[x + dimensions.x * (50 + dimensions.z * z)] = 6;
}
//}
}
// Hand code in some constructions

View File

@@ -326,14 +326,16 @@ void Software_Caster::blit_pixel(sf::Color color, sf::Vector2i position, sf::Vec
sf::Color Software_Caster::global_light(sf::Color in, sf::Vector3i mask) {
sf::Vector3f mask_f(mask);
// I think I may scrap this whole software fallback caster thing
in.a = in.a + (int)acos(
DotProduct(
Normalize(lights->at(0).direction_cartesian),
Normalize(mask_f)
)
)/ 2;
//sf::Vector3f mask_f(mask);
//in.a = in.a + (int)acos(
// DotProduct(
// Normalize(lights->at(0).direction_cartesian),
// Normalize(mask_f)
// )
// )/ 2;
return in;

View File

@@ -37,6 +37,7 @@
#include "Input.h"
#include "Pub_Sub.h"
#include "NetworkInput.h"
#include "light.h"
const int WINDOW_X = 1000;
const int WINDOW_Y = 1000;
@@ -123,10 +124,11 @@ int main() {
float h = 90.0;
// Light for the currently non functional Bling Phong shader
Light l;
l.direction_cartesian = sf::Vector3f(-1.0f, -1.0f, -1.5f);
l.position = sf::Vector3f(256.0f, 256.0f, 256.0f);
l.rgbi = sf::Vector4f(0.3f, 0.4f, 0.3f, 1.0f);
Light l(
sf::Vector3f(256.0f, 256.0f, 256.0f),
sf::Vector3f(-1.0f, -1.0f, -1.5f),
&window
);
std::vector<Light> light_vec;
light_vec.push_back(l);
@@ -198,34 +200,31 @@ int main() {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::F11)) {
while (raycaster->debug_quick_recompile() != 0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
light_vec.at(0).position.x -= delta_time * 100;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
light_vec.at(0).position.x += delta_time * 100;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
light_vec.at(0).position.y += delta_time * 100;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
light_vec.at(0).position.y -= delta_time * 100;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Home)) {
light_vec.at(0).position.z += delta_time * 100;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::End)) {
light_vec.at(0).position.z -= delta_time * 100;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt)) {
light_vec.at(0).position = camera->get_position();
light_vec.at(0).direction_cartesian = SphereToCart(camera->get_direction());
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::O)) {
light_vec.at(0).orbit_around_center(timer_accumulator += delta_time);
}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
// light_vec.at(0).position.x -= delta_time * 100;
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
// light_vec.at(0).position.x += delta_time * 100;
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
// light_vec.at(0).position.y += delta_time * 100;
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
// light_vec.at(0).position.y -= delta_time * 100;
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Home)) {
// light_vec.at(0).position.z += delta_time * 100;
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::End)) {
// light_vec.at(0).position.z -= delta_time * 100;
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt)) {
// light_vec.at(0).position = camera->get_position();
// light_vec.at(0).direction_cartesian = SphereToCart(camera->get_direction());
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::O)) {
// light_vec.at(0).orbit_around_center(timer_accumulator += delta_time);
//}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num0)) {
std::string path = "../assets/";