Пример #1
0
TEST(KDTree, shouldSearchInTree) {

  KDTree tree;

  vector<RTShape*> shapes;
  RTSphere sphere0(Vector(2.5, 2.5, 2.5), 2.4);
  RTSphere sphere1(Vector(2.5, 2.5, 7.5), 2.4);
  RTSphere sphere2(Vector(2.5, 7.5, 7.5), 2.4);
  RTSphere sphere3(Vector(2.5, 7.5, 2.5), 2.4);
  RTSphere sphere4(Vector(7.5, 2.5, 2.5), 2.4);
  RTSphere sphere5(Vector(7.5, 2.5, 7.5), 2.4);
  RTSphere sphere6(Vector(7.5, 7.5, 7.5), 2.4);
  RTSphere sphere7(Vector(7.5, 7.5, 2.5), 2.4);
  shapes.push_back(&sphere0);
  shapes.push_back(&sphere1);
  shapes.push_back(&sphere2);
  shapes.push_back(&sphere3);
  shapes.push_back(&sphere4);
  shapes.push_back(&sphere5);
  shapes.push_back(&sphere6);
  shapes.push_back(&sphere7);

  BoundingBox box(Vector(0,0,0), Vector(10,10,10));
  tree.setBoundingBox(box);
  tree.setTerminationCondition(1);
  tree.build(shapes, 0);

  Ray ray(Vector(7.5, 7.5, -2 ), Vector(0,0,1));
  IntersectionPtr intersection = tree.intersect(ray);
  
  CHECK( intersection != nullptr );
  CHECK( intersection->getShape() == &sphere7 );

}
Пример #2
0
TEST(KDTree, itSplitsXthenYthenZ) {

  KDTree tree;

  vector<RTShape*> shapes;
  RTSphere sphere0(Vector(5,5,0), 1);
  RTSphere sphere1(Vector(5,-5,0), 1);
  RTSphere sphere2(Vector(-5,5,0), 1);
  RTSphere sphere3(Vector(-5,-5,0), 1);
  shapes.push_back(&sphere0);
  shapes.push_back(&sphere1);
  shapes.push_back(&sphere2);
  shapes.push_back(&sphere3);

  BoundingBox box(Vector(-6,-6,-6), Vector(12,12,12));
  tree.setBoundingBox(box);
  tree.setTerminationCondition(1);
  tree.build(shapes, 0);

  CHECK_EQUAL( 1, tree.getLeft()->getLeft()->size() );
  CHECK_EQUAL( 1, tree.getLeft()->getRight()->size() );
  CHECK_EQUAL( 1, tree.getRight()->getLeft()->size() );
  CHECK_EQUAL( 1, tree.getRight()->getRight()->size() );


}
Пример #3
0
TEST(KDTree, shouldSupportIntersectionSearchForRegularNodes) {

  KDTree tree;
  
  vector<RTShape*> shapes;
  RTSphere sphere0(Vector(5,5,0), 1);
  RTSphere sphere1(Vector(5,-5,0), 1);
  RTSphere sphere2(Vector(-5,5,0), 1);
  RTSphere sphere3(Vector(-5,-5,0), 1);
  shapes.push_back(&sphere0);
  shapes.push_back(&sphere1);
  shapes.push_back(&sphere2);
  shapes.push_back(&sphere3);

  BoundingBox box(Vector(-6,-6,-6), Vector(12,12,12));
  tree.setBoundingBox(box);
  tree.setTerminationCondition(1);
  tree.build(shapes, 0);

  Ray ray(Vector(-10, 5, 0 ), Vector(1,0,0));
  IntersectionPtr intersection = tree.intersect(ray);
  
  CHECK( intersection != nullptr );
  CHECK( intersection->getShape() == &sphere2 );

}
void BoundingSphere::Test()
{
	BoundingSphere sphere1(Vector3f(0.0f, 0.0f, 0.0f), 1.0f);
	BoundingSphere sphere2(Vector3f(0.0f, 3.0f, 0.0f), 1.0f);
	BoundingSphere sphere3(Vector3f(0.0f, 0.0f, 2.0f), 1.0f);
	BoundingSphere sphere4(Vector3f(1.0f, 0.0f, 0.0f), 1.0f);
	
	IntersectData sphere1IntersectSphere2 = sphere1.IntersectBoundingSphere(sphere2);
	IntersectData sphere1IntersectSphere3 = sphere1.IntersectBoundingSphere(sphere3);
	IntersectData sphere1IntersectSphere4 = sphere1.IntersectBoundingSphere(sphere4);
	
	assert(sphere1IntersectSphere2.GetDoesIntersect() == false);
	assert(sphere1IntersectSphere2.GetDistance()      == 1.0f);

	assert(sphere1IntersectSphere3.GetDoesIntersect() == false);
	assert(sphere1IntersectSphere3.GetDistance()      == 0.0f);

	assert(sphere1IntersectSphere4.GetDoesIntersect() == true);
	assert(sphere1IntersectSphere4.GetDistance()      == -1.0f);

//	std::cout << "Sphere1 intersect Sphere2: " << sphere1IntersectSphere2.GetDoesIntersect() 
//	          << ", Distance: "                << sphere1IntersectSphere2.GetDistance() << std::endl;
//	std::cout << "Sphere1 intersect Sphere3: " << sphere1IntersectSphere3.GetDoesIntersect() 
//	          << ", Distance: "                << sphere1IntersectSphere3.GetDistance() << std::endl;
//	std::cout << "Sphere1 intersect Sphere4: " << sphere1IntersectSphere4.GetDoesIntersect() 
//	          << ", Distance: "                << sphere1IntersectSphere4.GetDistance() << std::endl;
}
Пример #5
0
void SphereScene::init(){
	if(_loaded){
		return;
	}
	_loaded = true;
	
	// Objects creation.
	Object sphere1(Object::Type::Regular, "sphere", { {"sphere_wood_lacquered_albedo", true }, {"sphere_wood_lacquered_normal", false}, {"sphere_wood_lacquered_rough_met_ao", false}});
	Object sphere2(Object::Type::Regular, "sphere", { {"sphere_gold_worn_albedo", true }, {"sphere_gold_worn_normal", false}, {"sphere_gold_worn_rough_met_ao", false}});
	const glm::mat4 model1 = glm::translate(glm::scale(glm::mat4(1.0f),glm::vec3(0.3f)), glm::vec3(1.2f,0.0f, 0.0f));
	const glm::mat4 model2 = glm::translate(glm::scale(glm::mat4(1.0f),glm::vec3(0.3f)), glm::vec3(-1.2f,0.0f, 0.0f));
	sphere1.update(model1);
	sphere2.update(model2);
	
	objects.push_back(sphere1);
	objects.push_back(sphere2);
	
	// Background creation.
	backgroundReflection = Resources::manager().getCubemap("studio", {GL_RGB32F})->id;
	background = Object(Object::Type::Skybox, "skybox", {}, {{"studio", false }});
	loadSphericalHarmonics("studio_shcoeffs");
	
	// Compute the bounding box of the shadow casters.
	const BoundingBox bbox = computeBoundingBox(true);
	// Lights creation.
	// Create directional light.
	//directionalLights.emplace_back(glm::vec3(-2.0f, -1.5f, 0.0f), glm::vec3(3.0f), bbox);
	// Create point lights.
	pointLights.emplace_back( glm::vec3(0.5f,-0.1f,0.5f), 6.0f*glm::vec3(0.2f,0.8f,1.2f), 0.9f, bbox);
	pointLights.emplace_back( glm::vec3(-0.5f,-0.1f,0.5f), 6.0f*glm::vec3(2.1f,0.3f,0.6f), 0.9f, bbox);
	
}
Пример #6
0
void CapsuleTest::collisionSphere() {
    Shapes::Capsule3D capsule({-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, 2.0f);
    Shapes::Sphere3D sphere({3.0f, 0.0f, 0.0f}, 0.9f);
    Shapes::Sphere3D sphere1({3.5f, 1.0f, 0.0f}, 0.6f);
    Shapes::Sphere3D sphere2({1.0f, 4.1f, 0.0f}, 1.0f);

    VERIFY_COLLIDES(capsule, sphere);
    VERIFY_COLLIDES(capsule, sphere1);
    VERIFY_NOT_COLLIDES(capsule, sphere2);
}
Пример #7
0
void CylinderTest::collisionSphere() {
    Shapes::Cylinder3D cylinder({-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, 2.0f);
    Shapes::Sphere3D sphere({3.0f, 0.0f, 0.0f}, 0.9f);
    Shapes::Sphere3D sphere1({1.0f, 4.1f, 0.0f}, 1.0f);
    Shapes::Sphere3D sphere2({3.5f, -1.0f, 0.0f}, 0.6f);

    VERIFY_COLLIDES(cylinder, sphere);
    VERIFY_COLLIDES(cylinder, sphere1);
    VERIFY_NOT_COLLIDES(cylinder, sphere2);
}
Пример #8
0
void drawScene(){
	
	if(angRot >= 360)
		angRot -= 360;
	else if(angRot < 0)
		angRot += 360;
	GLfloat tan = (obsP[0]/(GLfloat)raio)/(obsP[2]/(GLfloat)raio);
	GLfloat angLook = atan(tan);
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Eixos
	glColor4f(BLACK);
	glBegin(GL_LINES);
		glVertex3i( 0, 0, 0); 
		glVertex3i(xC, 0, 0); 
	glEnd();
	glBegin(GL_LINES);
		glVertex3i(0, 0, 0); 
		glVertex3i(0, yC, 0); 
	glEnd();
	glBegin(GL_LINES);
		glVertex3i( 0, 0, 0); 
		glVertex3i( 0, 0,zC); 
	glEnd();
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Sphere
	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glPushMatrix();
		if(angRot > angLook+90 && angRot < angLook+270)
			sphere2();
		else
			sphere1();
	glPopMatrix();
	
	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glPushMatrix();
		if(angRot > angLook+90 && angRot < angLook+270)
			sphere1();
		else
			sphere2();
	glPopMatrix();
}
Пример #9
0
void SphereTest::collisionSphere() {
    Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f);
    Physics::Sphere3D sphere1({1.0f, 3.0f, 5.0f}, 1.0f);
    Physics::Sphere3D sphere2({1.0f, 3.0f, 0.0f}, 1.0f);

    randomTransformation(sphere);
    randomTransformation(sphere1);
    randomTransformation(sphere2);

    VERIFY_COLLIDES(sphere, sphere1);
    VERIFY_NOT_COLLIDES(sphere, sphere2);
}
Пример #10
0
void CapsuleTest::collisionSphere() {
    Physics::Capsule3D capsule({-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, 2.0f);
    Physics::Sphere3D sphere({3.0f, 0.0f, 0.0f}, 0.9f);
    Physics::Sphere3D sphere1({3.5f, 1.0f, 0.0f}, 0.6f);
    Physics::Sphere3D sphere2({1.0f, 4.1f, 0.0f}, 1.0f);

    randomTransformation(capsule);
    randomTransformation(sphere);
    randomTransformation(sphere1);
    randomTransformation(sphere2);

    VERIFY_COLLIDES(capsule, sphere);
    VERIFY_COLLIDES(capsule, sphere1);
    VERIFY_NOT_COLLIDES(capsule, sphere2);
}
Пример #11
0
void buildAndRenderScene(Scene &scene, Camera &camera, RenderTarget &renderTarget)
{
    // Build scene
    AmbientLight        ambientLight(Color::white);
    PointLight          light1(Vector3D(50.0, 70.0, 0.0));
    PointLight          light2(Vector3D(50.0, 70.0, 200.0));

    Torus               sphere1(10, 4, Vector3D(0.0, 20.0, 100.0));
    PhongMaterial       material1(Color::red);

    Sphere              sphere2(10, Vector3D(0.0, 45.0, 100.0));
    PhongMaterial       material2(Color::green);

    Sphere              sphere3(10, Vector3D(35.0, 20.0, 100.0));
    PhongMaterial       material3(Color::blue);

    Plane               plane1(Vector3D(0, 0, 0), Vector3D(0.0, 1.0, 0.0));
    PhongMaterial       material4(Color(0.0, 1.0, 1.0));

    Plane               plane2(Vector3D(-100, 0, 0), Vector3D(1.0, 0.0, 0.0));
    PhongMaterial       material5(Color(1.0, 0.0, 1.0));

    Plane               plane3(Vector3D(0, 0, 500), Vector3D(0.0, 0.0, -1.0));
    PhongMaterial       material6(Color(1.0, 1.0, 0.0));

    sphere1.setMaterial(&material1);
    sphere2.setMaterial(&material2);
    sphere3.setMaterial(&material3);
    plane1.setMaterial(&material4);
    plane2.setMaterial(&material5);
    plane3.setMaterial(&material6);
    
    scene.addObject(&sphere1);
    scene.addObject(&sphere2);
    scene.addObject(&sphere3);
    scene.addObject(&plane1);
    scene.addObject(&plane2);
    scene.addObject(&plane3);

    scene.addLight(&light1);
    scene.addLight(&light2);
    scene.setAmbientLight(&ambientLight);

    // Render scene
    camera.computeFrame();
    camera.renderScene(scene, renderTarget);
    renderTarget.update();
}
Пример #12
0
TEST(KDTree, shapesCanBeInTwoVoxelsIfOnEdge) {
 
  KDTree tree;

  vector<RTShape*> shapes;
  RTSphere sphere0(Vector(-5,0,0), 1);
  RTSphere sphere1(Vector(5,0,0), 1);
  RTSphere sphere2(Vector(0,0,0), 1);
  shapes.push_back(&sphere0);
  shapes.push_back(&sphere1);
  shapes.push_back(&sphere2);

  BoundingBox box(Vector(-6, -1, -1), Vector(12, 2, 2));
  tree.setBoundingBox(box);
  tree.setTerminationCondition(2);
  tree.build(shapes, 0);

  CHECK_EQUAL( 2, tree.getLeft()->size() );
  CHECK_EQUAL( 2, tree.getRight()->size() ); 
}
Пример #13
0
TEST(collideWorld, sphere2sphere)
{
	Vector3 p1(0.0f, 0.0f, 0.0f);
	Vector3 p2(1.0f, 0.0f, 0.0f);
	float r1 = 0.5f;
	float r2 = 0.51f;
	Sphere sphere1(p1, r1);
	Sphere sphere2(p2, r2);
	CollidableObject object1(&sphere1, p1, 0);
	CollidableObject object2(&sphere2, p1, 1);
	Collide collide;
/**
	CollisionWorld world;
	world.addObject(object1);
	world.addObject(object2);
	world.computeCollision();

	printf("# of objects: %d\n", world.getObjectSize());
	printf("# of collides: %d\n", world.getCollideSize());
*/
}
Пример #14
0
int main(int argc, char** argv)
{
	/* Parse options */
	parseOption(argc, argv);
	/* Print to file */
	printf("output : %s\n", filename);
	printf("count  : %d\n", count);
	printf("xmin   : %lf\n", xmin);
	printf("ymin   : %lf\n", ymin);
	printf("zmin   : %lf\n", zmin);
	printf("mmin   : %lf\n", mmin);
	printf("xmax   : %lf\n", xmax);
	printf("ymax   : %lf\n", ymax);
	printf("zmax   : %lf\n", zmax);
	printf("mmax   : %lf\n", mmax);

	//random1();
	//sphere();
	sphere2();

	return(EXIT_SUCCESS);
}
Пример #15
0
void Plane::Test()
{
	BoundingSphere sphere1(Vector3f(0.0f, 0.0f, 0.0f), 1.0f);
	BoundingSphere sphere2(Vector3f(0.0f, 3.0f, 0.0f), 1.0f);
	BoundingSphere sphere3(Vector3f(0.0f, 0.0f, 2.0f), 1.0f);
	BoundingSphere sphere4(Vector3f(1.0f, 0.0f, 0.0f), 1.0f);

	Plane plane1(Vector3f(0.0f, 1.0f, 0.0f), 0.0f);
	
	IntersectData plane1IntersectSphere1 = plane1.IntersectSphere(sphere1);
	IntersectData plane1IntersectSphere2 = plane1.IntersectSphere(sphere2);
	IntersectData plane1IntersectSphere3 = plane1.IntersectSphere(sphere3);
	IntersectData plane1IntersectSphere4 = plane1.IntersectSphere(sphere4);

	assert(plane1IntersectSphere1.GetDoesIntersect() == true);
	assert(plane1IntersectSphere1.GetDistance()      == 1.0f);

	assert(plane1IntersectSphere2.GetDoesIntersect() == false);
	assert(plane1IntersectSphere2.GetDistance()      == 2.0f);

	assert(plane1IntersectSphere3.GetDoesIntersect() == true);
	assert(plane1IntersectSphere3.GetDistance()      == 1.0f);
	
	assert(plane1IntersectSphere4.GetDoesIntersect() == true);
	assert(plane1IntersectSphere4.GetDistance()      == 1.0f);

//	std::cout << "Plane1 intersect Sphere1: " << plane1IntersectSphere1.GetDoesIntersect() 
//	          << ", Distance: "               << plane1IntersectSphere1.GetDistance() << std::endl;
//	
//	std::cout << "Plane1 intersect Sphere2: " << plane1IntersectSphere2.GetDoesIntersect() 
//	          << ", Distance: "               << plane1IntersectSphere2.GetDistance() << std::endl;
//	
//	std::cout << "Plane1 intersect Sphere3: " << plane1IntersectSphere3.GetDoesIntersect() 
//	          << ", Distance: "               << plane1IntersectSphere3.GetDistance() << std::endl;
//	
//	std::cout << "Plane1 intersect Sphere4: " << plane1IntersectSphere4.GetDoesIntersect() 
//	          << ", Distance: "               << plane1IntersectSphere4.GetDistance() << std::endl;
}
Пример #16
0
void ShadowMapping::initialize(){

    std::shared_ptr<gland::BaseController> cameraController(new gland::CameraController(camera_, window_));
    std::shared_ptr<gland::BaseController> smController(new gland::SMController(params_, window_));
    controllers_.push_back(cameraController);  
    controllers_.push_back(smController);

    glfwSetKeyCallback(window_, &gland::Controller<gland::SMController>::keyCallback);

    params_["offsetFactor"] = gland::Param("Polygon offset factor");
    params_["offsetFactor"] = 4.0f;
    params_["offsetUnits"] = gland::Param("Polygon offset units");
    params_["offsetUnits"] = 4.0f;
    params_["renderDepth"] = gland::Param("Render depth");
    params_["renderDepth"] = false;
    params_["manualLight"] = gland::Param("Manual light");
    params_["manualLight"] = false;
    params_["angle"] = 0.0f;
    params_["lightSpeed"] = gland::Param("Light Rotation Speed");
    params_["lightSpeed"] = 1.0f;
    params_["lightRadius"] = gland::Param("Light circ. radius");
    params_["lightRadius"] = 10.0f;

    cameraController->generateHelpText(help_);
    smController->generateHelpText(help_);

    gland::ShaderDough shaderDough;
    
    shaderDough.addShaderFromFile("../src/shaders/shadowmapping_vs.glsl", GL_VERTEX_SHADER);
    shaderDough.addShaderFromFile("../src/shaders/shadowmapping_fs.glsl", GL_FRAGMENT_SHADER);

    gland::ShaderManager shaderManager;

    nViewProgram_ = shaderManager.cookDough(shaderDough);

    shaderPrograms_.push_back(nViewProgram_);

    //Light program
    gland::ShaderDough lightDough;
    
    lightDough.addShaderFromFile("../src/shaders/shadowmappinglight_vs.glsl", GL_VERTEX_SHADER);
    lightDough.addShaderFromFile("../src/shaders/shadowmappinglight_fs.glsl", GL_FRAGMENT_SHADER);

    nLightProgram_ = shaderManager.cookDough(lightDough);

    shaderPrograms_.push_back(nLightProgram_);

    //Depth program
    gland::ShaderDough depthDough;
    
    depthDough.addShaderFromFile("../src/shaders/shadowmappingdepth_vs.glsl", GL_VERTEX_SHADER);
    depthDough.addShaderFromFile("../src/shaders/shadowmappingdepth_fs.glsl", GL_FRAGMENT_SHADER);

    nDepthProgram_ = shaderManager.cookDough(depthDough);

    shaderPrograms_.push_back(nDepthProgram_);

    //Light source program
    gland::ShaderDough lightSourceDough;
    lightSourceDough.addShaderFromFile("../src/shaders/lightsource_vs.glsl", GL_VERTEX_SHADER);
    lightSourceDough.addShaderFromFile("../src/shaders/lightsource_fs.glsl", GL_FRAGMENT_SHADER);
    nLightSourceProgram_ = shaderManager.cookDough(lightSourceDough);
    shaderPrograms_.push_back(nLightSourceProgram_);

    //Frame buffer for depth
    glGenFramebuffers(1, &nDepthFbo_);
    glBindFramebuffer(GL_FRAMEBUFFER, nDepthFbo_);

    glGenTextures(1, &nDepthTex_);
    glBindTexture(GL_TEXTURE_2D, nDepthTex_);
    glTexStorage2D(GL_TEXTURE_2D, 11, GL_DEPTH_COMPONENT32F, DEPTH_TEXTURE_SIZE, DEPTH_TEXTURE_SIZE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

    glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, nDepthTex_, 0);

    glGenTextures(1, &nDepthDebug_);
    glBindTexture(GL_TEXTURE_2D, nDepthDebug_);
    glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32F, DEPTH_TEXTURE_SIZE, DEPTH_TEXTURE_SIZE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, nDepthDebug_, 0);

    glBindTexture(GL_TEXTURE_2D, 0);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);


    //VAO for drawing depth texture
    glGenVertexArrays(1, &nQuadVao_);
    glBindVertexArray(nQuadVao_);


    glEnable(GL_DEPTH_TEST);

    //Add object
    std::string inputfile = "../res/sphere.obj";
    std::vector<tinyobj::shape_t> shapes;
    std::string err = tinyobj::LoadObj(shapes, inputfile.c_str());
    std::shared_ptr<gland::Body> obj(new gland::Body(shapes[0]));
    obj->setShader(nViewProgram_);
    obj->translate(3.0f, 0.0f, -3.0f);
    standardObjects_.push_back(obj);

    //Add another sphere
    std::shared_ptr<gland::Body> sphere2(new gland::Body(shapes[0]));
    sphere2->setShader(nViewProgram_);
    sphere2->translate(-10.0f, -0.0f, -2.0f);
    standardObjects_.push_back(sphere2);

    inputfile = "../res/thickblock.obj";
    err = tinyobj::LoadObj(shapes, inputfile.c_str());
    std::shared_ptr<gland::Body> floor(new gland::Body(shapes[0]));
    floor->setShader(nViewProgram_);
    floor->rotate(0.0f, 1.0f, 0.0f, 0.0f);
    floor->translate(0.0f, 0.0f, -5.0f);
    standardObjects_.push_back(floor);

    inputfile = "../res/monkey.obj";
    err = tinyobj::LoadObj(shapes, inputfile.c_str());
    std::shared_ptr<gland::Body> monkey(new gland::Body(shapes[0]));
    monkey->setShader(nViewProgram_);
    monkey->translate(-2.0f, -0.0f, 0.0f);
    standardObjects_.push_back(monkey);

    inputfile = "../res/light.obj";
    err = tinyobj::LoadObj(shapes, inputfile.c_str());
    std::shared_ptr<gland::Body> lightSource(new gland::Body(shapes[0]));
    lightSource->setShader(nLightSourceProgram_);
    lightSources_.push_back(lightSource);

    glEnable (GL_CULL_FACE); // cull face
    glCullFace (GL_BACK); // cull back face
    //glFrontFace (GL_CW); // GL_CCW for counter clock-wise
            
    //Look at center
    camera_->lookAt(glm::vec3(0.0f, 0.0f, 20.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));

}
Пример #17
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   const double len=1.5;  //  Length of axes
   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);
   //  Undo previous transformations
   glLoadIdentity();
   //  Set view angle
   glRotatef(ph,1,0,0);
   glRotatef(th,0,1,0);
   //  Decide what to draw
   switch (mode)
   {
      //  Draw cubes
      case 0:
         cube(0,0,0 , 0.3,0.3,0.3 , 0);
         cube(1,0,0 , 0.2,0.2,0.2 , 45);
         cube(0,1,0 , 0.4,0.4,0.2 , 90);
         break;
      //  Draw spheres
      case 1:
         sphere1(0,0,0 , 0.4);
         sphere1(1,0,0 , 0.2);
         sphere2(0,1,0 , 0.2);
         break;
      //  Line airplane
      case 2:
         PolyPlane(GL_LINE_LOOP , 0,0,0);
         break;
      //  Polygon airplane
      case 3:
         PolyPlane(GL_POLYGON , 0,0,0);
         break;
      //  Three flat airplanes
      case 4:
         FlatPlane( 0.0, 0.0, 0.0);
         FlatPlane(-0.5, 0.5,-0.5);
         FlatPlane(-0.5,-0.5,-0.5);
         break;
      // Three solid airplanes
      case 5:
         SolidPlane( 0, 0, 0 , 1,0,0 , 0, 1,0);
         SolidPlane(-1, 1, 0 ,-1,0,0 , 0,-1,0);
         SolidPlane(-1,-1, 0 ,-1,0,0 , 0, 1,0);
         break;
      // Mix of objects
      case 6:
         //  Cube
         cube(-1,0,0 , 0.3,0.3,0.3 , 3*zh);
         //  Ball
         sphere1(0,0,0 , 0.3);
         //  Solid Airplane
         SolidPlane(Cos(zh),Sin(zh), 0 ,-Sin(zh),Cos(zh),0 , Cos(4*zh),0,Sin(4*zh));
         //  Utah Teapot
         glPushMatrix();
         glTranslatef(0,0,-1);
         glRotatef(zh,0,1,0);
         glColor3f(Cos(zh)*Cos(zh),0,Sin(zh)*Sin(zh));
         glutSolidTeapot(0.5);
         glPopMatrix();
         break;
   }
   //  White
   glColor3f(1,1,1);
   //  Draw axes
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Five pixels from the lower left corner of the window
   glWindowPos2i(5,5);
   //  Print the text string
   Print("Angle=%d,%d",th,ph);
   //  Render the scene
   glFlush();
   //  Make the rendered scene visible
   glutSwapBuffers();
}
Пример #18
0
Scene * D3D::BuildScene(IDirect3DDevice9 *d3dDevice)
 {
	 // Setup some materials - we'll use these for 
	 // making the same mesh appear in multiple
	 // colors

	 D3DMATERIAL9 colors[8];
	 D3DUtil_InitMaterial( colors[0], 1.0f, 1.0f, 1.0f, 1.0f );	// white
	 D3DUtil_InitMaterial( colors[1], 0.0f, 1.0f, 1.0f, 1.0f );	// cyan
	 D3DUtil_InitMaterial( colors[2], 1.0f, 0.0f, 0.0f, 1.0f );	// red
	 D3DUtil_InitMaterial( colors[3], 0.0f, 1.0f, 0.0f, 1.0f );	// green
	 D3DUtil_InitMaterial( colors[4], 0.0f, 0.0f, 1.0f, 1.0f );	// blue
	 D3DUtil_InitMaterial( colors[5], 0.4f, 0.4f, 0.4f, 0.4f );	// 40% grey
	 D3DUtil_InitMaterial( colors[6], 0.25f, 0.25f, 0.25f, 0.25f );	// 25% grey
	 D3DUtil_InitMaterial( colors[7], 0.65f, 0.65f, 0.65f, 0.65f );	// 65% grey

	 // The identity matrix is always useful
	 D3DXMATRIX ident;
	 D3DXMatrixIdentity(&ident);

	 // We'll use these rotations for some teapots and grid objects
	 D3DXMATRIX rotateX, rotateY, rotateZ;

	 // Create the root, and the camera.
	 // Remeber how to use smart pointers?? I hope so!

	 boost::shared_ptr<TransformNode> root(new TransformNode(&ident));

	 boost::shared_ptr<CameraNode> camera(new CameraNode(&ident));
	 root->m_children.push_back(camera);



	 // We'll put the camera in the scene at (20,20,20) looking back at the Origin

	 D3DXMATRIX rotOnly, result, inverse;
	 float cameraYaw = - (3.0f * D3DX_PI) / 4.0f;
	 float cameraPitch = D3DX_PI / 4.0f;
	 D3DXQUATERNION q;
	 D3DXQuaternionIdentity(&q);
	 D3DXQuaternionRotationYawPitchRoll(&q, cameraYaw, cameraPitch, 0.0);
	 D3DXMatrixRotationQuaternion(&rotOnly, &q);

	 D3DXMATRIX trans;
	 D3DXMatrixTranslation(&trans, 15.0f, 15.0f, 15.0f);

	 D3DXMatrixMultiply(&result, &rotOnly, &trans);

	 D3DXMatrixInverse(&inverse, NULL, &result);
	 camera->VSetTransform(&result, &inverse);

	 D3DXMatrixRotationZ(&rotateZ, D3DX_PI / 2.0f);
	 D3DXMatrixRotationX(&rotateX, -D3DX_PI / 2.0f);
	 D3DXVECTOR3 target(30, 2, 15);

	 //

	

	 ID3DXMesh *teapot;
	 if( SUCCEEDED( D3DXCreateTeapot( d3dDevice, &teapot, NULL ) ) )
	 {
		 // Teapot #1 - a white one at (x=6,y=2,z=4)
		 D3DXMatrixTranslation(&trans,6,2,4);

		 boost::shared_ptr<SceneNode> mesh1(new MeshNode(teapot, &trans, colors[2]));
		 root->m_children.push_back(mesh1);

		 // Teapot #2 - a cyan one at (x=3,y=2,z=1)
		 //   with a 
		 D3DXMatrixTranslation(&trans, 3,2,1);
		 D3DXMATRIX result;
		 D3DXMatrixMultiply(&result, &rotateZ, &trans);

		 boost::shared_ptr<SceneNode> mesh2(new MeshNode(teapot, &result, colors[1]));
		 root->m_children.push_back(mesh2);

		 // Teapot #3 - another white one at (x=30, y=2, z=15)
		 D3DXMATRIX rotateY90;
		 D3DXMatrixRotationY(&rotateY90, D3DX_PI / 2.0f);
		 D3DXMatrixTranslation(&trans, target.x, target.y, target.z);
		 D3DXMatrixMultiply(&result, &rotateY90, &trans);
		 boost::shared_ptr<SceneNode> mesh3(new MeshNode(teapot, &result, colors[0]));
		 root->m_children.push_back(mesh3);

		 // We can release the teapot now, mesh1 and mesh2 AddRef'd it.
		 SAFE_RELEASE(teapot);
	 }

	 ID3DXMesh *sphere;
	 if ( SUCCEEDED( 
		 D3DXCreateSphere( 
		 d3dDevice, .25, 16, 16, &sphere, NULL) ) )
	 {
		 // We're going to create a spiral of spheres...
		 // starting at (x=3, y=0, z=3), and spiraling
		 // upward about a local Y axis.

		 D3DXMatrixTranslation(&trans, 3,0,3);

		 boost::shared_ptr<SceneNode> sphere1(new MeshNode(sphere, &trans, colors[4]) );
		 root->m_children.push_back(sphere1);

		 // Here's the local rotation and translation.
		 // We'll rotate about Y, and then translate
		 // up (along Y) and forward (along Z).
		 D3DXMatrixRotationY(&rotateY, D3DX_PI / 8.0f);
		 D3DXMATRIX trans2;
		 D3DXMatrixTranslation(&trans2, 0, 0.5, 0.5);
		 D3DXMatrixMultiply(&result, &trans2, &rotateY);

		 for (int i=0; i<25; i++)
		 {
			 // If you didn't think smart pointers were cool - 
			 // watch this! No leaked memory....

			 // Notice this is a heirarchy....
			 boost::shared_ptr<SceneNode> sphere2(new MeshNode(sphere, &result, colors[i%5]) );
			 sphere1->m_children.push_back(sphere2);
			 sphere1 = sphere2;
		 }

		 // We can release the sphere now, all the cylinders AddRef'd it.
		 SAFE_RELEASE(sphere);
	 }
	 

	 //
	 D3DXMatrixTranslation(&trans,-25,20,20);
	 //D3DXMatrixScaling(&trans, -10, -10, -10);
	 ScaleMtrl scale;
	 scale.x = -50.0f;
	 scale.y = -50.0f;
	 scale.z = -50.0f;
	 boost::shared_ptr<SceneNode> xmesh1(new XMeshNode(L"gf3.x", d3dDevice, &trans, &scale));
	 root->m_children.push_back(xmesh1);

	 
	  root->m_children.push_back(xmesh1);

	 /*D3DXMatrixTranslation(&trans,-45,20,20);
	 boost::shared_ptr<SceneNode> xmesh11(new XMeshNode(L"gf3.x", d3dDevice, &trans, &scale));
	 root->m_children.push_back(xmesh11);*/


	  XMeshNode *mm = new XMeshNode(L"gow_m1.x", d3dDevice, &trans, &scale);

	 D3DXMatrixTranslation(&trans,10,10,10);
	 //D3DXMatrixScaling(&trans, -10, -10, -10);
	 //ScaleMtrl scale;
	 scale.x = 100.0f;
	 scale.y = 100.0f;
	 scale.z = 100.0f;
	 boost::shared_ptr<SceneNode> xmesh2( new XMeshNode(L"gow_m1.x", d3dDevice, &trans, &scale));
	 root->m_children.push_back(xmesh2);

	 
	 
	 /*D3DXMatrixTranslation(&trans,20,20,20);
	 boost::shared_ptr<SceneNode> xmesh3(new XMeshNode(mm->m_mesh, mm->Mtrls, mm->Textures, &trans, 0));
	 root->m_children.push_back(xmesh3);*/

	 int col = 10;
	 int row= 10;
	 int zoom = 10;
	 const int COUNT = 13;
	 for(int i = 0; i < COUNT; i++)
	 {
		 for (int j = 0; j< COUNT; j++)
		 {
			 for(int z = 0; z< COUNT; z++)
			 {
				 D3DXMatrixTranslation(&trans, col + i, row + j , zoom + z);
				 boost::shared_ptr<SceneNode> xmeshNew(new XMeshNode(mm->m_mesh, mm->Mtrls, mm->Textures, &trans, 0));
				 root->m_children.push_back(xmeshNew);
			 }
		 }
	 }


	 //D3DXMatrixScaling(&trans, 10, 10, 10);

	 // Here are the grids...they make it easy for us to 
	 // see where the coordinates are in 3D space.
	 boost::shared_ptr<SceneNode> grid1(new Grid(40, 0x00404040, L"Textures\\grid.dds", &ident));
	 root->m_children.push_back(grid1);
	 boost::shared_ptr<SceneNode> grid2(new Grid(40, 0x00004000, L"Textures\\grid.dds", &rotateX));
	 root->m_children.push_back(grid2);
	 boost::shared_ptr<SceneNode> grid3(new Grid(40, 0x00000040, L"Textures\\grid.dds", &rotateZ));
	 root->m_children.push_back(grid3);

	 //  Here's the sky node that never worked!!!!
	 boost::shared_ptr<SkyNode> sky(new SkyNode(_T("Sky2"), camera));
	 root->m_children.push_back(sky);

	 D3DXMatrixTranslation(&trans,15,2,15);
	 D3DXMatrixRotationY(&rotateY, D3DX_PI / 4.0f);
	 D3DXMatrixMultiply(&result, &rotateY, &trans);

	 boost::shared_ptr<SceneNode> arrow1(new ArrowNode(2, &result, colors[0], d3dDevice));
	 root->m_children.push_back(arrow1);

	 D3DXMatrixRotationY(&rotateY, D3DX_PI / 2.0f);
	 D3DXMatrixMultiply(&result, &rotateY, &trans);
	 boost::shared_ptr<SceneNode> arrow2(new ArrowNode(2, &result, colors[5], d3dDevice));
	 root->m_children.push_back(arrow2);

	 D3DXMatrixMultiply(&result, &rotateX, &trans);
	 boost::shared_ptr<SceneNode> arrow3(new ArrowNode(2, &result, colors[0], d3dDevice));
	 root->m_children.push_back(arrow3);


	 // Everything has been attached to the root. Now
	 // we attach the root to the scene.

	 Scene *scene = new Scene(d3dDevice, root);
	 scene->Restore();

	 // A movement controller is going to control the camera, 
	 // but it could be constructed with any of the objects you see in this
	 // function. You can have your very own remote controlled sphere. What fun...
	 boost::shared_ptr<MovementController> m_pMovementController(new MovementController(camera, cameraYaw, cameraPitch));

	 scene->m_pMovementController = m_pMovementController;
	 return scene;
 }
