#include #include #include "entity.h" #include "triangle.h" #include "sphere.h" #include "color.h" #include "disjoint_entities.h" #include "world_objects.h" #include "write_rgb.h" #include "tri_mesh.h" #include "entity_transform.h" #include "light.h" static double pi = atan(1) * 4; int main() { Ambient_Background.rgb = vector3d(0.2, 0.2, 0); world_objects world; Light L0, L1, L2, L3; L0.c.rgb = unit_x; // red L1.c.rgb = vec_one; // white L2.c.rgb = unit_z; // blue L3.c.rgb = vec_one; // white L0.I = .5; L1.I = 1.5; L2.I = .5; L3.I = .5; L0.pt = vector3d(20, 10, 20); L1.pt = vector3d(-2, -2, 0); L2.pt = vector3d(20, -20, -10); L3.pt = vector3d(0, 0, 10); world.lights.push_back(L2); world.lights.push_back(L3); world.lights.push_back(L1); world.lights.push_back(L0); tri_mesh cyl("cyl_poly.iv.smf"); cyl.ka = .2; cyl.ks = .5; cyl.kd = .4; cyl.n = 6; cyl.phong = true; cyl.CalcNorms(); cyl.col.rgb = vector3d(1, 1, .5); tri_mesh box("outx.smf"); box.ka = .3; box.ks = .7; box.kd = .5; box.n = 50; box.phong = false; box.CalcNorms(); box.col.rgb = vector3d(1, 1, 0); cyl.col.rgb = vector3d(.5, 1, 1); Sphere sph(vector3d(0, 0, -1.5), .5); sph.ka = .5; sph.ks = .5; sph.kd = .7; sph.n = 20; sph.col.rgb = vector3d(1, 1, 1); Sphere sph1(vector3d(0, 0, 3.7), 1); sph1.ka = .3; sph1.ks = .7; sph1.kd = .5; sph1.n = 10; sph1.col.rgb = vector3d(1, 0, 1); DisjointEntities bs(&sph, &cyl); Entity_Translate et0[5]; et0[0].SetChildToParent(vector3d(1.1, 2.6, 0.0)); et0[1].SetChildToParent(vector3d(-1.1, 2.6, 0.0)); et0[2].SetChildToParent(vector3d(1.1, -2.6, 0.0)); et0[3].SetChildToParent(vector3d(-1.1, -2.6, 0.0)); et0[4].SetChildToParent(vector3d(0.0, 0.0, 1.0)); et0[0].E = &bs; et0[1].E = &bs; et0[2].E = &bs; et0[3].E = &bs; et0[4].E = &box; DisjointEntities dje0(&et0[0], &et0[1]); DisjointEntities dje1(&et0[2], &et0[3]); DisjointEntities dje2(&et0[4], &dje0); DisjointEntities dje3(&dje1, &dje2); world.Insert(&dje3); Transform tr0; tr0.Rotation(unit_x, pi/6); tr0.Scale(.5); tr0.Translate(vector3d(0,0,-2)); Entity_Transform tr1; tr1.E = &dje3; tr1.SetChildToParent(tr0); world.Insert(&tr1); world.Insert(&sph1); tri_mesh cow("cow.smf"); cow.ka = .3; cow.ks = .7; cow.kd = .5; cow.n = 50; cow.phong = false; cow.CalcNorms(); cow.col.rgb = vector3d(1, 1, 1); tri_mesh bunny("cow.smf"); bunny.ka = .3; bunny.ks = .7; bunny.kd = .5; bunny.n = 50; bunny.phong = false; bunny.CalcNorms(); bunny.col.rgb = vector3d(1, 1, 1); Transform trcow; trcow.Rotation(unit_x, -pi/2); trcow.Scale(4); trcow.Translate(vector3d(0,4,3)); Transform trbunny; trbunny.Rotation(unit_x, -pi/2); trbunny.Scale(4); trbunny.Translate(vector3d(0,2,3)); Entity_Transform etcow; Entity_Transform etbunny; etcow.SetChildToParent(trcow); etbunny.SetChildToParent(trbunny); etcow.E = &cow; etbunny.E = &bunny; world.Insert(&etcow); world.Insert(&etbunny); vector3d camera(10, 0, 0), view_pt(0, 0, 0); world.PathCompress(); int screen_w = 512, screen_h = 512; int sample_factor = 2; long ** screen = new long*[screen_w*sample_factor]; *screen = new long[screen_w*screen_h*sample_factor*sample_factor]; for(int i=1; i