ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
ObjectAlign Class Reference

Handles aligning and transforming 3D objects to fit within specified 2D camera bounds. More...

#include <ObjectAlign.h>

Collaboration diagram for ObjectAlign:

Public Types

enum  Justification {
  UpperLeft , UpperMiddle , UpperRight , MiddleLeft ,
  Middle , MiddleRight , LowerLeft , LowerMiddle ,
  LowerRight , Stretch
}
 Describes how the object(s) should be justified within the bounding box. More...
 

Public Member Functions

 ObjectAlign (Vector2D camMin, Vector2D camMax, Quaternion targetOrientation=Quaternion())
 Constructor for ObjectAlign, setting up the camera bounds and orientation.
 
Vector3D GetCentroid (Object3D *obj)
 Computes the centroid of the given object's geometry.
 
Vector3D GetCentroid (Object3D **objs, uint8_t numObjects)
 Computes the collective centroid of multiple objects.
 
Vector3D GetObjectCenter (Object3D *obj)
 Computes the "center" of a single object. Generally the same as centroid, but could be defined differently if an object's pivot or bounding logic is distinct.
 
Vector3D GetObjectCenter (Object3D **objs, uint8_t numObjects)
 Computes the collective center for multiple objects.
 
Vector3D GetObjectSize (Object3D *obj)
 Retrieves the bounding box size (width, height, depth) of a single object.
 
Vector3D GetObjectSize (Object3D **objs, uint8_t numObjects)
 Computes the combined bounding box size for multiple objects.
 
Quaternion GetPlaneNormal (Object3D *obj)
 Determines the plane normal (as a Quaternion) of the object based on its geometry.
 
Quaternion GetPlaneNormal (Object3D **objs, uint8_t numObjects)
 Determines the average plane normal (as a Quaternion) for multiple objects.
 
Quaternion GetPlaneOrientation (Object3D *obj, Vector3D centroid)
 Calculates the orientation needed to make the object's plane face the camera or align with a given centroid.
 
Quaternion GetPlaneOrientation (Object3D **objs, uint8_t numObjects, Vector3D centroid)
 Calculates the orientation needed for multiple objects to share a consistent plane.
 
Transform GetTransform (Object3D *obj)
 Computes the final Transform for aligning a single Object3D within the camera bounds.
 
Transform GetTransform (Object3D **objs, uint8_t numObjects)
 Computes the final Transform for aligning multiple objects as a group.
 
float GetObjectPlanarityRatio (Object3D *obj)
 Computes how planar (flat) a single object is, typically as a ratio (0.0 = not planar, 1.0 = perfectly planar).
 
float GetObjectPlanarityRatio (Object3D **objs, uint8_t numObjects)
 Computes an average planarity ratio for multiple objects.
 
void SetPlaneOffsetAngle (float offsetPlaneAngle)
 Sets the additional rotation offset (plane offset angle), in degrees or radians, that will be applied when calculating plane orientation.
 
void SetEdgeMargin (float edgeMargin)
 Sets the margin to keep from the edges when aligning objects.
 
void SetForwardVector (Vector3D forwardVector)
 Sets the forward vector, i.e., which axis is considered "forward" for the alignment logic.
 
void SetCameraMin (Vector2D camMin)
 Updates the minimum bounds for the 2D camera region.
 
void SetCameraMax (Vector2D camMax)
 Updates the maximum bounds for the 2D camera region.
 
void SetMirrorX (bool mirrorX)
 Enables or disables mirroring along the X-axis for the aligned objects.
 
void SetMirrorY (bool mirrorY)
 Enables or disables mirroring along the Y-axis for the aligned objects.
 
void SetJustification (Justification jst)
 Sets the justification mode for alignment.
 
void SetScale (float scaleX, float scaleY)
 Sets the scaling factors that will be applied to objects during alignment.
 
void AlignObjectNoScale (Object3D *obj)
 Aligns a single Object3D within the camera bounds without applying the object's scaling factor.
 
void AlignObjectsNoScale (Object3D **objs, uint8_t numObjects)
 Aligns multiple objects without applying the object's scaling factor.
 
void AlignObject (Object3D *obj)
 Aligns a single Object3D within the camera bounds, including applying scale factors as necessary.
 
void AlignObjects (Object3D **objs, uint8_t numObjects)
 Aligns multiple objects within the camera bounds, including scale factors.
 

Private Member Functions

