mirror of https://github.com/kurisufriend/threedee
parent
ef50f1afcf
commit
d8be22ebdc
@ -1,5 +1,19 @@ |
||||
#pragma once |
||||
#include "vector3.h" |
||||
#include "SDL.h" |
||||
#include <iostream> |
||||
struct camera |
||||
{ |
||||
|
||||
vector3 position; |
||||
vector3 rotation; |
||||
camera(vector3 position_, vector3 rotation_) |
||||
{ |
||||
this->position = position_; |
||||
this->rotation = rotation_; |
||||
} |
||||
void run(SDL_Renderer* renderer) |
||||
{ |
||||
//ray3D ray = ray3D::trace(vector3(0, 0, -10), vector3(0, 0, 1));
|
||||
//std::cout << ray.dist << std::endl;
|
||||
} |
||||
}; |
@ -0,0 +1,46 @@ |
||||
#pragma once |
||||
#include <numeric> |
||||
#include "../globals/globals.h" |
||||
|
||||
#include "vector3.h" |
||||
#include "cube.h" |
||||
|
||||
struct ray3D |
||||
{ |
||||
vector3 start; |
||||
vector3 end; |
||||
float dist; |
||||
cube* hitEnt; |
||||
static ray3D trace(vector3 start, vector3 direction) |
||||
{ |
||||
ray3D ray{ start, start, -1 }; |
||||
vector3 point = start; |
||||
bool hit = false; |
||||
while (!hit) |
||||
{ |
||||
for (int i = 0; i < global::entList3D.size(); i++) |
||||
{ |
||||
cube* object = global::entList3D.at(i); |
||||
if (inCube(point, vector3(object->x, object->y, object->z), vector3(object->x + object->radius, object->y + object->radius, object->z + object->radius)) || ray.dist > 500) |
||||
{ |
||||
ray.start = start; |
||||
ray.end = point; |
||||
ray.dist = start.distance(point); |
||||
ray.hitEnt = object; |
||||
hit = true; |
||||
break; |
||||
} |
||||
} |
||||
ray.dist = start.distance(point); |
||||
point.x += direction.x; |
||||
point.y += direction.y; |
||||
point.z += direction.z; |
||||
} |
||||
return ray; |
||||
} |
||||
//temp
|
||||
static bool inCube(vector3 point, vector3 a, vector3 b) |
||||
{ |
||||
return (point.x > a.x && point.y > a.y && point.x < b.x && point.y < b.y && point.z > a.z && point.z < b.z); |
||||
} |
||||
}; |
Loading…
Reference in new issue