2014-04-30 08:50:12 +08:00
|
|
|
/**
|
|
|
|
Copyright 2013 BlackBerry Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
Original file from GamePlay3D: http://gameplay3d.org
|
|
|
|
|
|
|
|
This file was modified to fit the cocos2d-x project
|
|
|
|
*/
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
#ifndef MATH_MAT4_H
|
|
|
|
#define MATH_MAT4_H
|
2014-04-02 10:33:07 +08:00
|
|
|
|
2014-05-17 05:36:00 +08:00
|
|
|
#include "math/Vec3.h"
|
|
|
|
#include "math/Vec4.h"
|
2014-04-02 10:33:07 +08:00
|
|
|
|
2014-04-02 12:09:51 +08:00
|
|
|
NS_CC_MATH_BEGIN
|
2014-04-02 10:33:07 +08:00
|
|
|
|
2014-04-02 11:21:48 +08:00
|
|
|
//class Plane;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines a 4 x 4 floating point matrix representing a 3D transformation.
|
|
|
|
*
|
|
|
|
* Vectors are treated as columns, resulting in a matrix that is represented as follows,
|
|
|
|
* where x, y and z are the translation components of the matrix:
|
|
|
|
*
|
|
|
|
* 1 0 0 x
|
|
|
|
* 0 1 0 y
|
|
|
|
* 0 0 1 z
|
|
|
|
* 0 0 0 1
|
|
|
|
*
|
|
|
|
* This matrix class is directly compatible with OpenGL since its elements are
|
|
|
|
* laid out in memory exactly as they are expected by OpenGL.
|
|
|
|
* The matrix uses column-major format such that array indices increase down column first.
|
|
|
|
* Since matrix multiplication is not commutative, multiplication must be done in the
|
|
|
|
* correct order when combining transformations. Suppose we have a translation
|
|
|
|
* matrix T and a rotation matrix R. To first rotate an object around the origin
|
|
|
|
* and then translate it, you would multiply the two matrices as TR.
|
|
|
|
*
|
|
|
|
* Likewise, to first translate the object and then rotate it, you would do RT.
|
|
|
|
* So generally, matrices must be multiplied in the reverse order in which you
|
|
|
|
* want the transformations to take place (this also applies to
|
|
|
|
* the scale, rotate, and translate methods below; these methods are convenience
|
|
|
|
* methods for post-multiplying by a matrix representing a scale, rotation, or translation).
|
|
|
|
*
|
|
|
|
* In the case of repeated local transformations (i.e. rotate around the Z-axis by 0.76 radians,
|
|
|
|
* then translate by 2.1 along the X-axis, then ...), it is better to use the Transform class
|
|
|
|
* (which is optimized for that kind of usage).
|
|
|
|
*
|
|
|
|
* @see Transform
|
|
|
|
*/
|
2014-07-14 16:40:54 +08:00
|
|
|
class CC_DLL Mat4
|
2014-04-02 10:33:07 +08:00
|
|
|
{
|
|
|
|
public:
|
2014-04-14 17:49:45 +08:00
|
|
|
// //temp add conversion
|
|
|
|
// operator kmMat4() const
|
|
|
|
// {
|
|
|
|
// kmMat4 result;
|
|
|
|
// kmMat4Fill(&result, m);
|
|
|
|
// return result;
|
|
|
|
// }
|
2014-04-04 17:58:37 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
// Mat4(const kmMat4& mat)
|
2014-04-14 17:49:45 +08:00
|
|
|
// {
|
|
|
|
// set(mat.mat);
|
|
|
|
// }
|
2014-04-02 10:33:07 +08:00
|
|
|
/**
|
|
|
|
* Stores the columns of this 4x4 matrix.
|
|
|
|
* */
|
|
|
|
float m[16];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a matrix initialized to the identity matrix:
|
|
|
|
*
|
|
|
|
* 1 0 0 0
|
|
|
|
* 0 1 0 0
|
|
|
|
* 0 0 1 0
|
|
|
|
* 0 0 0 1
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4();
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a matrix initialized to the specified value.
|
|
|
|
*
|
|
|
|
* @param m11 The first element of the first row.
|
|
|
|
* @param m12 The second element of the first row.
|
|
|
|
* @param m13 The third element of the first row.
|
|
|
|
* @param m14 The fourth element of the first row.
|
|
|
|
* @param m21 The first element of the second row.
|
|
|
|
* @param m22 The second element of the second row.
|
|
|
|
* @param m23 The third element of the second row.
|
|
|
|
* @param m24 The fourth element of the second row.
|
|
|
|
* @param m31 The first element of the third row.
|
|
|
|
* @param m32 The second element of the third row.
|
|
|
|
* @param m33 The third element of the third row.
|
|
|
|
* @param m34 The fourth element of the third row.
|
|
|
|
* @param m41 The first element of the fourth row.
|
|
|
|
* @param m42 The second element of the fourth row.
|
|
|
|
* @param m43 The third element of the fourth row.
|
|
|
|
* @param m44 The fourth element of the fourth row.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24,
|
2014-04-02 10:33:07 +08:00
|
|
|
float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a matrix initialized to the specified column-major array.
|
|
|
|
*
|
|
|
|
* The passed-in array is in column-major order, so the memory layout of the array is as follows:
|
|
|
|
*
|
|
|
|
* 0 4 8 12
|
|
|
|
* 1 5 9 13
|
|
|
|
* 2 6 10 14
|
|
|
|
* 3 7 11 15
|
|
|
|
*
|
2014-04-16 10:42:39 +08:00
|
|
|
* @param mat An array containing 16 elements in column-major order.
|
2014-04-02 10:33:07 +08:00
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4(const float* mat);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a new matrix by copying the values from the specified matrix.
|
|
|
|
*
|
|
|
|
* @param copy The matrix to copy.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4(const Mat4& copy);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
~Mat4();
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a view matrix based on the specified input parameters.
|
|
|
|
*
|
|
|
|
* @param eyePosition The eye position.
|
|
|
|
* @param targetPosition The target's center position.
|
|
|
|
* @param up The up vector.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void createLookAt(const Vec3& eyePosition, const Vec3& targetPosition, const Vec3& up, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a view matrix based on the specified input parameters.
|
|
|
|
*
|
|
|
|
* @param eyePositionX The eye x-coordinate position.
|
|
|
|
* @param eyePositionY The eye y-coordinate position.
|
|
|
|
* @param eyePositionZ The eye z-coordinate position.
|
|
|
|
* @param targetCenterX The target's center x-coordinate position.
|
|
|
|
* @param targetCenterY The target's center y-coordinate position.
|
|
|
|
* @param targetCenterZ The target's center z-coordinate position.
|
|
|
|
* @param upX The up vector x-coordinate value.
|
|
|
|
* @param upY The up vector y-coordinate value.
|
|
|
|
* @param upZ The up vector z-coordinate value.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
|
|
|
static void createLookAt(float eyePositionX, float eyePositionY, float eyePositionZ,
|
|
|
|
float targetCenterX, float targetCenterY, float targetCenterZ,
|
2014-05-15 01:07:09 +08:00
|
|
|
float upX, float upY, float upZ, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds a perspective projection matrix based on a field of view and returns by value.
|
|
|
|
*
|
|
|
|
* Projection space refers to the space after applying projection transformation from view space.
|
|
|
|
* After the projection transformation, visible content has x- and y-coordinates ranging from -1 to 1,
|
|
|
|
* and a z-coordinate ranging from 0 to 1. To obtain the viewable area (in world space) of a scene,
|
|
|
|
* create a BoundingFrustum and pass the combined view and projection matrix to the constructor.
|
|
|
|
*
|
|
|
|
* @param fieldOfView The field of view in the y direction (in degrees).
|
|
|
|
* @param aspectRatio The aspect ratio, defined as view space width divided by height.
|
|
|
|
* @param zNearPlane The distance to the near view plane.
|
|
|
|
* @param zFarPlane The distance to the far view plane.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void createPerspective(float fieldOfView, float aspectRatio, float zNearPlane, float zFarPlane, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an orthographic projection matrix.
|
|
|
|
*
|
|
|
|
* @param width The width of the view.
|
|
|
|
* @param height The height of the view.
|
|
|
|
* @param zNearPlane The minimum z-value of the view volume.
|
|
|
|
* @param zFarPlane The maximum z-value of the view volume.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void createOrthographic(float width, float height, float zNearPlane, float zFarPlane, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an orthographic projection matrix.
|
|
|
|
*
|
|
|
|
* Projection space refers to the space after applying
|
|
|
|
* projection transformation from view space. After the
|
|
|
|
* projection transformation, visible content has
|
|
|
|
* x and y coordinates ranging from -1 to 1, and z coordinates
|
|
|
|
* ranging from 0 to 1.
|
|
|
|
*
|
|
|
|
* Unlike perspective projection, in orthographic projection
|
|
|
|
* there is no perspective foreshortening.
|
|
|
|
*
|
|
|
|
* The viewable area of this orthographic projection extends
|
|
|
|
* from left to right on the x-axis, bottom to top on the y-axis,
|
|
|
|
* and zNearPlane to zFarPlane on the z-axis. These values are
|
|
|
|
* relative to the position and x, y, and z-axes of the view.
|
|
|
|
* To obtain the viewable area (in world space) of a scene,
|
|
|
|
* create a BoundingFrustum and pass the combined view and
|
|
|
|
* projection matrix to the constructor.
|
|
|
|
*
|
|
|
|
* @param left The minimum x-value of the view volume.
|
|
|
|
* @param right The maximum x-value of the view volume.
|
|
|
|
* @param bottom The minimum y-value of the view volume.
|
|
|
|
* @param top The maximum y-value of the view volume.
|
|
|
|
* @param zNearPlane The minimum z-value of the view volume.
|
|
|
|
* @param zFarPlane The maximum z-value of the view volume.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
|
|
|
static void createOrthographicOffCenter(float left, float right, float bottom, float top,
|
2014-05-15 01:07:09 +08:00
|
|
|
float zNearPlane, float zFarPlane, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a spherical billboard that rotates around a specified object position.
|
|
|
|
*
|
|
|
|
* This method computes the facing direction of the billboard from the object position
|
|
|
|
* and camera position. When the object and camera positions are too close, the matrix
|
|
|
|
* will not be accurate. To avoid this problem, this method defaults to the identity
|
|
|
|
* rotation if the positions are too close. (See the other overload of createBillboard
|
|
|
|
* for an alternative approach).
|
|
|
|
*
|
|
|
|
* @param objectPosition The position of the object the billboard will rotate around.
|
|
|
|
* @param cameraPosition The position of the camera.
|
|
|
|
* @param cameraUpVector The up vector of the camera.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void createBillboard(const Vec3& objectPosition, const Vec3& cameraPosition,
|
|
|
|
const Vec3& cameraUpVector, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a spherical billboard that rotates around a specified object position with
|
|
|
|
* provision for a safe default orientation.
|
|
|
|
*
|
|
|
|
* This method computes the facing direction of the billboard from the object position
|
|
|
|
* and camera position. When the object and camera positions are too close, the matrix
|
|
|
|
* will not be accurate. To avoid this problem, this method uses the specified camera
|
|
|
|
* forward vector if the positions are too close. (See the other overload of createBillboard
|
|
|
|
* for an alternative approach).
|
|
|
|
*
|
|
|
|
* @param objectPosition The position of the object the billboard will rotate around.
|
|
|
|
* @param cameraPosition The position of the camera.
|
|
|
|
* @param cameraUpVector The up vector of the camera.
|
|
|
|
* @param cameraForwardVector The forward vector of the camera, used if the positions are too close.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void createBillboard(const Vec3& objectPosition, const Vec3& cameraPosition,
|
|
|
|
const Vec3& cameraUpVector, const Vec3& cameraForwardVector,
|
|
|
|
Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
2014-05-15 01:07:09 +08:00
|
|
|
* Fills in an existing Mat4 so that it reflects the coordinate system about a specified Plane.
|
2014-04-02 10:33:07 +08:00
|
|
|
*
|
|
|
|
* @param plane The Plane about which to create a reflection.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
//static void createReflection(const Plane& plane, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a scale matrix.
|
|
|
|
*
|
|
|
|
* @param scale The amount to scale.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void createScale(const Vec3& scale, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a scale matrix.
|
|
|
|
*
|
|
|
|
* @param xScale The amount to scale along the x-axis.
|
|
|
|
* @param yScale The amount to scale along the y-axis.
|
|
|
|
* @param zScale The amount to scale along the z-axis.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void createScale(float xScale, float yScale, float zScale, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a rotation matrix from the specified quaternion.
|
|
|
|
*
|
|
|
|
* @param quat A quaternion describing a 3D orientation.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void createRotation(const Quaternion& quat, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a rotation matrix from the specified axis and angle.
|
|
|
|
*
|
|
|
|
* @param axis A vector describing the axis to rotate about.
|
|
|
|
* @param angle The angle (in radians).
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void createRotation(const Vec3& axis, float angle, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a matrix describing a rotation around the x-axis.
|
|
|
|
*
|
|
|
|
* @param angle The angle of rotation (in radians).
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void createRotationX(float angle, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a matrix describing a rotation around the y-axis.
|
|
|
|
*
|
|
|
|
* @param angle The angle of rotation (in radians).
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void createRotationY(float angle, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a matrix describing a rotation around the z-axis.
|
|
|
|
*
|
|
|
|
* @param angle The angle of rotation (in radians).
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void createRotationZ(float angle, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a translation matrix.
|
|
|
|
*
|
|
|
|
* @param translation The translation.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void createTranslation(const Vec3& translation, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a translation matrix.
|
|
|
|
*
|
|
|
|
* @param xTranslation The translation on the x-axis.
|
|
|
|
* @param yTranslation The translation on the y-axis.
|
|
|
|
* @param zTranslation The translation on the z-axis.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void createTranslation(float xTranslation, float yTranslation, float zTranslation, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a scalar value to each component of this matrix.
|
|
|
|
*
|
|
|
|
* @param scalar The scalar to add.
|
|
|
|
*/
|
|
|
|
void add(float scalar);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a scalar value to each component of this matrix and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param scalar The scalar value to add.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void add(float scalar, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the specified matrix to this matrix.
|
|
|
|
*
|
2014-04-16 10:42:39 +08:00
|
|
|
* @param mat The matrix to add.
|
2014-04-02 10:33:07 +08:00
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void add(const Mat4& mat);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the specified matrices and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param m1 The first matrix.
|
|
|
|
* @param m2 The second matrix.
|
|
|
|
* @param dst The destination matrix to add to.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void add(const Mat4& m1, const Mat4& m2, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decomposes the scale, rotation and translation components of this matrix.
|
|
|
|
*
|
|
|
|
* @param scale The scale.
|
|
|
|
* @param rotation The rotation.
|
|
|
|
* @param translation The translation.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
bool decompose(Vec3* scale, Quaternion* rotation, Vec3* translation) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes the determinant of this matrix.
|
|
|
|
*
|
|
|
|
* @return The determinant.
|
|
|
|
*/
|
|
|
|
float determinant() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the scalar component of this matrix in the specified vector.
|
|
|
|
*
|
|
|
|
* If the scalar component of this matrix has negative parts,
|
|
|
|
* it is not possible to always extract the exact scalar component;
|
|
|
|
* instead, a scale vector that is mathematically equivalent to the
|
|
|
|
* original scale vector is extracted and returned.
|
|
|
|
*
|
|
|
|
* @param scale A vector to receive the scale.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void getScale(Vec3* scale) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the rotational component of this matrix in the specified quaternion.
|
|
|
|
*
|
|
|
|
* @param rotation A quaternion to receive the rotation.
|
|
|
|
*
|
|
|
|
* @return true if the rotation is successfully extracted, false otherwise.
|
|
|
|
*/
|
|
|
|
bool getRotation(Quaternion* rotation) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the translational component of this matrix in the specified vector.
|
|
|
|
*
|
|
|
|
* @param translation A vector to receive the translation.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void getTranslation(Vec3* translation) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the up vector of this matrix.
|
|
|
|
*
|
|
|
|
* @param dst The destination vector.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void getUpVector(Vec3* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the down vector of this matrix.
|
|
|
|
*
|
|
|
|
* @param dst The destination vector.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void getDownVector(Vec3* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the left vector of this matrix.
|
|
|
|
*
|
|
|
|
* @param dst The destination vector.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void getLeftVector(Vec3* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the right vector of this matrix.
|
|
|
|
*
|
|
|
|
* @param dst The destination vector.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void getRightVector(Vec3* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the forward vector of this matrix.
|
|
|
|
*
|
|
|
|
* @param dst The destination vector.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void getForwardVector(Vec3* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the backward vector of this matrix.
|
|
|
|
*
|
|
|
|
* @param dst The destination vector.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void getBackVector(Vec3* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Inverts this matrix.
|
|
|
|
*
|
|
|
|
* @return true if the the matrix can be inverted, false otherwise.
|
|
|
|
*/
|
2014-05-01 01:59:36 +08:00
|
|
|
bool inverse();
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the inverse of this matrix in the specified matrix.
|
|
|
|
*
|
|
|
|
* @param dst A matrix to store the invert of this matrix in.
|
|
|
|
*
|
|
|
|
* @return true if the the matrix can be inverted, false otherwise.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 getInversed() const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if this matrix is equal to the identity matrix.
|
|
|
|
*
|
|
|
|
* @return true if the matrix is an identity matrix, false otherwise.
|
|
|
|
*/
|
|
|
|
bool isIdentity() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiplies the components of this matrix by the specified scalar.
|
|
|
|
*
|
|
|
|
* @param scalar The scalar value.
|
|
|
|
*/
|
|
|
|
void multiply(float scalar);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiplies the components of this matrix by a scalar and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param scalar The scalar value.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void multiply(float scalar, Mat4* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiplies the components of the specified matrix by a scalar and stores the result in dst.
|
|
|
|
*
|
2014-04-16 10:42:39 +08:00
|
|
|
* @param mat The matrix.
|
2014-04-02 10:33:07 +08:00
|
|
|
* @param scalar The scalar value.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void multiply(const Mat4& mat, float scalar, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiplies this matrix by the specified one.
|
|
|
|
*
|
2014-04-16 10:42:39 +08:00
|
|
|
* @param mat The matrix to multiply.
|
2014-04-02 10:33:07 +08:00
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void multiply(const Mat4& mat);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiplies m1 by m2 and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param m1 The first matrix to multiply.
|
|
|
|
* @param m2 The second matrix to multiply.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void multiply(const Mat4& m1, const Mat4& m2, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Negates this matrix.
|
|
|
|
*/
|
|
|
|
void negate();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Negates this matrix and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 getNegated() const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified quaternion rotation.
|
|
|
|
*
|
|
|
|
* @param q The quaternion to rotate by.
|
|
|
|
*/
|
|
|
|
void rotate(const Quaternion& q);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified quaternion rotation and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param q The quaternion to rotate by.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void rotate(const Quaternion& q, Mat4* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified rotation about the specified axis.
|
|
|
|
*
|
|
|
|
* @param axis The axis to rotate about.
|
|
|
|
* @param angle The angle (in radians).
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void rotate(const Vec3& axis, float angle);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the specified
|
|
|
|
* rotation about the specified axis and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param axis The axis to rotate about.
|
|
|
|
* @param angle The angle (in radians).
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void rotate(const Vec3& axis, float angle, Mat4* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified rotation around the x-axis.
|
|
|
|
*
|
|
|
|
* @param angle The angle (in radians).
|
|
|
|
*/
|
|
|
|
void rotateX(float angle);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified rotation around the x-axis and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param angle The angle (in radians).
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void rotateX(float angle, Mat4* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified rotation around the y-axis.
|
|
|
|
*
|
|
|
|
* @param angle The angle (in radians).
|
|
|
|
*/
|
|
|
|
void rotateY(float angle);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified rotation around the y-axis and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param angle The angle (in radians).
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void rotateY(float angle, Mat4* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified rotation around the z-axis.
|
|
|
|
*
|
|
|
|
* @param angle The angle (in radians).
|
|
|
|
*/
|
|
|
|
void rotateZ(float angle);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified rotation around the z-axis and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param angle The angle (in radians).
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void rotateZ(float angle, Mat4* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified scale transformation.
|
|
|
|
*
|
|
|
|
* @param value The amount to scale along all axes.
|
|
|
|
*/
|
|
|
|
void scale(float value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified scale transformation and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param value The amount to scale along all axes.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void scale(float value, Mat4* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified scale transformation.
|
|
|
|
*
|
|
|
|
* @param xScale The amount to scale along the x-axis.
|
|
|
|
* @param yScale The amount to scale along the y-axis.
|
|
|
|
* @param zScale The amount to scale along the z-axis.
|
|
|
|
*/
|
|
|
|
void scale(float xScale, float yScale, float zScale);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified scale transformation and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param xScale The amount to scale along the x-axis.
|
|
|
|
* @param yScale The amount to scale along the y-axis.
|
|
|
|
* @param zScale The amount to scale along the z-axis.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void scale(float xScale, float yScale, float zScale, Mat4* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified scale transformation.
|
|
|
|
*
|
|
|
|
* @param s The scale values along the x, y and z axes.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void scale(const Vec3& s);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified scale transformation and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param s The scale values along the x, y and z axes.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void scale(const Vec3& s, Mat4* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the values of this matrix.
|
|
|
|
*
|
|
|
|
* @param m11 The first element of the first row.
|
|
|
|
* @param m12 The second element of the first row.
|
|
|
|
* @param m13 The third element of the first row.
|
|
|
|
* @param m14 The fourth element of the first row.
|
|
|
|
* @param m21 The first element of the second row.
|
|
|
|
* @param m22 The second element of the second row.
|
|
|
|
* @param m23 The third element of the second row.
|
|
|
|
* @param m24 The fourth element of the second row.
|
|
|
|
* @param m31 The first element of the third row.
|
|
|
|
* @param m32 The second element of the third row.
|
|
|
|
* @param m33 The third element of the third row.
|
|
|
|
* @param m34 The fourth element of the third row.
|
|
|
|
* @param m41 The first element of the fourth row.
|
|
|
|
* @param m42 The second element of the fourth row.
|
|
|
|
* @param m43 The third element of the fourth row.
|
|
|
|
* @param m44 The fourth element of the fourth row.
|
|
|
|
*/
|
|
|
|
void set(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24,
|
|
|
|
float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the values of this matrix to those in the specified column-major array.
|
|
|
|
*
|
2014-04-16 10:42:39 +08:00
|
|
|
* @param mat An array containing 16 elements in column-major format.
|
2014-04-02 10:33:07 +08:00
|
|
|
*/
|
2014-04-16 10:42:39 +08:00
|
|
|
void set(const float* mat);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the values of this matrix to those of the specified matrix.
|
|
|
|
*
|
2014-04-16 10:42:39 +08:00
|
|
|
* @param mat The source matrix.
|
2014-04-02 10:33:07 +08:00
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void set(const Mat4& mat);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets this matrix to the identity matrix.
|
|
|
|
*/
|
|
|
|
void setIdentity();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets all elements of the current matrix to zero.
|
|
|
|
*/
|
|
|
|
void setZero();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtracts the specified matrix from the current matrix.
|
|
|
|
*
|
2014-04-16 10:42:39 +08:00
|
|
|
* @param mat The matrix to subtract.
|
2014-04-02 10:33:07 +08:00
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void subtract(const Mat4& mat);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtracts the specified matrix from the current matrix.
|
|
|
|
*
|
|
|
|
* @param m1 The first matrix.
|
|
|
|
* @param m2 The second matrix.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static void subtract(const Mat4& m1, const Mat4& m2, Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms the specified point by this matrix.
|
|
|
|
*
|
|
|
|
* The result of the transformation is stored directly into point.
|
|
|
|
*
|
|
|
|
* @param point The point to transform and also a vector to hold the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void transformPoint(Vec3* point) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms the specified point by this matrix, and stores
|
|
|
|
* the result in dst.
|
|
|
|
*
|
|
|
|
* @param point The point to transform.
|
|
|
|
* @param dst A vector to store the transformed point in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void transformPoint(const Vec3& point, Vec3* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms the specified vector by this matrix by
|
|
|
|
* treating the fourth (w) coordinate as zero.
|
|
|
|
*
|
|
|
|
* The result of the transformation is stored directly into vector.
|
|
|
|
*
|
|
|
|
* @param vector The vector to transform and also a vector to hold the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void transformVector(Vec3* vector) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms the specified vector by this matrix by
|
|
|
|
* treating the fourth (w) coordinate as zero, and stores the
|
|
|
|
* result in dst.
|
|
|
|
*
|
|
|
|
* @param vector The vector to transform.
|
|
|
|
* @param dst A vector to store the transformed vector in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void transformVector(const Vec3& vector, Vec3* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms the specified vector by this matrix.
|
|
|
|
*
|
|
|
|
* @param x The vector x-coordinate to transform by.
|
|
|
|
* @param y The vector y-coordinate to transform by.
|
|
|
|
* @param z The vector z-coordinate to transform by.
|
|
|
|
* @param w The vector w-coordinate to transform by.
|
|
|
|
* @param dst A vector to store the transformed point in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void transformVector(float x, float y, float z, float w, Vec3* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms the specified vector by this matrix.
|
|
|
|
*
|
|
|
|
* The result of the transformation is stored directly into vector.
|
|
|
|
*
|
|
|
|
* @param vector The vector to transform.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void transformVector(Vec4* vector) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms the specified vector by this matrix.
|
|
|
|
*
|
|
|
|
* @param vector The vector to transform.
|
|
|
|
* @param dst A vector to store the transformed point in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void transformVector(const Vec4& vector, Vec4* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified translation.
|
|
|
|
*
|
|
|
|
* @param x The amount to translate along the x-axis.
|
|
|
|
* @param y The amount to translate along the y-axis.
|
|
|
|
* @param z The amount to translate along the z-axis.
|
|
|
|
*/
|
|
|
|
void translate(float x, float y, float z);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified translation and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param x The amount to translate along the x-axis.
|
|
|
|
* @param y The amount to translate along the y-axis.
|
|
|
|
* @param z The amount to translate along the z-axis.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void translate(float x, float y, float z, Mat4* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified translation.
|
|
|
|
*
|
|
|
|
* @param t The translation values along the x, y and z axes.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void translate(const Vec3& t);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-multiplies this matrix by the matrix corresponding to the
|
|
|
|
* specified translation and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param t The translation values along the x, y and z axes.
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void translate(const Vec3& t, Mat4* dst) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transposes this matrix.
|
|
|
|
*/
|
|
|
|
void transpose();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transposes this matrix and stores the result in dst.
|
|
|
|
*
|
|
|
|
* @param dst A matrix to store the result in.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 getTransposed() const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the sum of this matrix with the given matrix.
|
|
|
|
*
|
|
|
|
* Note: this does not modify this matrix.
|
|
|
|
*
|
2014-04-16 10:42:39 +08:00
|
|
|
* @param mat The matrix to add.
|
2014-04-02 10:33:07 +08:00
|
|
|
* @return The matrix sum.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
inline const Mat4 operator+(const Mat4& mat) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the given matrix to this matrix.
|
|
|
|
*
|
2014-04-16 10:42:39 +08:00
|
|
|
* @param mat The matrix to add.
|
2014-04-02 10:33:07 +08:00
|
|
|
* @return This matrix, after the addition occurs.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
inline Mat4& operator+=(const Mat4& mat);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the difference of this matrix with the given matrix.
|
|
|
|
*
|
|
|
|
* Note: this does not modify this matrix.
|
|
|
|
*
|
2014-04-16 10:42:39 +08:00
|
|
|
* @param mat The matrix to subtract.
|
2014-04-02 10:33:07 +08:00
|
|
|
* @return The matrix difference.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
inline const Mat4 operator-(const Mat4& mat) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtracts the given matrix from this matrix.
|
|
|
|
*
|
2014-04-16 10:42:39 +08:00
|
|
|
* @param mat The matrix to subtract.
|
2014-04-02 10:33:07 +08:00
|
|
|
* @return This matrix, after the subtraction occurs.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
inline Mat4& operator-=(const Mat4& mat);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the negation of this matrix.
|
|
|
|
*
|
|
|
|
* Note: this does not modify this matrix.
|
|
|
|
*
|
|
|
|
* @return The negation of this matrix.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
inline const Mat4 operator-() const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the matrix product of this matrix with the given matrix.
|
|
|
|
*
|
|
|
|
* Note: this does not modify this matrix.
|
|
|
|
*
|
2014-04-16 10:42:39 +08:00
|
|
|
* @param mat The matrix to multiply by.
|
2014-04-02 10:33:07 +08:00
|
|
|
* @return The matrix product.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
inline const Mat4 operator*(const Mat4& mat) const;
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Right-multiplies this matrix by the given matrix.
|
|
|
|
*
|
2014-04-16 10:42:39 +08:00
|
|
|
* @param mat The matrix to multiply by.
|
2014-04-02 10:33:07 +08:00
|
|
|
* @return This matrix, after the multiplication occurs.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
inline Mat4& operator*=(const Mat4& mat);
|
2014-05-14 01:26:25 +08:00
|
|
|
|
|
|
|
/** equals to a matrix full of zeros */
|
2014-05-15 01:07:09 +08:00
|
|
|
static const Mat4 ZERO;
|
2014-05-14 01:26:25 +08:00
|
|
|
/** equals to the identity matrix */
|
2014-05-15 01:07:09 +08:00
|
|
|
static const Mat4 IDENTITY;
|
2014-05-14 01:26:25 +08:00
|
|
|
|
2014-04-02 10:33:07 +08:00
|
|
|
private:
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
static void createBillboardHelper(const Vec3& objectPosition, const Vec3& cameraPosition,
|
|
|
|
const Vec3& cameraUpVector, const Vec3* cameraForwardVector,
|
|
|
|
Mat4* dst);
|
2014-04-02 10:33:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms the given vector by the given matrix.
|
|
|
|
*
|
|
|
|
* Note: this treats the given vector as a vector and not as a point.
|
|
|
|
*
|
|
|
|
* @param v The vector to transform.
|
|
|
|
* @param m The matrix to transform by.
|
|
|
|
* @return This vector, after the transformation occurs.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
inline Vec3& operator*=(Vec3& v, const Mat4& m);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms the given vector by the given matrix.
|
|
|
|
*
|
|
|
|
* Note: this treats the given vector as a vector and not as a point.
|
|
|
|
*
|
|
|
|
* @param m The matrix to transform by.
|
|
|
|
* @param v The vector to transform.
|
|
|
|
* @return The resulting transformed vector.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
inline const Vec3 operator*(const Mat4& m, const Vec3& v);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms the given vector by the given matrix.
|
|
|
|
*
|
|
|
|
* Note: this treats the given vector as a vector and not as a point.
|
|
|
|
*
|
|
|
|
* @param v The vector to transform.
|
|
|
|
* @param m The matrix to transform by.
|
|
|
|
* @return This vector, after the transformation occurs.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
inline Vec4& operator*=(Vec4& v, const Mat4& m);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms the given vector by the given matrix.
|
|
|
|
*
|
|
|
|
* Note: this treats the given vector as a vector and not as a point.
|
|
|
|
*
|
|
|
|
* @param m The matrix to transform by.
|
|
|
|
* @param v The vector to transform.
|
|
|
|
* @return The resulting transformed vector.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
inline const Vec4 operator*(const Mat4& m, const Vec4& v);
|
2014-04-02 10:33:07 +08:00
|
|
|
|
2014-04-02 12:09:51 +08:00
|
|
|
NS_CC_MATH_END
|
2014-04-02 10:33:07 +08:00
|
|
|
|
2014-05-17 05:36:00 +08:00
|
|
|
#include "math/Mat4.inl"
|
2014-04-02 10:33:07 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
#endif // MATH_MAT4_H
|