Skip to content

Commit

Permalink
testing cos and sin
Browse files Browse the repository at this point in the history
  • Loading branch information
erincatto committed Aug 27, 2024
1 parent 073a663 commit 6f6f899
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions samples/sample_determinism.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class FallingHinges : public Sample
bodyDef.type = b2_dynamicBody;

bodyDef.position = { x + offset * i, h + 2.0f * h * i };

// this tests the deterministic cosine and sine functions
bodyDef.rotation = b2MakeRot( 0.01f * i - 0.1f );

b2BodyId bodyId = b2CreateBody( m_worldId, &bodyDef );

if ((i & 1) == 0)
Expand Down
14 changes: 8 additions & 6 deletions src/math_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ bool b2Rot_IsValid( b2Rot q )

float b2Sqrt(float x)
{
#if defined( B2_CPU_X64 ) || defined( B2_CPU_WASM )
return _mm_cvtss_f32(_mm_sqrt_ss( _mm_set1_ps(x) ));
#else
float32x4_t v = vdupq_n_f32( x );
return vgetq_lane_f32( vsqrtq_f32( v ), 0 );
#endif
return sqrtf( x );

//#if defined( B2_CPU_X64 ) || defined( B2_CPU_WASM )
// return _mm_cvtss_f32(_mm_sqrt_ss( _mm_set1_ps(x) ));
//#else
// float32x4_t v = vdupq_n_f32( x );
// return vgetq_lane_f32( vsqrtq_f32( v ), 0 );
//#endif
}

float b2Length( b2Vec2 v )
Expand Down

0 comments on commit 6f6f899

Please sign in to comment.