コード例 #1
0
 void BrushMesh::addVertex(float x, float y, float z)
 {
    verts.push_back(Point(x, y, z));
    tverts.push_back(Point2D(x+z, y+z));
    Point normal = Point(x, y, z) - getCenter() ;
    normal.normalize() ;
    normals.push_back(normal) ;
    enormals.push_back(encodeNormal(normal)) ;
 }
コード例 #2
0
   void BoxMesh::construct() 
   {
      int   i ;
      Box   bounds = getBounds() ;
      Point center = (bounds.max - bounds.min) / 2 ;

      // Vertex
      verts.push_back(Point(bounds.min.x(), bounds.min.y(), bounds.min.z()));
      verts.push_back(Point(bounds.max.x(), bounds.min.y(), bounds.min.z()));
      verts.push_back(Point(bounds.min.x(), bounds.max.y(), bounds.min.z()));
      verts.push_back(Point(bounds.max.x(), bounds.max.y(), bounds.min.z()));
      verts.push_back(Point(bounds.min.x(), bounds.min.y(), bounds.max.z()));
      verts.push_back(Point(bounds.max.x(), bounds.min.y(), bounds.max.z()));
      verts.push_back(Point(bounds.min.x(), bounds.max.y(), bounds.max.z()));
      verts.push_back(Point(bounds.max.x(), bounds.max.y(), bounds.max.z()));

      // Texture coordinates
      for (i = 0 ; i < 8 ; i++)
         tverts.push_back(Point2D(0,0));

      // Indices
      int inds[] = { 0, 4, 1, 5, 3, 7, 2, 6, 0, 4, 6, 7, 4, 5, 0, 1, 2, 3 } ;
      for (i = 0 ; i < sizeof(inds)/sizeof(inds[0]) ; i++)
         indices.push_back(inds[i]);

      // Primitives
      Primitive p ;
      p.firstElement = 0 ;
      p.numElements  = 10 ;
      p.type         = Primitive::NoMaterial | Primitive::Strip | Primitive::Indexed ;
      primitives.push_back(p) ;
      p.firstElement = 10 ;
      p.numElements  = 4 ;
      primitives.push_back(p) ;
      p.firstElement = 14 ;
      primitives.push_back(p) ;

      // Normals
      std::vector<Point>::iterator ptr ;
      for (ptr = verts.begin() ; ptr != verts.end() ; ptr++)
      {
         Point normal ;
         normal = *ptr - center ;
         normal.normalize() ;
         normals.push_back (normal) ;
         enormals.push_back (encodeNormal(normal)) ;
      }

      // Other stuff
      setFrames (1) ;
      setParent (-1) ;
      calculateCenter() ;
      calculateRadius() ;
   }
コード例 #3
0
Doom3TextureManager::ImageID Doom3TextureManager::computeHeightmap(const Doom3TextureManager::ImageID& source,float bumpiness)
	{
	/* Get a reference to the source image: */
	const Images::RGBAImage& sourceImage=imageTree.getLeafValue(source).image;
	
	/* Store a new image structure in the image tree: */
	ImageID resultId=imageTree.insertLeaf(Misc::stringPrintf("/_computedTextures/tex%06d",numTextures).c_str(),Image());
	Image& result=imageTree.getLeafValue(resultId);
	Images::RGBAImage& resultImage=result.image;
	result.textureIndex=numTextures;
	++numTextures;
	
	/* Compute the result image's pixels: */
	resultImage=Images::RGBAImage(sourceImage.getWidth(),sourceImage.getHeight());
	for(unsigned int y=0;y<resultImage.getHeight();++y)
		{
		const Images::RGBAImage::Color* sourceRow=sourceImage.getPixelRow(y);
		Images::RGBAImage::Color* destRow=resultImage.modifyPixelRow(y);
		for(unsigned int x=0;x<resultImage.getWidth();++x)
			{
			Geometry::Vector<float,3> g;
			if(x==0)
				g[0]=float(sourceRow[x+1][0])-float(sourceRow[x][0]);
			else if(x==resultImage.getWidth()-1)
				g[0]=float(sourceRow[x][0])-float(sourceRow[x-1][0]);
			else
				g[0]=float(sourceRow[x+1][0])-float(sourceRow[x-1][0]);
			if(y==0)
				g[1]=float((sourceRow+resultImage.getWidth())[x][0])-float(sourceRow[x][0]);
			else if(y==resultImage.getHeight()-1)
				g[1]=float(sourceRow[x][0])-float((sourceRow-resultImage.getWidth())[x][0]);
			else
				g[1]=float((sourceRow+resultImage.getWidth())[x][0])-float((sourceRow-resultImage.getWidth())[x][0]);
			g[2]=128.0f/bumpiness;
			destRow[x]=encodeNormal(g);
			}
		}
	
	/* Return the result image ID: */
	return resultId;
	}
コード例 #4
0
Doom3TextureManager::ImageID Doom3TextureManager::computeAddNormals(const Doom3TextureManager::ImageID& source1,const Doom3TextureManager::ImageID& source2)
	{
	/* Get a reference to the source images: */
	const Images::RGBAImage& source1Image=imageTree.getLeafValue(source1).image;
	Images::RGBAImage source2Image=imageTree.getLeafValue(source2).image;
	if(source1Image.getWidth()!=source2Image.getWidth()||source1Image.getHeight()!=source2Image.getHeight())
		{
		/* Resample the second image to match the first image's size: */
		source2Image.resize(source1Image.getWidth(),source1Image.getHeight());
		}
	
	/* Store a new image structure in the image tree: */
	ImageID resultId=imageTree.insertLeaf(Misc::stringPrintf("/_computedTextures/tex%06d",numTextures).c_str(),Image());
	Image& result=imageTree.getLeafValue(resultId);
	Images::RGBAImage& resultImage=result.image;
	result.textureIndex=numTextures;
	++numTextures;
	
	/* Compute the result image's pixels: */
	resultImage=Images::RGBAImage(source1Image.getWidth(),source1Image.getHeight());
	for(unsigned int y=0;y<resultImage.getHeight();++y)
		{
		const Images::RGBAImage::Color* source1Row=source1Image.getPixelRow(y);
		const Images::RGBAImage::Color* source2Row=source2Image.getPixelRow(y);
		Images::RGBAImage::Color* destRow=resultImage.modifyPixelRow(y);
		for(unsigned int x=0;x<resultImage.getWidth();++x)
			{
			Geometry::Vector<float,3> g;
			for(int i=0;i<3;++i)
				g[i]=float(source1Row[x][i])+float(source2Row[x][i])-256.0f;
			destRow[x]=encodeNormal(g);
			}
		}
	
	/* Return the result image ID: */
	return resultId;
	}