Changeset af0bf71
 Timestamp:
 Nov 11, 2019, 2:41:41 PM (4 years ago)
 Branches:
 ADT, armeh, astexperimental, enum, forallpointerdecay, jacob/cs343translation, master, newastuniqueexpr, pthreademulation, qualifiedEnum
 Children:
 0856a96
 Parents:
 e1a0945
 gitauthor:
 Dmitry Kobets <dkobets@…> (10/11/19 15:57:39)
 gitcommitter:
 Dmitry Kobets <dkobets@…> (11/11/19 14:41:41)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libcfa/src/vector.hfa
re1a0945 raf0bf71 6 6 float x, y; 7 7 }; 8 9 static inline { 8 10 9 11 // Constructors … … 18 20 x = y = val; 19 21 } 20 void ?{}(vec2& vec, vec2& other) with (vec) {22 void ?{}(vec2& vec, const vec2& other) with (vec) { 21 23 [x,y] = other.[x,y]; 22 24 } … … 54 56 return [x * scalar, y * scalar]; 55 57 } 58 vec2 ?*?(float scalar, const vec2& v) { 59 return v * scalar; 60 } 56 61 vec2& ?*=?(vec2& v, float scalar) with (v) { 57 62 v = v * scalar; 58 63 return v; 59 }60 vec2 ?*?(float scalar, const vec2& v) {61 return v * scalar;62 64 } 63 65 … … 95 97 /* // These functions implement the Geometric Functions section of GLSL for 2D vectors*/ 96 98 97 static inlinefloat dot(const vec2& u, const vec2& v) {99 float dot(const vec2& u, const vec2& v) { 98 100 return u.x * v.x + u.y * v.y; 99 101 } 100 102 101 static inlinefloat length(const vec2& v) {103 float length(const vec2& v) { 102 104 return sqrt(dot(v, v)); 103 105 } 104 106 105 static inline float distance(const vec2& v1, const vec2& v2) { 107 float length_squared(const vec2& v) { 108 return dot(v, v); 109 } 110 111 float distance(const vec2& v1, const vec2& v2) { 106 112 return length(v1  v2); 107 113 } 108 114 109 static inlinevec2 normalize(const vec2& v) {115 vec2 normalize(const vec2& v) { 110 116 return v / sqrt(dot(v, v)); 111 117 } 112 118 113 119 // Project vector u onto vector v 114 static inlinevec2 project(const vec2& u, const vec2& v) {120 vec2 project(const vec2& u, const vec2& v) { 115 121 vec2 v_norm = normalize(v); 116 122 return v_norm * dot(u, v_norm); … … 118 124 119 125 // Reflect incident vector v with respect to surface with normal n 120 static inlinevec2 reflect(const vec2& v, const vec2& n) {126 vec2 reflect(const vec2& v, const vec2& n) { 121 127 return v  2 * project(v, n); 122 128 } … … 125 131 // eta is the ratio of indices of refraction between starting material and 126 132 // entering material (i.e., from air to water, eta = 1/1.33) 127 static inlinevec2 refract(const vec2& v, const vec2& n, float eta) {133 vec2 refract(const vec2& v, const vec2& n, float eta) { 128 134 float dotValue = dot(n, v); 129 float k = 1  eta * eta * (1  dotValue * dotValue);135 float k = 1  eta \ 2 * (1  dotValue \ 2); 130 136 if (k < 0) { 131 137 return 0; … … 134 140 } 135 141 136 // Used to render perturbed surfaces by ensuring that a perturbed normal137 // is pointing in the same direction as the geometric normal of the138 // surface.142 // Given a perturbed normal and a geometric normal, 143 // flip the perturbed normal if the geometric normal is pointing away 144 // from the observer. 139 145 // n is the perturbed vector that we want to align 140 146 // i is the incident vector 141 147 // ng is the geometric normal of the surface 142 static inline vec2 faceforward(const vec2& n, const vec2& i, floatng) {143 return dot(n , i) < 0 ? ng : ng;148 vec2 faceforward(const vec2& n, const vec2& i, const vec2& ng) { 149 return dot(ng, i) < 0 ? n : n; 144 150 } 151 152 }
Note: See TracChangeset
for help on using the changeset viewer.