2016-02-25 08:39:15 -05:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-04-05 21:29:32 -04:00
|
|
|
#include "titanic/star_control/fpose.h"
|
2016-02-25 08:39:15 -05:00
|
|
|
|
|
|
|
namespace Titanic {
|
|
|
|
|
2017-04-05 21:29:32 -04:00
|
|
|
FPose::FPose() {
|
2016-06-30 13:40:55 -04:00
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2017-04-05 21:29:32 -04:00
|
|
|
FPose::FPose(Axis axis, float amount) {
|
2017-03-12 20:18:53 -04:00
|
|
|
setRotationMatrix(axis, amount);
|
2016-07-16 18:23:25 -04:00
|
|
|
}
|
|
|
|
|
2017-04-06 07:40:21 -04:00
|
|
|
FPose::FPose(const FPose &src) : FMatrix() {
|
2016-07-17 16:43:53 -04:00
|
|
|
copyFrom(src);
|
|
|
|
}
|
|
|
|
|
2017-04-05 21:29:32 -04:00
|
|
|
FPose::FPose(const FPose &s1, const FPose &s2) {
|
|
|
|
_row1._x = s2._row1._x * s1._row1._x
|
|
|
|
+ s1._row1._z * s2._row3._x
|
|
|
|
+ s1._row1._y * s2._row2._x;
|
|
|
|
_row1._y = s1._row1._x * s2._row1._y
|
|
|
|
+ s2._row3._y * s1._row1._z
|
|
|
|
+ s2._row2._y * s1._row1._y;
|
|
|
|
_row1._z = s1._row1._x * s2._row1._z
|
|
|
|
+ s2._row3._z * s1._row1._z
|
|
|
|
+ s2._row2._z * s1._row1._y;
|
|
|
|
_row2._x = s2._row1._x * s1._row2._x
|
|
|
|
+ s1._row2._y * s2._row2._x
|
|
|
|
+ s1._row2._z * s2._row3._x;
|
|
|
|
_row2._y = s1._row2._y * s2._row2._y
|
|
|
|
+ s1._row2._z * s2._row3._y
|
|
|
|
+ s2._row1._y * s1._row2._x;
|
|
|
|
_row2._z = s2._row1._z * s1._row2._x
|
|
|
|
+ s1._row2._y * s2._row2._z
|
|
|
|
+ s1._row2._z * s2._row3._z;
|
|
|
|
_row3._x = s2._row1._x * s1._row3._x
|
|
|
|
+ s1._row3._y * s2._row2._x
|
|
|
|
+ s1._row3._z * s2._row3._x;
|
|
|
|
_row3._y = s1._row3._z * s2._row3._y
|
|
|
|
+ s1._row3._y * s2._row2._y
|
|
|
|
+ s2._row1._y * s1._row3._x;
|
|
|
|
_row3._z = s2._row3._z * s1._row3._z
|
|
|
|
+ s2._row2._z * s1._row3._y
|
|
|
|
+ s2._row1._z * s1._row3._x;
|
|
|
|
_vector._x = s2._row1._x * s1._vector._x
|
|
|
|
+ s1._vector._y * s2._row2._x
|
|
|
|
+ s1._vector._z * s2._row3._x
|
|
|
|
+ s2._vector._x;
|
|
|
|
_vector._y = s1._vector._z * s2._row3._y
|
|
|
|
+ s1._vector._y * s2._row2._y
|
|
|
|
+ s1._vector._x * s2._row1._y
|
|
|
|
+ s2._vector._y;
|
|
|
|
_vector._z = s1._vector._y * s2._row2._z
|
|
|
|
+ s1._vector._z * s2._row3._z
|
|
|
|
+ s1._vector._x * s2._row1._z
|
|
|
|
+ s2._vector._z;
|
2017-03-18 23:40:24 -04:00
|
|
|
}
|
|
|
|
|
2017-04-05 21:29:32 -04:00
|
|
|
void FPose::identity() {
|
2017-03-12 19:55:56 -04:00
|
|
|
FMatrix::identity();
|
2017-03-08 22:05:43 -05:00
|
|
|
_vector.clear();
|
2016-02-25 08:39:15 -05:00
|
|
|
}
|
|
|
|
|
2017-08-15 19:31:17 -07:00
|
|
|
// Source: https://en.wikipedia.org/wiki/Rotation_matrix
|
2017-04-05 21:29:32 -04:00
|
|
|
void FPose::setRotationMatrix(Axis axis, float amount) {
|
2017-04-05 21:08:51 -04:00
|
|
|
const float ROTATION = 2 * M_PI / 360.0;
|
|
|
|
float sinVal = sin(amount * ROTATION);
|
|
|
|
float cosVal = cos(amount * ROTATION);
|
2016-07-16 18:23:25 -04:00
|
|
|
|
2017-03-12 20:18:53 -04:00
|
|
|
switch (axis) {
|
|
|
|
case X_AXIS:
|
2017-03-02 21:54:22 -05:00
|
|
|
_row1._x = 1.0;
|
|
|
|
_row1._y = 0.0;
|
|
|
|
_row1._z = 0.0;
|
|
|
|
_row2._x = 0.0;
|
|
|
|
_row2._y = cosVal;
|
|
|
|
_row2._z = sinVal;
|
|
|
|
_row3._x = 0.0;
|
|
|
|
_row3._y = -sinVal;
|
|
|
|
_row3._z = cosVal;
|
2016-07-16 18:23:25 -04:00
|
|
|
break;
|
|
|
|
|
2017-03-12 20:18:53 -04:00
|
|
|
case Y_AXIS:
|
2017-03-02 21:54:22 -05:00
|
|
|
_row1._x = cosVal;
|
|
|
|
_row1._y = 0.0;
|
2017-08-15 19:31:17 -07:00
|
|
|
_row1._z = -sinVal;
|
2017-03-02 21:54:22 -05:00
|
|
|
_row2._x = 0.0;
|
|
|
|
_row2._y = 1.0;
|
|
|
|
_row2._z = 0.0;
|
2017-08-15 19:31:17 -07:00
|
|
|
_row3._x = sinVal;
|
2017-03-02 21:54:22 -05:00
|
|
|
_row3._y = 0.0;
|
2017-04-04 22:32:01 -04:00
|
|
|
_row3._z = cosVal;
|
2016-07-16 18:23:25 -04:00
|
|
|
break;
|
|
|
|
|
2017-03-12 20:18:53 -04:00
|
|
|
case Z_AXIS:
|
2017-03-02 21:54:22 -05:00
|
|
|
_row1._x = cosVal;
|
|
|
|
_row1._y = sinVal;
|
|
|
|
_row1._z = 0.0;
|
|
|
|
_row2._x = -sinVal;
|
|
|
|
_row2._y = cosVal;
|
|
|
|
_row2._z = 0.0;
|
|
|
|
_row3._x = 0.0;
|
|
|
|
_row3._y = 0.0;
|
|
|
|
_row3._z = 1.0;
|
2016-07-16 18:23:25 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-08 22:05:43 -05:00
|
|
|
_vector.clear();
|
2016-07-16 18:23:25 -04:00
|
|
|
}
|
|
|
|
|
2017-04-05 21:29:32 -04:00
|
|
|
void FPose::copyFrom(const FPose &src) {
|
|
|
|
_row1 = src._row1;
|
|
|
|
_row2 = src._row2;
|
|
|
|
_row3 = src._row3;
|
|
|
|
_vector = src._vector;
|
2016-07-17 16:43:53 -04:00
|
|
|
}
|
|
|
|
|
2017-04-05 21:29:32 -04:00
|
|
|
void FPose::copyFrom(const FMatrix &src) {
|
2017-03-11 14:30:31 -05:00
|
|
|
_row1 = src._row1;
|
|
|
|
_row2 = src._row2;
|
|
|
|
_row3 = src._row3;
|
|
|
|
}
|
|
|
|
|
2017-08-16 19:44:11 -07:00
|
|
|
FPose FPose::inverseTransform() const {
|
2017-04-05 21:29:32 -04:00
|
|
|
FPose result;
|
2017-04-02 10:06:42 -04:00
|
|
|
|
2017-08-16 19:44:11 -07:00
|
|
|
result._row1._x = _row1._x;
|
|
|
|
result._row2._x = _row1._y;
|
|
|
|
result._row3._x = _row1._z;
|
|
|
|
result._row1._y = _row2._x;
|
|
|
|
result._row2._y = _row2._y;
|
|
|
|
result._row3._y = _row2._z;
|
|
|
|
result._row1._z = _row3._x;
|
|
|
|
result._row2._z = _row3._y;
|
|
|
|
result._row3._z = _row3._z;
|
|
|
|
|
|
|
|
result._vector._x = -(_vector._x * result._row1._x
|
|
|
|
+ _vector._y * result._row2._x
|
|
|
|
+ _vector._z * result._row3._x);
|
|
|
|
result._vector._y = -(_vector._x * result._row1._y
|
|
|
|
+ _vector._y * result._row2._y
|
|
|
|
+ _vector._z * result._row3._y);
|
|
|
|
result._vector._z = -(_vector._x * result._row1._z
|
|
|
|
+ _vector._y * result._row2._z
|
|
|
|
+ _vector._z * result._row3._z);
|
2017-04-02 10:06:42 -04:00
|
|
|
|
|
|
|
return result;
|
2017-03-08 23:27:26 -05:00
|
|
|
}
|
|
|
|
|
2016-02-25 08:39:15 -05:00
|
|
|
} // End of namespace Titanic
|