Example #1
0
/* glu_fastuidraw_gl_meshMakeEdge creates one edge, two vertices, and a loop (face).
 * The loop consists of the two new half-edges.
 */
GLUhalfEdge *glu_fastuidraw_gl_meshMakeEdge( GLUmesh *mesh )
{
  GLUvertex *newVertex1= allocVertex();
  GLUvertex *newVertex2= allocVertex();
  GLUface *newFace= allocFace();
  GLUhalfEdge *e;

  /* if any one is null then all get freed */
  if (newVertex1 == nullptr || newVertex2 == nullptr || newFace == nullptr) {
     if (newVertex1 != nullptr) memFree(newVertex1);
     if (newVertex2 != nullptr) memFree(newVertex2);
     if (newFace != nullptr) memFree(newFace);
     return nullptr;
  }

  e = MakeEdge( &mesh->eHead );
  if (e == nullptr) {
     memFree(newVertex1);
     memFree(newVertex2);
     memFree(newFace);
     return nullptr;
  }

  MakeVertex( newVertex1, e, &mesh->vHead );
  MakeVertex( newVertex2, e->Sym, &mesh->vHead );
  MakeFace( newFace, e, &mesh->fHead );
  return e;
}
Example #2
0
/* __gl_meshAddEdgeVertex( eOrg ) creates a new edge eNew such that
 * eNew == eOrg->Lnext, and eNew->Dst is a newly created vertex.
 * eOrg and eNew will have the same left face.
 */
GLUhalfEdge* __gl_meshAddEdgeVertex(GLUhalfEdge* eOrg)
{
   GLUhalfEdge* eNewSym;
   GLUhalfEdge* eNew=MakeEdge(eOrg);

   if (eNew==NULL)
   {
      return NULL;
   }

   eNewSym=eNew->Sym;

   /* Connect the new edge appropriately */
   Splice(eNew, eOrg->Lnext);

   /* Set the vertex and face information */
   eNew->Org=eOrg->Dst;
   {
      GLUvertex* newVertex=allocVertex();
      if (newVertex==NULL)
      {
         return NULL;
      }

      MakeVertex(newVertex, eNewSym, eNew->Org);
   }
   eNew->Lface=eNewSym->Lface=eOrg->Lface;

   return eNew;
}
Example #3
0
void QTerrain::LoadRaw(LPSTR Name, int Height, int Width)
{
    FILE *pFile = NULL;
    pFile = fopen( Name, "rb" ); // abrir read binary
    if ( pFile == NULL )	// Si no existe
    {
        MessageBox(NULL, "Can't find the height map!", "Error", MB_OK);
        return;
    }
    // Size == ancho*alto

    if (m_pHeightMap != NULL)	// Borra datos previos, si los habia
        free(m_pHeightMap);

    m_pHeightMap = (BYTE*)malloc(Height * Width);
    fread( m_pHeightMap, 1, (Height * Width), pFile );

    if (ferror( pFile ))
    {
        MessageBox(NULL, "Can't get data!", "Error", MB_OK);
    }
    fclose(pFile); // Cerrar

    m_Height = Height;
    m_Width  = Width;
    m_StepSize = 16;
    MakeVertex();

}
Example #4
0
/* __gl_meshSplice( eOrg, eDst ) is the basic operation for changing the
 * mesh connectivity and topology.  It changes the mesh so that
 *      eOrg->Onext <- OLD(eDst->Onext)
 *      eDst->Onext <- OLD(eOrg->Onext)
 * where OLD(...) means the value before the meshSplice operation.
 *
 * This can have two effects on the vertex structure:
 *  - if eOrg->Org != eDst->Org, the two vertices are merged together
 *  - if eOrg->Org == eDst->Org, the origin is split into two vertices
 * In both cases, eDst->Org is changed and eOrg->Org is untouched.
 *
 * Similarly (and independently) for the face structure,
 *  - if eOrg->Lface == eDst->Lface, one loop is split into two
 *  - if eOrg->Lface != eDst->Lface, two distinct loops are joined into one
 * In both cases, eDst->Lface is changed and eOrg->Lface is unaffected.
 *
 * Some special cases:
 * If eDst == eOrg, the operation has no effect.
 * If eDst == eOrg->Lnext, the new face will have a single edge.
 * If eDst == eOrg->Lprev, the old face will have a single edge.
 * If eDst == eOrg->Onext, the new vertex will have a single edge.
 * If eDst == eOrg->Oprev, the old vertex will have a single edge.
 */
