diff options
| author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-11 14:15:27 -0500 | 
|---|---|---|
| committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-11 14:15:27 -0500 | 
| commit | b85a292ce06475d560bfa1195b63a8bfe211f22d (patch) | |
| tree | 463d71be55ff807513139f1de106aef6bdd7b4db /lib/tqwtplot3d/src/qwt3d_drawable.cpp | |
| parent | ce039289815e2802fdeca8d384126c807ca9cb58 (diff) | |
| download | ulab-b85a292ce06475d560bfa1195b63a8bfe211f22d.tar.gz ulab-b85a292ce06475d560bfa1195b63a8bfe211f22d.zip | |
Add 0.2.7 release of qwtplot3d for future TQt3 conversion and use
Diffstat (limited to 'lib/tqwtplot3d/src/qwt3d_drawable.cpp')
| -rw-r--r-- | lib/tqwtplot3d/src/qwt3d_drawable.cpp | 140 | 
1 files changed, 140 insertions, 0 deletions
| diff --git a/lib/tqwtplot3d/src/qwt3d_drawable.cpp b/lib/tqwtplot3d/src/qwt3d_drawable.cpp new file mode 100644 index 0000000..4025817 --- /dev/null +++ b/lib/tqwtplot3d/src/qwt3d_drawable.cpp @@ -0,0 +1,140 @@ +#include "qwt3d_drawable.h"
 +
 +using namespace Qwt3D;
 +
 +Drawable::~Drawable()
 +{
 +  detachAll();
 +}
 +
 +void Drawable::saveGLState()
 +{
 +	glGetBooleanv(GL_LINE_SMOOTH, &ls);
 +	glGetBooleanv(GL_POLYGON_SMOOTH, &pols);
 +	glGetFloatv(GL_LINE_WIDTH, &lw);
 +	glGetIntegerv(GL_BLEND_SRC, &blsrc);
 +	glGetIntegerv(GL_BLEND_DST, &bldst);
 +	glGetDoublev(GL_CURRENT_COLOR, col);
 +	glGetIntegerv(GL_LINE_STIPPLE_PATTERN, &pattern);
 +	glGetIntegerv(GL_LINE_STIPPLE_REPEAT, &factor);
 +	glGetBooleanv(GL_LINE_STIPPLE, &sallowed);
 +	glGetBooleanv(GL_TEXTURE_2D, &tex2d);
 +	glGetIntegerv(GL_POLYGON_MODE, polmode);
 +	glGetIntegerv(GL_MATRIX_MODE, &matrixmode);
 +	glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &poloffs[0]);
 +	glGetFloatv(GL_POLYGON_OFFSET_UNITS, &poloffs[1]);
 +	glGetBooleanv(GL_POLYGON_OFFSET_FILL, &poloffsfill);
 +}
 +
 +void Drawable::restoreGLState()
 +{
 +	Enable(GL_LINE_SMOOTH, ls);
 +	Enable(GL_POLYGON_SMOOTH, pols);
 +	
 +	setDeviceLineWidth(lw);
 +	glBlendFunc(blsrc, bldst);
 +	glColor4dv(col);
 +
 +	glLineStipple(factor,pattern);
 +	Enable(GL_LINE_STIPPLE,sallowed);
 +	Enable(GL_TEXTURE_2D,tex2d);
 +	glPolygonMode(polmode[0], polmode[1]);
 +	glMatrixMode(matrixmode);
 +	glPolygonOffset(poloffs[0], poloffs[1]);
 +	setDevicePolygonOffset(poloffs[0], poloffs[1]);
 +
 +	Enable(GL_POLYGON_OFFSET_FILL, poloffsfill);
 +}
 +
 +void Drawable::Enable(GLenum what, GLboolean val)
 +{
 +	if (val)
 +		glEnable(what);
 +  else
 +		glDisable(what);
 +}
 +
 +void Drawable::attach(Drawable* dr)
 +{
 +	if ( dlist.end() == std::find( dlist.begin(), dlist.end(), dr ) )
 +		if (dr)
 +		{
 +			dlist.push_back(dr);
 +		}
 +}
 +
 +void Drawable::detach(Drawable* dr)
 +{
 +	std::list<Drawable*>::iterator it = std::find(dlist.begin(), dlist.end(), dr);
 +	
 +	if ( it != dlist.end() )
 +	{
 +		dlist.erase(it);
 +	}
 +}
 +void Drawable::detachAll()
 +{
 +	dlist.clear();
 +}
 +
 +
 +//! simplified glut routine (glUnProject): windows coordinates_p --> object coordinates_p 
 +/**
 +	Don't rely on (use) this in display lists !
 +*/
 +Triple Drawable::ViewPort2World(Triple win, bool* err)
 +{
 +  Triple obj;
 +	
 +	getMatrices(modelMatrix, projMatrix, viewport);
 +	int res = gluUnProject(win.x, win.y, win.z, modelMatrix, projMatrix, viewport, &obj.x, &obj.y, &obj.z);
 +
 +	if (err)
 +		*err = (res) ? false : true;
 +	return obj;
 +}
 +
 +//! simplified glut routine (glProject): object coordinates_p --> windows coordinates_p 
 +/**
 +	Don't rely on (use) this in display lists !
 +*/
 +Triple Drawable::World2ViewPort(Triple obj,	bool* err)
 +{
 +  Triple win;
 +	
 +	getMatrices(modelMatrix, projMatrix, viewport);
 +	int res = gluProject(obj.x, obj.y, obj.z, modelMatrix, projMatrix, viewport, &win.x, &win.y, &win.z);
 +
 +	if (err)
 +		*err = (res) ? false : true;
 +	return win;
 +}
 +
 +/**
 +	Don't rely on (use) this in display lists !
 +*/
 +Triple Drawable::relativePosition(Triple rel)
 +{
 +	return ViewPort2World(Triple((rel.x-viewport[0])*viewport[2],(rel.y-viewport[1])*viewport[3],rel.z));
 +}
 +
 +void Drawable::draw()
 +{
 +	saveGLState();
 +
 +	for (std::list<Drawable*>::iterator it = dlist.begin(); it!=dlist.end(); ++it)
 +	{
 +		(*it)->draw();
 +	}
 +	restoreGLState();
 +}
 +
 +void Drawable::setColor(double r, double g, double b, double a)
 +{
 +	color = RGBA(r,g,b,a);
 +}	
 +
 +void Drawable::setColor(RGBA rgba)
 +{
 +	color = rgba;
 +}	
 | 
