clangd changes, rename funcs, modernize vertex attrib binding
This commit is contained in:
parent
2a7c7b75b3
commit
808ddee045
@ -1,6 +1,7 @@
|
||||
BasedOnStyle: Chromium
|
||||
IndentWidth: 4
|
||||
SortIncludes: false
|
||||
AlignTrailingComments: true
|
||||
|
||||
Language: Cpp
|
||||
# Force pointers to the type for C++.
|
||||
|
34
.clangd
34
.clangd
@ -1,19 +1,23 @@
|
||||
Diagnostics:
|
||||
ClangTidy:
|
||||
Add: [
|
||||
modernize*,
|
||||
bugprone*,
|
||||
performance*,
|
||||
readability*
|
||||
]
|
||||
Remove: [
|
||||
modernize-use-trailing-return-type,
|
||||
modernize-avoid-c-arrays,
|
||||
readability-magic-numbers,
|
||||
readability-implicit-bool-conversion,
|
||||
readability-identifier-length,
|
||||
bugprone-easily-swappable-parameters
|
||||
]
|
||||
Add: [modernize*, bugprone*, performance*, readability*]
|
||||
Remove:
|
||||
[
|
||||
modernize-use-trailing-return-type,
|
||||
modernize-avoid-c-arrays,
|
||||
readability-magic-numbers,
|
||||
readability-implicit-bool-conversion,
|
||||
readability-identifier-length,
|
||||
bugprone-easily-swappable-parameters,
|
||||
]
|
||||
|
||||
InlayHints:
|
||||
Enabled: Yes
|
||||
ParameterNames: Yes
|
||||
DeducedTypes: Yes
|
||||
|
||||
Hover:
|
||||
ShowAKA: No
|
||||
|
||||
Completion:
|
||||
AllScopes: Yes
|
||||
AllScopes: Yes
|
||||
|
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -1,5 +1,6 @@
|
||||
{
|
||||
"C_Cpp.intelliSenseEngine": "disabled",
|
||||
"editor.inlayHints.enabled": "on",
|
||||
"cmake.statusbar.advanced": {
|
||||
"debug": {
|
||||
"visibility": "hidden"
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <game/game.h>
|
||||
#include <graphics/graphics.h>
|
||||
#include <window/window.h>
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
@ -95,7 +96,7 @@ void Graphics::storeVertexBufObj(GLuint& dest, GLsizeiptr size, int* target) {
|
||||
glBufferData(GL_ARRAY_BUFFER, size, target, GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
void Graphics::multiply4x4Matrices(GLfloat* m, const GLfloat* n) {
|
||||
void Graphics::mulMat4x4(GLfloat* m, const GLfloat* n) {
|
||||
GLfloat tmp[16];
|
||||
const GLfloat* row;
|
||||
const GLfloat* column;
|
||||
@ -104,20 +105,20 @@ void Graphics::multiply4x4Matrices(GLfloat* m, const GLfloat* n) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
tmp[i] = 0;
|
||||
d = div(i, 4);
|
||||
row = n + d.quot * 4;
|
||||
row = n + (ptrdiff_t)(d.quot * 4);
|
||||
column = m + d.rem;
|
||||
for (int j = 0; j < 4; j++) {
|
||||
tmp[i] += row[j] * column[j * 4];
|
||||
tmp[i] += row[j] * column[(ptrdiff_t)(j * 4)];
|
||||
}
|
||||
}
|
||||
memcpy(m, &tmp, sizeof tmp);
|
||||
}
|
||||
|
||||
void Graphics::rotate4x4Matrix(GLfloat* m,
|
||||
GLfloat angle,
|
||||
GLfloat x,
|
||||
GLfloat y,
|
||||
GLfloat z) {
|
||||
void Graphics::rotMat4x4(GLfloat* m,
|
||||
GLfloat angle,
|
||||
GLfloat x,
|
||||
GLfloat y,
|
||||
GLfloat z) {
|
||||
double sin;
|
||||
double cos;
|
||||
|
||||
@ -139,16 +140,16 @@ void Graphics::rotate4x4Matrix(GLfloat* m,
|
||||
0,
|
||||
1};
|
||||
|
||||
multiply4x4Matrices(m, r);
|
||||
mulMat4x4(m, r);
|
||||
}
|
||||
|
||||
void Graphics::translate4x4Matrix(GLfloat* m, GLfloat x, GLfloat y, GLfloat z) {
|
||||
void Graphics::tlateMat4x4(GLfloat* m, GLfloat x, GLfloat y, GLfloat z) {
|
||||
GLfloat t[16] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1};
|
||||
|
||||
multiply4x4Matrices(m, t);
|
||||
mulMat4x4(m, t);
|
||||
}
|
||||
|
||||
void Graphics::create4x4IdentityMatrix(GLfloat* m) {
|
||||
void Graphics::identMat4x4(GLfloat* m) {
|
||||
GLfloat t[16] = {
|
||||
1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
|
||||
@ -157,16 +158,16 @@ void Graphics::create4x4IdentityMatrix(GLfloat* m) {
|
||||
memcpy(m, t, sizeof(t));
|
||||
}
|
||||
|
||||
void Graphics::transpose4x4Matrix(GLfloat* m) {
|
||||
void Graphics::tposeMat4x4(GLfloat* m) {
|
||||
GLfloat t[16] = {m[0], m[4], m[8], m[12], m[1], m[5], m[9], m[13],
|
||||
m[2], m[6], m[10], m[14], m[3], m[7], m[11], m[15]};
|
||||
|
||||
memcpy(m, t, sizeof(t));
|
||||
}
|
||||
|
||||
void Graphics::invert4x4Matrix(GLfloat* m) {
|
||||
void Graphics::invMat4x4(GLfloat* m) {
|
||||
GLfloat t[16];
|
||||
create4x4IdentityMatrix(t);
|
||||
identMat4x4(t);
|
||||
|
||||
// Extract and invert the translation part 't'. The inverse of a
|
||||
// translation matrix can be calculated by negating the translation
|
||||
@ -178,19 +179,19 @@ void Graphics::invert4x4Matrix(GLfloat* m) {
|
||||
// Invert the rotation part 'r'. The inverse of a rotation matrix is
|
||||
// equal to its transpose.
|
||||
m[12] = m[13] = m[14] = 0;
|
||||
transpose4x4Matrix(m);
|
||||
tposeMat4x4(m);
|
||||
|
||||
// inv(m) = inv(r) * inv(t)
|
||||
multiply4x4Matrices(m, t);
|
||||
mulMat4x4(m, t);
|
||||
}
|
||||
|
||||
void Graphics::calcPerspectiveProjectTransformation(GLfloat* m,
|
||||
GLfloat yFOV,
|
||||
GLfloat aspect,
|
||||
GLfloat zNear,
|
||||
GLfloat zFar) {
|
||||
void Graphics::calcPersProjTform(GLfloat* m,
|
||||
GLfloat yFOV,
|
||||
GLfloat aspect,
|
||||
GLfloat zNear,
|
||||
GLfloat zFar) {
|
||||
GLfloat tmp[16];
|
||||
create4x4IdentityMatrix(tmp);
|
||||
identMat4x4(tmp);
|
||||
|
||||
double sine;
|
||||
double cosine;
|
||||
|
@ -44,7 +44,7 @@ class Graphics {
|
||||
* @param m first matrix
|
||||
* @param n second matrix
|
||||
*/
|
||||
static void multiply4x4Matrices(GLfloat*, const GLfloat*);
|
||||
static void mulMat4x4(GLfloat*, const GLfloat*);
|
||||
|
||||
/**
|
||||
* Rotates a 4x4 matrix
|
||||
@ -55,7 +55,7 @@ class Graphics {
|
||||
* @param y the y component of the direction to rotate to
|
||||
* @param z the z component of the direction to rotate to
|
||||
*/
|
||||
static void rotate4x4Matrix(GLfloat*, GLfloat, GLfloat, GLfloat, GLfloat);
|
||||
static void rotMat4x4(GLfloat*, GLfloat, GLfloat, GLfloat, GLfloat);
|
||||
|
||||
/**
|
||||
* Translates a 4x4 matrix
|
||||
@ -65,28 +65,28 @@ class Graphics {
|
||||
* @param y the y component of the direction to translate to
|
||||
* @param z the z component of the direction to translate to
|
||||
*/
|
||||
static void translate4x4Matrix(GLfloat*, GLfloat, GLfloat, GLfloat);
|
||||
static void tlateMat4x4(GLfloat*, GLfloat, GLfloat, GLfloat);
|
||||
|
||||
/**
|
||||
* Creates a 4x4 identity matrix
|
||||
*
|
||||
* @param m the matrix to convert to an identity matrix
|
||||
*/
|
||||
static void create4x4IdentityMatrix(GLfloat*);
|
||||
static void identMat4x4(GLfloat*);
|
||||
|
||||
/**
|
||||
* Transposes a 4x4 matrix.
|
||||
*
|
||||
* @param m the matrix to transpose
|
||||
*/
|
||||
static void transpose4x4Matrix(GLfloat*);
|
||||
static void tposeMat4x4(GLfloat*);
|
||||
|
||||
/**
|
||||
* Inverts a 4x4 matrix.
|
||||
*
|
||||
* @param m the matrix to invert
|
||||
*/
|
||||
static void invert4x4Matrix(GLfloat*);
|
||||
static void invMat4x4(GLfloat*);
|
||||
|
||||
/**
|
||||
* Calculate a perspective projection transformation.
|
||||
@ -97,11 +97,7 @@ class Graphics {
|
||||
* @param zNear the near clipping plane
|
||||
* @param zFar the far clipping plane
|
||||
*/
|
||||
static void calcPerspectiveProjectTransformation(GLfloat*,
|
||||
GLfloat,
|
||||
GLfloat,
|
||||
GLfloat,
|
||||
GLfloat);
|
||||
static void calcPersProjTform(GLfloat*, GLfloat, GLfloat, GLfloat, GLfloat);
|
||||
};
|
||||
|
||||
#endif
|
@ -263,14 +263,14 @@ void GearsScene::drawGear(Gear* gear,
|
||||
|
||||
// Translate and rotate the gear
|
||||
memcpy(modelView, transform, sizeof(modelView));
|
||||
Graphics::translate4x4Matrix(modelView, x, y, 0);
|
||||
Graphics::rotate4x4Matrix(modelView, 2.0F * (float)M_PI * angle / 360.0F, 0,
|
||||
0, 1);
|
||||
Graphics::tlateMat4x4(modelView, x, y, 0);
|
||||
Graphics::rotMat4x4(modelView, 2.0F * (float)M_PI * angle / 360.0F, 0, 0,
|
||||
1);
|
||||
|
||||
/* Create and set the ModelViewProjectionMatrix */
|
||||
memcpy(modelViewProjection, this->projectionMatrix,
|
||||
sizeof(modelViewProjection));
|
||||
Graphics::multiply4x4Matrices(modelViewProjection, modelView);
|
||||
Graphics::mulMat4x4(modelViewProjection, modelView);
|
||||
Graphics::setUniformMatrixValue((GLint)this->modelViewProjectionMatrixLoc,
|
||||
modelViewProjection);
|
||||
|
||||
@ -279,8 +279,8 @@ void GearsScene::drawGear(Gear* gear,
|
||||
* ModelView matrix.
|
||||
*/
|
||||
memcpy(normalMatrix, modelView, sizeof(normalMatrix));
|
||||
Graphics::invert4x4Matrix(normalMatrix);
|
||||
Graphics::transpose4x4Matrix(normalMatrix);
|
||||
Graphics::invMat4x4(normalMatrix);
|
||||
Graphics::tposeMat4x4(normalMatrix);
|
||||
Graphics::setUniformMatrixValue((GLint)this->normalMatrixLoc, normalMatrix);
|
||||
|
||||
/* Set the gear color */
|
||||
@ -290,14 +290,17 @@ void GearsScene::drawGear(Gear* gear,
|
||||
glBindBuffer(GL_ARRAY_BUFFER, gear->vertexBufObj);
|
||||
|
||||
/* Set up the position of the attributes in the vertex buffer object */
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
|
||||
nullptr);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
|
||||
(GLfloat*)(sizeof(GLfloat) * 3));
|
||||
int bindingIdx = 0;
|
||||
|
||||
/* Enable the attributes */
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribFormat(0, 3, GL_FLOAT, GL_FALSE, 0);
|
||||
glVertexAttribBinding(0, bindingIdx);
|
||||
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribFormat(1, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 3);
|
||||
glVertexAttribBinding(1, bindingIdx);
|
||||
|
||||
glBindVertexBuffer(bindingIdx, gear->vertexBufObj, 0, sizeof(GLfloat) * 6);
|
||||
|
||||
/* Draw the triangle strips that comprise the gear */
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, gear->nVertices);
|
||||
@ -313,9 +316,9 @@ void GearsScene::reshape() {
|
||||
this->width = this->pGame->pWindow->getWidth();
|
||||
this->height = this->pGame->pWindow->getHeight();
|
||||
|
||||
Graphics::calcPerspectiveProjectTransformation(
|
||||
this->projectionMatrix, 60.0,
|
||||
(float)this->width / (float)this->height, 1.0, 1024.0);
|
||||
Graphics::calcPersProjTform(this->projectionMatrix, 60.0,
|
||||
(float)this->width / (float)this->height,
|
||||
1.0, 1024.0);
|
||||
glViewport(0, 0, (GLint)this->width, (GLint)this->height);
|
||||
}
|
||||
}
|
||||
@ -334,7 +337,7 @@ void GearsScene::idle() {
|
||||
tRot0 = t;
|
||||
|
||||
/* advance rotation for next frame */
|
||||
this->currentAngle += 70.0 * dt; /* 70 degrees per second */
|
||||
this->currentAngle += 70.0F * (GLfloat)dt; /* 70 degrees per second */
|
||||
if (this->currentAngle > 3600.0) {
|
||||
this->currentAngle -= 3600.0;
|
||||
}
|
||||
@ -346,8 +349,8 @@ void GearsScene::idle() {
|
||||
tRate0 = t;
|
||||
}
|
||||
if (t - tRate0 >= 5.0) {
|
||||
GLfloat seconds = t - tRate0;
|
||||
GLfloat fps = frames / seconds;
|
||||
auto seconds = (GLfloat)(t - tRate0);
|
||||
GLfloat fps = (GLfloat)frames / seconds;
|
||||
printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
|
||||
fps);
|
||||
tRate0 = t;
|
||||
@ -360,19 +363,19 @@ void GearsScene::draw() {
|
||||
const static GLfloat green[4] = {0.0, 0.8, 0.2, 1.0};
|
||||
const static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0};
|
||||
GLfloat transform[16];
|
||||
Graphics::create4x4IdentityMatrix(transform);
|
||||
Graphics::identMat4x4(transform);
|
||||
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
/* Translate and rotate the view */
|
||||
Graphics::translate4x4Matrix(transform, 0, 0, -20);
|
||||
Graphics::rotate4x4Matrix(
|
||||
transform, 2.0F * (float)M_PI * viewRotation[0] / 360.0F, 1, 0, 0);
|
||||
Graphics::rotate4x4Matrix(
|
||||
transform, 2.0F * (float)M_PI * viewRotation[1] / 360.0F, 0, 1, 0);
|
||||
Graphics::rotate4x4Matrix(
|
||||
transform, 2.0F * (float)M_PI * viewRotation[2] / 360.0F, 0, 0, 1);
|
||||
Graphics::tlateMat4x4(transform, 0, 0, -20);
|
||||
Graphics::rotMat4x4(transform,
|
||||
2.0F * (float)M_PI * viewRotation[0] / 360.0F, 1, 0, 0);
|
||||
Graphics::rotMat4x4(transform,
|
||||
2.0F * (float)M_PI * viewRotation[1] / 360.0F, 0, 1, 0);
|
||||
Graphics::rotMat4x4(transform,
|
||||
2.0F * (float)M_PI * viewRotation[2] / 360.0F, 0, 0, 1);
|
||||
|
||||
/* Draw the gears */
|
||||
drawGear(gears[0], transform, -3.0, -2.0, currentAngle, red);
|
||||
|
@ -96,7 +96,6 @@ class GearsScene : public Scene {
|
||||
/**
|
||||
* Draws a gear
|
||||
*
|
||||
* @param gear the gear to draw
|
||||
* @param transform the current transformation matrix
|
||||
* @param x the x pos to draw the gear at
|
||||
* @param y the y pos to draw the gear at
|
||||
|
Reference in New Issue
Block a user