Lighting, testing voxel generation
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#include <SFML/System/Vector3.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <random>
|
||||
|
||||
class Map {
|
||||
public:
|
||||
@@ -10,47 +12,19 @@ public:
|
||||
list[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 51; i < 52; i++) {
|
||||
list[55 + dim.x * (55 + dim.z * i)] = 1;
|
||||
}
|
||||
|
||||
// The X walls get red and magenta
|
||||
for (int x = 0; x < dim.x; x += 2) {
|
||||
for (int y = 0; y < dim.y; y += 2) {
|
||||
list[x + dim.x * (y + dim.z * 1)] = 1;
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < dim.x; x += 2) {
|
||||
for (int y = 0; y < dim.y; y += 2) {
|
||||
list[x + dim.x * (y + dim.z * 99)] = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// The Z walls get yellow and some other color
|
||||
for (int x = 0; x < dim.x; x += 2) {
|
||||
for (int z = 0; z < dim.z; z += 2) {
|
||||
list[x + dim.x * (99 + dim.z * z)] = 3;
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < dim.x; x += 2) {
|
||||
for (int z = 0; z < dim.z; z += 2) {
|
||||
list[x + dim.x * (1 + dim.z * z)] = 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int y = 0; y < dim.y; y += 2) {
|
||||
for (int z = 0; z < dim.z; z += 2) {
|
||||
list[99 + dim.x * (y + dim.z * z)] = 5;
|
||||
}
|
||||
}
|
||||
for (int y = 0; y < dim.y; y += 2) {
|
||||
for (int z = 0; z < dim.z; z += 2) {
|
||||
list[1 + dim.x * (y + dim.z * z)] = 6;
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < dim.x; x++) {
|
||||
for (int y = 0; y < dim.y; y++) {
|
||||
for (int z = 0; z < dim.z; z++) {
|
||||
if (rand() % 100 < 1)
|
||||
list[x + dim.x * (y + dim.z * z)] = rand() % 6;
|
||||
else
|
||||
list[x + dim.x * (y + dim.z * z)] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dimensions = dim;
|
||||
global_light = sf::Vector3f(0.2, 0.4, 1);
|
||||
}
|
||||
|
||||
~Map() {
|
||||
@@ -60,6 +34,9 @@ public:
|
||||
char *list;
|
||||
sf::Vector3i dimensions;
|
||||
|
||||
void moveLight(sf::Vector2f in);
|
||||
sf::Vector3f global_light;
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
@@ -68,6 +68,19 @@ inline sf::Vector3f Normalize(sf::Vector3f in) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline float DotProduct(sf::Vector3f a, sf::Vector3f b){
|
||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||
}
|
||||
|
||||
inline float Magnitude(sf::Vector3f in){
|
||||
return sqrt(in.x * in.x + in.y * in.y + in.z * in.z);
|
||||
}
|
||||
|
||||
inline float AngleBetweenVectors(sf::Vector3f a, sf::Vector3f b){
|
||||
return acos(DotProduct(a, b) / (Magnitude(a) * Magnitude(b)));
|
||||
}
|
||||
|
||||
inline float DegreesToRadians(float in) {
|
||||
return in * PI / 180.0f;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user