Пример #1
0
// operator * (Mat44)
//------------------------------------------------------------------------------
Mat44 Mat44::operator *(const Mat44 & other ) const
{
    return Mat44( (*this) * other.col0,
                  (*this) * other.col1,
                  (*this) * other.col2,
                  (*this) * other.col3 );
}
Пример #2
0
	namespace Numerics
	{
		UnitTest::Suite MatrixProjectionsTestSuite {
			"Euclid::Numerics::Matrix",

			{"Clip Space Orthographic Projection",
				[](UnitTest::Examiner & examiner) {
					// This is the natural clip space box:
					auto unit_box = Geometry::AlignedBox3::from_origin_and_size(Vec3{-1, -1, 0}, Vec3{2, 2, 1});
					
					auto projection = orthographic_projection_matrix(unit_box);
					
					examiner << "The unit projection should be the identity" << std::endl;
					examiner.expect(projection) == Mat44(IDENTITY);
				}
			},
			
			{"Unit Space Orthographic Projection",
				[](UnitTest::Examiner & examiner) {
					// This is the natural clip space box:
					auto unit_box = Geometry::AlignedBox3::from_center_and_size(ZERO, Vec3{2, 2, 2});
					
					auto projection = orthographic_projection_matrix(unit_box);
					
					examiner.expect(projection * unit_box.corner({false, false, false})) == Vec3{-1, -1, 0};
					examiner.expect(projection * unit_box.corner({true, true, true})) == Vec3{1, 1, 1};
				}
			},
		};
	}
Пример #3
0
// Build rotation matrix angle_in_degrees about x,y,z specified axis e.g. 90 degrees about x axis is BuildRotationMatrix(90, 1,0,0)
Mat44 Mat44::BuildRotationMatrix(f32 angle_in_degrees, f32 x, f32 y, f32 z)
{
	float3 fv(x,y,z);
	fv.normalize();
	
	x = fv.x();
	y = fv.y();
	z = fv.z();

	f32 angle = DEGTORAD(angle_in_degrees);

	f32 c = cos(angle);
	f32 s = sin(angle);

	return Mat44
		(
		x*x*(1-c)+c,   // m11
		x*y*(1-c)-z*s, // m12
		x*z*(1-c)+y*s, // m13
		0,			   // m14

		y*x*(1-c)+z*s, // m21
		y*y*(1-c)+c,   // m22
		y*z*(1-c)-x*s, // m23
		0,			   // m24

		x*z*(1-c)-y*s, // m31 
		y*z*(1-c)+x*s, // m32
		z*z*(1-c)+c,   // m33
		0,			   // m34

		0, 0, 0, 1     // m41, m42, m43, m44
		);
};
Пример #4
0
Mat44 Mat44::BuildRotationMatrix(const f32 angle_in_degrees, const f32 _x, const f32 _y, const f32 _z)
{
	float3 fv = float3(_x, _y, _z).normalize();
	
	const f32 x = fv.x();
	const f32 y = fv.y();
	const f32 z = fv.z();

	f32 angle = DEGTORAD(angle_in_degrees);

	f32 c = cos(angle);
	f32 s = sin(angle);

	return Mat44
		(
		x*x*(1-c)+c,   // m11
		x*y*(1-c)-z*s, // m12
		x*z*(1-c)+y*s, // m13
		0,			   // m14

		y*x*(1-c)+z*s, // m21
		y*y*(1-c)+c,   // m22
		y*z*(1-c)-x*s, // m23
		0,			   // m24

		x*z*(1-c)-y*s, // m31 
		y*z*(1-c)+x*s, // m32
		z*z*(1-c)+c,   // m33
		0,			   // m34

		0, 0, 0, 1     // m41, m42, m43, m44
		);
};
Пример #5
0
// Build scaling matrix
Mat44 Mat44::BuildScaleMatrix(f32 xscale, f32 yscale, f32 zscale)
{
	return Mat44(
		xscale,  0,       0,       0,
		0,       yscale,  0,       0,
		0,       0,       zscale,  0,
		0,       0,       0,       1);
};
Пример #6
0
Mat44 Mat44::BuildTranslationMatrix(const f32 x, const f32 y, const f32 z)
{
	return Mat44( // translation matrix is identity matrix with x,y,z,1 in the last column
		1,0,0,x,
		0,1,0,y,
		0,0,1,z,
		0,0,0,1);
};
Пример #7
0
    void Camera::updateViewMatrix()
    {
        if (mMatrixUpdateFlags & MatrixRotationUpdated) {
            mRotationMatrix = Mat44(
#if 1
                 mRight.x,  mUpReal.x, -mFront.x,  0.f,
                 mRight.y,  mUpReal.y, -mFront.y,  0.f,
                 mRight.z,  mUpReal.z, -mFront.z,  0.f,
                 0.f,       0.f,       0.f,        1.f
#else
                 mRight.x,   mRight.y,   mRight.z,  0.f,
                 mUpReal.x,  mUpReal.y,  mUpReal.z, 0.f,
                -mFront.x,  -mFront.y,  -mFront.z,  0.f,
                 0.f,        0.f,        0.f,       1.f
#endif
            );
        }
        if (mMatrixUpdateFlags & MatrixTranslationUpdated) {
            mTranslationMatrix = glm::translate(-mEye);
        }

        mMatrixUpdateFlags = 0;
        mViewMatrix = mRotationMatrix * mTranslationMatrix;
    }
