void MD3Model::GetVertices(uint32_t s, uint32_t f, MeshVertex_t*& vertexData, uint32_t& vertexCount) const {
    assert(s < header->numSurfaces);
    assert(f < header->numFrames);
    
    MD3::Surface_t*    surface = surfaces[s];
    MD3::Vertex_t*    vertices = GetVertices(s, f);
    MD3::TexCoord_t* texCoords = GetTexCoords(s);
    
    vertexCount = surface->numVerts;
    vertexData  = new MeshVertex_t[vertexCount];

    for (uint32_t i=0; i<vertexCount; ++i) {
        vertexData[i].coord = glm::vec3(
            vertices[i].x,
            vertices[i].y,
            vertices[i].z
        ) * MD3_SCALE;

        vertexData[i].normal = DecodeNormal(vertices[i].n);

        vertexData[i].texCoord = glm::vec2(
            texCoords[i].u,
            texCoords[i].v
        );
    }
}
示例#2
0
Matrix Mesh::GetTangentSpace(int index)
{
	Vector V [3];
	Vector T [3];
	
	GetVertexes(index, V);
	GetTexCoords(index, T);

	Matrix TBN;
	TBN.Tangent(V, T);
	return TBN;
}
示例#3
0
CIntersectionInfo CTriangle::GetIntersection	(CRay ray)
{
	CPoint3D ptNoIntersection (0.0f, 0.0f, 0.0f, 0.0f);	// no intersection by default
	CPoint3D ptOfIntersection;
	CIntersectionInfo hitInfo;

	/***************************************************************
	STRATEGY:

	There are two major steps when trying to find the point of 
	intersection of a ray with a triangle, first to see if the ray
	intersects the plane of the triangle and then to see if the point
	on the plane that the ray intersects with lies within the triangle.

	So:
	1. Find the point of intersection on the triangle plane.
	2. Check if this point lies insdie the plane or not.
	3. Set the information into the hitInfo object.
	4. Return the hitInfo object.
	***************************************************************/

	// 1.
	ptOfIntersection = PlaneIntersect(ray);

	// 2.
	if ( !inTriangle(ptOfIntersection) || ptOfIntersection.AtInfinity()) {

		return hitInfo;
	}

	// 3.
	hitInfo.SetPointOfIntersection (ptOfIntersection);
	hitInfo.SetNormal (GetNormalAt(ptOfIntersection));
	hitInfo.SetColor(objColor);
	hitInfo.SetTexCoords (GetTexCoords(ptOfIntersection));

	// 4.
	return hitInfo;
}
示例#4
0
void Mesh::GetTexCoords(int index, Vector *V)
{
	GetTexCoords(faces[index].points, V);
}
示例#5
0
//creer une carte de texture en melangeant les quatres types de textures de base
void TERRAIN::GenerateTextureMap( unsigned int size )
{
  unsigned char Red, Green, Blue;
  unsigned int tempID;
  unsigned int x, z;
  unsigned int  TexX,  TexZ;
  float totalRed, totalGreen, totalBlue;
  float blend[4];
  float mapRatio;
  int lastHeight;
  int i;

  //determiner le nombre de textures de bases presentes
  textures.numTextures= 0;
  for( i=0; i<TRN_NUM_TILES; i++ )
    {
      if( !textures.data[i].isNull( ) )
	textures.numTextures++;
    }

  //determiner les intervalles d'affichage pour chaque type de texture de base
  lastHeight= -1;
  for( i=0; i<TRN_NUM_TILES; i++ )
    {
      if( !textures.data[i].isNull( ) )
	{
	  //on a trois valeurs a determiner: inf, opt,sup
	  textures.region[i].lowHeight=lastHeight+1;
	  lastHeight+= 255/textures.numTextures;
	  textures.region[i].optimalHeight=lastHeight;
	  textures.region[i].highHeight= ( lastHeight-textures.region[i].lowHeight )+lastHeight;
	}
    }

#if QT_VERSION < 0x040000
  myTexture.create( size, size, 32 );
#else
  myTexture = QImage(size, size, QImage::Format_ARGB32);
#endif

  //determiner relation entre resolution de la carte d'hauteur et la res. de la texture
  //.. en general, la texture aura une res. plus elevee
  mapRatio= ( float )sizeHeightMap/ size;

  //creation de texture
  for( z=0; z< size; z++ )
    {
      for( x=0; x< size; x++ )
	{
	  totalRed  = 0.0f;
	  totalGreen= 0.0f;
	  totalBlue = 0.0f;

	  //pour chaque texture de base
	  for( i=0; i<TRN_NUM_TILES; i++ )
	    {
	      if( !textures.data[i].isNull( ) )
		{
		  TexX= x;
		  TexZ= z;

		  //quel pixel de texture a choisir pour cette position sur la carte?
		  GetTexCoords( textures.data[i], &TexX, &TexZ );

		  //quelle est la couleur actuelle a cet endroit?
		  GetColor( textures.data[i], TexX,  TexZ, &Red, &Green, &Blue );

		  //combien de pourcent de cette texture de base faut-il ajouter a cet endroit?
		  //.. on interpole la vraie hauteur pour avoir des textures plus realistes
		  blend[i]= RegionPercent( i, Limit( InterpolateHeight( x, z, mapRatio ) ) );

		  //ajouter ce pourcentage a la couleur
		  totalRed  += Red*blend[i];
		  totalGreen+= Green*blend[i];
		  totalBlue += Blue*blend[i];
		}
	    }

	  //modifier la couleur de la texture a cet endroit, limiter les valeurs a 0..255
	  SetColor( myTexture, x, z, Limit( totalRed ),Limit( totalGreen ),Limit( totalBlue ) );
	}
    }

  //construire la texture
  glGenTextures( 1, &tempID );
  glBindTexture( GL_TEXTURE_2D, tempID );
  //utiliser la moyenne ponderee lineairement pour elargir ou reduire les textures
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );


  //le plus grand mystere de tout le code: pour une raison completement pourrie, QImage inverse
  //.. les canaux rouge et bleu lors de l'ecriture dans l'image; mais si j'utilise QGLWidget::convertToGLFormat,
  //.. l'image est inversee; la solution swapRGB marche (apres 3h de recherche desesperee) pour une raison mysterieuse
#if QT_VERSION < 0x040000
  myTexture = myTexture.swapRGB();
#else
  myTexture = myTexture.rgbSwapped();
#endif

  //definir la source de donnees pour la texture
  glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, size,  size, 0, GL_RGBA, GL_UNSIGNED_BYTE, myTexture.bits() );

  //associer un no. ID a la texture
  textureColorID =  tempID;

  myTexture.save("texture.bmp","BMP");
}