[info-performer] Modifying a triangle mesh at run time

New Message Reply Date view Thread view Subject view Author view

From: Rob Body (rdb++at++hrwallingford.co.uk)
Date: 07/02/2002 01:29:31


Hi Performers,

I have created a triangle mesh using Performer 2.5 and RedHat Linux 7.2 but
don't know how to add a texture to it or modify the vertex's at run time. I
have calculated the new height's of each vertex and modified
vtx_table[i][PF_Z] at run time but the new values aren't drawn.

Code to create the triangles

/*--------------------------------------------------------------------------
*/

DS_create_test_tris(pfScene *scene)
{
   pfGroup *group;
   pfGeode *geode;
   pfGeoSet *gset = NULL;
   pfGeoState *gstate = NULL;
   void *arena = pfGetSharedArena();
   int p;
   int num_vtx;
   int num_triangles;
   int num_indices;
   int *lengths;
   pfVec3 *vtx_table;
   ushort *index_table;
   int num_col;
   pfVec4 *colour;
   ushort *col_index;

   col_index = (ushort*) pfMalloc(sizeof(ushort) * 1, arena);
 
   group = pfNewGroup();
   geode = pfNewGeode();
   gset = pfNewGSet(arena);

   pfAddChild( scene, group);
   pfAddChild(group, geode);
   pfAddGSet(geode, gset);

   num_vtx = 4; /* EXAMPLE */
   /* Allocate memory for vertices in shared memory */
   vtx_table = (pfVec3*) pfMalloc(sizeof(pfVec3) * num_vtx, arena);

   vtx_table[0][PF_X] = 50.0;
   vtx_table[0][PF_Y] = 50.0;
   vtx_table[0][PF_Z] = 2.0;

   vtx_table[1][PF_X] = 75.0;
   vtx_table[1][PF_Y] = 50.0;
   vtx_table[1][PF_Z] = 2.0;

   vtx_table[2][PF_X] = 50.0;
   vtx_table[2][PF_Y] = 75.0;
   vtx_table[2][PF_Z] = 2.0;

   vtx_table[3][PF_X] = 75.0;
   vtx_table[3][PF_Y] = 75.0;
   vtx_table[3][PF_Z] = 2.0;

   num_triangles = 2;
   num_indices = 3 * num_triangles;
   index_table = (ushort*) pfMalloc(sizeof(ushort) * num_indices, arena);

   /* For independent triangles */
   index_table[0] = 0; /* Indexing starts at 0 */
   index_table[1] = 1;
   index_table[2] = 2;

   index_table[3] = 2;
   index_table[4] = 1;
   index_table[5] = 3;

   /* Set up the vertex info of the geoset */

   pfGSetAttr(gset, PFGS_COORD3, PFGS_PER_VERTEX, vtx_table, index_table);

   pfGSetPrimType(gset, PFGS_TRIS);

   pfGSetNumPrims(gset, num_triangles); /* Number of triangles (our
primitive type) */

   /* COLOUR */
   /* ------ */
   /* Use the same colour for all triangles */
   num_col = 1;
   colour = (pfVec4*) pfMalloc(sizeof(pfVec4) * num_col, arena);

   colour[0][0] = 1.0;
   colour[0][1] = 0.0;
   colour[0][2] = 1.0;
   colour[0][3] = 1.0;

   /* Even though only 1 colour is used,
      need a colour index table, since cannot mix indexed and non-indexed
      data on a geoset */

   col_index = (ushort*) pfMalloc(sizeof(ushort) * 1, arena);
   col_index[0] = 0;

   pfGSetAttr (gset, PFGS_COLOR4, PFGS_OVERALL, colour, col_index);
}

/*--------------------------------------------------------------------------
*/

In my loop I update the z values like this:

 for (i = 0;i <= 16385;i++)
 {
  vtx_table[i][PF_Z] = rz[timecount][i];
 }

Can anyone see what I have missed out and advise on how I add a texture to
the triangles. I would like to use one texture, repeated over the whole
triangular surface.

Thanks for any help.

Rob

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Rob Body
Simulator Manager

HR Mardyn
HR Wallingford
Howbery Park
Wallingford
Oxon
OX10 8BA

Tel +44 (0) 1491 822327
Fax +44 (0) 1491 832233

E-mail r.body++at++hrwallingford.co.uk <mailto:r.body++at++hrwallingford.co.uk>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
HR Wallingford uses Faxes and Emails for confidential and
legally privileged business communications. They do not of
themselves create legal commitments. Disclosure to parties
other than addressees requires our specific consent. We are
not liable for unauthorised disclosures nor reliance upon
them. If you have received this message in error please
advise us immediately and destroy all copies of it.
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Tue Jul 02 2002 - 01:31:16 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.