Advertisement
Guest User

cone _cy

a guest
Oct 19th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1.  
  2. void Viewer::init_cone()
  3. {
  4.     float alpha;
  5.     int div=25;
  6.     float step=2*M_PI/div;
  7.     m_cone=Mesh(GL_TRIANGLE_STRIP);
  8.     for(int i=0;i<div+1;i++)
  9.     {
  10.         alpha=i*step;
  11.         m_cone.normal(Vector (cos(alpha)/sqrt(2),1/sqrt(2),sin(alpha)/sqrt(2)));
  12.         m_cone.vertex(Point(cos(alpha),0,sin(alpha)));
  13.         m_cone.vertex(Point(0,1,0));
  14.     }
  15. }
  16.  
  17. void Viewer::init_sphere()
  18. {
  19.     int divbeta=25;
  20.     int divalpha=divbeta/2;
  21.     float alpha, alpha2, beta;
  22.     m_sphere=Mesh(GL_TRIANGLE_STRIP);
  23.     for(int i=0;i<divalpha;i++)
  24.     {
  25.         alpha=0.5*2*M_PI+float(i)*2*M_PI/divalpha;
  26.         alpha2=0.5*2*M_PI+float(i+1)*2*M_PI/divalpha;
  27.         for(float j= 0 ;j<divbeta;j++)
  28.         {
  29.             beta= j*2*M_PI/divbeta;
  30.             m_sphere.normal(Vector(cos(alpha)*cos(beta),sin(alpha),cos(alpha)*sin(beta)));
  31.             m_sphere.vertex(Point(cos(alpha)*cos(beta),sin(alpha),cos(alpha)*sin(beta)));
  32.             m_sphere.normal(Vector(cos(alpha2)*cos(beta),sin(alpha),cos(alpha2)*sin(beta)));
  33.             m_sphere.vertex(Point(cos(alpha2)*cos(beta),sin(alpha),cos(alpha2)*sin(beta)));
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement