Переглянути джерело

Add degree math function, fix scale time when speed < 0.

aster 11 роки тому
батько
коміт
728ef72062

+ 23 - 4
Source/Engine/LuaScript/pkgs/Math/MathDefs.pkg

@@ -1,10 +1,12 @@
 $#include "MathDefs.h"
 
 static const float M_PI;
+static const float M_HALF_PI;
 static const int M_MIN_INT;
 static const int M_MAX_INT;
 static const unsigned M_MIN_UNSIGNED;
 static const unsigned M_MAX_UNSIGNED;
+
 static const float M_EPSILON;
 static const float M_LARGE_EPSILON;
 static const float M_MIN_NEARCLIP;
@@ -22,22 +24,39 @@ enum Intersection
     INSIDE
 };
 
+bool Equals(float lhs, float rhs);
+bool IsNaN(float value);
 float Lerp(float lhs, float rhs, float t);
 float Min(float lhs, float rhs);
 float Max(float lhs, float rhs);
 float Abs(float value);
 float Sign(float value);
+
 float Clamp(float value, float min, float max);
 float SmoothStep(float lhs, float rhs, float t);
-bool Equals(float lhs, float rhs);
-bool IsNaN(float value);
+
+float Sin(float angle);
+float Cos(float angle);
+float Tan(float angle);
+float Asin(float x);
+float Acos(float x);
+float Atan(float x);
+float Atan2(float y, float x);
+
+int Min(int lhs, int rhs);
+int Max(int lhs, int rhs);
+int Abs(int value);
+
+int Clamp @ ClampInt(int value, int min, int max);
+
 bool IsPowerOfTwo(unsigned value);
+
 unsigned NextPowerOfTwo(unsigned value);
-unsigned SDBMHash(unsigned hash, unsigned char c);
 
+unsigned SDBMHash(unsigned hash, unsigned char c);
 float Random();
 float Random(float range);
 float Random(float min, float max);
-float RandomNormal(float meanValue, float variance);
 int Random @ RandomInt(int range);
 int Random @ RandomInt(int min, int max);
+float RandomNormal(float meanValue, float variance);

+ 6 - 3
Source/Engine/Scene/AttributeAnimationInstance.cpp

@@ -57,9 +57,9 @@ bool AttributeAnimationInstance::Update(float timeStep)
 {
     if (!attributeAnimation_)
         return true;
-    
+
     currentTime_ += timeStep * speed_;
-    
+
     if (!attributeAnimation_->IsValid())
         return true;
 
@@ -109,7 +109,10 @@ float AttributeAnimationInstance::CalculateScaledTime(float currentTime, bool& f
     case WM_LOOP:
         {
             float span = endTime - beginTime;
-            return beginTime + fmodf(currentTime - beginTime, span);
+            float time = fmodf(currentTime - beginTime, span);
+            if (time < 0.0f)
+                time += span;
+            return beginTime + time;
         }
 
     case WM_ONCE:

+ 4 - 2
Source/Engine/Urho2D/AnimatedSprite2D.cpp

@@ -37,7 +37,7 @@ namespace Urho3D
 
 extern const char* URHO2D_CATEGORY;
 
-const char* cycleModeNames[] = 
+const char* cycleModeNames[] =
 {
     "Loop",
     "Clamp",
@@ -127,7 +127,7 @@ Animation2D* AnimatedSprite2D::GetAnimation() const
 void AnimatedSprite2D::SetAnimationAttr(ResourceRef value)
 {
     materialUpdatePending_ = true;
-    
+
     ResourceCache* cache = GetSubsystem<ResourceCache>();
     SetAnimation(cache->GetResource<Animation2D>(value.name_));
 }
@@ -164,6 +164,8 @@ void AnimatedSprite2D::HandleScenePostUpdate(StringHash eventType, VariantMap& e
     {
     case CM_LOOP:
         time = fmodf(animationTime_, animationTotalTime_);
+        if (time < 0.0f)
+            time += animationTotalTime_;
         break;
 
     case CM_CLAMP:

+ 2 - 2
Source/Engine/Urho2D/PhysicsWorld2D.cpp

@@ -113,7 +113,7 @@ void PhysicsWorld2D::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
 
 void PhysicsWorld2D::BeginContact(b2Contact* contact)
 {
-    // On receive begin contact when physics steping
+    // Only handle contact event when physics steping
     if (!physicsSteping_)
         return;
 
@@ -127,7 +127,7 @@ void PhysicsWorld2D::BeginContact(b2Contact* contact)
 
 void PhysicsWorld2D::EndContact(b2Contact* contact)
 {
-    // On receive begin contact when physics steping
+    // Only handle contact event when physics steping
     if (!physicsSteping_)
         return;