gl_aaboundingbox.h 1.37 KB
#ifndef STIM_GL_AABB
#define STIM_GL_AABB

#include <stim/visualization/aaboundingbox.h>
#include <GL/gl.h>

namespace stim{

template <typename T>
class gl_aaboundingbox : public aaboundingbox<T>{

public:

	using stim::aaboundingbox<T>::A;
	using stim::aaboundingbox<T>::B;

	//default constructor
	gl_aaboundingbox() : stim::aaboundingbox<T>(){}

	//constructor takes an AABB
	gl_aaboundingbox(stim::aaboundingbox<T> b) : stim::aaboundingbox<T>(b){}


	/// Specifies vertices of the bounding box using CW winding. Use GL_LINE_LOOP for wireframe or GL_QUADS for a solid.
	void glWire(){

		//front plane (in A[2])
		glBegin(GL_LINE_LOOP);
			glVertex3f(A[0], A[1], A[2]);
			glVertex3f(A[0], B[1], A[2]);
			glVertex3f(B[0], B[1], A[2]);
			glVertex3f(B[0], A[1], A[2]);
		glEnd();

		//back plane (in B[2])
		glBegin(GL_LINE_LOOP);
			glVertex3f(B[0], B[1], B[2]);
			glVertex3f(A[0], B[1], B[2]);
			glVertex3f(A[0], A[1], B[2]);			
			glVertex3f(B[0], A[1], B[2]);
		glEnd();

		//fill out the rest of the lines to connect the two faces
		glBegin(GL_LINES);
			glVertex3f(A[0], B[1], A[2]);
			glVertex3f(A[0], B[1], B[2]);
			glVertex3f(B[0], B[1], B[2]);
			glVertex3f(B[0], B[1], A[2]);
			glVertex3f(B[0], A[1], A[2]);
			glVertex3f(B[0], A[1], B[2]);
			glVertex3f(A[0], A[1], B[2]);
			glVertex3f(A[0], A[1], A[2]);
		glEnd();

	}


};		//end stim::gl_aabb


};		//end namespace stim

#endif