fix warnings

This commit is contained in:
2024-07-18 20:46:08 +02:00
parent 8bc2f26578
commit 7abb31c2e1

View File

@@ -1,5 +1,7 @@
#include <iostream>
#include "Network.h"
#include <Nazara/Core.hpp>
#include <Nazara/Graphics.hpp>
#include <Nazara/Renderer.hpp>
@@ -7,7 +9,8 @@
#include <Nazara/Physics3D.hpp>
#include <random>
static Nz::Vector3f Get2DDirectionVectorFromRotation(float yaw) {
static Nz::Vector3f Get2DDirectionVectorFromRotation(float yaw)
{
return {
-std::sin(yaw),
0,
@@ -136,6 +139,7 @@ static void CreateModel(Nz::EnttWorld &world)
}
static Nz::EulerAnglesf camAngles(0.f, 0.f, 0.f);
static Nz::MillisecondClock updateClock;
static void CreateCamera(Nz::EnttWorld &world, Nz::Window &window, Nz::Application<Nz::Graphics, Nz::Physics3D> &app)
{
@@ -151,7 +155,7 @@ static void CreateCamera(Nz::EnttWorld &world, Nz::Window &window, Nz::Applicati
entt::handle cameraEntity = world.CreateEntity();
auto &cameraNode = cameraEntity.emplace<Nz::NodeComponent>();
cameraNode.SetPosition({0, 1, 0});
cameraNode.SetPosition({0, 2.5, 0});
auto &cameraComponent = cameraEntity.emplace<Nz::CameraComponent>(std::make_shared<Nz::RenderWindow>(windowSwapchain), Nz::ProjectionType::Perspective);
cameraComponent.UpdateClearColor(Nz::Color(0.3f, 0.8f, 1.0f));
@@ -166,42 +170,56 @@ static void CreateCamera(Nz::EnttWorld &world, Nz::Window &window, Nz::Applicati
window.GetEventHandler().OnMouseMoved.Connect([&](const Nz::WindowEventHandler * /*eventHandler*/, const Nz::WindowEvent::MouseMoveEvent &event)
{
constexpr float sensitivity = 0.3f;
constexpr float sensitivity = 0.3f;
camAngles.yaw -= event.deltaX * sensitivity;
camAngles.yaw.Normalize();
camAngles.yaw -= event.deltaX * sensitivity;
camAngles.yaw.Normalize();
camAngles.pitch = Nz::Clamp(camAngles.pitch - event.deltaY * sensitivity, -89.f, 89.f);
camAngles.pitch = Nz::Clamp(camAngles.pitch - event.deltaY * sensitivity, -89.f, 89.f);
camAngles.roll = 0.0f;
camAngles.roll = 0.0f;
cameraNode.SetRotation(camAngles);
cameraNode.SetRotation(camAngles);
});
});
Nz::Vector3f playerSize{0.5, 2, 0.5};
std::shared_ptr<Nz::BoxCollider3D> boxCollider = std::make_shared<Nz::BoxCollider3D>(Nz::Vector3f(1, 2, 1));
{
std::shared_ptr<Nz::GraphicalMesh> boxMesh = Nz::GraphicalMesh::Build(Nz::Primitive::Box(playerSize));
std::shared_ptr<Nz::MaterialInstance> boxMaterial = Nz::MaterialInstance::Instantiate(Nz::MaterialType::Phong);
boxMaterial->SetValueProperty("BaseColor", Nz::Color::sRGBToLinear({1.0, 0.0, 0.0}));
std::shared_ptr<Nz::Model> sphereModel = std::make_shared<Nz::Model>(boxMesh);
sphereModel->SetMaterial(0, std::move(boxMaterial));
playerEntity.emplace<Nz::GraphicsComponent>(std::move(sphereModel));
}
std::shared_ptr<Nz::BoxCollider3D> boxCollider = std::make_shared<Nz::BoxCollider3D>(playerSize);
static const int playerMass = 100000;
Nz::RigidBody3D::DynamicSettings settings;
settings.geom = boxCollider;
settings.mass = playerMass;
auto &playerBody = playerEntity.emplace<Nz::RigidBody3DComponent>(settings);
app.AddUpdaterFunc([&](){
static Nz::MillisecondClock updateClock;
if (std::optional<Nz::Time> deltaTime = updateClock.RestartIfOver(Nz::Time::TickDuration(60)))
playerEntity.emplace<Nz::RigidBody3DComponent>(settings);
app.AddUpdaterFunc([playerEntity]()
{
if (std::optional<Nz::Time> deltaTime = updateClock.RestartIfOver(Nz::Time::Milliseconds(30)))
{
camAngles.roll = 0;
cameraNode.SetRotation(camAngles);
Nz::Vector3f front = Get2DDirectionVectorFromRotation(camAngles.yaw.ToRadians());
Nz::Vector3f left = Get2DDirectionVectorFromRotation(camAngles.yaw.ToRadians() + 3.1415926535/2.0);
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Z))
playerBody.AddForce(front * 10.f * playerMass, Nz::CoordSys::Local);
auto& playerBody = playerEntity.get<Nz::RigidBody3DComponent>();
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Z)){
std::cout << front << "\n";
std::cout << "Pos : " << playerBody.GetPosition() << " \n";
playerBody.AddForce(front * 10.f * playerMass, Nz::CoordSys::Global);
}
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::S))
playerBody.AddForce(-front * 10.f * playerMass, Nz::CoordSys::Local);
@@ -212,14 +230,21 @@ static void CreateCamera(Nz::EnttWorld &world, Nz::Window &window, Nz::Applicati
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::D))
playerBody.AddForce(-left * 10.f * playerMass, Nz::CoordSys::Local);
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Space))
playerBody.AddForce(Nz::Vector3f::Up() * 15.f * playerMass, Nz::CoordSys::Local);
}
});
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Space)){
playerBody.AddForce(Nz::Vector3f::Up() * 15.f * playerMass, Nz::CoordSys::Global);
}
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::R)) {
auto& playerNode = playerEntity.get<Nz::NodeComponent>();
playerNode.SetPosition({0, 10, 0});
playerBody.SetPosition({0, 10, 0});
}
//playerBody.SetRotation({});
} });
}
int main(int argc, char **argv)
{
int Video(int argc, char **argv) {
Nz::Application<Nz::Graphics, Nz::Physics3D> app(argc, argv);
auto &windowing = app.AddComponent<Nz::WindowingAppComponent>();
@@ -233,7 +258,7 @@ int main(int argc, char **argv)
auto &physSystem = world.AddSystem<Nz::Physics3DSystem>();
physSystem.GetPhysWorld().SetMaxStepCount(1);
physSystem.GetPhysWorld().SetStepSize(Nz::Time::TickDuration(50));
physSystem.GetPhysWorld().SetStepSize(Nz::Time::Milliseconds(20));
physSystem.GetPhysWorld().SetGravity(Nz::Vector3f::Down() * 9.81f);
CreateCamera(world, window, app);
@@ -258,3 +283,8 @@ int main(int argc, char **argv)
return app.Run();
}
int main(int argc, char **argv)
{
TestNetwork();
}