1/// @ref core 2/// @file glm/detail/type_gentype.inl 3 4namespace glm{ 5namespace detail{ 6 7///////////////////////////////// 8// Static functions 9 10template <typename vT, uint cT, uint rT, profile pT> 11typename base<vT, cT, rT, pT>::size_type base<vT, cT, rT, pT>::col_size() 12{ 13 return cT; 14} 15 16template <typename vT, uint cT, uint rT, profile pT> 17typename base<vT, cT, rT, pT>::size_type base<vT, cT, rT, pT>::row_size() 18{ 19 return rT; 20} 21 22template <typename vT, uint cT, uint rT, profile pT> 23typename base<vT, cT, rT, pT>::size_type base<vT, cT, rT, pT>::value_size() 24{ 25 return rT * cT; 26} 27 28template <typename vT, uint cT, uint rT, profile pT> 29bool base<vT, cT, rT, pT>::is_scalar() 30{ 31 return rT == 1 && cT == 1; 32} 33 34template <typename vT, uint cT, uint rT, profile pT> 35bool base<vT, cT, rT, pT>::is_vector() 36{ 37 return rT == 1; 38} 39 40template <typename vT, uint cT, uint rT, profile pT> 41bool base<vT, cT, rT, pT>::is_matrix() 42{ 43 return rT != 1; 44} 45 46///////////////////////////////// 47// Constructor 48 49template <typename vT, uint cT, uint rT, profile pT> 50base<vT, cT, rT, pT>::base() 51{ 52 memset(&this->value, 0, cT * rT * sizeof(vT)); 53} 54 55template <typename vT, uint cT, uint rT, profile pT> 56base<vT, cT, rT, pT>::base 57( 58 typename base<vT, cT, rT, pT>::class_type const & m 59) 60{ 61 for 62 ( 63 typename genType<vT, cT, rT, pT>::size_type i = typename base<vT, cT, rT, pT>::size_type(0); 64 i < base<vT, cT, rT, pT>::col_size(); 65 ++i 66 ) 67 { 68 this->value[i] = m[i]; 69 } 70} 71 72template <typename vT, uint cT, uint rT, profile pT> 73base<vT, cT, rT, pT>::base 74( 75 typename base<vT, cT, rT, pT>::T const & x 76) 77{ 78 if(rT == 1) // vector 79 { 80 for 81 ( 82 typename base<vT, cT, rT, pT>::size_type i = typename base<vT, cT, rT, pT>::size_type(0); 83 i < base<vT, cT, rT, pT>::col_size(); 84 ++i 85 ) 86 { 87 this->value[i][rT] = x; 88 } 89 } 90 else // matrix 91 { 92 memset(&this->value, 0, cT * rT * sizeof(vT)); 93 94 typename base<vT, cT, rT, pT>::size_type stop = cT < rT ? cT : rT; 95 96 for 97 ( 98 typename base<vT, cT, rT, pT>::size_type i = typename base<vT, cT, rT, pT>::size_type(0); 99 i < stop; 100 ++i 101 ) 102 { 103 this->value[i][i] = x; 104 } 105 } 106} 107 108template <typename vT, uint cT, uint rT, profile pT> 109base<vT, cT, rT, pT>::base 110( 111 typename base<vT, cT, rT, pT>::value_type const * const x 112) 113{ 114 memcpy(&this->value, &x.value, cT * rT * sizeof(vT)); 115} 116 117template <typename vT, uint cT, uint rT, profile pT> 118base<vT, cT, rT, pT>::base 119( 120 typename base<vT, cT, rT, pT>::col_type const * const x 121) 122{ 123 for 124 ( 125 typename base<vT, cT, rT, pT>::size_type i = typename base<vT, cT, rT, pT>::size_type(0); 126 i < base<vT, cT, rT, pT>::col_size(); 127 ++i 128 ) 129 { 130 this->value[i] = x[i]; 131 } 132} 133 134template <typename vT, uint cT, uint rT, profile pT> 135template <typename vU, uint cU, uint rU, profile pU> 136base<vT, cT, rT, pT>::base 137( 138 base<vU, cU, rU, pU> const & m 139) 140{ 141 for 142 ( 143 typename base<vT, cT, rT, pT>::size_type i = typename base<vT, cT, rT, pT>::size_type(0); 144 i < base<vT, cT, rT, pT>::col_size(); 145 ++i 146 ) 147 { 148 this->value[i] = base<vT, cT, rT, pT>(m[i]); 149 } 150} 151 152////////////////////////////////////// 153// Accesses 154 155template <typename vT, uint cT, uint rT, profile pT> 156typename base<vT, cT, rT, pT>::col_type& base<vT, cT, rT, pT>::operator[] 157( 158 typename base<vT, cT, rT, pT>::size_type i 159) 160{ 161 return this->value[i]; 162} 163 164template <typename vT, uint cT, uint rT, profile pT> 165typename base<vT, cT, rT, pT>::col_type const & base<vT, cT, rT, pT>::operator[] 166( 167 typename base<vT, cT, rT, pT>::size_type i 168) const 169{ 170 return this->value[i]; 171} 172 173////////////////////////////////////// 174// Unary updatable operators 175 176template <typename vT, uint cT, uint rT, profile pT> 177typename base<vT, cT, rT, pT>::class_type& base<vT, cT, rT, pT>::operator= 178( 179 typename base<vT, cT, rT, pT>::class_type const & x 180) 181{ 182 memcpy(&this->value, &x.value, cT * rT * sizeof(vT)); 183 return *this; 184} 185 186template <typename vT, uint cT, uint rT, profile pT> 187typename base<vT, cT, rT, pT>::class_type& base<vT, cT, rT, pT>::operator+= 188( 189 typename base<vT, cT, rT, pT>::T const & x 190) 191{ 192 typename base<vT, cT, rT, pT>::size_type stop_col = x.col_size(); 193 typename base<vT, cT, rT, pT>::size_type stop_row = x.row_size(); 194 195 for(typename base<vT, cT, rT, pT>::size_type j = 0; j < stop_col; ++j) 196 for(typename base<vT, cT, rT, pT>::size_type i = 0; i < stop_row; ++i) 197 this->value[j][i] += x; 198 199 return *this; 200} 201 202template <typename vT, uint cT, uint rT, profile pT> 203typename base<vT, cT, rT, pT>::class_type& base<vT, cT, rT, pT>::operator+= 204( 205 typename base<vT, cT, rT, pT>::class_type const & x 206) 207{ 208 typename base<vT, cT, rT, pT>::size_type stop_col = x.col_size(); 209 typename base<vT, cT, rT, pT>::size_type stop_row = x.row_size(); 210 211 for(typename base<vT, cT, rT, pT>::size_type j = 0; j < stop_col; ++j) 212 for(typename base<vT, cT, rT, pT>::size_type i = 0; i < stop_row; ++i) 213 this->value[j][i] += x[j][i]; 214 215 return *this; 216} 217 218template <typename vT, uint cT, uint rT, profile pT> 219typename base<vT, cT, rT, pT>::class_type& base<vT, cT, rT, pT>::operator-= 220( 221 typename base<vT, cT, rT, pT>::T const & x 222) 223{ 224 typename base<vT, cT, rT, pT>::size_type stop_col = x.col_size(); 225 typename base<vT, cT, rT, pT>::size_type stop_row = x.row_size(); 226 227 for(typename base<vT, cT, rT, pT>::size_type j = 0; j < stop_col; ++j) 228 for(typename base<vT, cT, rT, pT>::size_type i = 0; i < stop_row; ++i) 229 this->value[j][i] -= x; 230 231 return *this; 232} 233 234template <typename vT, uint cT, uint rT, profile pT> 235typename base<vT, cT, rT, pT>::class_type& base<vT, cT, rT, pT>::operator-= 236( 237 typename base<vT, cT, rT, pT>::class_type const & x 238) 239{ 240 typename base<vT, cT, rT, pT>::size_type stop_col = x.col_size(); 241 typename base<vT, cT, rT, pT>::size_type stop_row = x.row_size(); 242 243 for(typename base<vT, cT, rT, pT>::size_type j = 0; j < stop_col; ++j) 244 for(typename base<vT, cT, rT, pT>::size_type i = 0; i < stop_row; ++i) 245 this->value[j][i] -= x[j][i]; 246 247 return *this; 248} 249 250template <typename vT, uint cT, uint rT, profile pT> 251typename base<vT, cT, rT, pT>::class_type& base<vT, cT, rT, pT>::operator*= 252( 253 typename base<vT, cT, rT, pT>::T const & x 254) 255{ 256 typename base<vT, cT, rT, pT>::size_type stop_col = x.col_size(); 257 typename base<vT, cT, rT, pT>::size_type stop_row = x.row_size(); 258 259 for(typename base<vT, cT, rT, pT>::size_type j = 0; j < stop_col; ++j) 260 for(typename base<vT, cT, rT, pT>::size_type i = 0; i < stop_row; ++i) 261 this->value[j][i] *= x; 262 263 return *this; 264} 265 266template <typename vT, uint cT, uint rT, profile pT> 267typename base<vT, cT, rT, pT>::class_type& base<vT, cT, rT, pT>::operator*= 268( 269 typename base<vT, cT, rT, pT>::class_type const & x 270) 271{ 272 typename base<vT, cT, rT, pT>::size_type stop_col = x.col_size(); 273 typename base<vT, cT, rT, pT>::size_type stop_row = x.row_size(); 274 275 for(typename base<vT, cT, rT, pT>::size_type j = 0; j < stop_col; ++j) 276 for(typename base<vT, cT, rT, pT>::size_type i = 0; i < stop_row; ++i) 277 this->value[j][i] *= x[j][i]; 278 279 return *this; 280} 281 282template <typename vT, uint cT, uint rT, profile pT> 283typename base<vT, cT, rT, pT>::class_type& base<vT, cT, rT, pT>::operator/= 284( 285 typename base<vT, cT, rT, pT>::T const & x 286) 287{ 288 typename base<vT, cT, rT, pT>::size_type stop_col = x.col_size(); 289 typename base<vT, cT, rT, pT>::size_type stop_row = x.row_size(); 290 291 for(typename base<vT, cT, rT, pT>::size_type j = 0; j < stop_col; ++j) 292 for(typename base<vT, cT, rT, pT>::size_type i = 0; i < stop_row; ++i) 293 this->value[j][i] /= x; 294 295 return *this; 296} 297 298template <typename vT, uint cT, uint rT, profile pT> 299typename base<vT, cT, rT, pT>::class_type& base<vT, cT, rT, pT>::operator/= 300( 301 typename base<vT, cT, rT, pT>::class_type const & x 302) 303{ 304 typename base<vT, cT, rT, pT>::size_type stop_col = x.col_size(); 305 typename base<vT, cT, rT, pT>::size_type stop_row = x.row_size(); 306 307 for(typename base<vT, cT, rT, pT>::size_type j = 0; j < stop_col; ++j) 308 for(typename base<vT, cT, rT, pT>::size_type i = 0; i < stop_row; ++i) 309 this->value[j][i] /= x[j][i]; 310 311 return *this; 312} 313 314template <typename vT, uint cT, uint rT, profile pT> 315typename base<vT, cT, rT, pT>::class_type& base<vT, cT, rT, pT>::operator++ () 316{ 317 typename base<vT, cT, rT, pT>::size_type stop_col = col_size(); 318 typename base<vT, cT, rT, pT>::size_type stop_row = row_size(); 319 320 for(typename base<vT, cT, rT, pT>::size_type j = 0; j < stop_col; ++j) 321 for(typename base<vT, cT, rT, pT>::size_type i = 0; i < stop_row; ++i) 322 ++this->value[j][i]; 323 324 return *this; 325} 326 327template <typename vT, uint cT, uint rT, profile pT> 328typename base<vT, cT, rT, pT>::class_type& base<vT, cT, rT, pT>::operator-- () 329{ 330 typename base<vT, cT, rT, pT>::size_type stop_col = col_size(); 331 typename base<vT, cT, rT, pT>::size_type stop_row = row_size(); 332 333 for(typename base<vT, cT, rT, pT>::size_type j = 0; j < stop_col; ++j) 334 for(typename base<vT, cT, rT, pT>::size_type i = 0; i < stop_row; ++i) 335 --this->value[j][i]; 336 337 return *this; 338} 339 340} //namespace detail 341} //namespace glm 342