Пример #8
0
//----------------------------------------------------------------------------//
Resources::Resources(void)
{
	LOG("Create Resources");

	// terrain heightmap
	{
		m_terrainHeightmap = new Image;
		m_terrainHeightmap->CreatePerlin(512, 0.05f);
	}

	// R_MESH_Sphere
	{
		GeometryPtr _geom = new Geometry;
		_geom->CreateSphere(1, 32, 16);
		m_meshes[R_MESH_Sphere] = new Mesh();
		m_meshes[R_MESH_Sphere]->SetGeometry(_geom);
	}

	//R_MESH_DroneBody,
	{
		MaterialPtr _mtl = new Material;
		_mtl->SetShader(FS_NoTexture);

		GeometryPtr _geom = new Geometry;
		_geom->CreateSphere(0.5f, 32, 16);

		MeshPtr _mesh = new Mesh;
		_mesh->SetGeometry(_geom);
		_mesh->SetMaterial(_mtl);
		_mesh->GetMaterialParams().SetColor(G_DRONE_COLOR);
		_mesh->GetMaterialParams().SetShininess(G_DRONE_SHININESS);
		
		m_meshes[R_MESH_DroneBody] = _mesh;
	}

	//R_MESH_DroneEye,
	{
		MaterialPtr _mtl = new Material;
		_mtl->SetShader(FS_NoTexture);

		GeometryPtr _geom = new Geometry;
		_geom->CreateCylinder(0.25f, 0.25f, 32);
		_geom->Transform(Mat44().CreateRotation(Quat().FromAxisAngle(VEC3_UNIT_X, HALF_PI)));


		MeshPtr _mesh = new Mesh;
		_mesh->SetGeometry(_geom);
		_mesh->SetMaterial(_mtl);
		_mesh->GetMaterialParams().SetColor(G_DRONE_EYE_INACTIVE_COLOR);
		_mesh->GetMaterialParams().SetEmission(G_DRONE_EYE_EMISSION);

		m_meshes[R_MESH_DroneEye] = _mesh;
	}

	// R_MESH_Pilotless
	{
		MaterialPtr _mtl = new Material;
		_mtl->SetShader(FS_NoTexture);

		GeometryPtr _geom = new Geometry;
		GeometryPtr _geom2 = new Geometry;
		_geom2->CreateCylinder(0.25f, 2.25f, 16);
		_geom2->Transform(Mat44().CreateRotation(Quat().FromAxisAngle(VEC3_UNIT_X, HALF_PI)));
		//_geom->SetT
		//_geom->Merge(_geom2->Vertices().Ptr(), _geom2->Vertices().Size(), _geom2->Indices().Ptr(), _geom2->Indices().Size());
		
		MeshPtr _mesh = new Mesh;
		_mesh->SetGeometry(_geom2);
		_mesh->SetMaterial(_mtl);
		//_mesh->GetMaterialParams().SetColor(G_DRONE_EYE_INACTIVE_COLOR);
		//_mesh->GetMaterialParams().SetEmission(G_DRONE_EYE_EMISSION);

		m_meshes[R_MESH_Pilotless] = _mesh;
	}

	//,
	//R_MESH_DroneEngine,
	//R_MESH_MaxCount,
}
Пример #9
0
#include "Mat44.h"
#include "float4.h"
#include "float3.h"
#include "util.h"
#include <pmmintrin.h>

const f32 IDENTITY_MAT44_DATA[] = 
{
	1, 0, 0, 0,
	0, 1, 0, 0,
	0, 0, 1, 0,
	0, 0, 0, 1
};

const Mat44 Mat44::IDENTITY = Mat44();

Mat44::Mat44(void)
{
	// Alternative to memcpy (in SetMatrix) is to memset(...) all to 0, then set mat indices 0,5,10 and 15 to 1
	SetMatrix(IDENTITY_MAT44_DATA);
}

Mat44::Mat44(const f32* _mat) // use existing FP array to initialise the matrix
{
	SetMatrix(_mat);
};

Mat44::Mat44(
	const f32 m11, const f32 m12, const f32 m13, const f32 m14,
	const f32 m21, const f32 m22, const f32 m23, const f32 m24,
	const f32 m31, const f32 m32, const f32 m33, const f32 m34,
Пример #10
0
 inline Mat44 retvalopt( const Mat44& lhs, const Mat44& rhs )
 {
    return Mat44( lhs );
 }