游戏引擎矩阵乘法
Game Engine Matrices Multiplication
我一直在关注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&
相关文章:
- 提高基于组件的游戏引擎的效率
- 虚幻引擎 3 游戏在 Steam 输入时崩溃
- 我的游戏引擎的 spdlog 日志记录出现奇怪的"unresolved external symbol"错误
- 游戏引擎矩阵乘法
- 如何在没有现有引擎的情况下在游戏中设计我的事件触发器框架?
- 游戏引擎 SFML C++错误
- 游戏引擎设计问题
- 使用虚幻引擎4编程的平台游戏中的偏转问题
- 我正在尝试安装游戏引擎,但遇到错误
- 我的游戏引擎的 FMOD 音频
- 如何在 GLFW 中为游戏引擎执行正确的输入类
- 游戏引擎:如何从结构:编码实践转换变量
- 如何防止游戏引擎更新循环中的多个声音呼叫
- 游戏引擎:Dynamic_cast-对象类不是多态类型
- 在游戏引擎布局中使用shared_ptr
- 虚幻引擎4.20在我尝试玩游戏时崩溃
- 如何打包游戏的资产并仅允许引擎读取
- C#或C++来制作游戏引擎(深度)
- DirectX 11 2D游戏引擎使用Direct 3D(C )
- 游戏中图形和物理引擎之间共享数据