mirror of
				https://github.com/raysan5/raylib.git
				synced 2025-10-26 12:27:01 +00:00 
			
		
		
		
	REVIEWED: Vector2Angle()
				
					
				
			This commit is contained in:
		| @@ -78,9 +78,7 @@ int main(void) | |||||||
|                 DrawLineEx(v0, v2, 2.0f, RED); |                 DrawLineEx(v0, v2, 2.0f, RED); | ||||||
|                  |                  | ||||||
|                 float startangle = 90 - Vector2LineAngle(v0, v1)*RAD2DEG; |                 float startangle = 90 - Vector2LineAngle(v0, v1)*RAD2DEG; | ||||||
|                 DrawCircleSector(v0, 40.0f, startangle, angle + startangle, 32, Fade(GREEN, 0.6f)); |                 DrawCircleSector(v0, 40.0f, startangle, startangle + angle - 360.0f*(angle > 180.0f), 32, Fade(GREEN, 0.6f)); | ||||||
|                  |  | ||||||
|                 //DrawCircleSector(v0, 40.0f, 90 - Vector2LineAngle(v0, v1)*RAD2DEG, angle, 32, Fade(GREEN, 0.6f)); |  | ||||||
|             } |             } | ||||||
|             else if (angleMode == 1) |             else if (angleMode == 1) | ||||||
|             { |             { | ||||||
|   | |||||||
| @@ -316,15 +316,9 @@ RMAPI float Vector2Angle(Vector2 v1, Vector2 v2) | |||||||
| { | { | ||||||
|     float result = 0.0f; |     float result = 0.0f; | ||||||
|      |      | ||||||
|     float dot = v1.x*v2.x + v1.y*v2.y;              // Dot product |     float dot = v1.x*v2.x + v1.y*v2.y; | ||||||
|     float dotClamp = (dot < -1.0f)? -1.0f : dot;    // Clamp |     float det = v1.x*v2.y - v1.y*v2.x; | ||||||
|     if (dotClamp > 1.0f) dotClamp = 1.0f; |     result = -atan2f(det, dot); | ||||||
|     result = acosf(dotClamp); |  | ||||||
|  |  | ||||||
|     // Alternative implementation, more costly |  | ||||||
|     //float v1Length = sqrtf((v1.x*v1.x) + (v1.y*v1.y)); |  | ||||||
|     //float v2Length = sqrtf((v2.x*v2.x) + (v2.y*v2.y)); |  | ||||||
|     //result = -acosf((v1.x*v2.x + v1.y*v2.y)/(v1Length*v2Length)); |  | ||||||
|      |      | ||||||
|     return result; |     return result; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Ray
					Ray