Author Topic: Need Help Coding Chase in-eyes View  (Read 2908 times)

Offline QwazyWabbit

  • Carpal Tunnel Member
  • ******
  • Posts: 1373
    • View Profile
  • Rated:
Need Help Coding Chase in-eyes View
« on: March 13, 2011, 09:52:21 PM »
OK, it looks like no-one has ever solved the problem of player clipping in the in-eyes view mode. The original Q2 code had chasecam from behind the chased player. Setting in-eyes would seem to be just a matter of copying the target player's look-angle into the chasing view but this renders the chaser's POV inside the head of the target player with all the nice artifacts dancing in the view. I've got semi-working chasecam code but I get lost in the vector functions and can't tell when to use gi.trace, VectorMA, VectorNormalize, etc.

Maybe we can put our collective heads together and figure this one out.

Here's what I have so far:

void ChaseCamUpdate(edict_t *ent)
{
   vec3_t o, ownerv, goal;
   edict_t *targ;
   vec3_t forward;
   trace_t trace;
   vec3_t angles;

   assert(ent != NULL);
   targ = ent->client->chase_target;

   VectorCopy(targ->s.origin, ownerv);

   if (ent->client->chase_mode == CHASE_EYES)
   {
      VectorCopy (targ->s.origin, goal);
      goal[2] += targ->viewheight + 6;
   }
   
   if (ent->client->chase_mode == CHASE_THIRDPERSON)
   {
      ownerv[2] += targ->viewheight;

      VectorCopy(targ->client->v_angle, angles);
      if (angles[PITCH] > ent->lclient->cam_maxpitch)
         angles[PITCH] = ent->lclient->cam_maxpitch;
      AngleVectors (angles, forward, NULL, NULL);
      VectorNormalize(forward);
      VectorMA(ownerv, -ent->lclient->cam_distance, forward, o);

      if (o[2] < targ->s.origin[2] + ent->lclient->cam_height)
         o[2] = targ->s.origin[2] + ent->lclient->cam_height;

      // jump animation lifts
      if (!targ->groundentity)
         o[2] += ent->lclient->cam_jump;

      trace = gi.trace(ownerv, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
      VectorCopy(trace.endpos, goal);
      VectorMA(goal, 2, forward, goal);

      // pad for floors and ceilings
      VectorCopy(goal, o);
      o[2] += 6;
      trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
      if (trace.fraction < 1)
      {
         VectorCopy(trace.endpos, goal);
         goal[2] -= 6;
      }

      VectorCopy(goal, o);
      o[2] -= 6;
      trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
      if (trace.fraction < 1)
      {
         VectorCopy(trace.endpos, goal);
         goal[2] += 6;
      }
   }

   //common to all chase modes
 VectorCopy(goal, ent->s.origin);

   if(!ent->lclient->cam_freelook)
   {
      int i;
      ent->client->ps.pmove.pm_type = PM_FREEZE;
      for(i = 0; i < 3; i++)
         ent->client->ps.pmove.delta_angles = ANGLE2SHORT(targ->client->v_angle - ent->client->resp.cmd_angles);

      VectorCopy(targ->client->v_angle, ent->client->ps.viewangles);
      VectorCopy(targ->client->v_angle, ent->client->v_angle);
   }
   else
      ent->client->ps.pmove.pm_type = PM_NORMAL;

   ent->viewheight = 0;
   ent->client->ps.pmove.pm_flags |= PMF_NO_PREDICTION;
   gi.linkentity(ent);
}

I've highlighted the relevant block in yellow, this produces a in-head view, slightly elevated by 6 units, just to make it a little less annoying. I think the solution would be to push the camera POV forward of the targ->s.origin but I don't know how to do that at the moment.

Another solution might be to ID the chased player and then not render him in the chasing client.

Ideas anyone?
« Last Edit: March 13, 2011, 09:54:21 PM by QwazyWabbit »
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus

Offline skuller

  • Newbie
  • *
  • Posts: 13
    • View Profile
  • Rated:
Re: Need Help Coding Chase in-eyes View
« Reply #1 on: March 15, 2011, 05:32:40 AM »
Quote
Another solution might be to ID the chased player and then not render him in the chasing client.

This is how it works in OpenTDM/OpenFFA mods. It requires cooperation from the server to hide player entity from the specified client. Both R1Q2 and Q2PRO servers support this. Game API has been extended so that a new shared field ‘clientNum’ has been added to the beginning of gclient_s struct:
Code: [Select]
struct gclient_s
{
    player_state_t  ps;     // communicated by server to clients
    int             ping;

    // the game dll can add anything it wants after
    // this point in the structure
    int             clientNum;
};

A compatible game mod fills this field with current client POV number: it is equal to client slot number for normal players, and changes for spectators that are chasing other players. Server looks at this field and hides player entity from client frame if necessary. A question remains is how the server would know that game mod is ‘clientNum’ aware and actually fills it with meaningful information, and how the game mod would know if it can safely use ‘clientNum’ for in-eyes chasecam. This is implemented though game/server features cvars. On startup, R1Q2 and Q2PRO servers set a read-only cvar ‘sv_features’ to a bitmask of supported features, among them is GMF_CLIENTNUM feature:
Code: [Select]
#define GMF_CLIENTNUM   1
#define GMF_PROPERINUSE 2
#define GMF_MVDSPEC     4
#define GMF_WANT_ALL_DISCONNECTS 8

In turn, game mod sets a read-only cvar ‘g_features’, exporting a bitmask of features it supports. Server then looks if ‘g_features’ has GMF_CLIENTNUM bit set, and if so, it respects ‘clientNum’ field. Game mod looks if ‘sv_features’ has GMF_CLIENTNUM bit set, and if so, it implements ‘proper’ in-eyes chasecam view by simply copying the playerstate of chased player to spectator playerstate (changing pm_type to PM_FREEZE and setting PMF_NO_PREDICTION bit of course). This is an example of how it can be done:

Code: [Select]
static void UpdateChaseCam( gclient_t *client ) {
    edict_t *ent = client->edict;
    edict_t *targ = client->chase_target;

    client->clientNum = ( targ - g_edicts ) - 1;
    client->ps = targ->client->ps;
    client->ps.fov = client->pers.fov;
    client->ps.pmove.pm_flags |= PMF_NO_PREDICTION;
    client->ps.pmove.pm_type = PM_FREEZE;

    VectorCopy( client->ps.viewangles, ent->s.angles );
    VectorCopy( client->ps.viewangles, ent->client->v_angle );
    VectorScale( client->ps.pmove.origin, 0.125f, ent->s.origin );
    ent->viewheight = targ->viewheight;
}
« Last Edit: March 15, 2011, 05:35:28 AM by skuller »
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus

Offline fdrjk

  • Brobdingnagian Member
  • ***
  • Posts: 4996
  • gotta be above it
    • View Profile
  • Rated:
Re: Need Help Coding Chase in-eyes View
« Reply #2 on: March 15, 2011, 12:00:28 PM »
Yeah. Speccing players over their shoulder in FFA is pretty boring/ hard to watch. It also doesn't help when trying to pick out cheaters.

::)
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus

