Re: [hlcoders] 3rd Person Camera woes

2009-06-02 Thread Chris Marshall
On Mon, 1 Jun 2009 12:13:52 -0400
Jorge Rodriguez bs.v...@gmail.com wrote:

First of all, I really appreciate all your help. I'm starting to get
things the way I want them to function. I'm sure any experienced coder
would gasp if they ever saw how I have done things but no matter.

Next I want to fix the flashlight in 3rd person so the projected
texture is coming from the player instead of the screen. Do I need to
edit the vertex shader code to do this? BaseVSShader.cpp?

I suppose it would be sufficient to just attach the
env_projectedtexture to the muzzle of the player's gun perhaps.

 On Mon, Jun 1, 2009 at 1:16 AM, Chris Marshall krizt...@comcast.net
 wrote:
 
  First of all, what is the difference between CAM_Think() and
  CAM_ThirdThink()? I was looking to see which one to override in the
  sdk files but it appears that CAMThirdThink() is never called.
 
 
 Again I don't know about the standard sources but mine are set up so
 that CAM_Think() is called all the time and CAM_ThirdPersonThink() is
 called only if the player is in third person.
 
 Secondly, if I override CAM_Think, I don't see how I can control the
  location of the camera except for distance away from the player. I
  thought about how I could do some trig and set the pitch and yaw to
  move the camera, but then I'd have to rotate the camera itself back
  to look forward. I guess what I'm saying is that I don't see how I
  can rotate the camera relative to itself instead of the player. Do
  I _have_ to use the overrideview function? Can I use trig to set
  the proper location of the camera in CAM_Think and then override
  _only_ the view angles in OverrideView()?
 
 
 Thinking about it again I doubt what I said before. I'll just show
 you what my sources do and let you figure it out, I don't want to
 confuse you.
 
 void CSDKInput::CAM_SetUpCamera( Vector vecOffset, QAngle
 angCamera ) {
 VectorCopy( m_vecCamera, vecOffset );
 VectorCopy( m_angCamera, angCamera );
 }
 
 void ClientModeSDKNormal::OverrideView( CViewSetup *pSetup )
 {
 QAngle camAngles;
 
 // Let the player override the view.
 C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
 if(!pPlayer)
 return;
 
 pPlayer-OverrideView( pSetup );
 
 if( SDKInput()-CAM_IsThirdPerson() )
 {
 SDKInput()-CAM_SetUpCamera( pSetup-origin, pSetup-angles );
 }
 else if (::input-CAM_IsOrthographic())
 {
 pSetup-m_bOrtho = true;
 float w, h;
 ::input-CAM_OrthographicSize( w, h );
 w *= 0.5f;
 h *= 0.5f;
 pSetup-m_OrthoLeft   = -w;
 pSetup-m_OrthoTop= -h;
 pSetup-m_OrthoRight  = w;
 pSetup-m_OrthoBottom = h;
 }
 }
 
 void CSDKInput::CAM_Think( void )
 {
 VPROF(CSDKInput::CAM_Think);
 
 if(!C_BasePlayer::GetLocalPlayer())
 return;
 
 C_SDKPlayer* pPlayer = C_SDKPlayer::GetLocalSDKPlayer();
 
 if (!pPlayer)
 return;
 
 if (pPlayer-IsKnockedOut())
 CAM_ToThirdPerson();
 
 if( !m_fCameraInThirdPerson )
 return;
 
 Vector vecFollowCamera;
 QAngle angFollowCamera;
 Vector vecThirdCamera;
 QAngle angThirdCamera;
 
 m_flCameraWeight = Approach(pPlayer-IsInFollowMode()?1:0,
 m_flCameraWeight, gpGlobals-frametime *
 (1/cam_switchtime.GetFloat()));
 
 if (m_flCameraWeight  0.0f)
 {
 //if (pPlayer-IsInFollowMode()  !m_bWasInFollowMode)
 //CAM_ResetFollowModeVars();
 
 m_bWasInFollowMode = pPlayer-IsInFollowMode();
 
 CAM_FollowModeThink(vecFollowCamera, angFollowCamera);
 }
 
 if (m_flCameraWeight  1.0f)
 {
 CAM_ThirdPersonThink(vecThirdCamera, angThirdCamera);
 }
 
 float flWeight = Gain(m_flCameraWeight, 0.8f);
 
 m_vecCamera = vecFollowCamera * flWeight + vecThirdCamera *
 (1-flWeight);
 m_angCamera = angFollowCamera * flWeight + angThirdCamera *
 (1-flWeight);
 }
 
 The weight is used in order to transfer from follow mode to regular
 third person mode smoothly, and you probably won't need it. Other
 than that if you set m_vecCamera and m_angCamera then it should work
 properly. The method of finding the proper values for those two
 involves just doing some math. Start with the player origin, add a
 little bit of height (vecCamera.z += 10 or whatever) and then do
 something like this:
 
 QAngle angEngine;
 engine-GetViewAngles( angEngine );
 Vector vecEngineForward, vecEngineRight, vecEngineUp;
 AngleVectors(angEngine, vecEngineForward, vecEngineRight,
 vecEngineUp);
 
 vecCamera -= vecEngineForward * 20;
 vecCamera += vecEngineRight * 10;
 
 That's probably the simplest over-the-shoulder camera you can get.
 Probably a good idea to set those numbers to cvars so that you can
 modify them ingame and see what looks best, but that's the general
 idea. As for the angles they are most of the time best set to
 whatever the player's view angles are. This way the camera is always
 behind 

