Added comments + includes are now always in the header file (dunno if good but looks good so yeah)

This commit is contained in:
JonasJan2 2024-06-24 22:10:45 +02:00
parent a9d658502a
commit cd3fb4409b
13 changed files with 51 additions and 61 deletions

View File

@ -1,5 +1,8 @@
#include "inputHandler.h"
/**
* Moves the camera in a somewhat smooth motion.
*/
void handleCameraTravel()
{
if (cameraTraveling)
@ -16,6 +19,9 @@ void handleCameraTravel()
}
}
/**
* Sets the position of the camera while moving.
*/
void travelCamera(vec3 newPosition)
{
cameraTravelPosition = newPosition;
@ -54,10 +60,6 @@ void handleInputs(double deltaTime)
{
travelCamera((vec3){3.574698f, 0.966039f, 3.852249f});
}
if (glfwGetKey(window, GLFW_KEY_7) == GLFW_PRESS)
{
travelCamera((vec3){0.324839f, 1.325346f, 3.798471f});
}
if (!cameraTraveling)
{
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
@ -178,7 +180,9 @@ void handleInputs(double deltaTime)
}
}
// input handler to quit with ESC
/**
* Function for if you wanna escape the program.
*/
void keyboardHandler(GLFWwindow *window, int key, int scancode, int action, int mods)
{
assert(window != NULL);

View File

@ -1,10 +1,4 @@
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <GL/glew.h>
#include <string.h>
#include <assert.h>
#include "matrixMath.h"
// MATRICES IN COLUMN MAJOR
@ -90,10 +84,9 @@ void vec3Normalise(vec3* out, vec3* a) {
}
/*
mat4 functions
mat4 functions (tested)
*/
//tested
// CREATE 4x4 IDENTITY MATRIX
void identity(mat4* out) {
assert(out != NULL);
@ -103,7 +96,6 @@ void identity(mat4* out) {
}
}
//tested
// CREATE 4x4 TRANSLATION MATRIX
void translation(mat4* out, vec3* v) {
assert(out != NULL);
@ -114,7 +106,6 @@ void translation(mat4* out, vec3* v) {
out->m23 = v->z;
}
//tested
// CREATE 4x4 SCALING MATRIX
void scaling(mat4* out, vec3* v) {
assert(out != NULL);
@ -186,7 +177,6 @@ void multiplyAny(GLfloat* out, GLfloat* A, GLfloat* B, int wA, int hA, int wB) {
result = NULL;
}
//tested
// MULTIPLY TWO 4x4 MATRICES
void multiply(mat4* out, mat4* A, mat4* B) {
assert(out != NULL);
@ -196,7 +186,6 @@ void multiply(mat4* out, mat4* A, mat4* B) {
multiplyAny((GLfloat*)out, (GLfloat*)A, (GLfloat*)B, 4, 4, 4);
}
//!
// MULTIPLY in WITH TRANSLATION MATRIX OF v
void translate(mat4* out, mat4* in, vec3* v) {
assert(out != NULL);
@ -208,7 +197,6 @@ void translate(mat4* out, mat4* in, vec3* v) {
multiply(out, &translationMatrix, in);
}
//!
// MULTIPLY in WITH SCALING MATRIX OF v
void scale(mat4* out, mat4* in, vec3* v) {
assert(out != NULL);
@ -220,7 +208,6 @@ void scale(mat4* out, mat4* in, vec3* v) {
multiply(out, &scalingMatrix, in);
}
//!
// MULTIPLY in WITH ROTATION MATRIX OF angle AROUND Z AXIS
void rotateZ(mat4* out, mat4* in, GLfloat angle) {
assert(out != NULL);
@ -231,7 +218,6 @@ void rotateZ(mat4* out, mat4* in, GLfloat angle) {
multiply(out, &rotationMatrix, in);
}
//!
// MULTIPLY in WITH ROTATION MATRIX OF angle AROUND Y AXIS
void rotateY(mat4* out, mat4* in, GLfloat angle) {
assert(out != NULL);
@ -242,7 +228,6 @@ void rotateY(mat4* out, mat4* in, GLfloat angle) {
multiply(out, &rotationMatrix, in);
}
//!
// MULTIPLY in WITH ROTATION MATRIX OF angle AROUND X AXIS
void rotateX(mat4* out, mat4* in, GLfloat angle) {
assert(out != NULL);
@ -253,7 +238,6 @@ void rotateX(mat4* out, mat4* in, GLfloat angle) {
multiply(out, &rotationMatrix, in);
}
//tested
// TRANSPOSE MATRIX OF ANY SIZE
void transposeAny(GLfloat* out, GLfloat* in, int w, int h) {
assert(out != NULL);
@ -271,7 +255,6 @@ void transposeAny(GLfloat* out, GLfloat* in, int w, int h) {
result = NULL;
}
//tested, da transpose any schon getestet ist
// TRANSPOSE 4x4 MATRIX
void transpose(mat4* out, mat4* in) {
assert(out != NULL);
@ -315,7 +298,7 @@ void mat3Print(mat3* m) {
}
/*
mat3 functions
mat3 functions (tested)
*/
// TURN mat4 INTO mat3 BY CUTTING LAST COLUMN AND ROW
@ -328,7 +311,6 @@ void mat3From4(mat3* out, mat4* in) {
memcpy(&out->m02, &in->m02, sizeof(vec3));
}
//tested
// TRANSPOSE 3x3 MATRIX
void mat3Transpose(mat3* out, mat3* in) {
assert(out != NULL);
@ -337,7 +319,6 @@ void mat3Transpose(mat3* out, mat3* in) {
transposeAny((GLfloat*)out, (GLfloat*)in, 3, 3);
}
//tested
/**
* a - m00 b - m01 c - m02
* d - m10 e - m11 f - m12
@ -365,7 +346,6 @@ void mat3Minor(mat3* out, mat3* in) {
memcpy(out, &result, sizeof(mat3));
}
//tested
// GET THE COFACTOR MATRIX OF A 3x3 MATRIX
void mat3Cofactor(mat3* out, mat3* in) {
assert(out != NULL);
@ -380,7 +360,6 @@ void mat3Cofactor(mat3* out, mat3* in) {
out->m12 *= -1;
}
//tested
// GET ADJOING MATRRIX OF 3x3 MATRIX
void mat3Adjoint(mat3* out, mat3* in) {
assert(out != NULL);
@ -400,7 +379,6 @@ void mat3MultiplyScalar(mat3* out, mat3* in, GLfloat x) {
}
}
//tested
// CALCULATE DETERMINANT OF 3x3 MATRIX
GLfloat mat3Determinant(mat3* M) {
assert(M != NULL);
@ -416,7 +394,6 @@ GLfloat mat3Determinant(mat3* M) {
;
}
//tested
// GET INVERSE OF 3x3 MATRIX
void mat3Inverse(mat3* out, mat3* in) {
assert(out != NULL);
@ -429,7 +406,6 @@ void mat3Inverse(mat3* out, mat3* in) {
memcpy(out, &result, sizeof(mat3));
}
//tested
// GET THE SUM OF DIFFERENCES BETWEEN TWO MATRICES
GLfloat sumDiffAny(GLfloat* A, GLfloat* B, int w, int h) {
assert(A != NULL);
@ -442,7 +418,6 @@ GLfloat sumDiffAny(GLfloat* A, GLfloat* B, int w, int h) {
return result;
}
//tested
// GET THE SUM OF DIFFERENCES BETWEEN TWO 3x3 MATRICES
GLfloat mat3SumDiff(mat3* A, mat3* B) {
assert(A != NULL);

View File

@ -2,6 +2,12 @@
#define MATRIX_MATH
#include <GL/glew.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
typedef struct {
GLfloat x;

View File

@ -1,9 +1,4 @@
#include "objectHandler.h"
#include "wavefrontobj.h"
#include <GL/glew.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
/**
* Loads an object.
@ -75,6 +70,7 @@ void load_object(ObjectData* objectData) {
/**
* Takes a string-pointer, a number of files to read and a number to store the added objects to
* Returns an array of objects.
* The increasing count would be used in the main.c.
*/
ObjectData* readObjFiles(char** path, int numModels, int* count) {
assert(path != NULL);

View File

@ -2,6 +2,11 @@
#define OBJECTHANDLER_H
#include "wavefrontobj.h"
#include "wavefrontobj.h"
#include <GL/glew.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
typedef struct {
GLuint vao;

View File

@ -1,12 +1,6 @@
// sceneGraph.c
#include "sceneGraph.h"
#include "objectHandler.h"
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <GL/glew.h>
#include <stdbool.h>
#define STB_IMAGE_IMPLEMENTATION
#include "../lib/stb_image.h"

View File

@ -7,7 +7,11 @@
#include "matrixMath.h"
#include "wavefrontobj.h"
#include "objectHandler.h"
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <GL/glew.h>
#include <stdbool.h>
typedef struct SceneNode SceneNode;

View File

@ -1,9 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include "shader.h"
#include <assert.h>
/**
* Compiles shader from shaderSource.
* The shader given just needs a shader type to be set beforehand, the rest gets set here.
*/
void compileShader(const GLchar *shaderSource, Shader *shader) {
assert(shaderSource != NULL);
assert(shader != NULL);
@ -26,6 +26,9 @@ void compileShader(const GLchar *shaderSource, Shader *shader) {
}
}
/**
* Compiles multiple shaders. Basically compileShader() for multiple shaders in one go.
*/
void compileShaders(Shader* shaders, const GLchar** glslSources, int numShaders) {
assert(glslSources != NULL);
assert(shaders != NULL);
@ -34,6 +37,9 @@ void compileShaders(Shader* shaders, const GLchar** glslSources, int numShaders)
}
}
/**
* Creates a shaderProgram object.
*/
ShaderProgram createShaderProgram(const GLchar* vertexSource, const GLchar* fragmentSource) {
assert(vertexSource != NULL);
assert(fragmentSource != NULL);

View File

@ -2,6 +2,9 @@
#define SHADER_UTIL_H
#include <GL/glew.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef struct {
GLenum type;

View File

@ -1,10 +1,3 @@
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <GL/glew.h>
#include <string.h>
#include "matrixMath.h"
#include "transformation.h"
void lookAt(mat4* out, vec3* eye, vec3* look, vec3* up) {

View File

@ -2,6 +2,12 @@
#define TRANSFORMATION_H
#include <GL/glew.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "matrixMath.h"
extern void lookAt(mat4* out, vec3* eye, vec3* look, vec3* up);
extern void perspectiveProjection(mat4* out, GLfloat near, GLfloat far);

View File

@ -1,9 +1,3 @@
#include <GL/glew.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "wavefrontobj.h"
#define OBJ_LINE_BUFFER_SIZE 256

View File

@ -2,7 +2,11 @@
#define WAVEFRONTOBJ_H
#include <GL/glew.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "matrixMath.h"
#include <sys/types.h>
typedef struct {
vec3 position;