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
SphereMesh Class Reference

#include <sphere.h>

Inheritance diagram for SphereMesh:
Mesh CityLights

Public Member Functions

 SphereMesh ()
 
virtual int MeshType () const
 
virtual void SelectCullFace (int whichdrawqueue)
 Will draw all undrawn far meshes beyond the range of zbuffer (better be convex). More...
 
virtual void RestoreCullFace (int whichdrawqueue)
 
 SphereMesh (float radius, int stacks, int slices, const char *texture, const std::string &technique, const char *alpha=NULL, bool insideout=false, const BLENDFUNC a=ONE, const BLENDFUNC b=ZERO, bool envMap=false, float rho_min=0.0, float rho_max=M_PI, float theta_min=0.0, float theta_max=2 *M_PI, FILTER mipmap=MIPMAP, bool reverse_normals=false)
 
void Draw (float lod, bool centered=false, const Matrix &m=identity_matrix)
 
virtual void ProcessDrawQueue (int whichpass, int which, bool zsort, const QVector &sortctr)
 
- Public Member Functions inherited from Mesh
void initTechnique (const string &technique)
 
TechniquePtr getTechnique () const
 
void setTechnique (TechniquePtr tech)
 
bool LoadExistant (Mesh *mesh)
 Loads a mesh that has been found in the hash table into this mesh (copying original data) More...
 
bool LoadExistant (const string filehash, const Vector &scale, int faction)
 
 Mesh ()
 
 Mesh (const Mesh &m)
 
GFXVertexListgetVertexList () const
 
void setVertexList (GFXVertexList *_vlist)
 
float getFramesPerSecond () const
 
float getCurrentFrame () const
 
void setCurrentFrame (float)
 
int getNumAnimationFrames (const string &which=string()) const
 
int getNumLOD () const
 
int getNumTextureFrames () const
 
float getTextureFramesPerSecond () const
 
double getTextureCumulativeTime () const
 
void setTextureCumulativeTime (double)
 
bool getConvex () const
 
void setConvex (bool b)
 
BLENDFUNC getBlendSrc () const
 
BLENDFUNC getBlendDst () const
 
void Fork (Mesh *&one, Mesh *&two, float a, float b, float c, float d)
 Forks the mesh across the plane a,b,c,d into two separate meshes...upon which this may be deleted. More...
 
virtual ~Mesh ()
 Destructor... kills orig if refcount of orig becomes zero. More...
 
unsigned int numFX () const
 Gets number of specialFX. More...
 
void EnableSpecialFX ()
 Turns on SpecialFX. More...
 
unsigned int numTextures () const
 
Texturetexture (int i) const
 
void SetBlendMode (BLENDFUNC src, BLENDFUNC dst, bool lodcascade=false)
 
void GetPolys (vector< mesh_polygon > &)
 Gets all polygons in this mesh for collision computation. More...
 
void SetMaterial (const GFXMaterial &mat)
 Sets the material of this mesh to mat (affects original as well) More...
 
const GFXMaterialGetMaterial () const
 
GFXBOOL HasBeenDrawn () const
 If it has already been drawn this frame. More...
 
void UnDraw ()
 so one can query if it has or not been drawn More...
 
Vector const & Position () const
 Returns center of this mesh. More...
 
void Draw (float lod, const Matrix &m=identity_matrix, float toofar=1, int cloak=-1, float nebdist=0, unsigned char damage=0, bool renormalize_normals=false, const MeshFX *mfx=NULL)
 Draws lod pixel wide mesh at Transformation LATER. More...
 
void DrawNow (float lod, bool centered, const Matrix &m=identity_matrix, int cloak=-1, float nebdist=0)
 Draws lod pixels wide, mesh at Transformation NOW. If centered, then will center on camera and disable cull. More...
 
virtual void ProcessDrawQueue (size_t whichpass, int whichdrawqueue, bool zsort, const QVector &sortctr)
 Will draw all undrawn meshes of this type. More...
 
