Here is a general forecast for your code:
void function(Sphere s) { Vector3 centre = s.centre; float radius = s.radius;
First, you get much more efficiency by passing Sphere as a const reference. Thus, a new copy is not created, which is probably more expensive than access to membership. So the way:
void function(const Sphere& s) { Vector3 centre = s.centre; float radius = s.radius;
Secondly, you should not directly address class members. It may be easy now, but in a large project it is very difficult to debug. You must use the built-in receivers and setters. Thus, the generated code is the same, but you have one entry point.
Thirdly, this version is not thread safe. What if another thread modifies s ? s.center and s.radius would change, but you would still work with the old values.
Finally, compilers do better optimization than you can, so it's best to leave this to the compiler.
source share