Offline QwazyWabbit

  • Carpal Tunnel Member
  • ******
  • Posts: 1373
    • View Profile
  • Rated:
Re: Need Help Coding Chase in-eyes View
« Reply #3 on: March 15, 2011, 03:40:39 PM »
Anyone running a server today should be using r1q2 or equivalent simply for the security improvements if for no other reason. I'd like to come up with a generic solution that doesn't need to depend on a particular engine feature if it can be done "generically".

I'm thinking that copying the player origin, then offsetting the spectator position with VectorAdd() ought to be workable. The principle is just to put the spectator POV on the tip of the chasee's unit vector and keep it there so the chasee is behind the spectator and out of view. What this would do in the presence of lag is another story.
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus

Offline Whirlingdervish

  • Super ShortBus Extravaganza
  • Illimitable Sesquipedalian Member
  • *
  • Posts: 6384
    • View Profile
    • The Dervish Depository
  • Rated:
Re: Need Help Coding Chase in-eyes View
« Reply #4 on: March 15, 2011, 05:31:23 PM »
you'd just have to add about slightly more than half a bbox worth of units to get the spec position and that should work.

it won't be _exact_ but it will be much closer to what the player is seeing than the 3rd person or over the shoulder cam.
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus

Offline peewee_RotA

  • Brobdingnagian Member
  • ***
  • Posts: 4152
  • Hi, I'm from the gov'ment and I'm here to help you
    • View Profile
  • Rated:
Re: Need Help Coding Chase in-eyes View
« Reply #5 on: March 15, 2011, 07:10:27 PM »
I'd convert the viewangles into a direction (or verctorma and use the forward), normalize, scale by 10, then add to that to s.origin[2] + 20.. That would put you in front of the model and right about eye level.

Personally i like mods that put the camera inside the head. I think that it looks interesting to see the w_weap move around while playing.
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
GOTO ROTAMODS (rocketgib)
GOTO ROTAMAPS (fireworks)
HappyFriar- q2server.fuzzylogicinc.com
 Tune in to the Tastycast!!!!  http://dna.zeliepa.net

 

El Box de Shoutamente

Last 10 Shouts:

Costigan_Q2

November 11, 2024, 06:41:06 AM
"Stay cozy folks.

Everything is gonna be fine."

There'll be no excuses for having TDS after January 20th, there'll be no excuses AT ALL!!!
 

|iR|Focalor

November 06, 2024, 03:28:50 AM
 

RailWolf

November 05, 2024, 03:13:44 PM
Nice :)

Tom Servo

November 04, 2024, 05:05:24 PM
The Joe Rogan Experience episode 223 that dropped a couple hours ago with Musk, they're talking about Quake lol.

Costigan_Q2

November 04, 2024, 03:37:55 PM
Stay cozy folks.

Everything is gonna be fine.
 

|iR|Focalor

October 31, 2024, 08:56:37 PM

Costigan_Q2

October 17, 2024, 06:31:53 PM
Not activated your account yet?

Activate it now! join in the fun!

Tom Servo

October 11, 2024, 03:35:36 PM
HAHAHAHAHAHA
 

|iR|Focalor

October 10, 2024, 12:19:41 PM
I don't worship the devil. Jesus is Lord, friend. He died for your sins. He will forgive you if you just ask.
 

rikwad

October 09, 2024, 07:57:21 PM
Sorry, I couldn't resist my inner asshole.

Show 50 latest
Welcome, Guest. Please login or register.
November 22, 2024, 12:31:07 PM

Login with username, password and session length