Thread: vector trouble

  1. #16
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I believe some people have written ray tracers. Ask your questions concerning them in the Game Programming forum.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #17
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by h3ro View Post
    Just a question to the ones who looked at the source code, is my programing hard to read, or did it go ok?
    I think it's fine. I wouldn't waste an indent level on "public" and "private" though

    I also see you're using abstract virtuals appropriately. Cool beans. Good design so far.

  3. #18
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    A new question:

    When I try to add "std::vector <Triangle> triangleList;" as a public in my mesh class I get this error:
    from main.cpp In file included from Scene.h:6, from main.cpp
    using-declaration for non-member at class scope

    Does that mean that the variable name is already taken? (Its not, as there is no such variable in scene.h)

    Code:
    // mesh class
    class Mesh : public Primitive
    {
          public:
                 Mesh(std::string fName);
                 
                 result intersectionTest(Ray r);
                 Vector3D getPos();
                 // loadFromFile();
                 // bounding box
                 // getNormalX(int triangle)
                 
                 std::vector <Triangle> triangleList;   // <--- Error
          private:
                  // triangleList class Triangle?
                  // No of triangles
    };

  4. #19
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    It's good code. There's some things I would do differently... like the 'result' class is a bit of a cludge.
    Code:
    result Sphere::intersectionTest(Ray r)
    Also, having a 'Point' class is bad. It doesn't help you do anything you couldn't do using a Vector3D, and in fact you have to convert it back to a Vector3d to do anything mathematically interesting.

    If you want to distinguish that a certain variable is a point, you should do so by putting the word 'point' in the variable's name, not making a new class.

    And yea, I've written a ray tracer before. Thanks for the opportunity to plug my pictures =)
    http://questionc.com/graphics/
    Callou collei we'll code the way
    Of prime numbers and pings!

  5. #20
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Also, having a 'Point' class is bad. It doesn't help you do anything you couldn't do using a Vector3D, and in fact you have to convert it back to a Vector3d to do anything mathematically interesting.
    I know, but when I started writing this thing I had no knowledge of how to do it, so I tried to implement as much as possible from a book I bought (Physically based rendering), and there they uses Point for a few things. I later found out that this made things much harder, so I decided to make a easy way of fixing it instead of rewriting so much.

    And yea, I've written a ray tracer before. Thanks for the opportunity to plug my pictures =)
    Nice work! I see you started with global illumination, was it hard to implement? So far I only have diffuse lighting as you probably saw

    Right now I'm thinking of removing all the primitive classes and only have a mesh class. Its so much more fun to have some real objects instead of just spheres. But I plan to keep the sphere (and add at least box) code and use it for bounding box calculations to speed it all up.

    What do you think of doing mesh collision like this:
    Code:
    intersectionTest(Ray r)
    {
          if (boundingBoxTest == 1)
                 Check each of the triangles
                 Return the closest one
    }
    I think that will save a lot of calculation time.

    Btw: Are you still working on your raytracer?

  6. #21
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    That's standard procedure to shortcut collision tests. So yeah, it's a good thing.

    Another standard procedure is to sort all objects by location, e.g. in an octree. This way, you can quickly kick out a lot of elements. (Basically, everything that is not in the same subtree.)
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #22
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Another standard procedure is to sort all objects by location, e.g. in an octree. This way, you can quickly kick out a lot of elements. (Basically, everything that is not in the same subtree.)
    Thats nice. Ive seen that octrees often pops up when I read about raytracing. Looks like a nice concept, but I have a lot of other stuff to add first. This is the biggest program I have made so far so I'm not trying to create a kick-ass raytracer, just trying to learn stuff. If I get my mesh class to work so that I can load objects from my 3d program Im more than happy.

    What kind of information would I need to export?
    I know I will need the three vertexes of all triangles in the mesh, and probably the normal. Is there any other key parts? Im not going to export materials or UVs.

    I know there are a lot of formats that I could try to use, but I kind of like to make my own, if its not to complicated

  8. #23
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Quote Originally Posted by h3ro View Post
    I know, but when I started writing this thing I had no knowledge of how to do it, so I tried to implement as much as possible from a book I bought (Physically based rendering), and there they uses Point for a few things. I later found out that this made things much harder, so I decided to make a easy way of fixing it instead of rewriting so much.


    Nice work! I see you started with global illumination, was it hard to implement? So far I only have diffuse lighting as you probably saw

    Right now I'm thinking of removing all the primitive classes and only have a mesh class. Its so much more fun to have some real objects instead of just spheres. But I plan to keep the sphere (and add at least box) code and use it for bounding box calculations to speed it all up.

    What do you think of doing mesh collision like this:
    Code:
    intersectionTest(Ray r)
    {
          if (boundingBoxTest == 1)
                 Check each of the triangles
                 Return the closest one
    }
    I think that will save a lot of calculation time.

    Btw: Are you still working on your raytracer?
    • You can't remove all your primitive classes... even the Mesh class depends on Triangle's methods.
    • I pretty much had GI done, Global Illumination is relatively simple compared to the other problems in Raytracing. It just takes a sick amount of time to process. The grainy picture on my page represents maybe 5 minutes worth of processing (I was impatient). I like that image though.
    • The Raytracer images are from about five years ago, I'm not working on it anymore. It was part of an independent study in College and I lost the sources during a botched OS upgrage.
    • When exporting a triangle, only export the three vertices. The Normal should be computed ny the constructor.
    Callou collei we'll code the way
    Of prime numbers and pings!

Popular pages Recent additions subscribe to a feed