int __gl_meshSplice(GLUhalfEdge* eOrg, GLUhalfEdge* eDst)
{
   int joiningLoops=FALSE;
   int joiningVertices=FALSE;

   if (eOrg==eDst)
   {
      return 1;
   }

   if (eDst->Org!=eOrg->Org)
   {
      /* We are merging two disjoint vertices -- destroy eDst->Org */
      joiningVertices=TRUE;
      KillVertex(eDst->Org, eOrg->Org);
   }

   if (eDst->Lface!=eOrg->Lface)
   {
      /* We are connecting two disjoint loops -- destroy eDst->Lface */
      joiningLoops=TRUE;
      KillFace(eDst->Lface, eOrg->Lface);
   }

   /* Change the edge structure */
   Splice(eDst, eOrg);

   if (!joiningVertices)
   {
      GLUvertex* newVertex=allocVertex();
      if (newVertex==NULL)
      {
         return 0;
      }

      /* We split one vertex into two -- the new vertex is eDst->Org.
       * Make sure the old vertex points to a valid half-edge.
       */
      MakeVertex(newVertex, eDst, eOrg->Org);
      eOrg->Org->anEdge=eOrg;
   }

   if (!joiningLoops)
   {
      GLUface* newFace=allocFace();
      if (newFace==NULL)
      {
         return 0;
      }

      /* We split one loop into two -- the new loop is eDst->Lface.
       * Make sure the old face points to a valid half-edge.
       */
      MakeFace(newFace, eDst, eOrg->Lface);
      eOrg->Lface->anEdge=eOrg;
   }

   return 1;
}
Example #5
0
static void Generate_SphereOctant(void)
{
    int i,j;

    VECTORCH *o = OctantVertex;

    /* i=0, j=0 */
    MakeVertex(o,0,0,SPHERE_RADIUS);

    for (i=1; i<SPHERE_ORDER; i++)
    {
        int cosPhi, sinPhi;
        {
            int phi = 1024*i/SPHERE_ORDER;
            cosPhi = GetCos(phi);
            sinPhi = GetSin(phi);
        }

        /* 0<i<n, j=0 */
        /* => cosTheta = 1, sinTheta = 0 */
        MakeVertex(o,sinPhi,0,cosPhi);

        for (j=1; j<i; j++)
        {
            int cosTheta, sinTheta;
            {
                int theta = 1024*j/i;
                cosTheta = GetCos(theta);
                sinTheta = GetSin(theta);
            }

            /* 0<i<n, 0<j<i */
            MakeVertex(o,MUL_FIXED(cosTheta,sinPhi),MUL_FIXED(sinTheta,sinPhi),cosPhi);
        }

        /* 0<i<n, j=i */
        MakeVertex(o,0,sinPhi,cosPhi);
    }

    /* i=n, j=0 */
    MakeVertex(o,SPHERE_RADIUS,0,0);

    for (j=1; j<SPHERE_ORDER; j++)
    {
        int cosTheta, sinTheta;
        {
            int theta = 1024*j/SPHERE_ORDER;
            cosTheta = GetCos(theta);
            sinTheta = GetSin(theta);
        }
        /* i=n, 0<j<i */
        MakeVertex(o,cosTheta,sinTheta,0);
    }

    /* i=n, j=i */
    MakeVertex(o,0,SPHERE_RADIUS,0);
}
void CPlayerHP::Init() {
	//MakeVertexPolygon();
	D3DXCreateTextureFromFile(CGraphics::GetDevice(), PLAYER_HP_TEXTRUE, &m_pTexture);

	m_pCamera = (CCamera*)Find(ID_CAMERA);
	m_pPlayer = (CJintai*)Find(ID_JINTAI);

	m_Size = D3DXVECTOR2(80.0f, 10.0f);
	m_Scale = D3DXVECTOR3(1.0f, 1.0f, 1.0f);
	m_fMaxPlayerHP = m_pPlayer->GetHP();
	MakeVertex();
}
/* tessMeshMakeEdge creates one edge, two vertices, and a loop (face).
* The loop consists of the two new half-edges.
*/
TESShalfEdge *tessMeshMakeEdge( TESSmesh *mesh )
{
    TESSvertex *newVertex1 = (TESSvertex*)bucketAlloc(mesh->vertexBucket);
    TESSvertex *newVertex2 = (TESSvertex*)bucketAlloc(mesh->vertexBucket);
    TESSface *newFace = (TESSface*)bucketAlloc(mesh->faceBucket);
    TESShalfEdge *e;

    /* if any one is null then all get freed */
    if (newVertex1 == NULL || newVertex2 == NULL || newFace == NULL) {
        if (newVertex1 != NULL) bucketFree( mesh->vertexBucket, newVertex1 );
        if (newVertex2 != NULL) bucketFree( mesh->vertexBucket, newVertex2 );
        if (newFace != NULL) bucketFree( mesh->faceBucket, newFace );
        return NULL;
    }

    e = MakeEdge( mesh, &mesh->eHead );
    if (e == NULL) return NULL;

    MakeVertex( newVertex1, e, &mesh->vHead );
    MakeVertex( newVertex2, e->Sym, &mesh->vHead );
    MakeFace( newFace, e, &mesh->fHead );
    return e;
}
Example #8
0
/* __gl_meshMakeEdge creates one edge, two vertices, and a loop (face).
 * The loop consists of the two new half-edges.
 */
