For example,what I want to do is access getter from current class:
class Player
{
private:
Vector3 pos; //Position
public:
Player(char *filename);
~Player();
Vector3 GetPos() { return pos; }
Vector3 GetForward() { return forward; }
};
and access it from here
void CameraWorks::Update()
{
pos =/*player pos + etc2*/;
}
.....so what I want to know is which is the better way to get access to other class function,I know of 3(2?) ways to do it:
1. Add extern Player*player; in player.h and use player->GetPos(); ----->what I'm currently using,but it doesn't sound safe
2. adding Singleton Pattern and do player->getInstance()->GetPos(); -------> this also works but i heard singletons are bad
3. do something like this:
void CameraWorks::Update(Player*player)--------------->don't know if this work tho'
Which one is better design ? or are they all bad and theres other ways to do this?
Edit:
Code above is incomplete one,my current camera is like this
void CameraWorks::Update()
{
type = player->GetCurState();
switch (type)
{
case camType::DEFAULT:
pos = player->GetPlayerPos() - player->GetPlayerForward() * 5 + Vector3(0, 5, 0);
mViewport->Set(pos , player->GetPlayerPos() + Vector3(0,4,0));
break;
case camType::AIM:
pos = player->GetPlayerPos() - player->GetPlayerForward()*4 + Vector3(1, 3.5f, 0);
mViewport->Set(pos, player->GetPlayerPos() + Vector3(2, 3.5f, 0));
break;
case camType::SCRIPTED://for cutscene
break;
}
}
Currently having it only follow players back TPS-style