-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathray.cpp
More file actions
32 lines (30 loc) · 1018 Bytes
/
ray.cpp
File metadata and controls
32 lines (30 loc) · 1018 Bytes
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
#include "ray.h"
#include "render.h"
#include "vectorOps.h"
#include "shape.h"
Ray::Ray(double reach, std::vector<double> coords, std::vector<double> moveVector, std::vector<Shape*>* world, double speed=1){
this->reach = reach;
this->coords = coords;
this->moveVector = moveVector;
this->speed=speed;
this->world = world;
getOutput();
}
Color Ray::getOutput(){
for(double dist = 0; dist < reach; dist += speed){
coords = vectorOps::vectorAddition(coords, vectorOps::scalarMultiplication(moveVector, speed));
//std::cout << moveVector[0] << " " << moveVector[1] << " " << moveVector[2] << std::endl;
if(coords[1] < 0){
output = Color::blue;
return Color::blue;
}
for(int i = 0; i < world->size(); i++){
if((*world)[i]->doesIntersect(coords)){
output = Color::lightgreen;
return Color::lightgreen;
}
}
}
output = Color::white;
return Color::white;
}