void forceCullFace (GFXBOOL newValue)
 Sets whether or not this unit should be environment mapped. More...
 
GFXBOOL getCullFaceForcedOn () const
 
GFXBOOL getCullFaceForcedOff () const
 
void setEnvMap (GFXBOOL newValue, bool lodcascade=false)
 
GFXBOOL getEnvMap () const
 
void setLighting (GFXBOOL newValue, bool lodcascade=false)
 
GFXBOOL getLighting () const
 
Vector corner_min ()
 Returns bounding box values. More...
 
Vector corner_max ()
 
BoundingBox * getBoundingBox ()
 Returns a physical boudning box in 3space instead of in current unit space. More...
 
bool queryBoundingBox (const QVector &start, const float err) const
 queries this bounding box with a vector and radius More...
 
bool queryBoundingBox (const QVector &start, const QVector &end, const float err) const
 Queries bounding box with a ray. More...
 
float rSize () const
 returns the radial size of this More...
 
virtual float clipRadialSize () const
 
void UpdateFX (float ttime)
 based on TTL, etc, updates shield effects More...
 
void AddDamageFX (const Vector &LocalPos, const Vector &LocalNorm, const float percentage, const GFXColor &color=GFXColor(1, 1, 1, 1))
 Adds a new damage effect with age damage to the part of the unit. Color specifies the shield oclor. More...
 
void setVirtualBoundingBox (const Vector &mn, const Vector &mx, float rsize)
 

Protected Member Functions

virtual float GetT (float rho, float rho_min, float rho_max) const
 
virtual float GetS (float theta, float theta_min, float theta_max) const
 
virtual MeshAllocNewMeshesEachInSizeofMeshSpace (int num)
 
void InitSphere (float radius, int stacks, int slices, const char *texture, const std::string &technique, const char *alpha=NULL, bool insideout=false, const BLENDFUNC a=ONE, const BLENDFUNC b=ZERO, bool envMap=false, float rho_min=0.0, float rho_max=M_PI, float theta_min=0.0, float theta_max=2 *M_PI, FILTER mipmap=MIPMAP, bool reverse_normals=false, bool subclass=false)
 
- Protected Member Functions inherited from Mesh
void PostProcessLoading (struct MeshXML *xml, const vector< string > &overrideTexture)
 
 Mesh (std::string filename, const Vector &scalex, int faction, class Flightgroup *fg, bool orig=false)
 
void InitUnit ()
 Setting all values to defaults (good for mesh copying and stuff) More...
 
MeshgetLOD (float lod, bool bBypassDamping=true)
 Returing the mesh relevant to "size" pixels LOD of this mesh. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Mesh
static MeshLoadMesh (const char *filename, const Vector &scalex, int faction, class Flightgroup *fg, const std::vector< std::string > &textureOverride=std::vector< std::string >())
 Loading a mesh from an XML file. faction specifies the logos. Orig is for internal (LOD) use only! More...
 
static vector< Mesh * > LoadMeshes (const char *filename, const Vector &scalex, int faction, class Flightgroup *fg, const std::vector< std::string > &textureOverride=std::vector< std::string >())
 
static vector< Mesh * > LoadMeshes (VSFileSystem::VSFile &f, const Vector &scalex, int faction, class Flightgroup *fg, std::string hash_name, const std::vector< std::string > &textureOverride=std::vector< std::string >())
 
static void ProcessZFarMeshes (bool nocamerasetup=false)
 
static void ProcessUndrawnMeshes (bool pushSpecialEffects=false, bool nocamerasetup=false)
 Will draw all undrawn meshes in total If pushSpclFX, the last series of meshes will be drawn with other lighting off. More...
 
- Protected Attributes inherited from Mesh
Vector local_pos
 the position of the center of this mesh for collision detection More...
 
int refcount
 The refcount:: how many meshes are referencing the appropriate original. More...
 
Vector mx
 bounding box More...
 
Vector mn
 
float radialSize
 The radial size of this mesh. More...
 
