Skip to content

Commit

Permalink
C#: Fix Basis(Vec3,Vec3,Vec3) constructor
Browse files Browse the repository at this point in the history
Now it sets axes in order to match GDScript implementation.
  • Loading branch information
neikeq committed Nov 20, 2018
1 parent 7c4c646 commit bf94eed
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions modules/mono/glue/Managed/Files/Basis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,12 @@ public Vector3 XformInv(Vector3 v)
);
}

public Quat Quat() {
public Quat Quat()
{
real_t trace = _x[0] + _y[1] + _z[2];

if (trace > 0.0f) {
if (trace > 0.0f)
{
real_t s = Mathf.Sqrt(trace + 1.0f) * 2f;
real_t inv_s = 1f / s;
return new Quat(
Expand All @@ -424,7 +426,8 @@ public Quat Quat() {
);
}

if (_x[0] > _y[1] && _x[0] > _z[2]) {
if (_x[0] > _y[1] && _x[0] > _z[2])
{
real_t s = Mathf.Sqrt(_x[0] - _y[1] - _z[2] + 1.0f) * 2f;
real_t inv_s = 1f / s;
return new Quat(
Expand All @@ -435,7 +438,8 @@ public Quat Quat() {
);
}

if (_y[1] > _z[2]) {
if (_y[1] > _z[2])
{
real_t s = Mathf.Sqrt(-_x[0] + _y[1] - _z[2] + 1.0f) * 2f;
real_t inv_s = 1f / s;
return new Quat(
Expand All @@ -444,7 +448,9 @@ public Quat Quat() {
(_y[2] + _z[1]) * inv_s,
(_x[2] - _z[0]) * inv_s
);
} else {
}
else
{
real_t s = Mathf.Sqrt(-_x[0] - _y[1] + _z[2] + 1.0f) * 2f;
real_t inv_s = 1f / s;
return new Quat(
Expand Down Expand Up @@ -502,8 +508,8 @@ public Basis(Vector3 axis, real_t phi)
{
var axis_sq = new Vector3(axis.x * axis.x, axis.y * axis.y, axis.z * axis.z);

real_t cosine = Mathf.Cos( phi);
real_t sine = Mathf.Sin( phi);
real_t cosine = Mathf.Cos(phi);
real_t sine = Mathf.Sin(phi);

_x = new Vector3
(
Expand All @@ -529,9 +535,9 @@ public Basis(Vector3 axis, real_t phi)

public Basis(Vector3 xAxis, Vector3 yAxis, Vector3 zAxis)
{
_x = xAxis;
_y = yAxis;
_z = zAxis;
x = xAxis;
y = yAxis;
z = zAxis;
}

public Basis(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)
Expand Down

0 comments on commit bf94eed

Please sign in to comment.