Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Manni-99 committed Sep 18, 2024
1 parent 9c96ba7 commit cbdde1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/EDAF80/assignment2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ edaf80::Assignment2::run()
// Compute the interpolation factor
float total_duration = 10.0f;
float t = std::fmod(elapsed_time_s, total_duration) / total_duration;

// Determine which segment of control points to use
size_t segment = static_cast<size_t>(t * (control_point_locations.size() - 3));
float local_t = (t * (control_point_locations.size() - 3)) - segment;

printf("Segment value: %zu\n", segment);
// Get control points for this segment
glm::vec3 p0 = control_point_locations[segment];
glm::vec3 p1 = control_point_locations[segment + 1];
Expand Down
23 changes: 5 additions & 18 deletions src/EDAF80/interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,14 @@ interpolation::evalCatmullRom(glm::vec3 const &p0, glm::vec3 const &p1,
glm::vec4 xVec = glm::vec4(1.0f, x, x*x, x*x*x);

// Catmull-Rom matrix
glm::mat4 m = glm::mat4(glm::vec4(0.0f, 1.0f, 0.0f, 0.0f),
glm::mat4 m = glm::transpose(glm::mat4(glm::vec4(0.0f, 1.0f, 0.0f, 0.0f),
glm::vec4(-t, 0.0f, t, 0.0f),
glm::vec4(2.0f*t, t-3.0f, 3.0f-2.0f*t, -t),
glm::vec4(-t, 2.0f-t, t-2.0f, t));
glm::vec4(-t, 2.0f-t, t-2.0f, t)));

// Control points in homogeneous coordinates
glm::vec4 p0Vec = glm::vec4(p0, 1.0f);
glm::vec4 p1Vec = glm::vec4(p1, 1.0f);
glm::vec4 p2Vec = glm::vec4(p2, 1.0f);
glm::vec4 p3Vec = glm::vec4(p3, 1.0f);

// Create a matrix with control points as columns
glm::mat4 controlPoints;
controlPoints[0] = p0Vec;
controlPoints[1] = p1Vec;
controlPoints[2] = p2Vec;
controlPoints[3] = p3Vec;
glm::mat4x3 points = glm::mat4x3(p0, p1, p2, p3);


// Compute the interpolated position
glm::vec4 resultVec = xVec * (m * controlPoints);

// Return the result as glm::vec3
return glm::vec3(resultVec);
return xVec * m * glm::transpose(points);
}

0 comments on commit cbdde1c

Please sign in to comment.