Commit eeebe2234ddefea82c7205cba19e2cfebe5893b0
1 parent
fb0bc2f1
added comments to the rect class
Showing
1 changed file
with
7 additions
and
43 deletions
Show diff stats
math/rect.h
@@ -61,62 +61,22 @@ public: | @@ -61,62 +61,22 @@ public: | ||
61 | init(); | 61 | init(); |
62 | } | 62 | } |
63 | 63 | ||
64 | + //create a rectangle given a size and position | ||
64 | CUDA_CALLABLE rect(T size, T z_pos = (T)0){ | 65 | CUDA_CALLABLE rect(T size, T z_pos = (T)0){ |
65 | init(); //use the default setup | 66 | init(); //use the default setup |
66 | scale(size); //scale the rectangle | 67 | scale(size); //scale the rectangle |
67 | C[2] = z_pos; | 68 | C[2] = z_pos; |
68 | } | 69 | } |
69 | 70 | ||
71 | + //create a rectangle from a center point, normal, and size | ||
70 | CUDA_CALLABLE rect(T size, vec<T, N> c, vec<T, N> n = vec<T, N>(0, 0, 1)){ | 72 | CUDA_CALLABLE rect(T size, vec<T, N> c, vec<T, N> n = vec<T, N>(0, 0, 1)){ |
71 | init(); //start with the default setting | 73 | init(); //start with the default setting |
72 | C = c; | 74 | C = c; |
73 | scale(size); //scale the rectangle | 75 | scale(size); //scale the rectangle |
74 | normal(n); //orient | 76 | normal(n); //orient |
75 | - | ||
76 | } | 77 | } |
77 | 78 | ||
78 | - /*CUDA_CALLABLE rect(vec<T, N> a, vec<T, N> b, vec<T, N> c) | ||
79 | - { | ||
80 | - A = a; | ||
81 | - Y = b - a; | ||
82 | - X = c - a - Y; | ||
83 | - | ||
84 | - }*/ | ||
85 | - | ||
86 | - /******************************************************************* | ||
87 | - Constructor - create a rect from a position, normal, and rotation | ||
88 | - *******************************************************************/ | ||
89 | - /*CUDA_CALLABLE rect(stim::vec<T, N> c, stim::vec<T, N> normal, T width, T height, T theta) | ||
90 | - { | ||
91 | - | ||
92 | - //compute the X direction - start along world-space X | ||
93 | - Y = stim::vec<T, N>(0, 1, 0); | ||
94 | - if(Y == normal) | ||
95 | - Y = stim::vec<T, N>(0, 0, 1); | ||
96 | - | ||
97 | - X = Y.cross(normal).norm(); | ||
98 | - | ||
99 | - std::cout<<X<<std::endl; | ||
100 | - | ||
101 | - //rotate the X axis by theta radians | ||
102 | - stim::quaternion<T> q; | ||
103 | - q.CreateRotation(theta, normal); | ||
104 | - X = q.toMatrix3() * X; | ||
105 | - Y = normal.cross(X); | ||
106 | - | ||
107 | - //normalize everything | ||
108 | - X = X.norm(); | ||
109 | - Y = Y.norm(); | ||
110 | - | ||
111 | - //scale to match the rect width and height | ||
112 | - X = X * width; | ||
113 | - Y = Y * height; | ||
114 | - | ||
115 | - //set the corner of the plane | ||
116 | - A = c - X * 0.5f - Y * 0.5f; | ||
117 | - | ||
118 | - std::cout<<X<<std::endl; | ||
119 | - }*/ | 79 | + //Pavel - write a constructor to create a rectangle given a center point (c), direction vector (v) |
120 | 80 | ||
121 | //boolean comparison | 81 | //boolean comparison |
122 | bool operator==(const rect<T, N> & rhs) | 82 | bool operator==(const rect<T, N> & rhs) |
@@ -135,6 +95,7 @@ public: | @@ -135,6 +95,7 @@ public: | ||
135 | return (X.cross(Y)).norm(); | 95 | return (X.cross(Y)).norm(); |
136 | } | 96 | } |
137 | 97 | ||
98 | + //get the world space value given the planar coordinates a, b in [0, 1] | ||
138 | CUDA_CALLABLE stim::vec<T, N> p(T a, T b) | 99 | CUDA_CALLABLE stim::vec<T, N> p(T a, T b) |
139 | { | 100 | { |
140 | stim::vec<T, N> result; | 101 | stim::vec<T, N> result; |
@@ -145,6 +106,7 @@ public: | @@ -145,6 +106,7 @@ public: | ||
145 | return result; | 106 | return result; |
146 | } | 107 | } |
147 | 108 | ||
109 | + //parenthesis operator returns the world space given rectangular coordinates a and b in [0 1] | ||
148 | CUDA_CALLABLE stim::vec<T, N> operator()(T a, T b) | 110 | CUDA_CALLABLE stim::vec<T, N> operator()(T a, T b) |
149 | { | 111 | { |
150 | return p(a, b); | 112 | return p(a, b); |
@@ -162,6 +124,7 @@ public: | @@ -162,6 +124,7 @@ public: | ||
162 | 124 | ||
163 | } | 125 | } |
164 | 126 | ||
127 | + //scales the rectangle by a value rhs | ||
165 | CUDA_CALLABLE rect<T, N> operator*(T rhs) | 128 | CUDA_CALLABLE rect<T, N> operator*(T rhs) |
166 | { | 129 | { |
167 | //scales the plane by a scalar value | 130 | //scales the plane by a scalar value |
@@ -174,6 +137,7 @@ public: | @@ -174,6 +137,7 @@ public: | ||
174 | 137 | ||
175 | } | 138 | } |
176 | 139 | ||
140 | + //computes the distance between the specified point and this rectangle | ||
177 | CUDA_CALLABLE T dist(vec<T, N> p) | 141 | CUDA_CALLABLE T dist(vec<T, N> p) |
178 | { | 142 | { |
179 | //compute the distance between a point and this rect | 143 | //compute the distance between a point and this rect |