int numlods
 num lods contained in the array of Mesh "orig" More...
 
float framespersecond
 
Meshorig
 
float lodsize
 The size that this LOD (if original) comes into effect. More...
 
Logoforcelogos
 The number of force logos on this mesh (original) More...
 
int numforcelogo
 
Logosquadlogos
 The number of squad logos on this mesh (original) More...
 
int numsquadlogo
 
GFXVertexListvlist
 tri,quad,line, strips, etc More...
 
unsigned int myMatNum
 The number of the appropriate material for this mesh (default 0) More...
 
TechniquePtr technique
 The technique used to render this mesh. More...
 
vector< Texture * > Decal
 The decal relevant to this mesh. More...
 
TexturedetailTexture
 
vector< VectordetailPlanes
 
float polygon_offset
 
char envMapAndLit
 whether this should be environment mapped 0x1 and 0x2 for if it should be lit (ored together) More...
 
GFXBOOL will_be_drawn
 Whether this original will be drawn this frame. More...
 
bool convex
 The blend functions. More...
 
unsigned char alphatest
 
enum BLENDFUNC blendSrc
 
enum BLENDFUNC blendDst
 
vector< MeshDrawContext > * draw_queue
 Support for reorganized rendering. More...
 
int draw_sequence
 How transparent this mesh is (in what order should it be rendered in. More...
 
string hash_name
 The name of this unit. More...
 
vector< MeshFXLocalFX
 The enabled light effects on this mesh. More...
 
- Static Protected Attributes inherited from Mesh
static Hashtable< std::string,
Mesh, MESH_HASTHABLE_SIZE
meshHashTable
 The hash table of all meshes. More...
 
static Hashtable< std::string,
std::vector< int >
, MESH_HASTHABLE_SIZE
animationSequences
 

Detailed Description

Definition at line 13 of file sphere.h.

Constructor & Destructor Documentation

SphereMesh::SphereMesh ( )
inline

Definition at line 41 of file sphere.h.

References Mesh::setConvex().

41  : SphereMesh() : Mesh()
42  {
43  setConvex( true );
44  }
SphereMesh::SphereMesh ( float  radius,
int  stacks,
int  slices,
const char *  texture,
const std::string &  technique,
const char *  alpha = NULL,
bool  insideout = false,
const BLENDFUNC  a = ONE,
const BLENDFUNC  b = ZERO,
bool  envMap = false,
float  rho_min = 0.0,
float  rho_max = M_PI,
float  theta_min = 0.0,
float  theta_max = 2 *M_PI,
FILTER  mipmap = MIPMAP,
bool  reverse_normals = false 
)
inline

Definition at line 51 of file sphere.h.

References a, b, and InitSphere().

67  {
68  InitSphere( radius,
69  stacks,
70  slices,
71  texture,
72  technique,
73  alpha,
74  insideout,
75  a,
76  b,
77  envMap,
78  rho_min,
79  rho_max,
80  theta_min,
81  theta_max,
82  mipmap,
83  reverse_normals );
84  }

Member Function Documentation

virtual Mesh* SphereMesh::AllocNewMeshesEachInSizeofMeshSpace ( int  num)
inlineprotectedvirtual

Reimplemented in CityLights.

Definition at line 19 of file sphere.h.

Referenced by InitSphere().

20  {
21  assert( sizeof (Mesh) == sizeof (*this) );
22  return new SphereMesh[num];
23  }
void SphereMesh::Draw ( float  lod,
bool  centered = false,
const Matrix m = identity_matrix 
)

Definition at line 244 of file sphere_generic.cpp.

References _Universe, Universe::AccessCamera(), Mesh::Draw(), Camera::GetPosition(), m1, Matrix::p, and QVector.

245 {
246  if (centered) {
247  Matrix m1( m );
248  m1.p = QVector( _Universe->AccessCamera()->GetPosition().Transform( m1 ) );
249  Mesh::Draw( lod, m1 );
250  } else {
251  Mesh::Draw( lod, m );
252  }
253 }
float SphereMesh::GetS ( float  theta,
float  theta_min,
float  theta_max 
) const
protectedvirtual

Reimplemented in CityLights.

Definition at line 40 of file sphere_generic.cpp.

Referenced by CityLights::GetS(), and InitSphere().

41 {
42  return 1-(theta-theta_min)/(theta_max-theta_min);
43 }
float SphereMesh::GetT ( float  rho,
float  rho_min,
float  rho_max 
) const
protectedvirtual

Reimplemented in CityLights.

Definition at line 35 of file sphere_generic.cpp.

Referenced by CityLights::GetT(), and InitSphere().

36 {
37  return 1-(rho-rho_min)/(rho_max-rho_min);
38 }
void SphereMesh::InitSphere ( float  radius,
int  stacks,
int  slices,
const char *  texture,
const std::string &  technique,
const char *  alpha = NULL,
bool  insideout = false,
const BLENDFUNC  a = ONE,
const BLENDFUNC  b = ZERO,
bool  envMap = false,
float  rho_min = 0.0,
float  rho_max = M_PI,
float  theta_min = 0.0,
float  theta_max = 2 *M_PI,
FILTER  mipmap = MIPMAP,
bool  reverse_normals = false,
bool  subclass = false 
)
protected

Definition at line 68 of file sphere_generic.cpp.

References AllocNewMeshesEachInSizeofMeshSpace(), UniverseUtil::cos(), createAnimatedTexture(), FactionUtil::createTexture(), Mesh::Decal, Mesh::draw_queue, Mesh::draw_sequence, g_game, g_rho, g_theta, GetS(), GetT(), GFXFALSE, GFXQUADSTRIP, GFXTRUE, Mesh::hash_name, GFXVertex::i, i, Mesh::initTechnique(), GFXVertex::j, j, GFXVertex::k, Mesh::LoadExistant(), Mesh::lodsize, M_PI, Mesh::meshHashTable, Mesh::mn, Mesh::mx, NUM_ZBUF_SEQ, Mesh::numlods, Mesh::orig, pixelscalesize, Hashtable< KEY, VALUE, SIZ >::Put(), Mesh::radialSize, Mesh::refcount, GFXVertex::s, Mesh::SetBlendMode(), Mesh::setConvex(), Mesh::setEnvMap(), UniverseUtil::sin(), GFXVertex::t, Mesh::texture(), TEXTURE2D, TEXTURE_2D, XMLSupport::tostring(), truncateByPipe(), game_data_t::use_planet_textures, Vector, Mesh::vlist, GFXVertex::x, x, GFXVertex::y, y, GFXVertex::z, and z.

Referenced by CityLights::CityLights(), and SphereMesh().

85 {
86  setConvex( true );
87  int numspheres = (stacks+slices)/8;
88  if (numspheres < 1)
89  numspheres = 1;
90  Mesh *oldmesh;
91  char ab[3];
92  ab[2] = '\0';
93  ab[1] = b+'0';
94  ab[0] = a+'0';
95  hash_name = string( "@@Sphere" )+"#"+texture+"#"+technique+"#"+XMLSupport::tostring( stacks )+"#"+XMLSupport::tostring( slices )+ab+"#"
96  +XMLSupport::tostring( rho_min )+"#"+XMLSupport::tostring( rho_max );
97  if ( LoadExistant( hash_name, Vector( radius, radius, radius ), 0 ) ) {
98  return;
99  } else {}
100  this->orig = AllocNewMeshesEachInSizeofMeshSpace( numspheres ); //FIXME::RISKY::MIGHT HAVE...
101  //... DIFFERENT SIZES!! DON"T YOU DARE ADD XTRA VARS TO SphereMesh calsshave to!
102  oldmesh = this->orig;
103  numlods = numspheres;
104  meshHashTable.Put( hash_name, oldmesh );
105  radialSize = radius; //MAKE SURE FRUSTUM CLIPPING IS DONE CORRECTLY!!!!!
108  vector< MeshDrawContext > *odq = NULL;
109  for (int l = 0; l < numspheres; l++) {
110  draw_queue = new vector< MeshDrawContext >[NUM_ZBUF_SEQ+1];
111  if (subclass || rho_max != M_PI || rho_min != 0.0 || theta_min != 0.0 || theta_max != 2*M_PI)
112  odq = draw_queue;
113  vlist = NULL;
114  if (subclass) {
115  if (stacks > 12) {
116  stacks -= 4;
117  slices -= 4;
118  } else {
119  stacks -= 2;
120  slices -= 2;
121  }
122  float drho, dtheta;
123  float x, y, z;
124  float s, t, ds, dt;
125  int i, j, imin, imax;
126  float nsign = Insideout ? -1.0 : 1.0;
127  float normalscale = reverse_normals ? -1.0 : 1.0;
128  int fir = 0; //Insideout?1:0;
129  int sec = 1; //Insideout?0:1;
130  /* Code below adapted from gluSphere */
131  drho = (rho_max-rho_min)/(float) stacks;
132  dtheta = (theta_max-theta_min)/(float) slices;
133  ds = 1.0/slices;
134  dt = 1.0/stacks;
135  t = 1.0; /* because loop now runs from 0 */
136  imin = 0;
137  imax = stacks;
138  int numQuadstrips = stacks;
139  //numQuadstrips = 0;
140  int *QSOffsets = new int[numQuadstrips];
141  //draw intermediate stacks as quad strips
142  int numvertex = stacks*(slices+1)*2;
143  GFXVertex *vertexlist = new GFXVertex[numvertex];
144  GFXVertex *vl = vertexlist;
145  enum POLYTYPE *modes = new enum POLYTYPE[numQuadstrips];
146  float rhol[2];
147  float thetal[2];
148 #define g_rho( i ) (rhol[(i)&1])
149 #define g_theta( i ) (thetal[(i)&1])
150  g_rho( 0 ) = rho_min;
151  for (i = imin; i < imax; i++) {
152  GFXVertex *vertexlist = vl+(i*(slices+1)*2);
153  g_rho( i+1 ) = (i+1)*drho+rho_min;
154  s = 0.0;
155  g_theta( 0 ) = 0;
156  for (j = 0; j <= slices; j++) {
157  g_theta( j+1 ) = (j+1)*dtheta;
158  x = -sin( g_theta( j ) )*sin( g_rho( i ) );
159  y = cos( g_theta( j ) )*sin( g_rho( i ) );
160  z = nsign*cos( g_rho( i ) );
161  vertexlist[j*2+fir].i = x*normalscale;
162  vertexlist[j*2+fir].k = -y*normalscale;
163  vertexlist[j*2+fir].j = z*normalscale;
164  vertexlist[j*2+fir].s = GetS( g_theta( j ), theta_min, theta_max ); //1-s;//insideout?1-s:s;
165  vertexlist[j*2+fir].t = GetT( g_rho( i ), rho_min, rho_max ); //t;
166  vertexlist[j*2+fir].x = x*radius;
167  vertexlist[j*2+fir].z = -y*radius;
168  vertexlist[j*2+fir].y = z*radius;
169  x = -sin( g_theta( j ) )*sin( g_rho( i+1 ) );
170  y = cos( g_theta( j ) )*sin( g_rho( i+1 ) );
171  z = nsign*cos( g_rho( i+1 ) );
172  vertexlist[j*2+sec].i = x*normalscale;
173  vertexlist[j*2+sec].k = -y*normalscale;
174  vertexlist[j*2+sec].j = z*normalscale; //double negative
175  vertexlist[j*2+sec].s = GetS( g_theta( j ), theta_min, theta_max ); //1-s;//insideout?1-s:s;
176  vertexlist[j*2+sec].t = GetT( g_rho( i+1 ), rho_min, rho_max ); //t - dt;
177  vertexlist[j*2+sec].x = x*radius;
178  vertexlist[j*2+sec].z = -y*radius;
179  vertexlist[j*2+sec].y = z*radius;
180  s += ds;
181  }
182  t -= dt;
183  QSOffsets[i] = (slices+1)*2;
184  modes[i] = GFXQUADSTRIP;
185  }
186 #undef g_rho
187 #undef g_theta
188  vlist = new GFXVertexList( modes, numvertex, vertexlist, numQuadstrips, QSOffsets );
189  delete[] vertexlist;
190  delete[] modes;
191  delete[] QSOffsets;
192  } else {
193  vlist = new GFXSphereVertexList( radius, stacks > slices ? stacks : slices, Insideout, reverse_normals );
194  }
195  SetBlendMode( a, b );
196  string inputtex = texture;
197  unsigned int count = 0;
198  if ( Decal.empty() )
199  Decal.push_back( NULL );
200  while ( inputtex.length() ) {
201  string thistex = truncateByPipe( inputtex );
202  while (Decal.size() <= count)
203  Decal.push_back( NULL );
204  if (thistex.find( ".ani" ) != string::npos) {
205  Decal[count] = createAnimatedTexture( thistex.c_str(), 0, mipmap );
206  } else {
207  if (alpha) {
208  Decal[count] =
209  createTexture( thistex.c_str(), alpha, 0, mipmap, TEXTURE2D, TEXTURE_2D, 1, 0,
210  (Insideout || g_game.use_planet_textures) ? GFXTRUE : GFXFALSE );
211  } else {
212  Decal[count] =
214  thistex.c_str(), 0, mipmap, TEXTURE2D, TEXTURE_2D,
215  (Insideout || g_game.use_planet_textures) ? GFXTRUE : GFXFALSE );
216  }
217  }
218  count++;
219  }
220  Insideout ? setEnvMap( GFXFALSE ) : setEnvMap( envMapping );
221  if (Insideout)
222  draw_sequence = 0;
223  Mesh *oldorig = orig;
224  refcount = 1;
225  orig = NULL;
226  if (l >= 1) {
227  lodsize = (numspheres+1-l)*pixelscalesize;
228  if (l == 1)
229  lodsize *= 2;
230  else if (l == 2)
231  lodsize *= 1.75;
232  else if (l == 3)
233  lodsize *= 1.5;
234  }
236  oldmesh[l] = *this;
237  refcount = 0;
238  orig = oldorig;
239  lodsize = FLT_MAX;
240  }
241  draw_queue = odq;
242 }
virtual int SphereMesh::MeshType ( ) const
inlinevirtual

