Files
firestorm/Gameleap/code/mw4/Libraries/stuff/Spline.cpp
T
Cyd 2b8ca921cb Initial full mirror of c:\VWE (source + assets + toolchain + outputs) via Git LFS
Complete disaster-recovery snapshot: engine/game source, game data assets,
VC6 toolchain + DX SDKs, build outputs, deployed game, and _UNUSED archive.
Large binaries in Git LFS; text preserved byte-for-byte (core.autocrlf=false,
no eol attributes). See RECOVERY.md for the one-clone rebuild procedure.
2026-06-24 21:28:16 -05:00

102 lines
2.4 KiB
C++

#include "StuffHeaders.hpp"
#include "Spline.hpp"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
CubicCurve::CubicCurve(
const Point3D& p1,
const Vector3D& r1,
const Point3D& p4,
const Vector3D& r4
)
{
Check_Pointer(this);
Check_Object(&p1);
Check_Object(&r1);
Check_Object(&p4);
Check_Object(&r4);
//
//----------------------------------
// Generate the hermite basis matrix
//----------------------------------
//
basisMatrix(0,0) = 2.0f*(p1.x - p4.x) + r1.x + r4.x;
basisMatrix(0,1) = 2.0f*(p1.y - p4.y) + r1.y + r4.y;
basisMatrix(0,2) = 2.0f*(p1.z - p4.z) + r1.z + r4.z;
basisMatrix(1,0) = 3.0f*(p4.x - p1.x) - 2.0f*r1.x - r4.x;
basisMatrix(1,1) = 3.0f*(p4.y - p1.y) - 2.0f*r1.y - r4.y;
basisMatrix(1,2) = 3.0f*(p4.z - p1.z) - 2.0f*r1.z - r4.z;
basisMatrix(2,0) = r1.x;
basisMatrix(2,1) = r1.y;
basisMatrix(2,2) = r1.z;
basisMatrix(3,0) = p1.x;
basisMatrix(3,1) = p1.y;
basisMatrix(3,2) = p1.z;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
CubicCurve::CubicCurve(
const Point3D& p1,
const Point3D& p2,
const Point3D& p3,
const Point3D& p4
)
{
Check_Pointer(this);
Check_Object(&p1);
Check_Object(&p2);
Check_Object(&p3);
Check_Object(&p4);
//
//---------------------------------
// Generate the bezier basis matrix
//---------------------------------
//
basisMatrix(0,0) = p4.x - p1.x + 3.0f*(p2.x - p3.x);
basisMatrix(0,1) = p4.y - p1.y + 3.0f*(p2.y - p3.y);
basisMatrix(0,2) = p4.z - p1.z + 3.0f*(p2.z - p3.z);
basisMatrix(1,0) = 3.0f*(p1.x + p3.x) - 6.0f*p2.x;
basisMatrix(1,1) = 3.0f*(p1.y + p3.y) - 6.0f*p2.y;
basisMatrix(1,2) = 3.0f*(p1.z + p3.z) - 6.0f*p2.z;
basisMatrix(2,0) = 3.0f*(p2.x - p1.x);
basisMatrix(2,1) = 3.0f*(p2.y - p1.y);
basisMatrix(2,2) = 3.0f*(p2.z - p1.z);
basisMatrix(3,0) = p1.x;
basisMatrix(3,1) = p1.y;
basisMatrix(3,2) = p1.z;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
CubicCurve::Evaluate(
Scalar t,
Point3D *p,
Vector3D *v
)
{
Check_Object(this);
Check_Pointer(p);
Check_Pointer(v);
Verify(t >= 0.0f && t <= 1.0f);
Point3D t_pos;
t_pos.z = t;
t_pos.y = t_pos.z * t;
t_pos.x = t_pos.y * t;
p->Multiply(t_pos, basisMatrix);
Vector3D t_vec(3.0f*t*t, 2.0f*t, 1.0f);
v->Multiply(t_vec, basisMatrix);
}