Question

A couple of friends and I are trying to code a small animated segment. So, we decided that a good and still somewhat simple proyect would be to make some kind of horror house tour, in which the "player" travels in a cart across an abandoned mine.

Since making circles and straight lines is kind of boring, we decided to make a "slightly" more complex motion. We reasoned that we could import a .obj with a simple vertex strip that would act as a path to move along. This object would, of course, not be drawn on screen. So, I created a Trayectory class to handle the importing of this path. Here is the code I use to import the path:

Trayectory::Trayectory(String^ obj)
{
this->vert = gcnew List<Point3D^>();
this->norm = gcnew List<Point3D^>();

StreamReader^ archivo=gcnew StreamReader(obj);

array<String^>^ file = archivo->ReadToEnd()->Split('\n');
archivo->Close();

for each(String^ s in file) {
    array<String^>^ str = s->Split(' ');

    if(str[0]=="v") {
        Point3D^ tmp = gcnew Point3D(Convert::ToSingle(str[1]),Convert::ToSingle(str[2]),Convert::ToSingle(str[3]));
        this->vert->Add(tmp);
    }

    if(str[0]=="vn") {
        Point3D^ tmp = gcnew Point3D(Convert::ToSingle(str[1]),Convert::ToSingle(str[2])+1.0,Convert::ToSingle(str[3]));
        this->norm->Add(tmp);
    }
}
}

I have two small issues, however:

  1. Since I am using vertex strips, I can't assign normals to them. Is there a way to calculate a normal to use with gluLookAt()?
  2. When I render the object, I translate it to a vertex in my vert List and assign it's lookat to the next vertex in the line. However this brings the issue that vertices in my .obj are not necessarily in order. Is there any way to order them? I reasoned that I could calculate which was the closest vertex to each one and do a bubble sort-like sorting. But can it be any easier?
Was it helpful?

Solution

  1. vn can only indicate the top => vn may be (0,0,1);in the gluLookAt up vector using for calculating side vector: side=forward X up.
  2. This may be the appropriate method. Dont set the order in runtime.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top