改善力的显示

main
wuyize 2023-04-19 20:52:57 +08:00
parent 5bd6647d14
commit 26debb6419
2 changed files with 4 additions and 4 deletions

View File

@ -25,10 +25,10 @@ DemoWorld::DemoWorld()
particle->setSpeed(glm::vec3(-1, 0, 0)); particle->setSpeed(glm::vec3(-1, 0, 0));
particle->setPosition({ 4, 5, 0 }); particle->setPosition({ 4, 5, 0 });
//particle->addForce(std::make_shared<Force>(glm::vec3(0.f, -particle->getMass() * 9.8f, 0.f))); //particle->addForce(std::make_shared<Force>(glm::vec3(0.f, -particle->getMass() * 9.8f, 0.f)));
auto particle2 = std::make_shared<Particle>(10, "Models/vampire/vampire.gltf"); auto particle2 = std::make_shared<Particle>(10, "E:\\3D Objects\\pallet_wood\\New Folder\\pallet_wood.gltf");
particle2->setSpeed(glm::vec3(1, 0, 0)); particle2->setSpeed(glm::vec3(1, 0, 0));
particle2->setPosition({ 6, 5, 0 }); particle2->setPosition({ 6, 5, 0 });
particle2->setScale(glm::vec3{ 0.4 }); particle2->setScale(glm::vec3{ 0.002 });
auto particle3 = std::make_shared<Particle>(10); auto particle3 = std::make_shared<Particle>(10);
particle3->setSpeed(glm::vec3(0, 1, 0)); particle3->setSpeed(glm::vec3(0, 1, 0));

View File

@ -59,11 +59,11 @@ void Particle::draw(const RenderPassContext& context, Shader& shader)
debugShader.use(); debugShader.use();
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), getScale()) * glm::mat4_cast(getRotation()) * glm::scale(glm::mat4(1), glm::vec3(glm::abs(resultantForce / mass))); glm::mat4 modelMatrix = glm::translate(glm::mat4(1), getPosition()) * glm::mat4_cast(getRotation()) * glm::scale(glm::mat4(1), glm::vec3(glm::abs(resultantForce / mass)));
gl->BindVertexArray(vao); gl->BindVertexArray(vao);
for (auto& force : forces) for (auto& force : forces)
{ {
debugShader.setUniformValue("model", modelMatrix * glm::scale(glm::mat4(1), glm::vec3(5)) * glm::mat4_cast(glm::rotation(glm::vec3(1, 0, 0), glm::normalize(force->value)))); debugShader.setUniformValue("model", modelMatrix * glm::scale(glm::mat4(1), glm::vec3(1)) * glm::mat4_cast(glm::rotation(glm::vec3(1, 0, 0), glm::normalize(force->value))));
debugShader.setUniformValue("color", glm::vec3(0, 1, 0)); debugShader.setUniformValue("color", glm::vec3(0, 1, 0));
gl->DrawArrays(GL_LINES, 0, 2); gl->DrawArrays(GL_LINES, 0, 2);
} }