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?

  • \$\begingroup\$ Where are you running into trouble? Evaluating the spline function to sample points on the curve? Deciding which points / how densely to sample? Offsetting the curve to make two parallel rails? Extruding polygons along the sampled points to create a 2D or 3D rail with a particular cross section? The more you can tell us about what you've done and where you're stuck, the better we can target advice to help you out. \$\endgroup\$
    – DMGregory
    Sep 14, 2016 at 12:34
  • \$\begingroup\$ The code you've shown looks to me like it should follow the track. (Though for robustness you might want to mod by 1000 or check >= instead of ==, in case you overshoot the end). Can you show us your camera positioning & rotation code - maybe the problem is there. \$\endgroup\$
    – DMGregory
    Sep 21, 2016 at 12:42
  • \$\begingroup\$ Hey, for the camera i am using the glm::lookAt(this->bodyTranslation, this->bodyRotation, glm::vec3(0, 1, 0)); . So the camera is positioned in bodyTranslation and is looking towards the next point. Isn't that correct? \$\endgroup\$
    – mkanakis
    Sep 22, 2016 at 22:30
  • \$\begingroup\$ It sounds like you should include a video of the problem. Nothing obvious jumps out from the code alone. \$\endgroup\$
    – DMGregory
    Sep 22, 2016 at 22:58
  • \$\begingroup\$ Ok i will provide one soon enough. It is uploading. \$\endgroup\$
    – mkanakis
    Sep 23, 2016 at 8:22


You must log in to answer this question.

Browse other questions tagged .