Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GFXSphereVertexList Class Reference

#include <gfxlib_struct.h>

Inheritance diagram for GFXSphereVertexList:
GFXVertexList

Public Member Functions

 GFXSphereVertexList (float radius, int detail, bool insideout, bool reverse_normals)
 creates a vertex list with 1 polytype and a given number of vertices More...
 
 ~GFXSphereVertexList ()
 
virtual VDATBeginMutate (int offset)
 Returns the array of vertices to be mutated. More...
 
virtual void EndMutate (int newsize=0)
 Ends mutation and refreshes display list. More...
 
virtual void BeginDrawState (GFXBOOL lock=GFXTRUE)
 
virtual void Draw ()
 Draws a single copy of the mass-loaded vlist. More...
 
virtual void EndDrawState (GFXBOOL lock=GFXTRUE)
 
virtual void GetPolys (GFXVertex **vert, int *numPolys, int *numTris)
 returns a packed vertex list with number of polys and number of tries to passed in arguments. Useful for getting vertex info from a mesh More...
 
virtual void ProceduralModification ()
 generates procedural planetdata to the actual detaillevel with the "plasma method" More...
 
- Public Member Functions inherited from GFXVertexList
void RefreshDisplayList ()
 Propagates modifications to the display list. More...
 
 GFXVertexList (enum POLYTYPE poly, int numVertices, const GFXVertex *vertices, int numindices, bool Mutable=false, unsigned int *index=0)
 creates a vertex list with 1 polytype and a given number of vertices More...
 
 GFXVertexList (enum POLYTYPE *poly, int numVertices, const GFXVertex *vertices, int numlists, int *offsets, bool Mutable=false, unsigned int *index=0)
 Creates a vertex list with an arbitrary number of poly types and given vertices, num list and offsets (see above) More...
 
 GFXVertexList (enum POLYTYPE poly, int numVertices, const GFXColorVertex *colors, int numindices, bool Mutable=false, unsigned int *index=0)
 Creates a vertex list with 1 poly type and color information to boot. More...
 
 GFXVertexList (enum POLYTYPE *poly, int numVertices, const GFXColorVertex *colors, int numlists, int *offsets, bool Mutable=false, unsigned int *index=0)
 Creates a vertex list with an arbitrary number of poly types and color. More...
 
virtual ~GFXVertexList ()
 
virtual int numTris () const
 Returns number of Triangles in vertex list (counts tri strips) More...
 
virtual int numQuads () const
 Returns number of Quads in vertex list (counts quad strips) More...
 
unsigned int GetIndex (int offset) const
 Looks up the index in the appropriate short, char or int array. More...
 
POLYTYPEGetPolyType () const
 
intGetOffsets () const
 
int GetNumLists () const
 
bool hasColor () const
 
int GetNumVertices () const
 
virtual VDATMap (bool read, bool write)
 
void UnMap ()
 
void LoadDrawState ()
 Loads the draw state (what is active) of a given vlist for mass drawing. More...
 
void Draw (enum POLYTYPE poly, int numV)
 
void Draw (enum POLYTYPE poly, int numV, unsigned char *index)
 
void Draw (enum POLYTYPE poly, int numV, unsigned short *index)
 
void Draw (enum POLYTYPE poly, int numV, unsigned int *index)
 
void DrawOnce ()
 Loads draw state and prepares to draw only once. More...
 

Protected Member Functions

virtual void Draw (enum POLYTYPE *poly, const INDEX index, const int numLists, const int *offsets)
 
- Protected Member Functions inherited from GFXVertexList
const GFXVertexGetVertex (int index) const
 Num vertices allocated. More...
 
const GFXColorVertexGetColorVertex (int index) const
 
void Init (enum POLYTYPE *poly, int numVertices, const GFXVertex *vert, const GFXColorVertex *colors, int numlists, int *offsets, bool Mutable, unsigned int *indices)
 Init function (call from construtor) More...
 
void RenormalizeNormals ()
 
 GFXVertexList ()
 

Protected Attributes

float radius
 Num vertices allocated. More...
 
GFXVertexListsphere
 
- Protected Attributes inherited from GFXVertexList
int numVertices
 
union GFXVertexList::VDAT data
 
union GFXVertexList::INDEX index
 
enum POLYTYPEmode
 Array of modes that vertices will be drawn with. More...
 
bool unique_mode
 
int display_list
 Display list number if list is indeed active. 0 otherwise. More...
 
int vbo_data
 
int numlists
 number of different mode, drawn lists More...
 
intoffsets
 
char changed
 If vertex list has been mutated since last draw. Low 3 bits store the stride of the index list (if avail). another bit for if color is presnet. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from GFXVertexList