void NormalizeObjectPlane (Object3D **objs, uint8_t numObjects, Vector3D center, Quaternion planeOrientation)
 Normalizes the orientation of multiple objects onto a plane.
 
void NormalizeObjectCenter (Object3D **objs, uint8_t numObjects, Vector3D center)
 Translates the center of multiple objects so that their average center matches the specified center.
 

Private Attributes

Justification jst = Middle
 Current justification mode.
 
Quaternion targetOrientation
 Target orientation for aligning the object(s).
 
Vector3D forwardVector = Vector3D(0.0f, 0.0f, 1.0f)
 Default "forward" axis.
 
Vector2D cameraCenter
 Computed center between camMin and camMax.
 
Vector2D camMin
 Minimum 2D camera bounds (lower-left).
 
Vector2D camMax
 Maximum 2D camera bounds (upper-right).
 
float offsetPlaneAngle = 0.0f
 Additional rotation offset (plane offset angle in degrees or radians).
 
float edgeMargin = 10.0f
 Margin from the bounding edges, in screen-space units.
 
float scaleX = 1.0f
 Scaling factor on the X-axis.
 
float scaleY = 1.0f
 Scaling factor on the Y-axis.
 
bool mirrorX = false
 Whether to mirror objects along the X-axis.
 
bool mirrorY = false
 Whether to mirror objects along the Y-axis.
 

Detailed Description

Handles aligning and transforming 3D objects to fit within specified 2D camera bounds.

This class is primarily concerned with projecting objects into a plane, scaling them to fit within camera bounds, and applying transformations (orientation, mirroring, edge offsets, etc.).

Definition at line 24 of file ObjectAlign.h.

Member Enumeration Documentation

◆ Justification

Describes how the object(s) should be justified within the bounding box.

For instance, LowerLeft places the object in the lower-left corner (with potential offsets), while Stretch attempts to fit or stretch objects to fill the entire area.

Enumerator
UpperLeft 

Justify to the upper-left corner of the bounding area.

UpperMiddle 

Justify to the top center of the bounding area.

UpperRight 

Justify to the upper-right corner of the bounding area.

MiddleLeft 

Justify to the middle-left side of the bounding area.

Middle 

Center the object within the bounding area.

MiddleRight 

Align to the middle-right side of the bounding area.

LowerLeft 

Justify to the lower-left corner of the bounding area.

LowerMiddle 

Align to the bottom center of the bounding area.

LowerRight 

Justify to the lower-right corner of the bounding area.

Stretch 

Attempt to scale the object(s) to fill the entire area.

Definition at line 33 of file ObjectAlign.h.

Constructor & Destructor Documentation

◆ ObjectAlign()

ObjectAlign ( Vector2D  camMin,
Vector2D  camMax,
Quaternion  targetOrientation = Quaternion() 
)

Constructor for ObjectAlign, setting up the camera bounds and orientation.

Parameters
camMinThe lower-left corner of the 2D camera region.
camMaxThe upper-right corner of the 2D camera region.
targetOrientationOptional desired orientation for aligned objects.

Definition at line 245 of file ObjectAlign.cpp.

References cameraCenter, camMax, camMin, and targetOrientation.

Member Function Documentation

◆ AlignObject()

void AlignObject ( Object3D obj)

Aligns a single Object3D within the camera bounds, including applying scale factors as necessary.

Parameters
objPointer to the Object3D to align.

Definition at line 396 of file ObjectAlign.cpp.

References AlignObjects().

Referenced by ProtogenProject::AlignObject(), ProtogenProject::AlignObjectFace(), and ProtogenProject::AlignObjectRear().

◆ AlignObjectNoScale()

void AlignObjectNoScale ( Object3D obj)

Aligns a single Object3D within the camera bounds without applying the object's scaling factor.

Only transforms the object to fit in the plane (translation + orientation); no scaling from the object itself.

Parameters
objPointer to the Object3D to align.

Definition at line 370 of file ObjectAlign.cpp.

References AlignObjectsNoScale().

Referenced by ProtogenProject::AlignObjectNoScale(), ProtogenProject::AlignObjectNoScaleFace(), ProtogenProject::AlignObjectNoScaleRear(), and TamamoAnimation::Update().

◆ AlignObjects()

◆ AlignObjectsNoScale()

void AlignObjectsNoScale ( Object3D **  objs,
uint8_t  numObjects 
)

