我需要计算一个普通的模型矩阵,用于在GLSL着色器中进行法线贴图.我想确保我是对的:当我将视图(相机模型)矩阵与几何模型矩阵相乘时,视图矩阵应该已经被反转了吗?从这里和这里找到的在线示例中不清楚.此外,我发现在某些情况下,人们也会转换结果矩阵.为什么?那么在OpenGL中构建普通模型矩阵的正确方法是什么?
目前我是这样做的:
glm::mat4 view = inverse(GetCameraModel());
glm::mat3 normalModelMatr= glm::mat3(view * mesh.GetModel());
Run Code Online (Sandbox Code Playgroud)
这是要走的路吗?
我有一棵树是这样的:
|-父级
| |-子-子
|-父
| |-Child-Child
...
只有父母是可选择的。如何从选定的父级获取数据?
我试过
ui->treeView->selectedIndexes()[0];
Run Code Online (Sandbox Code Playgroud)
但它说 selectedIndexes() 是受保护的。
我想用glCopyBufferSubData将数据从一个缓冲区复制到另一个缓冲区.但是我不知道我要复制的缓冲区的大小.我如何获得尺寸?
编辑3:如果我删除第二个createTriangle函数,它的工作原理.那么如何绑定重载函数呢?
我有一个函数,它接受一个带有一个参数的函数对象,如下所示:
int createObject(std::function<void(int)>);
Run Code Online (Sandbox Code Playgroud)
如何用std :: bind调用这个函数?我试过这样的:
createObject(std::bind(&ClassA::createTriangle, std::placeholders::_1, a, b, c, color));
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误:
候选模板被忽略:无法推断模板参数
ClassA :: createTriangle是一个静态函数.
附加信息:
void ClassA::createTriangle(int id, const glm::vec3 & a, const glm::vec3 & b, const glm::vec3 & c, const glm::vec3 & col) {
/* ... */
}
int ClassB::createTriangle(const glm::vec3 & a, const glm::vec3 & b, const glm::vec3 & c, const glm::vec3 & color) {
return classCInstance.createObject(std::bind(&classA::createTriangle, std::placeholders::_1, a, b, c, color));
}
int ClassC::createObject(std::function<void(int)> f) {
f(++id);
return id;
}
Run Code Online (Sandbox Code Playgroud)
ClassA中还有另一个静态createTriangle函数,它具有不同的last参数.那可能是个问题吗?绑定不知道选择哪个createTriangle?它看起来像这样:
void ClassA::createTriangle(int …Run Code Online (Sandbox Code Playgroud) 我不能再建立assimp 3.2了.昨天它有效,但今天却没有.
我从这里下载assimp .然后我正在做cmake CMakeLists.txt -G 'Unix Makefiles',make正如他们的INSTALL文件中所描述的那样.但是,当make我这样做时,我收到以下错误:
[ 84%] Performing configure step for 'gtest'
CMake Error at /home/gartenriese/Documents/assimp/assimp-3.2/test/gtest/src/gtest-stamp/gtest-configure.cmake:16 (message):
Command failed: 1
'/usr/bin/cmake' '-DCMAKE_BUILD_TYPE=' '-Dgtest_force_shared_crt=ON' '-Dgtest_disable_pthreads:BOOL=OFF' '-GUnix Makefiles' '/home/gartenriese/Documents/assimp/assimp-3.2/test/gtest/src/gtest'
See also
/home/gartenriese/Documents/assimp/assimp-3.2/test/gtest/src/gtest-stamp/gtest-configure-*.log
make[2]: *** [test/gtest/src/gtest-stamp/gtest-configure] Error 1
Run Code Online (Sandbox Code Playgroud)
gtest-configure-out.log是空的,但是gtest-configure-err.log说如下:
CMake Error: The source directory "/home/gartenriese/Documents/assimp/assimp-3.2/test/gtest/src/gtest" does not appear to contain CMakeLists.txt.
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?昨天的工作,我并没有在我的系统在全球范围改变任何东西.
编辑:
我可以使用-DASSIMP_BUILD_TESTS=OFF添加到cmake命令的选项来构建它.然而,这只是一种解决方法,并没有解释这个问题.
我有一本字典,其中有一个Listas 值。我想从列表中选择属于特定键的特定元素。到目前为止我尝试过:
Dictionary<int, List<bool>> dic = new Dictionary<int, List<bool>>();
dic.Add(1, new List<bool> { true, true, false });
var works = dic.Where(x => x.Key == 1).SingleOrDefault().Value.Where(x => x == true).ToList();
var doesNotWork = dic.Where(x => x.Key == 2).SingleOrDefault().Value.Where(x => x == true).ToList();
Run Code Online (Sandbox Code Playgroud)
第一个 LINQ 之所以有效,是因为有一个键等于 1。因此我得到了List<bool>带有两个元素的 a 。第二个 LINQ 不起作用,因为 Value 是null。我如何重写该 LINQ,以便如果字典中没有合适的键,我会得到一个空的List<bool>?
我认为我的方法会起作用,因为我认为默认元素有一个空列表而不是 null 作为值。
我试图让这个答案工作,但我得到错误The property "Style" can only be set once..这是为什么?
这就是我所拥有的:
<UserControl x:Class="SFVControls.Controls.Basic.BooleanRectangleView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="20" d:DesignWidth="40">
<StackPanel Name="stackTextPanel" Orientation="Horizontal">
<StackPanel.Style>
<Setter Property="Margin" Value="0,8,0,0" />
<Style TargetType="{x:Type StackPanel}">
<Style.Triggers>
<DataTrigger Binding="{Binding QuickDrawBarPinned}" Value="False">
<Setter Property="Margin" Value="0,8,0,0" />
</DataTrigger>
<DataTrigger Binding="{Binding QuickDrawBarPinned}" Value="True">
<Setter Property="Margin" Value="0,48,0,0" />
</DataTrigger>
</Style.Triggers>
</Style>
</StackPanel.Style>
</StackPanel>
</UserControl>
Run Code Online (Sandbox Code Playgroud) 当我在我的班级中使用std :: deque作为私人成员时,我会遇到很多错误,例如
/usr/include/c++/v1/deque:907:49: error: implicit instantiation of undefined template 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >'
static const difference_type __block_size = sizeof(value_type) < 256 ? 4096 / sizeof(value_type) : 16;
/usr/include/c++/v1/deque:1181:30: error: '__alloc_traits' is a protected member of 'std::__1::__deque_base<std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >'
typedef typename __base::__alloc_traits __alloc_traits;
等等.
它在我使用矢量时有效,但我想要一个pop_front功能.
有任何想法吗?
编辑:
代码:
#include <deque>
class Example {
public:
Example() {}
~Example() {}
private:
std::deque<std::string> m_deque;
};
Run Code Online (Sandbox Code Playgroud) 我开始倾向于OpenCL,我想从主机缓冲区复制到设备缓冲区并返回另一个主机缓冲区.我正在使用OpenCL的c ++包装器.
我有的是这个:
std::string origBuf("Hello OpenCL");
cl::Buffer::Buffer deviceBuf(context, CL_MEM_READ_WRITE, origBuf.size());
queue.enqueueWriteBuffer(deviceBuf, CL_TRUE, 0, origBuf.size(), &origBuf);
std::string hostBuf("???????????????");
queue.enqueueReadBuffer(deviceBuf, CL_TRUE, 0, origBuf.size(), &hostBuf);
Run Code Online (Sandbox Code Playgroud)
但是,这给了我一个"双重免费或损坏"错误的段错误.我究竟做错了什么?
我想根据类型调用模板化函数中的不同函数,如下所示:
template<typename T>
T func() {
static_assert(std::is_same<T, int>::value || /* other allowed types */ , "Type not allowed");
T ret {};
// if T == int
funcInt(&ret);
// if T == /* other types */
/* other functions */
}
Run Code Online (Sandbox Code Playgroud)
这样的事情可能吗?
我试过这个:
std::function< int(*T)> query;
if (std::is_same<T, int>::value) {
query = funcInt;
}
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误:
错误:'T'不是指一个值