static void VtxCopy (GFXVertexList *thus, GFXVertex *dst, int offset, int howmany)
 copies nonindexed vertices to dst vertex array More...
 
static void ColVtxCopy (GFXVertexList *thus, GFXVertex *dst, int offset, int howmany)
 Copies nonindex colored vertices to dst vertex array. More...
 
static void ColIndVtxCopy (GFXVertexList *thus, GFXVertex *dst, int offset, int howmany)
 Copies indexed colored vertices to dst vertex array. More...
 
static void IndVtxCopy (GFXVertexList *thus, GFXVertex *dst, int offset, int howmany)
 Copies indexed vertices to dst vertex array. More...
 

Detailed Description

Definition at line 638 of file gfxlib_struct.h.

Constructor & Destructor Documentation

GFXSphereVertexList::GFXSphereVertexList ( float  radius,
int  detail,
bool  insideout,
bool  reverse_normals 
)

creates a vertex list with 1 polytype and a given number of vertices

Definition at line 59 of file gl_sphere_list.cpp.

References UniverseUtil::cos(), GFXVertexList::data, GFXVertexList::display_list, g_rho, g_theta, GetS, GetT, GFXQUADSTRIP, GFXVertexList::GFXVertexList(), GFXVertex::i, i, GFXVertexList::INDEX::i, GFXVertexList::index, GFXVertex::j, j, GFXVertex::k, GFXVertexList::mode, GFXVertexList::numlists, GFXVertexList::numVertices, GFXVertexList::offsets, radius, GFXVertex::s, UniverseUtil::sin(), size, sphere, GFXVertex::t, GFXVertex::tw, GFXVertex::tx, GFXVertex::ty, GFXVertex::tz, GFXVertexList::vbo_data, GFXVertexList::VDAT::vertices, GFXVertex::x, x, GFXVertex::y, y, GFXVertex::z, and z.

