Makeing Ellipsoid fuction in performer....

New Message Reply Date view Thread view Subject view Author view

From: ÀÌ»óà (vaper3++at++dreamwiz.com)
Date: 08/04/2001 03:01:28


Hello !

I'm a new user of performer.

I'm trying to convert OpenGl code drawing ellipsoid to Performer.
But I can't do this. Please help me.

Here is my OpenGl cord(In MS C++).

---------------------------------------------Begin

void Ellipse3D(float a, float b, float c);

void Ellipse3D(float a, float b, float c)
{
 float PI =3.141593f;
 float x2 = 0.0f, y2 = 0.0f, z2 = 0.0f, d2 = 0.0f;
 float x1 = 0.0f, y1 = 0.0f, z1 = 0.0f, d1 = 0.0f;
 int step = 2;
 int slice = 20;
 float phi = PI/slice;

 z1 = c;
 d1 = 0;

 for(int i=step; i<=slice; i+=step)
 {
  z2 = c*cos(i*phi);
  d2 = sqrt(1-pow(z2/c,2));

  glBegin(GL_QUAD_STRIP);
  for(int j=2*slice; j>=0; j-=step)
  {
   glNormal3f(cos(phi*j)*sin(phi*i), sin(phi*j)*sin(phi*i), cos(phi*i));
   glVertex3f(a*d2*cos(phi*j), b*d2*sin(phi*j), z2);
   
   glNormal3f(cos(phi*j)*sin((i-step)*phi), sin(phi*j)*sin((i-step)*phi), cos((i-step)*phi));
   glVertex3f(a*d1*cos(phi*j), b*d1*sin(phi*j), z1);
  }
  glEnd();

  z1 = z2;
  d1 = d2;
 }

---------------------------------------------------------End

And my performer sorce (based on gset.C)

-------------------------------------------------------Begin
#include <Performer/pr/pfWindow.h>
#include <Performer/pr/pfGeoSet.h>
#include <Performer/pr/pfGeoState.h>
#include <Math.h>



int main (void)
{
    float t = 0.0f;

    // Initialize Performer
    pfInit();
    pfInitState(NULL);

    // Initialize GL
    pfWindow *win = new pfWindow;
    win->setOriginSize(100, 100, 500, 500);
    win->setName("OpenGL Performer");
    win->setWinType(PFWIN_TYPE_X);
    win->open();

    // set up the window
    pfFrustum *frust = new pfFrustum;
    frust->apply();
    delete frust;

    pfAntialias(PFAA_ON);
    pfCullFace(PFCF_OFF);

    // Set up a geoset

    pfVec3 *coords = new pfVec3[2];
    pfVec3 *norms = new pfVec3[2];
 
    int vertex_coun=0t;

    float a = 5;
    float b = 5;
    float c = 5;

    float PI =3.141593f;
    float x2 = 0.0f, y2 = 0.0f, z2 = 0.0f, d2 = 0.0f;
    float x1 = 0.0f, y1 = 0.0f, z1 = 0.0f, d1 = 0.0f;
    int step = 2;
    int slice = 20;
    float phi = PI/slice;

   z1 = c;
   d1 = 0;


   for(int i=step; i<=slice; i+=step)
  {
      z2 = c*cos(i*phi);
      d2 = sqrt(1-pow(z2/c,2));

      for(int j=2*slice; j>=0; j-=step)
     {
         norms(vertex_count).set(cos(phi*j)*sin(phi*i), sin(phi*j)*sin(phi*i), cos(phi*i));
         coords(vertex_count).set(a*d2*cos(phi*j), b*d2*sin(phi*j), z2);

         norms(vertex_count).set(cos(phi*j)*sin((i-step)*phi), sin(phi*j)*sin((i-step)*phi), cos((i-step)*phi));
         coords(vertex_count).set(a*d1*cos(phi*j), b*d1*sin(phi*j), z1);
         vertex_count++;
      }
      z1 = z2;
      d1 = d2;
   }
    
    pfVec4 *colors = new pfVec4[4];
    colors[0].set(1.0f, 1.0f, 1.0f, 1.0f);
    colors[1].set(0.0f, 0.0f, 1.0f, 1.0f);
    colors[2].set(1.0f, 0.0f, 0.0f, 1.0f);
    colors[3].set(0.0f, 1.0f, 0.0f, 1.0f);

    pfGeoSet *gset = new pfGeoSet;
    gset->setAttr(PFGS_COORD3, PFGS_PER_VERTEX, coords, NULL);
    gset->setAttr(PFGS_COLOR4, PFGS_PER_VERTEX, colors, NULL);
    gset->setAttr(PFGS_NORMAL3, PFGS_PER_VERTEX, norms, NULL);

    gset->setPrimType(PFGS_TRISTRIPS);
    gset->setNumPrims(vertex_count);

    // Set up a geostate, backface removal turned off
    pfGeoState *gstate = new pfGeoState;
    gstate->setMode(PFSTATE_CULLFACE, PFCF_OFF);
    gset->setGState(gstate);

    pfTranslate (0.0f, 0.0f, -4.0f);

    // Simulate for twenty seconds.
    pfInitClock (0.0f);
    while (t < 20.0f)
    {
        static pfVec4 clr(0.1f, 0.0f, 0.4f, 1.0f);

 t = pfGetTime();
 pfClear(PFCL_COLOR | PFCL_DEPTH, &clr);
 pfRotate (PF_Y, 1.0f);
 gset->draw();

 win->swapBuffers();
    }
    return 0;
}

-------------------------------------------------------End


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Sat Aug 04 2001 - 02:53:45 PDT

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