Game Development Reference
In-Depth Information
public:
TeapotController(shared_ptr<SceneNode> object);
void OnUpdate(const DWORD elapsedMs);
public:
virtual bool VOnPointerMove(const CPoint &mousePos, const int radius)
{
return true;
}
virtual bool VOnPointerButtonDown(const CPoint &mousePos, const int radius,
const std::string &buttonName);
virtual bool VOnPointerButtonUp(const CPoint &mousePos, const int radius,
const std::string &buttonName)
{
return (buttonName ==
PointerLeft
);
}
bool VOnKeyDown(const BYTE c) { m_bKey[c] = true; return true; }
bool VOnKeyUp(const BYTE c) { m_bKey[c] = false; return true; }
};
TeapotController::TeapotController(shared_ptr<SceneNode> object)
: m_object(object)
{
memset(m_bKey, 0x00, sizeof(m_bKey));
}
As you can see from the class definition, really the only methods that have any meat
to them are the response to the left mouse button and OnUpdate() . Keyboard
events are recorded as they happen, which are used in OnUpdate() .
Here
'
s what happens when the player presses the left mouse button:
bool TeapotController::VOnPointerButtonDown(const CPoint &mousePos,
const int radius, const std::string &buttonName)
{
if (buttonName !=
PointerLeft
)
return false;
ActorId actorId = m_object->VGet()->ActorId();
GCC_ASSERT(actorId != INVALID_ACTOR_ID &&
The teapot controller isn
'
t attached to a valid actor!
);
shared_ptr<EvtData_Fire_Weapon> pFireEvent(
GCC_NEW EvtData_Fire_Weapon(actorId));
IEventManager::Get()->VQueueEvent(pFireEvent);
return true;
}
Search WWH ::




Custom Search