55
66namespace cage
77{
8- Real sdfPlane (const Vec3 & pos, const Plane & pln)
8+ Real sdfPlane (Vec3 pos, Plane pln)
99 {
1010 CAGE_ASSERT (pln.valid ());
1111 const Vec3 c = pln.normal * pln.d ;
1212 return dot (pln.normal , pos - c);
1313 }
1414
15- Real sdfSphere (const Vec3 & pos, Real radius)
15+ Real sdfSphere (Vec3 pos, Real radius)
1616 {
1717 return length (pos) - radius;
1818 }
1919
20- Real sdfCapsule (const Vec3 & pos, Real prolong, Real radius)
20+ Real sdfCapsule (Vec3 pos, Real prolong, Real radius)
2121 {
2222 Vec3 p = pos;
2323 p[2 ] += prolong * 0.5 ;
2424 p[2 ] -= clamp (p[2 ], 0 , prolong);
2525 return length (p) - radius;
2626 }
2727
28- Real sdfCylinder (const Vec3 & pos, Real halfHeight, Real radius)
28+ Real sdfCylinder (Vec3 pos, Real halfHeight, Real radius)
2929 {
3030 const Vec2 d = abs (Vec2 (length (Vec2 (pos)), pos[2 ])) - Vec2 (radius, halfHeight);
3131 return min (max (d[0 ], d[1 ]), 0 ) + length (max (d, 0 ));
3232 }
3333
34- Real sdfBox (const Vec3 & pos, const Vec3 & radius)
34+ Real sdfBox (Vec3 pos, Vec3 radius)
3535 {
3636 const Vec3 p = abs (pos) - radius;
3737 return length (max (p, 0 )) + min (max (p[0 ], max (p[1 ], p[2 ])), 0 );
3838 }
3939
40- Real sdfTetrahedron (const Vec3 & pos, Real radius)
40+ Real sdfTetrahedron (Vec3 pos, Real radius)
4141 {
4242 static constexpr const Vec3 corners[4 ] = { Vec3 (1 , 1 , 1 ), Vec3 (1 , -1 , -1 ), Vec3 (-1 , 1 , -1 ), Vec3 (-1 , -1 , 1 ) };
4343 static constexpr const Triangle tris[4 ] = {
@@ -59,7 +59,7 @@ namespace cage
5959 return mad * radius;
6060 }
6161
62- Real sdfOctahedron (const Vec3 & pos, Real radius)
62+ Real sdfOctahedron (Vec3 pos, Real radius)
6363 {
6464 const Vec3 p = abs (pos);
6565 const Real m = p[0 ] + p[1 ] + p[2 ] - radius;
@@ -76,7 +76,7 @@ namespace cage
7676 return length (Vec3 (q[0 ], q[1 ] - radius + k, q[2 ] - k));
7777 }
7878
79- Real sdfHexagonalPrism (const Vec3 & pos, Real halfHeight, Real radius)
79+ Real sdfHexagonalPrism (Vec3 pos, Real halfHeight, Real radius)
8080 {
8181 static constexpr Vec3 k = Vec3 (-0.8660254 , 0.5 , 0.57735 );
8282 Vec3 p = abs (pos);
@@ -85,13 +85,13 @@ namespace cage
8585 return min (max (d[0 ], d[1 ]), 0.0 ) + length (max (d, 0.0 ));
8686 }
8787
88- Real sdfTorus (const Vec3 & pos, Real major, Real minor)
88+ Real sdfTorus (Vec3 pos, Real major, Real minor)
8989 {
9090 const Vec2 q = Vec2 (length (Vec2 (pos)) - major, pos[2 ]);
9191 return length (q) - minor;
9292 }
9393
94- Real sdfKnot (const Vec3 & pos, Real scale, Real k)
94+ Real sdfKnot (Vec3 pos, Real scale, Real k)
9595 {
9696 static constexpr Real TAU = Real::Pi () * 2 ;
9797 static constexpr Real norm = 2 / 14.4 ;
0 commit comments