MCPcopy Create free account
hub / github.com/DavidColson/Polybox / SubDivide

Function SubDivide

source/shapes.cpp:122–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120// ***********************************************************************
121
122void SubDivide(Vec3f v1, Vec3f v2, Vec3f v3, i32 depth) {
123 if (depth == 0) {
124 DrawTriangle( v1, v2, v3);
125 return;
126 }
127 // midpoint of each edge
128 Vec3f v12;
129 Vec3f v23;
130 Vec3f v31;
131 for (int i = 0; i < 3; i++) {
132 v12[i] = v1[i] + v2[i];
133 v23[i] = v2[i] + v3[i];
134 v31[i] = v3[i] + v1[i];
135 }
136 v12 = v12.GetNormalized();
137 v23 = v23.GetNormalized();
138 v31 = v31.GetNormalized();
139
140 SubDivide( v1, v12, v31, depth - 1);
141 SubDivide( v2, v23, v12, depth - 1);
142 SubDivide( v3, v31, v23, depth - 1);
143 SubDivide( v12, v23, v31, depth - 1);
144}
145
146// ***********************************************************************
147

Callers 1

DrawIcosahedronFunction · 0.85

Calls 1

DrawTriangleFunction · 0.85

Tested by

no test coverage detected