示例#1
0
文件: scene.cpp 项目: yxrkt/DigiPen
void CreateScene(Scene& scene)
{
	scene.Clear();

	scene.EnableLighting = false;
	scene.EnableFlatShading = false;

	TileTexture* tile = new TileTexture(256,256);
	WoodTexture* wood = new WoodTexture(256,256);

	scene.SetAmbient(Color(0.4, 0.4, 0.4));
	scene.AddLight(Point3D(100,80,50), Color(0.8, 0.8, 0.8));
	scene.AddLight(Point3D(-100,-80,-50), Color(0.8, 0.8, 0.8));

	scene.SetTexture(tile, NULL);
	scene.modeling.Push();
	scene.modeling.Translate(-0.6, 0.0, 0);
	scene.SetColor(HSVColor(0.083, 0.75, 0.8), HSVColor(0.0, 0.0, 0.0), 0);
	CreateRect(scene, 1.0, 1.0);
	scene.modeling.Pop();

	scene.SetTexture(wood, NULL);
	scene.modeling.Push();
	scene.modeling.Translate(0.6, 0.0, 0);
	scene.SetColor(HSVColor(0.125, 0.7, 0.8), HSVColor(0.0, 0.0, 0.0), 0);
	CreateRect(scene, 1.0, 1.0);
	scene.modeling.Pop();
}
示例#2
0
void project1() {
	// Create scene
	Scene scn;
	scn.SetSkyColor(Color(0.8f, 0.9f, 1.0f));

	// Create boxes
    LambertMaterial lambert1;
    lambert1.SetDiffuseColor(Color(0.3f,0.3f,0.3f));

	MeshObject box1;
	box1.MakeBox(5.0f,0.1f,5.0f, &lambert1);
	scn.AddObject(box1);
    
    
    LambertMaterial lambert2;
    lambert2.SetDiffuseColor(Color(0.7f,0.7f,0.7f));
	MeshObject box2;
	box2.MakeBox(1.0f,1.0f,1.0f, &lambert2);
    
	InstanceObject inst1(box2);
	Matrix34 mtx;
	mtx.MakeRotateX(0.5f);
	mtx.d.y=1.0f;
	inst1.SetMatrix(mtx);
	scn.AddObject(inst1);
    
	InstanceObject inst2(box2);
	mtx.MakeRotateY(1.0f);
	mtx.d.Set(-1.0f,0.0f,1.0f);
	inst2.SetMatrix(mtx);
	scn.AddObject(inst2);
    
	// Create lights
	DirectLight sunlgt;
	sunlgt.SetBaseColor(Color(1.0f, 1.0f, 0.9f));
	sunlgt.SetIntensity(0.5f);
	sunlgt.SetDirection(Vector3(-0.5f, -1.0f, -0.5f));
	scn.AddLight(sunlgt);
    
	PointLight redlgt;
	redlgt.SetBaseColor(Color(1.0f, 0.2f, 0.2f));
	redlgt.SetIntensity(2.0f);
	redlgt.SetPosition(Vector3(2.0f, 2.0f, 0.0f));
	scn.AddLight(redlgt);
    
	// Create camera
	Camera cam;
	cam.LookAt(Vector3(2.0f,2.0f,5.0f), Vector3(0.0f,0.0f,0.0f));
	cam.SetResolution(800,600);
	cam.SetFOV(40.0f);
	cam.SetAspect(1.33f);
    
	// Render image
	cam.Render(scn);
	cam.SaveBitmap("project1.bmp");
}
示例#3
0
文件: scene.cpp 项目: yxrkt/DigiPen
void CreateScene(Scene& scene)
{
	scene.Clear();

	scene.EnableLighting = true;
	scene.EnableFlatShading = false;

	float r = 0.5;
	float count = 12;

	scene.SetAmbient(Color(0.2, 0.2, 0.2));
	scene.AddLight(Point3D(100,0,30), Color(0.8, 0.8, 0.8));
	scene.AddLight(Point3D(0,100,80), Color(0.5, 0.5, 0.5));

	// Red octant: Moderate specular, moderate shininess
	scene.modeling.Push();
	scene.SetColor(HSVColor(0.00, 1.0, 0.7), HSVColor(0.0, 0.0, 0.8), 30);
	scene.modeling.Translate( 0.5, -0.5, 0);
	CreateSphereOctant(scene, r, count);
	scene.modeling.Pop();

	// Blue octant: High specular, high shininess
	scene.modeling.Push();
	scene.SetColor(HSVColor(0.66, 1.0, 0.9), HSVColor(0.0, 0.0, 1.5), 120);
	scene.modeling.Translate(-0.5,  0.5, 0);
	CreateSphereOctant(scene, r, count);
	scene.modeling.Pop();

	// Green octant:  No specular
	scene.modeling.Push();
	scene.SetColor(HSVColor(0.33, 1.0, 0.7), HSVColor(0.0, 0.0, 0.0), 0);
	scene.modeling.Translate(-0.5, -0.5, 0);
	CreateSphereOctant(scene, r, count);
	scene.modeling.Pop();
}
void
SimObject::Activate(Scene& scene)
{
	if (rep)
	scene.AddGraphic(rep);
	if (light)
	scene.AddLight(light);

	active = true;
}
示例#5
0
int main() {
	// Initiatisation
	glm::ivec2 screenSize = glm::ivec2(400, 300);
	// -- Camera
	Camera cam = Camera(70.f, screenSize, 1);
	cam.LookAt(glm::vec3(50,52,295.6), glm::vec3(50,52,295.6) + glm::vec3(0,0.0,-1));

	// -- Scene
	Scene sc;
//	Sphere(1e5, Vec( 1e5+1,40.8,81.6), Vec(),Vec(.75,.25,.25),DIFF),//Left
//	Sphere(1e5, Vec(-1e5+99,40.8,81.6),Vec(),Vec(.25,.25,.75),DIFF),//Rght
//	Sphere(1e5, Vec(50,40.8, 1e5),     Vec(),Vec(.75,.75,.75),DIFF),//Back
//	Sphere(1e5, Vec(50,40.8,-1e5+170), Vec(),Vec(),           DIFF),//Frnt
//	Sphere(1e5, Vec(50, 1e5, 81.6),    Vec(),Vec(.75,.75,.75),DIFF),//Botm
//	Sphere(1e5, Vec(50,-1e5+81.6,81.6),Vec(),Vec(.75,.75,.75),DIFF),//Top

	sc.AddPrimitive(
			new Sphere(glm::vec3(1e5 + 1, 40.8, 81.6), 1e5,
					Material(glm::vec3(.75, .25, .25))));
	sc.AddPrimitive(
			new Sphere(glm::vec3(-1e5 + 99, 40.8, 81.6), 1e5,
					Material(glm::vec3(.25, .25, .75))));
	sc.AddPrimitive(
			new Sphere(glm::vec3(50,40.8, 1e5), 1e5,
					Material(glm::vec3(.75, .75, .75))));
	sc.AddPrimitive(
			new Sphere(glm::vec3(50, 40.8, -1e5 + 250), 1e5,
					Material(glm::vec3(.75, .75, .75))));
	sc.AddPrimitive(
			new Sphere(glm::vec3(50, 1e5, 81.6), 1e5,
					Material(glm::vec3(.75, .75, .75))));
	sc.AddPrimitive(
			new Sphere(glm::vec3(50,-1e5+81.6,81.6), 1e5,
					Material(glm::vec3(.75, .75, .75))));

	sc.AddLight(new PointLight(glm::vec3(50,52,240)));

	// -- Screne
	Screen screen(screenSize);
	// Ray generation
	for (int x = 0; x < screenSize.x; x++)
		for (int y = 0; y < screenSize.y; y++) {
			glm::vec3 colorFinal = sc.ComputeColor(cam.GetRay(x,y));
			screen.Store(x, y, colorFinal*100.f);
		}
	screen.SaveToPGM("out.pgm");
	return 0;
}
示例#6
0
文件: scene.cpp 项目: yxrkt/DigiPen
void CreateScene(Scene& scene)
{
	scene.Clear();

	scene.EnableLighting = false;
	scene.EnableFlatShading = false;

	ReflTexture* refl = new ReflTexture();

	scene.SetAmbient(Color(0.4, 0.4, 0.4));
	scene.AddLight(Point3D(0,-100,80), Color(0.8, 0.8, 0.8));

	scene.SetTexture(NULL, NULL, refl);
	scene.modeling.Push();
	scene.SetColor(HSVColor(0.66, 1.0, 0.9), HSVColor(0.0, 0.0, 1.5), 120);
	Reflector(scene, 12*4, 12*4);
	scene.modeling.Pop();
}
示例#7
0
void SceneLoader::ImportLight(Scene& scene, const aiLight* const light) {
    Light L;
    aiColor3D ai_color_ka = light->mColorAmbient;
    aiColor3D ai_color_kd = light->mColorDiffuse;
    aiColor3D ai_color_ks = light->mColorSpecular;
    aiVector3D ai_direction = light->mDirection;
    aiVector3D ai_position = light->mPosition;
    aiString ai_name = light->mName;
    aiLightSourceType ai_light_type = light->mType;
    L.ka = glm::vec3(ai_color_ka[0], ai_color_ka[1], ai_color_ka[2]);
    L.ks = glm::vec3(ai_color_ks[0], ai_color_ks[1], ai_color_ks[2]);
    L.kd = glm::vec3(ai_color_kd[0], ai_color_kd[1], ai_color_kd[2]);
    L.name = std::string(ai_name.C_Str());
    L.type = static_cast<Light::LightType>(ai_light_type);
    L.ray = Ray(glm::vec3(ai_position[0], ai_position[1], ai_position[2]),
                glm::vec3(ai_direction[0], ai_direction[1], ai_direction[2]));
    L.attenuation_coefficients = glm::vec3(light->mAttenuationConstant,
                                           light->mAttenuationLinear, light->mAttenuationQuadratic);
    L.spot_coefficients = glm::vec3(light->mAngleInnerCone,
                                    light->mAngleOuterCone, 0.0f);
    scene.AddLight(L);
}
示例#8
0
TEST(RayTracerTest, TurbineMeshTest) {
  SceneLoader& loader = SceneLoader::GetInstance();
  std::string path = "../assets/blade.ply";
  std::string status = "";
  Scene scene;
  std::cout << "loading" << std::endl;
  bool success = loader.LoadScene(path, scene, status);
  EXPECT_TRUE(success);
  EXPECT_EQ("OK", status);
  std::cout << "done loading" << std::endl;
  int image_width = 1024;
  int image_height = 1024;
  glm::vec3 eye_pos = glm::vec3(-274.564f, -282.243f, 950.0f);
  glm::vec3 at_pos = glm::vec3(-274.564f, -282.243f, 254.327f);
  glm::vec3 up_dir = glm::vec3(0.0f, 1.0f, 0.0f);
  std::cout << "set camera" << std::endl;
  glm::mat4x4 look_at = LookAt(eye_pos, at_pos, up_dir);
  Camera camera(image_width, image_height, Orthographic(0.0f, 1.0f), look_at);
  std::cout << "camera set" << std::endl;

  Light point_light;
  glm::vec3 point_light_color = glm::vec3(0.4f, 0.4f, 0.4f);
  point_light.ka = point_light_color;
  point_light.kd = point_light_color;
  point_light.ks = point_light_color;
  point_light.ray = Ray(glm::vec3(0.0, -400.0, 400.0f), glm::vec3(0.0f));
  point_light.type = Light::kPoint;
  point_light.attenuation_coefficients = glm::vec3(0.25f, 0.003372407f,
      0.000045492f);

  Light directional_light;
  glm::vec3 directional_light_color = glm::vec3(0.4f, 0.4f, 0.4f);
  directional_light.ka = directional_light_color;
  directional_light.kd = directional_light_color;
  directional_light.ks = directional_light_color;
  directional_light.ray = Ray(glm::vec3(0.0f), glm::vec3(0.0f, -1.0f, -1.0f));
  directional_light.type = Light::kDirectional;

  scene.AddLight(point_light);
  scene.AddLight(directional_light);

  Trimesh* trimesh = static_cast<Trimesh*>(scene.scene_objects()[0]);
  OctreeType octree;
  std::cout << "Building octree" << std::endl;
  octree.Build(trimesh->faces());
  //octree.set_trace(true);
  //octree.Print(std::cout);
  std::cout << "Octree built.\n";
  std::cout << "bounds = " << octree.GetBounds() << " center = "
      << octree.GetBounds().GetCenter() << std::endl;
  trimesh->set_accelerator(&octree);
  Image image;
  image.Resize(image_width, image_height);
  RayTracer ray_tracer(&scene, &camera);
  ray_tracer.set_display_progress(!use_timing);
  ray_tracer.set_display_stats(!use_timing);
  ray_tracer.set_background_color(glm::vec3(0.05f, 0.05f, 0.05f));

  timeval t_start, t_finish;
  if (use_timing)
    gettimeofday(&t_start, NULL);
  std::cout << "Rendering..." << std::endl;
  ray_tracer.Render(image);
  if (use_timing) {
    gettimeofday(&t_finish, NULL);
    float sec = t_finish.tv_sec - t_start.tv_sec + t_finish.tv_usec / 1000000.0f
        - t_start.tv_usec / 1000000.0f;
    std::cout << "Render time:" << sec << std::endl;
  } else
    std::cout << "Done." << std::endl;

  ImageStorage& storage = ImageStorage::GetInstance();
  success = storage.WriteImage("blade_octree.jpg", image, status);
  EXPECT_TRUE(success);
  EXPECT_EQ("OK", status);
}
int main (int argc, char *argv[]) {
    SharedAppenderPtr myAppender(new ConsoleAppender());
    myAppender->setName("myAppenderName");

    std::auto_ptr<Layout> myLayout = std::auto_ptr<Layout>(new log4cplus::TTCCLayout());
    myAppender->setLayout(myLayout);

    myLogger.addAppender(myAppender);
    myLogger.setLogLevel(DEBUG_LOG_LEVEL);

    SkyDragonEngineLogger::Instance()->AddAppender(myAppender);
    SkyDragonEngineLogger::Instance()->SetLogLevel(DEBUG_LOG_LEVEL);
	LOG4CPLUS_DEBUG(myLogger, "Testing adfsfsdfs  zzzzz");

    LightSource l;
    l.Position[0] = 0.f;
    l.Position[1] =  6.f;
    l.Position[2] =  10.f;
    l.Position[3] =  1.f;
    l.Ambient[0] = .2f;
    l.Ambient[1] =  .2f;
    l.Ambient[2] =  .2f;
    l.Ambient[3] =  1.f;
    l.Diffuse[0] = 1.f;
    l.Diffuse[1] =  1.f;
    l.Diffuse[2] =  1.f;
    l.Diffuse[3] =  1.f;
    l.Specular[0] = 1.f;
    l.Specular[1] =  1.f;
    l.Specular[2] =  1.f;
    l.Specular[3] =  1.f;
    
    ISceneObject* cube = CreateCubeObject();
    
    scene.AddLight(l);
    scene.SetRenderer(new GLSceneRenderer());
    scene.AddSceneObject(cube);
    
    ISceneObject* marble = CreatePlayerObject();
    scene.AddSceneObject(marble);
    
    ICollisionManager* collisionManager = new CollisionManager();
    collisionManager->AddCollisionHandler ( &HandleCollision );
    scene.SetCollisionManager ( collisionManager );
    
    //camera = new GLSatelliteCamera ( Vector3d ( 0.f, 0.f, 3.f ), marble );
    camera = new GLSphericalCamera();
    scene.SetCamera ( camera );
    
    ISceneObject* wall1 = CreateWallObject("Left wall", Vector3d (-2.5f, -0.1f, 0.f));
    scene.AddSceneObject(wall1);
    
    ISceneObject* wall2 = CreateWallObject("Right wall", Vector3d (2.5f, -0.1f, 0.f));
    scene.AddSceneObject(wall2);
    
    glutInit ( &argc, argv );
    glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutInitWindowSize ( WINDOW_WIDTH, WINDOW_HEIGHT );
    glutInitWindowPosition ( 100, 100 );
    glutCreateWindow ( argv[0] );
    
    glutDisplayFunc(draw_contents);
    glutReshapeFunc(resize_handler);
    glutIdleFunc(update_animation);
    glutMouseFunc(mouse_handler);
    glutMotionFunc(motion_handler);
    
    glutKeyboardFunc(kb_handler);
    glutSpecialFunc(kb_special_handler);
    
    glutMainLoop();
    
    return EXIT_SUCCESS;
}
示例#10
0
// Inicializacio, a program futasanak kezdeten, az OpenGL kontextus letrehozasa utan hivodik meg (ld. main() fv.)
void onInitialization() {
	glViewport(0, 0, screenWidth, screenHeight);

	Color ks = Color(0.4, 0.4, 0.4);
	Color kd = Color(255, 215, 0) / 255;
	Color k = Color(3.1, 2.7, 1.9);
	Color k_1 = Color(1.1, 1.7, 0.9);
	Color n = Color(0.17, 0.35, 1.5);
	Material *material = new Material(ks, Color(255, 200, 50) / 255, n, k,
			Color(), 50, false, false);
	Material *material_2 = new Material(ks, Color(205, 127, 50) / 255, n, k,
			Color(), 50, false, false);
	Material *material_3 = new Material(ks, Color(0, 178, 89) / 255, n, k,
			Color(), 50, true, false);

	Material *material_4 = new Material(ks, Color(0, 144, 244) / 255,
			Color(1.5, 1.5, 1.5), Color(), Color(), 50, false, true);
//	Sphere implementation----------------------------------------------
	Sphere *firstSphere = new Sphere(material_4);

//	Ellipsoid implementation-------------------------------------------
	Ellipsoid *firstEllipsoid = new Ellipsoid(material);
	myMatrix transfom1 = myMatrix(0.3, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.3, 0, 0,
			0, 0, 1);
	myMatrix transfom3 = myMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -0.2, 0,
			0.5, 1);
	myMatrix transfom2 = myMatrix(cos(M_PI / 6), sin(M_PI / 6), 0, 0,
			-sin(M_PI / 6), cos(M_PI / 6), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
	myMatrix transform4 = myMatrix(0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0.3, 0.2,
			1, 1);

	Vector normal = Vector(-0.529863, 0.253724, 0.80924, 1);
	Vector origo = Vector(-0.150579, 0.20029, 0.229974, 0);

	Hit hit = Hit();
	hit.normalVector = normal;
	hit.intersectPoint = origo;

	myMatrix tr1 = myMatrix(0.15, 0, 0, 0, 0, 0.25, 0, 0, 0, 0, 0.15, 0, 0, 0,
			0, 1);
	myMatrix tr3 = myMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0.25, 0, 1);
	myMatrix tr = getTheNewCoordSys(hit);

	Ellipsoid *secondEllipsoid = new Ellipsoid(material);
	myMatrix first_connection_matrix = tr1 * tr3 * tr;
	firstEllipsoid->setTrasformationMatrix(transfom1);
	secondEllipsoid->setTrasformationMatrix(first_connection_matrix);

	Vector normal_2 = normal * first_connection_matrix;
	Vector origo_2 = origo * first_connection_matrix;

	hit.normalVector = normal_2;
	hit.intersectPoint = origo_2;

	tr1 = myMatrix(0.15 , 0, 0, 0, 0, 0.25 , 0, 0, 0, 0,
			0.15 , 0, 0, 0, 0, 1);
	tr3 = myMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0.25 , 0,
			1);
	tr = getTheNewCoordSys(hit);
	Ellipsoid *thirdEllipsoid = new Ellipsoid(material);
	myMatrix second_connection_matrix = first_connection_matrix*tr;
	thirdEllipsoid->setTrasformationMatrix(second_connection_matrix);

