游戏引擎矩阵乘法

Game Engine Matrices Multiplication

本文关键字:引擎 游戏      更新时间:2023-10-16

我一直在关注TheChernoProject关于如何制作游戏引擎的教程,但到目前为止,我遇到了一个错误,我似乎无法弄清楚如何解决它。 这是我目前所在的剧集的链接,我的问题从 28:40 开始。 我不断收到错误"控制达到非无效功能的末尾"。 我正在使用Xcode。

这是mat4.cpp

#include "mat4.h"
namespace engine { namespace maths {
mat4::mat4() {
for(int i=0;i<4*4;i++) {
elements[i] = 0.0f;
}
}
mat4::mat4(float diagonal) {
for(int i=0;i<4*4;i++) {
elements[i] = 0.0f;
elements[0 + 0 * 4] = diagonal;
elements[1 + 1 * 4] = diagonal;
elements[2 + 2 * 4] = diagonal;
elements[3 + 3 * 4] = diagonal;

}
}
mat4 mat4::identity() {
return mat4(1.0f);
}
mat4& mat4::multiply(const mat4& other) {
for(int y=0;y<4;y++) {
for(int x=0;x<4;x++) {
float sum = 0.0f;
for(int e=0;e<4;e++) {
sum += elements[x + e * 4] * other.elements[e + y * 4];
}
elements[x + y * 4] = sum;
}
}
}
} }

这是头文件 mat4.h

#pragma once
#include "maths.h"
namespace engine { namespace maths {
struct mat4 {
float elements[4 * 4];
mat4();
mat4(float diagonal);
static mat4 identity();
mat4& multiply(const mat4& other);
friend mat4 operator*(mat4 left, const mat4& right);
mat4& operator*=(const mat4& other);
static mat4 orthographic(float left, float right, float bottom, float top, float near, float far);
static mat4 perspective(float fov, float aspectRatio, float near, float far);
static mat4 translation(const vec3& translation);
static mat4 rotation(float angle, const vec3& axis);
static mat4 scale(const vec3& scale);
};
} }
mat4& mat4::multiply(const mat4& other) {
for(int y=0;y<4;y++) {
for(int x=0;x<4;x++) {
float sum = 0.0f;
for(int e=0;e<4;e++) {
sum += elements[x + e * 4] * other.elements[e + y * 4];
}
elements[x + y * 4] = sum;
}
}
}

不返回任何内容,但声明返回mat4&