Game Development Reference
In-Depth Information
Intersection firstIntersection = rayCast.m_IntersectionArray[0];
return firstIntersection.m_actorId;
}
PickActor() will take the current cursor position and convert the position into
coordinates relative to the editor window. If you remember the Frustum class from
Chapter 14,
the ray will go from the camera location through
the near clipping plane at exactly the mouse position.
The RayCast class is designed with this purpose in mind, and it is a part of the
GameCode4 source code. RayCast::Pick() will fill member variables, indicating
the number of intersections and the actor information of all actors intersected by
the ray, sorted by their distance from the camera. The code grabs the first actor ID
in the list of intersection and returns the actor ID. This will allow users to click on
objects in the world and then find out information about them.
3D Graphics Basics,
Actor Modification Functions
A game editor wouldn
'
t be much of an editor without the ability to create, modify,
and remove actors from the game world. Here are those functions:
void CreateActor( BSTR bstrActorXMLFile )
{
std::string actorResource = ws2s(std::wstring(bstrActorXMLFile,
SysStringLen(bstrActorXMLFile)));
StrongActorPtr pActor = g_pApp->m_pGame->VCreateActor(actorResource, NULL);
if (!pActor)
return INVALID_ACTOR_ID;
// fire an event letting everyone else know that we created a new actor
shared_ptr<EvtData_New_Actor> pNewActorEvent(
GCC_NEW EvtData_New_Actor(pActor->GetId()));
IEventManager::Get()->VQueueEvent(pNewActorEvent);
return pActor->GetId();
}
The CreateActor() function creates actors just as you saw in the previous chapter.
The call to VCreateActor() is made with the name of the actor resource sent from
the editor, and it uses NULL for the override options, which you
ll see more about
later. Once the actor is created, an event is sent to inform all other game systems,
especially the Scene class in the editor
'
'
s view, that a new actor is ready. The actor
ID is returned to the editor.
Next up is ModifyActor() , which the editor calls any time the properties of an
actor are changed.
Search WWH ::




Custom Search