forked from freme/raybeam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_uvsphere.cc
50 lines (43 loc) · 1.28 KB
/
test_uvsphere.cc
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
// simple_raytrace.cc
#include <iostream>
#include "vector3.h"
#include "rgb.h"
#include "image.h"
#include "shape.h"
#include "uvsphere.h"
#include "marble_texture.h"
#include "wood_texture.h"
using namespace std;
int main() {
HitRecord rec;
bool is_a_hit;
float tmax;
// negative z so we can use right-handed coords
Vector3 dir(0,0,-1); // direction of viewing rays
//generate Texture
// Texture *tex = new MarbleTexture(0.001f, 5.0f, 8);
Texture *tex = new WoodTexture(0.0015f, 10);
// scene geometry
UVSphere sphere(Vector3(750,750,-1000), 500, tex);
Image im(1500, 1500);
// loop over pixels
for (int i = 0; i < 1500; i++)
for (int j = 0; j < 1500; j++) {
tmax = 100000.0f;
is_a_hit = false;
Ray r(Vector3(i,j,0), dir);
if (sphere.hit(r, .00001f, tmax, 0.0f, rec)) {
tmax = rec.t;
is_a_hit = true;
}
if (is_a_hit) {
rgb color = tex->value(rec.uv, rec.hit_p);
im.set(i, j, color);
}
// else if(sphere.shadowHit(r, .00001f, tmax, 0.0f))
// im.set(i,j,rgb(.0, .0, .0));
else
im.set(i, j, rgb(.2, .2, .2));
}
im.writePPM(cout);
}