zShapePolygon Class Reference

#include <zShape.hpp>

Inheritance diagram for zShapePolygon:

Inheritance graph
[legend]
Collaboration diagram for zShapePolygon:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 zShapePolygon (eGrid *grid, unsigned short idZone)
 zShapePolygon (nMessage &n)
 ~zShapePolygon ()
void WriteCreate (nMessage &m)
bool isInteracting (eGameObject *target)
void render (const eCamera *cam)
virtual void render2d (tCoord scale) const
void addPoint (myPoint const &aPoint)
bool isEmulatingOldZone ()

Protected Member Functions

bool isInside (eCoord anECoord)

Static Protected Member Functions

static void networkRead (nMessage &m, zShape *aShape)

Protected Attributes

std::vector< myPointpoints

Private Member Functions

virtual nDescriptorCreatorDescriptor () const
 returns the descriptor to recreate this object over the network


Detailed Description

Definition at line 98 of file zShape.hpp.


Constructor & Destructor Documentation

zShapePolygon::zShapePolygon ( eGrid grid,
unsigned short  idZone 
)

Definition at line 402 of file zShape.cpp.

00402                                                               :
00403         zShape(grid, idZone),
00404         points()
00405 {}

zShapePolygon::zShapePolygon ( nMessage n  ) 

Definition at line 385 of file zShape.cpp.

References addPoint(), and nMessage::End().

00385                                        :zShape(m),
00386         points()
00387 {
00388     int numPoints;
00389     m >> numPoints;
00390 
00391     // read the polygon shape
00392     for( ; numPoints>0 && !m.End(); numPoints-- )
00393     {
00394         tFunction tfX, tfY;
00395         m >> tfX;
00396         m >> tfY;
00397 
00398         addPoint( myPoint( tfX, tfY ) );
00399     }
00400 }

Here is the call graph for this function:

zShapePolygon::~zShapePolygon (  )  [inline]

Definition at line 102 of file zShape.hpp.

00102 {};


Member Function Documentation

void zShapePolygon::WriteCreate ( nMessage m  )  [virtual]

Reimplemented from zShape.

Definition at line 410 of file zShape.cpp.

References points, and zShape::WriteCreate().

00411 {
00412     zShape::WriteCreate(m);
00413 
00414     int numPoints;
00415     numPoints = points.size();
00416     m << numPoints;
00417 
00418     std::vector< myPoint >::const_iterator iter;
00419     for(iter = points.begin();
00420             iter != points.end();
00421             ++iter)
00422     {
00423         m << (*iter).first;
00424         m << (*iter).second;
00425     }
00426 
00427     //    WriteSync( m );
00428 }

Here is the call graph for this function:

bool zShapePolygon::isInteracting ( eGameObject target  )  [virtual]

Reimplemented from zShape.

Definition at line 481 of file zShape.cpp.

References gCycleMovement::Alive(), isInside(), eNetGameObject::Player(), and eGameObject::Position().

00482 {
00483     bool interact = false;
00484     gCycle* prey = dynamic_cast< gCycle* >( target );
00485     if ( prey )
00486     {
00487         if ( prey->Player() && prey->Alive() )
00488         {
00489             // Is the player inside or outside the zone
00490             if ( isInside( prey->Position() ) )
00491             {
00492                 interact = true;
00493             }
00494         }
00495     }
00496     return interact;
00497 }

Here is the call graph for this function:

void zShapePolygon::render ( const eCamera cam  )  [virtual]

Reimplemented from zShape.

Definition at line 499 of file zShape.cpp.

References tColor::a_, rColor::Apply(), BeginLineStrip(), BeginQuads(), zShape::color_, tPolynomial< T >::evaluate(), tFunction::Evaluate(), zShape::lasttime_, M_PI, ModelMatrix(), points, zShape::posx_, zShape::posy_, REAL, zShape::referencetime_, RenderEnd(), zShape::rotation2, zShape::scale_, and sr_alphaBlend.

00500 {
00501 #ifndef DEDICATED
00502 
00503     // HACK
00504     //  int sg_segments = 11;
00505     bool sr_alphaBlend = true;
00506     // HACK
00507 
00508     if ( color_.a_ > .7f )
00509         color_.a_ = .7f;
00510     if ( color_.a_ <= 0 )
00511         return;
00512 
00513 
00514     ModelMatrix();
00515     glPushMatrix();
00516 
00517     glDisable(GL_LIGHT0);
00518     glDisable(GL_LIGHT1);
00519     glDisable(GL_LIGHTING);
00520     glDisable(GL_CULL_FACE);
00521     glBlendFunc( GL_SRC_ALPHA, GL_ONE );
00522 
00523     //glDisable(GL_TEXTURE);
00524     glDisable(GL_TEXTURE_2D);
00525 
00526     //    glMultMatrixf(&m[0][0]);
00527 
00528     REAL currentScale = 0.0;
00529     glTranslatef(posx_.Evaluate(lasttime_ - referencetime_), posy_.Evaluate(lasttime_ - referencetime_), 0);
00530     currentScale = scale_.Evaluate(lasttime_ - referencetime_);
00531 
00532     if(currentScale > 0.0)
00533     {
00534         glScalef(currentScale, currentScale, 1.0);
00535 
00536         glRotatef(rotation2.evaluate(lasttime_)*180/M_PI, 0.0, 0.0, 1.0);
00537 
00538         if ( sr_alphaBlend ) {
00539             glDepthMask(GL_FALSE);
00540             BeginQuads();
00541         } else {
00542             RenderEnd();
00543             glDepthMask(GL_TRUE);
00544             BeginLineStrip();
00545         }
00546 
00547         //    const REAL seglen = .2f;
00548         const REAL bot = 0.0f;
00549         const REAL top = 5.0f; // + ( lastTime - createTime_ ) * .1f;
00550 
00551         color_.Apply();
00552 
00553 
00554 
00555 
00556         std::vector< myPoint >::const_iterator iter;
00557         std::vector< myPoint >::const_iterator prevIter = points.end() - 1;
00558 
00559         for(iter = points.begin();
00560                 iter != points.end();
00561                 prevIter = iter++)
00562         {
00563             REAL xp = (*iter).first.Evaluate( lasttime_ - referencetime_ ) ;
00564             REAL yp = (*iter).second.Evaluate( lasttime_ - referencetime_ ) ;
00565             REAL xpp = (*prevIter).first.Evaluate( lasttime_ - referencetime_ ) ;
00566             REAL ypp = (*prevIter).second.Evaluate( lasttime_ - referencetime_ ) ;
00567 
00568             glVertex3f(xp, yp, bot);
00569             glVertex3f(xp, yp, top);
00570             glVertex3f(xpp, ypp, top);
00571             glVertex3f(xpp, ypp, bot);
00572 
00573             if ( !sr_alphaBlend )
00574             {
00575                 glVertex3f(xp, yp, bot);
00576                 RenderEnd();
00577                 BeginLineStrip();
00578             }
00579         }
00580 
00581         RenderEnd();
00582 
00583         glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
00584         glDepthMask(GL_TRUE);
00585     }
00586     glPopMatrix();
00587 #endif
00588 }

Here is the call graph for this function:

void zShapePolygon::render2d ( tCoord  scale  )  const [virtual]

Reimplemented from zShape.

Definition at line 589 of file zShape.cpp.

References tColor::a_, rColor::Apply(), BeginLines(), zShape::color_, tPolynomial< T >::evaluate(), tFunction::Evaluate(), zShape::lasttime_, M_PI, ModelMatrix(), points, zShape::posx_, zShape::posy_, REAL, zShape::referencetime_, RenderEnd(), zShape::rotation2, and zShape::scale_.

00589                                                {
00590 #ifndef DEDICATED
00591 
00592     //if ( color_.a_ > .7f )
00593     //    color_.a_ = .7f;
00594     if ( color_.a_ <= 0 )
00595         return;
00596 
00597 
00598     ModelMatrix();
00599     glPushMatrix();
00600 
00601     REAL currentScale = 0.0;
00602     glTranslatef(posx_.Evaluate(lasttime_ - referencetime_), posy_.Evaluate(lasttime_ - referencetime_), 0);
00603 
00604     currentScale = scale_.Evaluate(lasttime_ - referencetime_);
00605 
00606     if(currentScale > 0.0)
00607     {
00608         glScalef(currentScale, currentScale, 1.0);
00609 
00610         glRotatef(rotation2.evaluate(lasttime_)*180/M_PI, 0.0, 0.0, 1.0);
00611 
00612         BeginLines();
00613 
00614         //    const REAL seglen = .2f;
00615 
00616         color_.Apply();
00617 
00618         std::vector< myPoint >::const_iterator iter;
00619         std::vector< myPoint >::const_iterator prevIter = points.end() - 1;
00620 
00621         for(iter = points.begin();
00622                 iter != points.end();
00623                 prevIter = iter++)
00624         {
00625             REAL xp = (*iter).first.Evaluate( lasttime_ - referencetime_ ) ;
00626             REAL yp = (*iter).second.Evaluate( lasttime_ - referencetime_ ) ;
00627             REAL xpp = (*prevIter).first.Evaluate( lasttime_ - referencetime_ ) ;
00628             REAL ypp = (*prevIter).second.Evaluate( lasttime_ - referencetime_ ) ;
00629 
00630             glVertex2f(xp, yp);
00631             glVertex2f(xpp, ypp);
00632         }
00633 
00634         RenderEnd();
00635     }
00636     glPopMatrix();
00637 #endif
00638 }

Here is the call graph for this function:

void zShapePolygon::addPoint ( myPoint const &  aPoint  )  [inline]

Definition at line 110 of file zShape.hpp.

References points.

Referenced by zShapePolygon().

00110 { points.push_back(aPoint);};

Here is the caller graph for this function:

bool zShapePolygon::isEmulatingOldZone (  )  [inline, virtual]

Reimplemented from zShape.

Definition at line 112 of file zShape.hpp.

00112 {return false;}; // zShapePolygon cant be used for emulation of old zones

bool zShapePolygon::isInside ( eCoord  anECoord  )  [protected]

Definition at line 430 of file zShape.cpp.

References c, cosf(), tPolynomial< T >::evaluate(), tFunction::Evaluate(), zShape::lasttime_, points, zShape::posx_, zShape::posy_, REAL, zShape::referencetime_, zShape::rotation2, zShape::scale_, sinf(), tCoord::x, x, and tCoord::y.

Referenced by isInteracting().

00430                                             {
00431     // The following is a modified version of code by Randolph Franklin,
00432     // Found at http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/
00433 
00434     // Hack!!!!
00435     // All the poinst need to be moved around the x,y position
00436     // then scaled
00437     //    REAL r = scale_->GetFloat();
00438     REAL x = anECoord.x;
00439     REAL y = anECoord.y;
00440     int c = 0;
00441 
00442     std::vector< myPoint >::const_iterator iter = points.end() - 1;
00443     // We need to position the prevIter to the last point.
00444     REAL currentScale = 0.0;
00445     REAL x_ = (*iter).first.Evaluate(lasttime_ - referencetime_);
00446     REAL y_ = (*iter).second.Evaluate(lasttime_ - referencetime_);
00447     tCoord centerPos = tCoord(posx_.Evaluate(lasttime_ - referencetime_), posy_.Evaluate(lasttime_ - referencetime_));
00448     //    tCoord rotation = tCoord( cosf(rotation_.Evaluate(lasttime_ - referencetime_)), sinf(rotation_.Evaluate(lasttime_ - referencetime_)) );
00449     tCoord rotation = tCoord( cosf(rotation2.evaluate(lasttime_)), sinf(rotation2.evaluate(lasttime_)) );
00450     currentScale = scale_.Evaluate(lasttime_ - referencetime_);
00451     tCoord previous = tCoord(x_, y_).Turn( rotation )*currentScale + centerPos;
00452 
00453     REAL xpp = previous.x;
00454     REAL ypp = previous.y;
00455 
00456     if(currentScale > 0.0)
00457     {
00458         for(iter = points.begin();
00459                 iter != points.end();
00460                 ++iter)
00461         {
00462             x_ = (*iter).first.Evaluate(lasttime_ - referencetime_);
00463             y_ = (*iter).second.Evaluate(lasttime_ - referencetime_);
00464             tCoord current = tCoord(x_, y_).Turn( rotation )*currentScale + centerPos;
00465 
00466             REAL xp = current.x;
00467             REAL yp = current.y;
00468 
00469             if ((((yp <= y) && (y < ypp)) || ((ypp <= y) && (y < yp))) &&
00470                     (x < (xpp - xp) * (y - yp) / (ypp - yp) + xp))
00471                 c = !c;
00472 
00473             xpp = xp; ypp = yp;
00474         }
00475     }
00476 
00477     return c;
00478 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void zShapePolygon::networkRead ( nMessage m,
zShape aShape 
) [static, protected]

nDescriptor & zShapePolygon::CreatorDescriptor ( void   )  const [private, virtual]

returns the descriptor to recreate this object over the network

Implements nNetObject.

Definition at line 649 of file zShape.cpp.

References zonePolygon_init.

00650 {
00651     return zonePolygon_init;
00652 }


Member Data Documentation

std::vector< myPoint > zShapePolygon::points [protected]

Definition at line 112 of file zShape.hpp.

Referenced by addPoint(), isInside(), render(), render2d(), and WriteCreate().


The documentation for this class was generated from the following files:
Generated on Sun Mar 16 00:02:23 2008 for Armagetron Advanced by  doxygen 1.5.4