Core Library
A simple library for handling 3D scenes
Object Class Reference

The Object class represents a 3D object. More...

#include <object.h>

Public Member Functions

 Object (std::string name)
 
void readObj (string filename)
 
Box boundingBox () const
 
const vector< Face > & faces () const
 
const vector< Vertex > & vertices () const
 
vector< Vertex > & vertices ()
 
const vector< Vector > & vertNormals () const
 
const vector< std::pair< float, float > > & vertTexCoords () const
 
void computeNormals ()
 
void computeBoundingBox ()
 
void applyGT (const QMatrix4x4 &mat)
 

Detailed Description

Each object consists of a collection of vertices and a collection of faces. Objects also store a bounding box.

Constructor & Destructor Documentation

Object::Object ( std::string  name)

Constructs an empty object.

Parameters
nameis the name of the new object.

Member Function Documentation

void Object::applyGT ( const QMatrix4x4 &  mat)

Applies geometric transform to all vertices; updates normals & bounding box.

Box Object::boundingBox ( ) const

Returns the value of the bounding box property. This property is undefined unless computeBoundingBox() has been called.

void Object::computeBoundingBox ( )

Recomputes the object bounding box.

void Object::computeNormals ( )

Recomputes per-face normals (for all faces of the object).

const vector< Face > & Object::faces ( ) const

Returns a constant reference (read-only) to the vector of faces of the object.

void Object::readObj ( string  filename)

Imports a Wavefront OBJ file as a single object. Previous faces and vertices, if any, are deleted.

This is a minimalistic parser. It can only handle polyhedral models, and then with limitations: faces with more than three sides are assumed to be convex, and are triangulated as a fan of triangles. This will give wrong results if a face is not convex. negative indices are not supported information is expected to be homogeneous (if one face has texture coordinates, for example, then every face does). it does not understand grouping or multi-object files for now, we do not use materials

const vector< Vertex > & Object::vertices ( ) const

Returns a constant reference (read-only) to the vector of vertices of the object.

vector< Vertex > & Object::vertices ( )

Returns a reference to the vector of vertices of the object. If vertices are modified, computeNormals() and computeBoundingBox() methods should be called to update per-face normals and the object's bounding box.

const vector< Vector > & Object::vertNormals ( ) const

Returns a reference to the vector of vertex normals of the object.

const vector< std::pair< float, float > > & Object::vertTexCoords ( ) const

Returns a reference to the vector of texture coordinates of the object.