我打算制作一款游戏,我想为这款游戏制作一些背景动画.其中一个动画是旋转矩形.我看了一遍,我找不到任何形式的数学或逻辑,允许我旋转一个矩形(SDL_Rect是具体的,但你可能已经知道).
我无法弄清楚自己的数学,我真的没有任何工作代码,所以我无法显示任何东西.
基本上我正在寻找某种类型的逻辑,我可以应用矩形的坐标,这样每当主游戏循环循环时,它将旋转矩形一定程度的度数.
我正在使用C ++中的SDL2和OpenGL开发一个简单的应用程序。
问题是我的程序没有绘制三角形。
Rect.hpp(绘制三角形的类):
#ifndef Rect_hpp
#define Rect_hpp
#include <stdio.h>
#include <iostream>
#define GLEW_STATIC
#include <GL/glew.h>
#include <SDL2/SDL.h>
#include "Shaders.hpp"
using namespace std;
extern GLfloat vertices[];
class Rect
{
public:
Rect();
~Rect();
void init();
void draw();
private:
void bind();
GLuint VAO;
GLuint VBO;
GLuint vertexShader;
GLuint fragmentShader;
GLuint shaderProgram;
Shaders shaders;
};
#endif /* Rect_hpp */
Run Code Online (Sandbox Code Playgroud)
Rect.cpp:
#include "Rect.hpp"
GLfloat vertices[] = {
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f,
};
Rect::Rect()
{
VBO = NULL;
vertexShader = …
Run Code Online (Sandbox Code Playgroud)