2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2019-05-28 00:32:53 +02:00
|
|
|
|
2019-05-28 08:45:28 +02:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup collada
|
|
|
|
|
*/
|
2019-05-28 00:32:53 +02:00
|
|
|
|
2019-12-10 11:06:38 +11:00
|
|
|
#pragma once
|
2019-05-28 00:32:53 +02:00
|
|
|
|
2023-10-09 23:41:53 +02:00
|
|
|
#include "BKE_object.hh"
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_rotation.h"
|
|
|
|
|
#include "BLI_math_vector.h"
|
|
|
|
|
#include "BlenderTypes.h"
|
2019-05-28 08:45:28 +02:00
|
|
|
|
|
|
|
|
class BCQuat {
|
|
|
|
|
private:
|
|
|
|
|
mutable Quat q;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
BCQuat(const BCQuat &other)
|
|
|
|
|
{
|
|
|
|
|
copy_v4_v4(q, other.q);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BCQuat(Quat &other)
|
|
|
|
|
{
|
|
|
|
|
copy_v4_v4(q, other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BCQuat()
|
|
|
|
|
{
|
|
|
|
|
unit_qt(q);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Quat &quat()
|
|
|
|
|
{
|
|
|
|
|
return q;
|
|
|
|
|
}
|
2019-05-28 22:08:23 +02:00
|
|
|
|
|
|
|
|
void rotate_to(Matrix &mat_to);
|
2019-05-28 08:45:28 +02:00
|
|
|
};
|
2019-05-28 00:32:53 +02:00
|
|
|
|
|
|
|
|
class BCMatrix {
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
mutable float matrix[4][4];
|
|
|
|
|
mutable float size[3];
|
|
|
|
|
mutable float rot[3];
|
|
|
|
|
mutable float loc[3];
|
|
|
|
|
mutable float q[4];
|
|
|
|
|
|
|
|
|
|
void unit();
|
|
|
|
|
void copy(Matrix &r, Matrix &a);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
float (&location() const)[3];
|
|
|
|
|
float (&rotation() const)[3];
|
|
|
|
|
float (&scale() const)[3];
|
|
|
|
|
float (&quat() const)[4];
|
|
|
|
|
|
|
|
|
|
BCMatrix(BC_global_forward_axis global_forward_axis, BC_global_up_axis global_up_axis);
|
|
|
|
|
BCMatrix(const BCMatrix &mat);
|
|
|
|
|
BCMatrix(Matrix &mat);
|
|
|
|
|
BCMatrix(Object *ob);
|
|
|
|
|
BCMatrix();
|
|
|
|
|
|
2021-12-09 22:25:45 +11:00
|
|
|
/**
|
|
|
|
|
* We need double here because the OpenCollada API needs it.
|
|
|
|
|
* precision = -1 indicates to not limit the precision.
|
|
|
|
|
*/
|
2022-01-07 11:38:08 +11:00
|
|
|
void get_matrix(DMatrix &matrix, bool transposed = false, int precision = -1) const;
|
2019-05-28 00:32:53 +02:00
|
|
|
void get_matrix(Matrix &matrix,
|
2022-01-07 11:38:08 +11:00
|
|
|
bool transposed = false,
|
|
|
|
|
int precision = -1,
|
|
|
|
|
bool inverted = false) const;
|
2019-05-28 00:32:53 +02:00
|
|
|
void set_transform(Object *ob);
|
|
|
|
|
void set_transform(Matrix &mat);
|
|
|
|
|
void add_transform(Matrix &to,
|
|
|
|
|
const Matrix &transform,
|
|
|
|
|
const Matrix &from,
|
2022-01-07 11:38:08 +11:00
|
|
|
bool inverted = false);
|
2019-05-28 00:32:53 +02:00
|
|
|
void apply_transform(Matrix &to,
|
|
|
|
|
const Matrix &transform,
|
|
|
|
|
const Matrix &from,
|
2022-01-07 11:38:08 +11:00
|
|
|
bool inverse = false);
|
2019-05-28 00:32:53 +02:00
|
|
|
void add_inverted_transform(Matrix &to, const Matrix &transform, const Matrix &from);
|
2022-01-07 11:38:08 +11:00
|
|
|
void add_transform(const Matrix &matrix, bool inverted = false);
|
|
|
|
|
void add_transform(const BCMatrix &matrix, bool inverted = false);
|
|
|
|
|
void apply_transform(const BCMatrix &matrix, bool inverted = false);
|
2019-05-28 00:32:53 +02:00
|
|
|
|
2020-09-04 12:04:47 +02:00
|
|
|
bool in_range(const BCMatrix &other, float distance) const;
|
2019-05-28 09:23:05 +02:00
|
|
|
|
2019-05-28 00:32:53 +02:00
|
|
|
static void sanitize(Matrix &matrix, int precision);
|
2019-05-28 09:23:05 +02:00
|
|
|
static void sanitize(DMatrix &matrix, int precision);
|
2019-05-28 00:32:53 +02:00
|
|
|
static void transpose(Matrix &matrix);
|
|
|
|
|
};
|