Example #1
0
void draw_shadow(int shad)
{
	int x = 0;
#ifdef GL_VERSION_1_1
  if (supportsOneDotOne() && !forceExtension) {
    polygonOffsetVersion = ONE_DOT_ONE;
    glPolygonOffset(-2.0, -1.0);
  } else
#endif
  {
#ifdef GL_EXT_polygon_offset
  /* check for the polygon offset extension */
  if (glutExtensionSupported("GL_EXT_polygon_offset")) {
    polygonOffsetVersion = EXTENSION;
    glPolygonOffsetEXT(-0.1, -0.002);
  } else 
#endif
    {
      polygonOffsetVersion = MISSING;
      //printf("\nMissing polygon offset.\n");
      //printf("Expect shadow depth aliasing artifacts.\n\n");
    }
  }
	findPlane(floorPlane, floorVertices[1], floorVertices[2], floorVertices[3]);
	redraw(shad);
}
Example #2
0
    KDTreeNode *KDTree::recursiveBuild(const std::vector<KDTreeNodeRef>& objectList, AABB &aabb, int currentDepth) {
        KDTreeNode *res = new KDTreeNode(aabb);
        if (terminateBuild(objectList, aabb, currentDepth)) {
            for (const KDTreeNodeRef & nodeRef : objectList) {
                res->objects.push_back(nodeRef);
            }
            return res;
        }
        findPlane(objectList, aabb, currentDepth, res);

        // split aabb with splitting plane
        AABB leftAabb(aabb);
        leftAabb.max[res->splittingAxis] = res->splittingPlane;
        AABB rightAabb(aabb);
        rightAabb.min[res->splittingAxis] = res->splittingPlane;

        vector < KDTreeNodeRef > leftObjects;
        vector < KDTreeNodeRef > rightObjects;
        for (const KDTreeNodeRef & nodeRef : objectList) {
            const AABB objectAABB = nodeRef.getAABB();
            if (leftAabb.intersect(objectAABB)) {
                leftObjects.push_back(nodeRef);
            }
            if (rightAabb.intersect(objectAABB)) {
                rightObjects.push_back(nodeRef);
            }
        }
        currentDepth++;
        res->leftChild = recursiveBuild(leftObjects, leftAabb, currentDepth);
        res->rightChild = recursiveBuild(rightObjects, rightAabb, currentDepth);
        return res;
    }
