首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >glm::rotate()调用无法编译?

glm::rotate()调用无法编译?
EN

Stack Overflow用户
提问于 2012-08-23 13:14:51
回答 3查看 15.2K关注 0票数 4

我无法调用glm::rotate(mat4,int,vec3(x,y,z));来工作。VS 2010告诉我

代码语言:javascript
复制
Intellisense: no instance of function template "glm::gtc::matrix_transform::rotate" matches the argument

我正在使用glm-0.9.1

我见过这个堆栈溢出问题,但解决方案仍然会触发智能感知错误:glm rotate usage in Opengl

我真的不能让它接受任何重载方法。不过,我可能只是遗漏了一些明显的东西。

我试着让rotate调用在代码中变得明显,它有点向下。

下面是一些代码:

代码语言:javascript
复制
#include <GL/glew.h>
#include <GL/glfw.h>
#include <GL/glut.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>

#include "loadShader.h"

#include <stdio.h>
#include <stdlib.h>

glm::mat4 Projection;
glm::mat4 View;
glm::mat4 Model;
glm::mat4 MVP;

glm::mat4 t;
glm::mat4 s;
glm::mat4 r;


GLuint programID;


int main()
{

    // Initialise GLFW
    if( !glfwInit() )
    {
        fprintf( stderr, "Failed to initialize GLFW\n" );
        return -1;
    }

    glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    // Open a window and create its OpenGL context
    if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) )
    {
        fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
        glfwTerminate();
        return -1;
    }

    // Initialize GLEW
    if (glewInit() != GLEW_OK) {
        fprintf(stderr, "Failed to initialize GLEW\n");
        return -1;
    }

    glfwSetWindowTitle( "Tutorial 02" );

    // Ensure we can capture the escape key being pressed below
    glfwEnable( GLFW_STICKY_KEYS );

    glewExperimental = GL_TRUE;
    glewInit();




    // Dark blue background
    glClearColor(0.0f, 0.0f, 0.3f, 0.0f);

    GLuint VertexArrayID;

    glGenVertexArrays(1, &VertexArrayID);

    glBindVertexArray(VertexArrayID);



    // Create and compile our GLSL program from the shaders
    programID = LoadShaders( "vertexShader.glsl", "fragmentShader.glsl" );


        //Pojectio matrix : 45 degree Field of view, 4:3 ratio, display range : 0.1 unit <-> 100 units
    Projection = glm::perspective( 45.0f, 4.0f / 3.0f, 0.1f, 100.0f );
    // Camera matrix
    View = glm::lookAt(
        glm::vec3(4,3,3), // Camera is at (4,3,3), in World Space
        glm::vec3(0,0,0), // and looks at the origin
        glm::vec3(0,1,0) // Head is up (set to 0, -1,0 to look upside down)
        );
    // Model matrix : an identity matrix (model will be at the origin)




    Model = glm::mat4(1.0f); // Changes for each Model !

    //INTELLISENSE ERROR ==================================================================>>>>
    r = glm::rotate(Model, 45, glm::vec3(1,0,0));

    // Our ModelViewProjection : multiplication of our 3 matrices
    MVP = Projection * View * Model; // Remember matrix multiplication is the other way around


        // Get a handle for our "MVP" uniform.
    // Only at initialisation time.
    GLuint MatrixID = glGetUniformLocation(programID, "MVP");

    // Send our transformation to the currently bound shader,
    // in the "MVP" uniform
    // For each model you fender, since the MVP will be different (at least the M part)


    static const GLfloat g_vertex_buffer_data[] = { 
        -1.0f, -1.0f, 0.0f,
         1.0f, -1.0f, 0.0f,
         0.0f,  1.0f, 0.0f,
    };

    GLuint vertexbuffer;
    glGenBuffers(1, &vertexbuffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);





    do{

        // Clear the screen
        glClear( GL_COLOR_BUFFER_BIT );

        // Use our shader
        glUseProgram(programID);

        glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);

        // 1rst attribute buffer : vertices
        glEnableVertexAttribArray(0);
        glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
        glVertexAttribPointer(
            0,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
            3,                  // size
            GL_FLOAT,           // type
            GL_FALSE,           // normalized?
            0,                  // stride
            (void*)0            // array buffer offset
        );

        // Draw the triangle !
        glDrawArrays(GL_TRIANGLES, 0, 3); // From index 0 to 3 -> 1 triangle

        glDisableVertexAttribArray(0);

        // Swap buffers
        glfwSwapBuffers();

    } // Check if the ESC key was pressed or the window was closed
    while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
           glfwGetWindowParam( GLFW_OPENED ) );

    // Close OpenGL window and terminate GLFW
    glfwTerminate();

    // Cleanup VBO
    glDeleteBuffers(1, &vertexbuffer);
    glDeleteVertexArrays(1, &VertexArrayID);

    return 0;
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-08-23 13:30:27

我对模板的了解还不够多,无法给你一个很好的答案,但我相信根据我对GLM的记忆,它对类型非常挑剔。

您可以尝试显式地将45更改为45.f,看看它是否接受吗?我认为你需要一致的参数(浮点矩阵,浮点数,浮点数向量)。我认为int在某种程度上混淆了它。

票数 24
EN

Stack Overflow用户

发布于 2013-04-25 16:32:29

代码语言:javascript
复制
glm::rotate(Model, (glm::mediump_float)45, glm::vec3(1,0,0));

我发现这个类型转换很有帮助,因为glm::vec3中使用的类型是模板。

此函数的定义如下:

代码语言:javascript
复制
glm::detail::tmat4x4<glm::lowp_float> glm::rotate<glm::lowp_float> ( const glm::detail::tmat4x4<glm::lowp_float> &m, const glm::lowp_float &angle, const glm::detail::tvec3<glm::mediump_float> &axis)

因此,您必须在角度值中使用适当的类型。

票数 2
EN

Stack Overflow用户

发布于 2021-03-05 12:15:32

我认为问题实际上出在"glm.h“文件上。老实说,我不太了解技术知识来解释为什么,但当我试图修复这个错误时,它起作用了。所以我只想把我的经验分享给有需要的人。

正如您所知道的,我们定义的库文件应该(或需要)放在双引号(“")而不是尖括号(< >)中。

因此,当我右键单击#include"glm.h“(转到文档"glm.h")查看发生了什么时,它将我引导到该文件。在它里面,我可以看到另外3行:

代码语言:javascript
复制
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

然后我把<>改成了“”,就像我之前说的:

代码语言:javascript
复制
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/type_ptr.hpp"

我的glm::rotate()函数现在可以工作了!

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12085109

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档