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++ »

john\′s Photo
10 Nov 05, 8:59AM
Do you want to use Polygons or just triangles?

If you really want to go completely C++, then I'd start with something like this:

class Point
{
  int x,y,z;
  void rotate(alpha_x, alpha_y, alpha_z);
  void scale(scale_x, scale_y, scale_z);  
}

where rotate and scale are the first of a collection of functions you'll probably want to manipulate each point. rotate for example, would translate any point around a central point (e.g. x=y=z=0), using the classical matrix transformation, i.e to rotate about x-axis you want: To rotate about the y_axis you want: Then for the z-axis:

At this point you can go two ways: a) Define a single array of Point, which contains the nodes of your entire mesh for the sphere (the option I'd do). Then have a new class relating the interconnectivity between nodes - Pro: Faster; Con: Not tightly encapsulated. b) Define a class that handles each polygon separately - Con: a little memory inefficient.

Thus

class TriNodes
{
  int m_points[3];  // you put in here the index values for each Point
}

You then have something like:

class Sphere
{
  std::vector<Point> m_points;
  std::vector<TriNodes> m_nodes;
 
  // with functions
  void addNode(int x, y, z);   
  void addTriMesh(int a, int b, int c); // where a,b,c reference m_points[a], m_points[b] etc.
  void scale(..);
  void rotate(..);
  void display(...); 
};

Seems like something CodeCogs should have, but can't find anything. Why don't you post it to CodeCogs. Keep it 'Private' initially make me an editor and I'll helping you out..

John

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