📄 cameraobj.cpp
字号:
g_pServerDE->SetObjectUserFlags(m_hObject, dwUsrFlags | USRFLG_SAVEABLE);
return DTRUE;
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CameraObj::Setup
//
// PURPOSE: Handles setup
//
// ----------------------------------------------------------------------- //
DBOOL CameraObj::Setup(DBYTE nType)
{
m_nType = nType;
return DTRUE;
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CameraObj::DisplayRay
//
// PURPOSE: Display a Ray from the Camera
//
// ----------------------------------------------------------------------- //
DBOOL CameraObj::DisplayRay()
{
if (!g_pServerDE) return DFALSE;
// Cast a Ray Forward From the camera (DebugOnly)
if (m_hRay) g_pServerDE->RemoveObject(m_hRay);
ObjectCreateStruct theStruct;
INIT_OBJECTCREATESTRUCT(theStruct);
DVector vPos;
DRotation rRot;
g_pServerDE->GetObjectPos(m_hObject, &vPos);
g_pServerDE->GetObjectRotation(m_hObject, &rRot);
VEC_COPY(theStruct.m_Pos, vPos);
ROT_COPY(theStruct.m_Rotation,rRot);
HCLASS hClass = g_pServerDE->GetClass("CClientCastLineSFX");
CClientCastLineSFX* pLine = DNULL;
if (hClass)
{
pLine = (CClientCastLineSFX*)g_pServerDE->CreateObject(hClass, &theStruct);
if (!pLine) return DFALSE;
}
DVector vColor;
VEC_SET(vColor, 0.0f, 1.0f, 0.0f); // Green Line
pLine->Setup(vColor, vColor, 1.0f, 1.0f);
m_hRay = pLine->m_hObject;
return DTRUE;
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CameraObj::Update
//
// PURPOSE: Handle Update
//
// ----------------------------------------------------------------------- //
DBOOL CameraObj::Update()
{
if (!g_pServerDE) return DFALSE;
g_pServerDE->SetNextUpdate(m_hObject, 0.01f);
// Need to check if Camera has Moved...
// If so, we need to change the Line...
// and Send new camera position
//
// Might have to send a pan up, pan down, pan direction, because of client/server slow down.
// That way all the updates are done on the client.
// if (g_pServerDE->GetVarValueFloat(g_pServerDE->GetGameConVar("DebugCutScene")) == 1.0f)
// {
// DisplayRay();
// }
// If we are linked then check to make sure the Link has not moved...
if (m_hLinkObject)
{
DVector vPos, vMyPos;
VEC_INIT(vPos);
VEC_INIT(vMyPos);
// From this Point
g_pServerDE->GetObjectPos(m_hObject, &vMyPos);
// To this Point
g_pServerDE->GetObjectPos(m_hLinkObject, &vPos);
DVector vF, vU;
VEC_SUB(vF, vPos, vMyPos);
VEC_SET(vU, 0, 1, 0);
DRotation rMyNewRot;
g_pServerDE->AlignRotation(&rMyNewRot, &vF, &vU);
g_pServerDE->SetObjectRotation(m_hObject, &rMyNewRot);
}
// Deactivate if the active time has expired.
if (m_fActiveTime > 0 && g_pServerDE->GetTime() > m_fDeactivateTime)
SetActive(DFALSE);
return DTRUE;
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CameraObj::SetActive
//
// PURPOSE: Activates or deactivates the camera
//
// ----------------------------------------------------------------------- //
void CameraObj::SetActive(DBOOL bActive)
{
if (!g_pServerDE) return;
m_bActive = bActive;
DDWORD dwUsrFlags = g_pServerDE->GetObjectUserFlags(m_hObject);
if (bActive)
{
g_pServerDE->SetObjectUserFlags(m_hObject, dwUsrFlags | USRFLG_VISIBLE);
g_pServerDE->SetNextUpdate(m_hObject, 0.01f);
if (m_fActiveTime > 0)
m_fDeactivateTime = g_pServerDE->GetTime() + m_fActiveTime;
}
else
{
g_pServerDE->SetObjectUserFlags(m_hObject, dwUsrFlags & ~USRFLG_VISIBLE);
g_pServerDE->SetNextUpdate(m_hObject, 0.0f);
m_fDeactivateTime = 0;
}
if (m_bIsListener && bActive)
{
g_hActiveCamera = m_hObject;
}
else // Look for another active camera
{
g_hActiveCamera = DNULL;
DLink* pLink = CameraObj::m_CameraHead.m_pNext;
while(pLink != &CameraObj::m_CameraHead)
{
CameraObj* pCam = (CameraObj*)pLink->m_pData;
if (pCam->IsActive() && pCam->IsListener())
{
g_hActiveCamera = pCam->m_hObject;
break;
}
pLink = pLink->m_pNext;
}
}
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CameraObj::SetLinkObject
//
// PURPOSE: Sets an object for the camera to link to.
//
// ----------------------------------------------------------------------- //
DBOOL CameraObj::SetLinkObject(HOBJECT hLinkObject)
{
if (!g_pServerDE) return DFALSE;
if (hLinkObject)
{
g_pServerDE->CreateInterObjectLink(m_hObject, hLinkObject);
// If active, start doing updates to track the object
if (m_bActive)
g_pServerDE->SetNextUpdate(m_hObject, 0.01f);
}
else
{
if (m_hLinkObject) // Break link?
g_pServerDE->BreakInterObjectLink(m_hObject, m_hLinkObject);
g_pServerDE->SetNextUpdate(m_hObject, 0.0f);
}
m_hLinkObject = hLinkObject;
return DTRUE;
}
// --------------------------------------------------------------------------- //
//
// ROUTINE: VolumeBrush::TriggerMsg()
//
// PURPOSE: Handler for volume brush trigger messages.
//
// --------------------------------------------------------------------------- //
void CameraObj::HandleTrigger(HOBJECT hSender, HSTRING hMsg)
{
if (!g_pServerDE) return;
char* pMsg = g_pServerDE->GetStringData(hMsg);
if (!pMsg) return;
// Turn the camera on
if (_mbsicmp((const unsigned char*)pMsg, (const unsigned char*)"ON") == 0)
{
SetActive(DTRUE);
}
// Turn the camera off
else if (_mbsicmp((const unsigned char*)pMsg, (const unsigned char*)"OFF") == 0)
{
SetActive(DFALSE);
}
// Link to a named object
else if (strnicmp(pMsg, "LINK", 4) == 0)
{
if (_mbstrlen(pMsg) >= 6)
{
// Skip ahead to the name of the object
pMsg += 5;
ObjectList* pList = g_pServerDE->FindNamedObjects(pMsg);
if (pList)
{
ObjectLink* pLink = pList->m_pFirstLink;
if (pLink)
{
SetLinkObject(pLink->m_hObject);
}
g_pServerDE->RelinquishList(pList);
}
}
else
{
SetLinkObject(DNULL);
}
}
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CameraObj::Save
//
// PURPOSE: Save the object
//
// ----------------------------------------------------------------------- //
void CameraObj::Save(HMESSAGEWRITE hWrite, DDWORD dwSaveFlags)
{
CServerDE* pServerDE = GetServerDE();
if (!pServerDE || !hWrite) return;
// Only need to save the data that changes (all the data in the
// special fx message is saved/loaded for us)...
DFLOAT fTime = pServerDE->GetTime();
pServerDE->WriteToMessageByte(hWrite, m_bActive);
pServerDE->WriteToMessageByte(hWrite, m_bStartActive);
pServerDE->WriteToMessageByte(hWrite, m_bIsListener);
pServerDE->WriteToMessageByte(hWrite, m_bPlayerMovement);
pServerDE->WriteToMessageByte(hWrite, m_nType);
pServerDE->WriteToMessageFloat(hWrite, m_fActiveTime);
pServerDE->WriteToMessageFloat(hWrite, m_fDeactivateTime - fTime);
pServerDE->WriteToMessageByte(hWrite, m_bHidePlayer);
pServerDE->WriteToLoadSaveMessageObject(hWrite, m_hLinkObject);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CameraObj::Load
//
// PURPOSE: Load the object
//
// ----------------------------------------------------------------------- //
void CameraObj::Load(HMESSAGEREAD hRead, DDWORD dwLoadFlags)
{
CServerDE* pServerDE = GetServerDE();
if (!pServerDE || !hRead) return;
DFLOAT fTime = pServerDE->GetTime();
m_bActive = pServerDE->ReadFromMessageByte(hRead);
m_bStartActive = pServerDE->ReadFromMessageByte(hRead);
m_bIsListener = pServerDE->ReadFromMessageByte(hRead);
m_bPlayerMovement = pServerDE->ReadFromMessageByte(hRead);
m_nType = pServerDE->ReadFromMessageByte(hRead);
m_fActiveTime = pServerDE->ReadFromMessageFloat(hRead);
m_fDeactivateTime = pServerDE->ReadFromMessageFloat(hRead) + fTime;
m_bHidePlayer = pServerDE->ReadFromMessageByte(hRead);
pServerDE->ReadFromLoadSaveMessageObject(hRead, &m_hLinkObject);
SetActive(m_bActive); // (new) [blg] 02/17/99
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -