I believe some people have written ray tracers. Ask your questions concerning them in the Game Programming forum.
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
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 };
It's good code. There's some things I would do differently... like the 'result' class is a bit of a cludge.
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.Code:result Sphere::intersectionTest(Ray r)
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!
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.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.
Nice work! I see you started with global illumination, was it hard to implement? So far I only have diffuse lighting as you probably sawAnd yea, I've written a ray tracer before. Thanks for the opportunity to plug my pictures =)
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:
I think that will save a lot of calculation time.Code:intersectionTest(Ray r) { if (boundingBoxTest == 1) Check each of the triangles Return the closest one }
Btw: Are you still working on your raytracer?
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
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.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.)
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
- 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!