Skip to content

Commit

Permalink
Cylinder work
Browse files Browse the repository at this point in the history
  • Loading branch information
intns committed Jan 13, 2025
1 parent 5f99b74 commit d252d7d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
22 changes: 11 additions & 11 deletions include/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
struct Sphere;

/**
* @brief TODO
* @brief A representation of a cylinder in 3D space.
*/
struct Cylinder {
Cylinder(Vector3f& p1, Vector3f& p2, f32 p3)
: _00(p1)
, _0C(p2)
, _18(p3)
Cylinder(Vector3f& startPoint, Vector3f& endPoint, f32 radius)
: mStartPoint(startPoint)
, mEndPoint(endPoint)
, mRadius(radius)
{
}

void get2dDist(Vector3f&);
void collide(const Sphere&, Vector3f&, f32&);
f32 getPosRatio(const Vector3f&);
f32 get2dDist(Vector3f& point);
void collide(const Sphere& sphere, Vector3f& point, f32& depth);
f32 getPosRatio(const Vector3f& point); // 0-1 along the cylinder axis

Vector3f _00; // _00
Vector3f _0C; // _0C
f32 _18; // _18
Vector3f mStartPoint; // _00
Vector3f mEndPoint; // _0C
f32 mRadius; // _18
};

/**
Expand Down
30 changes: 28 additions & 2 deletions src/plugPikiKando/collInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,34 @@ static char* _typeStr[] = {
* Address: 80086CC4
* Size: 0002DC
*/
void Cylinder::get2dDist(Vector3f&)
f32 Cylinder::get2dDist(Vector3f& point)
{
// Calculate cylinder direction vector
Vector3f cylinderDir = mEndPoint - mStartPoint;

Vector3f normalised = cylinderDir;

// Project point onto cylinder axis
f32 length = normalised.normalise();
f32 projectionRatio = normalised.DP(point - mStartPoint) / length;

if (projectionRatio < 0.0f) {
// Before cylinder start - get 2D distance to start point
Vector3f startToPoint = mStartPoint - point;
return sqrtf(startToPoint.x * startToPoint.x + startToPoint.z * startToPoint.z);
}

if (projectionRatio > 1.0f) {
// Past cylinder end - get 2D distance to end point
Vector3f endToPoint = mEndPoint - point;
return sqrtf(endToPoint.x * endToPoint.x + endToPoint.z * endToPoint.z);
}

// On cylinder body - get distance to projected point
Vector3f projectedPoint = (normalised * projectionRatio) + mStartPoint;
Vector3f projToPoint = projectedPoint - point;
return sqrtf(projToPoint.x * projToPoint.x + projToPoint.z * projToPoint.z);

/*
.loc_0x0:
mflr r0
Expand Down Expand Up @@ -761,7 +787,7 @@ bool Tube::collide(const Sphere&, Vector3f&, f32&)
* Address: 800876C8
* Size: 0000E4
*/
f32 Cylinder::getPosRatio(const Vector3f&)
f32 Cylinder::getPosRatio(const Vector3f& vec)
{
/*
.loc_0x0:
Expand Down

0 comments on commit d252d7d

Please sign in to comment.