【发布时间】:2014-09-01 09:48:00
【问题描述】:
我主要关心 glm 库。 我想翻译一个向量+矩阵,使用 glm::translate,但它会抛出错误:
我有以下代码:
#define GLEW_STATIC
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <GL\glew.h>
#include <GL\GLU.h>
#include <GL\glut.h>
#include <glm.hpp>
#include <GL\gl.h>
#include <gtx\transform2.hpp>
#include <GLFW\glfw3.h>
using namespace std;
using namespace glm;
int main()
{
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
return -1;
}
// defining the matrices
glm::mat4 myMatrix = glm::translate(10f,0.0f,0.0f);
glm::vec4 myVector(10.0f, 10.0f, 10.0f, 0.0f);
glm::vec4 transformedVector = myMatrix * myVectors; // multiplication
return 0;
}
当我执行代码时,出现以下错误:
error C2059: syntax error : 'bad suffix on number'
error C2146: syntax error : missing ')' before identifier 'f'
error C2784: 'glm::detail::tmat4x4<T,P> glm::translate(const glm::detail::
tvec3<T,P> &)' : could not deduce template argument for 'const glm::detail::tvec3<T,P> &' from 'int'
还有很多错误。
使用@lazyCoder 的解决方案,我消除了许多错误。不过,我收到一个关于 glm::translate() 的错误,这是关于参数的:
error C2780: 'glm::detail::tmat4x4<T,P> glm::translate(const glm::detail::tvec3<T,P> &)
' : expects 1 arguments - 3 provided
1> c:\opengl\glm-0.9.5.4\glm\glm\gtx\transform.hpp(61) : see declaration of
'glm::translate'
error C2780: 'glm::detail::tmat4x4<T,P> glm::translate(const glm::detail::tmat4x4<T,P>
&,const glm::detail::tvec3<T,P> &)' : expects 2 arguments - 3 provided
1> c:\opengl\glm-0.9.5.4\glm\glm\gtc\matrix_transform.hpp(86) : see declaration of 'glm::translate'
【问题讨论】:
-
1.在
#include指令中使用正斜杠而不是反斜杠 - 您实际上使用了一次转义序列\t。 2. 这些错误来自编译代码,而不是执行它。请指出它们也出现在哪一行。 -
和声音一样疯狂尝试
10.0f作为翻译的第一个参数。根据编译错误,似乎 MS 编译器无法将10f识别为正确的float并将其解释为int -
@lazycoder 这甚至不疯狂,它是正确的 C++。 floating-literal 需要 fractional-constant 或 exponent-part - 所以它必须包含
.或e/E。你应该把你的评论变成一个答案。请注意,最后一个0是可选的 - 它可以是10.f。 -
@lazycode,您的解决方案消除了 80% 的错误。现在我收到
expects 1 arguments - 4 provided行的错误,它与glm::translate()行有关 -
@MostafaTalebi 你能用新的错误更新问题吗