mirror of https://github.com/CGAL/cgal
69 lines
2.6 KiB
C++
69 lines
2.6 KiB
C++
// Copyright (c) 2005 INRIA Sophia-Antipolis (France)
|
||
// All rights reserved.
|
||
//
|
||
// Authors : Damien Leroy
|
||
// Julien Hazebrouck
|
||
//
|
||
// Partially supported by the IST Programme of the EU as a Shared-cost
|
||
// RTD (FET Open) Project under Contract No IST-2000-26473
|
||
// (ECG - Effective Computational Geometry for Curves and Surfaces)
|
||
// and a STREP (FET Open) Project under Contract No IST-006413
|
||
// (ACS -- Algorithms for Complex Shapes)
|
||
//
|
||
// Fonction dessinant un cercle pass<73>en param<61>re <20>partir de segments.
|
||
// Le nombre de segment utilis<69>est egal <20>la pr<70>ision pass<73>en param<61>re.
|
||
|
||
#ifndef _SPHERICAL_CIRCLE_GL__H_
|
||
#define _SPHERICAL_CIRCLE_GL__H_
|
||
|
||
#include <math.h>
|
||
|
||
#define ABS(d) (((d) > 0) ? (d) : (-d))
|
||
#define COLOR_POINT(p) glColor3f(ABS(p.x()),ABS(p.y()),ABS(p.z()))
|
||
#define AFFICHER_POINT_CONTOUR(p) COLOR_POINT(p),glVertex3f(CGAL::to_double(p.x()),CGAL::to_double(p.y()),CGAL::to_double(p.z()))
|
||
#define TRACE_SEGMENT(p1,p2) AFFICHER_POINT_CONTOUR(p1),AFFICHER_POINT_CONTOUR(p2)
|
||
#define COLOR_ROUGE glColor3f(1.0, 0.0, 0.0)
|
||
#define COLOR_POINT(p) glColor3f(ABS(p.x()),ABS(p.y()),ABS(p.z()))
|
||
#define IMPRIMER_POINT(n,p) std::cout << n << " = (" << p.x() << ", " << p.y() << ", " << p.z() << ")" << std::endl
|
||
#define VECTOR_LENGTH(v) sqrt((v.x()*v.x())+(v.y()*v.y())+(v.z()*v.z()))
|
||
|
||
/**
|
||
* Fonction dessinant le contour du cercle 3D passe en parametre avec la precision voulue.
|
||
*/
|
||
template <class SK>
|
||
void dessiner_spherical_circle (const typename SK::Circle_3& circle, int precision) {
|
||
typedef typename SK::Point_3 Point_3;
|
||
typedef typename SK::Vector_3 Vector_3;
|
||
typedef typename SK::Has_on_3 Has_on_3;
|
||
const Point_3& centre = circle.center();
|
||
//IMPRIMER_POINT("centre", centre);
|
||
Vector_3 u = circle.supporting_plane().base1();
|
||
u = u / VECTOR_LENGTH(u);
|
||
//IMPRIMER_POINT("u", u);
|
||
Vector_3 v = circle.supporting_plane().base2();
|
||
v = v / VECTOR_LENGTH(v);
|
||
//IMPRIMER_POINT("v", v);
|
||
double rayon = sqrt(CGAL::to_double(circle.squared_radius()));
|
||
double pas = 2 * M_PI / precision;
|
||
glLineWidth(5.0);
|
||
glDisable(GL_LIGHTING); // desactive la gestion de la lumiere
|
||
|
||
Point_3 pprec = centre + rayon * u;
|
||
Point_3 pcour;
|
||
glBegin(GL_LINES);
|
||
COLOR_ROUGE;
|
||
for (double theta = pas; theta < 2 * M_PI + pas; theta = theta + pas) {
|
||
pcour = Point_3(
|
||
centre.x() + rayon * (u.x() * cos(theta) + v.x() * sin(theta)),
|
||
centre.y() + rayon * (u.y() * cos(theta) + v.y() * sin(theta)),
|
||
centre.z() + rayon * (u.z() * cos(theta) + v.z() * sin(theta))
|
||
);
|
||
TRACE_SEGMENT(pprec, pcour);
|
||
pprec = pcour;
|
||
}
|
||
glEnd();
|
||
}
|
||
|
||
#endif // _SPHERICAL_CIRCLE_GL__H_
|
||
|