Usage
CompPoint represents a simple two-axis point on the screen. It does not represent a co-ordinate in 3D space. You should use GLVector for that. It is designed to reduce code clutter by having separate variables around for both X and Y co-ordinates of something.
Class Defininition
/** * A 2D coordinate (likely in screen space) that can only be mutated * through set() methods, since it's data members are private. */ class CompPoint { public: CompPoint (); CompPoint (int, int); /** * Get the x coordinate of this point */ int x () const; /** * Get the y coordinate of this point */ int y () const; /** * Set the x and y coordinate of this point */ void set (int, int); /** * Set the x coordinate of this point */ void setX (int); /** * Set the y coordinate of this point */ void setY (int); bool operator== (const CompPoint &) const; bool operator!= (const CompPoint &) const; /** * Takes from both co-ordinates */ CompPoint & operator-= (const CompPoint &); /** * Adds to both co-ordinates */ CompPoint & operator+= (const CompPoint &); /** * Retuns an added point */ CompPoint operator+ (const CompPoint &) const; /** * Returns a subtracted point */ CompPoint operator- (const CompPoint &) const; typedef std::vector<CompPoint> vector; typedef std::vector<CompPoint *> ptrVector; typedef std::list<CompPoint> list; typedef std::list<CompPoint *> ptrList; private: int mX, mY; }; inline int CompPoint::x () const { return mX; } inline int CompPoint::y () const { return mY; }
Adding and subtracting
The only non-self-expanatory part of this class is the operator overloads which allow you to add and subtract CompPoint's. These can be useful if you wish to translate a point by some X and Y amount.
Development/zero-nine/CoreClasses/CompPoint (last edited 2010-07-27 00:26:54 by 124-169-107-122)