我一直想用C++编写自己的多线程实时光线跟踪器,但我不想实现它附带的所有矢量和矩阵逻辑.我想我会做一些研究,为此找到一个好的图书馆,但我没有取得多大成功......
重要的是实施速度很快,最好是它带有一些友好的许可.我读过它boost有基本的代数,但我找不到任何关于它的速度有多好.
其余的,谷歌给了我Armadillo,声称速度非常快,并将自己与其他一些我没有听说过的图书馆进行比较.
然后我得到了Seldon,这也声称是高效和方便的,虽然我无法找到他们在规模上的确切位置.
最后我读了一下Eigen,在这里搜索时我也在StackOverflow上看过这个.
在我大学的CG讲座中,他们使用HLSL代数(让学生实现/优化光线跟踪器的部分),这让我思考是否可以使用GLSL它.同样,我不知道哪个选项最有效,或者对代数库的一般共识是什么.我希望SO可以帮助我,所以我可以开始一些真正的开发:)
PS:我尝试链接到网站,但我还没有足够的代表
我一直在研究我的程序,我决定使用它来开启一些优化g++ -O3.突然,我的程序开始了segfaulting.我已经找到了有问题的代码,并将我的程序最小化到仍然是段错误的东西(仅在使用3级优化时).我希望有人可以快速浏览代码(我尽可能地尽量减少它):
// src/main.cpp
#include "rt/lights/point.hpp"
int main(int argc, char **argv)
{
rt::Light *light = new rt::light::Point(alg::vector(.0f, 5.0f, 5.0f), rt::Color(1.0f), .5f);
return 0;
}
// include/rt/lights/point.hpp
#ifndef RT_LIGHT_POINT_HPP_
#define RT_LIGHT_POINT_HPP_
#include "rt/accelerator.hpp"
#include "rt/color.hpp"
#include "rt/intersection.hpp"
#include "rt/light.hpp" // abstract
namespace rt {
namespace light {
class Point : public Light
{
public:
Point(alg::vector pos, Color color, float intensity) : Light(intensity * color), pos(pos) {}
Color get_contrib(const Intersection&, const Accelerator&, const alg::vector& toViewer) const;
private:
alg::vector pos;
}; …Run Code Online (Sandbox Code Playgroud) 我正在尝试编译一些代码,在我的一个头文件中,我在全局命名空间中有以下函数:
template <class T>
inline
T
to_type<T> (const std::string& string)
{
std::stringstream ss(string);
T value;
ss >> value;
return value;
}
Run Code Online (Sandbox Code Playgroud)
但不知何故,这会引发g ++错误expected initializer before '<' token(我更改了其中一个引号以解决与SO格式的冲突)
我不明白这个错误.为什么to_type不是有效的初始值设定项?这是第一次使用此符号.如何修复此代码段?
我试图在我的矢量类中添加模板功能,之后在我的项目中使用它而没有模板.
旧版本使用硬编码float来保存值x,y和z.我现在要做的是让类也能够通过模板使用double.
我的类定义如下所示:
namespace alg {
template <class T=float> // <- note the default type specification
struct vector
{
T x, y, z;
vector() : x(0), y(0), z(0) {}
explicit vector(T f) : x(f), y(f), z(f) {}
vector(T x, T y, T z) : x(x), y(y), z(z) {}
// etc
};
}
Run Code Online (Sandbox Code Playgroud)
我希望现在能够编译我的项目而不更改其中的代码,通过告诉模板float默认情况下使用,如果没有给出模板参数.
但是,我仍然遇到有关缺少模板参数的错误...
#include "vector.hpp"
int main() {
alg::vector a;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
-
$ g++ -O3 -Wall -Wextra …Run Code Online (Sandbox Code Playgroud)