16 uint16_t vertexCount = 0;
18 for (uint8_t i = 0; i < numObjects; i++) {
19 for (uint16_t j = 0; j < objs[i]->
GetTriangleGroup()->GetVertexCount(); j++) {
25 centroid = centroid / float(vertexCount);
44 for (uint8_t i = 0; i < numObjects; i++) {
45 for (uint16_t j = 0; j < objs[i]->
GetTriangleGroup()->GetVertexCount(); j++) {
53 return (max + min) / 2.0f;
70 for (uint8_t i = 0; i < numObjects; i++) {
71 for (uint16_t j = 0; j < objs[i]->
GetTriangleGroup()->GetVertexCount(); j++) {
85 for (uint8_t i = 0; i < numObjects; i++) {
86 for (uint16_t j = 0; j < objs[i]->
GetTriangleGroup()->GetVertexCount(); j++) {
89 modifiedVector = modifiedVector - center;
98 for (uint8_t i = 0; i < numObjects; i++) {
99 for (uint16_t j = 0; j < objs[i]->
GetTriangleGroup()->GetVertexCount(); j++) {
102 modifiedVector = modifiedVector - center;
126 uint16_t totalVertices = 0;
129 for (uint8_t i = 0; i < numObjects; i++) {
132 for (uint16_t j = 0; j < objs[i]->
GetTriangleGroup()->GetVertexCount(); j++) {
137 diffSum = diffSum + diffRot.
Absolute();
141 diffSum = diffSum / totalVertices;
144 return 1.0f - 1.0f / (diffSum /
Mathematics::Min(diffSum.
X, diffSum.
Y, diffSum.
Z)).AverageHighestTwoComponents();
162 for (uint8_t i = 0; i < numObjects; i++) {
163 for (uint16_t j = 0; j < objs[i]->
GetTriangleGroup()->GetTriangleCount(); j++) {
170 normal = normal / count;
192 float xx = 0.0f, xy = 0.0f, xz = 0.0f, yy = 0.0f, yz = 0.0f, zz = 0.0f;
195 for (uint8_t i = 0; i < numObjects; i++) {
196 for (uint16_t j = 0; j < objs[i]->
GetTriangleGroup()->GetVertexCount(); j++) {
210 float xD = yy * zz - yz * yz;
211 float yD = xx * zz - xz * xz;
212 float zD = xx * yy - xy * xy;
222 dir.
Y = xz * yz - xy * zz;
223 dir.
Z = xy * yz - xz * yy;
225 dir.
X = xz * yz - xy * zz;
227 dir.
Z = xy * xz - yz * xx;
229 dir.
X = xy * yz - xz * yy;
230 dir.
Y = xy * xz - yz * xx;
312 float xRatio = (cameraSize.
X -
edgeMargin) / objectSize.
X;
313 float yRatio = (cameraSize.
Y -
edgeMargin) / objectSize.
Y;
321 float xOffset = ((cameraSize.
X -
edgeMargin) - (xRatio * objectSize.
X)) / 2.0f;
322 float yOffset = ((cameraSize.
Y -
edgeMargin) - (yRatio * objectSize.
Y)) / 2.0f;
385 for (uint8_t i = 0; i < numObjects; i++) {
386 for (uint16_t j = 0; j < objs[i]->
GetTriangleGroup()->GetVertexCount(); j++) {
390 modifiedVector = modifiedVector + cameraTarget;
420 float xRatio = (cameraSize.
X -
edgeMargin) / objectSize.
X;
421 float yRatio = (cameraSize.
Y -
edgeMargin) / objectSize.
Y;
429 float xOffset = ((cameraSize.
X -
edgeMargin) - (xRatio * objectSize.
X)) / 2.0f;
430 float yOffset = ((cameraSize.
Y -
edgeMargin) - (yRatio * objectSize.
Y)) / 2.0f;
469 for (uint8_t i = 0; i < numObjects; i++) {
477 modifiedVector = modifiedVector +
Vector3D(xOffset, yOffset, 0.0f);
483 modifiedVector = modifiedVector + cameraTarget;
Provides the ObjectAlign class for aligning 3D objects within defined 2D camera bounds.
Encapsulates a 3D rotation using Euler angles and a specific order of application.
virtual Vector3D * GetVertices()=0
Retrieves the array of mutable vertices in the triangle group.
virtual int GetVertexCount()=0
Retrieves the total number of vertices in the group.
virtual Triangle3D * GetTriangles()=0
Retrieves the array of Triangle3D objects representing the triangles.
static T Min(T value1, T value2)
Returns the minimum of two values.
static bool IsClose(float v1, float v2, float epsilon)
Checks if two values are close within a specified epsilon.
static T Max(T value1, T value2)
Returns the maximum of two values.
Represents a 3D object with geometry, material, and transformation data.
ITriangleGroup * GetTriangleGroup()
Retrieves the modifiable geometry of the object.
void SetEdgeMargin(float edgeMargin)
Sets the margin to keep from the edges when aligning objects.
void AlignObjectNoScale(Object3D *obj)
Aligns a single Object3D within the camera bounds without applying the object's scaling factor.
void SetForwardVector(Vector3D forwardVector)
Sets the forward vector, i.e., which axis is considered "forward" for the alignment logic.
float scaleY
Scaling factor on the Y-axis.
float GetObjectPlanarityRatio(Object3D *obj)
Computes how planar (flat) a single object is, typically as a ratio (0.0 = not planar,...
float offsetPlaneAngle
Additional rotation offset (plane offset angle in degrees or radians).
Vector3D GetObjectSize(Object3D *obj)
Retrieves the bounding box size (width, height, depth) of a single object.
Quaternion GetPlaneNormal(Object3D *obj)
Determines the plane normal (as a Quaternion) of the object based on its geometry.
void NormalizeObjectCenter(Object3D **objs, uint8_t numObjects, Vector3D center)
Translates the center of multiple objects so that their average center matches the specified center.
Justification
Describes how the object(s) should be justified within the bounding box.
@ MiddleLeft
Justify to the middle-left side of the bounding area.
@ LowerMiddle
Align to the bottom center of the bounding area.
@ MiddleRight
Align to the middle-right side of the bounding area.
@ UpperLeft
Justify to the upper-left corner of the bounding area.
@ Stretch
Attempt to scale the object(s) to fill the entire area.
@ UpperRight
Justify to the upper-right corner of the bounding area.
@ UpperMiddle
Justify to the top center of the bounding area.
@ LowerRight
Justify to the lower-right corner of the bounding area.
@ LowerLeft
Justify to the lower-left corner of the bounding area.
Transform GetTransform(Object3D *obj)
Computes the final Transform for aligning a single Object3D within the camera bounds.
Quaternion targetOrientation
Target orientation for aligning the object(s).
void SetJustification(Justification jst)
Sets the justification mode for alignment.
ObjectAlign(Vector2D camMin, Vector2D camMax, Quaternion targetOrientation=Quaternion())
Constructor for ObjectAlign, setting up the camera bounds and orientation.
void NormalizeObjectPlane(Object3D **objs, uint8_t numObjects, Vector3D center, Quaternion planeOrientation)
Normalizes the orientation of multiple objects onto a plane.
Vector2D camMin
Minimum 2D camera bounds (lower-left).
Vector3D GetCentroid(Object3D *obj)
Computes the centroid of the given object's geometry.
bool mirrorX
Whether to mirror objects along the X-axis.
Justification jst
Current justification mode.
Vector2D cameraCenter
Computed center between camMin and camMax.
float edgeMargin
Margin from the bounding edges, in screen-space units.
void SetPlaneOffsetAngle(float offsetPlaneAngle)
Sets the additional rotation offset (plane offset angle), in degrees or radians, that will be applied...
Vector3D GetObjectCenter(Object3D *obj)
Computes the "center" of a single object. Generally the same as centroid, but could be defined differ...
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.
Quaternion GetPlaneOrientation(Object3D *obj, Vector3D centroid)
Calculates the orientation needed to make the object's plane face the camera or align with a given ce...
void SetCameraMax(Vector2D camMax)
Updates the maximum bounds for the 2D camera region.
void AlignObjects(Object3D **objs, uint8_t numObjects)
Aligns multiple objects within the camera bounds, including scale factors.
bool mirrorY
Whether to mirror objects along the Y-axis.
void SetMirrorX(bool mirrorX)
Enables or disables mirroring along the X-axis for the aligned objects.
Vector3D forwardVector
Default "forward" axis.
float scaleX
Scaling factor on the X-axis.
void SetMirrorY(bool mirrorY)
Enables or disables mirroring along the Y-axis for the aligned objects.
Vector2D camMax
Maximum 2D camera bounds (upper-right).
void SetCameraMin(Vector2D camMin)
Updates the minimum bounds for the 2D camera region.
void SetScale(float scaleX, float scaleY)
Sets the scaling factors that will be applied to objects during alignment.
A mathematical construct representing a rotation in 3D space.
Quaternion Conjugate() const
Returns the conjugate of this quaternion (W stays the same, X/Y/Z get negated).
Vector2D RotateVector(const Vector2D &v) const
Rotates a 2D vector by this quaternion, projecting it in 2D.
Vector2D UnrotateVector(const Vector2D &coordinate) const
Applies the inverse of this quaternion's rotation to a 2D vector.
Quaternion Multiply(const Quaternion &quaternion) const
Multiplies (composes) this quaternion with another (order matters).
Handles 3D rotations and conversions between various rotation representations.
Quaternion GetQuaternion()
Gets the quaternion representation of the rotation.
Vector3D * Normal()
Calculates and returns the normal of the triangle.
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
float X
The X-component of the 2D vector.
float Y
The Y-component of the 2D vector.
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
float Max() const
Returns the maximum component value among X, Y, Z.
float Min() const
Returns the minimum component value among X, Y, Z.
float Z
The Z-component of the 3D vector.
Vector3D UnitSphere() const
Normalizes this vector such that its magnitude is 1 (if non-zero).
float X
The X-component of the 3D vector.
float Y
The Y-component of the 3D vector.
Vector3D Absolute() const
Returns a vector with the absolute value of each component.
const EulerOrder EulerOrderXYZS
Order: X → Y → Z, static frame.