Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MT_Plane3.inl « include « moto « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 77db9b35e1d73feba5e3770c5a474b18168cede6 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "MT_Optimize.h"


GEN_INLINE
MT_Plane3::
MT_Plane3(
	const MT_Vector3 &a,
	const MT_Vector3 &b,
	const MT_Vector3 &c
){
	MT_Vector3 l1 = b-a;
	MT_Vector3 l2 = c-b;

	MT_Vector3 n = l1.cross(l2);
	n = n.safe_normalized();
	MT_Scalar d = n.dot(a); 

	m_co[0] = n.x();
	m_co[1] = n.y();
	m_co[2] = n.z();
	m_co[3] = -d;
}

/**
 * Construction from vector and a point.
 */
GEN_INLINE
MT_Plane3::
MT_Plane3(
	const MT_Vector3 &n,
	const MT_Vector3 &p
){
	
	MT_Vector3 mn = n.safe_normalized();
	MT_Scalar md = mn.dot(p); 

	m_co[0] = mn.x();
	m_co[1] = mn.y();
	m_co[2] = mn.z();
	m_co[3] = -md;
}


/**
 * Default constructor
 */
GEN_INLINE
MT_Plane3::
MT_Plane3(
):
	MT_Tuple4()
{
	m_co[0] = MT_Scalar(1);
	m_co[1] = MT_Scalar(0);
	m_co[2] = MT_Scalar(0);
	m_co[3] = MT_Scalar(0);
}

/**
 * Return plane normal
 */

GEN_INLINE
	MT_Vector3
MT_Plane3::
Normal(
) const {
	return MT_Vector3(m_co[0],m_co[1],m_co[2]);
}

/**
 * Return plane scalar i.e the d from n.x + d = 0
 */

GEN_INLINE
	MT_Scalar
MT_Plane3::
Scalar(
) const {
	return m_co[3];
}

GEN_INLINE
	void
MT_Plane3::
Invert(
) {
	m_co[0] = -m_co[0];
	m_co[1] = -m_co[1];
	m_co[2] = -m_co[2];
	m_co[3] = -m_co[3];
}


/**
 * Assignment operator
 */

GEN_INLINE
	MT_Plane3 &
MT_Plane3::
operator = (
	const MT_Plane3 & rhs
) {
	m_co[0] = rhs.m_co[0];
	m_co[1] = rhs.m_co[1];
	m_co[2] = rhs.m_co[2];
	m_co[3] = rhs.m_co[3];
	return *this;
}

/**
 * Return the distance from a point to the plane
 */

GEN_INLINE
	MT_Scalar
MT_Plane3::
signedDistance(
	const MT_Vector3 &v
) const {
	return Normal().dot(v) + m_co[3];
}