コード例 #1
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateNormal()
{
	return Matrix43(0.5f,0.f,0.f,
		0.0f,0.5f,0.f,
		0.0f,0.f,0.5f,
		0.5f,0.5f,0.5f);
}
コード例 #2
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateProjectToXY()
{
	return Matrix43(1.f,0.f,0.f,
		0.f,1.f,0.f,
		0.f,0.f,0.f,
		0.f,0.f,0.f);
}
コード例 #3
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateProjectToYZ()
{
	return Matrix43(0.f,0.f,0.f,
		0.f,1.f,0.f,
		0.f,0.f,1.f,
		0.f,0.f,0.f);
}
コード例 #4
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateScale( const Scale3F& scale )
{
	return Matrix43(scale.X,0.f,0.f,
		0.f,scale.Y,0.f,
		0.f,0.f,scale.Z,
		0.f,0.f,0.f);
}
コード例 #5
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateFlipX()
{
	return Matrix43(-1.f,0.f,0.f,
		0.f,1.f,0.f,
		0.f,0.f,1.f,
		0.f,0.f,0.f);
}
コード例 #6
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateTranspose()
{
	return Matrix43(M11,M21,M31,
		M12,M22,M32,
		M13,M23,M33,
		0.f,0.f,0.f);
}
コード例 #7
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateTranslate( const Point3F& point )
{
	return Matrix43(1.f,0.f,0.f,
		0.f,1.f,0.f,
		0.f,0.f,1.f,
		point.X,point.Y,point.Z);
}
コード例 #8
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateFlipZ()
{
	return Matrix43(1.f,0.f,0.f,
		0.f,1.f,0.f,
		0.f,0.f,-1.f,
		0.f,0.f,0.f);
}
コード例 #9
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateFromQuaternion( const Quaternion& q )
{
	/*
	Quaternion and matrix can be converted to each other
	often:

	[ ww+xx-yy-zz , 2xy-2wz , 2xz+2wy ]
	[ 2xy+2wz , ww-xx-yy-zz , 2yz-2wx ]
	[ 2xz-2wy , 2yz+2wx , ww-xx-yy-zz ]

	But with normalized Quaternion, Could be simplifed to :

	[ 1-2yy-2zz , 2xy-2wz , 2xz+2wy ]
	[ 2xy+2wz , 1-2xx-2zz , 2yz-2wx ]
	[ 2xz-2wy , 2yz+2wx , 1-2xx-2yy ]

	*/
	float xx=q.X*q.X;
	float yy=q.Y*q.Y;
	float zz=q.Z*q.Z;
	float xy=q.X*q.Y;
	float xz=q.X*q.Z;
	float yz=q.Y*q.Z;
	float wx=q.W*q.X;
	float wy=q.W*q.Y;
	float wz=q.W*q.Z;

	return Matrix43(1.f - 2.f*(yy + zz), 2.f*(xy - wz), 2.f*(xz + wy),
		2.f*(xy + wz), 1 - 2.f*(xx + zz), 2.f*(yz - wx),
		2.f*(xz - wy), 2.f*(yz + wx), 1 - 2.f*(xx + yy), 
		0.f, 0.f, 0.f);
}
コード例 #10
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateShear( float xy,float xz,float yx,float yz,float zx,float zy )
{
	return Matrix43(1.f,yx,zx,
		xy,1.f,zy,
		xz,yz,1.f,
		0.f,0.f,0.f);
}
コード例 #11
0
 static Matrix43 translation(Vector3<T> const& displacement) {
     return Matrix43(
                   T(1),           T(0),           T(0),
                   T(0),           T(1),           T(0),
                   T(0),           T(0),           T(1),
         displacement.x, displacement.y, displacement.z
     );
 }
コード例 #12
0
 static Matrix43 scaling(Extent3<T> const& factor) {
     return Matrix43(
         factor.x,     T(0),     T(0),
             T(0), factor.y,     T(0),
             T(0),     T(0), factor.z,
             T(0),     T(0),     T(0)
     );
 }
コード例 #13
0
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
Matrix43 ManagerImplemented::GetBaseMatrix( Handle handle )
{
	if( m_DrawSets.count( handle ) > 0 )
	{
		return m_DrawSets[handle].BaseMatrix;
	}

	return Matrix43();
}
コード例 #14
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateRotateZ( float radian )
{
	float cosZ=Math::Cos(radian);
	float sinZ=Math::Sin(radian);

	return Matrix43(cosZ,sinZ,0.f,
		-sinZ,cosZ,0.f,
		0.f,0.f,1.f,
		0.f,0.f,0.f);
}
コード例 #15
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateRotateX( float radian )
{
	float cosX=Math::Cos(radian);
	float sinX=Math::Sin(radian);

	return Matrix43(	1.f,0.f,0.f,
		0.f,cosX,sinX,
		0.f,-sinX,cosX,
		0.f,0.f,0.f);
}
コード例 #16
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateRotateY( float radian )
{
	float cosY=Math::Cos(radian);
	float sinY=Math::Sin(radian);

	return Matrix43(cosY,0.f,-sinY,
		0.f,1.f,0.f,
		sinY,0.f,cosY,
		0.f,0.f,0.f);
}
コード例 #17
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateFlipByPlane( const Point3F& normal )
{
	float xy2=normal.X*normal.Y*2.f;
	float yz2=normal.Y*normal.Z*2.f;
	float xz2=normal.X*normal.Z*2.f;
	float xx2=normal.X*normal.X*2.f;
	float yy2=normal.Y*normal.Y*2.f;
	float zz2=normal.Z*normal.Z*2.f;

	return Matrix43(1-xx2,-xy2,-xz2,
		-xy2,1-yy2,-yz2,
		-xz2,-yz2,1-zz2,
		0.f,0.f,0.f);
}
コード例 #18
0
        static Matrix43 rotation(Vector3<T> const& axis, T angle) {
            T s = sin(angle);
            T c = cos(angle); T k = T(1) - c;

            Vector3<T> ak = axis * k;
            Vector3<T> as = axis * s;

            return Matrix43(
                ak.x * axis.x +    c, ak.x * axis.y + as.z, ak.x * axis.z - as.y,
                ak.x * axis.y - as.z, ak.y * axis.y +    c, ak.y * axis.z + as.x,
                ak.x * axis.z + as.y, ak.y * axis.z - as.x, ak.z * axis.z +    c,
                                T(0),                 T(0),                 T(0)
            );
        }
