Geno3D
A simple 3D visualisation library, using C++/SFML.
 All Classes Functions Variables
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Geno3D::Object Class Reference

#include <Object.hpp>

Inheritance diagram for Geno3D::Object:
Geno3D::Transformable

Public Member Functions

void load (std::string str)
 
void load (std::istream &stream)
 
sf::VertexArray render (std::vector< std::unique_ptr< Light >> &lights, const std::shared_ptr< Camera > &camera, int winHeight)
 
void loadTexture (sf::Texture texture)
 
sf::Texture getTexture ()
 
bool isTextured ()
 
void translate (float x, float y, float z) override
 
void scale (float m) override
 
void rotate (float x, float y, float z) override
 
void transform (const Transformation &t) override
 

Private Member Functions

void sortFaces (const Eigen::Matrix3Xf &projected)
 Sort the mesh faces by distance from the camera so they render in the correct order.
 
void calcNormals ()
 Calculate vertex normals based on the mesh faces.
 

Private Attributes

sf::Texture texture
 The texture to render with, if any.
 
bool textured
 Has the object been textured.
 
Eigen::Matrix3Xf verts
 The vertices of the object as points in 3D space.
 
std::vector< sf::Vector2f > uvMap
 A list of normalised UV points to map the texture to the mesh.
 
std::vector< sf::Vector2f > uvTexMap
 A list of scaled points to map this object's texture to the mesh.
 
std::vector< Eigen::Vector3i > faces
 A list of faces made up of three vertices to use.
 
Eigen::Matrix3Xf normals
 The object's vertex normals.
 
std::vector< Eigen::Vector3i > texCoords
 A list of which UVs to use for each face.
 

Detailed Description

This class holds data about a 3D mesh. Provides utilities to load a mesh from an obj file.

Member Function Documentation

sf::Texture Geno3D::Object::getTexture ( )
inline

Retrieve the current texture of the object.

See Also
loadTexture()
isTextured()

References texture.

bool Geno3D::Object::isTextured ( )
inline

Check if a texture is loaded.

See Also
loadTexture()
getTexture()

References textured.

void Geno3D::Object::load ( std::string  str)

Load the mesh from a string in the format of an obj file.

Parameters
strthe string to parse
See Also
load(std::istream&)
void Geno3D::Object::load ( std::istream &  stream)

Load the mesh from a stream in the format of an obj file.

Parameters
streamthe stream to load
See Also
load(std::string)

References calcNormals(), faces, texCoords, uvMap, and verts.

void Geno3D::Object::loadTexture ( sf::Texture  texture)

Load a texture into the object. This marks the object as being textured so isTextured will return true if this function has been called.

Parameters
texturethe texture to load
See Also
getTexture()
isTextured()

References texture, textured, uvMap, and uvTexMap.

sf::VertexArray Geno3D::Object::render ( std::vector< std::unique_ptr< Light >> &  lights,
const std::shared_ptr< Camera > &  camera,
int  winHeight 
)

Render the object as an SFML shape. Uses lighting and camera information to generate an sf::VertexArray object which can be rendered to a window.

Parameters
lightsa list of the lights in a scene
camerathe camera to use for the render
winHeightthe height of the window. Used to flip the image y-axis so the render is not inverted.
See Also
Light
Camera

References faces, normals, sortFaces(), texCoords, textured, uvTexMap, and verts.

void Geno3D::Object::rotate ( float  x,
float  y,
float  z 
)
overridevirtual

Rotate by Euler angles, in radians.

Parameters
xthe angle to rotate by about the x-axis
ythe angle to rotate by about the y-axis
zthe angle to rotate by about the z-axis

Implements Geno3D::Transformable.

References normals, and verts.

void Geno3D::Object::scale ( float  m)
overridevirtual

Scale by a factor.

Parameters
mthe factor to scale by

Implements Geno3D::Transformable.

References verts.

void Geno3D::Object::transform ( const Transformation t)
overridevirtual

Transform by a compound transformation.

Parameters
tthe transformation to apply

Implements Geno3D::Transformable.

References Geno3D::Transformation::apply(), Geno3D::Transformation::determinant(), normals, and verts.

void Geno3D::Object::translate ( float  x,
float  y,
float  z 
)
overridevirtual

Translate by a 3D vector.

Parameters
xthe amount to translate in the x-axis
ythe amount to translate in the y-axis
zthe amount to translate in the z-axis

Implements Geno3D::Transformable.

References verts.


The documentation for this class was generated from the following files: