Skip to content

Commit

Permalink
Fix rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjaltesorgenfrei committed Feb 11, 2024
1 parent cd0cf7a commit 6579419
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"JPH_DEBUG_RENDERER",
"VULKAN_HPP_NO_STRUCT_CONSTRUCTORS"
],
"windowsSdkVersion": "10.0.22000.0",
"compilerPath": "cl.exe",
"cStandard": "c17",
"intelliSenseMode": "windows-msvc-x64"
Expand Down
2 changes: 1 addition & 1 deletion src/client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ void App::drawDebugForSelectedEntity(entt::entity selectedEntity, FrameInfo& fra
if (currentGizmoOperation == ImGuizmo::TRANSLATE && drawImGuizmo(&bodyTransform, &delta)) {
physicsWorld->setPosition(body->bodyID, delta * glm::vec4(body->position, 1.f));
} else if (currentGizmoOperation == ImGuizmo::ROTATE && drawImGuizmo(&bodyTransform, &delta)) {
physicsWorld->setRotation(body->bodyID, glm::toQuat(delta) * body->rotation);
physicsWorld->setRotation(body->bodyID, body->rotation * glm::toQuat(delta));
} else if (currentGizmoOperation == ImGuizmo::SCALE &&
drawImGuizmo(&bodyTransform, &delta)) { // TODO: Broken and crashes.
physicsWorld->setScale(body->bodyID, delta * glm::vec4(body->scale, 1.f));
Expand Down
2 changes: 1 addition & 1 deletion src/engine/NetworkServerSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ void NetworkServerSystem::update(entt::registry &registry, PhysicsWorld *world,
message->position.y = body.position.y;
message->position.z = body.position.z;

message->rotation.w = body.rotation.w;
message->rotation.x = body.rotation.x;
message->rotation.y = body.rotation.y;
message->rotation.z = body.rotation.z;
message->rotation.w = body.rotation.w;

message->linearVelocity.x = body.linearVelocity.x;
message->linearVelocity.y = body.linearVelocity.y;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ void PhysicsWorld::setPosition(IDType bodyID, glm::vec3 position) {
}

void PhysicsWorld::setRotation(IDType bodyID, glm::quat rotation) {
bodyInterface->SetRotation(bodyID, Quat(rotation.w, rotation.x, rotation.y, rotation.z), EActivation::Activate);
bodyInterface->SetRotation(bodyID, Quat(rotation.x, rotation.y, rotation.z, rotation.w), EActivation::Activate);
}

void PhysicsWorld::setScale(IDType bodyID, glm::vec3 scale) {
Expand Down
4 changes: 2 additions & 2 deletions src/engine/networking_handlers/PhysicsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ glm::vec3 fromFloat3(float3 v3) {
}

glm::quat fromFloat4(float4 v4) {
return glm::quat(v4.x, v4.y, v4.z, v4.w);
return glm::quat(v4.w, v4.x, v4.y, v4.z);
}

const void PhysicsHandler::internalHandle(entt::registry& registry, PhysicsWorld* world,
std::unordered_map<NetworkID, entt::entity>& idToEntity,
PhysicsState* state) {
auto entity = idToEntity[state->networkID];
auto body = registry.try_get<PhysicsBody>(entity);

if (body && state->isActive) {
world->setPosition(body->bodyID, fromFloat3(state->position));
world->setLinearVelocity(body->bodyID, fromFloat3(state->linearVelocity));
Expand Down
4 changes: 2 additions & 2 deletions src/shared/SharedServerSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ struct float3 {
};

struct float4 {
float w;
float x;
float y;
float z;
float w;
};

struct PhysicsState : public Message {
Expand All @@ -38,7 +38,7 @@ struct PhysicsState : public Message {
serialize_bits(stream, tick, 32);
serialize_bits(stream, networkID, 32);
serialize_bool(stream, isActive);

if (isActive) {
serialize_float(stream, position.x);
serialize_float(stream, position.y);
Expand Down

0 comments on commit 6579419

Please sign in to comment.