ceti (ceti++at++worldnet.net)
Tue, 12 Mar 1996 17:05:51 +0000
So if anybody could send me a sample to morph two iv objects or just tell me
what is wrong in the following
I will appreciate a lot ..
*******************************************************************
#include <stdlib.h>
#include <math.h>
#include <Performer/pf.h>
#include <Performer/pfdu.h>
int nSph;
static void breatheMorph(pfMorph *morph, double t)
{
float s = (sinf(t) + 1.0f) / 2.0f;
float weights[2];
weights[0] = s;
weights[1] = 1.0f - s;
pfMorphWeights(morph, 0, weights);
pfMorphWeights(morph, 1, weights);
}
static pfMorph* initMorph(char *namesource, char *namecible)
{
pfGeoSet *cible;
pfGeoSet *source;
pfGeode *geode;
pfGeoState *gstate;
pfMaterial *mtl;
pfMorph *morph;
ushort *icoords, *inorms;
pfVec3 *coords, *obcoords, *norms, *obnorms;
pfVec4 *colors;
float *srcs[2];
int i;
void *arena = pfGetSharedArena();
morph = pfNewMorph();
geode = pfNewGeode();
source = (pfGeoSet*)pfdLoadFile(namesource);
/*source = pfdNewSphere(400, arena);*/
if(source==NULL)
{
pfNotify(PFNFY_NOTICE, PFNFY_PRINT,"WARNING: could not load
\"%s\"",namesource);
exit(0);
}
cible = (pfGeoSet*)pfdLoadFile(namecible);
/*cible = pfdNewArrow(400, arena);*/
if(cible==NULL)
{
pfNotify(PFNFY_NOTICE, PFNFY_PRINT,"WARNING: could not load
\"%s\"",namecible);
exit(0);
}
gstate = pfNewGState(arena);
pfGStateMode(gstate, PFSTATE_ENLIGHTING, 1);
pfGSetGState(source, gstate);
pfAddGSet(geode, source);
pfAddChild(morph, geode);
pfGSetBBox(source, NULL, PFBOUND_STATIC);
pfNodeBSphere(geode, NULL, PFBOUND_STATIC);
pfGetGSetAttrLists(source, PFGS_COORD3, (void**)&coords, &icoords);
pfGetGSetAttrLists(cible, PFGS_COORD3, (void**)&obcoords, &icoords);
pfGetGSetAttrLists(source, PFGS_NORMAL3, (void**)&norms, &inorms);
pfGetGSetAttrLists(cible, PFGS_NORMAL3, (void**)&obnorms, &icoords);
nSph = pfGetSize(coords) / sizeof(pfVec3);
srcs[0] = (float*)coords;
srcs[1] = (float*)obcoords;
pfMorphAttr(morph, 0, 3, nSph, NULL, 2, srcs, NULL, NULL);
pfGSetAttr(source, PFGS_COORD3, PFGS_PER_VERTEX,
(void*)pfGetMorphDst(morph, 0), icoords);
srcs[0] = (float*)norms;
srcs[1] = (float*)obnorms;
pfMorphAttr(morph, 1, 3, nSph, NULL, 2, srcs, NULL, NULL);
pfGSetAttr(source, PFGS_NORMAL3, PFGS_PER_VERTEX,
(void*)pfGetMorphDst(morph, 1), inorms);
return morph;
}
void OpenPipeWin (pfPipeWindow *pw)
{
pfOpenPWin(pw);
pfApplyLModel(pfNewLModel(NULL));
}
void
DrawChannel (pfChannel *chan, void *data)
{
pfVec4 clr;
pfSetVec4(clr, .2f, .2f, .2f, 1.0f);
pfClear(PFCL_COLOR|PFCL_DEPTH, clr);
pfDraw();
}
int
main (int argc, char *argv[])
{
double t = 0.;
pfScene *scene;
pfDCS *morphDCS;
pfMorph *morph;
pfPipe *p;
pfPipeWindow *pw;
pfChannel *chan;
pfSphere bsphere;
pfCoord view;
pfLightSource *ls;
if(argc<3)
{
printf("use: %s <objet source> <objet cible>\n",argv[0]);
exit(0);
}
pfInit();
pfMultiprocess(PFMP_DEFAULT);
pfConfig();
scene = pfNewScene();
morphDCS = pfNewDCS();
morph = initMorph(argv[1],argv[2]);
pfAddChild(morphDCS, morph);
pfAddChild(scene, morphDCS);
pfGetNodeBSphere (scene, &bsphere);
p = pfGetPipe(0);
pw = pfNewPWin(p);
pfPWinName(pw, argv[0]);
pfPWinConfigFunc(pw, OpenPipeWin);
pfPWinOriginSize(pw, 0, 0, 500, 500);
pfConfigPWin(pw);
chan = pfNewChan(p);
pfChanScene(chan, scene);
pfChanNearFar(chan, 1.0f, 10.0f * bsphere.radius);
pfChanFOV(chan, 45.0f, 0.0f);
pfCopyVec3(view.xyz, bsphere.center);
view.xyz[PF_Y] -= 3.0f * bsphere.radius;
pfSetVec3(view.hpr, 0.0f, 0.0f, 0.0f);
pfChanView(chan, view.xyz, view.hpr);
pfChanTravFunc(chan, PFTRAV_DRAW, DrawChannel);
ls = pfNewLSource();
pfLSourcePos(ls, view.xyz[0], view.xyz[1], view.xyz[2], 1.0f);
pfAddChild(scene, ls);
while (t < 20.0f)
{
pfMatrix mat;
/* Spin morph object */
t = pfGetTime();
pfMakeRotMat(mat, t*57.0f, 1.0f, -0.3f, 1.0f);
pfDCSMat(morphDCS, mat);
breatheMorph(morph, t);
pfFrame();
}
pfExit();
return 0;
}
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
< _/_/ _/ _/_/_/ _/ _/ _/_/_/ _/_/_/ _/_/_/ >
< _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ >
< _/ _/ _/ _/ _/ _/ _/ _/_/_/ _/ _/ >
< _/ _/ _/ _/ _/ _/ _/ _/ _/_/_/ >
< _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ >
< _/_/ _/_/_/ _/_/_/ _/ _/_/_/ _/_/_/ _/ _/ >
< >
< BILLARD Olivier - Ingeneer R&D ++at++ C&I Software >
< 1 avenue de la mer - 44380 PORNICHET - FRANCE >
< Tel: +33 40 11 68 72 Fax: +33 140 61 68 14 >
< Email: ceti++at++worldnet.net >
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:52:32 PDT