◆ GetCentroid() [1/2]

Vector3D GetCentroid ( Object3D **  objs,
uint8_t  numObjects 
)

Computes the collective centroid of multiple objects.

Parameters
objsArray of pointers to Object3D objects.
numObjectsNumber of objects in objs.
Returns
A Vector3D representing the combined centroid of all objects.

Definition at line 14 of file ObjectAlign.cpp.

References Object3D::GetTriangleGroup(), and ITriangleGroup::GetVertices().

◆ GetCentroid() [2/2]

Vector3D GetCentroid ( Object3D obj)

Computes the centroid of the given object's geometry.

Parameters
objPointer to the Object3D.
Returns
A Vector3D representing the centroid position.

Definition at line 3 of file ObjectAlign.cpp.

References GetCentroid().

Referenced by AlignObjects(), AlignObjectsNoScale(), GetCentroid(), GetObjectPlanarityRatio(), and GetTransform().

◆ GetObjectCenter() [1/2]

Vector3D GetObjectCenter ( Object3D **  objs,
uint8_t  numObjects 
)

Computes the collective center for multiple objects.

Parameters
objsArray of pointers to Object3D.
numObjectsNumber of objects in objs.
Returns
A Vector3D representing the combined center of all objects.

Definition at line 41 of file ObjectAlign.cpp.

References Object3D::GetTriangleGroup(), ITriangleGroup::GetVertices(), Vector3D::Max(), and Vector3D::Min().

◆ GetObjectCenter() [2/2]

Vector3D GetObjectCenter ( Object3D obj)

Computes the "center" of a single object. Generally the same as centroid, but could be defined differently if an object's pivot or bounding logic is distinct.

Parameters
objPointer to the Object3D.
Returns
The object's center as a Vector3D.

Definition at line 30 of file ObjectAlign.cpp.

References GetObjectCenter().

Referenced by AlignObjects(), AlignObjectsNoScale(), GetObjectCenter(), and GetTransform().

◆ GetObjectPlanarityRatio() [1/2]

float GetObjectPlanarityRatio ( Object3D **  objs,
uint8_t  numObjects 
)

Computes an average planarity ratio for multiple objects.

Parameters
objsArray of pointers to Object3D.
numObjectsNumber of objects in objs.
Returns
A float representing the combined or averaged planarity ratio.

Definition at line 121 of file ObjectAlign.cpp.

References Vector3D::Absolute(), GetCentroid(), GetPlaneOrientation(), Object3D::GetTriangleGroup(), ITriangleGroup::GetVertexCount(), ITriangleGroup::GetVertices(), Mathematics::Min(), Quaternion::RotateVector(), Vector3D::X, Vector3D::Y, and Vector3D::Z.

◆ GetObjectPlanarityRatio() [2/2]

float GetObjectPlanarityRatio ( Object3D obj)

Computes how planar (flat) a single object is, typically as a ratio (0.0 = not planar, 1.0 = perfectly planar).

Parameters
objPointer to the Object3D.
Returns
A float representing the planarity ratio.

Definition at line 109 of file ObjectAlign.cpp.

References GetObjectPlanarityRatio().

Referenced by GetObjectPlanarityRatio().

◆ GetObjectSize() [1/2]

Vector3D GetObjectSize ( Object3D **  objs,
uint8_t  numObjects 
)

Computes the combined bounding box size for multiple objects.

Parameters
objsArray of pointers to Object3D.
numObjectsNumber of objects in objs.
Returns
A Vector3D representing the bounding box that encloses all objects.

Definition at line 67 of file ObjectAlign.cpp.

References Object3D::GetTriangleGroup(), ITriangleGroup::GetVertices(), Vector3D::Max(), and Vector3D::Min().

◆ GetObjectSize() [2/2]

Vector3D GetObjectSize ( Object3D obj)

Retrieves the bounding box size (width, height, depth) of a single object.

Parameters
objPointer to the Object3D.
Returns
A Vector3D whose components represent the bounding box dimensions.

Definition at line 56 of file ObjectAlign.cpp.

References GetObjectSize().

Referenced by AlignObjects(), GetObjectSize(), and GetTransform().

◆ GetPlaneNormal() [1/2]

Quaternion GetPlaneNormal ( Object3D **  objs,
uint8_t  numObjects 
)

Determines the average plane normal (as a Quaternion) for multiple objects.