コード例 #19
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateProjectToPlane( const Point3F& normal )
{
	float xy=normal.X*normal.Y;
	float yz=normal.Y*normal.Z;
	float xz=normal.X*normal.Z;
	float xx=normal.X*normal.X;
	float yy=normal.Y*normal.Y;
	float zz=normal.Z*normal.Z;

	return Matrix43(1-xx,-xy,-xz,
		-xy,1-yy,-yz,
		-xz,-yz,1-zz,
		0.f,0.f,0.f);
}
コード例 #20
0
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
Matrix43 ManagerImplemented::GetMatrix( Handle handle )
{
	if( m_DrawSets.count( handle ) > 0 )
	{
		DrawSet& drawSet = m_DrawSets[handle];

		InstanceContainer* pContainer = drawSet.InstanceContainerPointer;
		
		InstanceGroup* pGroup = pContainer->GetFirstGroup();

		if( pGroup != NULL )
		{
			Instance* instance = pGroup->GetFirst();
			if( instance != NULL )
			{
				return instance->m_GlobalMatrix43;
			}
		}

		return Matrix43();
	}

	return Matrix43();
}
コード例 #21
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateScaleAxis( const Point3F& axis,float scale )
{
	float xy=axis.X*axis.Y;
	float yz=axis.Y*axis.Z;
	float xz=axis.X*axis.Z;
	float xx=axis.X*axis.X;
	float yy=axis.Y*axis.Y;
	float zz=axis.Z*axis.Z;
	float scaleMinusOne=scale-1.f;

	return Matrix43(1+scaleMinusOne*xx,scaleMinusOne*xy,scaleMinusOne*xz,
		scaleMinusOne*xy,1+scaleMinusOne*yy,scaleMinusOne*yz,
		scaleMinusOne*xz,scaleMinusOne*yz,1+scaleMinusOne*zz,
		0.f,0.f,0.f);
}
コード例 #22
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateFromEuler( const EulerAngle& angle )
{
	float cosh=Math::Cos(angle.Heading);
	float cosp=Math::Cos(angle.Pitch);
	float cosb=Math::Cos(angle.Bank);

	float sinh=Math::Sin(angle.Heading);
	float sinp=Math::Sin(angle.Pitch);
	float sinb=Math::Sin(angle.Bank);

	return Matrix43(cosh*cosb+sinh*sinp*sinb,sinb*cosp,-sinh*cosb+cosh*sinp*sinb,
		-cosh*sinb+sinh*sinp*cosb,cosb*cosp,sinb*sinh+cosh*sinp*cosb,
		sinh*cosp,-sinp,cosh*cosp,
		0.f,0.f,0.f);
}
コード例 #23
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateRotateXYZ( const Rotation3F& rotation )
{
	//rotate order: x,y,z
	float cosY=Math::Cos(rotation.Y);
	float cosZ=Math::Cos(rotation.Z);
	float cosX=Math::Cos(rotation.X);

	float sinY=Math::Sin(rotation.Y);
	float sinZ=Math::Sin(rotation.Z);
	float sinX=Math::Sin(rotation.X);

	float sinXsinY=sinX*sinY;
	float cosXsinY=cosX*sinY;

	return Matrix43(cosY*cosZ,cosY*sinZ,-sinY,
		sinXsinY*cosZ-cosX*sinZ,sinXsinY*sinZ+cosX*cosZ,sinX*cosY,
		cosXsinY*cosZ+sinX*sinZ,cosXsinY*sinZ-sinX*cosZ,cosX*cosY,
		0.f,0.f,0.f);
}
コード例 #24
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
Matrix43 Matrix43::CreateRotateAxis( const Point3F& axis,float radian )
{
	float cosValue=Math::Cos(radian);
	float sinValue=Math::Sin(radian);
	float oneMinusCosValue=1-cosValue;

	float xy=axis.X*axis.Y;
	float yz=axis.Y*axis.Z;
	float xz=axis.X*axis.Z;
	float xx=axis.X*axis.X;
	float yy=axis.Y*axis.Y;
	float zz=axis.Z*axis.Z;

	float xSin=axis.X*sinValue;
	float ySin=axis.Y*sinValue;
	float zSin=axis.Z*sinValue;


	return Matrix43(xx*oneMinusCosValue+cosValue,xy*oneMinusCosValue+zSin,xz*oneMinusCosValue-ySin,
		xy*oneMinusCosValue-zSin,yy*oneMinusCosValue+cosValue,yz*oneMinusCosValue+xSin,
		xz*oneMinusCosValue+ySin,yz*oneMinusCosValue-xSin,zz*oneMinusCosValue+cosValue,
		0.f,0.f,0.f);
}
コード例 #25
0
namespace photon_mapping {
    template <typename T>
    struct Matrix43 {
        T s00; T s01; T s02;
        T s10; T s11; T s12;
        T s20; T s21; T s22;
        T s30; T s31; T s32;

        Matrix43() {}

        Matrix43(
            T s00, T s01, T s02,
            T s10, T s11, T s12,
            T s20, T s21, T s22,
            T s30, T s31, T s32
        )
            : s00(s00), s01(s01), s02(s02)
            , s10(s10), s11(s11), s12(s12)
            , s20(s20), s21(s21), s22(s22)
            , s30(s30), s31(s31), s32(s32)
        {}

        static Matrix43 const IDENTITY;

        static Matrix43 translation(Vector3<T> const& displacement) {
            return Matrix43(
                          T(1),           T(0),           T(0),
                          T(0),           T(1),           T(0),
                          T(0),           T(0),           T(1),
                displacement.x, displacement.y, displacement.z
            );
        }

