I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » C/C++ »

pacman\′s Photo
12 Nov 05, 8:58PM
Keep things simple and define a Point using a struct! Then get complex with your classes...

To save memory, define a static class called something like 'PolyMethods' - this simply contains methods for rotating/translating/scaling/etc an array of Points. This class is never instatiated - the Points are passed into the methods as a parameter.

Then, for neatness, define a virtual class called Polyhedron - this encapsulates an array of Points, and would also inherit all the (static) methods from PolyMethods.

Am I right in thinking that you can inherit from static to non-static (but not vice-versa, obviously) ??? This class would override the methods of PolyMethods (so I guess PolyMethods would need to be virtual too) with its own methods, which actually call the methods they override, to pass them the Points data.

Finally, you can define yourself an actual, instatiatable subclass, eg 'Sphere'. This would inherit methods and data from Polyhedron.

static virtual class PolyMethods
{
  protected:
 
    // rotates the given array of Points about (0,0,0)
    // by changing each Point's bearing and elevation by the amounts given
    void rotate(Point * points, double bearing_change, double elevation_change)
    {
       /* do all that trigonometry stuff here */    
    }
 
    // translate, scale, etc...
}
 
virtual class Polyhedron: public PolyMethods
{
  protected:
 
    Point points[]; // not sure about this...
 
    // constructor 
    Polyhedron(Point* initial_data)
    {
      self.points = initial_data;
    }
 
    // rotate... this method gets the Points data, then passes it to the method it overrides
    void rotate(double bearing_change, double elevation_change)
    {
      super.rotate( self.points, bearing_change, elevation_change)
    }
 
    // translate, scale, etc...
};
 
class Sphere: public Polyhedron
{
  // In here you do something about knowing how many points there are
  // perhaps you override the constructor or something... I don't know
};

Or, I suppose, you might just make Polyhedron non-virtual and use it directly... But I'm not sure how you would deal with the variable number of points then. In fact I'm not sure anyway...

Feel free to correct me on any of this, my C++ is a bit rusty!

Currently you need to be logged in to leave a message.