// Polygon.h -- colored, moving polygons // // // DESCRIPTION // Represent and draw colored, moving polygons for Mondrian motion test sequences. // // SEE ALSO // Color.h - RGBA Color class CCol // Polygon.cpp - Implementation // // Copyright © Daniel Scharstein, 2003. // /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // A 2-Vector class #include "Color.h" class CVec2 { public: float x, y; // Constructors and helper functions CVec2(float x=0, float y=0) : x(x), y(y) {} void scale(float s); void translate(CVec2 v); void move(CVec2 velocity, float time); void randomize(float min, float max); }; // scalar multiplication inline CVec2 operator * (float s, CVec2 v) { return CVec2(s * v.x, s * v.y); } // addition inline CVec2 operator + (CVec2 v, CVec2 w) { return CVec2(v.x + w.x, v.y + w.y); } // swap two vectors void swap(CVec2 &v, CVec2 &w); /* not used: inline void CVec2::scale(float s) { x *= s; y *= s; } inline void CVec2::translate(CVec2 v) { x += v.x; y += v.y; } inline void CVec2::move(CVec2 velocity, float time) { translate(time * velocity); } */ /////////////////////////////////////////////////////////////////////////// // A Polygon class class CPoly { public: CVec2 vel; // velocity float z; // depth (determines depth ordering) CCol color; // Constructor CPoly(CVec2 vel=CVec2(), float z=0, CCol c=CCol()) : vel(vel), z(z), color(c) {} // draw this rectangle at time t (implemented by subclasses) virtual void draw(CByteImage dst, float t) {} }; /////////////////////////////////////////////////////////////////////////// // A Rectangle class class CRect: public CPoly { public: CVec2 p0; // position of top-left corner at time 0 CVec2 diag; // determines width, height; // vel, z, color inherited from CPoly // Constructors CRect(CVec2 p0=CVec2(), CVec2 diag=CVec2(), CVec2 vel=CVec2(), float z=0, CCol c=CCol()) : p0(p0), diag(diag), CPoly(vel, z, c) {} // draw this rectangle at time t void draw(CByteImage dst, float t); }; /////////////////////////////////////////////////////////////////////////// // A Triangle class #pragma once class CTri: public CPoly { CVec2 p0; // position of vertex 0 at time 0 CVec2 p1; // position of vertex 1 at time 0 CVec2 p2; // position of vertex 2 at time 0 public: // Constructors CTri(CVec2 p0=CVec2(), CVec2 p1=CVec2(), CVec2 p2=CVec2(), CVec2 vel=CVec2(), float z=0, CCol c=CCol()) : p0(p0), p1(p1), p2(p2), CPoly(vel, z, c) {} // draw this triangle at time t void draw(CByteImage dst, float t); }; /////////////////////////////////////////////////////////////////////////// // A class of shapes that satisfy //the property that any all points //between any two points in the shape WITH THE //SAME X COORDINATE are also in the shape. //They are horizontally convex. //Note that this is less restrictive than real Convexity. class CConvex: public CPoly { public: CVec2 p0; // position of top-left corner at time 0 CVec2 diag; // determines width, height of maximum points; // vel, z, color inherited from CPoly bool**data;//the shape itself, represented by a boolean map // Constructors CConvex(CVec2 p0=CVec2(), CVec2 diag=CVec2(), CVec2 vel=CVec2(), float z=0, CCol c=CCol()); // draw this rectangle at time t void draw(CByteImage dst, float t); private: //helper functions int getMax(int row); int getMin(int row); };