游戏引擎矩阵乘法
Game Engine Matrices Multiplication
我一直在关注 TheChernoProject 关于如何制作游戏引擎的教程,但到目前为止我一直收到一个错误,我似乎无法弄清楚如何解决它。
Here is the link to the episode where I am currently at, my problem starts at 28:40.
我一直收到错误 "Control reaches end of non-void function."
我正在使用 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;
}
}
}
return 除了声明为 return mat4&
什么都没有
我一直在关注 TheChernoProject 关于如何制作游戏引擎的教程,但到目前为止我一直收到一个错误,我似乎无法弄清楚如何解决它。 Here is the link to the episode where I am currently at, my problem starts at 28:40. 我一直收到错误 "Control reaches end of non-void function." 我正在使用 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;
}
}
}
return 除了声明为 return mat4&