Ejemplo n.º 1
0
/* and draw the resulting triangles */
void subdivide(GLfloat v1[3], GLfloat v2[3], GLfloat v3[3], int depth)
{
  GLfloat v12[3], v23[3], v31[3];
  int i;

  if (depth == 0) {
    glBegin(GL_TRIANGLES);
      glNormal3fv(v1);   glVertex3fv(v1);      
      glNormal3fv(v2);   glVertex3fv(v2);      
      glNormal3fv(v3);   glVertex3fv(v3);      
    glEnd(); 
    return;
  }

  /* calculate midpoints of each side */
  for (i = 0; i < 3; i++) {
    v12[i] = (v1[i]+v2[i])/2.0;
    v23[i] = (v2[i]+v3[i])/2.0;
    v31[i] = (v3[i]+v1[i])/2.0;
  }

  /* extrude midpoints to lie on unit sphere */
  normalize(v12);
  normalize(v23);
  normalize(v31);

  /* recursively subdivide new triangles */
  subdivide(v1 , v12, v31, depth-1);
  subdivide(v2 , v23, v12, depth-1);
  subdivide(v3 , v31, v23, depth-1);
  subdivide(v12, v23, v31, depth-1);
}
Ejemplo n.º 2
0
void subdivide(std::vector<V>& vertices, std::vector<uint32_t>& indices, const vec3& p1, const vec3& p2, const vec3& p3, int level)
{
    if (level > 0)
    {
        vec3 m1 = p1 + p2;
        vec3 m2 = p2 + p3;
        vec3 m3 = p3 + p1;
        m1.normalize();
        m2.normalize();
        m3.normalize();
        subdivide(vertices, indices, p1, m1, m3, level - 1);
        subdivide(vertices, indices, m1, p2, m2, level - 1);
        subdivide(vertices, indices, m2, m3, m1, level - 1);
        subdivide(vertices, indices, m3, m2, p3, level - 1);
    }
    else
    {
        V v;
        v.pos = p1;
        vertices.push_back(v);
        v.pos = p2;
        vertices.push_back(v);
        v.pos = p3;
        vertices.push_back(v);

        uint32_t start = indices.size();
        indices.push_back(start);
        indices.push_back(start + 1);
        indices.push_back(start + 2);
    }
}
Ejemplo n.º 3
0
static void subdivide(apiflt *base, int xres, int yres, apiflt wx, apiflt wy,
                  int x1, int y1, int x2, int y2) {
  long x,y;

  if (((x2 - x1) < 2) && ((y2 - y1) < 2)) { return; }

  x=(x1 + x2) / 2;
  y=(y1 + y2) / 2;

  adjust(base, xres, yres, wx, wy, x1, y1, x, y1, x2, y1);
  adjust(base, xres, yres, wx, wy, x2, y1, x2, y, x2, y2);
  adjust(base, xres, yres, wx, wy, x1, y2, x, y2, x2, y2);
  adjust(base, xres, yres, wx, wy, x1, y1, x1, y, x1, y2);

 
  if (base[x + xres*y]==0.0) {
    base[x + (xres * y)]=(base[x1 + xres*y1] + base[x2 + xres*y1] +
                          base[x2 + xres*y2] + base[x1 + xres*y2]   )/4.0;
  }
 
  subdivide(base, xres, yres, wx, wy, x1, y1 ,x ,y);
  subdivide(base, xres, yres, wx, wy, x, y1, x2, y);
  subdivide(base, xres, yres, wx, wy, x, y, x2, y2);
  subdivide(base, xres, yres, wx, wy, x1, y, x, y2);
}
Ejemplo n.º 4
0
void OpenGL3DSphereRenderer::subdivide( const Eigen::Matrix<GLfloat,3,1>& v1, const Eigen::Matrix<GLfloat,3,1>& v2, const Eigen::Matrix<GLfloat,3,1>& v3, unsigned& current_vertex, const unsigned depth )
{
  // If we hit the lowest level of recursion
  if( depth == 0 )
  {
    // Save the current triangle
    saveTriangleInMem( v1, v2, v3, current_vertex );
    return;
  }

  // New vertices lie on the midpoint of the three edges of the larger triangle
  Eigen::Matrix<GLfloat,3,1> v12{ 0.5 * ( v1 + v2 ) };
  Eigen::Matrix<GLfloat,3,1> v23{ 0.5 * ( v2 + v3 ) };
  Eigen::Matrix<GLfloat,3,1> v31{ 0.5 * ( v3 + v1 ) };

  // Ensure that the new vertices are on the surface of the sphere
  v12 = v12.normalized();
  v23 = v23.normalized();
  v31 = v31.normalized();

  // This triangle is divided into four children
  subdivide( v1, v12, v31, current_vertex, depth - 1 );
  subdivide( v2, v23, v12, current_vertex, depth - 1 );
  subdivide( v3, v31, v23, current_vertex, depth - 1 );
  subdivide( v12, v23, v31, current_vertex, depth - 1 );
}
Ejemplo n.º 5
0
void subdivide(GLfloat u1[2], GLfloat u2[2], GLfloat u3[2],
	       GLfloat cutoff, int depth,
	       GLfloat(*curv) (GLfloat[2]),
	       void (*surf) (GLfloat[2], GLfloat *, GLfloat *, GLfloat *)
    )
{
    GLfloat v1[3], v2[3], v3[3];
    GLfloat n1[3], n2[3], n3[3];
    GLfloat t1[2], t2[2], t3[2];
    GLfloat u12[2], u23[2], u31[2];
    GLint i;

    if (depth == 0 || ((*curv) (u1) < cutoff &&
		       (*curv) (u2) < cutoff && (*curv) (u3) < cutoff)) {
	(*surf) (u1, v1, n1, t1);
	(*surf) (u2, v2, n2, t2);
	(*surf) (u3, v3, n3, t3);
	return;
    }
    for (i = 0; i < 2; i++) {
	u12[i] = (u1[i] + u2[i]) / 2.0;
	u23[i] = (u2[i] + u3[i]) / 2.0;
	u31[i] = (u3[i] + u1[i]) / 2.0;
    }
    subdivide(u1, u12, u31, cutoff, depth - 1, curv, surf);
    subdivide(u2, u23, u12, cutoff, depth - 1, curv, surf);
    subdivide(u3, u31, u23, cutoff, depth - 1, curv, surf);
    subdivide(u12, u23, u31, cutoff, depth - 1, curv, surf);
}
Ejemplo n.º 6
0
GeodesicHemisphereMesh::GeodesicHemisphereMesh(unsigned level)
{
    unsigned nv = (level + 1) * (level + 1) * 2;
    
    unsigned nf = level * level * 2 * 2;
    
    createVertices(nv);
	createIndices(nf * 3);

	Vector3F * p = vertices();
	
	unsigned * idx = indices();
	
	unsigned currentidx = 0;
	unsigned currentver = 0;
	
	Vector3F a(0.f, 1.f, 0.f);
	Vector3F b(-1.f, 0.001f, 0.f);
	Vector3F c(0.f, 0.001f, 1.f);
	Vector3F d(1.f, 0.001f, 0.f);
	Vector3F e(0.f, 0.001f, -1.f);
	
	subdivide(level, currentver, currentidx, p, idx, a, b, c, d);
	subdivide(level, currentver, currentidx, p, idx, a, d, e, b);

    printf("vertices count: %d\n", currentver);
    printf("indices count: %d\n", currentidx);	
}
Ejemplo n.º 7
0
 static void subdivide
 (
     GLfloat point0[3], 
     GLfloat point1[3], 
     GLfloat point2[3], 
     int level
 )
 {
     int coord;
     GLfloat midpoint[3][3];
     
     /* Don't subdivide any further; just draw the triangle */
     if (level==0) {
         glColor3fv(point0);
         glVertex3fv(point0);
         glColor3fv(point1);
         glVertex3fv(point1);
         glColor3fv(point2);
         glVertex3fv(point2);
         return;
     }
 
     /* Calculate a midpoint on each edge of the triangle */
     for(coord = 0; coord<3; coord++) {
         midpoint[0][coord] = (point0[coord] + point1[coord])*0.5;
         midpoint[1][coord] = (point1[coord] + point2[coord])*0.5;
         midpoint[2][coord] = (point2[coord] + point0[coord])*0.5;
     }
 
     /* Subdivide each triangle into three more */    /*     .      */
     level--;                                         /*    /X\     */
     subdivide(point0,midpoint[0],midpoint[2],level); /*   /xxx\    */
     subdivide(point1,midpoint[1],midpoint[0],level); /*  /X\ /X\   */
     subdivide(point2,midpoint[2],midpoint[1],level); /* /XXXVXXX\  */
 }
