17 int main(
int argc,
char **argv )
19 const char *file=
"geometry.obj";
20 if(argc > 1) file= argv[1];
26 Orbiter camera= read_orbiter(
"orbiter.txt");
28 BVH bvh= make_bvh(mesh.positions);
33 Image image(1024, 640);
37 Point o= orbiter_position(camera);
38 orbiter_image_frame(camera, image.width(), image.height(), 1, 45, d0, dx, dy);
40 #pragma omp parallel for schedule(dynamic, 16)
41 for(
int y= 0; y < image.height(); y++)
42 for(
int x= 0; x < image.width(); x++)
44 Point e= d0 + (float) x * dx + (
float) y * dy;
45 Ray ray= make_ray(o, e);
48 if(intersect(bvh, ray, FLT_MAX, hit))
50 Color color= make_white();
51 color= make_color( std::abs(ray.direction.x), std::abs(ray.direction.y), std::abs(ray.direction.z) );
52 float cos_theta= std::abs(
dot(hit.n,
normalize(make_vector(hit.p, o))) );
55 Ray mray= reflect(ray, hit.p, hit.n);
64 image(x, y)=
Color(color * cos_theta, 1);
68 printf(
"triangles %lu %f/ray, boxes %lu %f/ray\n", tri_n, (
float) tri_n / (
float) image.size(), box_n, (float) box_n / (
float) image.size());
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet...
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
representation d'un objet / maillage.
representation d'une couleur (rgba) transparente ou opaque.
representation d'un vecteur 3d.
float dot(const Vector &u, const Vector &v)
renvoie le produit scalaire de 2 vecteurs.
representation d'un point d'intersection.
void printf(Text &text, const int px, const int py, const char *format,...)
affiche un texte a la position x, y. meme utilisation que printf().
int write_image(const Image &image, const char *filename)
enregistre une image dans un fichier png.
representation d'un rayon.
representation d'une image.
representation d'un point 3d.
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes. utiliser glDrawArrays pour l'afficher. a detruire avec Mesh::release( ).