        static Matrix43 rotation(Vector3<T> const& axis, T angle) {
            T s = sin(angle);
            T c = cos(angle); T k = T(1) - c;

            Vector3<T> ak = axis * k;
            Vector3<T> as = axis * s;

            return Matrix43(
                ak.x * axis.x +    c, ak.x * axis.y + as.z, ak.x * axis.z - as.y,
                ak.x * axis.y - as.z, ak.y * axis.y +    c, ak.y * axis.z + as.x,
                ak.x * axis.z + as.y, ak.y * axis.z - as.x, ak.z * axis.z +    c,
                                T(0),                 T(0),                 T(0)
            );
        }

        static Matrix43 rotation(Vector3<T> const& axis, T angle, Point3<T> const& point) {
            Vector3<T> displacement = point - Point3<T>::ORIGIN;
            return translation(-displacement) * rotation(axis, angle) * translation(+displacement);
        }

        static Matrix43 scaling(Extent3<T> const& factor) {
            return Matrix43(
                factor.x,     T(0),     T(0),
                    T(0), factor.y,     T(0),
                    T(0),     T(0), factor.z,
                    T(0),     T(0),     T(0)
            );
        }

        static Matrix43 scaling(Extent3<T> const& factor, Point3<T> const& point) {
            Vector3<T> displacement = point - Point3<T>::ORIGIN;
            return translation(-displacement) * scaling(factor) * translation(+displacement);
        }
    };

    template <typename T>
    Matrix43<T> const Matrix43<T>::IDENTITY = Matrix43(
        T(1), T(0), T(0),
        T(0), T(1), T(0),
        T(0), T(0), T(1),
        T(0), T(0), T(0)
    );

    typedef Matrix43<float> Matrix43f;

    template <typename T>
    inline Matrix43<T> operator~(Matrix43<T> const& m) {
        T d = m.s10 * m.s21 * m.s02 - m.s20 * m.s11 * m.s02
            + m.s20 * m.s01 * m.s12 - m.s00 * m.s21 * m.s12
            + m.s00 * m.s11 * m.s22 - m.s10 * m.s01 * m.s22;
        return Matrix43<T>(
            (m.s11 * m.s22 - m.s21 * m.s12) / d,
            (m.s21 * m.s02 - m.s01 * m.s22) / d,
            (m.s01 * m.s12 - m.s11 * m.s02) / d,

            (m.s20 * m.s12 - m.s10 * m.s22) / d,
            (m.s00 * m.s22 - m.s20 * m.s02) / d,
            (m.s10 * m.s02 - m.s00 * m.s12) / d,

            (m.s10 * m.s21 - m.s20 * m.s11) / d,
            (m.s20 * m.s01 - m.s00 * m.s21) / d,
            (m.s00 * m.s11 - m.s10 * m.s01) / d,

            (m.s30 * m.s21 * m.s12 - m.s20 * m.s31 * m.s12 - m.s30 * m.s11 * m.s22 + m.s10 * m.s31 * m.s22 + m.s20 * m.s11 * m.s32 - m.s10 * m.s21 * m.s32) / d,
            (m.s20 * m.s31 * m.s02 - m.s30 * m.s21 * m.s02 + m.s30 * m.s01 * m.s22 - m.s00 * m.s31 * m.s22 - m.s20 * m.s01 * m.s32 + m.s00 * m.s21 * m.s32) / d,
            (m.s30 * m.s11 * m.s02 - m.s10 * m.s31 * m.s02 - m.s30 * m.s01 * m.s12 + m.s00 * m.s31 * m.s12 + m.s10 * m.s01 * m.s32 - m.s00 * m.s11 * m.s32) / d
        );
    }
   
