Ver código fonte

Merge remote-tracking branch 'origin/sincos'

Lasse Öörni 9 anos atrás
pai
commit
382a7a35c5

+ 2 - 4
Source/Urho3D/Graphics/BillboardSet.cpp

@@ -582,8 +582,7 @@ void BillboardSet::UpdateVertexBuffer(const FrameInfo& frame)
             unsigned color = billboard.color_.ToUInt();
 
             float rotationMatrix[2][2];
-            rotationMatrix[0][0] = Cos(billboard.rotation_);
-            rotationMatrix[0][1] = Sin(billboard.rotation_);
+            SinCos(billboard.rotation_, rotationMatrix[0][1], rotationMatrix[0][0]);
             rotationMatrix[1][0] = -rotationMatrix[0][1];
             rotationMatrix[1][1] = rotationMatrix[0][0];
 
@@ -636,8 +635,7 @@ void BillboardSet::UpdateVertexBuffer(const FrameInfo& frame)
             unsigned color = billboard.color_.ToUInt();
 
             float rot2D[2][2];
-            rot2D[0][0] = Cos(billboard.rotation_);
-            rot2D[0][1] = Sin(billboard.rotation_);
+            SinCos(billboard.rotation_, rot2D[0][1], rot2D[0][0]);
             rot2D[1][0] = -rot2D[0][1];
             rot2D[1][1] = rot2D[0][0];
 

+ 17 - 0
Source/Urho3D/Math/MathDefs.h

@@ -163,6 +163,23 @@ template <class T>
 inline T Atan2(T y, T x) { return M_RADTODEG * atan2(y, x); }
 template <> inline float Atan2<float>(float y, float x) { return M_RADTODEG * atan2f(y, x); }
 
+/// Calculate both sine and cosine, with angle in degrees.
+inline void SinCos(float angle, float& sin, float& cos)
+{
+    float angleRadians = angle * M_DEGTORAD;
+    // glibc can be assumed to have the sincosf() function, while MSVC doesn't
+#ifndef __GNUC__
+    sin = sinf(angleRadians);
+    cos = cosf(angleRadians);
+#else
+    #ifdef __APPLE__
+        __sincosf(angleRadians, &sin, &cos);
+    #else
+        sincosf(angleRadians, &sin, &cos);
+    #endif
+#endif
+}
+
 /// Check whether an unsigned integer is a power of two.
 inline bool IsPowerOfTwo(unsigned value)
 {