Parameters
objsArray of pointers to Object3D.
numObjectsNumber of objects in objs.
Returns
A Quaternion representing the average plane orientation.

Definition at line 158 of file ObjectAlign.cpp.

References Vector3D::Absolute(), EulerConstants::EulerOrderXYZS, Rotation::GetQuaternion(), Object3D::GetTriangleGroup(), ITriangleGroup::GetTriangles(), Triangle3D::Normal(), offsetPlaneAngle, and Vector3D::UnitSphere().

◆ GetPlaneNormal() [2/2]

Quaternion GetPlaneNormal ( Object3D obj)

Determines the plane normal (as a Quaternion) of the object based on its geometry.

This might be computed from the surface normal if the object is considered planar, or from an average of normals if the object is more complex.

Parameters
objPointer to the Object3D.
Returns
A Quaternion representing the plane's orientation (normal).

Definition at line 147 of file ObjectAlign.cpp.

References GetPlaneNormal().

Referenced by AlignObjectsNoScale(), and GetPlaneNormal().

◆ GetPlaneOrientation() [1/2]

Quaternion GetPlaneOrientation ( Object3D **  objs,
uint8_t  numObjects,
Vector3D  centroid 
)

Calculates the orientation needed for multiple objects to share a consistent plane.

Parameters
objsArray of pointers to Object3D.
numObjectsNumber of objects in objs.
centroidThe computed centroid of all objects.
Returns
A Quaternion representing the plane orientation for the combined objects.

Definition at line 191 of file ObjectAlign.cpp.

References EulerConstants::EulerOrderXYZS, Rotation::GetQuaternion(), Object3D::GetTriangleGroup(), ITriangleGroup::GetVertices(), Mathematics::IsClose(), Mathematics::Max(), offsetPlaneAngle, Vector3D::UnitSphere(), Vector3D::X, Vector3D::Y, and Vector3D::Z.

◆ GetPlaneOrientation() [2/2]

Quaternion GetPlaneOrientation ( Object3D obj,
Vector3D  centroid 
)

Calculates the orientation needed to make the object's plane face the camera or align with a given centroid.

Parameters
objPointer to the Object3D.
centroidThe computed centroid of the object.
Returns
A Quaternion representing the orientation for that plane.

Definition at line 180 of file ObjectAlign.cpp.

References GetPlaneOrientation().

Referenced by AlignObjects(), GetObjectPlanarityRatio(), GetPlaneOrientation(), and GetTransform().

◆ GetTransform() [1/2]

◆ GetTransform() [2/2]

Transform GetTransform ( Object3D obj)

Computes the final Transform for aligning a single Object3D within the camera bounds.

The Transform includes translation, rotation, and scaling as determined by the justification, margins, and plane offset angle.

Parameters
objPointer to the Object3D to align.
Returns
A Transform struct containing position, rotation, and scale.

Definition at line 292 of file ObjectAlign.cpp.

References GetTransform().

Referenced by ProtogenProject::GetAlignmentTransform(), ProtogenProject::GetAlignmentTransform(), and GetTransform().

◆ NormalizeObjectCenter()

void NormalizeObjectCenter ( Object3D **  objs,
uint8_t  numObjects,
Vector3D  center 
)
private

Translates the center of multiple objects so that their average center matches the specified center.

Parameters
objsArray of pointers to Object3D instances.
numObjectsNumber of objects in objs.
centerThe target center position in 3D space.

Definition at line 97 of file ObjectAlign.cpp.

References Object3D::GetTriangleGroup(), and ITriangleGroup::GetVertices().

Referenced by AlignObjects(), and AlignObjectsNoScale().

◆ NormalizeObjectPlane()

void NormalizeObjectPlane ( Object3D **  objs,
uint8_t  numObjects,
Vector3D  center,
Quaternion  planeOrientation 
)
private

Normalizes the orientation of multiple objects onto a plane.

This function modifies the input objects so that they are oriented parallel to a plane defined by planeOrientation, also adjusting their centers to the specified center.

Parameters
objsArray of pointers to Object3D instances.
numObjectsNumber of objects in objs.
centerDesired alignment center in 3D space.
planeOrientationOrientation (Quaternion) defining the plane normal.

Definition at line 84 of file ObjectAlign.cpp.

References Object3D::GetTriangleGroup(), ITriangleGroup::GetVertices(), and Quaternion::UnrotateVector().

Referenced by AlignObjects(), and AlignObjectsNoScale().

◆ SetCameraMax()

◆ SetCameraMin()

◆ SetEdgeMargin()

◆ SetForwardVector()

void SetForwardVector ( Vector3D  forwardVector)

Sets the forward vector, i.e., which axis is considered "forward" for the alignment logic.

Parameters
forwardVectorA Vector3D defining the forward axis.

Definition at line 260 of file ObjectAlign.cpp.

References forwardVector.

◆ SetJustification()

◆ SetMirrorX()

◆ SetMirrorY()

void SetMirrorY ( bool  mirrorY)

Enables or disables mirroring along the Y-axis for the aligned objects.

Parameters
mirrorYTrue to mirror objects on Y-axis, false to disable.

Definition at line 278 of file ObjectAlign.cpp.

References mirrorY.

Referenced by BroookAnimation::BroookAnimation().

◆ SetPlaneOffsetAngle()

◆ SetScale()

void SetScale ( float  scaleX,
float  scaleY 
)

Sets the scaling factors that will be applied to objects during alignment.

Parameters
scaleXThe multiplier for width.
scaleYThe multiplier for height.

Definition at line 286 of file ObjectAlign.cpp.

References scaleX, and scaleY.

Member Data Documentation

◆ cameraCenter

Vector2D cameraCenter
private

Computed center between camMin and camMax.

Definition at line 50 of file ObjectAlign.h.

Referenced by AlignObjects(), AlignObjectsNoScale(), GetTransform(), ObjectAlign(), SetCameraMax(), and SetCameraMin().

◆ camMax

Vector2D camMax
private

Maximum 2D camera bounds (upper-right).

Definition at line 52 of file ObjectAlign.h.

Referenced by AlignObjects(), GetTransform(), ObjectAlign(), SetCameraMax(), and SetCameraMin().

◆ camMin

Vector2D camMin
private

Minimum 2D camera bounds (lower-left).

Definition at line 51 of file ObjectAlign.h.

Referenced by AlignObjects(), GetTransform(), ObjectAlign(), SetCameraMax(), and SetCameraMin().

◆ edgeMargin

float edgeMargin = 10.0f
private

Margin from the bounding edges, in screen-space units.

Definition at line 54 of file ObjectAlign.h.

Referenced by AlignObjects(), GetTransform(), and SetEdgeMargin().

◆ forwardVector

Vector3D forwardVector = Vector3D(0.0f, 0.0f, 1.0f)
private

Default "forward" axis.

Definition at line 49 of file ObjectAlign.h.

Referenced by AlignObjects(), AlignObjectsNoScale(), GetTransform(), and SetForwardVector().

◆ jst

Justification jst = Middle
private

Current justification mode.

Definition at line 47 of file ObjectAlign.h.

Referenced by AlignObjects(), GetTransform(), and SetJustification().

◆ mirrorX

bool mirrorX = false
private

Whether to mirror objects along the X-axis.

Definition at line 57 of file ObjectAlign.h.

Referenced by AlignObjects(), AlignObjectsNoScale(), GetTransform(), and SetMirrorX().

◆ mirrorY

bool mirrorY = false
private

Whether to mirror objects along the Y-axis.

Definition at line 58 of file ObjectAlign.h.

Referenced by AlignObjects(), AlignObjectsNoScale(), GetTransform(), and SetMirrorY().

◆ offsetPlaneAngle

float offsetPlaneAngle = 0.0f
private

Additional rotation offset (plane offset angle in degrees or radians).

Definition at line 53 of file ObjectAlign.h.

Referenced by GetPlaneNormal(), GetPlaneOrientation(), and SetPlaneOffsetAngle().

◆ scaleX

float scaleX = 1.0f
private

Scaling factor on the X-axis.

Definition at line 55 of file ObjectAlign.h.

Referenced by AlignObjects(), GetTransform(), and SetScale().

◆ scaleY

float scaleY = 1.0f
private

Scaling factor on the Y-axis.

Definition at line 56 of file ObjectAlign.h.

Referenced by AlignObjects(), GetTransform(), and SetScale().

◆ targetOrientation

Quaternion targetOrientation
private

Target orientation for aligning the object(s).

Definition at line 48 of file ObjectAlign.h.

Referenced by AlignObjects(), AlignObjectsNoScale(), GetTransform(), and ObjectAlign().


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