Struct Object3D¶
Defined in File Object3D.hpp
Struct Documentation¶
-
struct Object3D¶
Represents a 3D object loaded from a file, containing geometry and mesh data.
The Object3D class is responsible for parsing 3D model files (such as .obj), temporarily storing vertex data (positions, texture coordinates, normals), and managing sub-objects and meshes. It provides functionality to draw the object using a given shader program and transformation matrices.
Public Functions
-
Object3D() = default¶
Constructs an Object3D from an OBJ file.
Loads a 3D object from the given file path, initializing its geometry, textures, and other relevant data required for rendering.
- Parameters:
path – The file system path to the 3D object file to load.
- Throws:
std::runtime_error – if the file cannot be opened or parsed.
-
bool Init(const std::string &path)¶
-
void Draw(ShaderProgram &shader, Camera &camera) const¶
Renders the 3D object using the provided shader and transformation matrices.
Iterates through all meshes associated with this Object3D instance and calls their Draw method, passing the shader program and the model, view, and projection matrices.
- Parameters:
shader – Reference to the ShaderProgram used for rendering.
view – The view matrix representing the camera’s transformation.
proj – The projection matrix defining the camera’s lens. (screen space)
Sets the texture for a specific mesh in the object.
This function updates the texture of a mesh identified by its ID within the object.
- Parameters:
meshID – The ID of the mesh to update.
t – A shared pointer to the Texture to be applied to the mesh.
- Throws:
std::out_of_range – if the meshID is invalid.
-
inline void SetPosition(const glm::vec3 &pos)¶
Sets the position of the object in 3D space.
Updates the model matrix by applying a translation transformation based on the given position vector.
- Parameters:
pos – The new position as a glm::vec3.
-
inline void Translate(const glm::vec3 &pos)¶
Translates the object by the given position vector.
Applies a translation transformation to the object’s model matrix using the specified position vector.
- Parameters:
pos – The translation vector to apply to the object’s position.
-
inline void SetRotation(float angle, const glm::vec3 &axis)¶
Sets the rotation of the object around a specified axis.
This function applies a rotation transformation to the object’s model matrix, rotating it by the given angle (in degrees) around the provided axis.
- Parameters:
angle – The angle of rotation in degrees.
axis – The axis to rotate around, represented as a glm::vec3.
-
inline void SetScale(const glm::vec3 &scale)¶
Sets the scale of the object by applying a scaling transformation to the model matrix.
- Parameters:
scale – A glm::vec3 representing the scaling factors along the x, y, and z axes.
Public Members
-
glm::mat4 modelMatrix = glm::mat4(1.0)¶
4x4 transformation matrix representing the model’s local transformations.
This matrix is used to apply translation, rotation, and scaling to the 3D object in world space. It is initialized as the identity matrix.
-
Object3D() = default¶