Changeset b545cad
 Timestamp:
 Nov 11, 2019, 2:41:41 PM (2 years ago)
 Branches:
 armeh, jacob/cs343translation, master, newastuniqueexpr
 Children:
 a39fd1d
 Parents:
 44f41997
 gitauthor:
 Dmitry Kobets <dkobets@…> (10/04/19 18:51:57)
 gitcommitter:
 Dmitry Kobets <dkobets@…> (11/11/19 14:41:41)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libcfa/src/vector.hfa
r44f41997 rb545cad 1 1 #pragma once 2 #include "math.hfa"2 #include <math.hfa> 3 3 #include <iostream.hfa> 4 4 5 5 // Vector Types  6 6 // TODO: make generic, as per glm 7 8 7 9 8 struct vec2 { … … 21 20 return os; 22 21 } 23 void ??( ostype & os, const vec2 v ) {22 void ??( ostype & os, const vec2& v ) { 24 23 (ostype &)(os  v); ends( os ); 25 24 } 25 } 26 27 void ?{}(vec2& vec, zero_t) with (vec) { 28 x = y = 0; 29 } 30 void ?{}(vec2& vec, vec2& other) with (vec) { 31 [x,y] = other.[x,y]; 26 32 } 27 33 … … 31 37 vec2 ?*?(const vec2& v, float scalar) with (v) { 32 38 return [x * scalar, y * scalar]; 39 } 40 vec2 ?*?(float scalar, const vec2& v) { 41 return v * scalar; 33 42 } 34 43 vec2 ?/?(const vec2& v, float scalar) with (v) { … … 58 67 return v / sqrt(dot(v, v)); 59 68 } 69 70 // project vector u onto vector v 71 static inline vec2 project(const vec2& u, const vec2& v) { 72 vec2 v_norm = normalize(v); 73 return v_norm * dot(u, v_norm); 74 } 75 76 /* returns the reflection direction : v  2.0 * project(v, n) 77 * for incident vector v and surface normal n 78 */ 79 static inline vec2 reflect(const vec2& v, const vec2& n) { 80 return v  2 * project(v, n); 81 } 82 83 // incident vector v, surface normal n 84 // eta = ratio of indices of refraction between starting material and 85 // entering material (i.e., from air to water, eta = 1/1.33) 86 static inline vec2 refract(const vec2& v, const vec2& n, float eta) { 87 float dotValue = dot(n, v); 88 float k = 1  eta * eta * (1  dotValue * dotValue); 89 if (k < 0) { 90 return 0; 91 } 92 return eta * v  (eta * dotValue + sqrt(k)) * n; 93 }
Note: See TracChangeset
for help on using the changeset viewer.