Moved over from Win32 resources to purely nfpack; Included primitives and default shader in base.nfpack; Camera fixes

This commit is contained in:
grayson committed 2021-09-01 13:08:21 -05:00
1 parent 48821afd76
commit c0f7634b5f
32 files changed
+5062 -224

No files matched your search

+31 -22
View File
@@ -7,17 +7,26 @@
namespace nf {
Camera::Camera(Application* app) :
m_app(app)
m_app(app),
m_type(Type::NF_CAMERA_UI),
m_position(0.0),
m_front(0.0, 0.0, -1.0),
m_yaw(-90.0f),
m_pitch(0.0)
{
m_type = Type::NF_CAMERA_UI;
}
void Camera::setType(Type cameraType) {
m_type = cameraType;
if (m_type == Type::NF_CAMERA_FIRST_PERSON || m_type == Type::NF_CAMERA_ORBIT)
m_app->trackMouse(true);
else
m_app->trackMouse(false);
if (cameraType != m_type) {
m_type = cameraType;
if (m_type == Type::NF_CAMERA_FIRST_PERSON || m_type == Type::NF_CAMERA_ORBIT)
m_app->trackMouse(true);
else
m_app->trackMouse(false);
m_yaw = -90.0f;
m_pitch = 0.0f;
}
}
Camera::Type Camera::getType() const {
@@ -26,24 +35,26 @@ namespace nf {
void Camera::moveForward(double speed) {
Vec3 temp = m_front * speed;
m_position = { m_position.x + temp.x, m_position.y + temp.y, m_position.z + temp.z };
m_position += temp;
}
void Camera::moveBackward(double speed) {
Vec3 temp = m_front * speed;
m_position = { m_position.x - temp.x, m_position.y - temp.y, m_position.z - temp.z };
m_position -= temp;
}
void Camera::moveRight(double speed) {
glm::vec3 front = { m_front.x, m_front.y, m_front.z };
glm::vec3 temp = glm::normalize(glm::cross(front, glm::vec3(0.0, 1.0, 0.0))) * (float)speed;
m_position = { m_position.x + temp.x, m_position.y + temp.y, m_position.z + temp.z };
Vec3 move = { temp.x, temp.y, temp.z };
m_position += move;
}
void Camera::moveLeft(double speed) {
glm::vec3 front = { m_front.x, m_front.y, m_front.z };
glm::vec3 temp = glm::normalize(glm::cross(front, glm::vec3(0.0, 1.0, 0.0))) * (float)speed;
m_position = { m_position.x - temp.x, m_position.y - temp.y, m_position.z - temp.z };
Vec3 move = { temp.x, temp.y, temp.z };
m_position -= move;
}
void Camera::setPosition(double x, double y, double z) {
@@ -68,18 +79,16 @@ namespace nf {
m_app->getMouseDiff(mouseDiffx, mouseDiffy);
float mouseX = (float)mouseDiffx * 0.1f;
float mouseY = (float)mouseDiffy * 0.1f;
static float yaw = -90.0f;
static float pitch = 0.0f;
yaw += mouseX;
pitch += mouseY;
if (pitch > 89.0f)
pitch = 89.0f;
if (pitch < -89.0f)
pitch = -89.0f;
m_yaw += mouseX;
m_pitch += mouseY;
if (m_pitch > 89.0f)
m_pitch = 89.0f;
if (m_pitch < -89.0f)
m_pitch = -89.0f;
glm::vec3 rotation;
rotation.x = std::cos(glm::radians(yaw)) * std::cos(glm::radians(pitch));
rotation.y = std::sin(glm::radians(pitch));
rotation.z = std::sin(glm::radians(yaw)) * std::cos(glm::radians(pitch));
rotation.x = std::cos(glm::radians(m_yaw)) * std::cos(glm::radians(m_pitch));
rotation.y = std::sin(glm::radians(m_pitch));
rotation.z = std::sin(glm::radians(m_yaw)) * std::cos(glm::radians(m_pitch));
rotation = glm::normalize(rotation);
m_front = { rotation.x, rotation.y, rotation.z };
glm::vec3 position(m_position.x, m_position.y, m_position.z);
+1 -1
View File
@@ -14,7 +14,7 @@ namespace nf {
void Entity::create(Asset* modelAsset, Asset* textureAsset) {
AModel& model = *(AModel*)modelAsset;
if (model.alreadyLoaded) {
if (model.alreadyLoaded && textureAsset == nullptr) {
m_model = model.loadedModel;
return;
}
+1 -1
View File
@@ -10,7 +10,7 @@ namespace nf {
Model::Model() {
}
void Model::create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinatesBufferData, size_t textureCoordinatesBufferSize, const unsigned char* textureData, size_t textureSize) {
void Model::create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinatesBufferData, size_t textureCoordinatesBufferSize, const char* textureData, size_t textureSize) {
m_vao = new VertexArray;
m_vao->addBuffer(vertexBufferData, vertexBufferSize);
m_vao->push<float>(3);
+11 -7
View File
@@ -6,7 +6,6 @@
#include "Application.h"
#include "Utility.h"
#include "resource.h"
namespace nf {
Renderer::Renderer(Application* app) {
@@ -55,19 +54,24 @@ namespace nf {
glEnable(GL_CULL_FACE);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Win32Res vs(IDR_DEFAULTVERTEX);
const char* defaultVertex = (const char*)vs.ptr;
Win32Res fs(IDR_DEFAULTFRAGMENT);
const char* defaultFragment = (const char*)fs.ptr;
if (defaultVertex == nullptr || defaultFragment == nullptr)
Error("Default engine resources not found! Please link nf.res to your application!");
baseAP.load("base.nfpack");
const char* defaultVertex = baseAP["defaultVertex.shader"]->data;
const char* defaultFragment = baseAP["defaultFragment.shader"]->data;
m_defaultShader = new Shader(defaultVertex, defaultFragment);
BaseAssets::cube = (AModel*)baseAP["cube.obj"];
BaseAssets::plane = (AModel*)baseAP["plane.obj"];
BaseAssets::sphere = (AModel*)baseAP["sphere.obj"];
BaseAssets::cone = (AModel*)baseAP["cone.obj"];
BaseAssets::cylinder = (AModel*)baseAP["cylinder.obj"];
BaseAssets::torus = (AModel*)baseAP["torus.obj"];
}
void Renderer::render(Entity& in) {
if (&in == nullptr)
Error("Tried to render Entity before being created!");
m_lGame.push_back(&in);
//TODO: Sort transparent objects by distance; Farthest first
}
void Renderer::doFrame(Camera* camera) {
+2 -2
View File
@@ -11,10 +11,10 @@ namespace nf {
glGenTextures(1, &m_id);
}
void Texture::create(const unsigned char* textureData, size_t textureSize) {
void Texture::create(const char* textureData, size_t textureSize) {
int width, height, nChannels;
stbi_set_flip_vertically_on_load(true);
unsigned char* texture = stbi_load_from_memory(textureData, textureSize, &width, &height, &nChannels, 0);
unsigned char* texture = stbi_load_from_memory((unsigned char*)textureData, textureSize, &width, &height, &nChannels, 0);
if (!texture)
Error("Texture failed to load from memory!");
glBindTexture(GL_TEXTURE_2D, m_id);