Module: dmesh.cpp

class DMesh
.h

constructorDMesh()

: DObject()

destructor~DMesh()
GetPolyDPoly *GetPoly(int n)
Definevoid Define(int ps)
DefineFlat2Dvoid DefineFlat2D(int w,int h,int xOff,int yOff)

Define a single flat polygon of the right size

DefineDSvoid DefineDS(int w,int h,int xOff,int yOff)

Define a double-sided flat area (2 polygons, 0=front, 1=back)

_Paintvoid _Paint()


/*
 * DMesh - definition/implementation
 * 06-08-1999: Now a subclass of DObject, which contains universe position
 * NOTES:
 * - Generated by mkclass
 * (C) 19-02-1999 (17:35) MarketGraph/RVG
 */

#include <d3/d3.h>
#include <qlib/debug.h>
DEBUG_ENABLE

DMesh::DMesh()
  : DObject()
{
  poly=0;
  polys=0;
  apolys=0;
  // Begin with some allocated polygons; assume a cube
  Define(6);
}

DMesh::~DMesh()
{
  int i;
//qdbg("DMesh dtor\n");
  for(i=0;i<apolys;i++)
    delete poly[i];
  if(poly)qfree(poly);
}

DPoly *DMesh::GetPoly(int n)
{
  if(!poly)return 0;
  if(n<0||n>=polys)return 0;
  return poly[n];
}

void DMesh::Define(int ps)
{ int i;
  apolys=ps;
  //poly=(DPoly*)qcalloc(apolys*sizeof(DPoly));
  poly=(DPoly**)qcalloc(apolys*sizeof(void*));
  for(i=0;i<apolys;i++)
  { poly[i]=new DPoly();
  }
}

void DMesh::DefineFlat2D(int w,int h,int xOff,int yOff)
// Define a single flat polygon of the right size
{
  DPolyPoint p;
  DPoly *pl;
  int n;

  n=polys;
  pl=poly[n];
  pl->Define(4);
  p.x=-w/2+xOff; p.y=-h/2+yOff; p.z=0;
  p.tx=0; p.ty=0;
  pl->DefinePoint(0,&p);
  p.x=w/2+xOff; p.y=-h/2+yOff; p.z=0;
  p.tx=1; p.ty=0;
  pl->DefinePoint(1,&p);
  p.x=w/2+xOff; p.y=h/2+yOff; p.z=0;
  p.tx=1; p.ty=1;
  pl->DefinePoint(2,&p);
  p.x=-w/2+xOff; p.y=h/2+yOff; p.z=0;
  p.tx=0; p.ty=1;
  pl->DefinePoint(3,&p);
  polys++;
}

void DMesh::DefineDS(int w,int h,int xOff,int yOff)
// Define a double-sided flat area (2 polygons, 0=front, 1=back)
{
  DPolyPoint p;
  DPoly *pl,*pl2;
  int n;

  n=polys;
  pl=poly[n];
  pl2=poly[n+1];
  pl->Define(4);
  pl2->Define(4);

  p.x=-w/2+xOff; p.y=-h/2+yOff; p.z=0;
  p.tx=0; p.ty=0;
  pl->DefinePoint(0,&p);
  p.tx=.5; p.ty=.5;
  pl2->DefinePoint(3,&p);

  p.x=w/2+xOff; p.y=-h/2+yOff; p.z=0;
  p.tx=1; p.ty=0;
  pl->DefinePoint(1,&p);
  p.tx=1; p.ty=1;
  pl2->DefinePoint(2,&p);

  p.x=w/2+xOff; p.y=h/2+yOff; p.z=0;
  p.tx=1; p.ty=1;
  pl->DefinePoint(2,&p);
  p.tx=.5; p.ty=.1;
  pl2->DefinePoint(1,&p);

  p.x=-w/2+xOff; p.y=h/2+yOff; p.z=0;
  p.tx=0; p.ty=1;
  pl->DefinePoint(3,&p);
  p.tx=0; p.ty=0;
  pl2->DefinePoint(0,&p);

  polys+=2;
}

void DMesh::_Paint()
{
  int i;

//qdbg("DMesh::_Paint\n");

  for(i=0;i<polys;i++)
    poly[i]->Paint();
}