Add Capsule collider

This commit is contained in:
2023-03-29 20:57:01 -07:00
parent b77d0526eb
commit 7bfc067e27
4 changed files with 46 additions and 2 deletions

View File

@ -1,6 +1,6 @@
<prefab name="Player" type=""> <prefab name="Player" type="">
<MeshRenderer /> <MeshRenderer />
<CubeMeshHost /> <CapsuleMeshHost />
<SimpleTexturedMaterial ref="material" /> <SimpleTexturedMaterial ref="material" />
<CharacterController2D /> <CharacterController2D />
<BoxCollider min="-1, -1" max="1, 1" /> <BoxCollider min="-1, -1" max="1, 1" />
@ -8,7 +8,7 @@
<child position="0, 0, -0.7"> <child position="0, 0, -0.7">
<MeshRenderer /> <MeshRenderer />
<CubeMeshHost ref="burnout" size="0.4, 0.4, 0.4" /> <CubeMeshHost size="0.4, 0.4, 0.4" />
<SimpleTexturedMaterial color="COLOR_RED" /> <SimpleTexturedMaterial color="COLOR_RED" />
</child> </child>
</prefab> </prefab>

View File

@ -8,5 +8,6 @@ target_sources(${DAWN_TARGET_NAME}
PRIVATE PRIVATE
MeshRenderer.cpp MeshRenderer.cpp
CubeMeshHost.cpp CubeMeshHost.cpp
CapsuleMeshHost.cpp
MeshHost.cpp MeshHost.cpp
) )

View File

@ -0,0 +1,21 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "CapsuleMeshHost.hpp"
using namespace Dawn;
CapsuleMeshHost::CapsuleMeshHost(SceneItem *item) :
MeshHost(item),
radius(0.5f),
height(1.0f)
{
}
void CapsuleMeshHost::onStart() {
useEffect([&]{
CapsuleMesh::create(&this->mesh, radius, height);
}, { &this->radius, &this->height })();
}

View File

@ -0,0 +1,22 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "MeshHost.hpp"
#include "display/mesh/CapsuleMesh.hpp"
namespace Dawn {
class CapsuleMeshHost : public MeshHost {
public:
// @optional
StateProperty<float> radius;
// @optional
StateProperty<float> height;
CapsuleMeshHost(SceneItem *item);
void onStart() override;
};
}