ModelHandle/source/geometry/transformation.js
2021-10-26 07:53:25 +02:00

59 lines
1.2 KiB
JavaScript

OV.Transformation = class
{
constructor (matrix)
{
if (matrix !== undefined && matrix !== null) {
this.matrix = matrix;
} else {
this.matrix = new OV.Matrix ();
this.matrix.CreateIdentity ();
}
}
SetMatrix (matrix)
{
this.matrix = matrix;
return this;
}
GetMatrix ()
{
return this.matrix;
}
IsIdentity ()
{
return this.matrix.IsIdentity ();
}
AppendMatrix (matrix)
{
this.matrix = this.matrix.MultiplyMatrix (matrix);
return this;
}
Append (transformation)
{
this.AppendMatrix (transformation.GetMatrix ());
return this;
}
TransformCoord3D (coord)
{
let resultVector = this.matrix.MultiplyVector ([coord.x, coord.y, coord.z, 1.0]);
let result = new OV.Coord3D (resultVector[0], resultVector[1], resultVector[2]);
return result;
}
Clone ()
{
const clonedMatrix = this.matrix.Clone ();
return new OV.Transformation (clonedMatrix);
}
};
OV.TransformationIsEqual = function (a, b)
{
return OV.MatrixIsEqual (a.GetMatrix (), b.GetMatrix ());
};