Example #3
0
TEST(Estimator,SE3PlaneRansac) {
    auto estimator=GSLAM::Estimator::create();
    if(!estimator.get())
    {
        LOG(WARNING)<<"Test aborded since estimator not created.";
        return ;
    }
    const double points_raw[] = {
        0,0,1,
        0,1,1,
        1,0,1,
        1,1,1,
        7,7,1,
        0,9,1,
        9,0,1,
        9,9,1,
        0,0,0,
        0,1,0};

    const size_t kNumPoints = 10;

    std::vector<GSLAM::Point3d> points(kNumPoints);
    for (size_t i = 0; i < kNumPoints; ++i) {
        points[i] = GSLAM::Point3d(points_raw[3 * i], points_raw[3 * i + 1], points_raw[3*i+2]);
    }

    GSLAM::SE3 plane;
    std::vector<uchar> inlier_mask;
    EXPECT_TRUE(estimator->findPlane(plane,points,GSLAM::RANSAC,0.02,&inlier_mask));

    EXPECT_FALSE(inlier_mask[8]);
    EXPECT_FALSE(inlier_mask[9]);

    for(int i=0;i<8;i++)
    {
        EXPECT_TRUE(fabs((plane.inverse()*points[i]).z)<0.01);
    }


}
Example #4
0
void
recursiveSplit(Node &n, int depth)
{
    const bool not_a_leaf{ false };
    const bool is_a_leaf { true  };

    if (n.numVoxels() <= svt::minVoxels) {
        n.isLeaf(is_a_leaf);
        std::cout << depth << ": Returning... numVoxels.\n";
        return;
    }

    if (n.percentEmpty() <= svt::minEmptyPercent){
        n.isLeaf(is_a_leaf);
        std::cout << depth << ": Returning... minEmptyPercent.\n";
        return;
    }

    Plane p{ findPlane(n.shortestAxis(), n.bv()) };

    Node left{ n.leftChild(),
               not_a_leaf,
               num(n.min(), p.max()),
               n.min(),
               p.max() - n.min() };
    recursiveSplit(left, depth + 1);

    Node right{ n.rightChild(),
                not_a_leaf,
                num(p.min(), n.max()),
                p.min(),
                n.max() - p.min() };
    recursiveSplit(right, depth + 1);

    svt::tree[left.index()] = left;
    svt::tree[right.index()] = right;
}
Example #5
0
void DrawScene()
{
    glPushMatrix();

    glDisable(GL_LIGHTING);
    glDisable(GL_TEXTURE_2D);

    //effet brouillard
    if(brouillard) {
        GLint fogmode; //Initialisation de fogmode
        GLfloat fogcolor[4] = {0.5, 0.5, 0.5, 1} ; //Initialisation de la couleur (RGBA)

        glEnable(GL_FOG); //Cela permet d'activer le mode GL_FOG
        fogmode = GL_EXP ;
        glFogi(GL_FOG_MODE, fogmode); //On range le mode fogmode dans la variable GL_FOG_MODE
        glFogfv(GL_FOG_COLOR, fogcolor); //On fait la meme chose pour la couleur et la variable GL_FOG_COLOR
        glFogf(GL_FOG_DENSITY, 0.05); //cela permet de definir la densite du brouillard (plus ou moins epais)
        glFogf(GL_FOG_START, 1.0);  //Debut du brouillard
        glFogf(GL_FOG_END, 5.0); //Fin du brouillar
    }
    else //desactiver effet brouillard
        glDisable(GL_FOG);

    /**********************************/

//effect du reflet
    if(reflet) {
        glDisable(GL_DEPTH_TEST);
        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
        glEnable(GL_STENCIL_TEST);
        glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
        glStencilFunc(GL_ALWAYS, 1, 0xffffffff);

        glDisable(GL_LIGHTING);
        glDisable(GL_TEXTURE_2D);

        DrawGrille();

        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
        glEnable(GL_DEPTH_TEST);

        glStencilFunc(GL_EQUAL, 1, 0xffffffff); /* draw if ==1 */
        glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

        glPushMatrix();
        glScalef(1.0, -1.0, 1.0);
        //glEnable(GL_LIGHTING);  glEnable(GL_TEXTURE_2D);
        glmDraw22( pmodel, GLM_SMOOTH | GLM_2_SIDED | GLM_MATERIAL | GLM_TEXTURE);
        glPopMatrix();

        glDisable(GL_STENCIL_TEST);


        glDisable(GL_LIGHTING);
        glDisable(GL_TEXTURE_2D);
        DrawPlateau();

    }
    else
        DrawPlateau();

    glEnable(GL_LIGHTING);
    glEnable(GL_TEXTURE_2D);
    glmDraw2( pmodel, GLM_SMOOTH | GLM_2_SIDED | GLM_MATERIAL | GLM_TEXTURE);

    /**********************************/
//effect d ombre
    if(ombre) {
        glPushMatrix();
        static GLfloat floorPlane[4];
        static GLfloat floorShadow[4][4];
        GLfloat light_pos[] = { .3, .5, .2, 0.0 };
        findPlane(floorPlane, vfloor[1], vfloor[2], vfloor[3]);
        shadowMatrix(floorShadow, floorPlane, light_pos);

        glMultMatrixf((GLfloat *) floorShadow);
        glmDraw22( pmodel, GLM_NONE);
        glPopMatrix();
    }
    glPopMatrix();
}
Example #6
0
int
main(int argc, char **argv)
{
  int i;

  glutInit(&argc, argv);

  for (i=1; i<argc; i++) {
    if (!strcmp("-linear", argv[i])) {
      linearFiltering = 1;
    } else if (!strcmp("-mipmap", argv[i])) {
      useMipmaps = 1;
    } else if (!strcmp("-ext", argv[i])) {
      forceExtension = 1;
    }
  }

  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL);

#if 0
  /* In GLUT 4.0, you'll be able to do this an be sure to
     get 2 bits of stencil if the machine has it for you. */
  glutInitDisplayString("samples stencil>=2 rgb double depth");
