当前位置: 首页>>代码示例>>C++>>正文


C++ Quad::update方法代码示例

本文整理汇总了C++中Quad::update方法的典型用法代码示例。如果您正苦于以下问题:C++ Quad::update方法的具体用法?C++ Quad::update怎么用?C++ Quad::update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Quad的用法示例。


在下文中一共展示了Quad::update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: updateScene

void ColoredCubeApp::updateScene(float dt)
{
	D3DApp::updateScene(dt);
	xLine.update(dt);
	yLine.update(dt);
	zLine.update(dt);
	quad1.update(dt);
	quad2.update(dt);
	quad3.update(dt);
	quad4.update(dt);
	quad5.update(dt);

	for(int i = 0; i < WALL_SIZE; ++i) {
		wall[i].update(dt);
	}

	D3DXVECTOR3 pos(0.0f,0.0f,15.0f);
	D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
	D3DXMatrixLookAtLH(&mView, &pos, &target, &up);
}
开发者ID:,项目名称:,代码行数:21,代码来源:

示例2: main

int main() {
    std::string dataRoot;
#ifdef DATA_ROOT
    dataRoot = DATA_ROOT;
#else
    std::cerr << "No DATA_ROOT path found" << std::endl;
    return -1;
#endif

    GLFWwindow *window = nullptr;

    if (initWindow(window)) {
        return -1;
    }

    Shader shader(dataRoot + "/data/shaders/shader.vert", dataRoot + "/data/shaders/shader.frag");

    Texture textures(dataRoot + "/data/assets/textures.png");
    Texture normals(dataRoot + "/data/assets/normals.png");

    std::vector<GLfloat> vertices;
    std::vector<GLuint> indices;

    std::vector<Quad> quads;

    Map map(10, 10);
    for (int x = 0; x < map.getWidth(); ++x) {
        for (int y = 0; y < map.getHeight(); ++y) {
            if (map.isPassable(x, y)) {
                quads.push_back(Quad(glm::vec3(x, 0, -y), glm::vec3(0, 0, -1), glm::vec3(1, 0, 0), 0.5f, 0.0f));
                quads.push_back(Quad(glm::vec3(x, 1, -y), glm::vec3(1, 0, 0), glm::vec3(0, 0, -1), 0.0f, 0.5f));
            }
            for (int direction = 0; direction < 4; ++direction) {
                int cx = x + dx[direction];
                int cy = y + dy[direction];
                if (map.isPassable(x, y) && !map.isPassable(cx, cy)) {
                    quads.push_back(Quad(
                            glm::vec3(x, 0, -y) + WALL_SHIFT[direction],
                            glm::vec3(0, 1, 0),
                            WALL_DIRECTION[direction],
                            0.0f,
                            0.0f
                    ));
                }
            }
        }
    }

    for (int index = 0; index < quads.size(); ++index) {
        Quad quad = quads[index];
        quad.update(vertices);

        indices.push_back(GLuint(4 * index + 0));
        indices.push_back(GLuint(4 * index + 1));
        indices.push_back(GLuint(4 * index + 2));

        indices.push_back(GLuint(4 * index + 2));
        indices.push_back(GLuint(4 * index + 3));
        indices.push_back(GLuint(4 * index + 0));
    }

    GLuint VBO, VAO, EBO;
    createBuffers(VBO, VAO, EBO, vertices, indices);

    glm::mat4 projection = glm::perspective(45.0f, WIDTH / (float) HEIGHT, 0.1f, 100.0f);
    glm::vec3 lamp(map.getWidth() / 2, 0.9f, -map.getHeight() / 2);

    float time = (float) glfwGetTime();

    while (!glfwWindowShouldClose(window)) {
        glfwPollEvents();

        float cTime = (float) glfwGetTime();
        float delta = cTime - time;
        time = cTime;

        update(map, delta);

        glClearColor(117 / 255.0f, 187 / 255.0f, 253 / 255.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        shader.use();

        GLint textureLocation = glGetUniformLocation(shader.get(), "textureSampler");
        glUniform1i(textureLocation, 0);

        GLint normalLocation = glGetUniformLocation(shader.get(), "normalSampler");
        glUniform1i(normalLocation, 1);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, textures.get());

        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, normals.get());

        GLfloat timeValue = (GLfloat) glfwGetTime();

        GLfloat xValue = (GLfloat) (sin(timeValue) / 4) + 0.25f;
        GLint xValueLocation = glGetUniformLocation(shader.get(), "xValue");
        glUniform1f(xValueLocation, xValue);
//.........这里部分代码省略.........
开发者ID:MekaGem,项目名称:opengl-course-mipt,代码行数:101,代码来源:main.cpp


注:本文中的Quad::update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。