Skip to content

Commit

Permalink
passing vec3 as value
Browse files Browse the repository at this point in the history
  • Loading branch information
malytomas committed Jan 22, 2025
1 parent cc339b4 commit 4ea0687
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
20 changes: 10 additions & 10 deletions sources/include/cage-core/signedDistanceFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

namespace cage
{
CAGE_CORE_API Real sdfPlane(const Vec3 &pos, const Plane &plane);
CAGE_CORE_API Real sdfSphere(const Vec3 &pos, Real radius);
CAGE_CORE_API Real sdfCapsule(const Vec3 &pos, Real prolong, Real radius);
CAGE_CORE_API Real sdfCylinder(const Vec3 &pos, Real halfHeight, Real radius);
CAGE_CORE_API Real sdfBox(const Vec3 &pos, const Vec3 &radius);
CAGE_CORE_API Real sdfTetrahedron(const Vec3 &pos, Real radius);
CAGE_CORE_API Real sdfOctahedron(const Vec3 &pos, Real radius);
CAGE_CORE_API Real sdfHexagonalPrism(const Vec3 &pos, Real halfHeight, Real radius);
CAGE_CORE_API Real sdfTorus(const Vec3 &pos, Real major, Real minor);
CAGE_CORE_API Real sdfKnot(const Vec3 &pos, Real scale, Real k);
CAGE_CORE_API Real sdfPlane(Vec3 pos, Plane plane);
CAGE_CORE_API Real sdfSphere(Vec3 pos, Real radius);
CAGE_CORE_API Real sdfCapsule(Vec3 pos, Real prolong, Real radius);
CAGE_CORE_API Real sdfCylinder(Vec3 pos, Real halfHeight, Real radius);
CAGE_CORE_API Real sdfBox(Vec3 pos, Vec3 radius);
CAGE_CORE_API Real sdfTetrahedron(Vec3 pos, Real radius);
CAGE_CORE_API Real sdfOctahedron(Vec3 pos, Real radius);
CAGE_CORE_API Real sdfHexagonalPrism(Vec3 pos, Real halfHeight, Real radius);
CAGE_CORE_API Real sdfTorus(Vec3 pos, Real major, Real minor);
CAGE_CORE_API Real sdfKnot(Vec3 pos, Real scale, Real k);
}

#endif // guard_signedDistanceFunction_h_sdfgr1esd56r
20 changes: 10 additions & 10 deletions sources/libcore/signedDistanceFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@

namespace cage
{
Real sdfPlane(const Vec3 &pos, const Plane &pln)
Real sdfPlane(Vec3 pos, Plane pln)
{
CAGE_ASSERT(pln.valid());
const Vec3 c = pln.normal * pln.d;
return dot(pln.normal, pos - c);
}

Real sdfSphere(const Vec3 &pos, Real radius)
Real sdfSphere(Vec3 pos, Real radius)
{
return length(pos) - radius;
}

Real sdfCapsule(const Vec3 &pos, Real prolong, Real radius)
Real sdfCapsule(Vec3 pos, Real prolong, Real radius)
{
Vec3 p = pos;
p[2] += prolong * 0.5;
p[2] -= clamp(p[2], 0, prolong);
return length(p) - radius;
}

Real sdfCylinder(const Vec3 &pos, Real halfHeight, Real radius)
Real sdfCylinder(Vec3 pos, Real halfHeight, Real radius)
{
const Vec2 d = abs(Vec2(length(Vec2(pos)), pos[2])) - Vec2(radius, halfHeight);
return min(max(d[0], d[1]), 0) + length(max(d, 0));
}

Real sdfBox(const Vec3 &pos, const Vec3 &radius)
Real sdfBox(Vec3 pos, Vec3 radius)
{
const Vec3 p = abs(pos) - radius;
return length(max(p, 0)) + min(max(p[0], max(p[1], p[2])), 0);
}

Real sdfTetrahedron(const Vec3 &pos, Real radius)
Real sdfTetrahedron(Vec3 pos, Real radius)
{
static constexpr const Vec3 corners[4] = { Vec3(1, 1, 1), Vec3(1, -1, -1), Vec3(-1, 1, -1), Vec3(-1, -1, 1) };
static constexpr const Triangle tris[4] = {
Expand All @@ -59,7 +59,7 @@ namespace cage
return mad * radius;
}

Real sdfOctahedron(const Vec3 &pos, Real radius)
Real sdfOctahedron(Vec3 pos, Real radius)
{
const Vec3 p = abs(pos);
const Real m = p[0] + p[1] + p[2] - radius;
Expand All @@ -76,7 +76,7 @@ namespace cage
return length(Vec3(q[0], q[1] - radius + k, q[2] - k));
}

Real sdfHexagonalPrism(const Vec3 &pos, Real halfHeight, Real radius)
Real sdfHexagonalPrism(Vec3 pos, Real halfHeight, Real radius)
{
static constexpr Vec3 k = Vec3(-0.8660254, 0.5, 0.57735);
Vec3 p = abs(pos);
Expand All @@ -85,13 +85,13 @@ namespace cage
return min(max(d[0], d[1]), 0.0) + length(max(d, 0.0));
}

Real sdfTorus(const Vec3 &pos, Real major, Real minor)
Real sdfTorus(Vec3 pos, Real major, Real minor)
{
const Vec2 q = Vec2(length(Vec2(pos)) - major, pos[2]);
return length(q) - minor;
}

Real sdfKnot(const Vec3 &pos, Real scale, Real k)
Real sdfKnot(Vec3 pos, Real scale, Real k)
{
static constexpr Real TAU = Real::Pi() * 2;
static constexpr Real norm = 2 / 14.4;
Expand Down
4 changes: 4 additions & 0 deletions sources/libcore/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ namespace cage
{
func = wasm_runtime_lookup_function(instance->instance, name.c_str());
if (!func)
{
CAGE_LOG_THROW(Stringizer() + "function: " + name);
CAGE_THROW_ERROR(Exception, "wasm function not found");
}

const uint32 rc = wasm_func_get_result_count(func, instance->instance);
if (rc >= 2)
Expand Down Expand Up @@ -471,6 +474,7 @@ namespace cage
{
const String e = wasm_runtime_get_exception(impl->instance->instance);
CAGE_LOG_THROW(e);
CAGE_LOG_THROW(Stringizer() + "function: " + impl->name);
CAGE_THROW_ERROR(Exception, "wasm function call failed");
}
}
Expand Down

0 comments on commit 4ea0687

Please sign in to comment.