#endif

  glutCreateWindow("Shadowy Leapin' Lizards");
  glewInit();

  if (glutGet(GLUT_WINDOW_STENCIL_SIZE) <= 1) {
    printf("dinoshade: Sorry, I need at least 2 bits of stencil.\n");
    exit(1);
  }

  /* Register GLUT callbacks. */
  glutDisplayFunc(redraw);
  glutMouseFunc(mouse);
  glutMotionFunc(motion);
  glutVisibilityFunc(visible);
  glutKeyboardFunc(key);
  glutSpecialFunc(special);

  glutCreateMenu(controlLights);

  glutAddMenuEntry("Toggle motion", M_MOTION);
  glutAddMenuEntry("-----------------------", M_NONE);
  glutAddMenuEntry("Toggle light", M_LIGHT);
  glutAddMenuEntry("Toggle texture", M_TEXTURE);
  glutAddMenuEntry("Toggle shadows", M_SHADOWS);
  glutAddMenuEntry("Toggle reflection", M_REFLECTION);
  glutAddMenuEntry("Toggle dinosaur", M_DINOSAUR);
  glutAddMenuEntry("-----------------------", M_NONE);
  glutAddMenuEntry("Toggle reflection stenciling", M_STENCIL_REFLECTION);
  glutAddMenuEntry("Toggle shadow stenciling", M_STENCIL_SHADOW);
  glutAddMenuEntry("Toggle shadow offset", M_OFFSET_SHADOW);
  glutAddMenuEntry("----------------------", M_NONE);
  glutAddMenuEntry("Positional light", M_POSITIONAL);
  glutAddMenuEntry("Directional light", M_DIRECTIONAL);
  glutAddMenuEntry("-----------------------", M_NONE);
  glutAddMenuEntry("Toggle performance", M_PERFORMANCE);
  glutAttachMenu(GLUT_RIGHT_BUTTON);
  makeDinosaur();

#ifdef GL_VERSION_1_1
  if (GLEW_VERSION_1_1 && !forceExtension) {
    polygonOffsetVersion = ONE_DOT_ONE;
    glPolygonOffset(-2.0, -9.0);
  } else
#endif
  {
#ifdef GL_EXT_polygon_offset
  /* check for the polygon offset extension */
  if (GLEW_EXT_polygon_offset) {
    polygonOffsetVersion = EXTENSION;
    glPolygonOffsetEXT(-2.0, -0.002);
  } else 
#endif
    {
      polygonOffsetVersion = MISSING;
      printf("\ndinoshine: Missing polygon offset.\n");
      printf("           Expect shadow depth aliasing artifacts.\n\n");
      fflush(stdout);
    }
  }

  glEnable(GL_CULL_FACE);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_TEXTURE_2D);
  glLineWidth(3.0);

  glMatrixMode(GL_PROJECTION);
  gluPerspective( /* field of view in degree */ 40.0,
  /* aspect ratio */ 1.0,
    /* Z near */ 20.0, /* Z far */ 100.0);
  glMatrixMode(GL_MODELVIEW);
  gluLookAt(0.0, 8.0, 60.0,  /* eye is at (0,8,60) */
    0.0, 8.0, 0.0,      /* center is at (0,8,0) */
    0.0, 1.0, 0.);      /* up is in postivie Y direction */

  glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
  glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
  glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHTING);

  makeFloorTexture();

  /* Setup floor plane for projected shadow calculations. */
  findPlane(floorPlane, floorVertices[1], floorVertices[2], floorVertices[3]);

  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}
void display(void)

