gl_matrices.h 3.06 KB
Newer Older
1 2 3
/*******************************************************************************
 * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
 * version 0.1                                                                  *
4
 * Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *                                                                              *
 * This library is free software; you can redistribute it and/or modify it      *
 * under the terms of the GNU Lesser General Public License as published by the *
 * Free Software Foundation; either version 2.1 of the License, or (at your     *
 * option) any later version.                                                   *
 *                                                                              *
 * This library 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 Lesser General Public License  *
 * for more details.                                                            *
 *                                                                              *
 * You should have received a copy of the GNU Lesser General Public License     *
 * along with this library; if not, write to the Free Software Foundation,      *
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
 *                                                                              *
20
 * Web site: http://cgogn.unistra.fr/                                           *
21 22 23 24 25 26 27 28 29
 * Contact information: cgogn@unistra.fr                                        *
 *                                                                              *
 *******************************************************************************/


#ifndef __GL_MATRICES_H_
#define __GL_MATRICES_H_

#include "glm/glm.hpp"
Sylvain Thery's avatar
Sylvain Thery committed
30
#include "glm/gtc/matrix_transform.hpp"
31
#include <stack>
Sylvain Thery's avatar
Sylvain Thery committed
32
#include "Geometry/vector_gen.h"
33 34 35 36 37 38 39 40 41

namespace CGoGN
{
namespace Utils
{

class GL_Matrices
{
public:
Sylvain Thery's avatar
Sylvain Thery committed
42 43
	/// 0: projection / 1: modelView /2: transfo / 3:PMV /4:normal
	glm::mat4 m_matrices[5];
44 45 46
	/// stack of transfo matrix
	std::stack<glm::mat4> m_stack;

Sylvain Thery's avatar
Sylvain Thery committed
47 48 49 50 51 52 53 54
public:
	void pushTransfo()
	{
		m_stack.push(m_matrices[2]);
	}

	void popTransfo()
	{
Sylvain Thery's avatar
Sylvain Thery committed
55 56
		if (m_stack.empty())
			return;
Sylvain Thery's avatar
Sylvain Thery committed
57 58 59 60
		m_matrices[2] = m_stack.top();
		m_stack.pop();
	}

Sylvain Thery's avatar
Sylvain Thery committed
61 62 63 64 65 66
	const glm::mat4&  getTransfo() const
	{
		return m_matrices[2];
	}

	glm::mat4& getTransfo()
Sylvain Thery's avatar
Sylvain Thery committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
	{
		return m_matrices[2];
	}

	void rotate(float angle, const Geom::Vec3f& Axis)
	{
		m_matrices[2] = glm::rotate(m_matrices[2], angle, glm::vec3(Axis[0],Axis[1],Axis[2]));
	}

	void translate(const Geom::Vec3f& P)
	{
		m_matrices[2] = glm::translate(m_matrices[2], glm::vec3(P[0],P[1],P[2]));
	}

	void scale(const Geom::Vec3f& S)
	{
		m_matrices[2] = glm::scale(m_matrices[2], glm::vec3(S[0],S[1],S[2]));
	}

	void scale(float s)
	{
		m_matrices[2] = glm::scale(m_matrices[2], glm::vec3(s,s,s));
	}

Sylvain Thery's avatar
Sylvain Thery committed
91 92 93 94 95 96
	void apply (const glm::mat4& m)
	{
		m_matrices[2] = m * m_matrices[2];

	}

97 98 99 100 101 102 103
};


}
}

#endif