From: Angus Dorbie (dorbie++at++sgi.com)
Date: 12/11/2000 07:10:40
OK, it appears the problem is related to the indexing of the attribute
data.
If I remove the indexing and explicitly specify vertices then I get
varying primitive return information. I've attached the modified
tristrip intersection code.
Cheers,Angus.
#include <stdio.h>
#include <math.h>
#include <X11/keysym.h>
#include <stdlib.h>
#include <Performer/pf/pfChannel.h>
#include <Performer/pf/pfEarthSky.h>
#include <Performer/pf/pfGeode.h>
#include <Performer/pf/pfSCS.h>
#include <Performer/pr/pfGeoSet.h>
typedef struct SharedData
{
int exitFlag;
int showStats;
float yval;
float zval;
} SharedData;
static void DrawChannel (pfChannel *chan, void *data);
static void OpenPipeWin (pfPipeWindow *pw);
SharedData *shared;
int
main(int argc, char *argv[])
{
pfSCS *scs[10];
pfMatrix mat;
pfCoord view;
pfSegSet segset;
int loop;
// Initialize Performer
pfInit();
// Use default multiprocessing mode based on number of processors.
pfMultiprocess(PFMP_DEFAULT);
// Malloc storage in shared memory region for shared data
shared = (SharedData *) pfMalloc(sizeof(SharedData),pfGetSharedArena());
// Configure multiprocessing mode and start parallel processes
pfConfig();
shared->exitFlag = 0;
shared->showStats = 0;
//
// Configure and open GL window
//
pfPipe *pipe = pfGetPipe(0);
pfPipeWindow *pw = new pfPipeWindow(pipe);
pw->setWinType(PFPWIN_TYPE_X);
pw->setName(argv[0]);
pw->setOriginSize(0, 0, 500, 500);
// Open and configure the GL window.
pw->setConfigFunc(OpenPipeWin);
pw->config();
pfFrameRate(30.0f);
// Create & configure channel
pfChannel *chan = new pfChannel(pipe);
chan->setTravFunc(PFTRAV_DRAW, DrawChannel);
chan->setNearFar(0.1f, 10000.0f);
chan->setFOV(45.0f, -1.0f);
// Add an earth/sky effect
pfEarthSky *esky = new pfEarthSky();
esky->setMode(PFES_BUFFER_CLEAR, PFES_SKY_GRND);
esky->setAttr(PFES_GRND_HT, 0.0f);
esky->setColor(PFES_GRND_FAR, 0.3f, 0.1f, 0.0f, 1.0f);
esky->setColor(PFES_GRND_NEAR, 0.5f, 0.3f, 0.1f, 1.0f);
chan->setESky(esky);
//
// Create pfScene node, attach it to channel
//
pfScene *scene = new pfScene();
chan->setScene(scene);
// Create group node to hold SCS's; attach it to scene
pfGroup *root = new pfGroup();
scene->addChild(root);
// Create 10 SCS nodes, spaced equally apart. Make each one
// a child of 'root', and make 'geode' a child of each SCS
pfGeode *geode = new pfGeode();
for (loop=0; loop < 10; loop++)
{
mat.makeTrans(0.0f, (float) loop * 10.0f + 10.0f, 0.0f);
scs[loop] = new pfSCS(mat);
scs[loop]->addChild(geode);
root->addChild(scs[loop]);
// set up SCS's (and their children) for intersections
scs[loop]->setTravMask(PFTRAV_ISECT, 1, PFTRAV_SELF,
PF_SET);
}
// Create a GeoSet to hold the ramp geometry
// pfGeoSet *gset = new pfGeoSet(pfGetSharedArena());
pfVec3 *verts = (pfVec3*) new(24*sizeof(pfVec3)) pfMemory;
//verts[0].set(-1.0f, -1.0f, 1.0f);
//verts[1].set( 1.0f, -1.0f, 1.0f);
//verts[2].set( 1.0f, 1.0f, 1.0f);
//verts[3].set(-1.0f, 1.0f, 1.0f);
//verts[4].set(-2.0f, -2.0f, 0.0f);
//verts[5].set( 2.0f, -2.0f, 0.0f);
//verts[6].set( 2.0f, 2.0f, 0.0f);
//verts[7].set(-2.0f, 2.0f, 0.0f);
verts[0].set(-1.0f, -1.0f, 1.0f);
verts[1].set( 1.0f, -1.0f, 1.0f);
verts[2].set(-1.0f, 1.0f, 1.0f);
verts[3].set( 1.0f, 1.0f, 1.0f);
verts[4].set(-1.0f, -1.0f, 1.0f);
verts[5].set(-1.0f, 1.0f, 1.0f);
verts[6].set(-2.0f, -2.0f, 0.0f);
verts[7].set(-2.0f, 2.0f, 0.0f);
verts[8].set(-2.0f, -2.0f, 0.0f);
verts[9].set(-2.0f, 2.0f, 0.0f);
verts[10].set( 2.0f, -2.0f, 0.0f);
verts[11].set( 2.0f, 2.0f, 0.0f);
verts[12].set( 1.0f, -1.0f, 1.0f);
verts[13].set( 2.0f, -2.0f, 0.0f);
verts[14].set( 1.0f, 1.0f, 1.0f);
verts[15].set( 2.0f, 2.0f, 0.0f);
verts[16].set(-1.0f, 1.0f, 1.0f);
verts[17].set( 1.0f, 1.0f, 1.0f);
verts[18].set(-2.0f, 2.0f, 0.0f);
verts[19].set( 2.0f, 2.0f, 0.0f);
verts[20].set(-1.0f, -1.0f, 1.0f);
verts[21].set(-2.0f, -2.0f, 0.0f);
verts[22].set( 1.0f, -1.0f, 1.0f);
verts[23].set( 2.0f, -2.0f, 0.0f);
//*********************************************************************
// Following is Changed
ushort *vindex = (ushort*) new(24*sizeof(ushort)) pfMemory;
vindex[0] = 0; vindex[1] = 1; vindex[2] = 3; vindex[3] = 2; // top
vindex[4] = 0; vindex[5] = 3; vindex[6] = 4; vindex[7] = 7; // left
vindex[8] = 4; vindex[9] = 7; vindex[10] = 5; vindex[11] = 6; // bottom
vindex[12] = 1; vindex[13] = 5; vindex[14] = 2; vindex[15] = 6; // right
vindex[16] = 3; vindex[17] = 2; vindex[18] = 7; vindex[19] = 6; // back
vindex[20] = 0; vindex[21] = 4; vindex[22] = 1; vindex[23] = 5; // front
pfVec4 *colors = (pfVec4*) new(4*sizeof(pfVec4)) pfMemory;
colors[0].set(1.0f, 0.0f, 0.0f, 0.5f);
colors[1].set(0.0f, 1.0f, 0.0f, 0.5f);
colors[2].set(0.0f, 0.0f, 1.0f, 0.5f);
colors[3].set(1.0f, 1.0f, 1.0f, 0.5f);
ushort *cindex = (ushort*) new(24*sizeof(ushort)) pfMemory;
cindex[0] = 0; cindex[1] = 1; cindex[2] = 3; cindex[3] = 2;
cindex[4] = 0; cindex[5] = 1; cindex[6] = 3; cindex[7] = 2;
cindex[8] = 0; cindex[9] = 1; cindex[10] = 3; cindex[11] = 2;
cindex[12] = 0; cindex[13] = 1; cindex[14] = 3; cindex[15] = 2;
cindex[16] = 0; cindex[17] = 1; cindex[18] = 3; cindex[19] = 2;
cindex[20] = 0; cindex[21] = 1; cindex[22] = 3; cindex[23] = 2;
int *length = (int *) new(6*sizeof(int)) pfMemory;
for(uint i=0; i<6; i++)
length[i] = 4;
pfGeoSet *gset = new pfGeoSet;
gset->setPrimType(PFGS_TRISTRIPS);
gset->setPrimLengths(length);
gset->setAttr(PFGS_COORD3, PFGS_PER_VERTEX, verts, NULL);
gset->setAttr(PFGS_COLOR4, PFGS_OVERALL, colors, NULL);
gset->setNumPrims(6);
//****************************************************************************
// attach it to the parent geode
geode->addGSet(gset);
//
// set initial view position
//
shared->yval=0.0f;
shared->zval=0.5f;
// set up intersection segment, pointing down
// for "terrain" following
segset.activeMask = 1;
segset.isectMask = 0xFFFF;
segset.discFunc = NULL;
segset.bound = NULL;
//*************************************************************
//You also don't discard the CULL_BACK
//segset.mode = PFTRAV_IS_PRIM|PFTRAV_IS_NORM|PFTRAV_IS_CULL_BACK;
//After change
segset.mode = PFTRAV_IS_PRIM|PFTRAV_IS_NORM|PFTRAV_IS_CULL_BACK;
//***************************************************************
segset.segs[0].dir.set(0.0f, 0.0f, -1.0f);
segset.segs[0].length = 50000.0f;
//
// main loop
//
while (!shared->exitFlag)
{
pfHit **hits[32];
int isect;
view.xyz.set(0.0f, shared->yval, shared->zval);
view.hpr.set(0.0f, -5.0f, 0.0f);
chan->setView(view.xyz, view.hpr);
pfFrame();
// increment view position; if too far, reset
shared->yval += 0.1f;
if (shared->yval > 110.0f) shared->yval = 0.0f;
// update location of intersection segment
segset.segs[0].pos.set(0.0f, shared->yval,shared->zval);
// do an intersection test against the scene graph
isect = root->isect(&segset, hits);
// if successful, set our height to that of
// the point of contact, plus a small offset
if (isect)
{
pfVec3 pnt, xpnt;
pfMatrix xmat;
(*hits[0])->query(PFQHIT_POINT, pnt.vec);
// transform object point into scene coordinates
(*hits[0])->query(PFQHIT_XFORM, (float*)xmat.mat);
//****************************************************
//Following are added
unsigned int flag;
(*hits[0])->query(PFQHIT_FLAGS, &flag);
if( !(flag&PFHIT_PRIM))
printf("error!\n");
int prim_index, tri_index;
(*hits[0])->query(PFQHIT_PRIM, &prim_index);
(*hits[0])->query(PFQHIT_TRI, &tri_index);
printf("prim_index = %d\t tri_index = %d\n", prim_index,
tri_index);
//****************************************************
xpnt.xformPt(pnt, xmat);
shared->zval = xpnt[PF_Z] + 0.5f;
}
}
pfExit();
return 0;
}
//
// Pipe Initialization Callback to open and configure
// GL window, and set up GL event handling
//
static void
OpenPipeWin(pfPipeWindow *pw)
{
Display *dsp;
Window win;
pw->open();
dsp = pfGetCurWSConnection();
win = pw->getWSWindow();
XSelectInput(dsp, win, KeyPressMask);
XMapWindow(dsp, win);
}
//
// Draw Process Callback to draw the channel and handle GL events
//
static void DrawChannel (pfChannel *chan, void *)
{
Display *dsp;
// clear and draw the channel
chan->clear();
pfDraw();
dsp = pfGetCurWSConnection();
if (XEventsQueued(dsp, QueuedAfterFlush))
while (XEventsQueued(dsp, QueuedAlready))
{
XEvent event;
XNextEvent(dsp, &event);
switch (event.type)
{
case KeyPress:
{
char buf[100];
int rv;
KeySym ks;
rv = XLookupString(&event.xkey, buf, sizeof(buf), &ks, 0);
switch(ks)
{
case XK_Escape:
exit(0);
break;
case XK_F1:
case XK_g:
shared->showStats = !shared->showStats;
break;
default:
break;
}
}
}
}
if (shared->showStats) chan->drawStats();
}
This archive was generated by hypermail 2b29 : Mon Dec 11 2000 - 07:10:50 PST