87 UnitType( meshes, SubU, fact )
95 std::string unitModifications,
101 Unit::Init( filename, SubU, faction, unitModifications, flightgrp, fg_subnumber, netxml );
106 for (
unsigned int meshcount = 0; meshcount < this->meshdata.size(); meshcount++)
107 if (this->meshdata[meshcount])
108 delete this->meshdata[meshcount];
109 this->meshdata.clear();
113 template <
class UnitType >
116 return ( (
int) this->meshdata.size() )-1;
119 template <
class UnitType >
124 basename = baseun->
name;
138 template <
class UnitType >
141 return this->pImage->pHudImage;
144 template <
class UnitType >
149 std::string halo_type,
152 phalos->AddHalo( filename, loc, size, col, halo_type, halo_speed );
155 template <
class UnitType >
163 UnitType::Cloak( engage );
165 UnitType::Cloak( engage );
169 template <
class UnitType >
173 #ifdef VARIABLE_LENGTH_PQR
174 Vector TargetPoint( cumulative_transformation_matrix[0],
175 cumulative_transformation_matrix[1],
176 cumulative_transformation_matrix[2] );
177 float SizeScaleFactor = sqrtf( TargetPoint.Dot( TargetPoint ) );
181 for (i = 0; i <
nummesh(); i++) {
182 TargetPoint =
Transform( this->cumulative_transformation_matrix, this->meshdata[i]->Position() );
185 this->meshdata[i]->rSize()
186 #ifdef VARIABLE_LENGTH_PQR
193 for (
un_fkiter iter = this->SubUnits.constFastIterator(); (un = *iter); ++iter)
199 template <
class UnitType >
203 Matrix ctm = this->cumulative_transformation_matrix;
207 CrossProduct( r,
q, tmp );
211 this->pImage->CockpitCenter.Cast() ),
212 this->GetWarpVelocity(), this->GetAngularVelocity(), this->GetAcceleration() );
216 extern int cloakVal(
int cloakint,
int cloakminint,
int cloakrateint,
bool cloakglass );
218 template <
class UnitType >
221 static const void *rootunit = NULL;
222 if (rootunit == NULL) rootunit = (
const void*)
this;
224 unsigned char chardamage = 0;
225 if (this->hull < this->maxhull) {
226 damagelevel = this->hull/this->maxhull;
227 chardamage = ( 255-(
unsigned char) (damagelevel*255) );
229 #ifdef VARIABLE_LENGTH_PQR
230 const float vlpqrScaleFactor = SizeScaleFactor;
232 const float vlpqrScaleFactor = 1.f;
236 if (this->graphicOptions.FaceCamera) {
244 int cloak = this->cloaking;
245 if (this->cloaking > this->cloakmin)
246 cloak =
cloakVal( cloak, this->cloakmin, this->pImage->cloakrate, this->pImage->cloakglass );
249 if (this->meshdata[i] == NULL)
252 this->meshdata[i]->Position().Cast() );
253 float d =
GFXSphereInFrustum( TransformedPosition, this->meshdata[i]->clipRadialSize()*vlpqrScaleFactor );
256 this->meshdata[i]->Draw( lod, mat, d, cloak );
259 for (
un_kiter iter = this->SubUnits.constIterator(); (un = *iter); ++iter) {
268 haloalpha = ( (
float) cloak )/2147483647;
270 Vector Scale( 1, pImage->ecm, computer.set_speed );
272 float cmas = this->computer.max_ab_speed()*this->computer.max_ab_speed();
277 int nummounts = this->GetNumMounts();
278 for (i = 0; (
int) i < nummounts; i++) {
280 Mount *mahnt = &this->mounts[i];
282 if (mahnt->xyscale != 0 && mahnt->zscale != 0) {
283 Mesh *gun = mahnt->type->gun;
285 Transformation mountLocation( mahnt->GetMountOrientation(), mahnt->GetMountLocation().Cast() );
288 mountLocation.to_matrix( mmat );
295 gun->
Draw( lod, mmat, d, cloak,
299 if (mahnt->type->gun1) {
300 gun = mahnt->type->gun1;
302 gun->
Draw( lod, mmat, d, cloak,
311 Vector accel = this->GetAcceleration();
312 float maxaccel = this->GetMaxAccelerationInDirectionOf( mat.
getR(), true );
313 Vector velocity = this->GetVelocity();
314 if (
phalos->ShouldDraw( mat, velocity, accel, maxaccel,
315 cmas ) && !( this->docked&(UnitType::DOCKED|UnitType::DOCKED_INSIDE) ) )
316 phalos->Draw( mat, Scale, cloak, 0, this->GetHullPercent(), velocity, accel, maxaccel, cmas, this->
faction );
317 if (rootunit == (
const void*)
this) {
324 template <
class UnitType >
330 extern double calc_blend_factor(
double frac,
int priority,
int when_it_will_be_simulated,
int cur_simulation_frame );
332 template <
class UnitType >
338 #ifdef VARIABLE_LENGTH_PQR
339 const float vlpqrScaleFactor = SizeScaleFactor;
341 const float vlpqrScaleFactor = 1.f;
349 this->curr_physical_state,
351 this->cumulative_transformation.Compose( parent, parentMatrix );
352 this->cumulative_transformation.to_matrix( this->cumulative_transformation_matrix );
354 ctm = &this->cumulative_transformation_matrix;
355 ct = &this->cumulative_transformation;
356 if (this->graphicOptions.FaceCamera == 1) {
360 float magr = parentMatrix.
getR().Magnitude();
361 float magp = parentMatrix.
getP().Magnitude();
362 float magq = parentMatrix.
getQ().Magnitude();
369 AUDAdjustSound( sound.engine, cumulative_transformation.position, GetVelocity() );
372 int cloak = this->cloaking;
373 if (this->cloaking > this->cloakmin) {
375 cloak =
cloakVal( cloak, this->cloakmin, this->pImage->cloakrate, this->pImage->cloakglass );
383 unsigned char chardamage = 0;
385 damagelevel = this->hull/this->maxhull;
386 chardamage = ( 255-(
unsigned char) (damagelevel*255) );
389 bool On_Screen =
false;
390 if ( ( !(this->invisible&UnitType::INVISUNIT) ) && ( ( !(this->invisible&UnitType::INVISCAMERA) ) || (!myparent) ) ) {
395 float minmeshradius =
398 unsigned int numKeyFrames = this->graphicOptions.NumAnimationPoints;
399 for (i = 0; i < this->meshdata.size(); i++) {
401 if (this->meshdata[i] == NULL)
403 if ( (
int) i == this->
nummesh() && (this->meshdata[i]->numFX() == 0 || this->hull < 0) )
405 if (this->meshdata[i]->getBlendDst() ==
ONE) {
406 if ( (this->invisible&UnitType::INVISGLOW) != 0 )
408 if (damagelevel < .9)
412 QVector TransformedPosition =
Transform( *ctm, this->meshdata[i]->Position().Cast() );
415 minmeshradius+this->meshdata[i]->clipRadialSize()*vlpqrScaleFactor );
418 d = ( TransformedPosition-camerapos ).
Magnitude();
419 double rd = d-this->meshdata[i]->rSize();
423 if (lod >= 0.5 && pixradius >= 2.5) {
425 float currentFrame = this->meshdata[i]->getCurrentFrame();
426 this->meshdata[i]->Draw( lod, this->
WarpMatrix( *ctm ), d,
427 i == this->meshdata.size()-1 ? -1 : cloak,
428 (camera->
GetNebula() == this->nebula && this->nebula != NULL) ? -1 : 0,
431 unsigned int numAnimFrames = 0;
432 static const string default_animation;
433 if ( this->meshdata[i]->getFramesPerSecond()
434 && ( numAnimFrames = this->meshdata[i]->getNumAnimationFrames( default_animation ) ) ) {
435 float currentprogress = floor(
436 this->meshdata[i]->getCurrentFrame()*numKeyFrames/(
float) numAnimFrames );
438 && floor( currentFrame*numKeyFrames/(
float) numAnimFrames ) != currentprogress)
440 this->graphicOptions.Animating = 0;
441 this->meshdata[i]->setCurrentFrame( .1+currentprogress*numAnimFrames/(
float) numKeyFrames );
442 }
else if (!this->graphicOptions.Animating) {
443 this->meshdata[i]->setCurrentFrame( currentFrame );
454 for (
un_kiter iter = this->SubUnits.constIterator(); (un = *iter); ++iter) {
462 (un)->
Draw( *ct, *ctm );
488 int nummounts = this->GetNumMounts();
489 for (i = 0; (
int) i < nummounts; i++) {
491 Mount *mahnt = &this->mounts[i];
492 if (draw_mounts && On_Screen)
493 if (mahnt->xyscale != 0 && mahnt->zscale != 0) {
494 Mesh *gun = mahnt->type->gun;
496 Transformation mountLocation( mahnt->GetMountOrientation(), mahnt->GetMountLocation().Cast() );
499 mountLocation.to_matrix( mat );
506 gun->
Draw( lod, mat, d, cloak,
510 if (mahnt->type->gun1) {
511 gun = mahnt->type->gun1;
513 gun->
Draw( lod, mat, d, cloak,
522 if (this->mounts[i].ref.gun)
523 this->mounts[i].ref.gun->Draw( *ct, this->
WarpMatrix( *ctm ),
525 && (this->mounts[i].time_to_lock <= 0)
526 && (this->computer.radar.trackingactive) ) ?
Unit::Target() : NULL,
531 haloalpha = ( (
float) cloak )/2147483647;
532 if ( On_Screen && (
phalos->NumHalos() > 0) && !( this->docked&(UnitType::DOCKED|UnitType::DOCKED_INSIDE) ) ) {
533 Vector accel = this->GetAcceleration();
534 float maxaccel = this->GetMaxAccelerationInDirectionOf( this->
WarpMatrix( *ctm ).
getR(), true );
535 Vector velocity = this->GetVelocity();
538 Vector Scale( 1, pImage->ecm, computer.set_speed );
540 float cmas = this->computer.max_ab_speed()*this->computer.max_ab_speed();
547 if (
phalos->ShouldDraw( this->WarpMatrix( *ctm ), velocity, accel, maxaccel, cmas ) )
550 this->GetHull() > 0 ? damagelevel : 1.0, velocity, accel, maxaccel, cmas, this->
faction );
552 if ( On_Screen && !UnitType::graphicOptions.NoDamageParticles
553 && !( this->docked&(UnitType::DOCKED|UnitType::DOCKED_INSIDE) ) ) {
555 if (damagelevel < .99 && numm > 0 && this->GetHull() > 0) {
556 unsigned int switcher = (damagelevel > .8) ? 1
557 : (damagelevel > .6) ? 2 : (damagelevel > .4) ? 3 : (damagelevel > .2) ? 4 : 5;
560 int spawn = (
int) (sparkle_accum);
561 sparkle_accum -= spawn;
562 while (spawn-- > 0) {
581 template <
class UnitType >
587 template <
class UnitType >
606 string::size_type ini = 0, end;
608 while (i < 4 && ini != string::npos) {
609 value[i++] =
parseFloat( s.substr( ini, end = s.find_first_of(
',', ini ) ) );
610 ini = ( (end == string::npos) ? end : (end+1) );
612 if (i >= 4 && ini != string::npos)
618 template <
class UnitType >
621 for (vector<Mesh*>::iterator mesh = this->meshdata.begin(); mesh != this->meshdata.end(); ++mesh) {
625 if (technique.get() != NULL) {
626 bool doOverride =
false;
627 for (
int passno = 0; !doOverride && passno < technique->getNumPasses(); ++passno) {
629 for (
size_t paramno = 0; !doOverride && paramno < pass.
getNumShaderParams(); ++paramno) {
640 for (
int passno = 0; passno < technique->getNumPasses(); ++passno) {
644 map<string, string>::const_iterator
override = overrides.find(param.
name);
645 if (
override != overrides.end())
650 (*mesh)->setTechnique(newtechnique);
657 template <
class UnitType >
660 static float cutoff =
664 static float cutoffcutoff = cutoff*cutoff;
665 static bool only_stretch_in_warp =
667 if ( this->GetWarpVelocity().MagnitudeSquared() < cutoffcutoff
668 || (only_stretch_in_warp && this->graphicOptions.InWarp == 0) ) {
673 float speed = this->GetWarpVelocity().Magnitude();
674 static float maxregion0stretch =
682 static float maxregion0speed =
686 float stretchregion0length = maxregion0stretch*(speed-cutoff)/(maxregion0speed-cutoff);
687 float stretchlength =
689 -maxregion0stretch)*(speed-maxregion0speed)/(maxspeed-maxregion0speed+.06125)+maxregion0stretch;
690 if (stretchlength > maxstretch)
691 stretchlength = maxstretch;
692 if (stretchregion0length > maxregion0stretch)
693 stretchregion0length = maxregion0stretch;
694 ScaleMatrix( k,
Vector( 1, 1, 1+(speed > maxregion0speed ? stretchlength : stretchregion0length) ) );
702 template <
class UnitType >
705 for (
int i = 0;
i < numhalos;
i++)
708 halos[i]->
Draw( cumulative_transformation, cumulative_transformation_matrix, 0 );
710 template <
class UnitType >
713 for (
int i = 0;
i < numhalos;
i++) {