60 {
61  this->radius = radius;
62  radius = 100000.0f;
63  static vector< GFXVertexList* >vlists[4];
64  int which = (Insideout ? 1 : 0)+(reverse_normals ? 2 : 0);
65  while ( detail >= static_cast<int>(vlists[which].size()) )
66  vlists[which].insert( vlists[which].end(), 1+detail-vlists[which].size(), NULL );
67  if (vlists[which][detail] == 0) {
68  int slices;
69  int stacks = slices = detail;
70  if (stacks > 12) {
71  stacks -= 4;
72  slices -= 4;
73  } else {
74  stacks -= 2;
75  slices -= 2;
76  }
77  float rho_max = 3.1415926536f;
78  float rho_min = 0.0f;
79  float theta_min = 0.0f;
80  float theta_max = 2.0f*3.1415926536f;
81  float drho, dtheta;
82  float x, y, z, tx, ty;
83  float s, t, ds, dt;
84  int i, j, imin, imax;
85  float nsign = Insideout ? -1.0 : 1.0;
86  float normalscale = reverse_normals ? -1.0 : 1.0;
87  int fir = 0; //Insideout?1:0;
88  int sec = 1; //Insideout?0:1;
89  /* Code below adapted from gluSphere */
90  drho = (rho_max-rho_min)/(float) stacks;
91  dtheta = (theta_max-theta_min)/(float) slices;
92 
93  ds = 1.0f/slices;
94  dt = 1.0f/stacks;
95  t = 1.0f; /* because loop now runs from 0 */
96 
97  imin = 0;
98  imax = stacks;
99 
100  int numQuadstrips = stacks;
101  //numQuadstrips = 0;
102  int *QSOffsets = new int[numQuadstrips];
103 
104  //draw intermediate stacks as quad strips
105  int numvertex = stacks*(slices+1)*2;
106  GFXVertex *vertexlist = new GFXVertex[numvertex];
107 
108  GFXVertex *vl = vertexlist;
109  enum POLYTYPE *modes = new enum POLYTYPE[numQuadstrips];
110  /* SetOrientation(Vector(1,0,0),
111  * Vector(0,0,-1),
112  * Vector(0,1,0));//that's the way prop*/ //taken care of in loading
113 
114  float rhol[2];
115  float thetal[2];
116 #define g_rho( i ) ((rhol[((i))&1]))
117 #define g_theta( i ) ((thetal[((i))&1]))
118 
119  g_rho( 0 ) = rho_min;
120  for (i = imin; i < imax; i++) {
121  GFXVertex *vertexlist = vl+(i*(slices+1)*2);
122  g_rho( i+1 ) = (i+1)*drho+rho_min; //FIXME These macros are horrible
123 
124  s = 0.0;
125  g_theta( 0 ) = 0;
126  for (j = 0; j <= slices; j++) {
127  g_theta( j+1 ) = (j+1)*dtheta;
128 
129  tx = -sin( g_theta( j ) );
130  ty = cos( g_theta( j ) );
131  z = sin( g_rho( i ) );
132  x = tx*z;
133  y = ty*z;
134  z = nsign*cos( g_rho( i ) );
135 
136  //normal
137  vertexlist[j*2+fir].i = x*normalscale;
138  vertexlist[j*2+fir].k = -y*normalscale;
139  vertexlist[j*2+fir].j = z*normalscale;
140 
141  //tangent
142  vertexlist[j*2+fir].tx = -ty*normalscale;
143  vertexlist[j*2+fir].tz = -tx*normalscale;
144  vertexlist[j*2+fir].ty = 0;
145  vertexlist[j*2+fir].tw = nsign*normalscale;
146 #define GetS( theta, theta_min, theta_max ) ( 1-(theta-theta_min)/(theta_max-theta_min) )
147 #define GetT( rho, rho_min, rho_max ) ( 1-(rho-rho_min)/(rho_max-rho_min) )
148 
149  //texcoords
150  vertexlist[j*2+fir].s = GetS( g_theta( j ), theta_min, theta_max ); //1-s;
151  vertexlist[j*2+fir].t = GetT( g_rho( i ), rho_min, rho_max ); //t;
152 
153  //position
154  vertexlist[j*2+fir].x = x*radius;
155  vertexlist[j*2+fir].z = -y*radius;
156  vertexlist[j*2+fir].y = z*radius;
157 
158  z = sin( g_rho( i+1 ) );
159  x = tx*z;
160  y = ty*z;
161  z = nsign*cos( g_rho( i+1 ) );
162 
163  //normal
164  vertexlist[j*2+sec].i = x*normalscale;
165  vertexlist[j*2+sec].k = -y*normalscale;
166  vertexlist[j*2+sec].j = z*normalscale;
167 
168  //tangent
169  vertexlist[j*2+sec].tx = -ty*normalscale;
170  vertexlist[j*2+sec].tz = -tx*normalscale;
171  vertexlist[j*2+sec].ty = 0;
172  vertexlist[j*2+sec].tw = nsign*normalscale;
173 
174  //texcoords
175  vertexlist[j*2+sec].s = GetS( g_theta( j ), theta_min, theta_max ); //1-s;
176  vertexlist[j*2+sec].t = GetT( g_rho( i+1 ), rho_min, rho_max ); //t - dt;
177 
178  //position
179  vertexlist[j*2+sec].x = x*radius;
180  vertexlist[j*2+sec].z = -y*radius;
181  vertexlist[j*2+sec].y = z*radius;
182 
183  s += ds;
184  }
185 
186  t -= dt;
187  QSOffsets[i] = (slices+1)*2;
188  modes[i] = GFXQUADSTRIP;
189  }
190 
191 #undef g_rho
192 #undef g_theta
193 
194  vlists[which][detail] = new GFXVertexList( modes, numvertex, vertexlist, numQuadstrips, QSOffsets );
195  }
196  sphere = vlists[which][detail];
200  index.i = sphere->index.i;
203  mode = sphere->mode;
205 }
GFXSphereVertexList::~GFXSphereVertexList ( )

Member Function Documentation

void GFXSphereVertexList::BeginDrawState ( GFXBOOL  lock = GFXTRUE)
virtual

Loads the draw state (what is active) of a given vlist for mass drawing Specifies array pointers and loads the draw state of a given vlist for mass drawing

Reimplemented from GFXVertexList.

Definition at line 28 of file gl_sphere_list.cpp.

References GFXVertexList::BeginDrawState(), and sphere.

29 {
30  //
31 
32  sphere->BeginDrawState( lock );
33 }
GFXVertexList::VDAT * GFXSphereVertexList::BeginMutate ( int  offset)
virtual

Returns the array of vertices to be mutated.

Reimplemented from GFXVertexList.

Definition at line 51 of file gl_sphere_list.cpp.

52 {
53  return NULL;
54 }
void GFXSphereVertexList::Draw ( enum POLYTYPE poly,
const INDEX  index,
const int  numLists,
const int offsets 
)
protectedvirtual

Reimplemented from GFXVertexList.

Definition at line 18 of file gl_sphere_list.cpp.

References GFXVertexList::Draw(), f, radius, and sphere.

19 {
20  glEnable( GL_NORMALIZE );
21  glMatrixMode( GL_MODELVIEW );
22  glPushMatrix();
23  glScalef( radius/100000.0f, radius/100000.0f, radius/100000.0f );
24  sphere->Draw( poly, index, numLists, offsets );
25  glPopMatrix();
26  glDisable( GL_NORMALIZE );
27 }
void GFXSphereVertexList::Draw ( )
virtual

