Created
July 18, 2012 20:28
-
-
Save SilverIce/3138687 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Represents abstract environment for objects that inside */ | |
struct IMoveEnvironment | |
{ | |
/** Converts relative object position that environment contains into global position | |
Takes 'outGlobal' parameter as local object position offset and converts it into global position */ | |
virtual void ComputeGlobalPosition(Vector3& outGlobal) = 0; | |
/** Converts global into relative object position */ | |
virtual void ComputeLocalPosition(Vector3& outLocal) = 0; | |
}; | |
struct MovingEntity0 | |
{ | |
IMoveEnvironment* m_Environment; | |
/** Relative position */ | |
Vector3 Position; | |
explicit MovingEntity0() : m_Environment(nullptr) {} | |
/** Attaches entity to environment. | |
Null environment can be passed also. In this case entity will be attached to global coordinate system. | |
Note: environment switch does not changes global position. */ | |
void Environment(IMoveEnvironment* Env) | |
{ | |
if (Env == m_Environment) | |
return; | |
Position = GlobalPosition(); // "move" our entity into global coord system | |
if (Env == nullptr) | |
; // special case: null environment recognized as global coordinate system, nothing to do | |
else | |
Env->ComputeLocalPosition(Position); // convert global into relative position | |
m_Environment = Env; | |
} | |
/** Current environment entity attached. | |
In case environment is null - it means that entity attached to global coordinate system. */ | |
IMoveEnvironment* Environment() const { | |
return m_Environment; | |
} | |
Vector3 GlobalPosition() const | |
{ | |
Vector3 global(Position); | |
if (m_Environment != nullptr) | |
m_Environment->ComputeGlobalPosition(global); | |
return global; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment