Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ set(CUBOS_ENGINE_SOURCE
"src/physics/solver/plugin.cpp"
"src/physics/constraints/penetration_constraint.cpp"
"src/physics/constraints/distance_constraint.cpp"
"src/physics/constraints/spring_constraint.cpp"
"src/physics/solver/penetration_constraint/plugin.cpp"
"src/physics/solver/distance_constraint/plugin.cpp"
"src/physics/solver/spring_constraint/plugin.cpp"
"src/physics/fixed_substep/plugin.cpp"
"src/physics/fixed_substep/substeps.cpp"
"src/physics/solver/integration/plugin.cpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/// @file
/// @brief Component @ref cubos::engine::SpringConstraint.
/// @ingroup physics-solver-plugin

#pragma once

#include <vector>

#include <glm/vec3.hpp>

#include <cubos/core/ecs/entity/entity.hpp>
#include <cubos/core/reflection/reflect.hpp>

namespace cubos::engine
{
/// @brief Relation which holds the information for a spring constraint between two bodies.
/// @ingroup physics-solver-plugin
struct SpringConstraint
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it needs CUBOS_ENGINE_API after struct so that it is accessible in the dll for us to use in games

{
CUBOS_REFLECT;
float stiffness; ///< Spring stiffness (force per unit extension)
float damping; ///< Damping coefficient
float restLength; ///< Rest length of spring
glm::vec3 localAnchor1; ///< The local contact point relative to the center of mass of the first body.
glm::vec3 localAnchor2; ///< The local contact point relative to the center of mass of the second body.
};
} // namespace cubos::engine
2 changes: 2 additions & 0 deletions engine/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function(make_sample)
target_link_libraries(${target} cubos::engine)
cubos_common_target_options(${target})


if(EMSCRIPTEN)
target_link_options(${target} PRIVATE
"SHELL:--shell-file ${CMAKE_CURRENT_SOURCE_DIR}/emscripten.html"
Expand Down Expand Up @@ -77,4 +78,5 @@ make_sample(DIR "ui" ASSETS)
make_sample(DIR "physics" ASSETS)
make_sample(DIR "complex_physics" ASSETS)
make_sample(DIR "distance_constraint" ASSETS)
make_sample(DIR "spring_constraint" ASSETS)
make_sample(DIR "games/cubosurfers" ASSETS SOURCES "spawner.cpp" "obstacle.cpp" "player.cpp")
11 changes: 8 additions & 3 deletions engine/samples/distance_constraint/main.cpp
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did a sample just for the spring constraint so I think you can remove the changes you did to this file (if they are different move it to the other sample)

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <cubos/engine/gizmos/target.hpp>
#include <cubos/engine/input/plugin.hpp>
#include <cubos/engine/physics/constraints/distance_constraint.hpp>
#include <cubos/engine/physics/constraints/spring_constraint.hpp>
#include <cubos/engine/physics/plugin.hpp>
#include <cubos/engine/physics/solver/plugin.hpp>
#include <cubos/engine/render/camera/camera.hpp>
Expand Down Expand Up @@ -48,9 +49,10 @@ struct Options
Circle,
Pendulum,
DoublePendulum,
PushPull
PushPull,
SpringTest
};
Scenarios currentScenario = DoublePendulum;
Scenarios currentScenario = Circle;
};

struct State
Expand Down Expand Up @@ -288,7 +290,7 @@ int main(int argc, char** argv)
glm::vec3 direction =
glm::normalize(glm::vec3(localToWorld2.mat * glm::vec4(constraint.localAnchor2, 1.0F)) - pointFrom);

gizmos.color({1.0F, 0.0F, 0.0F});
gizmos.color({0.0F, 1.0F, 1.0F});
gizmos.drawLine("the line between", pointFrom,
constraint.isRigid ? pointFrom + glm::normalize(direction) * constraint.fixedDistance
: pointFrom + glm::normalize(direction) * constraint.minDistance);
Expand Down Expand Up @@ -345,6 +347,9 @@ int main(int argc, char** argv)
options.currentScenario = Options::Scenarios::PushPull;
break;
case Options::Scenarios::PushPull:
options.currentScenario = Options::Scenarios::SpringTest;
break;
case Options::Scenarios::SpringTest:
options.currentScenario = Options::Scenarios::Circle;
break;
}
Expand Down
44 changes: 44 additions & 0 deletions engine/samples/spring_constraint/assets/collisions.bind
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"actions": {
"camera-toggle": [
{"keys": ["LControl"]}
],
"reset": [
{"keys": ["Space"]}
]
},
"axes": {
"move-lateral": {
"positive": [
{"keys": ["D"]}
],
"negative": [
{"keys": ["A"]}
]
},
"move-vertical": {
"positive": [
{"keys": ["E"]}
],
"negative": [
{"keys": ["Q"]}
]
},
"move-longitudinal": {
"positive": [
{"keys": ["W"]}
],
"negative": [
{"keys": ["S"]}
]
},
"change-speed": {
"positive": [
{"keys": ["Tab"]}
],
"negative": [
{"keys": ["LShift"]}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "53d85d6f-42a8-4eb8-aeae-1754a4cb20df"
}
Loading
Loading