[go: up one dir, main page]

Menu

[e79954]: / media / Model.h  Maximize  Restore  History

Download this file

102 lines (84 with data), 2.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
// Obj - obj-format objects
//
// Copyright (C) 2015 Sam Varner
//
// This file is part of Vamos Automotive Simulator.
//
// Vamos 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 3 of the License, or
// (at your option) any later version.
//
// Vamos 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 for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vamos. If not, see <http://www.gnu.org/licenses/>.
#ifndef _MODEL_H_
#define _MODEL_H_
#include "../geometry/Three_Vector.h"
#include <GL/gl.h>
#include <assimp/scene.h>
#include <assimp/Importer.hpp>
#include <boost/filesystem.hpp>
#include <exception>
#include <string>
#include <map>
namespace fs = boost::filesystem;
class aiMaterial;
class aiNode;
namespace Vamos_Media
{
class Model_Exception : public std::exception
{
public:
Model_Exception (std::string message) : m_message (message) {};
virtual ~Model_Exception () throw () {};
virtual const char* what () const throw () { return m_message.c_str (); }
private:
std::string m_message;
};
class Model_Cant_Convert_Image : Model_Exception
{
public:
Model_Cant_Convert_Image (std::string path)
: Model_Exception ("Can't convert image in file '" + path + "'")
{}
};
class Model_Cant_Load_Image : Model_Exception
{
public:
Model_Cant_Load_Image (std::string path)
: Model_Exception ("Can't load image from file '" + path + "'")
{}
};
class Model
{
public:
Model (const std::string& file,
double scale,
const Vamos_Geometry::Three_Vector& translation,
const Vamos_Geometry::Three_Vector& rotation,
bool two_sided = false);
~Model ();
/// Render the object in a display list.
/// @return the display list.
GLuint build ();
private:
boost::filesystem::path m_file;
void load_textures ();
void render (const aiNode* nd);
void apply_material (const aiMaterial& material);
Assimp::Importer m_importer;
const aiScene* mp_object;
GLuint* mp_texture_ids;
std::map <std::string, GLuint*> m_texture_id_map;
double m_scale;
Vamos_Geometry::Three_Vector m_translation;
Vamos_Geometry::Three_Vector m_rotation;
bool m_two_sided;
};
}
#endif // not _MODEL_H_