Draws a single copy of the mass-loaded vlist.

Reimplemented from GFXVertexList.

Definition at line 7 of file gl_sphere_list.cpp.

References GFXVertexList::Draw(), f, radius, and sphere.

8 {
9  glEnable( GL_NORMALIZE );
10  glMatrixMode( GL_MODELVIEW );
11  glPushMatrix();
12  glScalef( radius/100000.0f, radius/100000.0f, radius/100000.0f );
13  sphere->Draw();
14  glPopMatrix();
15  glDisable( GL_NORMALIZE );
16 }
void GFXSphereVertexList::EndDrawState ( GFXBOOL  lock = GFXTRUE)
virtual

Reimplemented from GFXVertexList.

Definition at line 46 of file gl_sphere_list.cpp.

References GFXVertexList::EndDrawState(), and sphere.

47 {
48  //
49  sphere->EndDrawState( lock );
50 }
void GFXSphereVertexList::EndMutate ( int  newsize = 0)
virtual

Ends mutation and refreshes display list.

Reimplemented from GFXVertexList.

Definition at line 55 of file gl_sphere_list.cpp.

56 {
57  assert( 0 );
58 }
void GFXSphereVertexList::GetPolys ( GFXVertex **  vert,
int numPolys,
int numTris 
)
virtual

returns a packed vertex list with number of polys and number of tries to passed in arguments. Useful for getting vertex info from a mesh

Reimplemented from GFXVertexList.

Definition at line 34 of file gl_sphere_list.cpp.

References GFXVertexList::GetPolys(), i, GFXVertexList::numTris(), radius, and sphere.

35 {
36  sphere->GetPolys( vert, numPolys, numTris );
37  int numt = *numTris;
38  int numq = *numPolys-numt;
39  int verts = numt*3+numq*4;
40  for (int i = 0; i < verts; ++i) {
41  (*vert)[i].x *= radius;
42  (*vert)[i].y *= radius;
43  (*vert)[i].z *= radius;
44  }
45 }
void GFXSphereVertexList::ProceduralModification ( )
virtual

generates procedural planetdata to the actual detaillevel with the "plasma method"

Definition at line 637 of file gfxlib_struct.cpp.

References GFXVertexList::BeginMutate(), GFXVertexList::EndMutate(), GFXVertex::GetPosition(), i, j, GFXVertexList::numVertices, CockpitXML::ROWS, SetVector(), GFXVertex::SetVertex(), sphere, VSRandom::uniformInc(), v, Vector, vert, GFXVertexList::VDAT::vertices, and vsrandom.

638 {
640  const int ROWS = 28;
641  int row[ROWS];
642  for(int i=0; i < ROWS; i++) {
643  row[i] = numVertices/ROWS*i;
644  }
645 
646  Vector vert[ROWS];
647  int direction[ROWS/2];
648 
649  int last_row_set[ROWS];
650  for(int i=0; i < ROWS; i++) {
651  last_row_set[i] = 0;
652  }
653 
654  for(int i=0; i < numVertices; i++) {
655  for(int j=0; j < ROWS; j++)
656  if(row[j] < numVertices/ROWS*(j+1))
657  vert[j] = v[row[j]].GetPosition();
658 
659  for(int j=0; j < ROWS/2; j++)
660  direction[j] = (int)vsrandom.uniformInc( 0.0, 5.0 );
661  if(i % 4 == 1) {
662  for(int j=0; j < ROWS; j+=2) {
663  if(direction[j/2] > 2) {
664  SetVector( 1.003, &vert[j] );
665  last_row_set[j] = 1;
666  } else {
667  last_row_set[j] = -1;
668  }
669  }
670 
671  }
672 
673  if(i % 4 == 0 ) {
674  for(int j=1; j < ROWS; j+=2) {
675  if(direction[(j-1)/2] > 2) {
676  SetVector( 1.003, &vert[j] );
677  last_row_set[j] = 1;
678  } else {
679  last_row_set[j] = -1;
680  }
681  }
682  }
683 
684  for(int j=0; j < ROWS; j++)
685  if(row[j] < numVertices/ROWS*(j+1))
686  v[row[j]].SetVertex( vert[j] );
687 
688  for(int j=0; j < ROWS; j++)
689  row[j]++;
690  }
691 
692  sphere->EndMutate( /*numVertices*/ );
693 }

Member Data Documentation

float GFXSphereVertexList::radius
protected

Num vertices allocated.

Definition at line 642 of file gfxlib_struct.h.

Referenced by Draw(), GetPolys(), and GFXSphereVertexList().

GFXVertexList* GFXSphereVertexList::sphere
protected

The documentation for this class was generated from the following files: