解决Model变换累计误差的问题
parent
ffe842c7eb
commit
210f7a3bf3
|
@ -14,16 +14,6 @@ ModelWorld::ModelWorld()
|
||||||
camera.Position = { 0,10,20 };
|
camera.Position = { 0,10,20 };
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelWorld::logicalTick(float deltaTime)
|
|
||||||
{
|
|
||||||
World::logicalTick(deltaTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ModelWorld::rendererTick(float deltaTime)
|
|
||||||
{
|
|
||||||
World::rendererTick(deltaTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ModelWorld::cursorPosCallback(GLFWwindow* window, double xpos, double ypos)
|
void ModelWorld::cursorPosCallback(GLFWwindow* window, double xpos, double ypos)
|
||||||
{
|
{
|
||||||
static bool firstMouse = true;
|
static bool firstMouse = true;
|
||||||
|
|
|
@ -5,8 +5,6 @@ class ModelWorld : public World
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ModelWorld();
|
ModelWorld();
|
||||||
void logicalTick(float deltaTime) override;
|
|
||||||
void rendererTick(float deltaTime) override;
|
|
||||||
virtual void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) override;
|
virtual void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) override;
|
||||||
virtual void scrollCallback(GLFWwindow* window, double xoffset, double yoffset) override;
|
virtual void scrollCallback(GLFWwindow* window, double xoffset, double yoffset) override;
|
||||||
virtual void processInput(GLFWwindow* window, float deltaTime) override;
|
virtual void processInput(GLFWwindow* window, float deltaTime) override;
|
||||||
|
|
|
@ -150,6 +150,9 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="ModelWorld.h" />
|
<ClInclude Include="ModelWorld.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="ClassDiagram.cd" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
|
|
@ -27,4 +27,7 @@
|
||||||
<Filter>头文件</Filter>
|
<Filter>头文件</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="ClassDiagram.cd" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -6,23 +6,12 @@ ModelWorld::ModelWorld()
|
||||||
light.lightDirection = glm::normalize(glm::vec3((cos(lightPitch) * cos(lightYaw)), (sin(lightPitch)), (cos(lightPitch) * sin(lightYaw))));
|
light.lightDirection = glm::normalize(glm::vec3((cos(lightPitch) * cos(lightYaw)), (sin(lightPitch)), (cos(lightPitch) * sin(lightYaw))));
|
||||||
light.radiance = 3.f * lightColor;
|
light.radiance = 3.f * lightColor;
|
||||||
RenderingSystem::instance().exposure = 0.45f;
|
RenderingSystem::instance().exposure = 0.45f;
|
||||||
|
camera.Position = { 0,5,10 };
|
||||||
|
|
||||||
model = std::make_shared<Actor>("Models/David_Brown_25D_tractor_SF/David_Brown_25D_tractor_SF.obj");
|
model = std::make_shared<Actor>("Models/David_Brown_25D_tractor_SF/David_Brown_25D_tractor_SF.obj");
|
||||||
model->setPosition({ 0,0,0 });
|
model->setPosition({ 0,0,0 });
|
||||||
model->setScale(glm::vec3(0.5));
|
model->setScale(glm::vec3(0.5));
|
||||||
addActor(model);
|
addActor(model);
|
||||||
|
|
||||||
camera.Position = { 0,5,10 };
|
|
||||||
}
|
|
||||||
|
|
||||||
void ModelWorld::logicalTick(float deltaTime)
|
|
||||||
{
|
|
||||||
World::logicalTick(deltaTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ModelWorld::rendererTick(float deltaTime)
|
|
||||||
{
|
|
||||||
World::rendererTick(deltaTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelWorld::cursorPosCallback(GLFWwindow* window, double xpos, double ypos)
|
void ModelWorld::cursorPosCallback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
@ -74,13 +63,14 @@ void ModelWorld::processInput(GLFWwindow* window, float deltaTime)
|
||||||
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
|
||||||
camera.processKeyboard(DOWN, deltaTime);
|
camera.processKeyboard(DOWN, deltaTime);
|
||||||
|
|
||||||
float speed = 0.1;
|
float speed = 10;
|
||||||
|
float d = speed * deltaTime;
|
||||||
if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS)
|
||||||
model->setPosition(model->getPosition() + glm::vec3(0, 0, -speed));
|
model->setPosition(model->getPosition() + glm::vec3(0, 0, -d));
|
||||||
if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS)
|
||||||
model->setPosition(model->getPosition() + glm::vec3(0, 0, speed));
|
model->setPosition(model->getPosition() + glm::vec3(0, 0, d));
|
||||||
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS)
|
||||||
model->setPosition(model->getPosition() + glm::vec3(-speed, 0, 0));
|
model->setPosition(model->getPosition() + glm::vec3(-d, 0, 0));
|
||||||
if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS)
|
||||||
model->setPosition(model->getPosition() + glm::vec3(speed, 0, 0));
|
model->setPosition(model->getPosition() + glm::vec3(d, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,6 @@ class ModelWorld : public World
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ModelWorld();
|
ModelWorld();
|
||||||
void logicalTick(float deltaTime) override;
|
|
||||||
void rendererTick(float deltaTime) override;
|
|
||||||
virtual void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) override;
|
virtual void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) override;
|
||||||
virtual void scrollCallback(GLFWwindow* window, double xoffset, double yoffset) override;
|
virtual void scrollCallback(GLFWwindow* window, double xoffset, double yoffset) override;
|
||||||
virtual void processInput(GLFWwindow* window, float deltaTime) override;
|
virtual void processInput(GLFWwindow* window, float deltaTime) override;
|
||||||
|
|
|
@ -42,18 +42,18 @@ ParticleWorld::ParticleWorld()
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
planet = std::make_shared<Particle>(100);
|
star = std::make_shared<Particle>(100);
|
||||||
planet->setPosition({ -10,0,0 });
|
star->setPosition({ -10,0,0 });
|
||||||
planet->setFixed(true);
|
star->setFixed(true);
|
||||||
|
|
||||||
auto p1 = std::make_shared<Particle>(1);
|
auto p = std::make_shared<Particle>(1);
|
||||||
p1->setPosition({ -15,0,0 });
|
p->setPosition({ -15,0,0 });
|
||||||
p1->setSpeed(glm::vec3(0, 0, 1) * glm::sqrt(G * planet->getMass() / glm::distance(planet->getPosition(), p1->getPosition())));
|
p->setSpeed(glm::vec3(0, 0, 1) * glm::sqrt(G * star->getMass() / glm::distance(star->getPosition(), p->getPosition())));
|
||||||
|
|
||||||
addActor(planet);
|
addActor(star);
|
||||||
addActor(p1);
|
addActor(p);
|
||||||
|
|
||||||
physicsManager.addGravitation(planet, p1, G);
|
physicsManager.addGravitation(star, p, G);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,18 +75,6 @@ void ParticleWorld::rendererTick(float deltaTime)
|
||||||
}
|
}
|
||||||
else iter++;
|
else iter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addNewParticle)
|
|
||||||
{
|
|
||||||
addNewParticle = false;
|
|
||||||
|
|
||||||
auto p = std::make_shared<Particle>(1);
|
|
||||||
p->setPosition(camera.Position + glm::vec3(0, -0.3, 0));
|
|
||||||
p->setSpeed(5.f * glm::normalize(camera.Front));
|
|
||||||
addActor(p);
|
|
||||||
physicsManager.addGravitation(planet, p, G);
|
|
||||||
particles.push_back(p);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleWorld::cursorPosCallback(GLFWwindow* window, double xpos, double ypos)
|
void ParticleWorld::cursorPosCallback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
@ -114,7 +102,14 @@ void ParticleWorld::cursorPosCallback(GLFWwindow* window, double xpos, double yp
|
||||||
void ParticleWorld::mouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
void ParticleWorld::mouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
||||||
{
|
{
|
||||||
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS)
|
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS)
|
||||||
addNewParticle = true;
|
{
|
||||||
|
auto p = std::make_shared<Particle>(1);
|
||||||
|
p->setPosition(camera.Position + glm::vec3(0, -0.3, 0));
|
||||||
|
p->setSpeed(5.f * glm::normalize(camera.Front));
|
||||||
|
addActor(p);
|
||||||
|
physicsManager.addGravitation(star, p, G);
|
||||||
|
particles.push_back(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleWorld::scrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
void ParticleWorld::scrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
||||||
|
|
|
@ -13,13 +13,11 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::shared_ptr<Particle>> particles;
|
std::vector<std::shared_ptr<Particle>> particles;
|
||||||
std::shared_ptr<Particle> planet;
|
std::shared_ptr<Particle> star;
|
||||||
float G = 1;
|
float G = 1;
|
||||||
|
|
||||||
glm::vec3 lightColor = glm::normalize(glm::vec3(0.7529, 0.7450, 0.6784));
|
glm::vec3 lightColor = glm::normalize(glm::vec3(0.7529, 0.7450, 0.6784));
|
||||||
float lightYaw = glm::radians(80.f);
|
float lightYaw = glm::radians(80.f);
|
||||||
float lightPitch = glm::radians(105.f);
|
float lightPitch = glm::radians(105.f);
|
||||||
|
|
||||||
bool addNewParticle = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -59,25 +59,26 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="ClassDiagram.cd" />
|
<None Include="ClassDiagram.cd" />
|
||||||
<None Include="Shaders\brdf_lut.comp" />
|
<None Include="ClassDiagram1.cd" />
|
||||||
<None Include="Shaders\cubemap.frag" />
|
<None Include="Engine\Shaders\brdf_lut.comp" />
|
||||||
<None Include="Shaders\cubemap.vert" />
|
<None Include="Engine\Shaders\cubemap.frag" />
|
||||||
<None Include="Shaders\cubemap_prefilter.frag" />
|
<None Include="Engine\Shaders\cubemap.vert" />
|
||||||
<None Include="Shaders\debug.frag" />
|
<None Include="Engine\Shaders\cubemap_prefilter.frag" />
|
||||||
<None Include="Shaders\debug.vert" />
|
<None Include="Engine\Shaders\debug.frag" />
|
||||||
<None Include="Shaders\final.frag" />
|
<None Include="Engine\Shaders\debug.vert" />
|
||||||
<None Include="Shaders\final.vert" />
|
<None Include="Engine\Shaders\final.frag" />
|
||||||
<None Include="Shaders\irradiance_convolution.frag" />
|
<None Include="Engine\Shaders\final.vert" />
|
||||||
<None Include="Shaders\model.frag" />
|
<None Include="Engine\Shaders\irradiance_convolution.frag" />
|
||||||
<None Include="Shaders\model.vert" />
|
<None Include="Engine\Shaders\model.frag" />
|
||||||
<None Include="Shaders\model_shadow.frag" />
|
<None Include="Engine\Shaders\model.vert" />
|
||||||
<None Include="Shaders\model_shadow.geom" />
|
<None Include="Engine\Shaders\model_shadow.frag" />
|
||||||
<None Include="Shaders\model_shadow.vert" />
|
<None Include="Engine\Shaders\model_shadow.geom" />
|
||||||
<None Include="Shaders\pbr.comp" />
|
<None Include="Engine\Shaders\model_shadow.vert" />
|
||||||
<None Include="Shaders\plain.frag" />
|
<None Include="Engine\Shaders\pbr.comp" />
|
||||||
<None Include="Shaders\plain.vert" />
|
<None Include="Engine\Shaders\plain.frag" />
|
||||||
<None Include="Shaders\skybox.frag" />
|
<None Include="Engine\Shaders\plain.vert" />
|
||||||
<None Include="Shaders\skybox.vert" />
|
<None Include="Engine\Shaders\skybox.frag" />
|
||||||
|
<None Include="Engine\Shaders\skybox.vert" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<VCProjectVersion>16.0</VCProjectVersion>
|
<VCProjectVersion>16.0</VCProjectVersion>
|
||||||
|
|
|
@ -127,62 +127,63 @@
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Shaders\brdf_lut.comp">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\cubemap.frag">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\cubemap.vert">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\cubemap_prefilter.frag">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\final.frag">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\final.vert">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\irradiance_convolution.frag">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\model.frag">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\model.vert">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\model_shadow.frag">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\model_shadow.geom">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\model_shadow.vert">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\pbr.comp">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\plain.frag">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\plain.vert">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\skybox.frag">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Shaders\skybox.vert">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="ClassDiagram.cd" />
|
<None Include="ClassDiagram.cd" />
|
||||||
<None Include="Shaders\debug.frag">
|
<None Include="ClassDiagram1.cd" />
|
||||||
|
<None Include="Engine\Shaders\brdf_lut.comp">
|
||||||
<Filter>Shaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="Shaders\debug.vert">
|
<None Include="Engine\Shaders\cubemap.frag">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\cubemap.vert">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\cubemap_prefilter.frag">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\debug.frag">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\debug.vert">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\final.frag">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\final.vert">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\irradiance_convolution.frag">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\model.frag">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\model.vert">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\model_shadow.frag">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\model_shadow.geom">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\model_shadow.vert">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\pbr.comp">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\plain.frag">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\plain.vert">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\skybox.frag">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Engine\Shaders\skybox.vert">
|
||||||
<Filter>Shaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -73,9 +73,6 @@ int MainWindow::exec(std::unique_ptr<World> world_)
|
||||||
|
|
||||||
void MainWindow::processInput(GLFWwindow* window, float deltaTime)
|
void MainWindow::processInput(GLFWwindow* window, float deltaTime)
|
||||||
{
|
{
|
||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
|
||||||
glfwSetWindowShouldClose(window, true);
|
|
||||||
|
|
||||||
world->processInput(window, deltaTime);
|
world->processInput(window, deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +93,8 @@ void MainWindow::scrollCallback(GLFWwindow* window, double xoffset, double yoffs
|
||||||
|
|
||||||
void MainWindow::keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
void MainWindow::keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||||
{
|
{
|
||||||
|
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||||
|
glfwSetWindowShouldClose(window, true);
|
||||||
if (key == GLFW_KEY_TAB && action == GLFW_PRESS)
|
if (key == GLFW_KEY_TAB && action == GLFW_PRESS)
|
||||||
RenderingSystem::instance().setShowDebug(!RenderingSystem::instance().getShowDebug());
|
RenderingSystem::instance().setShowDebug(!RenderingSystem::instance().getShowDebug());
|
||||||
world->keyCallback(window, key, scancode, action, mods);
|
world->keyCallback(window, key, scancode, action, mods);
|
||||||
|
|
|
@ -32,12 +32,12 @@ public:
|
||||||
GLuint textureNormal = 0;
|
GLuint textureNormal = 0;
|
||||||
glm::vec3 baseColor;
|
glm::vec3 baseColor;
|
||||||
glm::vec2 metallicRoughness;
|
glm::vec2 metallicRoughness;
|
||||||
unsigned int VAO;
|
|
||||||
|
|
||||||
Mesh(GladGLContext* gl, const std::vector<Vertex>& vertices, const std::vector<unsigned int>& indices, const glm::mat4& model = glm::mat4(1));
|
Mesh(GladGLContext* gl, const std::vector<Vertex>& vertices, const std::vector<unsigned int>& indices, const glm::mat4& model = glm::mat4(1));
|
||||||
void draw(Shader& shader);
|
void draw(Shader& shader);
|
||||||
void setupMesh();
|
void setupMesh();
|
||||||
private:
|
private:
|
||||||
GladGLContext* gl;
|
GladGLContext* gl;
|
||||||
|
unsigned int VAO;
|
||||||
unsigned int VBO, EBO;
|
unsigned int VBO, EBO;
|
||||||
};
|
};
|
|
@ -60,7 +60,7 @@ Model Model::createSphere(GladGLContext* gl, const glm::vec3& baseColor, const g
|
||||||
mesh->drawMode = GL_TRIANGLE_STRIP;
|
mesh->drawMode = GL_TRIANGLE_STRIP;
|
||||||
mesh->baseColor = baseColor;
|
mesh->baseColor = baseColor;
|
||||||
mesh->metallicRoughness = metallicRoughness;
|
mesh->metallicRoughness = metallicRoughness;
|
||||||
sphere.meshes.emplace_back(std::move(mesh));
|
sphere.meshes.emplace_back(std::make_pair(std::move(mesh), glm::mat4(1)));
|
||||||
|
|
||||||
return sphere;
|
return sphere;
|
||||||
}
|
}
|
||||||
|
@ -79,17 +79,13 @@ Model::Model(GladGLContext* gl, std::string const& path)
|
||||||
void Model::draw(Shader& shader)
|
void Model::draw(Shader& shader)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < meshes.size(); i++)
|
for (unsigned int i = 0; i < meshes.size(); i++)
|
||||||
meshes[i]->draw(shader);
|
meshes[i].first->draw(shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::setTransform(const glm::mat4& trans)
|
void Model::setTransform(const glm::mat4& trans)
|
||||||
{
|
{
|
||||||
auto inverse = glm::inverse(transform);
|
|
||||||
transform = trans;
|
|
||||||
for (auto& mesh : meshes)
|
for (auto& mesh : meshes)
|
||||||
mesh->model = transform * inverse * mesh->model;
|
mesh.first->model = trans * mesh.second;
|
||||||
minPos = transform * inverse * glm::vec4(minPos, 1);
|
|
||||||
maxPos = transform * inverse * glm::vec4(maxPos, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<glm::vec3, glm::vec3> Model::getAABB()
|
std::pair<glm::vec3, glm::vec3> Model::getAABB()
|
||||||
|
@ -110,23 +106,20 @@ void Model::loadModel(std::string const& path)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
aiMatrix4x4 transform;
|
processNode(scene->mRootNode, scene, scene->mRootNode->mTransformation);
|
||||||
//aiMatrix4x4::Scaling(aiVector3D(10), transform);
|
|
||||||
//aiMatrix4x4::Rotation(glm::radians(-90.f), { 1,0,0 }, transform);
|
|
||||||
processNode(scene->mRootNode, scene, transform * scene->mRootNode->mTransformation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::processNode(aiNode* node, const aiScene* scene, aiMatrix4x4 mat4)
|
void Model::processNode(aiNode* node, const aiScene* scene, aiMatrix4x4 mat4)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < node->mNumMeshes; i++)
|
for (unsigned int i = 0; i < node->mNumMeshes; i++)
|
||||||
if (auto mesh = processMesh(scene->mMeshes[node->mMeshes[i]], scene, mat4))
|
if (auto mesh = processMesh(scene->mMeshes[node->mMeshes[i]], scene, mat4); mesh.first)
|
||||||
meshes.emplace_back(std::move(mesh));
|
meshes.emplace_back(std::move(mesh));
|
||||||
|
|
||||||
for (unsigned int i = 0; i < node->mNumChildren; i++)
|
for (unsigned int i = 0; i < node->mNumChildren; i++)
|
||||||
processNode(node->mChildren[i], scene, mat4 * node->mChildren[i]->mTransformation);
|
processNode(node->mChildren[i], scene, mat4 * node->mChildren[i]->mTransformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Mesh> Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 model)
|
std::pair<std::unique_ptr<Mesh>, glm::mat4> Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 model)
|
||||||
{
|
{
|
||||||
glm::mat4 mat4 = glm::transpose(glm::make_mat4((float*)&model));
|
glm::mat4 mat4 = glm::transpose(glm::make_mat4((float*)&model));
|
||||||
|
|
||||||
|
@ -148,7 +141,7 @@ std::unique_ptr<Mesh> Model::processMesh(aiMesh* mesh, const aiScene* scene, aiM
|
||||||
indices.insert(indices.end(), face->mIndices, face->mIndices + face->mNumIndices);
|
indices.insert(indices.end(), face->mIndices, face->mIndices + face->mNumIndices);
|
||||||
|
|
||||||
if (vertices.empty() || indices.empty())
|
if (vertices.empty() || indices.empty())
|
||||||
return nullptr;
|
return { nullptr, mat4 };
|
||||||
|
|
||||||
extractBoneWeightForVertices(vertices, mesh, scene);
|
extractBoneWeightForVertices(vertices, mesh, scene);
|
||||||
auto meshPtr = std::make_unique<Mesh>(gl, vertices, indices, mat4);
|
auto meshPtr = std::make_unique<Mesh>(gl, vertices, indices, mat4);
|
||||||
|
@ -177,8 +170,7 @@ std::unique_ptr<Mesh> Model::processMesh(aiMesh* mesh, const aiScene* scene, aiM
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
return meshPtr;
|
return std::make_pair(std::move(meshPtr), mat4);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Model
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
glm::mat4 transform = glm::mat4(1);
|
glm::mat4 transform = glm::mat4(1);
|
||||||
std::vector<std::unique_ptr<Mesh>> meshes;
|
std::vector<std::pair<std::unique_ptr<Mesh>, glm::mat4>> meshes;
|
||||||
std::map<std::string, BoneInfo> boneInfoMap;
|
std::map<std::string, BoneInfo> boneInfoMap;
|
||||||
int boneCount = 0;
|
int boneCount = 0;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ private:
|
||||||
|
|
||||||
void loadModel(std::string const& path);
|
void loadModel(std::string const& path);
|
||||||
void processNode(aiNode* node, const aiScene* scene, aiMatrix4x4 mat4 = aiMatrix4x4());
|
void processNode(aiNode* node, const aiScene* scene, aiMatrix4x4 mat4 = aiMatrix4x4());
|
||||||
std::unique_ptr<Mesh> processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 model);
|
std::pair<std::unique_ptr<Mesh>, glm::mat4> processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 model);
|
||||||
GLuint loadMaterialTextures(aiMaterial* mat, aiTextureType type);
|
GLuint loadMaterialTextures(aiMaterial* mat, aiTextureType type);
|
||||||
void extractBoneWeightForVertices(std::vector<Vertex>& vertices, aiMesh* mesh, const aiScene* scene);
|
void extractBoneWeightForVertices(std::vector<Vertex>& vertices, aiMesh* mesh, const aiScene* scene);
|
||||||
};
|
};
|
|
@ -19,6 +19,7 @@ Particle::Particle(float mass, const std::string& path)
|
||||||
|
|
||||||
void Particle::logicalTick(float deltaTime)
|
void Particle::logicalTick(float deltaTime)
|
||||||
{
|
{
|
||||||
|
Actor::logicalTick(deltaTime);
|
||||||
resultantForce = glm::vec3(0);
|
resultantForce = glm::vec3(0);
|
||||||
for (std::lock_guard<std::mutex> lk(forcesMutex); auto & force : forces)
|
for (std::lock_guard<std::mutex> lk(forcesMutex); auto & force : forces)
|
||||||
resultantForce += force->value;
|
resultantForce += force->value;
|
||||||
|
@ -29,8 +30,8 @@ void Particle::logicalTick(float deltaTime)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//auto pos = getPosition() + speed * deltaTime + 0.5f * resultantForce / mass * deltaTime * deltaTime;
|
acceleration = resultantForce / mass;
|
||||||
speed += resultantForce / mass * deltaTime;
|
speed += acceleration * deltaTime;
|
||||||
auto pos = getPosition() + speed * deltaTime;
|
auto pos = getPosition() + speed * deltaTime;
|
||||||
setPosition(pos);
|
setPosition(pos);
|
||||||
}
|
}
|
||||||
|
@ -46,11 +47,9 @@ void Particle::draw(const RenderPassContext& context, Shader& shader)
|
||||||
if (vao == 0)
|
if (vao == 0)
|
||||||
{
|
{
|
||||||
float vertices[] = {
|
float vertices[] = {
|
||||||
// positions
|
|
||||||
0.0f, 0.0f, 0.0f,
|
0.0f, 0.0f, 0.0f,
|
||||||
1.0f, 0.0f, 0.0f,
|
1.0f, 0.0f, 0.0f,
|
||||||
};
|
};
|
||||||
// setup plane VAO
|
|
||||||
gl->GenVertexArrays(1, &vao);
|
gl->GenVertexArrays(1, &vao);
|
||||||
gl->GenBuffers(1, &vbo);
|
gl->GenBuffers(1, &vbo);
|
||||||
gl->BindVertexArray(vao);
|
gl->BindVertexArray(vao);
|
||||||
|
@ -64,7 +63,7 @@ void Particle::draw(const RenderPassContext& context, Shader& shader)
|
||||||
gl->DepthMask(false);
|
gl->DepthMask(false);
|
||||||
debugShader.setUniformValue("projection", *context.projection);
|
debugShader.setUniformValue("projection", *context.projection);
|
||||||
debugShader.setUniformValue("view", *context.view);
|
debugShader.setUniformValue("view", *context.view);
|
||||||
glm::mat4 modelMatrix = glm::translate(glm::mat4(1), getPosition());// *glm::scale(glm::mat4(1), glm::vec3(glm::abs(resultantForce / mass)));
|
glm::mat4 modelMatrix = glm::translate(glm::mat4(1), getPosition());
|
||||||
gl->BindVertexArray(vao);
|
gl->BindVertexArray(vao);
|
||||||
for (std::lock_guard<std::mutex> lk(forcesMutex); auto & force : forces)
|
for (std::lock_guard<std::mutex> lk(forcesMutex); auto & force : forces)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue