Geno3D
A simple 3D visualisation library, using C++/SFML.
 All Classes Functions Variables
Object.hpp
1 #pragma once
2 
3 #include <iostream>
4 #include <SFML/Graphics.hpp>
5 #include <eigen3/Eigen/Dense>
6 #include <vector>
7 #include <string>
8 #include <memory>
9 #include "Light.hpp"
10 #include "Camera.hpp"
11 #include "Transformable.hpp"
12 
13 namespace Geno3D
14 {
19  class Object : public Transformable {
20  public:
21  Object() : textured(false) {};
27  void load(std::string str);
33  void load(std::istream& stream);
45  sf::VertexArray render(
46  std::vector<std::unique_ptr<Light>>& lights,
47  const std::shared_ptr<Camera>& camera,
48  int winHeight
49  );
58  void loadTexture(sf::Texture texture);
64  sf::Texture getTexture() { return texture; }
70  bool isTextured() { return textured; }
71  // Transformable
72  void translate(float x, float y, float z) override;
73  void scale(float m) override;
74  void rotate(float x, float y, float z) override;
75  void transform(const Transformation& t) override;
76  private:
78  void sortFaces(const Eigen::Matrix3Xf& projected);
80  void calcNormals();
82  sf::Texture texture;
84  bool textured;
86  Eigen::Matrix3Xf verts;
88  std::vector<sf::Vector2f> uvMap;
90  std::vector<sf::Vector2f> uvTexMap;
92  std::vector<Eigen::Vector3i> faces;
94  Eigen::Matrix3Xf normals;
96  std::vector<Eigen::Vector3i> texCoords;
97  };
98 }
Eigen::Matrix3Xf verts
The vertices of the object as points in 3D space.
Definition: Object.hpp:86
void loadTexture(sf::Texture texture)
Definition: Object.cpp:111
sf::Texture getTexture()
Definition: Object.hpp:64
sf::VertexArray render(std::vector< std::unique_ptr< Light >> &lights, const std::shared_ptr< Camera > &camera, int winHeight)
Definition: Object.cpp:85
Eigen::Matrix3Xf normals
The object's vertex normals.
Definition: Object.hpp:94
Definition: Transformation.hpp:12
std::vector< sf::Vector2f > uvMap
A list of normalised UV points to map the texture to the mesh.
Definition: Object.hpp:88
void load(std::string str)
Definition: Object.cpp:49
bool textured
Has the object been textured.
Definition: Object.hpp:84
void rotate(float x, float y, float z) override
Definition: Object.cpp:126
Definition: Object.hpp:19
void translate(float x, float y, float z) override
Definition: Object.cpp:121
std::vector< Eigen::Vector3i > texCoords
A list of which UVs to use for each face.
Definition: Object.hpp:96
void sortFaces(const Eigen::Matrix3Xf &projected)
Sort the mesh faces by distance from the camera so they render in the correct order.
Definition: Object.cpp:54
void scale(float m) override
Definition: Object.cpp:135
std::vector< sf::Vector2f > uvTexMap
A list of scaled points to map this object's texture to the mesh.
Definition: Object.hpp:90
std::vector< Eigen::Vector3i > faces
A list of faces made up of three vertices to use.
Definition: Object.hpp:92
void calcNormals()
Calculate vertex normals based on the mesh faces.
Definition: Object.cpp:67
void transform(const Transformation &t) override
Definition: Object.cpp:62
bool isTextured()
Definition: Object.hpp:70
sf::Texture texture
The texture to render with, if any.
Definition: Object.hpp:82
Definition: Transformable.hpp:9