mirror of
https://github.com/antopilo/Nuake.git
synced 2026-01-06 06:09:52 +03:00
More blending code + ShapeCastSphere now works
This commit is contained in:
@@ -145,6 +145,7 @@ namespace Nuake
|
||||
private:
|
||||
std::unordered_map<std::string, BoneTransformTrack> m_Tracks;
|
||||
float m_CurrentTime;
|
||||
float m_PreviousTime;
|
||||
float m_Duration;
|
||||
float m_TicksPerSecond;
|
||||
std::string m_Name;
|
||||
|
||||
@@ -40,6 +40,16 @@ namespace Nuake
|
||||
m_Animations.push_back(std::move(animation));
|
||||
}
|
||||
|
||||
void SkinnedModel::SetCurrentBlendTime(float blendTime)
|
||||
{
|
||||
m_TransitionBlendTime = std::max(blendTime, 0.0f);
|
||||
}
|
||||
|
||||
float SkinnedModel::GetCurrentBlendTime()
|
||||
{
|
||||
return m_TransitionBlendTime;
|
||||
}
|
||||
|
||||
Ref<Nuake::SkeletalAnimation> SkinnedModel::GetCurrentAnimation()
|
||||
{
|
||||
if (m_CurrentAnimation < m_NumAnimation)
|
||||
@@ -51,6 +61,17 @@ namespace Nuake
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Ref<Nuake::SkeletalAnimation> SkinnedModel::GetPreviousAnimation()
|
||||
{
|
||||
if (m_PreviousAnimation < m_NumAnimation)
|
||||
{
|
||||
return m_Animations[m_PreviousAnimation];
|
||||
}
|
||||
|
||||
Logger::Log("Cannot get animation if no animation exists", "skinned model", WARNING);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SkinnedModel::PlayAnimation(uint32_t animationId)
|
||||
{
|
||||
if (animationId >= m_NumAnimation)
|
||||
@@ -61,7 +82,10 @@ namespace Nuake
|
||||
|
||||
GetCurrentAnimation()->SetCurrentTime(0.0f); // Reset previous animation
|
||||
|
||||
m_PreviousAnimation = m_CurrentAnimation;
|
||||
m_CurrentAnimation = animationId;
|
||||
|
||||
m_TransitionBlendTime = 0.6f;
|
||||
}
|
||||
|
||||
json SkinnedModel::Serialize()
|
||||
|
||||
@@ -16,6 +16,8 @@ namespace Nuake
|
||||
SkeletonNode m_SkeletonRoot;
|
||||
|
||||
uint32_t m_CurrentAnimation = 0;
|
||||
uint32_t m_PreviousAnimation = 0;
|
||||
float m_TransitionBlendTime = 0.0f;
|
||||
uint32_t m_NumAnimation = 0;
|
||||
std::vector<Ref<SkeletalAnimation>> m_Animations;
|
||||
|
||||
@@ -39,7 +41,10 @@ namespace Nuake
|
||||
void SetAnimations(const std::vector<Ref<SkeletalAnimation>> animations);
|
||||
void AddAnimation(Ref<SkeletalAnimation> animation);
|
||||
|
||||
float GetCurrentBlendTime();
|
||||
void SetCurrentBlendTime(float time);
|
||||
Ref<SkeletalAnimation> GetCurrentAnimation();
|
||||
Ref<SkeletalAnimation> GetPreviousAnimation();
|
||||
void PlayAnimation(uint32_t animationId);
|
||||
uint32_t GetCurrentAnimationIndex() const { return m_CurrentAnimation; }
|
||||
uint32_t GetAnimationsCount() const { return m_NumAnimation; }
|
||||
|
||||
@@ -97,6 +97,16 @@ namespace Nuake {
|
||||
return ConvertHitsToArray(hits);
|
||||
}
|
||||
|
||||
Coral::Array<float> ShapeCastSphere(float fromX, float fromY, float fromZ, float toX, float toY, float toZ, float radius)
|
||||
{
|
||||
auto sphere = CreateRef<Physics::Sphere>(radius);
|
||||
const Vector3 from = { fromX, fromY, fromZ };
|
||||
const Vector3 to = { toX, toY, toZ };
|
||||
auto hits = PhysicsManager::Get().Shapecast(from, to, sphere);
|
||||
|
||||
return ConvertHitsToArray(hits);
|
||||
}
|
||||
|
||||
Coral::Array<float> ShapeCastBox(float fromX, float fromY, float fromZ, float toX, float toY, float toZ, BoxInternal boxInternal)
|
||||
{
|
||||
auto capsule = CreateRef<Physics::Box>(boxInternal.x, boxInternal.y, boxInternal.z);
|
||||
@@ -143,6 +153,7 @@ namespace Nuake {
|
||||
RegisterMethod("Debug.DrawShapeCylinderIcall", &DrawShapeCylinder);
|
||||
|
||||
RegisterMethod("Physic.RayCastIcall", &Raycast);
|
||||
RegisterMethod("Physic.ShapeCastSphereIcall", &ShapeCastSphere);
|
||||
RegisterMethod("Physic.ShapeCastCapsuleIcall", &ShapeCastCapsule);
|
||||
RegisterMethod("Physic.ShapeCastBoxIcall", &ShapeCastBox);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user