2021-08-02 16:34:47 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* Transform.hpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2017-03-03 20:04:23 +00:00
|
|
|
#ifndef TRANSFORM_H
|
|
|
|
#define TRANSFORM_H
|
|
|
|
|
2017-03-06 07:49:24 +00:00
|
|
|
#include "Basis.hpp"
|
2017-03-03 20:04:23 +00:00
|
|
|
|
2017-11-23 11:50:05 +00:00
|
|
|
#include "AABB.hpp"
|
2018-11-23 22:09:41 +00:00
|
|
|
#include "Plane.hpp"
|
2017-03-03 20:04:23 +00:00
|
|
|
|
|
|
|
namespace godot {
|
|
|
|
|
2017-07-23 15:53:50 +00:00
|
|
|
class Transform {
|
2017-03-03 20:04:23 +00:00
|
|
|
public:
|
2020-12-08 23:00:34 +00:00
|
|
|
static const Transform IDENTITY;
|
|
|
|
static const Transform FLIP_X;
|
|
|
|
static const Transform FLIP_Y;
|
|
|
|
static const Transform FLIP_Z;
|
|
|
|
|
2017-03-03 20:04:23 +00:00
|
|
|
Basis basis;
|
|
|
|
Vector3 origin;
|
|
|
|
|
|
|
|
void invert();
|
|
|
|
Transform inverse() const;
|
|
|
|
|
|
|
|
void affine_invert();
|
|
|
|
Transform affine_inverse() const;
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
Transform rotated(const Vector3 &p_axis, real_t p_phi) const;
|
2017-03-03 20:04:23 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void rotate(const Vector3 &p_axis, real_t p_phi);
|
|
|
|
void rotate_basis(const Vector3 &p_axis, real_t p_phi);
|
2017-03-03 20:04:23 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const Vector3 &p_up);
|
|
|
|
Transform looking_at(const Vector3 &p_target, const Vector3 &p_up) const;
|
2017-03-03 20:04:23 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void scale(const Vector3 &p_scale);
|
|
|
|
Transform scaled(const Vector3 &p_scale) const;
|
|
|
|
void scale_basis(const Vector3 &p_scale);
|
|
|
|
void translate(real_t p_tx, real_t p_ty, real_t p_tz);
|
|
|
|
void translate(const Vector3 &p_translation);
|
|
|
|
Transform translated(const Vector3 &p_translation) const;
|
2017-03-03 20:04:23 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
inline const Basis &get_basis() const { return basis; }
|
|
|
|
inline void set_basis(const Basis &p_basis) { basis = p_basis; }
|
2017-03-03 20:04:23 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
inline const Vector3 &get_origin() const { return origin; }
|
|
|
|
inline void set_origin(const Vector3 &p_origin) { origin = p_origin; }
|
2017-03-03 20:04:23 +00:00
|
|
|
|
|
|
|
void orthonormalize();
|
|
|
|
Transform orthonormalized() const;
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
bool operator==(const Transform &p_transform) const;
|
|
|
|
bool operator!=(const Transform &p_transform) const;
|
2017-03-03 20:04:23 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
Vector3 xform(const Vector3 &p_vector) const;
|
|
|
|
Vector3 xform_inv(const Vector3 &p_vector) const;
|
2017-03-03 20:04:23 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
Plane xform(const Plane &p_plane) const;
|
|
|
|
Plane xform_inv(const Plane &p_plane) const;
|
2017-03-03 20:04:23 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
AABB xform(const AABB &p_aabb) const;
|
|
|
|
AABB xform_inv(const AABB &p_aabb) const;
|
2017-03-03 20:04:23 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void operator*=(const Transform &p_transform);
|
|
|
|
Transform operator*(const Transform &p_transform) const;
|
2017-03-03 20:04:23 +00:00
|
|
|
|
2019-04-11 15:06:02 +00:00
|
|
|
inline Vector3 operator*(const Vector3 &p_vector) const {
|
|
|
|
return Vector3(
|
|
|
|
basis.elements[0].dot(p_vector) + origin.x,
|
|
|
|
basis.elements[1].dot(p_vector) + origin.y,
|
|
|
|
basis.elements[2].dot(p_vector) + origin.z);
|
|
|
|
}
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
Transform interpolate_with(const Transform &p_transform, real_t p_c) const;
|
2017-03-03 20:04:23 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
Transform inverse_xform(const Transform &t) const;
|
2017-03-03 20:04:23 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t tx, real_t ty, real_t tz);
|
2017-03-03 20:04:23 +00:00
|
|
|
|
|
|
|
operator String() const;
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
inline Transform(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t tx, real_t ty, real_t tz) {
|
|
|
|
set(xx, xy, xz, yx, yy, yz, zx, zy, zz, tx, ty, tz);
|
2017-04-04 19:02:44 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
Transform(const Basis &p_basis, const Vector3 &p_origin = Vector3());
|
2017-03-06 02:30:46 +00:00
|
|
|
inline Transform() {}
|
2017-03-03 20:04:23 +00:00
|
|
|
};
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
} // namespace godot
|
2017-03-03 20:04:23 +00:00
|
|
|
|
|
|
|
#endif // TRANSFORM_H
|