1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | #include "Plane.hpp" |
16 | |
17 | #include "Matrix.hpp" |
18 | |
19 | namespace sw |
20 | { |
21 | Plane::Plane() |
22 | { |
23 | } |
24 | |
25 | Plane::Plane(float p_A, float p_B, float p_C, float p_D) |
26 | { |
27 | A = p_A; |
28 | B = p_B; |
29 | C = p_C; |
30 | D = p_D; |
31 | } |
32 | |
33 | Plane::Plane(const float ABCD[4]) |
34 | { |
35 | A = ABCD[0]; |
36 | B = ABCD[1]; |
37 | C = ABCD[2]; |
38 | D = ABCD[3]; |
39 | } |
40 | |
41 | Plane operator*(const Plane &p, const Matrix &T) |
42 | { |
43 | Matrix M = !T; |
44 | |
45 | return Plane(p.A * M(1, 1) + p.B * M(1, 2) + p.C * M(1, 3) + p.D * M(1, 4), |
46 | p.A * M(2, 1) + p.B * M(2, 2) + p.C * M(2, 3) + p.D * M(2, 4), |
47 | p.A * M(3, 1) + p.B * M(3, 2) + p.C * M(3, 3) + p.D * M(3, 4), |
48 | p.A * M(4, 1) + p.B * M(4, 2) + p.C * M(4, 3) + p.D * M(4, 4)); |
49 | } |
50 | |
51 | Plane operator*(const Matrix &T, const Plane &p) |
52 | { |
53 | Matrix M = !T; |
54 | |
55 | return Plane(M(1, 1) * p.A + M(2, 1) * p.B + M(3, 1) * p.C + M(4, 1) * p.D, |
56 | M(1, 2) * p.A + M(2, 2) * p.B + M(3, 2) * p.C + M(4, 2) * p.D, |
57 | M(1, 3) * p.A + M(2, 3) * p.B + M(3, 3) * p.C + M(4, 3) * p.D, |
58 | M(1, 4) * p.A + M(2, 4) * p.B + M(3, 4) * p.C + M(4, 4) * p.D); |
59 | } |
60 | } |
61 | |