{
/* set clear color to white and clear window */

	//part 1 a & b
	GLfloat light[3]={10.0, 2.0, 0.0};

	GLfloat plane[4];
	GLfloat v1[3] = {-4.0, 2.0, 0.0};
	GLfloat v2[3] = {-4.0, 0.0, 5.0};
	GLfloat v3[3] = {-4.0, 1.0, 3.0};

	findPlane(plane, v1,v2,v3);
	
	GLfloat direction[3] = {-1.0, 0.0, 0.0};

	GLfloat m[16];

	double sin(), cos();

	int i;
	for(i=0;i<16;i++) m[i]=0.0;

	GLfloat a,b,c,d,dx,dy,dz;
	a=plane[0];
	b=plane[1];
	c=plane[2];
	d=plane[3];
	dx=direction[0];
	dy=direction[1];
	dz=direction[2];

	m[0]=b*dy+c*dz;
	m[1]=-a*dy;
	m[2]=-a*dz;
	m[4]=-b*dx;
	m[5]=a*dx+c*dz;
	m[6]=-b*dz;
	m[8]=-c*dx;
	m[9]=-c*dy;
	m[10]=a*dx+b*dy;
	m[12]=-d*dx;
	m[13]=-d*dy;
	m[14]=-d*dz;
	m[15]=a*dx+b*dy+c*dz;



	glClearColor (1.0, 1.0, 1.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

/* set drawing/fill  color to red */

	glColor3f(1.0, 0.0, 0.0);

/* set up standard orthogonal view with clipping */
/* box as cube of side 2 centered at origin */

	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	glOrtho(-15.0, 15.0, -15.0, 15.0, -15.0, 15.0); 

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0);

/* define unit square polygon */

	glBegin(GL_QUADS);
		glVertex3f( 0.0, 0.0, 0.0);		
		glVertex3f( 3.0, 0.0, 0.0);
		glVertex3f( 3.0, 0.0, 3.0);	
		glVertex3f( 0.0, 0.0, 3.0);

		glVertex3f( 0.0, 0.0, 0.0);		
		glVertex3f( 3.0, 0.0, 0.0);
		glVertex3f( 3.0, 3.0, 0.0);	
		glVertex3f( 0.0, 3.0, 0.0);

		glVertex3f( 0.0, 0.0, 0.0);		
		glVertex3f( 0.0, 3.0, 0.0);
		glVertex3f( 0.0, 3.0, 3.0);	
		glVertex3f( 0.0, 0.0, 3.0);


		glVertex3f( 0.0, 0.0, 3.0);		
		glVertex3f( 3.0, 0.0, 3.0);
		glVertex3f( 3.0, 3.0, 3.0);	
		glVertex3f( 0.0, 3.0, 3.0);

		glVertex3f( 0.0, 3.0, 3.0);		
		glVertex3f( 0.0, 3.0, 0.0);
		glVertex3f( 3.0, 3.0, 0.0);	
		glVertex3f( 3.0, 3.0, 3.0);
		
		glVertex3f( 3.0, 3.0, 3.0);		
		glVertex3f( 3.0, 3.0, 0.0);
		glVertex3f( 3.0, 0.0, 0.0);	
		glVertex3f( 3.0, 0.0, 3.0);

		glEnd();

	glPushMatrix();

	glMultMatrixf(m);

	glColor3f(0.0,0.0,0.0);
	glBegin(GL_QUADS);
		glVertex3f( 0.0, 0.0, 0.0);		
		glVertex3f( 3.0, 0.0, 0.0);
		glVertex3f( 3.0, 0.0, 3.0);	
		glVertex3f( 0.0, 0.0, 3.0);

		glVertex3f( 0.0, 0.0, 0.0);		
		glVertex3f( 3.0, 0.0, 0.0);
		glVertex3f( 3.0, 3.0, 0.0);	
		glVertex3f( 0.0, 3.0, 0.0);

		glVertex3f( 0.0, 0.0, 0.0);		
		glVertex3f( 0.0, 3.0, 0.0);
		glVertex3f( 0.0, 3.0, 3.0);	
		glVertex3f( 0.0, 0.0, 3.0);


		glVertex3f( 0.0, 0.0, 3.0);		
		glVertex3f( 3.0, 0.0, 3.0);
		glVertex3f( 3.0, 3.0, 3.0);	
		glVertex3f( 0.0, 3.0, 3.0);

		glVertex3f( 0.0, 3.0, 3.0);		
		glVertex3f( 0.0, 3.0, 0.0);
		glVertex3f( 3.0, 3.0, 0.0);	
		glVertex3f( 3.0, 3.0, 3.0);
		
		glVertex3f( 3.0, 3.0, 3.0);		
		glVertex3f( 3.0, 3.0, 0.0);
		glVertex3f( 3.0, 0.0, 0.0);	
		glVertex3f( 3.0, 0.0, 3.0);


		glEnd();
	glPopMatrix();

	glLoadIdentity();
	glColor3f(0.0,1.0,0.0);
	glTranslatef(10.0,-5.0,0.0);
	glRotatef(-128.0,0.0,1.0,0.0);
	glRotatef(-30.0,1.0,0.0,0.0);
	glutWireCone(1.0, 3.0, 10.0, 1.0);

/* Swap buffers */

	glutSwapBuffers();

}