Ocular Engine
MathUtils.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_ENGINE_MATH_UTILS__H__
19 #define __H__OCULAR_ENGINE_MATH_UTILS__H__
20 
21 #include "Vector4.hpp"
22 
23 //------------------------------------------------------------------------------------------
24 
29 namespace Ocular
30 {
35  namespace Math
36  {
44  static Vector2f PointOnCircle(Vector2f const& center, float const radius, float const angle)
45  {
46  const float angleRad = DegreesToRadians(angle);
47 
48  Vector2f result = center;
49 
50  result.x += cosf(angleRad) * radius;
51  result.y += sinf(angleRad) * radius;
52 
53  return result;
54  }
55 
64  static Vector3f PointOnSphere(Vector3f const& center, float const radius, float const angleX, float const angleY)
65  {
66  // https://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates
67 
68  // Where,
69  // r = radius
70  // theta = inclination = radX
71  // phi = azimuth = radY
72 
73  const float radX = DegreesToRadians(angleX);
74  const float radY = DegreesToRadians(angleY);
75 
76  Vector3f result = center;
77 
78  result.x += radius * sinf(radX) * cosf(radY);
79  result.y += radius * sinf(radX) * sinf(radY);
80  result.z += radius * cosf(radX);
81 
82  return result;
83  }
84  }
88 }
93 //------------------------------------------------------------------------------------------
94 
95 #endif#pragma once
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70