Пример #19
0
BaseIF* makeGeometry(Box&      a_domain,
                     RealVect& a_origin,
                     Real&     a_dx)
{
  RealVect center1;
  Real     radius1;

  RealVect center2;
  Real     radius2;

  bool     insideRegular;

  // parse input file
  ParmParse pp;

  Vector<int> n_cell(SpaceDim);
  pp.getarr("n_cell",n_cell,0,SpaceDim);

 CH_assert(n_cell.size() == SpaceDim);

  IntVect lo = IntVect::Zero;
  IntVect hi;

  for (int ivec = 0; ivec < SpaceDim; ivec++)
  {
    if (n_cell[ivec] <= 0)
    {
      pout() << "Bogus number of cells input = " << n_cell[ivec];
      exit(1);
    }

    hi[ivec] = n_cell[ivec] - 1;
  }

  a_domain.setSmall(lo);
  a_domain.setBig(hi);

  Vector<Real> prob_lo(SpaceDim,1.0);
  Real prob_hi;

  pp.getarr("prob_lo",prob_lo,0,SpaceDim);
  pp.get("prob_hi",prob_hi);

  a_dx = (prob_hi-prob_lo[0])/n_cell[0];

  for (int idir = 0; idir < SpaceDim; idir++)
  {
    a_origin[idir] = prob_lo[idir];
  }

  // ParmParse doesn't get RealVects, so work-around with Vector<Real>
  Vector<Real> vectorCenter;
  pp.getarr("center1",vectorCenter,0,SpaceDim);

  for (int idir = 0; idir < SpaceDim; idir++)
  {
    center1[idir] = vectorCenter[idir];
  }

  pp.get("radius1",radius1);

  pp.getarr("center2",vectorCenter,0,SpaceDim);

  for (int idir = 0; idir < SpaceDim; idir++)
  {
    center2[idir] = vectorCenter[idir];
  }

  pp.get("radius2",radius2);

  // Parm Parse doesn't get bools, so work-around with int
  int intInsideRegular;
  pp.get("insideRegular",intInsideRegular);

  if (intInsideRegular != 0) insideRegular = true;
  if (intInsideRegular == 0) insideRegular = false;

  // Stay inside until the end
  bool inside = true;

  // Sphere 1 is the given "radius1" and "center1"
  SphereIF sphere1(radius1,center1,inside);

  // Sphere 2 is the given "radius2" and "center2"
  SphereIF sphere2(radius2,center2,inside);

  // Take the union of the spheres
  UnionIF implicit(sphere1,sphere2);

  // Complement if necessary
  ComplementIF insideOut(implicit,!insideRegular);

  RealVect vectDx = RealVect::Unit;
  vectDx *= a_dx;

  GeometryShop workshop(insideOut,0,vectDx);

  // This generates the new EBIS
  EBIndexSpace* ebisPtr = Chombo_EBIS::instance();
  ebisPtr->define(a_domain,a_origin,a_dx,workshop);

  return insideOut.newImplicitFunction();
}