Re: [hlcoders] 3rd Person Camera woes

2009-06-02 Thread Jorge Rodriguez
I don't know about any of that.


-- 
Jorge Vino Rodriguez
___
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders



Re: [hlcoders] 3rd Person Camera woes

2009-06-02 Thread Harry Jeffery
No, you dont need to touch the vertex shader coder.

I believe the existing flashlight can just be tweaked to be mounted
from the gun's muzzle so that you don't need a new
env_projectedtexture.

This may help you: http://forums.steampowered.com/forums/showthread.php?t=844322

2009/6/2 Jorge Rodriguez bs.v...@gmail.com:
 I don't know about any of that.


 --
 Jorge Vino Rodriguez
 ___
 To unsubscribe, edit your list preferences, or view the list archives, please 
 visit:
 http://list.valvesoftware.com/mailman/listinfo/hlcoders



___
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders



Re: [hlcoders] 3rd Person Camera woes

2009-06-01 Thread Jorge Rodriguez
On Mon, Jun 1, 2009 at 1:16 AM, Chris Marshall krizt...@comcast.net wrote:

 First of all, what is the difference between CAM_Think() and
 CAM_ThirdThink()? I was looking to see which one to override in the sdk
 files but it appears that CAMThirdThink() is never called.


Again I don't know about the standard sources but mine are set up so that
CAM_Think() is called all the time and CAM_ThirdPersonThink() is called only
if the player is in third person.

Secondly, if I override CAM_Think, I don't see how I can control the
 location of the camera except for distance away from the player. I
 thought about how I could do some trig and set the pitch and yaw to
 move the camera, but then I'd have to rotate the camera itself back to
 look forward. I guess what I'm saying is that I don't see how I can
 rotate the camera relative to itself instead of the player. Do I _have_
 to use the overrideview function? Can I use trig to set the proper
 location of the camera in CAM_Think and then override _only_ the view
 angles in OverrideView()?


Thinking about it again I doubt what I said before. I'll just show you what
my sources do and let you figure it out, I don't want to confuse you.

void CSDKInput::CAM_SetUpCamera( Vector vecOffset, QAngle angCamera )
{
VectorCopy( m_vecCamera, vecOffset );
VectorCopy( m_angCamera, angCamera );
}

void ClientModeSDKNormal::OverrideView( CViewSetup *pSetup )
{
QAngle camAngles;

// Let the player override the view.
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
if(!pPlayer)
return;

pPlayer-OverrideView( pSetup );

if( SDKInput()-CAM_IsThirdPerson() )
{
SDKInput()-CAM_SetUpCamera( pSetup-origin, pSetup-angles );
}
else if (::input-CAM_IsOrthographic())
{
pSetup-m_bOrtho = true;
float w, h;
::input-CAM_OrthographicSize( w, h );
w *= 0.5f;
h *= 0.5f;
pSetup-m_OrthoLeft   = -w;
pSetup-m_OrthoTop= -h;
pSetup-m_OrthoRight  = w;
pSetup-m_OrthoBottom = h;
}
}

void CSDKInput::CAM_Think( void )
{
VPROF(CSDKInput::CAM_Think);

if(!C_BasePlayer::GetLocalPlayer())
return;

C_SDKPlayer* pPlayer = C_SDKPlayer::GetLocalSDKPlayer();

if (!pPlayer)
return;

if (pPlayer-IsKnockedOut())
CAM_ToThirdPerson();

if( !m_fCameraInThirdPerson )
return;

Vector vecFollowCamera;
QAngle angFollowCamera;
Vector vecThirdCamera;
QAngle angThirdCamera;

m_flCameraWeight = Approach(pPlayer-IsInFollowMode()?1:0,
m_flCameraWeight, gpGlobals-frametime * (1/cam_switchtime.GetFloat()));

if (m_flCameraWeight  0.0f)
{
//if (pPlayer-IsInFollowMode()  !m_bWasInFollowMode)
//CAM_ResetFollowModeVars();

m_bWasInFollowMode = pPlayer-IsInFollowMode();

CAM_FollowModeThink(vecFollowCamera, angFollowCamera);
}

if (m_flCameraWeight  1.0f)
{
CAM_ThirdPersonThink(vecThirdCamera, angThirdCamera);
}

float flWeight = Gain(m_flCameraWeight, 0.8f);

m_vecCamera = vecFollowCamera * flWeight + vecThirdCamera *
(1-flWeight);
m_angCamera = angFollowCamera * flWeight + angThirdCamera *
(1-flWeight);
}

The weight is used in order to transfer from follow mode to regular third
person mode smoothly, and you probably won't need it. Other than that if you
set m_vecCamera and m_angCamera then it should work properly. The method of
finding the proper values for those two involves just doing some math. Start
with the player origin, add a little bit of height (vecCamera.z += 10 or
whatever) and then do something like this:

