I am currently taking a computer graphics course in C++ and having to do exams for it. The current task says:
Make sure, the recursive function 'trace_recursive' gets stopped at the recursion depth 'max-depth' without changing the code of 'trace-recursive'.
I have worked with recursion before, but always with my own recursive functions, where I could set my own end to the function. Is there any way to kill a recursive function from 'outside' the function in C++ without killing the whole program?
I always thought you need to stop recursion from inside the function and I did not find anything online that helps me with my problem.
Edit:
This is the method, that calls 'trace_recursive':
glm::vec3 evaluate_reflection(
RenderData &data, // class containing raytracing information
int depth, // the current recursion depth
glm::vec3 const& P, // world space position
glm::vec3 const& N, // normal at the position (already normalized)
glm::vec3 const& V) // view vector (already normalized){
glm::vec3 Refl = reflect(V, N);
float epsilon = data.context.params.ray_epsilon;
Ray ray(P + epsilon*Refl, Refl);
glm::vec3 Mirror = trace_recursive(data, ray, depth);
return Mirror;}
I am not allowed to post the code of the actual function 'trace_recursive'
What my method is asked to do is:
Create the vector Refl; create the ray; create the vector mirror by using trace_recursive. If trace recursive reaches a recursive depth of for example 5, it should return the current value and stop, even if it would not stop by itself.