123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- /**
- 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
- */
- #include "math/Mat4.h"
- NS_CC_MATH_BEGIN
- /* --- --- --- --- Add by JJ start --- --- --- --- */
- inline Vec3 Mat4::MultiplyPoint3 (const Vec3& v) const
- {
- Vec3 res;
- res.x = m[0] * v.x + m[4] * v.y + m[ 8] * v.z + m[12];
- res.y = m[1] * v.x + m[5] * v.y + m[ 9] * v.z + m[13];
- res.z = m[2] * v.x + m[6] * v.y + m[10] * v.z + m[14];
- return res;
- }
- inline void Mat4::MultiplyPoint3 (const Vec3& v, Vec3& output) const
- {
- output.x = m[0] * v.x + m[4] * v.y + m[ 8] * v.z + m[12];
- output.y = m[1] * v.x + m[5] * v.y + m[ 9] * v.z + m[13];
- output.z = m[2] * v.x + m[6] * v.y + m[10] * v.z + m[14];
- }
- inline Vec3 Mat4::MultiplyVector3 (const Vec3& v) const
- {
- Vec3 res;
- res.x = m[0] * v.x + m[4] * v.y + m[ 8] * v.z;
- res.y = m[1] * v.x + m[5] * v.y + m[ 9] * v.z;
- res.z = m[2] * v.x + m[6] * v.y + m[10] * v.z;
- return res;
- }
- inline void Mat4::MultiplyVector3 (const Vec3& v, Vec3& output) const
- {
- output.x = m[0] * v.x + m[4] * v.y + m[ 8] * v.z;
- output.y = m[1] * v.x + m[5] * v.y + m[ 9] * v.z;
- output.z = m[2] * v.x + m[6] * v.y + m[10] * v.z;
- }
- inline void Mat4::SetPosition( const Vec3& v ) {
- Get(0,3) = v.x; Get(1,3) = v.y; Get(2,3) = v.z;
- }
- /* --- --- --- --- Add by JJ end --- --- --- --- */
- inline Mat4 Mat4::operator+(const Mat4& mat) const
- {
- Mat4 result(*this);
- result.add(mat);
- return result;
- }
- inline Mat4& Mat4::operator+=(const Mat4& mat)
- {
- add(mat);
- return *this;
- }
- inline Mat4 Mat4::operator-(const Mat4& mat) const
- {
- Mat4 result(*this);
- result.subtract(mat);
- return result;
- }
- inline Mat4& Mat4::operator-=(const Mat4& mat)
- {
- subtract(mat);
- return *this;
- }
- inline Mat4 Mat4::operator-() const
- {
- Mat4 mat(*this);
- mat.negate();
- return mat;
- }
- inline Mat4 Mat4::operator*(const Mat4& mat) const
- {
- Mat4 result(*this);
- result.multiply(mat);
- return result;
- }
- inline Mat4& Mat4::operator*=(const Mat4& mat)
- {
- multiply(mat);
- return *this;
- }
- inline Vec3& operator*=(Vec3& v, const Mat4& m)
- {
- m.transformVector(&v);
- return v;
- }
- inline Vec3 operator*(const Mat4& m, const Vec3& v)
- {
- Vec3 x;
- m.transformVector(v, &x);
- return x;
- }
- inline Vec4& operator*=(Vec4& v, const Mat4& m)
- {
- m.transformVector(&v);
- return v;
- }
- inline Vec4 operator*(const Mat4& m, const Vec4& v)
- {
- Vec4 x;
- m.transformVector(v, &x);
- return x;
- }
- NS_CC_MATH_END
|