QAngle angEngine;
engine-GetViewAngles( angEngine );
Vector vecEngineForward, vecEngineRight, vecEngineUp;
AngleVectors(angEngine, vecEngineForward, vecEngineRight,
vecEngineUp);

vecCamera -= vecEngineForward * 20;
vecCamera += vecEngineRight * 10;

That's probably the simplest over-the-shoulder camera you can get. Probably
a good idea to set those numbers to cvars so that you can modify them ingame
and see what looks best, but that's the general idea. As for the angles they
are most of the time best set to whatever the player's view angles are. This
way the camera is always behind and a little to the side of the player, and
facing the same way the player is. Is that what you want?

As for the muzzle flashes, either your player character has contracted EUTS
(Explosive Urinary Tract Syndrome) or you are trying to retrieve an
attachment from the wrong model. You should either instruct your player
character on the dangers of STDs or make sure you are calling
GetAttachment() on the w model and not the v model or player model.

-- 
Jorge Vino Rodriguez
___
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders



Re: [hlcoders] 3rd Person Camera woes

2009-05-31 Thread Chris Marshall
I'm looking at in_camera.cpp and I have a few questions.

First of all, what is the difference between CAM_Think() and
CAM_ThirdThink()? I was looking to see which one to override in the sdk
files but it appears that CAMThirdThink() is never called.

Secondly, if I override CAM_Think, I don't see how I can control the
location of the camera except for distance away from the player. I
thought about how I could do some trig and set the pitch and yaw to
move the camera, but then I'd have to rotate the camera itself back to
look forward. I guess what I'm saying is that I don't see how I can
rotate the camera relative to itself instead of the player. Do I _have_
to use the overrideview function? Can I use trig to set the proper
location of the camera in CAM_Think and then override _only_ the view
angles in OverrideView()?

Secondly, about muzzle flashes. With the weapons from the beta sdk,
they appear to be calling FireObsoleteEvent() in c_baseanimating (its
the only call of that function I can find, on line 3597). Shouldn't it
be calling FireEvent() since the .qc file read AE_NPC_MUZZLEFLASH?

Lastly, I'm trying to replace the old muzzle flashes that it calls with
particle ones I made. So I modified weaponsdk_base.

In ::PrimaryAttack()

Vector vecShootOrigin;
QAngle angShootDir;
GetAttachment( LookupAttachment(muzzle), vecShootOrigin, andShootDir);
DispatchParticleEffect( muzzle_test, vecShootOrigin, andShootDir);

pPlayer-DoMuzzleFlash();

This code works, but the muzzle flash comes out of the player's crotch.
While humorous, its not exactly the desired result. The w_smg_mp5.qc
specifies a muzzle attachment. Any idea whats going wrong?

Thanks a lot to anyone who can lend an inexperienced coder a hand.

On Sat, 30 May 2009 11:10:52 -0400
Jorge Rodriguez bs.v...@gmail.com wrote:

 My mod is far deviated from the standard sources and I don't have
 those lying around, but in my sources the third person camera code is
 in:
 
 void CSDKInput::CAM_ThirdPersonThink()
 
 In your code it may be in CInput and you'd have to override it. The
 file you're looking at should be c_sdk_input.cpp/h In that think
 function is where you can put special rules to place the camera where
 you want it to be depending on the position and orientation of the
 player. Also you can force the player into third person all the time
 by issuing a CAM_ToThirdPerson() command somewhere, or perhaps by
 putting thirdperson in a config file somewhere.
 
 I take it you modified OverrideView(), and you're right, that's not
 the best place to do it. In general you should try to only modify
 SDK-specific files and classes, and OverrideView() isn't quite for
 what you're trying to do with it. You don't set the third person
 camera information there, however you should save off the results of
 CAM_ThirdPersonThink and pass them into OverrideView if the player is
 in third person.
 
 Sorry if this is vague, I'm doing it all from memory! I hope it helps.
 

___
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders



Re: [hlcoders] 3rd Person Camera woes

2009-05-30 Thread Jorge Rodriguez
My mod is far deviated from the standard sources and I don't have those
lying around, but in my sources the third person camera code is in:

void CSDKInput::CAM_ThirdPersonThink()

In your code it may be in CInput and you'd have to override it. The file
you're looking at should be c_sdk_input.cpp/h In that think function is
where you can put special rules to place the camera where you want it to be
depending on the position and orientation of the player. Also you can force
the player into third person all the time by issuing a CAM_ToThirdPerson()
command somewhere, or perhaps by putting thirdperson in a config file
somewhere.

I take it you modified OverrideView(), and you're right, that's not the best
place to do it. In general you should try to only modify SDK-specific files
and classes, and OverrideView() isn't quite for what you're trying to do
with it. You don't set the third person camera information there, however
you should save off the results of CAM_ThirdPersonThink and pass them into
OverrideView if the player is in third person.

Sorry if this is vague, I'm doing it all from memory! I hope it helps.

-- 
Jorge Vino Rodriguez
___
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders