Small thing, but some of the examples have some pretty bad undefined behavior bugs. For instance: Matrix& operator*( const double scalar, const Matrix& rhs) { Matrix result(rhs); result *= scalar; return result; } (Returning a reference to a stack variable is undefined behavior, but realistically you're probably either looking at a hard crash or a really hard to track down bug)
Introduction to the Math of Computer Graphics
21–30 of 35 posts
Re: Introduction to the Math of Computer Graphics
#22From the title, I was hoping this would cover coordinate systems, the Bresenham line algorithm and midpoint circle algorithm, Lambertian reflection, perspective transformation, quaternions, Gouraud and Phong shading, rotation, metaball approximation, parametric vs. implicit vs. explicit function representation, splines, ray tracing, alpha compositing, and some basic filtering. Instead, it consists only of basic linear algebra — it doesn't even cover how to generate a rotation matrix! However, it does cover a lot of stuff that basically doesn't come up at all in computer graphics, like multiplying nonsquare matrices together, and as pandaman points out, adding matrices together.
(Also, as overgard points out, the code contains basic novice errors: https://news.ycombinator.com/item?id=10812881)
(pandaman correctly points out that matrix-vector multiply is a special case of multiplying nonsquare matrices. I still don't think you need to deal with that in an introduction; it's easy to learn as a special case, and that's probably how you'll have to code it anyway!)
Unfortunately, I don't know where to point people for a real introduction to the math of computer graphics. This is a shame; even without libraries and hardware, you can do rotating 3-D shapes in just 15 lines of code http://canonical.org/~kragen/sw/netbook-misc-devel/rotcube.p... or ray-tracing in 186: http://canonical.org/~kragen/sw/aspmisc/my-very-first-raytra... or basic VR with your cellphone accelerometer in 114: http://canonical.org/~kragen/sw/81hacks/topopt-ar/
(That last one is cheating a little bit since I didn't write the circle-drawing algorithm myself, so it isn't included in the line count.)
Math is super powerful when you apply it to computer graphics. It empowers you to make magic happen in only a few hours and a few dozen lines of code, and the magic is visible even to people who can't program. You don't have to understand all that math stuff I mentioned in the first paragraph in order to do these things.
Re: Introduction to the Math of Computer Graphics
#23This post is mistitled, and I really wish I knew where to find a thing that is what this post claims to be. From the title, I was hoping this would cover coordinate systems, the Bresenham line algorithm and midpoint circle algorithm, Lambertian reflection, perspective transformation, quaternions, Gouraud and Phong shading, rotation, metaball approximation, parametric vs. implicit vs. explicit function representation,…
Re: Introduction to the Math of Computer Graphics
#24This post is mistitled, and I really wish I knew where to find a thing that is what this post claims to be. From the title, I was hoping this would cover coordinate systems, the Bresenham line algorithm and midpoint circle algorithm, Lambertian reflection, perspective transformation, quaternions, Gouraud and Phong shading, rotation, metaball approximation, parametric vs. implicit vs. explicit function representation,…
Matrix multiplication by vector and vice versa is a multiplication by at least one non-square matrix. But matrix addition, on the other hand, is something I have never seen come up in graphics.
Re: Introduction to the Math of Computer Graphics
#25Earlier quoted context omitted.
Matrix multiplication by vector and vice versa is a multiplication by at least one non-square matrix. But matrix addition, on the other hand, is something I have never seen come up in graphics.
[deleted]
Re: Introduction to the Math of Computer Graphics
#26Earlier quoted context omitted.
I've been using quaternions for 15 years now and I still don't have a good mental image of why they work. I've just learned to accept the operations and what they do.
Visualising Quaternions is a book which goes into much beautiful depth about what they represent and how they behave, if you fancy digging deeper than the everyday practicality of them.
[1]: http://www.amazon.com/Visualizing-Quaternions-Kaufmann-Inter...
[2]: http://gamedev.stackexchange.com/questions/4801/how-can-you-...
Re: Introduction to the Math of Computer Graphics
#27What I'm failing to understand is how do matrices relate to 3D graphics. What is a matrix representing? I think I get the idea of a vertex, as that can be used to represent a point on a shape, like a 3d model.
http://webglfundamentals.org/webgl/lessons/webgl-2d-matrices...
That's 2d but if you follow them forward it will go to 3d
Re: Introduction to the Math of Computer Graphics
#28What I'm failing to understand is how do matrices relate to 3D graphics. What is a matrix representing? I think I get the idea of a vertex, as that can be used to represent a point on a shape, like a 3d model.
Here's an example 3-d matrix:
[ a d g ]
[ b e h ]
[ c f i ]
(a,b,c) is the vector representing the direction of the X axis; (d,e,f), Y; (g,h,i), Z.Re: Introduction to the Math of Computer Graphics
#29Small thing, but some of the examples have some pretty bad undefined behavior bugs. For instance: Matrix& operator*( const double scalar, const Matrix& rhs) { Matrix result(rhs); result *= scalar; return result; } (Returning a reference to a stack variable is undefined behavior, but realistically you're probably either looking at a hard crash or a really hard to track down bug)
Re: Introduction to the Math of Computer Graphics
#30Small thing, but some of the examples have some pretty bad undefined behavior bugs. For instance: Matrix& operator*( const double scalar, const Matrix& rhs) { Matrix result(rhs); result *= scalar; return result; } (Returning a reference to a stack variable is undefined behavior, but realistically you're probably either looking at a hard crash or a really hard to track down bug)
I wonder why they didn't simply nuke the reference and get move semantics? Or better yet, use expression templates.
The way the code is now structured will allow for the RVO (Return-value optimization) to occur, so the new instance will be constructed in the location of the receiving object.
Move semantics would not apply in this case, it would actually suffer from a similar problem as the version that returned a reference, except the program would not crash. Instead the return value would contain garbage.
(edit: added a link to details on how to use move semantics) http://codeofthedamned.com/index.php/c-r-value-references
I did not use expression templates, or try to optimize any of the implementation because my intent is to demonstrate "how" to get started with the math. I also wanted to make the code accessible to programmers that do not use C++. For example, someone trying to learn WebGL.