2005-03-03 11:48:54 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* VCGLib o o *
|
|
|
|
* Visual and Computer Graphics Library o o *
|
|
|
|
* _ O _ *
|
2016-06-13 07:29:25 +02:00
|
|
|
* Copyright(C) 2004-2016 \/)\/ *
|
2005-03-03 11:48:54 +01:00
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
|
|
|
* for more details. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
2006-03-29 09:54:03 +02:00
|
|
|
History
|
|
|
|
$Log: not supported by cvs2svn $
|
2006-07-03 15:46:34 +02:00
|
|
|
Revision 1.12 2006/05/25 09:22:58 cignoni
|
|
|
|
Removed all GLUT dependencies!
|
|
|
|
|
2006-05-25 11:22:58 +02:00
|
|
|
Revision 1.11 2006/03/29 07:54:03 cignoni
|
|
|
|
Wrong matrix type in cone (thx Maarten)
|
|
|
|
|
2005-04-04 13:59:16 +02:00
|
|
|
|
2005-03-03 11:48:54 +01:00
|
|
|
****************************************************************************/
|
2005-04-04 13:59:16 +02:00
|
|
|
#ifndef __VCG_GLADDONS
|
|
|
|
#define __VCG_GLADDONS
|
2005-03-03 11:48:54 +01:00
|
|
|
|
|
|
|
#include <wrap/gl/math.h>
|
|
|
|
#include <wrap/gl/space.h>
|
|
|
|
#include <vcg/space/point3.h>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace vcg
|
|
|
|
{
|
2006-05-25 11:22:58 +02:00
|
|
|
#include "gl_geometry.h"
|
2005-03-03 11:48:54 +01:00
|
|
|
/** Class Add_Ons.
|
|
|
|
This is class draw 3d icons on the screen
|
|
|
|
*/
|
|
|
|
class Add_Ons
|
|
|
|
{
|
|
|
|
public:
|
2012-12-21 16:34:32 +01:00
|
|
|
enum DrawMode {DMUser,DMWire,DMSolid,DMFlat} ;
|
2005-03-03 11:48:54 +01:00
|
|
|
private:
|
|
|
|
|
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
|
|
|
///used to find right transformation in case of rotation
|
|
|
|
static void XAxis(vcg::Point3f zero, vcg::Point3f uno, Matrix44f & tr)
|
|
|
|
{
|
|
|
|
#ifndef VCG_USE_EIGEN
|
2005-03-03 11:48:54 +01:00
|
|
|
tr.SetZero();
|
2006-01-03 12:13:25 +01:00
|
|
|
*((vcg::Point3f*)&tr[0][0]) = uno-zero;
|
|
|
|
GetUV(*((vcg::Point3f*)tr[0]),*((vcg::Point3f*)tr[1]),*((vcg::Point3f*)tr[2]));
|
2005-03-03 11:48:54 +01:00
|
|
|
tr[3][3] = 1.0;
|
2006-01-03 12:13:25 +01:00
|
|
|
*((vcg::Point3f*)&tr[3][0]) = zero;
|
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
|
|
|
#else
|
|
|
|
tr.col(0).start<3>().setZero();
|
|
|
|
tr.row(0).start<3>() = (uno-zero).normalized(); // n
|
|
|
|
tr.row(1).start<3>() = tr.row(0).start<3>().unitOrthogonal(); // u
|
|
|
|
tr.row(2).start<3>() = tr.row(0).start<3>().cross(tr.row(1).start<3>()).normalized(); // v
|
|
|
|
tr.row(3) << zero.transpose(), 1.;
|
|
|
|
#endif
|
2005-03-03 11:48:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//set drawingmode parameters
|
|
|
|
static void SetGLParameters(DrawMode DM)
|
|
|
|
{
|
|
|
|
switch(DM)
|
|
|
|
{
|
|
|
|
case DMUser :
|
|
|
|
break;
|
2012-12-21 16:34:32 +01:00
|
|
|
case DMFlat :
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_NORMALIZE);
|
|
|
|
break;
|
|
|
|
case DMWire :
|
2005-03-03 14:29:35 +01:00
|
|
|
glDisable(GL_CULL_FACE);
|
2005-03-03 11:48:54 +01:00
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glDisable(GL_NORMALIZE);
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
|
|
|
|
break;
|
|
|
|
case DMSolid :
|
2005-03-03 14:29:35 +01:00
|
|
|
glDisable(GL_CULL_FACE);
|
2005-03-03 11:48:54 +01:00
|
|
|
glPolygonMode(GL_FRONT,GL_FILL);
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///draw a cylinder
|
2006-01-03 12:13:25 +01:00
|
|
|
static void Cylinder(int slices,float lenght,float width,bool useDisplList)
|
2005-03-03 11:48:54 +01:00
|
|
|
{
|
|
|
|
static std::map<int,GLint> Disp_listMap;
|
|
|
|
GLint cyl_List=-1;
|
|
|
|
std::map<int,GLint>::const_iterator it=Disp_listMap.find(slices);
|
|
|
|
///if the diplay list is createdtake the Glint that identify it
|
|
|
|
bool to_insert=false;
|
2005-04-04 13:59:16 +02:00
|
|
|
if (useDisplList)
|
|
|
|
{
|
2005-05-19 11:09:54 +02:00
|
|
|
if (it!=Disp_listMap.end())///the list exist
|
|
|
|
cyl_List=it->second;
|
|
|
|
else to_insert=true;
|
2005-04-04 13:59:16 +02:00
|
|
|
}
|
2005-03-03 11:48:54 +01:00
|
|
|
|
|
|
|
glScaled(lenght,width,width);
|
|
|
|
|
2005-04-04 13:59:16 +02:00
|
|
|
if (((!glIsList(cyl_List))&&(useDisplList))||(!useDisplList))
|
2005-03-03 11:48:54 +01:00
|
|
|
{
|
2005-04-04 13:59:16 +02:00
|
|
|
if (useDisplList)
|
|
|
|
{
|
|
|
|
cyl_List = glGenLists(1);
|
|
|
|
glNewList(cyl_List, GL_COMPILE);
|
|
|
|
}
|
2005-03-03 11:48:54 +01:00
|
|
|
int b;
|
2006-01-03 12:13:25 +01:00
|
|
|
vcg::Point3f p0;
|
|
|
|
vcg::Point3f p1;
|
2005-05-19 11:09:54 +02:00
|
|
|
|
2006-07-03 15:46:34 +02:00
|
|
|
float step=6.28f/(float)slices;
|
2006-01-03 12:13:25 +01:00
|
|
|
float angle=0;
|
2005-03-03 11:48:54 +01:00
|
|
|
glBegin(GL_TRIANGLE_STRIP);
|
2005-04-04 13:59:16 +02:00
|
|
|
for(b = 0; b <= slices-1; ++b){
|
2006-01-03 12:13:25 +01:00
|
|
|
p0 = vcg::Point3f( 0, sin(angle),cos(angle));
|
2005-03-03 11:48:54 +01:00
|
|
|
p1 = p0; p1[0] = 1.f;
|
|
|
|
glNormal3f(p0[0],p0[1],p0[2]);
|
|
|
|
glVertex3d(p0[0],p0[1],p0[2]);
|
|
|
|
glVertex3d(p1[0],p1[1],p1[2]);
|
2005-04-04 13:59:16 +02:00
|
|
|
angle+=step;
|
2005-03-03 11:48:54 +01:00
|
|
|
}
|
2005-04-04 13:59:16 +02:00
|
|
|
///re-conjunction with first point of cylinder
|
|
|
|
glNormal3f(0,0,1);
|
|
|
|
glVertex3d(0,0,1);
|
|
|
|
glVertex3d(1,0,1);
|
|
|
|
|
2005-03-03 11:48:54 +01:00
|
|
|
glEnd();
|
2005-04-04 13:59:16 +02:00
|
|
|
|
|
|
|
///fill the cylinder down
|
|
|
|
angle=0;
|
2006-01-03 12:13:25 +01:00
|
|
|
p0=vcg::Point3f(0,0,0);
|
2005-04-04 13:59:16 +02:00
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
|
|
|
glNormal3f(-1,0,0);
|
|
|
|
glVertex3d(p0[0],p0[1],p0[2]);
|
|
|
|
for(b = 0; b <= slices-1; ++b){
|
|
|
|
glNormal3f(-1,0,0);
|
2006-01-03 12:13:25 +01:00
|
|
|
p1 = Point3f( 0, sin(angle),cos(angle));
|
2005-04-04 13:59:16 +02:00
|
|
|
glVertex3d(p1[0],p1[1],p1[2]);
|
|
|
|
angle+=step;
|
|
|
|
}
|
|
|
|
glNormal3f(-1,0,0);
|
|
|
|
glVertex3d(0,0,1);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
angle=0;
|
2006-01-03 12:13:25 +01:00
|
|
|
p0=vcg::Point3f(1,0,0);
|
2005-04-04 13:59:16 +02:00
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
|
|
|
glNormal3f(1,0,0);
|
|
|
|
glVertex3d(p0[0],p0[1],p0[2]);
|
|
|
|
for(b = 0; b <= slices-1; ++b){
|
|
|
|
glNormal3f(1,0,0);
|
2006-01-03 12:13:25 +01:00
|
|
|
p1 = Point3f( 1, sin(angle),cos(angle));
|
2005-04-04 13:59:16 +02:00
|
|
|
glVertex3d(p1[0],p1[1],p1[2]);
|
|
|
|
angle+=step;
|
|
|
|
}
|
|
|
|
glNormal3f(1,0,0);
|
|
|
|
glVertex3d(1,0,1);
|
|
|
|
glEnd();
|
2005-06-30 15:20:32 +02:00
|
|
|
|
2005-07-11 11:04:26 +02:00
|
|
|
|
2005-04-04 13:59:16 +02:00
|
|
|
if (useDisplList)
|
|
|
|
glEndList();
|
2005-03-03 11:48:54 +01:00
|
|
|
}
|
2005-04-04 13:59:16 +02:00
|
|
|
if (useDisplList)
|
|
|
|
{
|
|
|
|
glCallList(cyl_List);
|
2005-05-19 11:09:54 +02:00
|
|
|
///I insert key and value in the map if I need
|
2005-04-04 13:59:16 +02:00
|
|
|
if (to_insert)
|
|
|
|
Disp_listMap.insert(std::pair<int,GLint>(slices,cyl_List));
|
|
|
|
}
|
2005-03-03 11:48:54 +01:00
|
|
|
}
|
2005-07-23 11:21:37 +02:00
|
|
|
public:
|
2006-01-03 12:13:25 +01:00
|
|
|
static void Diamond (float radius,bool useDisplList)
|
2005-03-03 11:48:54 +01:00
|
|
|
{
|
|
|
|
static GLint diam_List=-1;
|
2005-05-19 11:09:54 +02:00
|
|
|
|
2005-03-03 11:48:54 +01:00
|
|
|
glScaled(radius,radius,radius);
|
2005-04-04 13:59:16 +02:00
|
|
|
if (((!glIsList(diam_List))&&(useDisplList))||(!useDisplList))
|
|
|
|
{
|
2005-05-19 11:09:54 +02:00
|
|
|
if (useDisplList)
|
|
|
|
{
|
|
|
|
diam_List = glGenLists(1);
|
|
|
|
glNewList(diam_List, GL_COMPILE);
|
|
|
|
}
|
2005-03-03 11:48:54 +01:00
|
|
|
|
2005-05-19 11:09:54 +02:00
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
|
|
|
glNormal3f( 0.0, 1, 0.0);
|
|
|
|
glVertex3f(0.0,1,0.0);
|
2005-03-03 11:48:54 +01:00
|
|
|
|
2005-05-19 11:09:54 +02:00
|
|
|
glNormal3f( 1, 0.0, 0.0);
|
|
|
|
glVertex3f( 1, 0.0, 0.0);
|
2005-03-03 11:48:54 +01:00
|
|
|
|
2005-05-19 11:09:54 +02:00
|
|
|
glNormal3f( 0.0, 0.0, -1);
|
|
|
|
glVertex3f( 0.0, 0.0,-1);
|
2005-03-03 11:48:54 +01:00
|
|
|
|
2005-05-19 11:09:54 +02:00
|
|
|
glNormal3f(-1, 0.0 , 0.0);
|
|
|
|
glVertex3f(-1, 0.0, 0.0);
|
2005-03-03 11:48:54 +01:00
|
|
|
|
2005-05-19 11:09:54 +02:00
|
|
|
glNormal3f( 0.0, 0.0, 1);
|
|
|
|
glVertex3f( 0.0, 0.0, 1);
|
2005-03-03 11:48:54 +01:00
|
|
|
|
2005-05-19 11:09:54 +02:00
|
|
|
glNormal3f( 1, 0.0, 0.0);
|
|
|
|
glVertex3f( 1, 0.0, 0.0);
|
2005-03-03 11:48:54 +01:00
|
|
|
|
2005-05-19 11:09:54 +02:00
|
|
|
glEnd();
|
2005-03-03 11:48:54 +01:00
|
|
|
|
2005-05-19 11:09:54 +02:00
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
|
|
|
glNormal3f( 0.0, 1, 0.0);
|
|
|
|
glVertex3f( 0.0,-1, 0.0);
|
2005-03-03 11:48:54 +01:00
|
|
|
|
2005-05-19 11:09:54 +02:00
|
|
|
glNormal3f( 1, 0.0, 0.0);
|
|
|
|
glVertex3f( 1, 0.0, 0.0);
|
2005-03-03 11:48:54 +01:00
|
|
|
|
2005-05-19 11:09:54 +02:00
|
|
|
glNormal3f( 0.0, 0.0, 1);
|
|
|
|
glVertex3f( 0.0, 0.0, 1);
|
2005-03-03 11:48:54 +01:00
|
|
|
|
2005-05-19 11:09:54 +02:00
|
|
|
glNormal3f(-1,0.0 , 0.0);
|
|
|
|
glVertex3f(-1, 0.0, 0.0);
|
2005-03-03 11:48:54 +01:00
|
|
|
|
2005-05-19 11:09:54 +02:00
|
|
|
glNormal3f( 0.0,0.0, -1);
|
|
|
|
glVertex3f( 0.0, 0.0,-1);
|
2005-03-03 11:48:54 +01:00
|
|
|
|
2005-05-19 11:09:54 +02:00
|
|
|
glNormal3f( 1, 0.0, 0.0);
|
|
|
|
glVertex3f( 1, 0.0, 0.0);
|
|
|
|
glEnd();
|
|
|
|
if (useDisplList)
|
|
|
|
glEndList();
|
2005-03-03 11:48:54 +01:00
|
|
|
}
|
2005-04-04 13:59:16 +02:00
|
|
|
if (useDisplList)
|
|
|
|
glCallList(diam_List);
|
2005-03-03 11:48:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///draw a cone
|
2006-01-03 12:13:25 +01:00
|
|
|
static void Cone(int slices,float lenght,float width,bool useDisplList)
|
2005-03-03 11:48:54 +01:00
|
|
|
{
|
|
|
|
static std::map<int,GLint> Disp_listMap;
|
|
|
|
GLint cone_List=-1;
|
|
|
|
std::map<int,GLint>::const_iterator it=Disp_listMap.find(slices);
|
|
|
|
///if the diplay list is createdtake the Glint that identify it
|
|
|
|
bool to_insert=false;
|
2005-05-19 11:09:54 +02:00
|
|
|
|
2005-04-04 13:59:16 +02:00
|
|
|
if (useDisplList)
|
|
|
|
{
|
|
|
|
if (it!=Disp_listMap.end())///the list exist
|
|
|
|
cone_List=it->second;
|
|
|
|
else to_insert=true;
|
|
|
|
}
|
2005-03-03 11:48:54 +01:00
|
|
|
|
|
|
|
glScaled(lenght,width,width);
|
2005-04-04 13:59:16 +02:00
|
|
|
if (((!glIsList(cone_List))&&(useDisplList))||(!useDisplList))
|
2005-03-03 11:48:54 +01:00
|
|
|
{
|
2005-06-30 15:20:32 +02:00
|
|
|
int h=1;
|
|
|
|
vcg::Point3f p0;
|
2005-07-11 11:04:26 +02:00
|
|
|
vcg::Point3f P[2];
|
2005-06-30 15:20:32 +02:00
|
|
|
vcg::Point3f N[2];
|
2005-03-03 11:48:54 +01:00
|
|
|
glScaled(lenght,width,width);
|
2005-04-04 13:59:16 +02:00
|
|
|
if (useDisplList)
|
|
|
|
{
|
|
|
|
cone_List = glGenLists(1);
|
|
|
|
glNewList(cone_List, GL_COMPILE);
|
|
|
|
}
|
2005-06-30 15:20:32 +02:00
|
|
|
for(h=0; h < 2; ++h)
|
|
|
|
{
|
2012-12-21 16:34:32 +01:00
|
|
|
// assert(!glGetError());
|
2005-06-30 15:20:32 +02:00
|
|
|
//glBegin(GL_TRIANGLE_FAN);
|
|
|
|
p0 = Point3f(0,0,0);
|
|
|
|
if(h==0) p0[0]+=1.f;
|
|
|
|
//glNormal3f(1,0.0,0.0);
|
|
|
|
//glVertex3d(p0[0],p0[1],p0[2]);
|
2005-07-11 11:04:26 +02:00
|
|
|
N[0]= Point3f( 1.f,sinf(0),cosf(0) );
|
|
|
|
P[0]= Point3f( 0,sinf(0),cosf(0));
|
2005-03-03 11:48:54 +01:00
|
|
|
int b;
|
2005-06-30 15:20:32 +02:00
|
|
|
for(b = 1; b <= slices; ++b)
|
|
|
|
{
|
2006-07-03 15:46:34 +02:00
|
|
|
float angle = -6.28f*(float)b/(float)slices;
|
2005-06-30 15:20:32 +02:00
|
|
|
if (b==slices) angle=0;
|
|
|
|
N[1] = Point3f( 1.f, sinf(angle), cosf(angle) );
|
|
|
|
P[1] = Point3f( 0, sinf(angle), cosf(angle));
|
|
|
|
glBegin(GL_TRIANGLES);
|
2012-12-21 16:34:32 +01:00
|
|
|
Point3f n = ( (P[0]-p0) ^ (P[1]-p0) ).Normalize();
|
|
|
|
// Point3f n = ( (N[0]+N[1]) ).Normalize();
|
|
|
|
glNormal(n);
|
|
|
|
glVertex(p0);
|
2005-07-11 11:04:26 +02:00
|
|
|
glNormal3f(N[0][0],N[0][1],N[0][2]);
|
|
|
|
glVertex3f(P[0][0],P[0][1],P[0][2]);
|
|
|
|
glNormal3f(N[1][0],N[1][1],N[1][2]);
|
|
|
|
glVertex3f(P[1][0],P[1][1],P[1][2]);
|
2005-06-30 15:20:32 +02:00
|
|
|
glEnd();
|
2012-12-21 16:34:32 +01:00
|
|
|
// assert(!glGetError());
|
2005-07-11 11:04:26 +02:00
|
|
|
N[0] = N[1];
|
2005-06-30 15:20:32 +02:00
|
|
|
P[0] = P[1];
|
2005-03-03 11:48:54 +01:00
|
|
|
}
|
2005-07-11 11:04:26 +02:00
|
|
|
//glEnd();
|
2005-03-03 11:48:54 +01:00
|
|
|
}
|
2005-04-04 13:59:16 +02:00
|
|
|
if (useDisplList)
|
|
|
|
glEndList();
|
|
|
|
}
|
|
|
|
if (useDisplList)
|
|
|
|
{
|
|
|
|
glCallList(cone_List);
|
|
|
|
///I insert key and value in the map if I need
|
|
|
|
if (to_insert)
|
|
|
|
Disp_listMap.insert(std::pair<int,GLint>(slices,cone_List));
|
2005-03-03 11:48:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// draw an arrow from tail to head
|
|
|
|
/// body_width = width of the body of arrow
|
|
|
|
/// head_lenght = lenght of the head of arrow
|
|
|
|
/// head_width = width of the head of arrow
|
|
|
|
/// body_slice = number of slices on the body
|
|
|
|
/// head_slice = number of slices on the head
|
|
|
|
template <DrawMode dm>
|
2006-01-03 12:13:25 +01:00
|
|
|
static void glArrow(Point3f tail, Point3f head,float body_width,float head_lenght,
|
|
|
|
float head_width,int body_slice=10,int head_slice=10,bool useDisplList=true)
|
2005-03-03 11:48:54 +01:00
|
|
|
{
|
2005-05-19 11:09:54 +02:00
|
|
|
if (tail!=head)
|
|
|
|
{
|
|
|
|
//assert(!glGetError());
|
2006-01-03 12:13:25 +01:00
|
|
|
Matrix44f tr;
|
2005-05-19 11:09:54 +02:00
|
|
|
XAxis(tail,head,tr);
|
|
|
|
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
|
|
SetGLParameters(dm);
|
|
|
|
glPushMatrix();
|
2006-01-03 12:13:25 +01:00
|
|
|
glMultMatrixf(&tr[0][0]);
|
|
|
|
vcg::Point3f Direct=(head-tail);
|
2012-12-21 16:34:32 +01:00
|
|
|
if(body_width == 0) body_width = Direct.Norm()/40.0f;
|
|
|
|
if(head_lenght == 0) head_lenght = Direct.Norm()/5.0f;
|
|
|
|
if(head_width == 0) head_width = Direct.Norm()/15.0f;
|
2006-01-03 12:13:25 +01:00
|
|
|
float l_body=Direct.Norm()-head_lenght;
|
2005-05-19 11:09:54 +02:00
|
|
|
glPushMatrix();
|
2008-06-23 16:33:51 +02:00
|
|
|
//glTranslate(vcg::Point3f(tail.Norm(),0,0));
|
2005-05-19 11:09:54 +02:00
|
|
|
Cylinder(body_slice,l_body,body_width,useDisplList);
|
|
|
|
glPopMatrix();
|
2006-01-03 12:13:25 +01:00
|
|
|
glTranslate(vcg::Point3f(l_body,0,0));
|
2005-05-19 11:09:54 +02:00
|
|
|
Cone(head_slice,head_lenght,head_width,useDisplList);
|
|
|
|
glPopMatrix();
|
|
|
|
//assert(!glGetError());
|
|
|
|
glPopAttrib();
|
|
|
|
//assert(!glGetError());
|
|
|
|
}
|
2005-03-03 11:48:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// draw a cone from tail to head
|
|
|
|
/// width = width of the base of the cone
|
|
|
|
/// slice = number of slices on the cone
|
|
|
|
template <DrawMode dm>
|
2006-01-03 12:13:25 +01:00
|
|
|
static void glCone(Point3f tail, Point3f head,float width,int slice=10,bool useDisplList=true)
|
2005-03-03 11:48:54 +01:00
|
|
|
{
|
2005-05-19 11:09:54 +02:00
|
|
|
if (tail!=head)
|
|
|
|
{
|
2006-03-29 09:54:03 +02:00
|
|
|
Matrix44f tr;
|
2005-05-19 11:09:54 +02:00
|
|
|
XAxis(tail,head,tr);
|
|
|
|
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
|
|
SetGLParameters(dm);
|
|
|
|
glPushMatrix();
|
2006-01-03 12:13:25 +01:00
|
|
|
glMultMatrixf(&tr[0][0]);
|
|
|
|
vcg::Point3f Direct=(head-tail);
|
|
|
|
float l_body=Direct.Norm();
|
2008-06-23 16:33:51 +02:00
|
|
|
//glTranslate(vcg::Point3f(tail.Norm(),0,0));
|
2005-05-19 11:09:54 +02:00
|
|
|
Cone(slice,l_body,width,useDisplList);
|
|
|
|
glPopMatrix();
|
|
|
|
glPopAttrib();
|
|
|
|
}
|
2005-03-03 11:48:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// draw a cylinder from tail to head
|
|
|
|
/// width = width of the base of the cylinder
|
|
|
|
/// slice = number of slices on the cylinder
|
|
|
|
template <DrawMode dm>
|
2006-01-03 12:13:25 +01:00
|
|
|
static void glCylinder(Point3f tail, Point3f head,float width,int slice=10,bool useDisplList=true)
|
2005-03-03 11:48:54 +01:00
|
|
|
{
|
2005-05-19 11:09:54 +02:00
|
|
|
if (tail!=head)
|
|
|
|
{
|
2006-01-03 12:13:25 +01:00
|
|
|
Matrix44f tr;
|
2005-05-19 11:09:54 +02:00
|
|
|
XAxis(tail,head,tr);
|
|
|
|
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
|
|
SetGLParameters(dm);
|
|
|
|
glPushMatrix();
|
2006-01-03 12:13:25 +01:00
|
|
|
glMultMatrixf(&tr[0][0]);
|
|
|
|
vcg::Point3f Direct=(head-tail);
|
|
|
|
float l_body=Direct.Norm();
|
2008-06-23 16:33:51 +02:00
|
|
|
//glTranslate(vcg::Point3f(tail.Norm(),0,0));
|
2005-05-19 11:09:54 +02:00
|
|
|
Cylinder(slice,l_body,width,useDisplList);
|
|
|
|
glPopMatrix();
|
|
|
|
glPopAttrib();
|
|
|
|
}
|
|
|
|
|
2005-03-03 11:48:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// draw a point in Center
|
|
|
|
/// size = Radius of the point
|
|
|
|
/// slices = The number of subdivisions around the Z axis (similar to lines of longitude).
|
|
|
|
/// stacks = The number of subdivisions along the Z axis (similar to lines of latitude).
|
|
|
|
template <DrawMode dm>
|
|
|
|
static void glPoint(vcg::Point3f Center,float size,int slices =16,int stacks =16)
|
|
|
|
{
|
2005-05-19 11:09:54 +02:00
|
|
|
if (size!=0){
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslate(Center);
|
|
|
|
if (dm==DMWire)
|
|
|
|
glutWireSphere(size,slices,stacks);
|
2005-03-03 11:48:54 +01:00
|
|
|
else
|
2005-05-19 11:09:54 +02:00
|
|
|
if (dm==DMSolid)
|
|
|
|
glutSolidSphere(size,slices,stacks);
|
|
|
|
else
|
|
|
|
glutSolidSphere(size,slices,stacks);
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
2005-03-03 11:48:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// draw a point in Center
|
|
|
|
/// size = Radius of the point
|
|
|
|
/// slices = The number of subdivisions around the Z axis (similar to lines of longitude).
|
|
|
|
/// stacks = The number of subdivisions along the Z axis (similar to lines of latitude).
|
|
|
|
template <DrawMode dm>
|
2006-01-03 12:13:25 +01:00
|
|
|
static void glDiamond (Point3f Center, float size,bool useDisplList=true)
|
2005-03-03 11:48:54 +01:00
|
|
|
{
|
2005-05-19 11:09:54 +02:00
|
|
|
if (size!=0){
|
|
|
|
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
|
|
SetGLParameters(dm);
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslated(Center[0],Center[1],Center[2]);
|
|
|
|
Diamond(size,useDisplList);
|
|
|
|
glPopMatrix();
|
|
|
|
glPopAttrib();
|
|
|
|
}
|
2005-03-03 11:48:54 +01:00
|
|
|
}
|
|
|
|
};
|
2005-04-04 13:59:16 +02:00
|
|
|
}
|
2005-12-06 15:11:15 +01:00
|
|
|
#endif
|