Billboard/Transparency problem

New Message Reply Date view Thread view Subject view Author view

Prakash Mahesh (prakash++at++DRAWCOMP.COM)
Mon, 16 Nov 1998 11:48:38 -0500


I am attaching badBill.C file along with the shared object we made with
that. The C file has on the top the compile line to make the shared
object.

All it does is makes a dummy wrl loader, so that when you give a .wrl
file (any name) name, it loads this shared object and shows the problem.

The dummy loader creats two boxes, one with billboard and the other a
simple box. And there is transparency applied to them.

When you try to move the scene with your mouse right-left, the
un-billboarded box jumps on to top of the billboarded box.

If I replace the box with a cylinder parts of cylinder jumps. It is so
strange!

Is this a bug of some kind? I would really appreciate the performer
folks or any other in the mailing list who have encountered this problem
to let me know what the problem is, and if there is any workaround/fix.

Thanks.

-- 
  Prakash Mahesh                                     
  prakash++at++drawcomp.com
  	--or--
  prakash++at++openworlds.com

/* *This loader creates two boxes, the one on the left is billboarded, *the one on the right is normal. The non-billboarded box shifts at certain positions *if transparency is turned on (FAIL is defined). When the boxes appear, rotate holding *the middle mouse button down and the objects towards you. The non-billboarded box *on the right will "jump" at a certain position. * *run with perfly and a non-existing "wrl" file: * perfly -W800,800 a.wrl * *To build: CC -n32 -all -shared -check_registry /usr/lib/so_locations -exceptions -D_OWEXCEPTIONS_ -D_OWNOLICENSE_ -set_version sgi4.0.440 badbill.C -o libpfwrl_ogl.so * */ #include <iostream.h> #include <Performer/pf.h> #include <Performer/pf/pfScene.h>

#include <malloc.h> #include <stdio.h> #include <Performer/pr/pfMaterial.h>

#include <Performer/pf/pfDCS.h> #include <Performer/pf/pfGeode.h> #include <Performer/pf/pfBillboard.h>

pfDCS *topSceneGraph; pfGeode *addBox(float xV, float yV, float zV); pfGeode *addBillboardBox(float xV, float yV, float zV); pfDCS *addDCS(float x, float y, float z);

//define FAIL to see the bad shifting behavior #define FAIL 1

//the main loader routine extern "C" pfNode *pfdLoadFile_wrl(char *fileName) { fprintf(stderr,"\n\n--------------------DUMMY WRLLOADER-----------------\n"); topSceneGraph = new pfDCS();

//add group pfDCS *dcs1= addDCS(10.,0.,0.); dcs1->addChild(addBox(1.,4.,9.));

//add group pfDCS *dcs2= addDCS(0.,0.,0.); dcs2->addChild(addBillboardBox(10.,2.,.4)); pfDCS *sceneMatrix = new pfDCS();

sceneMatrix->addChild(dcs1); sceneMatrix->addChild(dcs2); // topSceneGraph->addChild(sceneMatrix); topSceneGraph->addChild(dcs1); topSceneGraph->addChild(dcs2); return topSceneGraph; }

//adds a material for the geoset //the turning on transparency is causing problems for billboard void addmat(pfGeoSet *gset){ void *arena = pfGetSharedArena(); pfGeoState *gst = new(arena) pfGeoState; gset->setGState(gst); //fprintf(stderr,"\n\n------------------BOTH\n\n"); pfMaterial *mtl= new pfMaterial; #if 0 mtl->setSide(PFMTL_BOTH); //fprintf(stderr,"\n\n------------------BOTH\n\n"); mtl->setColor(PFMTL_DIFFUSE, .2,.2,.2); mtl->setColor(PFMTL_SPECULAR, .2,.2,.2); mtl->setColor(PFMTL_AMBIENT, .2,.2,.2); mtl->setColor(PFMTL_EMISSION,.2,.2,.4); mtl->setColorMode(PFMTL_BOTH, PFMTL_CMODE_OFF); mtl->setAlpha(1.); mtl->setShininess(0.); #endif gst->setAttr(PFSTATE_FRONTMTL, mtl); gst->setAttr(PFSTATE_BACKMTL, mtl); #if 0 gst->setMode(PFSTATE_ENLIGHTING, 1); gst->setMode(PFSTATE_ALPHAFUNC, PFAF_GREATER); gst->setVal(PFSTATE_ALPHAREF, .01); #endif #ifdef FAIL gst->setMode(PFSTATE_TRANSPARENCY, PFTR_ON); #endif }

//adds a DCS with translation x,y,z pfDCS * addDCS(float x, float y, float z) { pfDCS *dcs = new pfDCS; pfMatrix TR; TR.makeIdent(); TR.preTrans(x,y,z,TR); dcs->setMat(TR); return dcs; }

//adds a regular box pfGeode * addBox(float xV, float yV, float zV) { pfGeode *geoDE; void *arena; pfVec3 *normals; pfVec2 *txtCoords; pfVec3 *Coords; ushort *normIndex, *ptIndex, *txtIndex; int i,j;

geoDE = new pfGeode; arena = pfGetSharedArena(); #if 0 normals = (pfVec3*)pfMalloc(sizeof(pfVec3)*6, arena); normals[0].set( 0.0f, 0.0f, 1.0f); //Front normals[1].set( 0.0f, 0.0f, -1.0f); //Back normals[2].set(-1.0f, 0.0f, 0.0f); //Left normals[3].set( 1.0f, 0.0f, 0.0f); //Right normals[4].set( 0.0f, 1.0f, 0.0f); //Top normals[5].set( 0.0f, -1.0f, 0.0f); //Bottom #endif Coords = (pfVec3*)pfMalloc(sizeof(pfVec3)*8, arena);

float x, y, z; x = xV/2; y = yV/2; z = zV/2; Coords[0].set(-x, -y, z); Coords[1].set( x ,-y, z); Coords[2].set( x, y, z); Coords[3].set(-x, y, z); Coords[4].set(-x, -y, -z); Coords[5].set( x, -y, -z); Coords[6].set( x, y, -z); Coords[7].set(-x, y, -z); #if 0 normIndex = (ushort*)pfMalloc(sizeof(ushort)*24, arena);

j = -1; for (i=0; i<24; i++){ if (i%4 == 0) j++; normIndex[i] = j; } #endif ptIndex = (ushort*)pfMalloc(sizeof(ushort)*24, arena); ptIndex[0] = 0; ptIndex[1] = 1; ptIndex[2] = 2; ptIndex[3] = 3; /* front */ ptIndex[4] = 5; ptIndex[5] = 4; ptIndex[6] = 7; ptIndex[7] = 6; /* left */ ptIndex[8] = 4; ptIndex[9] = 0; ptIndex[10] = 3; ptIndex[11] = 7; /* back */ ptIndex[12]= 1; ptIndex[13] = 5; ptIndex[14] = 6; ptIndex[15] = 2; /* right */ ptIndex[16]= 3; ptIndex[17] = 2; ptIndex[18] = 6; ptIndex[19] = 7; /* top */ ptIndex[20]= 4; ptIndex[21] = 5; ptIndex[22] = 1; ptIndex[23] = 0; /*bottom*/

pfGeoSet *gset; gset = new pfGeoSet; gset->setAttr(PFGS_COORD3, PFGS_PER_VERTEX, Coords, ptIndex);

// gset->setAttr(PFGS_NORMAL3, PFGS_PER_VERTEX, normals, normIndex); gset->setPrimType(PFGS_QUADS); gset->setNumPrims(6);

geoDE->addGSet(gset);

addmat(gset); return geoDE; }

//adds a billboarded box pfGeode * addBillboardBox(float xV, float yV, float zV) { pfGeode *geoDE; void *arena; pfVec3 *normals; pfVec2 *txtCoords; pfVec3 *Coords; ushort *normIndex, *ptIndex, *txtIndex; int i,j;

geoDE = new pfBillboard; arena = pfGetSharedArena(); #if 0 normals = (pfVec3*)pfMalloc(sizeof(pfVec3)*6, arena); normals[0].set( 0.0f, 0.0f, 1.0f); //Front normals[1].set( 0.0f, 0.0f, -1.0f); //Back normals[2].set(-1.0f, 0.0f, 0.0f); //Left normals[3].set( 1.0f, 0.0f, 0.0f); //Right normals[4].set( 0.0f, 1.0f, 0.0f); //Top normals[5].set( 0.0f, -1.0f, 0.0f); //Bottom #endif Coords = (pfVec3*)pfMalloc(sizeof(pfVec3)*8, arena);

float x, y, z; x = xV/2; y = yV/2; z = zV/2; Coords[0].set(-x, -y, z); Coords[1].set( x ,-y, z); Coords[2].set( x, y, z); Coords[3].set(-x, y, z); Coords[4].set(-x, -y, -z); Coords[5].set( x, -y, -z); Coords[6].set( x, y, -z); Coords[7].set(-x, y, -z); #if 0 normIndex = (ushort*)pfMalloc(sizeof(ushort)*24, arena);

j = -1; for (i=0; i<24; i++){ if (i%4 == 0) j++; normIndex[i] = j; } #endif ptIndex = (ushort*)pfMalloc(sizeof(ushort)*24, arena); ptIndex[0] = 0; ptIndex[1] = 1; ptIndex[2] = 2; ptIndex[3] = 3; /* front */ ptIndex[4] = 5; ptIndex[5] = 4; ptIndex[6] = 7; ptIndex[7] = 6; /* left */ ptIndex[8] = 4; ptIndex[9] = 0; ptIndex[10] = 3; ptIndex[11] = 7; /* back */ ptIndex[12]= 1; ptIndex[13] = 5; ptIndex[14] = 6; ptIndex[15] = 2; /* right */ ptIndex[16]= 3; ptIndex[17] = 2; ptIndex[18] = 6; ptIndex[19] = 7; /* top */ ptIndex[20]= 4; ptIndex[21] = 5; ptIndex[22] = 1; ptIndex[23] = 0; /*bottom*/

pfGeoSet *gset; gset = new pfGeoSet; gset->setAttr(PFGS_COORD3, PFGS_PER_VERTEX, Coords, ptIndex); // gset->setAttr(PFGS_TEXCOORD2, PFGS_PER_VERTEX, txtCoords, txtIndex); // gset->setAttr(PFGS_NORMAL3, PFGS_PER_VERTEX, normals, normIndex); gset->setPrimType(PFGS_QUADS); gset->setNumPrims(6); // gset->setGState(gsStack->top()); geoDE->addGSet(gset);

addmat(gset); return geoDE; }



New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Nov 16 1998 - 08:57:08 PST

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