Game Development Reference
In-Depth Information
</GridRenderComponent>
</Actor>
This particular actor is a Grid, the type that forms the floor and walls of the Teapot
Wars game. It has three components: a TransformComponent that stores its loca-
tion and orientation, a PhysicsComponent that tells the physics engine how it
behaves in the game world, and a GridRenderComponent that tells the rendering
engine how it appears.
Throughout the rest of this chapter, I
ll be referring to components, their definitions,
and how the editor interacts with them to do its work.
Every game editor needs a method to select an actor from the visual display. To do
this requires a special bit of technology called a raycaster, which mathematically cal-
culates which objects in the game world are intersected by a ray given two endpoints.
PickActor() is a function that does exactly this.
'
int PickActor(int *hWndPtrAddress)
{
HWND hWnd = (HWND)hWndPtrAddress;
CPoint ptCursor;
GetCursorPos( &ptCursor );
// Convert the screen coordinates of the mouse cursor into
// coordinates relative to the client window
ScreenToClient( hWnd, &ptCursor );
RayCast rayCast(ptCursor);
EditorGame* pGame = (EditorGame*)g_pApp->m_pGame;
if (!pGame)
return INVALID_ACTOR_ID;
shared_ptr<EditorGameView> gameView = pGame->GetHumanView();
if (!pView)
return INVALID_ACTOR_ID;
// Cast a ray through the scene. The RayCast object contains an array of
// Intersection objects.
pView->GetScene()->Pick(&rayCast);
rayCast.Sort();
// If there are any intersections, get information from the first
// intersection.
if (!rayCast.m_NumIntersections)
{
return INVALID_ACTOR_ID;
}
Search WWH ::




Custom Search