I would like to draw your attention to a new math library I created.
Further information here:
libmymath
Best regards,
Yours3!f
float &operator[](size_t const index);
float const &operator[](size_t const index) const;
//vec2 header file
namespace mymath
{
class myvec2f
{
.....
}
}
//vec2 cpp file
mymath::myvec2f::myvec2f(float x, float y)
{
...
}
namespace mymath {
myvec2f::myvec2f()
{
}
} // namespace mymath
and about templates:
I think they shouldn't be used. I read an article on cplusplus.com, which convinced me of not using them, at least in our case.
I mean do they have any advantage besides letting the programmer write less code? they don't allow separation of interface and implementation, and they make the whole code less understandable. I mean beginner programmers don't even have an idea what templates are... To add because the classes' functions' implementations are very different we wouldn't benefit from using templates.
I mean do they have any advantage besides letting the programmer write less code?[/quote]
Writing less code is good enough reason by itself. Code duplication makes code harder to write, debug, test, and maintain, and should be avoided wherever possible and practical. A math library that offers, say 2-d, 3-d, and 4-d vector classes and 2x2, 3x3, and 4x4 matrix classes will have reams of duplicate or similar code, which is undesirable by any reasonable standard. Use of templates can fix that problem.
To be fair, some might argue that having separate 2-d, 3-d, and 4-d vector classes is preferable, as the required functionality differs somewhat based on dimension. Just remember that there's no 'one size fits all' solution; what works for some may not work for others.
they don't allow separation of interface and implementation[/quote]
I think that ship has sailed, more or less :) Many if not most of the libraries commonly used with C++ (the standard library, Boost, etc.) are heavily template-based. The fact is, templates are not only part of the C++ language, they're arguably integral to it. You can certainly write C++ code without touching templates, but use of them (and the potential exposure of implementation that goes along with them) is entirely idiomatic.
and they make the whole code less understandable[/quote]
Arguably true :) Complex template code can verge on the impenetrable. But, that doesn't mean you shouldn't use templates. Plus, you can write clear code even when using templates, and how extensively you want to use them is entirely up to you. (For example, simply parameterizing the real-number type of a vector class will add very little in terms of code complexity, and will affect readability hardly at all.)
To add because the classes' functions' implementations are very different we wouldn't benefit from using templates.[/quote]
As I mentioned before, differences in functionality between related classes is certainly a consideration. But, the fact that there are libraries that do abstract away these differences shows that it can be done. Granted though, it's not necessarily trivial to do so.
To sum up, use of templates is just an option to consider; no one's saying you have to do it that way. If it's not immediately obvious to you how it would be advantageous, then I'd just stick with what you have.
so I guess a binary operator should be non-member only if lval's type is different than rval's, right?
- Some might suggest inverting and multiplying rather than dividing repeatedly (I don't know how much that matters these days though) [/quote]
where did you find this?
after correcting it I write some examples, and hopefully on Thursday I'll release libmymath v1.1.0
Best regards,
Yours3!f
void matrix_stack::mult_matrix(m4x4 m)
{
stack[stack_pointer] *= m;
}
void matrix_stack::mult_matrix(m4x4 m)
{
stack[stack_pointer] = m * stack[stack_pointer] ;
}
I'm not familiar with m3d, but whether you want A*B or B*A generally depends on whether your matrices are set up for use with row vectors or column vectors. With row vectors, A*B applies the respective transforms in the order A->B, while with column vectors it applies the transforms in the order B->A.
If the order seems to be reversed between your math library and another math library, it may be because opposite vector notation conventions are being used. (Note however that from a purely mathematical standpoint, matrix multiplication is always defined in the same way; the differences in order just have to do with how the matrices are being used.)
umm, ok so that must be because mymath uses row major order, and m3d uses column major order.
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more