I'm developing a game with Unreal Engine and I have a class that represent something (a pawn) that I can move inside the game's level. I'm using Spherical coordinates to move it.
This class has a method to convert its spherical coordinates into a Cartesian location because Unreal uses Cartesian location to place pawns inside the level.
A piece of the class is:
struct SphericalCoordinates
{
float Radius;
float Azimuth;
float Zenit;
};
class MyClass
{
public:
// Convert a spherical coordiantes to cartesian coordiantes.
FVector SphericalToCartesian(SphericalCoordinates Spherical) const;
private:
SphericalCoordinates SphereCoors;
}
The private member SphericalCoordinates SphereCoors
is the one that I'm going to pass to the method SphericalToCartesian
as its parameter. In other words, inside the same class, MyClass
I'm going to call it in this way:
SphericalToCartesian(SphereCoors);
I use the member variable SphereCoors
to store the spherical coordinates of the class instead of compute it every time I need it.
Is it a good idea to pass a member variable as a parameter in a method of the same class?
Of course, I think I can move this method to another class because it only does coordinates transformations, but I think it is a good question to ask if it is a good design to pass a member variable as a parameter in a method of the same class.
Aucun commentaire:
Enregistrer un commentaire