IF YOUR CUBE EVER LOOKS SHADED WEIRDLY, CHECK ITS NORMALS!!!
This commit is contained in:
parent
49672a793e
commit
3f51b9a28b
|
@ -1,7 +1,10 @@
|
|||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/ext/quaternion_trigonometric.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
|
@ -107,15 +110,15 @@ void processInput(GLFWwindow* window) {
|
|||
float shiftFactor = (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) ? -0.5 : 0.5;
|
||||
shiftFactor *= deltaTime;
|
||||
if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS) {
|
||||
parts.back().rotation.x += shiftFactor;
|
||||
parts.back().rotation *= glm::angleAxis(shiftFactor, glm::vec3(1, 0, 0));
|
||||
syncPartPhysics(parts.back());
|
||||
}
|
||||
if (glfwGetKey(window, GLFW_KEY_Y) == GLFW_PRESS) {
|
||||
parts.back().rotation.y += shiftFactor;
|
||||
parts.back().rotation *= glm::angleAxis(shiftFactor, glm::vec3(0, 1, 0));
|
||||
syncPartPhysics(parts.back());
|
||||
}
|
||||
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) {
|
||||
parts.back().rotation.z += shiftFactor;
|
||||
parts.back().rotation *= glm::angleAxis(shiftFactor, glm::vec3(0, 0, 1));
|
||||
syncPartPhysics(parts.back());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/fwd.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <reactphysics3d/body/RigidBody.h>
|
||||
#include "rendering/material.h"
|
||||
|
||||
|
@ -7,7 +9,7 @@ namespace rp = reactphysics3d;
|
|||
|
||||
struct Part {
|
||||
glm::vec3 position;
|
||||
glm::vec3 rotation;
|
||||
glm::quat rotation = glm::identity<glm::quat>();
|
||||
glm::vec3 scale;
|
||||
Material material;
|
||||
|
||||
|
|
|
@ -34,12 +34,8 @@ void simulationInit() {
|
|||
|
||||
void syncPartPhysics(Part& part) {
|
||||
glm::mat4 rotMat = glm::mat4(1.0f);
|
||||
rotMat = glm::rotate(rotMat, part.rotation.x, glm::vec3(1., 0., 0.));
|
||||
rotMat = glm::rotate(rotMat, part.rotation.y, glm::vec3(0., 1., 0.));
|
||||
rotMat = glm::rotate(rotMat, part.rotation.z, glm::vec3(0., 0., 1.));
|
||||
glm::quat quat(rotMat);
|
||||
|
||||
rp::Transform transform(glmToRp(part.position), glmToRp(quat));
|
||||
rp::Transform transform(glmToRp(part.position), glmToRp(part.rotation));
|
||||
if (!part.rigidBody) {
|
||||
part.rigidBody = world->createRigidBody(transform);
|
||||
} else {
|
||||
|
@ -63,6 +59,7 @@ void physicsStep(float deltaTime) {
|
|||
for (Part& part : parts) {
|
||||
const rp::Transform& transform = part.rigidBody->getTransform();
|
||||
part.position = rpToGlm(transform.getPosition());
|
||||
part.rotation = glm::eulerAngles(rpToGlm(transform.getOrientation()));
|
||||
// part.rotation = glm::eulerAngles(rpToGlm(transform.getOrientation()));
|
||||
part.rotation = rpToGlm(transform.getOrientation());
|
||||
}
|
||||
}
|
|
@ -5,12 +5,12 @@ Mesh* CUBE_MESH;
|
|||
void initMeshes() {
|
||||
static float vertices[] = {
|
||||
// positions // normals // texture coords
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
|
||||
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f,
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <GL/gl.h>
|
||||
#include <cstdio>
|
||||
#include <glm/ext.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
|
@ -75,9 +76,7 @@ void render(GLFWwindow* window) {
|
|||
for (Part part : parts) {
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, part.position);
|
||||
model = glm::rotate(model, part.rotation.x, glm::vec3(1., 0., 0.));
|
||||
model = glm::rotate(model, part.rotation.y, glm::vec3(0., 1., 0.));
|
||||
model = glm::rotate(model, part.rotation.z, glm::vec3(0., 0., 1.));
|
||||
model = model * glm::mat4_cast(part.rotation);
|
||||
model = glm::scale(model, part.scale);
|
||||
shader->set("model", model);
|
||||
glm::mat3 normalMatrix = glm::mat3(glm::transpose(glm::inverse(model)));
|
||||
|
|
Loading…
Reference in a new issue