Forum

Tutorial: Adding r_viewmodeloffset to GLQuake/WinQuake

Post tutorials on how to do certain tasks within game or engine code here.

Moderator: InsideQC Admins

Tutorial: Adding r_viewmodeloffset to GLQuake/WinQuake

Postby Baker » Wed Nov 19, 2008 5:15 am

Adding r_viewmodeloffset cvar to a Quake engine

The r_viewmodeloffset console variable allows you to position the gun to the left or right by any amount you choose. One example is using r_viewmodeloffset 5 or -5 to shift the gun to the left or right.

This code isn't renderer specific so both GLQuake and WinQuake receive the functionality.

[It can also position higher or farther in front if you want via r_viewmodeloffset "0 5 6". But that doesn't appear to be commonly used.]

Image

Instuctions adding it to stock GLQuake/WinQuake


1. First we need 1 extra addition to mathlib so open mathlib.h

//Add this definition to very bottom
int ParseFloats(char *s, float *f, int *f_size);


2. Now open mathlib.c and add the function itself

Code: Select all
// Add this to the bottom if you prefer.

int ParseFloats(char *s, float *f, int *f_size) {
   int i, argc;

   if (!s || !f || !f_size)
      Sys_Error("ParseFloats() wrong params");

   if (f_size[0] <= 0)
      return (f_size[0] = 0); // array have no size, unusual but no crime

   Cmd_TokenizeString(s);
   argc = min(Cmd_Argc(), f_size[0]);
   
   for(i = 0; i < argc; i++)
      f[i] = Q_atof(Cmd_Argv(i));

   for( ; i < f_size[0]; i++)
      f[i] = 0; // zeroing unused elements

   return (f_size[0] = argc);
}


3. Open view.c - Near the top, find "cvar_t crosshair" (about 60 lines from top).

//Add this after crosshair cvar declaration
// the "true" means it saves to config
cvar_t r_viewmodeloffset = {"r_viewmodeloffset", "0", true};


4. Still in view.c, find void V_CalcRefdef (void) around line 850-860

Locate this rotten code:

Code: Select all
   for (i=0 ; i<3 ; i++)
   {
      view->origin[i] += forward[i]*bob*0.4;
//      view->origin[i] += right[i]*bob*0.4;
//      view->origin[i] += up[i]*bob*0.8;
   }
   view->origin[2] += bob;


Replace it with this ...

Code: Select all
#if 0
   for (i=0 ; i<3 ; i++)
   {
      view->origin[i] += forward[i]*bob*0.4;
//      view->origin[i] += right[i]*bob*0.4;
//      view->origin[i] += up[i]*bob*0.8;
   }
   view->origin[2] += bob;
#endif

#if 1   
   VectorCopy (r_refdef.vieworg, view->origin);
   VectorMA (view->origin, bob * 0.4, forward, view->origin);

   if (r_viewmodeloffset.string[0]) {
      float offset[3];
      int size = sizeof(offset)/sizeof(offset[0]);

      ParseFloats(r_viewmodeloffset.string, offset, &size);
      VectorMA (view->origin,  offset[0], right,   view->origin);
      VectorMA (view->origin, -offset[1], up,      view->origin);
      VectorMA (view->origin,  offset[2], forward, view->origin);
   }
#endif


5. In view.c, find the section where Cvar_RegisterVariable is. Add this one in there as such ...

Code: Select all
Cvar_RegisteVariable (&r_viewmodeloffset);


You are done. Compile + start up Quake and type r_viewmodeloffset 5 in the console. Or type r_viewmodeloffset -5 in the console.

I'm pretty sure this code made it's first appearance in FTEQW back in 2005 maybe.
Last edited by Baker on Fri Nov 21, 2008 1:24 pm, edited 5 times in total.
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby MeTcHsteekle » Thu Nov 20, 2008 3:01 am

I've tried several times and cant seem to get it to work :?:

compiles fine though, but when i type in command in console it has unknown command :?
bah
MeTcHsteekle
 
Posts: 399
Joined: Thu May 15, 2008 10:46 pm
Location: its a secret

Postby Baker » Thu Nov 20, 2008 4:23 am

I've added a step #5, the part where r_viewmodeloffset gets registered was missing.
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby MeTcHsteekle » Thu Nov 20, 2008 4:40 am

yay with a capital V and a [space] it works perfectly

horrra for forward development of eyecandy useless but fun stuff :D

http://www.albinoblacksheep.com/video/developers-remix
bah
MeTcHsteekle
 
Posts: 399
Joined: Thu May 15, 2008 10:46 pm
Location: its a secret

Postby Baker » Thu Nov 20, 2008 11:19 am

MeTcHsteekle wrote:yay with a capital V and a [space] it works perfectly

horrra for forward development of eyecandy useless but fun stuff :D

http://www.albinoblacksheep.com/video/developers-remix


Fixxored.
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Tutorial: Adding r_viewmodeloffset to GLQuake/WinQuake

Postby Team Xlink » Mon Nov 09, 2009 8:09 am

Baker wrote:Adding r_viewmodeloffset cvar to a Quake engine

5. In view.c, find the section where Cvar_RegisterVariable is. Add this one in there as such ...

Code: Select all
Cvar_RegisteVariable (&r_viewmodeloffset);


Your missing the letter "r" on the end of Register, it should look like this:

Code: Select all
Cvar_RegisterVariable (&r_viewmodeloffset);


Thank you for the tutorial, it works like a charm.
Team Xlink
 
Posts: 368
Joined: Thu Jun 25, 2009 4:45 am
Location: Michigan

Postby George30 » Mon Aug 23, 2010 2:24 am

hi..
thanks for that wonderfull tutorial..
btw im new in this site..
thanks a lot and have a nice day..







Make Money Online
George30
 
Posts: 1
Joined: Mon Aug 23, 2010 2:04 am

Postby r00k » Mon Aug 23, 2010 6:51 am

you forgot to post a link to some free movies online site...
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby mankrip » Wed Sep 01, 2010 3:02 am

It doesn't make sense for the weapons to be aligned to the side of the screen while the bolts, the projectiles and the tracelines are aligned to the center of the screen.

In my opinion, the right way to do this is by adjusting the scr_ofsy cvar, since then everything will be aligned correctly without affecting the physics. So, all that's really needed is to make the server allow usage of the scr_ofsy cvar in multiplayer games.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

Postby ceriux » Wed Sep 01, 2010 3:16 pm

if the content maker isnt lazy they could do this all via their modeling program.
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby Spike » Wed Sep 01, 2010 3:45 pm

not everyone likes models off to the side. Also baker forgot the virtical bob, and kept only the forwards bob.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK


Return to Programming Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest