summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Utils/MatrixUtility.cs
blob: f3d865f256341f0e91384a1e692da209a6af7b40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class MatrixUtility
{

	public static void SetTR(ref this Matrix4x4 matrix, Vector3 pos, Quaternion q)
	{
		matrix = q.ToMatrix();
		matrix[12] = pos[0];
		matrix[13] = pos[1];
		matrix[14] = pos[2];
	}

	public static void SetTRS2(ref this Matrix4x4 matrix, Vector3 pos, Quaternion q, Vector3 s)
	{
		matrix = q.ToMatrix();
		
		matrix[0] *= s[0];
		matrix[1] *= s[0];
		matrix[2] *= s[0];
		matrix[4] *= s[1];
		matrix[5] *= s[1];
		matrix[6] *= s[1];
		matrix[8] *= s[2];
		matrix[9] *= s[2];
		matrix[10] *= s[2];
		matrix[12] = pos[0];
		matrix[13] = pos[1];
		matrix[14] = pos[2];

	}

	public static Matrix4x4 RotateAndTranslate(Vector3 pos, Quaternion q)
	{
		Matrix4x4 m = new Matrix4x4();
		m.SetTR(pos, q);
		return m;
	}

}