I am trying to make a roller coaster and currently I have created a spline class which loads a spline from a text file . So I have all the points and I have a Catmull-Rom Spline function but I have trouble figuring how a proper track can be created from those points.
Anyone done anything similar?
edit: Ok i think i will make it more clear now. I was working on it yesterday that's why i didn't reply sooner.
First problem is that my camera is going off tracks. This is the path generated: http://prntscr.com/ci9sud drawing it as GL_LINE_STRIP.
I have a cameraUpdate function:
float t = (float)TrackPointIndex / (float)1000; ++TrackPointIndex; point viewPoint = tr->over->getInterpolatedSplinePoint(t); t = (float)TrackPointIndex / (float)1000; ++TrackPointIndex; point nextPoint = tr->over->getInterpolatedSplinePoint(t); std::cout << "viewPoint " << glm::to_string(viewPoint) << std::endl; std::cout << "nextPoint " <<glm::to_string(nextPoint) << std::endl; if (TrackPointIndex == 1000) TrackPointIndex = 0; control->bodyTranslation = viewPoint; control->bodyRotation = nextPoint;
which with the use of getInterpolatedSplinePoint(t) returns the viewPoint and the nextPoint which are points on the spline. Printing them proves they are indeed on the line. But since i am using GLM i update my camera with the glm::lookAt function . So i thought that the first argument which is the camera position should be the viewPoint and the second one which is where the camera should be pointing at should be nextPoint . But that just doesn't work . cameraUpdate is called every 250ms or so but it is off tracks . Do i have to do any extra calculations to define where the camera should be / or be looking at?
That's my first problem.
The second one is not really a problem because i have not started working on it yet. I want to know how can somebody generate from the path a fairly good looking rail track.
Edit2: I put a sphere to travel through the tracks and it seems to be working fine . Still if i try moving the camera along the path it does not .
Anyone knows any way around this?