mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-08 13:14:33 +00:00
initial commit jolt
This commit is contained in:
parent
0c2aa5328c
commit
8acf7da95b
1086 changed files with 214612 additions and 4 deletions
|
|
@ -0,0 +1,59 @@
|
|||
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
|
||||
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <TestFramework.h>
|
||||
|
||||
#include <Tests/Constraints/DistanceConstraintTest.h>
|
||||
#include <Jolt/Physics/Collision/Shape/CapsuleShape.h>
|
||||
#include <Jolt/Physics/Constraints/DistanceConstraint.h>
|
||||
#include <Jolt/Physics/Body/BodyCreationSettings.h>
|
||||
#include <Layers.h>
|
||||
|
||||
JPH_IMPLEMENT_RTTI_VIRTUAL(DistanceConstraintTest)
|
||||
{
|
||||
JPH_ADD_BASE_CLASS(DistanceConstraintTest, Test)
|
||||
}
|
||||
|
||||
void DistanceConstraintTest::Initialize()
|
||||
{
|
||||
// Floor
|
||||
CreateFloor();
|
||||
|
||||
float half_cylinder_height = 2.5f;
|
||||
|
||||
// Variation 0: Fixed distance
|
||||
// Variation 1: Min/max distance
|
||||
for (int variation = 0; variation < 2; ++variation)
|
||||
{
|
||||
// Bodies attached through distance constraints
|
||||
Quat rotation = Quat::sRotation(Vec3::sAxisZ(), 0.5f * JPH_PI);
|
||||
RVec3 position(0, 75, 10.0f * variation);
|
||||
Body &top = *mBodyInterface->CreateBody(BodyCreationSettings(new CapsuleShape(half_cylinder_height, 1), position, rotation, EMotionType::Static, Layers::NON_MOVING));
|
||||
mBodyInterface->AddBody(top.GetID(), EActivation::DontActivate);
|
||||
|
||||
Body *prev = ⊤
|
||||
for (int i = 1; i < 15; ++i)
|
||||
{
|
||||
position += Vec3(5.0f + 2.0f * half_cylinder_height, 0, 0);
|
||||
|
||||
Body &segment = *mBodyInterface->CreateBody(BodyCreationSettings(new CapsuleShape(half_cylinder_height, 1), position, rotation, EMotionType::Dynamic, Layers::MOVING));
|
||||
mBodyInterface->AddBody(segment.GetID(), EActivation::Activate);
|
||||
|
||||
DistanceConstraintSettings settings;
|
||||
settings.mPoint1 = position - Vec3(5.0f + half_cylinder_height, 0, 0);
|
||||
settings.mPoint2 = position - Vec3(half_cylinder_height, 0, 0);
|
||||
|
||||
if (variation == 1)
|
||||
{
|
||||
// Default distance is 5, override min/max range
|
||||
settings.mMinDistance = 4.0f;
|
||||
settings.mMaxDistance = 8.0f;
|
||||
}
|
||||
|
||||
mPhysicsSystem->AddConstraint(settings.Create(*prev, segment));
|
||||
|
||||
prev = &segment;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue