Talk:Point viewcontrol: Difference between revisions
No edit summary |
(Added info for playing back cameras in demos) |
||
Line 191: | Line 191: | ||
Now, the point_viewcontrol entity will work as it used to, as well as being able to be "stacked." I haven't tested this thoroughly, but it works for me. Please let me know if you have any problems.--[[User:Ndnichols|Ndnichols]] 11:13, 17 Aug 2006 (PDT) | Now, the point_viewcontrol entity will work as it used to, as well as being able to be "stacked." I haven't tested this thoroughly, but it works for me. Please let me know if you have any problems.--[[User:Ndnichols|Ndnichols]] 11:13, 17 Aug 2006 (PDT) | ||
===Record Camera in Demo=== | |||
Currently, if you record a demo where a point_viewcontrol camera is active, when you playback the demo, the camera is not active. This is because CBasePlayer.m_hViewEntity is not networked, and (I believe) the demo system works by recording the packets sent and then playing them back. So, since the m_hViewEntity is never sent, it is never set when playing back the demo. | |||
The obvious fix is to make m_hViewEntity a networked variable. We can change this thusly: | |||
Open player.h, and change line 894 from | |||
EHANDLE m_hViewEntity; | |||
to | |||
CNetworkHandle( CBaseEntity, m_hViewEntity ); | |||
Now, in player.cpp, add the following line: | |||
SendPropEHandle ( SENDINFO( m_hViewEntity)), | |||
near line 6990. Now, serverside CBasePlayer is sending it, but the clientside C_BasePlayer needs to receive it. | |||
So, go to c_baseplayer.h and add: | |||
EHANDLE m_hViewEntity; | |||
as a private variable. (I added it at line 369.) | |||
Also in c_baseplayer.h, add the following public inline member function: | |||
CBaseEntity *GetViewEntity( void ) { return m_hViewEntity; } | |||
(I added it at line 334.) | |||
Now we need to add it to the network receiving table. | |||
In c_baseplayer.cpp, add the line: | |||
RecvPropEHandle ( RECVINFO( m_hViewEntity)), | |||
(I added it at line 198.) | |||
Now, CBasePlayer is transmitting the ViewEntity, and C_BasePlayer is receiving it. Now we just need to ensure that the demo playback is checking for a ViewEntity and responding appropriately. | |||
In view.cpp, right after the | |||
if ( engine->IsPlayingDemo() ) | |||
line at 684, add the following block: | |||
if (pPlayer->GetViewEntity()) | |||
{ | |||
VectorCopy( pPlayer->GetViewEntity()->GetAbsOrigin(), m_View.origin ); | |||
VectorCopy( pPlayer->GetViewEntity()->GetAbsAngles(), m_View.angles ); | |||
} | |||
(Those lines occupy lines 686-690 for me.) | |||
The logic here obviously is that if we are playing back a demo, and pPlayer has a specific view entity, we copy its origins and angles over and the scene is rendered from the camera's point of view as expected. | |||
== Another Point viewcontrol Bug == | == Another Point viewcontrol Bug == | ||
It seems that the point_viewcontrol only moves along paths if you check the "Freeze Player" flag in the "Flags" tab. --[[User:Skucker|Skucker]] 17:16, 28 Oct 2006 (EDT) | It seems that the point_viewcontrol only moves along paths if you check the "Freeze Player" flag in the "Flags" tab. --[[User:Skucker|Skucker]] 17:16, 28 Oct 2006 (EDT) |
Revision as of 11:16, 20 March 2007
Update August 17th, 2006: The Camera-Not-Looking-At-Target bug has been fixed in the SDK release at the beginning of August, 2006. The other two bugs are still present, however, and the fixes below still apply.
Bugs
Camera won't look at target
Update: This bug was corrected in the 8/2006 SDK update.
There is a bug with the camera pointing at the targetted entity. Currently (8/9/06) the camera always points to the origin when a target is set. To fix this, go into the code and open triggers.cpp. Starting at line 2892, the code looks like
if ( m_iAttachmentIndex ) { Vector vecOrigin; m_hTarget->GetBaseAnimating()->GetAttachment( m_iAttachmentIndex, vecOrigin ); VectorAngles( vecOrigin - GetLocalOrigin(), vecGoal ); } else { if ( m_hTarget ) { VectorAngles( m_hTarget->GetLocalOrigin() - GetLocalOrigin(), vecGoal ); } else { // Use the viewcontroller's angles vecGoal = GetAbsAngles(); } }
Change the code to be this:
if ( m_iAttachmentIndex ) { Vector vecOrigin; m_hTarget->GetBaseAnimating()->GetAttachment( m_iAttachmentIndex, vecOrigin ); VectorAngles( vecOrigin - GetAbsOrigin(), vecGoal ); //Changed to use AbsOrigin } else { if ( m_hTarget ) { VectorAngles( m_hTarget->GetAbsOrigin() - GetAbsOrigin(), vecGoal ); //Changed to use AbsOrigin } else { // Use the viewcontroller's angles vecGoal = GetAbsAngles(); } }
--Ndnichols 20:42, 9 Aug 2006 (PDT)
Camera won't follow path correctly
There is an apparent bug with getting the camera to follow the path_controls set up for it. To fix this, go to triggers.cpp and do the following. To the declaration of CTriggerCamera, add the following private member:
Vector m_vecLastPos;
and also declare it with the DEFINE_FIELD macro (I believe this is necessary for the camera to save and load properly.)
DEFINE_FIELD( m_vecLastPos, FIELD_VECTOR),
In CTriggerCamera::Enable() is the code block
if ( m_pPath ) { if ( m_pPath->m_flSpeed != 0 ) m_targetSpeed = m_pPath->m_flSpeed; m_flStopTime += m_pPath->GetDelay(); }
Change this block to be
if ( m_pPath ) { if ( m_pPath->m_flSpeed != 0 ) m_targetSpeed = m_pPath->m_flSpeed; m_flStopTime += m_pPath->GetDelay(); m_vecMoveDir = m_pPath->GetLocalOrigin() - GetLocalOrigin(); m_moveDistance = VectorNormalize( m_vecMoveDir ); m_flStopTime = gpGlobals->curtime + m_pPath->GetDelay(); } else { m_moveDistance = 0; }
Near the end of the Enable() function is the line
m_moveDistance = 0;
Change this to be
m_vecLastPos = GetAbsOrigin();
Now, in the CTrigger::Move() function, change the line that reads
m_moveDistance -= m_flSpeed * gpGlobals->frametime;
to read
m_moveDistance -= VectorNormalize(GetAbsOrigin() - m_vecLastPos);
Finally, add the line
m_vecLastPos = GetAbsOrigin();
to the very end of the Move() function.
(I believe the two bugs were that m_moveDistance wasn't being calculated properly in Enable(), and that the m_flSpeed * gpGlobals->frametime expression reported moving much farther than actually happened. This caused the camera to think it had arrived at the destination camera before it actually had.)
I haven't tested this extensively at all, but it seems to work for me. Please let me know if you have any issues. --Ndnichols 13:09, 10 Aug 2006 (PDT)
Teleport spawnflag on path_corner doesn't do anything for camera
The point_viewcontrol currently ignores the "Teleport to THIS path_corner" spawn flag on a path_corner. To fix, this, go to line 2533 in trigger.cpp (right after the SF_CAMERA_PLAYER_* #defines and add the line
#define SF_PATHCORNER_TELEPORT 2
Now, go to the line that decreases m_moveDistance. It begins with
m_moveDistance -=
near the beginning of CTriggerCamera::Move(). (The actual line depends on whether or not you have changed it as per the above bug-fixes.) Regardless, change the code from
m_moveDistance -= VectorNormalize(GetAbsOrigin() - m_vecLastPos);
to
if (m_pPath->GetSpawnFlags() & SF_PATHCORNER_TELEPORT) { SetAbsOrigin(m_pPath->GetAbsOrigin()); m_moveDistance = -1; //Make sure we enter the conditional below and advance to the next corner. } else { // Subtract movement from the previous frame m_moveDistance -= VectorNormalize(GetAbsOrigin() - m_vecLastPos); }
If you're working on with a .VCD script with camera movements (presumably fired with triggers from the scene) it can be convenient to put a path_corner at the camera's starting position that the camera teleports to. This ensures that if you modify the scene and reload it without exiting HL2, the camera will always start at the correct point (and not wherever it ended up with after the previous completion of the scene.) --Ndnichols 11:18, 12 Aug 2006 (PDT)
ETC.
The camera won't fall path_corners without having a "look at" target set. This is because the think function is only being set if m_hTarget is valid. Just give the camera something to look at, and it should work fine. --Ndnichols 10:11, 12 Aug 2006 (PDT)
Additional Features
These are small bits of code you can add to increase the functionality of the point_viewcontrol entity.
Camera Stack
Currently, if you have viewcontrol A enabled, then enable viewcontrol B, then disable B, the view will be reset to the player (not viewcontrol A.) This makes it difficult to go from one camera to another and back without carefully timed enables and disables. It is easy to change this behaviour, though, and have a viewcontrol "stack". Each successively enabled viewcontrol will add a camera to the "stack", and when the top of the stack is popped (by disabling the top camera), view will return to the viewcontrol that is now at the top of the stack. Please note that if you disable cameras out of order (ie, enable A, enable B, disable A) things will get weird and out-of-sync; so, always make sure to disable the most recently enabled camera. Now, for the implementation. (The gist is that when a camera is enabled, it stores the player's current ViewEntity; when the camera is disabled, then, we set the player's view entity to be the previous view entity, and not automatically the player. If we DO reset it to the player (because the player was the original view entity), we also make sure to re-enable the player's movement, etc.)
Open triggers.cpp, and add the following private declaration to CTriggerCamera:
CBaseEntity* m_pPrevViewEntity;
and make sure to add it with the DEFINE_FIELD macro so it will be saved as well:
DEFINE_FIELD( m_pPrevViewEntity, FIELD_CLASSPTR ),
Now, in the enable function, just before the line where you set the ViewEntity:
((CBasePlayer*)m_hPlayer.Get())->SetViewEntity( this );
add the line
m_pPrevViewEntity = ((CBasePlayer*)m_hPlayer.Get())->GetViewEntity(); // Store the current view entity
Now, in the disable function, we use to always reset the view to the player and restore movement/weapons with this code:
((CBasePlayer*)m_hPlayer.Get())->SetViewEntity( m_hPlayer ); ((CBasePlayer*)m_hPlayer.Get())->EnableControl(TRUE); // Restore the player's viewmodel if ( ((CBasePlayer*)m_hPlayer.Get())->GetActiveWeapon() ) { ((CBasePlayer*)m_hPlayer.Get())->GetActiveWeapon()->RemoveEffects( EF_NODRAW ); }
Remove this block, though, and replace it with the following:
((CBasePlayer*)m_hPlayer.Get())->SetViewEntity( m_pPrevViewEntity ); if (m_pPrevViewEntity == (CBasePlayer*)m_hPlayer.Get()) //If the previous viewentity is the player, reset everything properly { ((CBasePlayer*)m_hPlayer.Get())->EnableControl(TRUE); // Restore the player's viewmodel if ( ((CBasePlayer*)m_hPlayer.Get())->GetActiveWeapon() ) { ((CBasePlayer*)m_hPlayer.Get())->GetActiveWeapon()->RemoveEffects( EF_NODRAW ); } }
Now, the point_viewcontrol entity will work as it used to, as well as being able to be "stacked." I haven't tested this thoroughly, but it works for me. Please let me know if you have any problems.--Ndnichols 11:13, 17 Aug 2006 (PDT)
Record Camera in Demo
Currently, if you record a demo where a point_viewcontrol camera is active, when you playback the demo, the camera is not active. This is because CBasePlayer.m_hViewEntity is not networked, and (I believe) the demo system works by recording the packets sent and then playing them back. So, since the m_hViewEntity is never sent, it is never set when playing back the demo. The obvious fix is to make m_hViewEntity a networked variable. We can change this thusly:
Open player.h, and change line 894 from
EHANDLE m_hViewEntity;
to
CNetworkHandle( CBaseEntity, m_hViewEntity );
Now, in player.cpp, add the following line:
SendPropEHandle ( SENDINFO( m_hViewEntity)),
near line 6990. Now, serverside CBasePlayer is sending it, but the clientside C_BasePlayer needs to receive it. So, go to c_baseplayer.h and add:
EHANDLE m_hViewEntity;
as a private variable. (I added it at line 369.) Also in c_baseplayer.h, add the following public inline member function:
CBaseEntity *GetViewEntity( void ) { return m_hViewEntity; }
(I added it at line 334.) Now we need to add it to the network receiving table. In c_baseplayer.cpp, add the line:
RecvPropEHandle ( RECVINFO( m_hViewEntity)),
(I added it at line 198.)
Now, CBasePlayer is transmitting the ViewEntity, and C_BasePlayer is receiving it. Now we just need to ensure that the demo playback is checking for a ViewEntity and responding appropriately. In view.cpp, right after the
if ( engine->IsPlayingDemo() )
line at 684, add the following block:
if (pPlayer->GetViewEntity()) { VectorCopy( pPlayer->GetViewEntity()->GetAbsOrigin(), m_View.origin ); VectorCopy( pPlayer->GetViewEntity()->GetAbsAngles(), m_View.angles ); }
(Those lines occupy lines 686-690 for me.) The logic here obviously is that if we are playing back a demo, and pPlayer has a specific view entity, we copy its origins and angles over and the scene is rendered from the camera's point of view as expected.
Another Point viewcontrol Bug
It seems that the point_viewcontrol only moves along paths if you check the "Freeze Player" flag in the "Flags" tab. --Skucker 17:16, 28 Oct 2006 (EDT)