0
votes

I'm writing code for mouse picking in 3D space. So far I've made Ray and AABB classes. What I need is a function for Ray-AABB intersecting. I know how to write it and make it work, my question is which class should define said funcion? Should it be a member of Ray or AABB, both, neither? What are the best practices for object oriented approach?

For me it makes the most sense to implement that function as a member of "engine" class, more like a procedure rather than a function. However I want my code to be truly object oriented.

1

1 Answers

1
votes

I would say: neither.

  • Ray: Structure (Members: Start, End)
  • AABB: Structure (Members: Position, Size).

Ray-AABB intersection method could be in a Physics or Intersection class (Depends on your actual context) as static methods (Or functions in a namespace, depends on your coding convention).

Object oriented is fine, but it doesn't mean that everything you create should be a class.

Data oriented is a very good approach (CPU friendly with less cache misses).

EDIT: A good coding rule is to think your things independently, meaning that the AABB implementation shouldn't be dependent on the Ray implementation.