GLUhalfEdge *__gl_meshMakeEdge( GLUmesh *mesh )
{
  GLUvertex *newVertex1= allocVertex();
  GLUvertex *newVertex2= allocVertex();
  GLUface *newFace= allocFace();
  GLUhalfEdge *e;

  /* if any one is null then all get freed */
  if (newVertex1 == NULL || newVertex2 == NULL || newFace == NULL) {
     if (newVertex1 != NULL) memFree(newVertex1);
     if (newVertex2 != NULL) memFree(newVertex2);
     if (newFace != NULL) memFree(newFace);     
     return NULL;
  } 

  e = MakeEdge( &mesh->eHead );
  if (e == NULL) return NULL;

  MakeVertex( newVertex1, e, &mesh->vHead );
  MakeVertex( newVertex2, e->Sym, &mesh->vHead );
  MakeFace( newFace, e, &mesh->fHead );
  return e;
}
Example #9
0
/* tessMeshMakeEdge creates one edge, two vertices, and a loop (face).
* The loop consists of the two new half-edges.
*/
THalfEdge *tessMeshMakeEdge(TMesh *pMesh) 
{
	TVertex *newVertex1 = (TVertex*)BucketAlloc(pMesh->pVertexBucket);
	TVertex *newVertex2 = (TVertex*)BucketAlloc(pMesh->pVertexBucket);
	TFace *newFace = (TFace*)BucketAlloc(pMesh->pFaceBucket);
	THalfEdge *e;

	/* if any one is null then all get freed */
	if (newVertex1 == NULL || newVertex2 == NULL || newFace == NULL) 
    {
		if (newVertex1 != NULL) BucketFree (pMesh->pVertexBucket, newVertex1) ;
		if (newVertex2 != NULL) BucketFree (pMesh->pVertexBucket, newVertex2) ;
		if (newFace != NULL) BucketFree (pMesh->pFaceBucket, newFace) ;     
		return NULL;
	} 

	e = MakeEdge (pMesh, &pMesh->eHead) ;
	if (e == NULL) return NULL;

	MakeVertex (newVertex1, e, &pMesh->vHead) ;
	MakeVertex (newVertex2, e->Sym, &pMesh->vHead) ;
	MakeFace (newFace, e, &pMesh->fHead) ;
	return e;
}
Example #10
0
/* tessMeshSplice (eOrg, eDst)  is the basic operation for changing the
* mesh connectivity and topology.  It changes the mesh so that
*	eOrg->Onext <- OLD (eDst->Onext) 
*	eDst->Onext <- OLD (eOrg->Onext) 
* where OLD(...) means the value before the meshSplice operation.
*
* This can have two effects on the vertex structure:
*  - if eOrg->Org != eDst->Org, the two vertices are merged together
*  - if eOrg->Org == eDst->Org, the origin is split into two vertices
* In both cases, eDst->Org is changed and eOrg->Org is untouched.
*
* Similarly (and independently) for the face structure,
*  - if eOrg->Lface == eDst->Lface, one loop is split into two
*  - if eOrg->Lface != eDst->Lface, two distinct loops are joined into one
* In both cases, eDst->Lface is changed and eOrg->Lface is unaffected.
*
* Some special cases:
* If eDst == eOrg, the operation has no effect.
* If eDst == eOrg->Lnext, the new face will have a single edge.
* If eDst == eOrg->Lprev, the old face will have a single edge.
* If eDst == eOrg->Onext, the new vertex will have a single edge.
* If eDst == eOrg->Oprev, the old vertex will have a single edge.
*/
int tessMeshSplice(TMesh* pMesh, THalfEdge *pEdgeOrg, THalfEdge *pEdgeDst) 
{
	int bJoiningLoops = false;
	int bJoiningVertices = false;

	if (pEdgeOrg == pEdgeDst) return 1;

	if (pEdgeDst->pOrigin != pEdgeOrg->pOrigin)  
    {
		/* We are merging two disjoint vertices -- destroy eDst->Org */
		bJoiningVertices = true;
		KillVertex(pMesh, pEdgeDst->pOrigin, pEdgeOrg->pOrigin);
	}
	if (pEdgeDst->Lface != pEdgeOrg->Lface)  
    {
		/* We are connecting two disjoint loops -- destroy eDst->Lface */
		bJoiningLoops = true;
		KillFace(pMesh, pEdgeDst->Lface, pEdgeOrg->Lface);
	}

	/* Change the edge structure */
	Splice(pEdgeDst, pEdgeOrg);

	if (!bJoiningVertices)
    {
		TVertex *pNewVertex = (TVertex*)BucketAlloc(pMesh->pVertexBucket);
		if (pNewVertex == NULL) return 0;

		/* We split one vertex into two -- the new vertex is eDst->Org.
		* Make sure the old vertex points to a valid half-edge.
		*/
		MakeVertex(pNewVertex, pEdgeDst, pEdgeOrg->pOrigin);
		pEdgeOrg->pOrigin->pHalfEdge = pEdgeOrg;
	}
	if (!bJoiningLoops)  
    {
		TFace *pNewFace = (TFace*)BucketAlloc(pMesh->pFaceBucket);
		if (pNewFace == NULL) return 0;

		/* We split one loop into two -- the new loop is eDst->Lface.
		* Make sure the old face points to a valid half-edge.
		*/
		MakeFace(pNewFace, pEdgeDst, pEdgeOrg->Lface);
		pEdgeOrg->Lface->pHalfEdge = pEdgeOrg;
	}

	return 1;
}
/* tessMeshSplice( eOrg, eDst ) is the basic operation for changing the
* mesh connectivity and topology.  It changes the mesh so that
*    eOrg->Onext <- OLD( eDst->Onext )
*    eDst->Onext <- OLD( eOrg->Onext )
* where OLD(...) means the value before the meshSplice operation.
*
* This can have two effects on the vertex structure:
*  - if eOrg->Org != eDst->Org, the two vertices are merged together
*  - if eOrg->Org == eDst->Org, the origin is split into two vertices
* In both cases, eDst->Org is changed and eOrg->Org is untouched.
*
* Similarly (and independently) for the face structure,
*  - if eOrg->Lface == eDst->Lface, one loop is split into two
*  - if eOrg->Lface != eDst->Lface, two distinct loops are joined into one
* In both cases, eDst->Lface is changed and eOrg->Lface is unaffected.
*
* Some special cases:
* If eDst == eOrg, the operation has no effect.
* If eDst == eOrg->Lnext, the new face will have a single edge.
* If eDst == eOrg->Lprev, the old face will have a single edge.
* If eDst == eOrg->Onext, the new vertex will have a single edge.
* If eDst == eOrg->Oprev, the old vertex will have a single edge.
*/
int tessMeshSplice( TESSmesh* mesh, TESShalfEdge *eOrg, TESShalfEdge *eDst )
{
    int joiningLoops = FALSE;
    int joiningVertices = FALSE;

    if( eOrg == eDst ) return 1;

    if( eDst->Org != eOrg->Org ) {
        /* We are merging two disjoint vertices -- destroy eDst->Org */
        joiningVertices = TRUE;
        KillVertex( mesh, eDst->Org, eOrg->Org );
    }
    if( eDst->Lface != eOrg->Lface ) {
        /* We are connecting two disjoint loops -- destroy eDst->Lface */
        joiningLoops = TRUE;
        KillFace( mesh, eDst->Lface, eOrg->Lface );
    }

    /* Change the edge structure */
    Splice( eDst, eOrg );

    if( ! joiningVertices ) {
        TESSvertex *newVertex = (TESSvertex*)bucketAlloc( mesh->vertexBucket );
        if (newVertex == NULL) return 0;

        /* We split one vertex into two -- the new vertex is eDst->Org.
        * Make sure the old vertex points to a valid half-edge.
        */
        MakeVertex( newVertex, eDst, eOrg->Org );
        eOrg->Org->anEdge = eOrg;
    }
    if( ! joiningLoops ) {
        TESSface *newFace = (TESSface*)bucketAlloc( mesh->faceBucket );
        if (newFace == NULL) return 0;

        /* We split one loop into two -- the new loop is eDst->Lface.
        * Make sure the old face points to a valid half-edge.
        */
        MakeFace( newFace, eDst, eOrg->Lface );
        eOrg->Lface->anEdge = eOrg;
    }

    return 1;
}
void CPlayerHP::Update() {
	m_fPlayerHP = m_pPlayer->GetHP();

	MakeVertex();

	D3DXMatrixIdentity(&m_world);

	// 転置行列を求める
	m_world._11 = m_pCamera->GetView()._11;
	m_world._12 = m_pCamera->GetView()._21;
	m_world._13 = m_pCamera->GetView()._31;
	m_world._21 = m_pCamera->GetView()._12;
	m_world._22 = m_pCamera->GetView()._22;
	m_world._23 = m_pCamera->GetView()._32;
	m_world._31 = m_pCamera->GetView()._13;
	m_world._32 = m_pCamera->GetView()._23;
	m_world._33 = m_pCamera->GetView()._33;

	m_world._41 = m_pPlayer->GetWorld()._41;
	m_world._42 = m_pPlayer->GetWorld()._42 + 170.0f;
	m_world._43 = m_pPlayer->GetWorld()._43;
}
/* tessMeshAddEdgeVertex( eOrg ) creates a new edge eNew such that
* eNew == eOrg->Lnext, and eNew->Dst is a newly created vertex.
* eOrg and eNew will have the same left face.
*/
TESShalfEdge *tessMeshAddEdgeVertex( TESSmesh *mesh, TESShalfEdge *eOrg )
{
    TESShalfEdge *eNewSym;
    TESShalfEdge *eNew = MakeEdge( mesh, eOrg );
    if (eNew == NULL) return NULL;

    eNewSym = eNew->Sym;

    /* Connect the new edge appropriately */
    Splice( eNew, eOrg->Lnext );

    /* Set the vertex and face information */
    eNew->Org = eOrg->Dst;
    {
        TESSvertex *newVertex= (TESSvertex*)bucketAlloc( mesh->vertexBucket );
        if (newVertex == NULL) return NULL;

        MakeVertex( newVertex, eNewSym, eNew->Org );
    }
    eNew->Lface = eNewSym->Lface = eOrg->Lface;

    return eNew;
}
Graph* MakeGraph ()
{
	Graph *G = malloc (sizeof (Graph));

	int i, S, Des, Val, W, Val1, Val2;
	Vertex *TempV = NULL;


	printf ("How many vertices: ");
	scanf ("%d", &(G -> NoOfV));

	G -> V = malloc (sizeof (Vertex *) * (G -> NoOfV));
	printf ("Automatic numbering - ");
	for (i = 0; i < (G -> NoOfV); ++i)
	{
		printf ("%d ", i);
		TempV = MakeVertex (i);
		if (TempV == NULL)
		{
			fprintf (stderr, "Error creating vertex.");
			return NULL;
		}
		G -> V[i] = TempV;
	}

	printf ("How many edges: ");
	scanf ("%d", &(G -> NoOfE));

	G -> E = malloc (sizeof (Edge *) * (G -> NoOfE));

	printf ("Directed(1) or Undirected(0): ");
	scanf ("%d", &(G -> Dir));

	printf ("Weighted(1) or Unweighted(0): ");
	scanf ("%d", &(G -> Wt));

	if ((G -> Dir))
	{
		for (i = 0; i < (G -> NoOfE); i++)
		{
			W = 0;
			printf ("\nEdge %d ", i + 1);
			printf ("\nEnter Source: ");
			scanf ("%d", &S);

			printf ("\nEnter destination: ");
			scanf ("%d", &Des);

			if (S > G -> NoOfV || Des > G -> NoOfV)
			{
				fprintf (stderr, "\nInvalid Source or Destination try again!");
				i--;
				continue;
			}

			if ((G -> Wt))
			{
				printf ("\nEnter weight: ");
				scanf ("%d", &W);
			}
			Val = InsertAdj (G -> V[S], G -> V[Des], W);
			if (Val == -1)
			{
				fprintf (stderr, "\nError making adjacency list.");
				i--;
				continue;
			}
			else
				G -> E[i] = MakeEdge (G -> V[S], G -> V[Des], W);
		}
	}
	else
	{
		for (i = 0; i < (G -> NoOfE); i++)
		{
			W = 0;
			printf ("\nEdge %d: ", i + 1);
			printf ("\nEnter first Vertex: ");
			scanf ("%d", &S);

			printf ("\nEnter second Vertex: ");
			scanf ("%d", &Des);

			if (S > G -> NoOfV || Des > G -> NoOfV)
			{
				fprintf (stderr, "\nInvalid Source or Destination try again!");
				i--;
				continue;
			}

			if ((G -> Wt))
			{
				printf ("\nEnter weight: ");
				scanf ("%d", &W);
			}
			Val1 = InsertAdj (G -> V[S], G -> V[Des], W);
			Val2 = InsertAdj (G -> V[Des], G -> V[S], W);
			if (Val1 == -1 || Val2 == -1)
			{
					fprintf (stderr, "\nError making adjacency list.");
					i--;
					continue;
			}

			else
				G -> E[i] = MakeEdge (G -> V[S], G -> V[Des], W);

		}
	}

	/*
	printf ("All data are as follows: \n");
	for (i = 0; i < (G -> NoOfV); i++)
		PrintVertexData(G -> V[i]);

	for (i = 0; i < (G -> NoOfE); i++)
		PrintEdgeData(G -> E[i]);
	*/
	return G;
}