Inside3D!
     

custom chasecam tutorial

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials
View previous topic :: View next topic  
Author Message
frag.machine



Joined: 25 Nov 2006
Posts: 728

PostPosted: Sat Sep 20, 2008 4:33 pm    Post subject: custom chasecam tutorial Reply with quote

This small tutorial is inspired by the excellent ArcadeQuake project shown in the last QExpo. We will add a customizable 3rd. person chasecam, enabled by the original chase_active cvar using the value = 2 (chase_active 1 stills working as usual). I am assuming vanilla GLQuake / WinQuake source code with the almost mandatory chasecam fix tutorial applied as the base code. If you don't want or can't apply this fix, just skip the commented part in the code, although the camera will "see" through the world geometry.

So, let's start opening up the chase.c. At the begin, you will find this:

Code:

cvar_t  chase_back = {"chase_back", "100"};
cvar_t  chase_up = {"chase_up", "16"};
cvar_t  chase_right = {"chase_right", "0"};
cvar_t  chase_active = {"chase_active", "0"};


After it, add these new cvars:

Code:

cvar_t  chase_roll = {"chase_roll", "0"};
cvar_t  chase_yaw = {"chase_yaw", "180"};
cvar_t  chase_pitch = {"chase_pitch", "45"};


These will control the fixed angles of our camera. The default values are set to show the player in the same angle as in a side-scroller game.

Below, we have the Chase_Init () function. We paste this at the end of the code:
Code:

    Cvar_RegisterVariable (&chase_roll);
    Cvar_RegisterVariable (&chase_yaw);
    Cvar_RegisterVariable (&chase_pitch);


Now we can access our new cvars by console.

Finally, we will replace the original Chase_Update function with this:
Code:

void Chase_Update (void)
{
    int     i;
    float   dist;
    vec3_t  forward, up, right;
    vec3_t  dest, stop;

    if ((int)chase_active.value != 2)
    {
        // if can't see player, reset
        AngleVectors (cl.viewangles, forward, right, up);

        // calc exact destination
        for (i=0 ; i<3 ; i++)
            chase_dest[i] = r_refdef.vieworg[i]
            - forward[i]*chase_back.value
            - right[i]*chase_right.value;
        chase_dest[2] = r_refdef.vieworg[2] + chase_up.value;

        // find the spot the player is looking at
        VectorMA (r_refdef.vieworg, 4096, forward, dest);
        TraceLine (r_refdef.vieworg, dest, stop);

        // calculate pitch to look at the same spot from camera
        VectorSubtract (stop, r_refdef.vieworg, stop);
        dist = DotProduct (stop, forward);
        if (dist < 1)
            dist = 1;

        r_refdef.viewangles[PITCH] = -atan(stop[2] / dist) / M_PI * 180;

            TraceLine(r_refdef.vieworg, chase_dest, stop);
        if (Length(stop) != 0)
            VectorCopy(stop, chase_dest);

        // move towards destination
        VectorCopy (chase_dest, r_refdef.vieworg);
    }
    else
    {
        chase_dest[0] = r_refdef.vieworg[0] + chase_back.value;
        chase_dest[1] = r_refdef.vieworg[1] + chase_right.value;
        chase_dest[2] = r_refdef.vieworg[2] + chase_up.value;

        // this is from the chasecam fix - start
        TraceLine (r_refdef.vieworg, chase_dest, stop);     
        if (Length (stop) != 0)
        {
            VectorCopy (stop, chase_dest);
        }
        // this is from the chasecam fix - end

        VectorCopy (chase_dest, r_refdef.vieworg);
        r_refdef.viewangles[ROLL] = chase_roll.value;
        r_refdef.viewangles[YAW] = chase_yaw.value;
        r_refdef.viewangles[PITCH] = chase_pitch.value;
    }
}


And that's it. Compile the code, start a new single player game, bring down the console and experiment with the cvars values, like this:
Code:

chase_active 2
chase_up 64
chase_pitch 45
chase_back 200

_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/
Back to top
View user's profile Send private message Visit poster's website
MeTcHsteekle



Joined: 15 May 2008
Posts: 397
Location: its a secret

PostPosted: Sun Nov 30, 2008 4:42 pm    Post subject: Reply with quote

hehe this one is fun Very Happy
_________________
bah
Back to top
View user's profile Send private message AIM Address
Baker



Joined: 14 Mar 2006
Posts: 1538

PostPosted: Thu Jun 10, 2010 4:42 am    Post subject: Reply with quote

The following settings are one of many sets that work very well ...

(some RPGs use this type of angle)

chase_right -160
chase_back -160
chase_up 200
chase_roll 0
chase_pitch 45
chase_yaw 45

Of course, these work well too ...

(overhead)

chase_right 0
chase_back 0
chase_up 200
chase_roll 0
chase_pitch 90
chase_yaw 0

Secretly this has been of the simplest and most useful tutorials ever. Especially combined with MH and R00k's super-enhanced chasecam fixes.
_________________
Tomorrow Never Dies. I feel this Tomorrow knocking on the door ...
Back to top
View user's profile Send private message
ceriux



Joined: 06 Sep 2008
Posts: 968
Location: Florida, USA

PostPosted: Thu Jun 10, 2010 5:19 pm    Post subject: Reply with quote

omg i wish i was home -.- i want to start my orpg so bad! hopefully only two months left.
_________________
QuakeDB - Quake ModDB Group
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group