-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.hpp
101 lines (87 loc) · 2.12 KB
/
camera.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#pragma once
#include "raylib.h"
#include "raymath.h"
#include <thread>
#include <vector>
#define EP 1
#define MAX 100
#define SCALE 5
#define MAX_THREADS 5
#define FOV 2.5
typedef struct FoxModel FoxModel;
class RaycastRay {
private:
public:
Vector3 direction;
Vector3 directionComputed;
Vector3 origin;
Vector3 rotation;
RaycastRay(Vector3 cDirection, Vector3 cOrigin);
~RaycastRay();
float GetDistance(std::vector<FoxModel> *models);
Color GetColor(std::vector<FoxModel> *models);
};
class FoxPlane {
public:
FoxPlane(Vector3 normal, Vector3 origin);
~FoxPlane();
float IntersectsRay(RaycastRay ray);
float DistanceToPoint(Vector3 point);
Vector3 PointForDistance(float dist, Vector3 point);
Vector3 origin;
Vector3 normal;
private:
};
class FoxTri {
public:
FoxTri(Vector3 A, Vector3 B, Vector3 C);
~FoxTri();
float IntersectsRay(RaycastRay ray, float maxDist);
float IntersectsSphere(Vector3 point, float radius);
float PointInside(Vector3 point, float scalar);
Vector3 normal;
Vector3 A;
Vector3 B;
Vector3 C;
private:
FoxPlane *raycastPlane;
// Pre-Calc
Vector3 BASub;
Vector3 CBSub;
Vector3 ACSub;
};
struct FoxModel {
FoxTri **tris;
int size;
int hue;
};
class FoxCamera {
private:
int width;
int height;
int vmax;
int aspectRatio;
pthread_t threads[MAX_THREADS];
RaycastRay **rays;
public:
FoxCamera(int cWidth, int cHeight);
~FoxCamera();
void Render(Image *image, std::vector<FoxModel> *models);
void RenderChunk(Image *image, int chunk, std::vector<FoxModel> *models);
static void *ThreadHelper(void *context);
Vector3 position;
Vector3 rotation;
};
FoxModel makeCubeColor(Vector3 position, Vector3 scale, int hue);
FoxModel makeCube(Vector3 position, Vector3 scale);
FoxModel makeTorus(Vector3 position, Vector3 scale);
FoxModel readTris();
FoxTri **vertToTri(float *vert, int size, Vector3 position, Vector3 scale);
void proccessPixel(Image *image, int x, int y, RaycastRay *ray,
std::vector<FoxModel> *models);
typedef struct ChunkInfo {
FoxCamera *camera;
Image *image;
int chunk;
std::vector<FoxModel> *models;
} ChunkInfo;