//	Cylinder implementation---------------------------------------------
	Cylinder *firstCylinder = new Cylinder(material);
	transfom1 = myMatrix(0.2, 0, 0, 0, 0, 0.2, 0, 0, 0, 0, 0.2, 0, 0, 0, 0, 1);
	transfom3 = myMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.4, 0, -0.6, 1);
	transfom2 = myMatrix(cos(M_PI / 2), sin(M_PI / 2), 0, 0, -sin(M_PI / 2),
			cos(M_PI / 2), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
	firstCylinder->setTrasformationMatrix((transfom1 * transfom2) * transfom3);

//	Paraboloid implemenation--------------------------------------------
	Paraboloid *firstParaboloid = new Paraboloid(material_4);
	transfom1 = myMatrix(0.2, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.2, 0, 0, 0, 0, 1);
	transfom3 = myMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.4, 0, -0.6, 1);
	transfom2 = myMatrix(cos(M_PI / 2), sin(M_PI / 2), 0, 0, -sin(M_PI / 2),
			cos(M_PI / 2), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
	firstParaboloid->setTrasformationMatrix((transfom1) * transfom3);

//	Plane implementation------------------------------------------------
	Plane *firstPlane = new Plane(material_2);
	Plane2 *secondPlane = new Plane2(material_2);
	Scene scene = Scene();
	scene.AddObject((Intersectable*) firstPlane);
//	scene.AddObject((Intersectable*) firstCylinder);
//	scene.AddObject((Intersectable*) firstSphere);
	scene.AddObject((Intersectable*) firstEllipsoid);
	scene.AddObject((Intersectable*) secondEllipsoid);
//	scene.AddObject((Intersectable*) thirdEllipsoid);
//	scene.AddObject((Intersectable*) secondPlane);
//	scene.AddObject((Intersectable*) firstParaboloid);

	scene.SetAmbientColor(Color(77, 199, 253) / 255);

	PositionLightSource *light = new PositionLightSource(Vector(-1, 6, 7),
			Color(1, 1, 1));

	scene.AddLight((LightSource*) light);

	MyCamera camera = MyCamera(Vector(1, 2, 3), Vector(0, 0, 0),
			Vector(0, 1, 0));

	scene.SetCamera(camera);

	scene.render();

}
示例#11
0
void MainWindow::renderScene()
{
    // Setup scene
    Camera camera (Vector3(0.0,0.0,-29.0),
                   Vector3(0.0,0.0,0.0),
                   0.01f, 500.0, 55.0);
    camera.SetImage(m_image);
    camera.SetResultFileName("output_image");  //default filename of output image, particular rendering methods override it using actual params for filename
    camera.SetPhotonMappingParams(5, 400, 3, 100); //default setup of parameters (searching radius and number of searched photons for global and caustic map

    int liczbaodbic=0;
    int liczbafotonow=0;

 //pętla przebiegów renderingu
 for (int przebieg=0; przebieg</*11*/1; przebieg++){

    //SCENA PIRAMIDA Z BOXOW
 /*
    Scene scene;
    Box* box1111 = new Box(Vector3(-4.5,-9,-5),Vector3(2,2,2));
    Box* box2111 = new Box(Vector3(-1.5,-9,-5),Vector3(2,2,2));
    Box* box3111 = new Box(Vector3(1.5,-9,-5),Vector3(2,2,2));
    Box* box4111 = new Box(Vector3(4.5,-9,-5),Vector3(2,2,2));
    Box* box111 = new Box(Vector3(-3,-7,-4),Vector3(2,2,2));
    Box* box211 = new Box(Vector3(0,-7,-4),Vector3(2,2,2));
    Box* box311 = new Box(Vector3(3,-7,-4),Vector3(2,2,2));
    Box* box11 = new Box(Vector3(-1.5,-5,-3),Vector3(2,2,2));
    Box* box21 = new Box(Vector3(1.5,-5,-3),Vector3(2,2,2));
    Box* box4 = new Box(Vector3(0,-3,-2),Vector3(2,2,2));
    ReflectiveMaterial mat;
    RefractiveMaterial mat2(0.45f);
    DiffuseMaterial mat3(Color(1,1,1),Color(1,1,1),Color(0,0,0), 15, 0.0f);
    //cornell box musi byc na poczatku listy geometrii aby przy renderingu (funkcja traceraystream)z listy usuwane byly dwa ostatnie trojkaty sciany frontowej
    scene.AddGeometry(new CornellBox(Vector3(0,0,0), Vector3(20,20,20)));
    box1111->SetMaterial(&mat3);
    box2111->SetMaterial(&mat3);
    box3111->SetMaterial(&mat3);
    box4111->SetMaterial(&mat3);
    box111->SetMaterial(&mat3);
    box211->SetMaterial(&mat3);
    box311->SetMaterial(&mat3);
    box11->SetMaterial(&mat3);
    box21->SetMaterial(&mat3);
    box4->SetMaterial(&mat3);
    if(przebieg>0) scene.AddGeometry(box1111);
    if(przebieg>1) scene.AddGeometry(box2111);
    if(przebieg>2) scene.AddGeometry(box3111);
    if(przebieg>3) scene.AddGeometry(box4111);
    if(przebieg>4) scene.AddGeometry(box111);
    if(przebieg>5) scene.AddGeometry(box211);
    if(przebieg>6) scene.AddGeometry(box311);
    if(przebieg>7) scene.AddGeometry(box11);
    if(przebieg>8) scene.AddGeometry(box21);
    if(przebieg>9) scene.AddGeometry(box4);
    //LPOINT LIGHT
    //scene.AddLight(new POINTLight(Vector3(0, 9.5, -3),Color(1.0,1.0,1.0),Vector3(1,0.1f,0.0f)));
    //AREA LIGHT
    scene.AddLight(new AreaLight(Vector3(0, 9.5, -4),Vector2(3,3),Color(1.0,1.0,1.0),Vector3(1,0.1f,0.0f),4));

*/

    //SCENA DYFUZYJNA

//    Scene scene;
//    //Sphere* sphere1 = new Sphere(Vector3(-3,-7,2), 3);
// //   Sphere* sphere2 = new Sphere(Vector3(4.6,-6.8,-2), 3.5);
//    //Sphere* sphere3 = new Sphere(Vector3(-4,-7,-6), 3);
//    //Box* box1 = new Box(Vector3(-4,-8,0),Vector3(6,6,6));
//    MS3DModel* model = new MS3DModel();
//    model->Load("box.ms3d");
//    ReflectiveMaterial mat;
//    RefractiveMaterial mat2(0.45f);
//    DiffuseMaterial mat3(Color(1,1,1),Color(1,1,1),Color(0,0,0), 15, 0.0f);
//    //cornell box musi byc na poczatku listy geometrii aby przy renderingu (funkcja traceraystream)z listy usuwane byly dwa ostatnie trojkaty sciany frontowej
//    scene.AddGeometry(new CornellBox(Vector3(0,0,0), Vector3(20,20,20)));
//    //sphere1->SetMaterial(&mat);
// //   sphere2->SetMaterial(&mat3);
//    //sphere3->SetMaterial(&mat3);
//    //box1->SetMaterial(&mat3);
//    model->SetMaterial(&mat3);
//    model->SetPositionAndScale(Vector3(-4,-7.2,-2), 3);
//    //LPOINT LIGHT
//    //scene.AddLight(new POINTLight(Vector3(0, 9.5, -3),Color(1.0,1.0,1.0),Vector3(1,0.1f,0.0f)));
//    //AREA LIGHT
//    scene.AddLight(new AreaLight(Vector3(0, 9.5, -3),Vector2(3,3),Color(1.0,1.0,1.0),Vector3(1,0.1f,0.0f),4));
//    //scene.AddGeometry(sphere1);
//    //scene.AddGeometry(box1);
//    //SFERA DO TESTOW
//  //  scene.AddGeometry(sphere2);
//    //BOX DO TESTOW
//    scene.AddGeometry(model);


    //SCENA KAUSTYCZNA DWIE SFERY

    Scene scene;
    Sphere* sphere1 = new Sphere(Vector3(-4.6,-6.8,-2), 3.5);
    Sphere* sphere2 = new Sphere(Vector3(4.6,-6.8,-2), 3.5);
    //Box* box1 = new Box(Vector3(0,-6.8,0), Vector3(3.5,3.5,3.5));
    ReflectiveMaterial mat;
    RefractiveMaterial mat2(0.45f);
    // DiffuseMaterial mat3(Color(0,0,0),Color(0,1,0),Color(0,0,0), 15, 0.0f);
    //cornel box musi byc na poczatku listy geometrii aby przy renderingu (funkcja traceraystream)z listy usuwane byly dwa ostatnie trojkaty sciany frontowej
    scene.AddGeometry(new CornellBox(Vector3(0,0,0), Vector3(20,20,20)));
    sphere1->SetMaterial(&mat);
    sphere2->SetMaterial(&mat2);
    //box1->SetMaterial(&mat3);
    scene.AddGeometry(sphere1);
    scene.AddGeometry(sphere2);
    const Vector3 c(0.0f, 9.5f, -1.0f);
    const float d = 3.0f;
    Triangle* emisiveTriangle1 = new Triangle(Vector3(c.x+d, c.y, c.z+d), Vector3(c.x+d, c.y, c.z-d), Vector3(c.x-d, c.y, c.z+d));
    Triangle* emisiveTriangle2 = new Triangle(Vector3(c.x-d, c.y, c.z-d), Vector3(c.x-d, c.y, c.z+d), Vector3(c.x+d, c.y, c.z-d));
    EmmisiveMaterial emmisiveMat(LightIntensity(1.0f, 1.0f, 1.0f));
    emisiveTriangle1->SetMaterial(&emmisiveMat);
    emisiveTriangle2->SetMaterial(&emmisiveMat);
    scene.AddGeometry(emisiveTriangle1);
    scene.AddGeometry(emisiveTriangle2);

    //scene.AddGeometry(box1);
    //LPOINT LIGHT
    //scene.AddLight(new POINTLight(Vector3(0, 9.5, -3),Color(1.0,1.0,1.0),Vector3(1,0.1f,0.0f)));
    //AREA LIGHT
    scene.AddLight(new AreaLight(c,Vector2(d,d),Color(1.0,1.0,1.0),Vector3(1,0.1f,0.0f),4));


    //SCENA KATAKAUSTYCZNA
    /*
    Scene scene;
    ReflectiveMaterial mat1;
    RefractiveMaterial mat2(0.45f);
    DiffuseMaterial mat3(Color(1,1,1),Color(1,1,1),Color(0,0,0), 15, 0.0f);
    //cornel box musi byc na poczatku listy geometrii aby przy renderingu (funkcja traceraystream)z listy usuwane byly dwa ostatnie trojkaty sciany frontowej
    scene.AddGeometry(new CornellBox(Vector3(0,0,0), Vector3(20,20,20)));
    //1 scianka od prawej
    Triangle* t1 = new Triangle(Vector3(2,-10,4), Vector3(0,-10,5), Vector3(0,-2,5));
    Triangle* t2 = new Triangle(Vector3(0,-2,5), Vector3(2,-2,4), Vector3(2,-10,4));
    //2 scianka
    Triangle* t3 = new Triangle(Vector3(0,-10,5), Vector3(-2,-10,5), Vector3(-2,-2,5));
    Triangle* t4 = new Triangle(Vector3(-2,-2,5), Vector3(0,-2,5), Vector3(0,-10,5));
    //3 scianka
    Triangle* t5 = new Triangle(Vector3(-2,-10,5), Vector3(-4,-10,4), Vector3(-4,-2,4));
    Triangle* t6 = new Triangle(Vector3(-4,-2,4), Vector3(-2,-2,5), Vector3(-2,-10,5));
    //4 scianka
    Triangle* t7 = new Triangle(Vector3(-4,-10,4), Vector3(-5,-10,2), Vector3(-5,-2,2));
    Triangle* t8 = new Triangle(Vector3(-5,-2,2), Vector3(-4,-2,4), Vector3(-4,-10,4));
    //5 scianka
    Triangle* t9 = new Triangle(Vector3(-5,-10,2), Vector3(-5,-10,0), Vector3(-5,-2,0));
    Triangle* t10 = new Triangle(Vector3(-5,-2,0), Vector3(-5,-2,2), Vector3(-5,-10,2));
    //6 scianka
    Triangle* t11 = new Triangle(Vector3(-5,-10,0), Vector3(-4,-10,-2), Vector3(-4,-2,-2));
    Triangle* t12 = new Triangle(Vector3(-4,-2,-2), Vector3(-5,-2,0), Vector3(-5,-10,0));
    t1->SetMaterial(&mat1);
    scene.AddGeometry(t1);
    t2->SetMaterial(&mat1);
    scene.AddGeometry(t2);
    t3->SetMaterial(&mat1);
    scene.AddGeometry(t3);
    t4->SetMaterial(&mat1);
    scene.AddGeometry(t4);
    t5->SetMaterial(&mat1);
    scene.AddGeometry(t5);
    t6->SetMaterial(&mat1);
    scene.AddGeometry(t6);
    t7->SetMaterial(&mat1);
    scene.AddGeometry(t7);
    t8->SetMaterial(&mat1);
    scene.AddGeometry(t8);
    t9->SetMaterial(&mat1);
    scene.AddGeometry(t9);
    t10->SetMaterial(&mat1);
    scene.AddGeometry(t10);
    t11->SetMaterial(&mat1);
    scene.AddGeometry(t11);
    t12->SetMaterial(&mat1);
    scene.AddGeometry(t12);
    //LPOINT LIGHT
    //scene.AddLight(new POINTLight(Vector3(0, 9.5, -3),Color(1.0,1.0,1.0),Vector3(1,0.1f,0.0f)));
    //AREA LIGHT
    scene.AddLight(new AreaLight(Vector3(0, 9.5, -3),Vector2(3,3),Color(1.0,1.0,1.0),Vector3(1,0.1f,0.0f),4));
    */

    // SCENA STANFORD BUNNY
    /*
    Scene scene;
    DiffuseMaterial mat3(Color(1,1,1),Color(1,1,1),Color(0,0,0), 15, 0.0f);
    //cornel box musi byc na poczatku listy geometrii aby przy renderingu (funkcja traceraystream)z listy usuwane byly dwa ostatnie trojkaty sciany frontowej
    scene.AddGeometry(new CornellBox(Vector3(0,0,0), Vector3(20,20,20)));
    MS3DModel* model = new MS3DModel();
    model->Load("bunny.ms3d");
    model->SetPositionAndScale(Vector3(-2,-13,-2), 4);
    model->SetMaterial(&mat3);
    scene.AddGeometry(model);
    //LPOINT LIGHT
    //scene.AddLight(new POINTLight(Vector3(0, 9.5, -3),Color(1.0,1.0,1.0),Vector3(1,0.1f,0.0f)));
    //AREA LIGHT
    scene.AddLight(new AreaLight(Vector3(0, 9.5, -3),Vector2(3,3),Color(1.0,1.0,1.0),Vector3(1,0.1f,0.0f),4));
    */

    // SCENA UTAH TEAPOT
    /*
    Scene scene;
    DiffuseMaterial mat3(Color(1,1,1),Color(1,1,1),Color(0,0,0), 15, 0.0f);
    //cornel box musi byc na poczatku listy geometrii aby przy renderingu (funkcja traceraystream)z listy usuwane byly dwa ostatnie trojkaty sciany frontowej
    scene.AddGeometry(new CornellBox(Vector3(0,0,0), Vector3(20,20,20)));
    MS3DModel* model = new MS3DModel();
    model->Load("teapot.ms3d");
    model->SetPositionAndScale(Vector3(0,-10,-2), 5);
    model->SetMaterial(&mat3);
    scene.AddGeometry(model);
    //LPOINT LIGHT
    //scene.AddLight(new POINTLight(Vector3(0, 9.5, -3),Color(1.0,1.0,1.0),Vector3(1,0.1f,0.0f)));
    //AREA LIGHT
    scene.AddLight(new AreaLight(Vector3(0, 9.5, -3),Vector2(3,3),Color(1.0,1.0,1.0),Vector3(1,0.1f,0.0f),4));
    */

    // Render image using selected method
    if (StreamRenderer == m_rendererPanel->renderingMethod()) {
        RendererParams params = m_rendererPanel->getRendererParams();
        //podmiana parametrów renderingu
        if(przebieg>=0){
             liczbafotonow=10;
             liczbaodbic=7;
        }
        if(przebieg>=1){
            liczbafotonow=20;
            liczbaodbic=7;
        }
        if(przebieg>=2){
            liczbafotonow=30;
            liczbaodbic=7;
        }
        if(przebieg>=3){
            liczbafotonow=50;
           liczbaodbic=7;
        }
        if(przebieg>=4){
            liczbafotonow=100;
            liczbaodbic=7;
        }
        if(przebieg>=5){
            liczbafotonow=150;
            liczbaodbic=7;
        }
        if(przebieg>=6){
           liczbafotonow=200;
            liczbaodbic=7;
        }
        if(przebieg>=7){
           liczbafotonow=250;
            liczbaodbic=7;
        }
        if(przebieg>=8){
          liczbafotonow=300;
           liczbaodbic=7;
        }
        if(przebieg>=9){
          liczbafotonow=400;
            liczbaodbic=7;
        }
        if(przebieg>9){
          liczbafotonow=500;
            liczbaodbic=7;
        }
//dla foton mapingu
//liczbafotonowPM=liczbafotonow*1000;
//liczbafotonow=0;
        camera.SetPhotonMappingParams(params.m_globalSearchingRadius, params.m_numSearchedGlobalPhotons, params.m_causticSearchingRadius, params.m_numSearchedCausticPhotons);
        camera.RenderSceneStream(&scene,
                                 params.m_numSamples,
                                 params.m_numEmittedGlobalPhotons,
                                 //liczbafotonowPM,
                                 params.m_numEmittedCausticPhotons,
                                 liczbafotonow,
                                 params.m_streamRadius,
                                 liczbaodbic);
        m_rendererPanel->updateRenderingTime(camera.renderingTime());
    } else if (PhotonMapRenderer == m_rendererPanel->renderingMethod()) {

        RendererParams params = m_rendererPanel->getRendererParams();
        camera.RenderScene(&scene,
                           params.m_numSamples,
                           params.m_numEmittedGlobalPhotons,
                           params.m_numEmittedCausticPhotons);
        m_rendererPanel->updateRenderingTime(camera.renderingTime());
    } else if (StreamVisualizer == m_rendererPanel->renderingMethod()) {
        RendererParams params = m_rendererPanel->getRendererParams();
        camera.VisualizeStreamPhotonMap(&scene,
                                        params.m_numPhotons,
                                        params.m_maxReflections,
                                        params.m_numAssociatedPhotons,
                                        params.m_streamRadius);
        m_rendererPanel->updateRenderingTime(camera.renderingTime());
    } else if (PhotonMapVisualizer == m_rendererPanel->renderingMethod()) {
        RendererParams params = m_rendererPanel->getRendererParams();
        camera.VisualizePhotonMap(&scene,
                                  params.m_numPhotons,
                                  params.m_maxReflections);
        m_rendererPanel->updateRenderingTime(camera.renderingTime());
    } else {
        QMessageBox::warning(this,"Wrong rendering method",
                             "Error");
    }

    repaint();
    }
    QMessageBox::warning(this,"The End",
                         "Complete");
}
示例#12
0
Scene* Parser::GetSceneFromFile(std::string filename)
{
    Scene* scene = NULL;
    fstream fichierScene(filename.c_str(), ios::in );

    if( fichierScene.is_open() )
    {
        PRINT_GREEN("Fchier de scene bien ouvert.");
        scene = new Scene();
        EtatTraitementScene EtatCourant = TRAITEMENT_SCENE;
        EtatTraitementScene EtatNouveau = TRAITEMENT_SCENE;

        char line[ NB_MAX_CAR_PAR_LIGNE ];
        string buffer;

        Light light;
        Triangle triangle;
        Plan plan;
        Quadrique quadric;
        Materiau materiau;

        float Val0, Val1, Val2;
        float  R, G, B;

        while( !fichierScene.eof() )
        {
            fichierScene.getline( line, NB_MAX_CAR_PAR_LIGNE );
            buffer = line;
            CStringUtils::Trim( buffer, " ");

            // Passer les lignes vides et les commentaires
            if( buffer.empty() || buffer[ 0 ] == '*'  || buffer[ 0 ] == '\r' )
                continue;
            else
            {
                // Vérifier l'arrivée d'un nouvel état de traitement
                bool EstNouvelObjetScene = true;
                if     ( STRING_CHECKFIND( buffer, "Lumiere:" ) ) EtatNouveau = TRAITEMENT_LUMIERE;
                else if( STRING_CHECKFIND( buffer, "Poly:"    ) ) EtatNouveau = TRAITEMENT_TRIANGLE;
                else if( STRING_CHECKFIND( buffer, "Plane:"   ) ) EtatNouveau = TRAITEMENT_PLAN;
                else if( STRING_CHECKFIND( buffer, "Quad:"    ) ) EtatNouveau = TRAITEMENT_QUADRIQUE;
                else
                    EstNouvelObjetScene = false;

                if( EstNouvelObjetScene )
                {
                    // Ajouter objet nouvellement traité à la scène
                    if( EtatCourant != TRAITEMENT_SCENE )
                    {
                        if( EtatCourant == TRAITEMENT_LUMIERE )
                            scene->AddLight(light);
                        else
                        {
                            switch(EtatCourant)
                            {
                            case TRAITEMENT_PLAN:
                                scene->AddPlane(plan, materiau);
                                break;
                            case TRAITEMENT_TRIANGLE:
                                scene->AddTriangle(triangle, materiau);
                                break;
                            case TRAITEMENT_QUADRIQUE:
                                scene->AddQuadric(quadric, materiau);
                                break;
                            default:
                                PRINT_RED("Cas non pris en charge.");
                            }
                        }
                    }

                    // Substituer le nouvel état pour l'ancien
                    EtatCourant = EtatNouveau;
                }
                else
                {
                    // Remplir les informations génériques de l'objet courant

                    bool IsGenericsurfaceInfo = true;

                    if( STRING_CHECKFIND( buffer, "color:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f %f %f", line, &R, &G, &B );
                        materiau.color = Vector4(R, G, B, 1.0f);
                    }
                    /*else if( STRING_CHECKFIND( buffer, "ambient:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f", line, &Val0 );
                        surface->AjusterCoeffAmbiant( Val0 );
                    }
                    else if( STRING_CHECKFIND( buffer, "diffus:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f", line, &Val0 );
                        surface->AjusterCoeffDiffus( Val0 );
                    }
                    else if( STRING_CHECKFIND( buffer, "specular:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f %f", line, &Val0, &Val1 );
                        surface->AjusterCoeffSpeculaire( Val0 );
                        surface->AjusterCoeffBrillance( Val1 );
                    }*/
                    else if( STRING_CHECKFIND( buffer, "reflect:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f", line, &Val0 );
                        materiau.coeffReflexion = Val0;
                    }
                    else if( STRING_CHECKFIND( buffer, "refract:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f %f", line, &Val0, &Val1 );
                        materiau.coeffRefraction = Val0;
                        materiau.indiceRefraction = Val1;
                    }/*
                    else if( STRING_CHECKFIND( buffer, "rotate:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f %f %f", line, &Val0, &Val1, &Val2 );

                        CMatrice4 Transform = surface->ObtenirTransformation();
                        Transform.RotationAutourDesX( Deg2Rad<REAL>( Val0 ) );
                        Transform.RotationAutourDesY( Deg2Rad<REAL>( Val1 ) );
                        Transform.RotationAutourDesZ( Deg2Rad<REAL>( Val2 ) );
                        surface->AjusterTransformation( Transform );
                    }
                    else if( STRING_CHECKFIND( buffer, "translate:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f %f %f", line, &Val0, &Val1, &Val2 );
                        CMatrice4 Transform = surface->ObtenirTransformation();
                        Transform.Translation( Val0, Val1, Val2 );
                        surface->AjusterTransformation( Transform );
                    }
                    else if( STRING_CHECKFIND( buffer, "scale:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f %f %f", line, &Val0, &Val1, &Val2 );
                        CMatrice4 Transform = surface->ObtenirTransformation();
                        Transform.MiseAEchelle( Val0, Val1, Val2 );
                        surface->AjusterTransformation( Transform );
                    }*/
                    else
                        IsGenericsurfaceInfo = false;

                    if( IsGenericsurfaceInfo )
                        continue;
                }

                // Remplir les infos spécifiques à l'objet
                switch( EtatCourant )
                {
                case TRAITEMENT_SCENE:

                    /*if( STRING_CHECKFIND( buffer, "background:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %i %i %i", line, &R, &G, &B );
                        AjusterCouleurArrierePlan( CCouleur( R, G, B ) );
                    }
                    else if( STRING_CHECKFIND( buffer, "origin:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f %f %f", line, &Val0, &Val1, &Val2 );
                        AjusterPositionCamera( CVecteur3( Val0, Val1, Val2 ) );
                    }
                    else if( STRING_CHECKFIND( buffer, "eye:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f %f %f", line, &Val0, &Val1, &Val2 );
                        AjusterPointViseCamera( CVecteur3( Val0, Val1, Val2 ) );
                    }
                    else if( STRING_CHECKFIND( buffer, "up:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f %f %f", line, &Val0, &Val1, &Val2 );
                        AjusterVecteurUpCamera( CVecteur3( Val0, Val1, Val2 ) );
                    }
*/


                    break;

                case TRAITEMENT_LUMIERE:

                    if( STRING_CHECKFIND( buffer, "position:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f %f %f", line, &Val0, &Val1, &Val2 );
                        light.position = Vector3(Val0, Val1, Val2);
                    }
                    else if( STRING_CHECKFIND( buffer, "intens:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f", line, &Val0 );
                        light.intensity = Val0;
                    }
                    else if( STRING_CHECKFIND( buffer, "colorSpec:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f %f %f", line, &R, &G, &B );
                        light.color = Vector3(R, G, B);
                    }

                    break;

                case TRAITEMENT_TRIANGLE:

                    if( STRING_CHECKFIND( buffer, "point:" ) )
                    {
                        int PtIdx;
                        sscanf( buffer.c_str(), "%s %i %f %f %f", line, &PtIdx, &Val0, &Val1, &Val2 );
                        switch(PtIdx)
                        {
                            case 0:
                            triangle.p0 = Vector3(Val0, Val1, Val2);
                            break;
                            case 1:
                            triangle.p1 = Vector3(Val0, Val1, Val2);
                            break;
                            case 2:
                            triangle.p2 = Vector3(Val0, Val1, Val2);
                            triangle.normale = Vector3::crossProduct(triangle.p1-triangle.p0,triangle.p2-triangle.p0);
                            triangle.normale = triangle.normale/triangle.normale.Norm();
                            break;
                        }
                    }
                    else if( STRING_CHECKFIND( buffer, "uv:" ) )
                    {
                        int PtIdx;
                        sscanf( buffer.c_str(), "%s %i %f %f", line, &PtIdx, &Val0, &Val1 );
                        switch(PtIdx)
                        {
                            case 0:
			      triangle.uv0 = vec2(Val0,Val1);
			      break;
			    case 1:
			      triangle.uv1 = vec2(Val0,Val1);
			      break;
			    case 2:
			      triangle.uv2 = vec2(Val0,Val1);
			      break;
                        }
                    }

                    break;

                case TRAITEMENT_PLAN:

                    if( STRING_CHECKFIND( buffer, "v_linear:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f %f %f", line, &Val0, &Val1, &Val2 );
                        //( ( CPlan* )surface )->AjusterNormale( CVecteur3( Val0, Val1, Val2 ) );
                    }
                    else if( STRING_CHECKFIND( buffer, "v_const:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f", line, &Val0 );
                        //( ( CPlan* )surface )->AjusterConstante( Val0 );
                    }

                    break;

                case TRAITEMENT_QUADRIQUE:

                    if( STRING_CHECKFIND( buffer, "v_quad:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f %f %f", line, &Val0, &Val1, &Val2 );
                        quadric.A = Val0;
                        quadric.B = Val1;
                        quadric.C = Val2;
                    }
                    else if( STRING_CHECKFIND( buffer, "v_mixte:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f %f %f", line, &Val0, &Val1, &Val2 );
                        quadric.D = Val0;
                        quadric.E = Val1;
                        quadric.F = Val2;
                    }
                    else if( STRING_CHECKFIND( buffer, "v_linear:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f %f %f", line, &Val0, &Val1, &Val2 );
                        quadric.G = Val0;
                        quadric.H = Val1;
                        quadric.I = Val2;
                    }
                    else if( STRING_CHECKFIND( buffer, "v_const:" ) )
                    {
                        sscanf( buffer.c_str(), "%s %f", line, &Val0 );
                        quadric.J = Val0;
                    }
                    break;
                default:
                    PRINT_RED("Cas non pris en charge.");
                }
            }
        }

        // Fermer le fichier de scène
        fichierScene.close();

        // Ajouter le dernier objet traité
        switch(EtatCourant)
        {
        case TRAITEMENT_PLAN:
            scene->AddPlane(plan, materiau);
            break;
        case TRAITEMENT_TRIANGLE:
            scene->AddTriangle(triangle, materiau);
            break;
        case TRAITEMENT_QUADRIQUE:
            scene->AddQuadric(quadric, materiau);
            break;
        case TRAITEMENT_LUMIERE:
            scene->AddLight(light);
            break;
        default:
            PRINT_RED("Cas non pris en charge.");
        }
    }
    else
        PRINT_RED("[Parser::GetSceneFromFile()] : Incapable d'ouvrir " << filename);

    return scene;
}
示例#13
0
void project2() {
    // Create scene
    Scene scn;
    scn.SetSkyColor(Color(0.8f, 0.8f, 1.0f));
    
    // Create ground
    MeshObject ground;
    ground.MakeBox(5.0f,0.1f,5.0f);
    scn.AddObject(ground);
    
    // Create dragon
    MeshObject dragon;
    dragon.LoadPLY("dragon.ply");
    dragon.Smooth();
    
    std::chrono::time_point<std::chrono::system_clock> start, end;
    start = std::chrono::system_clock::now();
    
    std::cout <<  "Constructing the tree ..." << std::endl;
    
    BoxTreeObject tree;
    tree.Construct(dragon);
    scn.AddObject(tree);
    
    end = std::chrono::system_clock::now();
    std::chrono::duration<double> elapsed_seconds = end-start;
    
    std::cout << "Tree construcion done in " << elapsed_seconds.count() * 1000 << " milliseconds" <<  std::endl;

    
    // Create instance
    InstanceObject inst(tree);
    Matrix34 mtx;
    mtx.MakeRotateY(PI);
    mtx.d.Set(-0.05f,0.0f,-0.1f);
    inst.SetMatrix(mtx); scn.AddObject(inst);

    // Create lights
    DirectLight sunlgt;
    sunlgt.SetBaseColor(Color(1.0f, 1.0f, 0.9f));
    sunlgt.SetIntensity(1.0f);
    sunlgt.SetDirection(Vector3(2.0f, -3.0f, -2.0f));
    scn.AddLight(sunlgt);

    PointLight redlgt;
    redlgt.SetBaseColor(Color(1.0f, 0.2f, 0.2f));
    redlgt.SetIntensity(0.02f);
    redlgt.SetPosition(Vector3(-0.2f, 0.2f, 0.2f));
    scn.AddLight(redlgt);

    PointLight bluelgt;
    bluelgt.SetBaseColor(Color(0.2f, 0.2f, 1.0f));
    bluelgt.SetIntensity(0.02f);
    bluelgt.SetPosition(Vector3(0.1f, 0.1f, 0.3f));
    scn.AddLight(bluelgt);

    // Create camera
    Camera cam;
    cam.LookAt(Vector3(-0.1f,0.1f,0.2f),Vector3(-0.05f,0.12f,0.0f));
    cam.SetFOV(40.0f);
    cam.SetAspect(1.33f);
    cam.SetResolution(800,600);

    start = std::chrono::system_clock::now();
    std::cout <<  "Rendering the scene ..." << std::endl;
    
    // Render image
    cam.Render(scn);
    cam.SaveBitmap("project2.bmp");
    
    end = std::chrono::system_clock::now();
    elapsed_seconds = end-start;
    
    std::cout << "Scene rendering done in " << elapsed_seconds.count() * 1000 << " milliseconds" <<  std::endl;

}
示例#14
0
void project3() {
    // Create scene
    Scene scn;
    scn.SetSkyColor(Color(0.8f, 0.9f, 1.0f));
    
    // Materials
    const int nummtls=4;
    AshikhminMaterial mtl[nummtls];
    
    // Diffuse
    mtl[0].SetSpecularLevel(0.0f);
    mtl[0].SetDiffuseLevel(1.0f);
    mtl[0].SetDiffuseColor(Color(0.7f,0.7f,0.7f));
    
    // Roughened copper
    mtl[1].SetDiffuseLevel(0.0f);
    mtl[1].SetSpecularLevel(1.0f);
    mtl[1].SetSpecularColor(Color(0.9f,0.6f,0.5f));
    mtl[1].SetRoughness(100.0f,100.0f);
    
    // Anisotropic gold
    mtl[2].SetDiffuseLevel(0.0f);
    mtl[2].SetSpecularLevel(1.0f);
    mtl[2].SetSpecularColor(Color(0.95f,0.7f,0.3f));
    mtl[2].SetRoughness(1.0f,1000.0f);
    
    // Red plastic
    mtl[3].SetDiffuseColor(Color(1.0f,0.1f,0.1f));
    mtl[3].SetDiffuseLevel(0.8f);
    mtl[3].SetSpecularLevel(0.2f);
    mtl[3].SetSpecularColor(Color(1.0f,1.0f,1.0f));
    mtl[3].SetRoughness(1000.0f,1000.0f);
    
    // Load dragon mesh
    MeshObject dragon;
    dragon.LoadPLY("dragon.ply");
    
    // Create box tree
    BoxTreeObject tree;
    tree.Construct(dragon);
    
    // Create ground
    LambertMaterial lambert;
    lambert.SetDiffuseColor(Color(0.3f,0.3f,0.35f));
    MeshObject ground;
    ground.MakeBox(2.0f,0.11f,2.0f,&lambert);
    scn.AddObject(ground);

    
    // Create dragon instances
    Matrix34 mtx;
    for(int i=0;i<nummtls;i++) {
        InstanceObject *inst=new InstanceObject(tree);
        mtx.d.Set(0.0f,0.0f,-0.1f*float(i));
        inst->SetMatrix(mtx);
        inst->SetMaterial(&mtl[i]);
        scn.AddObject(*inst);
    }
    
    // Create lights
    DirectLight sunlgt;
    sunlgt.SetBaseColor(Color(1.0f, 1.0f, 0.9f));
    sunlgt.SetIntensity(1.0f);
    sunlgt.SetDirection(Vector3(2.0f, -3.0f, -2.0f));
    scn.AddLight(sunlgt);
    
    // Create camera
    Camera cam;
    cam.LookAt(Vector3(-0.5f,0.25f,-0.2f),Vector3(0.0f,0.15f,-0.15f));
    cam.SetFOV(40.0f); 
    cam.SetAspect(1.33f); 
    cam.SetResolution(800,600); 
    cam.SetSuperSample(100);
    
    // Render image 
    cam.Render(scn); 
    cam.SaveBitmap("project3.bmp"); 
} 
示例#15
0
Scene* CreateScene(void){
	Scene* scene = new Scene();

	//Initiate materials
	Material* sunMaterial = new Material(
		vec4(0.0f, 0.0f, 0.0f, 0.0f),
		vec4(0.0f, 0.0f, 0.0f, 0.0f),
		vec4(0.0f, 0.0f, 0.0f, 0.0f),
		vec4(1.0f, 1.0f, 0.6f, 1.0f),
		1
	);
	scene->AddMaterial(sunMaterial);

	Material* earthMaterial = new Material(
		vec4(0.04f, 0.04f, 0.2f, 1.0f),
		vec4(0.1f, 0.5f, 0.3f, 1.0f),
		vec4(0.5f, 0.5f, 0.5f, 1.0f),
		vec4(0.0f, 0.0f, 0.0f, 1.0f),
		5
	);
	scene->AddMaterial(earthMaterial);

	Material* moonMaterial = new Material(
		vec4(0.1f, 0.1f, 0.1f, 1.0f),
		vec4(0.5f, 0.5f, 0.5f, 1.0f),
		vec4(0.0f, 0.0f, 0.0f, 1.0f),
		vec4(0.0f, 0.0f, 0.0f, 1.0f),
		1
	);
	scene->AddMaterial(moonMaterial);

	Material* brickMaterial = new Material(
		vec4(-0.3f, -0.3f, -0.3f, 1.0f),
		vec4(1.5f, 1.5f, 1.5f, 1.0f),
		vec4(1.6f, 1.6f, 1.6f, 1.0f),
		vec4(0.0f, 0.0f, 0.0f, 1.0f),
		20
	);
	scene->AddMaterial(earthMaterial);

	Material* metalMaterial = new Material(
		vec4(0.2f, 0.2f, 0.2f, 1.0f),
		vec4(0.2f, 0.2f, 0.2f, 1.0f),
		vec4(1.0f, 1.0f, 1.0f, 1.0f),
		vec4(0.0f, 0.0f, 0.0f, 1.0f),
		10
	);
	scene->AddMaterial(metalMaterial);

	// Initiate Textures
	Texture* mudBrickTexture = new Texture("Textures/AlternatingMudbrick-ColorMap.png");
	scene->AddTexture(mudBrickTexture);
	Texture* mudBrickNormals = new Texture("Textures/AlternatingMudbrick-NormalMap.png");
	scene->AddTexture(mudBrickNormals);

	Texture* crackedBrickTexture = new Texture("Textures/CrackedAlternatingBricks-ColorMap.png");
	scene->AddTexture(crackedBrickTexture);
	Texture* crackedBrickNormals = new Texture("Textures/CrackedAlternatingBricks-NormalMap.png");
	scene->AddTexture(crackedBrickNormals);

	Texture* sandTexture = new Texture("Textures/Sand_1_Diffuse.png");
	scene->AddTexture(sandTexture);
	Texture* sandNormals = new Texture("Textures/Sand_1_Normal.png");
	scene->AddTexture(sandNormals);

	Texture* heightMap = new Texture("Textures/terrain-heightmap.png");
	//Texture* heightMap = new Texture("Textures/heightmap.png");
	//Texture* heightMap = new Texture("Textures/z.png");
	scene->AddTexture(heightMap);

	// Initiate Models
	/*
	Model* cube = new Cube();
	scene->AddModel(cube);
	*/
	Model* sphere = new Sphere(24);
	scene->AddModel(sphere);
	Model3DS* imported = new Model3DS("Model/pine_green_v3.3DS");
	scene->AddModel(imported);
	Model* plane = new Plane(2.0f, 2.0f, 64, 64);
	scene->AddModel(plane);

	Model* heightMapPlane = new HeightMappedPlane(2.0f, 2.0f, 5.0f, 64, 64, heightMap);

	// Initiate TextureSets
	TextureSet* brickBlend = new TextureSet();
	brickBlend->Add(mudBrickTexture, 2.0f);
	brickBlend->Add(crackedBrickTexture, 2.0f);

	TextureSet* blankTextureSet = new TextureSet();

	TextureSet* brickBlendNormals = new TextureSet();
	brickBlendNormals->Add(mudBrickNormals, 2.0f);
	brickBlendNormals->Add(crackedBrickNormals, 2.0f);

	TextureSet* smallBricks = new TextureSet();
	smallBricks->Add(crackedBrickTexture, 0.25f);
	TextureSet* smallBrickNormals = new TextureSet();
	smallBrickNormals->Add(crackedBrickNormals, 0.25f);

	// Initiate Nodes
	//EulerNode* ground = new EulerNode(plane, brickMaterial, brickBlend);
	EulerNode* ground = new EulerNode(heightMapPlane, brickMaterial, brickBlend);
	ground->Position = vec3(0.0f, -10.0f, 0.0f);
	ground->SetNormalMaps(brickBlendNormals);
	
	TextureSwitcher* textureSwitcher = new TextureSwitcher(ground);
	textureSwitcher->AddTextures(mudBrickTexture, mudBrickNormals);
	textureSwitcher->AddTextures(crackedBrickTexture, crackedBrickNormals);
	textureSwitcher->AddTextures(sandTexture, sandNormals);
	scene->AddNode(textureSwitcher);
	
	EulerNode* orb = new EulerNode(sphere, metalMaterial, blankTextureSet);
	//EulerNode* orb = new EulerNode(sphere, metalMaterial, smallBricks);
	orb->Position = vec3(0.0f, 5.0f, 0.0f);
	orb->SetNormalMaps(blankTextureSet);
	//orb->SetNormalMaps(smallBrickNormals);
	orb->Size = 5;
	ground->AddChild(orb);
	
	// Initiate Lights
	PointLight* pointLight = new PointLight();
	SpotLight* spotLight = new SpotLight();
	spotLight->Ambient = vec4(0.3f, 0.3f, 0.3f, 1.0);
	spotLight->Diffuse = vec4(0.5f, 0.5f, 0.3f, 0.0);
	spotLight->Specular = vec4(1.0f, 1.0f, 1.0f, 1.0);
	spotLight->Angle = 55.0f;
	spotLight->Direction = vec3(0.0f, -1.0f, 0.0f);

	scene->AddLight(pointLight);
	scene->AddLight(spotLight);

	EulerNode* spotLightModelNode = new EulerNode(sphere, sunMaterial, blankTextureSet);
	spotLightModelNode->Position = vec3(50.0f, 100.0f, 50.0f);
	spotLightModelNode->SetNormalMaps(blankTextureSet);
	spotLightModelNode->Position = vec3(spotLight->Position);
	scene->AddNode(spotLightModelNode);

	MouseNode* spotLightMover = new MouseNode(spotLightModelNode, GLUT_LEFT_BUTTON, true);
	LightNode* spotLightNode = new LightNode(spotLight, spotLightMover);
	spotLightMover->SetPosition(vec3(5.0f, 5.0f, 5.0f));
	scene->AddNode(spotLightNode);

	EulerNode* pointLightModelNode = new EulerNode(sphere, sunMaterial, blankTextureSet);
	pointLightModelNode->Position = vec3(50.0f, 50.0f, 50.0f);
	pointLightModelNode->SetNormalMaps(blankTextureSet);
	pointLightModelNode->Position = vec3(pointLight->Position);
	scene->AddNode(pointLightModelNode);

	MouseNode* pointLightMover = new MouseNode(pointLightModelNode, GLUT_RIGHT_BUTTON, false);
	LightNode* pointLightNode = new LightNode(pointLight, pointLightMover);
	pointLightMover->SetPosition(vec3(0.0f, 5.0f, 0.0f));
	scene->AddNode(pointLightNode);

	Node* globalControls = new GlobalControls();
	scene->AddNode(globalControls);

	return scene;
}