    template <typename TA, typename TB>
    inline Matrix43<typename std::common_type<TA, TB>::type> operator*(Matrix43<TA> const& a, Matrix43<TB> const& b) {
        return Matrix43<typename std::common_type<TA, TB>::type>(
            a.s00 * b.s00 + a.s01 * b.s10 + a.s02 * b.s20,
            a.s00 * b.s01 + a.s01 * b.s11 + a.s02 * b.s21,
            a.s00 * b.s02 + a.s01 * b.s12 + a.s02 * b.s22,

            a.s10 * b.s00 + a.s11 * b.s10 + a.s12 * b.s20,
            a.s10 * b.s01 + a.s11 * b.s11 + a.s12 * b.s21,
            a.s10 * b.s02 + a.s11 * b.s12 + a.s12 * b.s22,

            a.s20 * b.s00 + a.s21 * b.s10 + a.s22 * b.s20,
            a.s20 * b.s01 + a.s21 * b.s11 + a.s22 * b.s21,
            a.s20 * b.s02 + a.s21 * b.s12 + a.s22 * b.s22,

            a.s30 * b.s00 + a.s31 * b.s10 + a.s32 * b.s20 + b.s30,
            a.s30 * b.s01 + a.s31 * b.s11 + a.s32 * b.s21 + b.s31,
            a.s30 * b.s02 + a.s31 * b.s12 + a.s32 * b.s22 + b.s32
        );
    }

    template <typename TA, typename TB>
    inline Matrix43<TA>& operator*=(Matrix43<TA>& a, Matrix43<TB> const& b) {
        return a = a * b;
    }

    template <typename TV, typename TM>
    inline Vector3<typename std::common_type<TV, TM>::type> operator*(Vector3<TV> const& v, Matrix43<TM> const& m) {
        return Vector3<typename std::common_type<TV, TM>::type>(
            v.x * m.s00 + v.y * m.s10 + v.z * m.s20,
            v.x * m.s01 + v.y * m.s11 + v.z * m.s21,
            v.x * m.s02 + v.y * m.s12 + v.z * m.s22
        );
    }

    template <typename TV, typename TM>
    inline Vector3<TV>& operator*=(Vector3<TV>& v, Matrix43<TM> const& m) {
        return v = v * m;
    }

    template <typename TP, typename TM>
    inline Point3<typename std::common_type<TP, TM>::type> operator*(Point3<TP> const& p, Matrix43<TM> const& m) {
        return Point3<typename std::common_type<TP, TM>::type>(
            p.x * m.s00 + p.y * m.s10 + p.z * m.s20 + m.s30,
            p.x * m.s01 + p.y * m.s11 + p.z * m.s21 + m.s31,
            p.x * m.s02 + p.y * m.s12 + p.z * m.s22 + m.s32
        );
    }

    template <typename TV, typename TM>
    inline Point3<TV>& operator*=(Point3<TV>& p, Matrix43<TM> const& m) {
        return p = p * m;
    }
}
コード例 #26
0
ファイル: Matrix43.cpp プロジェクト: johndpope/Medusa
#include "Core/Geometry/Cube.h"
#include "Core/Geometry/Scale3.h"
#include "Core/Geometry/Rotation3.h"

#include "Core/Geometry/Rect2.h"
#include "Core/Geometry/Quad.h"
#include "Core/Math/Math.h"
#include "Core/Utility/Utility.h"
#include "Core/Assertion/CommonAssert.h"
#include "Core/Memory/Memory.h"


MEDUSA_BEGIN;

const Matrix43 Matrix43::Zero=Matrix43(0.f,0.f,0.f,
	0.f,0.f,0.f,
	0.f,0.f,0.f,
	0.f,0.f,0.f);
const Matrix43 Matrix43::Identity=Matrix43(1.f,0.f,0.f,
	0.f,1.f,0.f,
	0.f,0.f,1.f,
	0.f,0.f,0.f);


Matrix43::Matrix43( const Matrix4& m ,bool isTransposed)
{
	if (isTransposed)
	{
		M11=m.M11;M12=m.M21;M13=m.M31;
		M21=m.M12;M22=m.M22;M23=m.M32;
		M31=m.M13;M32=m.M23;M33=m.M33;
		M41=m.M14;M42=m.M24;M43=m.M34;