Skip to content

Commit

Permalink
Smaller changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tippesi committed Feb 15, 2024
1 parent e977ae6 commit ba4283b
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 15 deletions.
35 changes: 22 additions & 13 deletions src/editor/ui/panels/ViewportPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,17 @@ namespace Atlas::Editor::UI {

ImGui::Begin(GetNameID());

isFocused = ImGui::IsWindowFocused();

if (drawMenuBarFunc) {
ImGui::BeginChild("Viewport area");

isFocused |= ImGui::IsWindowFocused();

drawMenuBarFunc();

ImGui::EndChild();
// Workaround for offsetted Gizmo without resize after a restart
// Seems like some ImGuizmo or ImGui config isn't properly updated
if (firstFrame) {
auto size = ImGui::GetWindowPos();
ImGui::SetWindowPos(ImVec2(size.x + 1.0f, size.y));
firstFrame = false;
}

ImGui::BeginChild("Viewport area");
isFocused = ImGui::IsWindowFocused();

ImGui::BeginChild("Viewport area", ImVec2(0.0f, 0.0f));

isFocused |= ImGui::IsWindowFocused();

Expand Down Expand Up @@ -92,13 +90,24 @@ namespace Atlas::Editor::UI {
ImGui::Image(set, region);
}

ImGui::SetCursorPos(ImVec2(0.0f, windowPos.y));

if (drawOverlayFunc)
drawOverlayFunc();

ImGui::EndChild();

ImGui::SetCursorPos(ImVec2(0.0f, 0.0f));

if (drawMenuBarFunc) {
ImGui::BeginChild("Viewport area");

isFocused |= ImGui::IsWindowFocused();

drawMenuBarFunc();

ImGui::EndChild();
}


ImGui::End();

}
Expand Down
3 changes: 3 additions & 0 deletions src/editor/ui/panels/ViewportPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace Atlas::Editor::UI {
std::function<void()> drawMenuBarFunc;
std::function<void()> drawOverlayFunc;

private:
bool firstFrame = true;

};

}
8 changes: 8 additions & 0 deletions src/editor/ui/windows/SceneWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,14 @@ namespace Atlas::Editor::UI {
const auto& cameraComponent = entity.GetComponent<CameraComponent>();
viewportPanel.primitiveBatchWrapper.RenderLineFrustum(cameraComponent.frustum, vec3(1.0f, 0.0f, 1.0f));
}
if (entity.HasComponent<LightComponent>()) {
const auto& lightComponent = entity.GetComponent<LightComponent>();
if (lightComponent.shadow) {
for (const auto& component : lightComponent.shadow->views)
viewportPanel.primitiveBatchWrapper.RenderLineFrustum(
Volume::Frustum(component.frustumMatrix), vec3(1.0f, 0.0f, 0.0f));
}
}

}

Expand Down
98 changes: 98 additions & 0 deletions src/engine/physics/Player.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "Player.h"
#include "MathConversion.h"
#include "PhysicsWorld.h"
#include "PhysicsManager.h"

namespace Atlas::Physics {

Expand All @@ -13,10 +15,106 @@ namespace Atlas::Physics {
settings.mMass = mass;
settings.mMaxStrength = maxStrength;

settings.mPredictiveContactDistance = predictiveContactDistance;
settings.mCharacterPadding = padding;

settings.mShapeOffset = VecToJPHVec(shapeOffset);
settings.mShape = shape->ref;

return settings;

}

void Player::SetPosition(vec3 position) {

AE_ASSERT(world != nullptr && "Physics world is invalid");
character->SetPosition(Physics::VecToJPHVec(position));

}

mat4 Player::GetMatrix() const {

AE_ASSERT(world != nullptr && "Physics world is invalid");
return Physics::JPHMatToMat(character->GetWorldTransform());

}

void Player::SetLinearVelocity(vec3 velocity) {

AE_ASSERT(world != nullptr && "Physics world is invalid");
character->SetLinearVelocity(Physics::VecToJPHVec(velocity));

}

vec3 Player::GetLinearVelocity() const {

AE_ASSERT(world != nullptr && "Physics world is invalid");
return Physics::JPHVecToVec(character->GetLinearVelocity());

}

vec3 Player::GetGroundVelocity() const {

AE_ASSERT(world != nullptr && "Physics world is invalid");

character->UpdateGroundVelocity();
return Physics::JPHVecToVec(character->GetGroundVelocity());

}

bool Player::IsOnGround() const {

AE_ASSERT(world != nullptr && "Physics world is invalid");
return character->GetGroundState() == JPH::CharacterVirtual::EGroundState::OnGround;

}

void Player::SetUp(vec3 up) {

AE_ASSERT(world != nullptr && "Physics world is invalid");
character->SetUp(Physics::VecToJPHVec(up));

}

vec3 Player::GetUp() const {

AE_ASSERT(world != nullptr && "Physics world is invalid");
return Physics::JPHVecToVec(character->GetUp());

}

void Player::SetShape(const Ref<Shape>& shape) {

AE_ASSERT(world != nullptr && "Physics world is invalid");

auto system = world->system;

const auto& physicsSettings = system->GetPhysicsSettings();
const auto& broadPhaseLayerFilter = system->GetDefaultBroadPhaseLayerFilter(Layers::MOVABLE);
const auto& defaultLayerFilter = system->GetDefaultLayerFilter(Physics::Layers::MOVABLE);
const auto& tempAllocator = Physics::PhysicsManager::tempAllocator;

character->SetShape(shape->ref, physicsSettings.mPenetrationSlop * 1.5f, broadPhaseLayerFilter,
defaultLayerFilter, {}, {}, *tempAllocator);

}

void Player::Update(float deltaTime) {

AE_ASSERT(world != nullptr && "Physics world is invalid");

auto system = world->system;

const auto& physicsSettings = system->GetPhysicsSettings();
const auto& broadPhaseLayerFilter = system->GetDefaultBroadPhaseLayerFilter(Layers::MOVABLE);
const auto& defaultLayerFilter = system->GetDefaultLayerFilter(Physics::Layers::MOVABLE);
const auto& tempAllocator = Physics::PhysicsManager::tempAllocator;

auto gravityVector = -GetUp() * glm::length(world->GetGravity());

character->Update(deltaTime, VecToJPHVec(gravityVector), broadPhaseLayerFilter,
defaultLayerFilter, {}, {}, *tempAllocator);

}

}
35 changes: 34 additions & 1 deletion src/engine/physics/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,42 @@ namespace Atlas::Physics {
class Player {

public:
Player(const PlayerCreationSettings& creationSettings, Ref<PhysicsWorld>& physicsWorld);
Player(const PlayerCreationSettings& creationSettings, const Ref<PhysicsWorld>& physicsWorld);

bool IsValid() const { return world != nullptr; }

void SetPosition(vec3 position);

vec3 GetPosition() const;

void SetRotation(quat rotation);

quat GetRotation() const;

mat4 GetMatrix() const;

void SetLinearVelocity(vec3 velocity);

vec3 GetLinearVelocity() const;

vec3 GetGroundVelocity() const;

bool IsOnGround() const;

void SetUp(vec3 up);

vec3 GetUp() const;

void SetShape(const Ref<Shape>& shape);

virtual void Update(float deltaTime);

Ref<Physics::PlayerCreationSettings> playerCreationSettings = nullptr;

protected:
Ref<JPH::CharacterVirtual> character = nullptr;

PhysicsWorld* world = nullptr;

};

Expand Down
2 changes: 1 addition & 1 deletion src/engine/scene/components/RigidBodyComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Atlas {
explicit RigidBodyComponent(const Physics::BodyCreationSettings& bodyCreationSettings)
: layer(bodyCreationSettings.objectLayer), bodyCreationSettings(CreateRef(bodyCreationSettings)) {}

Physics::BodyCreationSettings GetBodyCreationSettings() override;
virtual Physics::BodyCreationSettings GetBodyCreationSettings() override;

Physics::ObjectLayer layer = Physics::Layers::STATIC;
Ref<Physics::BodyCreationSettings> bodyCreationSettings = nullptr;
Expand Down

0 comments on commit ba4283b

Please sign in to comment.