Ejemplo n.º 8
0
/* ---------------------------------------------------------- */
void subdivide(GLfloat v1[2], GLfloat v2[2],GLfloat v3[2], int depth)
{ 
	int i;
	GLfloat v12[2], v23[2], v31[2]; 
	
	if (!depth) 
	{
		GLfloat P0[3],P1[3],P2[3],N0[3],N1[3],N2[3];
		getPointOnTorus(P0,N0,v1[0],v1[1]);glNormal3fv(N0);glVertex3fv(P0);
		getPointOnTorus(P1,N1,v2[0],v2[1]);glNormal3fv(N1);glVertex3fv(P1);
		getPointOnTorus(P2,N2,v3[0],v3[1]);glNormal3fv(N2);glVertex3fv(P2);
	}
	else 
  	{
		for (i = 0; i < 2; i++) 
		{
			v12[i] = (v1[i]+v2[i])/2.0f;
			v23[i] = (v2[i]+v3[i])/2.0f;
			v31[i] = (v3[i]+v1[i])/2.0f;		
		}

		subdivide(v1 ,v12,v31 ,depth-1);
		subdivide(v31,v12,v23 ,depth-1);
		subdivide(v23,v12,v2  ,depth-1);
		subdivide(v31,v23,v3  ,depth-1); 
	}
}
Ejemplo n.º 9
0
void TSphere::subdivide(const GLfloat inA[3], const GLfloat inB[3],
    const GLfloat inC[3], size_t inDepth)
{
    if (!inDepth)
    {
        addTriangle(inA, inB, inC);
        return;
    }
    
    GLfloat ab[3];
    GLfloat bc[3];
    GLfloat ca[3];
    
    for (size_t i = 0; i < 3; ++i)
    {
        ab[i] = (inA[i] + inB[i]) / 2.0f;
        bc[i] = (inB[i] + inC[i]) / 2.0f;
        ca[i] = (inC[i] + inA[i]) / 2.0f;
    }
    
    normalize(ab);
    normalize(bc);
    normalize(ca);
    
    subdivide(inA, ab, ca, inDepth - 1);
    subdivide(inB, bc, ab, inDepth - 1);
    subdivide(inC, ca, bc, inDepth - 1);
    subdivide(ab, bc, ca, inDepth - 1);

}
Ejemplo n.º 10
0
/* ---------------------------------------------------------- */
void subdivide(GLfloat v1[2], GLfloat v2[2],GLfloat v3[2], int depth)
{ 
	int i;
	GLfloat v12[2], v23[2], v31[2]; 
	
	if (!depth) 
	{
		GLfloat P0[3],P1[3],P2[3],t0,t1,t2;

		getPoint(P0,&t0,v1[0],v1[1]);glTexCoord1f(t0);glVertex3fv(P0);
		getPoint(P1,&t1,v2[0],v2[1]);glTexCoord1f(t1);glVertex3fv(P1);
		getPoint(P2,&t2,v3[0],v3[1]);glTexCoord1f(t2);glVertex3fv(P2);
	}
	else 
  	{
		for (i = 0; i < 2; i++) 
		{
			v12[i] = (v1[i]+v2[i])/2.0f;
			v23[i] = (v2[i]+v3[i])/2.0f;
			v31[i] = (v3[i]+v1[i])/2.0f;		
		}

		subdivide(v1 ,v12,v31 ,depth-1);
		subdivide(v31,v12,v23 ,depth-1);
		subdivide(v23,v12,v2  ,depth-1);
		subdivide(v31,v23,v3  ,depth-1); 
	}
}
Ejemplo n.º 11
0
/* and draw the resulting triangles */
void subdivide(GLfloat u1[2], GLfloat u2[2], GLfloat u3[2], float cutoff, int depth)
{
   GLfloat v1[3], v2[3], v3[3], n1[3], n2[3], n3[3];
   GLfloat u12[2], u23[2], u31[2];
   int i;

   if(depth == MAXDEPTH || (curv(u1) < cutoff && curv(u2) < cutoff && curv(u3) < cutoff)){
    surf(u1,v1,n1);
    surf(u2,v2,n2);
    surf(u3,v3,n3);
    glBegin(GL_POLYGON);
      glNormal3fv(n1); 
      glVertex3fv(v1);
      //glNormal3fv(n2); 
      glVertex3fv(v2);
      //glNormal3fv(n3);
      glVertex3fv(v3);
    glEnd();
    return;
   } 

   for(i=0;i<2;i++){
    u12[i]=(u1[i]+u2[i])/2.0;
    u23[i]=(u2[i]+u3[i])/2.0;
    u31[i]=(u1[i]+u3[i])/2.0;
   }
   subdivide(u1,u12,u31,cutoff,depth+1);
   subdivide(u2,u23,u12,cutoff,depth+1);
   subdivide(u3,u31,u23,cutoff,depth+1);
   subdivide(u12,u23,u31,cutoff,depth+1);
}
Ejemplo n.º 12
0
static void
subdivide(glb_data *d,
          const GLfloat * v1, GLuint vi1,
	  const GLfloat * v2, GLuint vi2,
	  const GLfloat * v3, GLuint vi3,
	  int depth)
{
	int         i;

	if (depth == 0) {
		save_triangle(d, vi1, vi2, vi3);
	} else {
		GLuint      vi12, vi23, vi31;
		GLfloat     v12[3], v23[3], v31[3];

		for (i = 0; i < 3; ++i) {
			v12[i] = v1[i] + v2[i];
			v23[i] = v2[i] + v3[i];
			v31[i] = v3[i] + v1[i];
		}
		normalize(v12);
		vi12 = save_vertex(d, v12);
		normalize(v23);
		vi23 = save_vertex(d, v23);
		normalize(v31);
		vi31 = save_vertex(d, v31);
		subdivide(d, v1, vi1, v12, vi12, v31, vi31, depth - 1);
		subdivide(d, v2, vi2, v23, vi23, v12, vi12, depth - 1);
		subdivide(d, v3, vi3, v31, vi31, v23, vi23, depth - 1);
		subdivide(d, v12, vi12, v23, vi23, v31, vi31, depth - 1);
	}
}
Ejemplo n.º 13
0
void subdivide(char ar[], int low, int high, int level){
	if (level == 0)
		return;
	int mid = (high + low) / 2;
	ar[mid] = '|';
	subdivide(ar, low, mid, level-1);
	subdivide(ar, mid, high, level-1);
}
Ejemplo n.º 14
0
void subdivide(char ar[],int head,int foot,int level)
{
	int mid;
	if(level==0) return;
	mid=(head+foot)/2;
	ar[mid]='|';
	subdivide(ar,head,mid,level-1);
	subdivide(ar,mid,foot,level-1);
}
static void subdivide(BVItem* items, int nitems, int imin, int imax, int& curNode, dtBVNode* nodes)
{
	int inum = imax - imin;
	int icur = curNode;
	
	dtBVNode& node = nodes[curNode++];
	
	if (inum == 1)
	{
		// Leaf
		node.bmin[0] = items[imin].bmin[0];
		node.bmin[1] = items[imin].bmin[1];
		node.bmin[2] = items[imin].bmin[2];
		
		node.bmax[0] = items[imin].bmax[0];
		node.bmax[1] = items[imin].bmax[1];
		node.bmax[2] = items[imin].bmax[2];
		
		node.i = items[imin].i;
	}
	else
	{
		// Split
		calcExtends(items, nitems, imin, imax, node.bmin, node.bmax);
		
		int	axis = longestAxis(node.bmax[0] - node.bmin[0],
							   node.bmax[1] - node.bmin[1],
							   node.bmax[2] - node.bmin[2]);
		
		if (axis == 0)
		{
			// Sort along x-axis
			qsort(items+imin, inum, sizeof(BVItem), compareItemX);
		}
		else if (axis == 1)
		{
			// Sort along y-axis
			qsort(items+imin, inum, sizeof(BVItem), compareItemY);
		}
		else
		{
			// Sort along z-axis
			qsort(items+imin, inum, sizeof(BVItem), compareItemZ);
		}
		
		int isplit = imin+inum/2;
		
		// Left
		subdivide(items, nitems, imin, isplit, curNode, nodes);
		// Right
		subdivide(items, nitems, isplit, imax, curNode, nodes);
		
		int iescape = curNode - icur;
		// Negative index means escape.
		node.i = -iescape;
	}
}
Ejemplo n.º 16
0
void subdivide(BezierRow const& G, int N, std::vector<glm::vec3> &points){
	if (N==0){
		points.push_back(G[1]);
		points.push_back(G[4]);
	}
	else{
		subdivide(G*DLB, N - 1, points);
		subdivide(G*DRB, N - 1, points);
	}
}
Ejemplo n.º 17
0
void BezierPath::const_iterator::flatten_adaptive(BezierPath::vertices& v,
						  Coord flat) const
{
  unsigned int subdivisions;
  //vector2d<double> d1, d2, d3;

  v.push_back(control_[0]);
  switch(type()) {
  case move:
    return;
  case line:
  case close:
    v.push_back(control_[1]);
    return;
  case parabolic:{
    BezierPath::Point p1,p2;
    p1.x() = (2*control_[1].x() + control_[0].x())/3.;
    p1.y() = (2*control_[1].y() + control_[0].y())/3.;

    p2.x() = (2*control_[1].x() + control_[2].x())/3.;
    p2.y() = (2*control_[1].y() + control_[2].y())/3.;

    subdivisions = compute_subdivisions(control_[0], p1,
					p2, control_[2],
					flat);
    v.reserve(v.size()+(1 << subdivisions));
    subdivide(v, 
	      control_[0], p1,
	      p2, control_[2],
	      flat*flat);
    return;
  }
  case cubic:
    subdivisions = compute_subdivisions(control_[0], control_[1],
					control_[2], control_[3],
					flat);
    v.reserve(v.size()+(1 << subdivisions));
    subdivide(v, 
	      control_[0], control_[1],
	      control_[2], control_[3],
	      flat*flat);
    return;
  default:
    assert(type() == line ||
	   type() == move ||
	   type() == parabolic ||
	   type() == cubic);
    return;
  }
}
Ejemplo n.º 18
0
static void subdivide( vector<q3_vertex> &verts,int level,int index,int step ){
	if( !level ){
		q3_vertex t1,t2;
		average( verts[index],verts[index+step],&t1 );
		average( verts[index+step],verts[index+step*2],&t2 );
		average( t1,t2,&verts[index+step] );
		return;
	}
	average( verts[index],verts[index+step],&verts[index+step/2] );
	average( verts[index+step],verts[index+step*2],&verts[index+step+step/2] );
	average( verts[index+step/2],verts[index+step+step/2],&verts[index+step] );
	subdivide( verts,level-1,index,step/2 );
	subdivide( verts,level-1,index+step,step/2 );
}
Ejemplo n.º 19
0
void BSPSector::subdivide(BSPSector* sector)
{
    AABB aabbLeft, aabbRight; 
    sector->getBoundingBox()->divide( aabbLeft, aabbRight, AABB::maxPlane );

    sector->_leftSubset  = new BSPSector( sector->_bsp, sector, aabbLeft, NULL );
    sector->_rightSubset = new BSPSector( sector->_bsp, sector, aabbRight, NULL );

    if( sector->getSectorLevel() < 3 )
    {
        subdivide( sector->_leftSubset );
        subdivide( sector->_rightSubset );
    }
}
Ejemplo n.º 20
0
void SimplexSphereGenerator::subdivide(const D3DXVECTOR3 &v1, const D3DXVECTOR3 &v2, const D3DXVECTOR3 &v3, vector<D3DXVECTOR3> &sphere_points, const unsigned int depth) {
	if (depth == 0) {
		sphere_points.push_back(v1);
		sphere_points.push_back(v2);
		sphere_points.push_back(v3);
		return;
	}
	D3DXVECTOR3 v12; D3DXVec3Normalize(&v12, &(v1 + v2));
	D3DXVECTOR3 v23; D3DXVec3Normalize(&v23, &(v2 + v3));
	D3DXVECTOR3 v31; D3DXVec3Normalize(&v31, &(v3 + v1));
	subdivide(v1, v12, v31, sphere_points, depth - 1);
	subdivide(v2, v23, v12, sphere_points, depth - 1);
	subdivide(v3, v31, v23, sphere_points, depth - 1);
	subdivide(v12, v23, v31, sphere_points, depth - 1);
}
Ejemplo n.º 21
0
t_get	*subdivide(char *s, t_get *prev, char **bad_sintax)
{
  size_t l;
  t_get *link;

  if (empty(s))
    return (prev);
  if (s[0] == '\\' && prev)
    if ((!S_IN(prev->word, "\"'|;<>()`")))
      return (echappment(s, prev, bad_sintax, 0));
  if ((link = xmalloc(sizeof(*prev))) == NULL)
    return (NULL);
  link->word = (void*)(link->next = NULL);
  link->prev = prev;
  if (prev)
    prev->next = link;
  s += hempty(s);
  if (s[(link->inter = 0)] == '\\')
    return (echappment(s, link, bad_sintax, 1));
  l = subdiv(s, bad_sintax);
  if (*bad_sintax)
    return (nullify_link(link, 0, 1));
  if ((link->word = my_strndup(s, l)) == NULL)
    return (nullify_link(link, 0, 1));
  if (subdivide(s + my_strlen(link->word), link, bad_sintax) == NULL)
    return (nullify_link(link, 1, 1));
  return (link);
}
Ejemplo n.º 22
0
bool rcCreateChunkyTriMesh(const float* verts, const int* tris, int ntris,
						   int trisPerChunk, rcChunkyTriMesh* cm)
{
	int nchunks = (ntris + trisPerChunk-1) / trisPerChunk;

	cm->nodes = new rcChunkyTriMeshNode[nchunks*4];
	if (!cm->nodes)
		return false;
		
	cm->tris = new int[ntris*3];
	if (!cm->tris)
		return false;
		
	cm->ntris = ntris;

	// Build tree
	BoundsItem* items = new BoundsItem[ntris];
	if (!items)
		return false;

	for (int i = 0; i < ntris; i++)
	{
		const int* t = &tris[i*3];
		BoundsItem& it = items[i];
		it.i = i;
		// Calc triangle XZ bounds.
		it.bmin[0] = it.bmax[0] = verts[t[0]*3+0];
		it.bmin[1] = it.bmax[1] = verts[t[0]*3+2];
		for (int j = 1; j < 3; ++j)
		{
			const float* v = &verts[t[j]*3];
			if (v[0] < it.bmin[0]) it.bmin[0] = v[0]; 
			if (v[2] < it.bmin[1]) it.bmin[1] = v[2]; 

			if (v[0] > it.bmax[0]) it.bmax[0] = v[0]; 
			if (v[2] > it.bmax[1]) it.bmax[1] = v[2]; 
		}
	}

	int curTri = 0;
	int curNode = 0;
	subdivide(items, ntris, 0, ntris, trisPerChunk, curNode, cm->nodes, nchunks*4, curTri, cm->tris, tris);
	
	delete [] items;
	
	cm->nnodes = curNode;
	
	// Calc max tris per node.
	cm->maxTrisPerChunk = 0;
	for (int i = 0; i < cm->nnodes; ++i)
	{
		rcChunkyTriMeshNode& node = cm->nodes[i];
		const bool isLeaf = node.i >= 0;
		if (!isLeaf) continue;
		if (node.n > cm->maxTrisPerChunk)
			cm->maxTrisPerChunk = node.n;
	}
	 
	return true;
}
Ejemplo n.º 23
0
TriangleGraph::TriangleGraph(int n):_size(20 * (int)pow(4.0,n))
{
	const float phi = 1 + sqrt(5.0) / 2;
	_triangles = new Triangle[_size];
	_triangles_new = new Triangle[_size];
	int currentSize = 20;
	Triangle* startTriangles = calculateStartTriangles();
	normalize(startTriangles, currentSize);
	link_triangles(startTriangles);
	for(int i = 0; i < currentSize; i++){_triangles[i] = startTriangles[i]; }
	
	for(int tes = 0 ; tes <n; tes++)
	{
		for(int i = 0; i < currentSize; i++)
		{
			Triangle new_triangles [4];
			subdivide(_triangles[i], new_triangles[0], new_triangles[1], new_triangles[2], new_triangles[3]);
			for(int ii = 0; ii < 4; ii++)
			{
				_triangles_new[new_triangles[ii].id] = new_triangles[ii];
			}
		}
		currentSize = currentSize * 4;
		for(int i = 0; i < currentSize; i++){_triangles[i] = _triangles_new[i]; }
		normalize(_triangles, currentSize);
	}
}
Ejemplo n.º 24
0
void WaterQuadTree::draw(const Camera &camera, double delta_time) {
	if (!setup_done()) { return; }
	if (!camera.intersects_box(_patch->get_center(), _patch->get_extents())) {
		remove_children();
		return;
	}

	// Get LOD metric to see if we should draw child quads or just draw this one
	double rho = compute_level_metric(camera, distance_to_patch(camera, _patch->get_center()));
	if (rho >= 0.0 || _level > _deepest_level) {
		_patch->draw(camera, delta_time);
		remove_children();
	}
	else {
		// If we already have created the children then just draw them
		if (_has_children) {
			if (_northwest->setup_done() && _northeast->setup_done() &&
				_southwest->setup_done() && _southeast->setup_done()) {
				_northwest->draw(camera, delta_time);
				_northeast->draw(camera, delta_time);
				_southwest->draw(camera, delta_time);
				_southeast->draw(camera, delta_time);

			}
			else {
				// Draw this tile until all children is setup
				_patch->draw(camera, delta_time);
			}
		}
		else { // Else create children and draw this tile
			subdivide();
			_patch->draw(camera, delta_time);
		}
	}
}
Ejemplo n.º 25
0
int insert(node* currentNode, body* pBody, int level) {
  // Return false if body does not belong in this node.
  if(!checkBounds(pBody, currentNode)) {
    return 0;
  }

  // Insert body into node
  if(currentNode->nodeBody == NULL) {
    currentNode->nodeBody = pBody;
    return 1;
  }

  // Prevent adding body to same location (Skip Parents)
  if((!currentNode->isParent) & ((currentNode->nodeBody->pX == pBody->pX) & (currentNode->nodeBody->pY == pBody->pY))) {
    return 0;
  }

  // Subdivide node
  if(currentNode->northWest == NULL) {
    subdivide(currentNode);
    currentNode->isParent = 1;
    insert(currentNode, currentNode->nodeBody, level+1);
    // TODO: Add body averaging
    currentNode->nodeBody = newBody(1,  -1,  -1,  0,  0);
  }

  // Put point into subtree
  if(insert(currentNode->northWest, pBody, level+1)) return 1;
  if(insert(currentNode->northEast, pBody, level+1)) return 1;
  if(insert(currentNode->southEast, pBody, level+1)) return 1;
  if(insert(currentNode->southWest, pBody, level+1)) return 1;

  // Return false if point cannot be inserted.
  return 0;
}
Ejemplo n.º 26
0
void BezierPatchModel::update()
{
	glBindVertexArray(0);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	glDeleteBuffers(BUFFER_COUNT, buffers);
	glDeleteVertexArrays(1, &vao);
    
    for (std::vector<BezierPatch>::const_iterator patch = patches.begin();
            patch != patches.end(); ++patch) {

        subdivide(* patch, level);
    }

    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);

    glGenBuffers(BUFFER_COUNT, buffers);

    glBindBuffer(GL_ARRAY_BUFFER, buffers[VERTEX_BUFFER]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * vertices.size(),
            &vertices[0], GL_STATIC_DRAW);

    glBindBuffer(GL_ARRAY_BUFFER, buffers[NORMAL_BUFFER]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * normals.size(),
            &normals[0], GL_STATIC_DRAW);

    glBindVertexArray(0);

    num_vertices = vertices.size();

    vertices.clear();
    normals.clear();
}
Ejemplo n.º 27
0
LidarProcessOctree::Node* LidarProcessOctree::nextNodePrefix(LidarProcessOctree::Node* node)
	{
	/* Check if the node is an interior node: */
	if(node->childrenOffset!=0)
		{
		/* Subdivide the node if necessary: */
		if(node->children==0)
			subdivide(*node);
		
		/* Go to the node's first child: */
		return &node->children[0];
		}
	else
		{
		while(node->parent!=0)
			{
			/* Find the node's index among its parent's children: */
			int childIndex;
			for(childIndex=0;childIndex<8&&node!=&node->parent->children[childIndex];++childIndex)
				;
			
			/* Return the node's next sibling if there is one: */
			if(childIndex+1<8)
				return &node->parent->children[childIndex+1];
			
			/* Try the node's parent: */
			node=node->parent;
			}
		
		/* The root doesn't have siblings; we're done here: */
		return 0;
		}
	}
Ejemplo n.º 28
0
void rt_landscape(void * tex, int m, int n, 
              	vector ctr, apiflt wx, apiflt wy) {
  int totalsize, x, y;
  apiflt * field; 

  totalsize=m*n;

  srand(totalsize);

  field=(apiflt *) malloc(totalsize*sizeof(apiflt));

  for (y=0; y<n; y++) {
    for (x=0; x<m; x++) {
       field[x + y*m]=0.0;
    }
  }

  field[0 + 0]=1.0 + (rand() % 100)/100.0;
  field[m - 1]=1.0 + (rand() % 100)/100.0;
  field[0     + m*(n - 1)]=1.0 + (rand() % 100)/100.0;
  field[m - 1 + m*(n - 1)]=1.0 + (rand() % 100)/100.0;

  subdivide(field, m, n, wx, wy, 0, 0, m-1, n-1);

  rt_sheightfield(tex, ctr, m, n, field, wx, wy);

  free(field);
}
Ejemplo n.º 29
0
int main()
{
    char ruler[Len];
    int i;
    for(i=1; i < Len -2; i++)
    {
        ruler[i] = ' ';
    }
    ruler[Len - 1] = '\0';
    int max = Len - 2;
    int min = 0;
    ruler[min] = ruler[max] = '|';
    std::cout << ruler << std::endl;
    for(i = 1; i<= Divs; i++)
    {
        subdivide(ruler, min ,max, i);
        std::cout << ruler << std::endl;
        for(int j = 1;j<Len -2; j++)
        {
            ruler[j] = ' '; // reset to blank ruler
        }
    }
  
    return 0;
}
Ejemplo n.º 30
0
void insert_source(node_t *node, source_t *source) {
    node_t *quadrant;
    
    // Check if the MAX has been reached
    if (node->contents.length == MAX)
        subdivide(node);    

    // A node in the tree will be filled with either content or sub
    // quadrants. Check to see whether subquads exist.
    if (node->q1 != NULL) {

        if (source->x >= node->xmid) {
            if (source->y >= node->ymid)
                quadrant = node->q1;
            else
                quadrant = node->q4;
        } else {
            if (source->y >= node->ymid)
                quadrant = node->q2;
            else
                quadrant = node->q3;
        }
        insert_source(quadrant, source);

    } else {    
        // If no subquads exist add source to the list in contents element 
        // Use push() to prepend the source on the list.
        push(&node->contents, source);
    }
}