Reimplemented from Mesh.

Definition at line 45 of file sphere.h.

46  {
47  return 1;
48  }
void SphereMesh::ProcessDrawQueue ( int  whichpass,
int  which,
bool  zsort,
const QVector sortctr 
)
virtual

Reimplemented in CityLights.

Definition at line 23 of file sphere.cpp.

References getSphereColor(), GFXGetLightContextAmbient(), GFXLightContextAmbient(), GFXPolygonOffset(), and Mesh::ProcessDrawQueue().

24 {
25  static GFXColor spherecol( getSphereColor() );
26  GFXColor tmpcol( 0, 0, 0, 1 );
27  GFXGetLightContextAmbient( tmpcol );
28  GFXLightContextAmbient( spherecol );
29  Mesh::ProcessDrawQueue( whichpass, whichdrawqueue, zsort, sortctr );
30  GFXLightContextAmbient( tmpcol );
31  GFXPolygonOffset( 0, 0 );
32 }
void SphereMesh::RestoreCullFace ( int  whichdrawqueue)
virtual

Reimplemented from Mesh.

Definition at line 255 of file sphere_generic.cpp.

256 {
257  //always right
258 }
void SphereMesh::SelectCullFace ( int  whichdrawqueue)
virtual

Will draw all undrawn far meshes beyond the range of zbuffer (better be convex).

Reimplemented from Mesh.

Definition at line 34 of file sphere.cpp.

References CULLFACE, and GFXEnable().

35 {
37 }

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