|
@@ -40,24 +40,24 @@
|
|
namespace godot {
|
|
namespace godot {
|
|
|
|
|
|
float Projection::determinant() const {
|
|
float Projection::determinant() const {
|
|
- return matrix[0][3] * matrix[1][2] * matrix[2][1] * matrix[3][0] - matrix[0][2] * matrix[1][3] * matrix[2][1] * matrix[3][0] -
|
|
|
|
- matrix[0][3] * matrix[1][1] * matrix[2][2] * matrix[3][0] + matrix[0][1] * matrix[1][3] * matrix[2][2] * matrix[3][0] +
|
|
|
|
- matrix[0][2] * matrix[1][1] * matrix[2][3] * matrix[3][0] - matrix[0][1] * matrix[1][2] * matrix[2][3] * matrix[3][0] -
|
|
|
|
- matrix[0][3] * matrix[1][2] * matrix[2][0] * matrix[3][1] + matrix[0][2] * matrix[1][3] * matrix[2][0] * matrix[3][1] +
|
|
|
|
- matrix[0][3] * matrix[1][0] * matrix[2][2] * matrix[3][1] - matrix[0][0] * matrix[1][3] * matrix[2][2] * matrix[3][1] -
|
|
|
|
- matrix[0][2] * matrix[1][0] * matrix[2][3] * matrix[3][1] + matrix[0][0] * matrix[1][2] * matrix[2][3] * matrix[3][1] +
|
|
|
|
- matrix[0][3] * matrix[1][1] * matrix[2][0] * matrix[3][2] - matrix[0][1] * matrix[1][3] * matrix[2][0] * matrix[3][2] -
|
|
|
|
- matrix[0][3] * matrix[1][0] * matrix[2][1] * matrix[3][2] + matrix[0][0] * matrix[1][3] * matrix[2][1] * matrix[3][2] +
|
|
|
|
- matrix[0][1] * matrix[1][0] * matrix[2][3] * matrix[3][2] - matrix[0][0] * matrix[1][1] * matrix[2][3] * matrix[3][2] -
|
|
|
|
- matrix[0][2] * matrix[1][1] * matrix[2][0] * matrix[3][3] + matrix[0][1] * matrix[1][2] * matrix[2][0] * matrix[3][3] +
|
|
|
|
- matrix[0][2] * matrix[1][0] * matrix[2][1] * matrix[3][3] - matrix[0][0] * matrix[1][2] * matrix[2][1] * matrix[3][3] -
|
|
|
|
- matrix[0][1] * matrix[1][0] * matrix[2][2] * matrix[3][3] + matrix[0][0] * matrix[1][1] * matrix[2][2] * matrix[3][3];
|
|
|
|
|
|
+ return columns[0][3] * columns[1][2] * columns[2][1] * columns[3][0] - columns[0][2] * columns[1][3] * columns[2][1] * columns[3][0] -
|
|
|
|
+ columns[0][3] * columns[1][1] * columns[2][2] * columns[3][0] + columns[0][1] * columns[1][3] * columns[2][2] * columns[3][0] +
|
|
|
|
+ columns[0][2] * columns[1][1] * columns[2][3] * columns[3][0] - columns[0][1] * columns[1][2] * columns[2][3] * columns[3][0] -
|
|
|
|
+ columns[0][3] * columns[1][2] * columns[2][0] * columns[3][1] + columns[0][2] * columns[1][3] * columns[2][0] * columns[3][1] +
|
|
|
|
+ columns[0][3] * columns[1][0] * columns[2][2] * columns[3][1] - columns[0][0] * columns[1][3] * columns[2][2] * columns[3][1] -
|
|
|
|
+ columns[0][2] * columns[1][0] * columns[2][3] * columns[3][1] + columns[0][0] * columns[1][2] * columns[2][3] * columns[3][1] +
|
|
|
|
+ columns[0][3] * columns[1][1] * columns[2][0] * columns[3][2] - columns[0][1] * columns[1][3] * columns[2][0] * columns[3][2] -
|
|
|
|
+ columns[0][3] * columns[1][0] * columns[2][1] * columns[3][2] + columns[0][0] * columns[1][3] * columns[2][1] * columns[3][2] +
|
|
|
|
+ columns[0][1] * columns[1][0] * columns[2][3] * columns[3][2] - columns[0][0] * columns[1][1] * columns[2][3] * columns[3][2] -
|
|
|
|
+ columns[0][2] * columns[1][1] * columns[2][0] * columns[3][3] + columns[0][1] * columns[1][2] * columns[2][0] * columns[3][3] +
|
|
|
|
+ columns[0][2] * columns[1][0] * columns[2][1] * columns[3][3] - columns[0][0] * columns[1][2] * columns[2][1] * columns[3][3] -
|
|
|
|
+ columns[0][1] * columns[1][0] * columns[2][2] * columns[3][3] + columns[0][0] * columns[1][1] * columns[2][2] * columns[3][3];
|
|
}
|
|
}
|
|
|
|
|
|
void Projection::set_identity() {
|
|
void Projection::set_identity() {
|
|
for (int i = 0; i < 4; i++) {
|
|
for (int i = 0; i < 4; i++) {
|
|
for (int j = 0; j < 4; j++) {
|
|
for (int j = 0; j < 4; j++) {
|
|
- matrix[i][j] = (i == j) ? 1 : 0;
|
|
|
|
|
|
+ columns[i][j] = (i == j) ? 1 : 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -65,7 +65,7 @@ void Projection::set_identity() {
|
|
void Projection::set_zero() {
|
|
void Projection::set_zero() {
|
|
for (int i = 0; i < 4; i++) {
|
|
for (int i = 0; i < 4; i++) {
|
|
for (int j = 0; j < 4; j++) {
|
|
for (int j = 0; j < 4; j++) {
|
|
- matrix[i][j] = 0;
|
|
|
|
|
|
+ columns[i][j] = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -73,26 +73,26 @@ void Projection::set_zero() {
|
|
Plane Projection::xform4(const Plane &p_vec4) const {
|
|
Plane Projection::xform4(const Plane &p_vec4) const {
|
|
Plane ret;
|
|
Plane ret;
|
|
|
|
|
|
- ret.normal.x = matrix[0][0] * p_vec4.normal.x + matrix[1][0] * p_vec4.normal.y + matrix[2][0] * p_vec4.normal.z + matrix[3][0] * p_vec4.d;
|
|
|
|
- ret.normal.y = matrix[0][1] * p_vec4.normal.x + matrix[1][1] * p_vec4.normal.y + matrix[2][1] * p_vec4.normal.z + matrix[3][1] * p_vec4.d;
|
|
|
|
- ret.normal.z = matrix[0][2] * p_vec4.normal.x + matrix[1][2] * p_vec4.normal.y + matrix[2][2] * p_vec4.normal.z + matrix[3][2] * p_vec4.d;
|
|
|
|
- ret.d = matrix[0][3] * p_vec4.normal.x + matrix[1][3] * p_vec4.normal.y + matrix[2][3] * p_vec4.normal.z + matrix[3][3] * p_vec4.d;
|
|
|
|
|
|
+ ret.normal.x = columns[0][0] * p_vec4.normal.x + columns[1][0] * p_vec4.normal.y + columns[2][0] * p_vec4.normal.z + columns[3][0] * p_vec4.d;
|
|
|
|
+ ret.normal.y = columns[0][1] * p_vec4.normal.x + columns[1][1] * p_vec4.normal.y + columns[2][1] * p_vec4.normal.z + columns[3][1] * p_vec4.d;
|
|
|
|
+ ret.normal.z = columns[0][2] * p_vec4.normal.x + columns[1][2] * p_vec4.normal.y + columns[2][2] * p_vec4.normal.z + columns[3][2] * p_vec4.d;
|
|
|
|
+ ret.d = columns[0][3] * p_vec4.normal.x + columns[1][3] * p_vec4.normal.y + columns[2][3] * p_vec4.normal.z + columns[3][3] * p_vec4.d;
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
Vector4 Projection::xform(const Vector4 &p_vec4) const {
|
|
Vector4 Projection::xform(const Vector4 &p_vec4) const {
|
|
return Vector4(
|
|
return Vector4(
|
|
- matrix[0][0] * p_vec4.x + matrix[1][0] * p_vec4.y + matrix[2][0] * p_vec4.z + matrix[3][0] * p_vec4.w,
|
|
|
|
- matrix[0][1] * p_vec4.x + matrix[1][1] * p_vec4.y + matrix[2][1] * p_vec4.z + matrix[3][1] * p_vec4.w,
|
|
|
|
- matrix[0][2] * p_vec4.x + matrix[1][2] * p_vec4.y + matrix[2][2] * p_vec4.z + matrix[3][2] * p_vec4.w,
|
|
|
|
- matrix[0][3] * p_vec4.x + matrix[1][3] * p_vec4.y + matrix[2][3] * p_vec4.z + matrix[3][3] * p_vec4.w);
|
|
|
|
|
|
+ columns[0][0] * p_vec4.x + columns[1][0] * p_vec4.y + columns[2][0] * p_vec4.z + columns[3][0] * p_vec4.w,
|
|
|
|
+ columns[0][1] * p_vec4.x + columns[1][1] * p_vec4.y + columns[2][1] * p_vec4.z + columns[3][1] * p_vec4.w,
|
|
|
|
+ columns[0][2] * p_vec4.x + columns[1][2] * p_vec4.y + columns[2][2] * p_vec4.z + columns[3][2] * p_vec4.w,
|
|
|
|
+ columns[0][3] * p_vec4.x + columns[1][3] * p_vec4.y + columns[2][3] * p_vec4.z + columns[3][3] * p_vec4.w);
|
|
}
|
|
}
|
|
Vector4 Projection::xform_inv(const Vector4 &p_vec4) const {
|
|
Vector4 Projection::xform_inv(const Vector4 &p_vec4) const {
|
|
return Vector4(
|
|
return Vector4(
|
|
- matrix[0][0] * p_vec4.x + matrix[0][1] * p_vec4.y + matrix[0][2] * p_vec4.z + matrix[0][3] * p_vec4.w,
|
|
|
|
- matrix[1][0] * p_vec4.x + matrix[1][1] * p_vec4.y + matrix[1][2] * p_vec4.z + matrix[1][3] * p_vec4.w,
|
|
|
|
- matrix[2][0] * p_vec4.x + matrix[2][1] * p_vec4.y + matrix[2][2] * p_vec4.z + matrix[2][3] * p_vec4.w,
|
|
|
|
- matrix[3][0] * p_vec4.x + matrix[3][1] * p_vec4.y + matrix[3][2] * p_vec4.z + matrix[3][3] * p_vec4.w);
|
|
|
|
|
|
+ columns[0][0] * p_vec4.x + columns[0][1] * p_vec4.y + columns[0][2] * p_vec4.z + columns[0][3] * p_vec4.w,
|
|
|
|
+ columns[1][0] * p_vec4.x + columns[1][1] * p_vec4.y + columns[1][2] * p_vec4.z + columns[1][3] * p_vec4.w,
|
|
|
|
+ columns[2][0] * p_vec4.x + columns[2][1] * p_vec4.y + columns[2][2] * p_vec4.z + columns[2][3] * p_vec4.w,
|
|
|
|
+ columns[3][0] * p_vec4.x + columns[3][1] * p_vec4.y + columns[3][2] * p_vec4.z + columns[3][3] * p_vec4.w);
|
|
}
|
|
}
|
|
|
|
|
|
void Projection::adjust_perspective_znear(real_t p_new_znear) {
|
|
void Projection::adjust_perspective_znear(real_t p_new_znear) {
|
|
@@ -100,8 +100,8 @@ void Projection::adjust_perspective_znear(real_t p_new_znear) {
|
|
real_t znear = p_new_znear;
|
|
real_t znear = p_new_znear;
|
|
|
|
|
|
real_t deltaZ = zfar - znear;
|
|
real_t deltaZ = zfar - znear;
|
|
- matrix[2][2] = -(zfar + znear) / deltaZ;
|
|
|
|
- matrix[3][2] = -2 * znear * zfar / deltaZ;
|
|
|
|
|
|
+ columns[2][2] = -(zfar + znear) / deltaZ;
|
|
|
|
+ columns[3][2] = -2 * znear * zfar / deltaZ;
|
|
}
|
|
}
|
|
|
|
|
|
Projection Projection::create_depth_correction(bool p_flip_y) {
|
|
Projection Projection::create_depth_correction(bool p_flip_y) {
|
|
@@ -171,7 +171,7 @@ Projection Projection::perspective_znear_adjusted(real_t p_new_znear) const {
|
|
}
|
|
}
|
|
|
|
|
|
Plane Projection::get_projection_plane(Planes p_plane) const {
|
|
Plane Projection::get_projection_plane(Planes p_plane) const {
|
|
- const real_t *matrix = (const real_t *)this->matrix;
|
|
|
|
|
|
+ const real_t *matrix = (const real_t *)this->columns;
|
|
|
|
|
|
switch (p_plane) {
|
|
switch (p_plane) {
|
|
case PLANE_NEAR: {
|
|
case PLANE_NEAR: {
|
|
@@ -257,7 +257,7 @@ void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t
|
|
}
|
|
}
|
|
|
|
|
|
real_t sine, cotangent, deltaZ;
|
|
real_t sine, cotangent, deltaZ;
|
|
- real_t radians = Math::deg2rad(p_fovy_degrees / 2.0);
|
|
|
|
|
|
+ real_t radians = Math::deg_to_rad(p_fovy_degrees / 2.0);
|
|
|
|
|
|
deltaZ = p_z_far - p_z_near;
|
|
deltaZ = p_z_far - p_z_near;
|
|
sine = Math::sin(radians);
|
|
sine = Math::sin(radians);
|
|
@@ -269,12 +269,12 @@ void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t
|
|
|
|
|
|
set_identity();
|
|
set_identity();
|
|
|
|
|
|
- matrix[0][0] = cotangent / p_aspect;
|
|
|
|
- matrix[1][1] = cotangent;
|
|
|
|
- matrix[2][2] = -(p_z_far + p_z_near) / deltaZ;
|
|
|
|
- matrix[2][3] = -1;
|
|
|
|
- matrix[3][2] = -2 * p_z_near * p_z_far / deltaZ;
|
|
|
|
- matrix[3][3] = 0;
|
|
|
|
|
|
+ columns[0][0] = cotangent / p_aspect;
|
|
|
|
+ columns[1][1] = cotangent;
|
|
|
|
+ columns[2][2] = -(p_z_far + p_z_near) / deltaZ;
|
|
|
|
+ columns[2][3] = -1;
|
|
|
|
+ columns[3][2] = -2 * p_z_near * p_z_far / deltaZ;
|
|
|
|
+ columns[3][3] = 0;
|
|
}
|
|
}
|
|
|
|
|
|
void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov, int p_eye, real_t p_intraocular_dist, real_t p_convergence_dist) {
|
|
void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov, int p_eye, real_t p_intraocular_dist, real_t p_convergence_dist) {
|
|
@@ -284,7 +284,7 @@ void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t
|
|
|
|
|
|
real_t left, right, modeltranslation, ymax, xmax, frustumshift;
|
|
real_t left, right, modeltranslation, ymax, xmax, frustumshift;
|
|
|
|
|
|
- ymax = p_z_near * tan(Math::deg2rad(p_fovy_degrees / 2.0));
|
|
|
|
|
|
+ ymax = p_z_near * tan(Math::deg_to_rad(p_fovy_degrees / 2.0));
|
|
xmax = ymax * p_aspect;
|
|
xmax = ymax * p_aspect;
|
|
frustumshift = (p_intraocular_dist / 2.0) * p_z_near / p_convergence_dist;
|
|
frustumshift = (p_intraocular_dist / 2.0) * p_z_near / p_convergence_dist;
|
|
|
|
|
|
@@ -311,7 +311,7 @@ void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t
|
|
// translate matrix by (modeltranslation, 0.0, 0.0)
|
|
// translate matrix by (modeltranslation, 0.0, 0.0)
|
|
Projection cm;
|
|
Projection cm;
|
|
cm.set_identity();
|
|
cm.set_identity();
|
|
- cm.matrix[3][0] = modeltranslation;
|
|
|
|
|
|
+ cm.columns[3][0] = modeltranslation;
|
|
*this = *this * cm;
|
|
*this = *this * cm;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -346,13 +346,13 @@ void Projection::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_di
|
|
void Projection::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) {
|
|
void Projection::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) {
|
|
set_identity();
|
|
set_identity();
|
|
|
|
|
|
- matrix[0][0] = 2.0 / (p_right - p_left);
|
|
|
|
- matrix[3][0] = -((p_right + p_left) / (p_right - p_left));
|
|
|
|
- matrix[1][1] = 2.0 / (p_top - p_bottom);
|
|
|
|
- matrix[3][1] = -((p_top + p_bottom) / (p_top - p_bottom));
|
|
|
|
- matrix[2][2] = -2.0 / (p_zfar - p_znear);
|
|
|
|
- matrix[3][2] = -((p_zfar + p_znear) / (p_zfar - p_znear));
|
|
|
|
- matrix[3][3] = 1.0;
|
|
|
|
|
|
+ columns[0][0] = 2.0 / (p_right - p_left);
|
|
|
|
+ columns[3][0] = -((p_right + p_left) / (p_right - p_left));
|
|
|
|
+ columns[1][1] = 2.0 / (p_top - p_bottom);
|
|
|
|
+ columns[3][1] = -((p_top + p_bottom) / (p_top - p_bottom));
|
|
|
|
+ columns[2][2] = -2.0 / (p_zfar - p_znear);
|
|
|
|
+ columns[3][2] = -((p_zfar + p_znear) / (p_zfar - p_znear));
|
|
|
|
+ columns[3][3] = 1.0;
|
|
}
|
|
}
|
|
|
|
|
|
void Projection::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov) {
|
|
void Projection::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov) {
|
|
@@ -368,7 +368,7 @@ void Projection::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, rea
|
|
ERR_FAIL_COND(p_top <= p_bottom);
|
|
ERR_FAIL_COND(p_top <= p_bottom);
|
|
ERR_FAIL_COND(p_far <= p_near);
|
|
ERR_FAIL_COND(p_far <= p_near);
|
|
|
|
|
|
- real_t *te = &matrix[0][0];
|
|
|
|
|
|
+ real_t *te = &columns[0][0];
|
|
real_t x = 2 * p_near / (p_right - p_left);
|
|
real_t x = 2 * p_near / (p_right - p_left);
|
|
real_t y = 2 * p_near / (p_top - p_bottom);
|
|
real_t y = 2 * p_near / (p_top - p_bottom);
|
|
|
|
|
|
@@ -404,7 +404,7 @@ void Projection::set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, r
|
|
}
|
|
}
|
|
|
|
|
|
real_t Projection::get_z_far() const {
|
|
real_t Projection::get_z_far() const {
|
|
- const real_t *matrix = (const real_t *)this->matrix;
|
|
|
|
|
|
+ const real_t *matrix = (const real_t *)this->columns;
|
|
Plane new_plane = Plane(matrix[3] - matrix[2],
|
|
Plane new_plane = Plane(matrix[3] - matrix[2],
|
|
matrix[7] - matrix[6],
|
|
matrix[7] - matrix[6],
|
|
matrix[11] - matrix[10],
|
|
matrix[11] - matrix[10],
|
|
@@ -417,7 +417,7 @@ real_t Projection::get_z_far() const {
|
|
}
|
|
}
|
|
|
|
|
|
real_t Projection::get_z_near() const {
|
|
real_t Projection::get_z_near() const {
|
|
- const real_t *matrix = (const real_t *)this->matrix;
|
|
|
|
|
|
+ const real_t *matrix = (const real_t *)this->columns;
|
|
Plane new_plane = Plane(matrix[3] + matrix[2],
|
|
Plane new_plane = Plane(matrix[3] + matrix[2],
|
|
matrix[7] + matrix[6],
|
|
matrix[7] + matrix[6],
|
|
matrix[11] + matrix[10],
|
|
matrix[11] + matrix[10],
|
|
@@ -428,7 +428,7 @@ real_t Projection::get_z_near() const {
|
|
}
|
|
}
|
|
|
|
|
|
Vector2 Projection::get_viewport_half_extents() const {
|
|
Vector2 Projection::get_viewport_half_extents() const {
|
|
- const real_t *matrix = (const real_t *)this->matrix;
|
|
|
|
|
|
+ const real_t *matrix = (const real_t *)this->columns;
|
|
///////--- Near Plane ---///////
|
|
///////--- Near Plane ---///////
|
|
Plane near_plane = Plane(matrix[3] + matrix[2],
|
|
Plane near_plane = Plane(matrix[3] + matrix[2],
|
|
matrix[7] + matrix[6],
|
|
matrix[7] + matrix[6],
|
|
@@ -456,7 +456,7 @@ Vector2 Projection::get_viewport_half_extents() const {
|
|
}
|
|
}
|
|
|
|
|
|
Vector2 Projection::get_far_plane_half_extents() const {
|
|
Vector2 Projection::get_far_plane_half_extents() const {
|
|
- const real_t *matrix = (const real_t *)this->matrix;
|
|
|
|
|
|
+ const real_t *matrix = (const real_t *)this->columns;
|
|
///////--- Far Plane ---///////
|
|
///////--- Far Plane ---///////
|
|
Plane far_plane = Plane(matrix[3] - matrix[2],
|
|
Plane far_plane = Plane(matrix[3] - matrix[2],
|
|
matrix[7] - matrix[6],
|
|
matrix[7] - matrix[6],
|
|
@@ -498,7 +498,10 @@ bool Projection::get_endpoints(const Transform3D &p_transform, Vector3 *p_8point
|
|
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
for (int i = 0; i < 8; i++) {
|
|
Vector3 point;
|
|
Vector3 point;
|
|
- bool res = planes[intersections[i][0]].operator Plane().intersect_3(planes[intersections[i][1]].operator Plane(), planes[intersections[i][2]].operator Plane(), &point);
|
|
|
|
|
|
+ Plane a = planes[intersections[i][0]];
|
|
|
|
+ Plane b = planes[intersections[i][1]];
|
|
|
|
+ Plane c = planes[intersections[i][2]];
|
|
|
|
+ bool res = a.intersect_3(b, c, &point);
|
|
ERR_FAIL_COND_V(!res, false);
|
|
ERR_FAIL_COND_V(!res, false);
|
|
p_8points[i] = p_transform.xform(point);
|
|
p_8points[i] = p_transform.xform(point);
|
|
}
|
|
}
|
|
@@ -514,8 +517,9 @@ Array Projection::get_projection_planes(const Transform3D &p_transform) const {
|
|
*/
|
|
*/
|
|
|
|
|
|
Array planes;
|
|
Array planes;
|
|
|
|
+ planes.resize(6);
|
|
|
|
|
|
- const real_t *matrix = (const real_t *)this->matrix;
|
|
|
|
|
|
+ const real_t *matrix = (const real_t *)this->columns;
|
|
|
|
|
|
Plane new_plane;
|
|
Plane new_plane;
|
|
|
|
|
|
@@ -528,7 +532,7 @@ Array Projection::get_projection_planes(const Transform3D &p_transform) const {
|
|
new_plane.normal = -new_plane.normal;
|
|
new_plane.normal = -new_plane.normal;
|
|
new_plane.normalize();
|
|
new_plane.normalize();
|
|
|
|
|
|
- planes.push_back(p_transform.xform(new_plane));
|
|
|
|
|
|
+ planes[0] = p_transform.xform(new_plane);
|
|
|
|
|
|
///////--- Far Plane ---///////
|
|
///////--- Far Plane ---///////
|
|
new_plane = Plane(matrix[3] - matrix[2],
|
|
new_plane = Plane(matrix[3] - matrix[2],
|
|
@@ -539,7 +543,7 @@ Array Projection::get_projection_planes(const Transform3D &p_transform) const {
|
|
new_plane.normal = -new_plane.normal;
|
|
new_plane.normal = -new_plane.normal;
|
|
new_plane.normalize();
|
|
new_plane.normalize();
|
|
|
|
|
|
- planes.push_back(p_transform.xform(new_plane));
|
|
|
|
|
|
+ planes[1] = p_transform.xform(new_plane);
|
|
|
|
|
|
///////--- Left Plane ---///////
|
|
///////--- Left Plane ---///////
|
|
new_plane = Plane(matrix[3] + matrix[0],
|
|
new_plane = Plane(matrix[3] + matrix[0],
|
|
@@ -550,7 +554,7 @@ Array Projection::get_projection_planes(const Transform3D &p_transform) const {
|
|
new_plane.normal = -new_plane.normal;
|
|
new_plane.normal = -new_plane.normal;
|
|
new_plane.normalize();
|
|
new_plane.normalize();
|
|
|
|
|
|
- planes.push_back(p_transform.xform(new_plane));
|
|
|
|
|
|
+ planes[2] = p_transform.xform(new_plane);
|
|
|
|
|
|
///////--- Top Plane ---///////
|
|
///////--- Top Plane ---///////
|
|
new_plane = Plane(matrix[3] - matrix[1],
|
|
new_plane = Plane(matrix[3] - matrix[1],
|
|
@@ -561,7 +565,7 @@ Array Projection::get_projection_planes(const Transform3D &p_transform) const {
|
|
new_plane.normal = -new_plane.normal;
|
|
new_plane.normal = -new_plane.normal;
|
|
new_plane.normalize();
|
|
new_plane.normalize();
|
|
|
|
|
|
- planes.push_back(p_transform.xform(new_plane));
|
|
|
|
|
|
+ planes[3] = p_transform.xform(new_plane);
|
|
|
|
|
|
///////--- Right Plane ---///////
|
|
///////--- Right Plane ---///////
|
|
new_plane = Plane(matrix[3] - matrix[0],
|
|
new_plane = Plane(matrix[3] - matrix[0],
|
|
@@ -572,7 +576,7 @@ Array Projection::get_projection_planes(const Transform3D &p_transform) const {
|
|
new_plane.normal = -new_plane.normal;
|
|
new_plane.normal = -new_plane.normal;
|
|
new_plane.normalize();
|
|
new_plane.normalize();
|
|
|
|
|
|
- planes.push_back(p_transform.xform(new_plane));
|
|
|
|
|
|
+ planes[4] = p_transform.xform(new_plane);
|
|
|
|
|
|
///////--- Bottom Plane ---///////
|
|
///////--- Bottom Plane ---///////
|
|
new_plane = Plane(matrix[3] + matrix[1],
|
|
new_plane = Plane(matrix[3] + matrix[1],
|
|
@@ -583,7 +587,7 @@ Array Projection::get_projection_planes(const Transform3D &p_transform) const {
|
|
new_plane.normal = -new_plane.normal;
|
|
new_plane.normal = -new_plane.normal;
|
|
new_plane.normalize();
|
|
new_plane.normalize();
|
|
|
|
|
|
- planes.push_back(p_transform.xform(new_plane));
|
|
|
|
|
|
+ planes[5] = p_transform.xform(new_plane);
|
|
|
|
|
|
return planes;
|
|
return planes;
|
|
}
|
|
}
|
|
@@ -602,15 +606,15 @@ void Projection::invert() {
|
|
real_t determinant = 1.0f;
|
|
real_t determinant = 1.0f;
|
|
for (k = 0; k < 4; k++) {
|
|
for (k = 0; k < 4; k++) {
|
|
/** Locate k'th pivot element **/
|
|
/** Locate k'th pivot element **/
|
|
- pvt_val = matrix[k][k]; /** Initialize for search **/
|
|
|
|
|
|
+ pvt_val = columns[k][k]; /** Initialize for search **/
|
|
pvt_i[k] = k;
|
|
pvt_i[k] = k;
|
|
pvt_j[k] = k;
|
|
pvt_j[k] = k;
|
|
for (i = k; i < 4; i++) {
|
|
for (i = k; i < 4; i++) {
|
|
for (j = k; j < 4; j++) {
|
|
for (j = k; j < 4; j++) {
|
|
- if (Math::abs(matrix[i][j]) > Math::abs(pvt_val)) {
|
|
|
|
|
|
+ if (Math::abs(columns[i][j]) > Math::abs(pvt_val)) {
|
|
pvt_i[k] = i;
|
|
pvt_i[k] = i;
|
|
pvt_j[k] = j;
|
|
pvt_j[k] = j;
|
|
- pvt_val = matrix[i][j];
|
|
|
|
|
|
+ pvt_val = columns[i][j];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -621,13 +625,13 @@ void Projection::invert() {
|
|
return; /** Matrix is singular (zero determinant). **/
|
|
return; /** Matrix is singular (zero determinant). **/
|
|
}
|
|
}
|
|
|
|
|
|
- /** "Interchange" elements (with sign change stuff) **/
|
|
|
|
|
|
+ /** "Interchange" rows (with sign change stuff) **/
|
|
i = pvt_i[k];
|
|
i = pvt_i[k];
|
|
- if (i != k) { /** If elements are different **/
|
|
|
|
|
|
+ if (i != k) { /** If rows are different **/
|
|
for (j = 0; j < 4; j++) {
|
|
for (j = 0; j < 4; j++) {
|
|
- hold = -matrix[k][j];
|
|
|
|
- matrix[k][j] = matrix[i][j];
|
|
|
|
- matrix[i][j] = hold;
|
|
|
|
|
|
+ hold = -columns[k][j];
|
|
|
|
+ columns[k][j] = columns[i][j];
|
|
|
|
+ columns[i][j] = hold;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -635,25 +639,25 @@ void Projection::invert() {
|
|
j = pvt_j[k];
|
|
j = pvt_j[k];
|
|
if (j != k) { /** If columns are different **/
|
|
if (j != k) { /** If columns are different **/
|
|
for (i = 0; i < 4; i++) {
|
|
for (i = 0; i < 4; i++) {
|
|
- hold = -matrix[i][k];
|
|
|
|
- matrix[i][k] = matrix[i][j];
|
|
|
|
- matrix[i][j] = hold;
|
|
|
|
|
|
+ hold = -columns[i][k];
|
|
|
|
+ columns[i][k] = columns[i][j];
|
|
|
|
+ columns[i][j] = hold;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/** Divide column by minus pivot value **/
|
|
/** Divide column by minus pivot value **/
|
|
for (i = 0; i < 4; i++) {
|
|
for (i = 0; i < 4; i++) {
|
|
if (i != k) {
|
|
if (i != k) {
|
|
- matrix[i][k] /= (-pvt_val);
|
|
|
|
|
|
+ columns[i][k] /= (-pvt_val);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/** Reduce the matrix **/
|
|
/** Reduce the matrix **/
|
|
for (i = 0; i < 4; i++) {
|
|
for (i = 0; i < 4; i++) {
|
|
- hold = matrix[i][k];
|
|
|
|
|
|
+ hold = columns[i][k];
|
|
for (j = 0; j < 4; j++) {
|
|
for (j = 0; j < 4; j++) {
|
|
if (i != k && j != k) {
|
|
if (i != k && j != k) {
|
|
- matrix[i][j] += hold * matrix[k][j];
|
|
|
|
|
|
+ columns[i][j] += hold * columns[k][j];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -661,32 +665,32 @@ void Projection::invert() {
|
|
/** Divide row by pivot **/
|
|
/** Divide row by pivot **/
|
|
for (j = 0; j < 4; j++) {
|
|
for (j = 0; j < 4; j++) {
|
|
if (j != k) {
|
|
if (j != k) {
|
|
- matrix[k][j] /= pvt_val;
|
|
|
|
|
|
+ columns[k][j] /= pvt_val;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/** Replace pivot by reciprocal (at last we can touch it). **/
|
|
/** Replace pivot by reciprocal (at last we can touch it). **/
|
|
- matrix[k][k] = 1.0 / pvt_val;
|
|
|
|
|
|
+ columns[k][k] = 1.0 / pvt_val;
|
|
}
|
|
}
|
|
|
|
|
|
/* That was most of the work, one final pass of row/column interchange */
|
|
/* That was most of the work, one final pass of row/column interchange */
|
|
/* to finish */
|
|
/* to finish */
|
|
for (k = 4 - 2; k >= 0; k--) { /* Don't need to work with 1 by 1 corner*/
|
|
for (k = 4 - 2; k >= 0; k--) { /* Don't need to work with 1 by 1 corner*/
|
|
i = pvt_j[k]; /* Rows to swap correspond to pivot COLUMN */
|
|
i = pvt_j[k]; /* Rows to swap correspond to pivot COLUMN */
|
|
- if (i != k) { /* If elements are different */
|
|
|
|
|
|
+ if (i != k) { /* If rows are different */
|
|
for (j = 0; j < 4; j++) {
|
|
for (j = 0; j < 4; j++) {
|
|
- hold = matrix[k][j];
|
|
|
|
- matrix[k][j] = -matrix[i][j];
|
|
|
|
- matrix[i][j] = hold;
|
|
|
|
|
|
+ hold = columns[k][j];
|
|
|
|
+ columns[k][j] = -columns[i][j];
|
|
|
|
+ columns[i][j] = hold;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
j = pvt_i[k]; /* Columns to swap correspond to pivot ROW */
|
|
j = pvt_i[k]; /* Columns to swap correspond to pivot ROW */
|
|
if (j != k) { /* If columns are different */
|
|
if (j != k) { /* If columns are different */
|
|
for (i = 0; i < 4; i++) {
|
|
for (i = 0; i < 4; i++) {
|
|
- hold = matrix[i][k];
|
|
|
|
- matrix[i][k] = -matrix[i][j];
|
|
|
|
- matrix[i][j] = hold;
|
|
|
|
|
|
+ hold = columns[i][k];
|
|
|
|
+ columns[i][k] = -columns[i][j];
|
|
|
|
+ columns[i][j] = hold;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -694,7 +698,7 @@ void Projection::invert() {
|
|
|
|
|
|
void Projection::flip_y() {
|
|
void Projection::flip_y() {
|
|
for (int i = 0; i < 4; i++) {
|
|
for (int i = 0; i < 4; i++) {
|
|
- matrix[1][i] = -matrix[1][i];
|
|
|
|
|
|
+ columns[1][i] = -columns[1][i];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -709,9 +713,9 @@ Projection Projection::operator*(const Projection &p_matrix) const {
|
|
for (int i = 0; i < 4; i++) {
|
|
for (int i = 0; i < 4; i++) {
|
|
real_t ab = 0;
|
|
real_t ab = 0;
|
|
for (int k = 0; k < 4; k++) {
|
|
for (int k = 0; k < 4; k++) {
|
|
- ab += matrix[k][i] * p_matrix.matrix[j][k];
|
|
|
|
|
|
+ ab += columns[k][i] * p_matrix.columns[j][k];
|
|
}
|
|
}
|
|
- new_matrix.matrix[j][i] = ab;
|
|
|
|
|
|
+ new_matrix.columns[j][i] = ab;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -719,7 +723,7 @@ Projection Projection::operator*(const Projection &p_matrix) const {
|
|
}
|
|
}
|
|
|
|
|
|
void Projection::set_depth_correction(bool p_flip_y) {
|
|
void Projection::set_depth_correction(bool p_flip_y) {
|
|
- real_t *m = &matrix[0][0];
|
|
|
|
|
|
+ real_t *m = &columns[0][0];
|
|
|
|
|
|
m[0] = 1;
|
|
m[0] = 1;
|
|
m[1] = 0.0;
|
|
m[1] = 0.0;
|
|
@@ -740,7 +744,7 @@ void Projection::set_depth_correction(bool p_flip_y) {
|
|
}
|
|
}
|
|
|
|
|
|
void Projection::set_light_bias() {
|
|
void Projection::set_light_bias() {
|
|
- real_t *m = &matrix[0][0];
|
|
|
|
|
|
+ real_t *m = &columns[0][0];
|
|
|
|
|
|
m[0] = 0.5;
|
|
m[0] = 0.5;
|
|
m[1] = 0.0;
|
|
m[1] = 0.0;
|
|
@@ -761,7 +765,7 @@ void Projection::set_light_bias() {
|
|
}
|
|
}
|
|
|
|
|
|
void Projection::set_light_atlas_rect(const Rect2 &p_rect) {
|
|
void Projection::set_light_atlas_rect(const Rect2 &p_rect) {
|
|
- real_t *m = &matrix[0][0];
|
|
|
|
|
|
+ real_t *m = &columns[0][0];
|
|
|
|
|
|
m[0] = p_rect.size.width;
|
|
m[0] = p_rect.size.width;
|
|
m[1] = 0.0;
|
|
m[1] = 0.0;
|
|
@@ -785,7 +789,7 @@ Projection::operator String() const {
|
|
String str;
|
|
String str;
|
|
for (int i = 0; i < 4; i++) {
|
|
for (int i = 0; i < 4; i++) {
|
|
for (int j = 0; j < 4; j++) {
|
|
for (int j = 0; j < 4; j++) {
|
|
- str = str + String((j > 0) ? ", " : "\n") + rtos(matrix[i][j]);
|
|
|
|
|
|
+ str = str + String((j > 0) ? ", " : "\n") + rtos(columns[i][j]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -804,11 +808,11 @@ int Projection::get_pixels_per_meter(int p_for_pixel_width) const {
|
|
}
|
|
}
|
|
|
|
|
|
bool Projection::is_orthogonal() const {
|
|
bool Projection::is_orthogonal() const {
|
|
- return matrix[3][3] == 1.0;
|
|
|
|
|
|
+ return columns[3][3] == 1.0;
|
|
}
|
|
}
|
|
|
|
|
|
real_t Projection::get_fov() const {
|
|
real_t Projection::get_fov() const {
|
|
- const real_t *matrix = (const real_t *)this->matrix;
|
|
|
|
|
|
+ const real_t *matrix = (const real_t *)this->columns;
|
|
|
|
|
|
Plane right_plane = Plane(matrix[3] - matrix[0],
|
|
Plane right_plane = Plane(matrix[3] - matrix[0],
|
|
matrix[7] - matrix[4],
|
|
matrix[7] - matrix[4],
|
|
@@ -817,7 +821,7 @@ real_t Projection::get_fov() const {
|
|
right_plane.normalize();
|
|
right_plane.normalize();
|
|
|
|
|
|
if ((matrix[8] == 0) && (matrix[9] == 0)) {
|
|
if ((matrix[8] == 0) && (matrix[9] == 0)) {
|
|
- return Math::rad2deg(Math::acos(Math::abs(right_plane.normal.x))) * 2.0;
|
|
|
|
|
|
+ return Math::rad_to_deg(Math::acos(Math::abs(right_plane.normal.x))) * 2.0;
|
|
} else {
|
|
} else {
|
|
// our frustum is asymmetrical need to calculate the left planes angle separately..
|
|
// our frustum is asymmetrical need to calculate the left planes angle separately..
|
|
Plane left_plane = Plane(matrix[3] + matrix[0],
|
|
Plane left_plane = Plane(matrix[3] + matrix[0],
|
|
@@ -826,7 +830,7 @@ real_t Projection::get_fov() const {
|
|
matrix[15] + matrix[12]);
|
|
matrix[15] + matrix[12]);
|
|
left_plane.normalize();
|
|
left_plane.normalize();
|
|
|
|
|
|
- return Math::rad2deg(Math::acos(Math::abs(left_plane.normal.x))) + Math::rad2deg(Math::acos(Math::abs(right_plane.normal.x)));
|
|
|
|
|
|
+ return Math::rad_to_deg(Math::acos(Math::abs(left_plane.normal.x))) + Math::rad_to_deg(Math::acos(Math::abs(right_plane.normal.x)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -839,48 +843,49 @@ float Projection::get_lod_multiplier() const {
|
|
return 1.0 / (zn / width);
|
|
return 1.0 / (zn / width);
|
|
}
|
|
}
|
|
|
|
|
|
- // usage is lod_size / (lod_distance * multiplier) < threshold
|
|
|
|
|
|
+ // Usage is lod_size / (lod_distance * multiplier) < threshold
|
|
}
|
|
}
|
|
|
|
+
|
|
void Projection::make_scale(const Vector3 &p_scale) {
|
|
void Projection::make_scale(const Vector3 &p_scale) {
|
|
set_identity();
|
|
set_identity();
|
|
- matrix[0][0] = p_scale.x;
|
|
|
|
- matrix[1][1] = p_scale.y;
|
|
|
|
- matrix[2][2] = p_scale.z;
|
|
|
|
|
|
+ columns[0][0] = p_scale.x;
|
|
|
|
+ columns[1][1] = p_scale.y;
|
|
|
|
+ columns[2][2] = p_scale.z;
|
|
}
|
|
}
|
|
|
|
|
|
void Projection::scale_translate_to_fit(const AABB &p_aabb) {
|
|
void Projection::scale_translate_to_fit(const AABB &p_aabb) {
|
|
Vector3 min = p_aabb.position;
|
|
Vector3 min = p_aabb.position;
|
|
Vector3 max = p_aabb.position + p_aabb.size;
|
|
Vector3 max = p_aabb.position + p_aabb.size;
|
|
|
|
|
|
- matrix[0][0] = 2 / (max.x - min.x);
|
|
|
|
- matrix[1][0] = 0;
|
|
|
|
- matrix[2][0] = 0;
|
|
|
|
- matrix[3][0] = -(max.x + min.x) / (max.x - min.x);
|
|
|
|
|
|
+ columns[0][0] = 2 / (max.x - min.x);
|
|
|
|
+ columns[1][0] = 0;
|
|
|
|
+ columns[2][0] = 0;
|
|
|
|
+ columns[3][0] = -(max.x + min.x) / (max.x - min.x);
|
|
|
|
|
|
- matrix[0][1] = 0;
|
|
|
|
- matrix[1][1] = 2 / (max.y - min.y);
|
|
|
|
- matrix[2][1] = 0;
|
|
|
|
- matrix[3][1] = -(max.y + min.y) / (max.y - min.y);
|
|
|
|
|
|
+ columns[0][1] = 0;
|
|
|
|
+ columns[1][1] = 2 / (max.y - min.y);
|
|
|
|
+ columns[2][1] = 0;
|
|
|
|
+ columns[3][1] = -(max.y + min.y) / (max.y - min.y);
|
|
|
|
|
|
- matrix[0][2] = 0;
|
|
|
|
- matrix[1][2] = 0;
|
|
|
|
- matrix[2][2] = 2 / (max.z - min.z);
|
|
|
|
- matrix[3][2] = -(max.z + min.z) / (max.z - min.z);
|
|
|
|
|
|
+ columns[0][2] = 0;
|
|
|
|
+ columns[1][2] = 0;
|
|
|
|
+ columns[2][2] = 2 / (max.z - min.z);
|
|
|
|
+ columns[3][2] = -(max.z + min.z) / (max.z - min.z);
|
|
|
|
|
|
- matrix[0][3] = 0;
|
|
|
|
- matrix[1][3] = 0;
|
|
|
|
- matrix[2][3] = 0;
|
|
|
|
- matrix[3][3] = 1;
|
|
|
|
|
|
+ columns[0][3] = 0;
|
|
|
|
+ columns[1][3] = 0;
|
|
|
|
+ columns[2][3] = 0;
|
|
|
|
+ columns[3][3] = 1;
|
|
}
|
|
}
|
|
|
|
|
|
void Projection::add_jitter_offset(const Vector2 &p_offset) {
|
|
void Projection::add_jitter_offset(const Vector2 &p_offset) {
|
|
- matrix[3][0] += p_offset.x;
|
|
|
|
- matrix[3][1] += p_offset.y;
|
|
|
|
|
|
+ columns[3][0] += p_offset.x;
|
|
|
|
+ columns[3][1] += p_offset.y;
|
|
}
|
|
}
|
|
|
|
|
|
Projection::operator Transform3D() const {
|
|
Projection::operator Transform3D() const {
|
|
Transform3D tr;
|
|
Transform3D tr;
|
|
- const real_t *m = &matrix[0][0];
|
|
|
|
|
|
+ const real_t *m = &columns[0][0];
|
|
|
|
|
|
tr.basis.rows[0][0] = m[0];
|
|
tr.basis.rows[0][0] = m[0];
|
|
tr.basis.rows[1][0] = m[1];
|
|
tr.basis.rows[1][0] = m[1];
|
|
@@ -900,15 +905,17 @@ Projection::operator Transform3D() const {
|
|
|
|
|
|
return tr;
|
|
return tr;
|
|
}
|
|
}
|
|
|
|
+
|
|
Projection::Projection(const Vector4 &p_x, const Vector4 &p_y, const Vector4 &p_z, const Vector4 &p_w) {
|
|
Projection::Projection(const Vector4 &p_x, const Vector4 &p_y, const Vector4 &p_z, const Vector4 &p_w) {
|
|
- matrix[0] = p_x;
|
|
|
|
- matrix[1] = p_y;
|
|
|
|
- matrix[2] = p_z;
|
|
|
|
- matrix[3] = p_w;
|
|
|
|
|
|
+ columns[0] = p_x;
|
|
|
|
+ columns[1] = p_y;
|
|
|
|
+ columns[2] = p_z;
|
|
|
|
+ columns[3] = p_w;
|
|
}
|
|
}
|
|
|
|
+
|
|
Projection::Projection(const Transform3D &p_transform) {
|
|
Projection::Projection(const Transform3D &p_transform) {
|
|
const Transform3D &tr = p_transform;
|
|
const Transform3D &tr = p_transform;
|
|
- real_t *m = &matrix[0][0];
|
|
|
|
|
|
+ real_t *m = &columns[0][0];
|
|
|
|
|
|
m[0] = tr.basis.rows[0][0];
|
|
m[0] = tr.basis.rows[0][0];
|
|
m[1] = tr.basis.rows[1][0];
|
|
m[1] = tr.basis.rows[1][0];
|