Add skybox console command for dynamic use (blame sock). Additional args for skyroom speed and axis of rotation.

This commit is contained in:
Shpoike 2019-11-02 20:22:54 +00:00
parent e38664c222
commit e259d0db52
6 changed files with 125 additions and 60 deletions

View file

@ -1147,14 +1147,35 @@ void R_RenderView (void)
if (skyroom_enabled && skyroom_visible)
{
vec3_t vieworg;
vec3_t viewang;
VectorCopy(r_refdef.vieworg, vieworg);
VectorCopy(skyroom_origin, r_refdef.vieworg);
VectorCopy(r_refdef.viewangles, viewang);
VectorMA(skyroom_origin, skyroom_origin[3],vieworg, r_refdef.vieworg); //allow a little paralax
if (skyroom_orientation[3])
{
vec3_t axis[3];
float ang = skyroom_orientation[3] * cl.time;
if (!skyroom_orientation[0]&&!skyroom_orientation[1]&&!skyroom_orientation[2])
{
skyroom_orientation[0] = 0;
skyroom_orientation[1] = 0;
skyroom_orientation[2] = 1;
}
VectorNormalize(skyroom_orientation);
RotatePointAroundVector(axis[0], skyroom_orientation, vpn, ang);
RotatePointAroundVector(axis[1], skyroom_orientation, vright, ang);
RotatePointAroundVector(axis[2], skyroom_orientation, vup, ang);
VectorAngles(axis[0], axis[2], r_refdef.viewangles);
}
R_SetupView ();
//note: sky boxes are generally considered an 'infinite' distance away such that you'd not see paralax.
//that's my excuse for not handling r_stereo here, and I'm sticking to it.
R_RenderScene ();
VectorCopy(vieworg, r_refdef.vieworg);
VectorCopy(viewang, r_refdef.viewangles);
skyroom_drawn = true; //disable glClear(GL_COLOR_BUFFER_BIT)
}
//skyroom end

View file

@ -37,7 +37,8 @@ float skymins[2][6], skymaxs[2][6];
qboolean skyroom_drawn;
qboolean skyroom_enabled;
vec3_t skyroom_origin;
vec4_t skyroom_origin;
vec4_t skyroom_orientation;
char skybox_name[1024]; //name of current skybox, or "" if no skybox
@ -276,7 +277,18 @@ void Sky_NewMap (void)
skyroom_origin[1] = atof(com_token);
t = COM_Parse(t);
skyroom_origin[2] = atof(com_token);
t = COM_Parse(t);
skyroom_origin[3] = atof(com_token);
skyroom_enabled = true;
t = COM_Parse(t);
skyroom_orientation[3] = atof(com_token);
t = COM_Parse(t);
skyroom_orientation[0] = atof(com_token);
t = COM_Parse(t);
skyroom_orientation[1] = atof(com_token);
t = COM_Parse(t);
skyroom_orientation[2] = atof(com_token);
}
else if (!strcmp("skyfog", key))
@ -311,6 +323,37 @@ void Sky_SkyCommand_f (void)
}
}
static void Sky_SkyRoomCommand_f (void)
{
switch (Cmd_Argc())
{
case 1:
if (skyroom_enabled)
Con_Printf("\"skyroom\" is \"%f %f %f %f %f %f %f %f\"\n", skyroom_origin[0],skyroom_origin[1],skyroom_origin[2],skyroom_origin[3], skyroom_orientation[3],skyroom_orientation[0],skyroom_orientation[1],skyroom_orientation[2]);
else
Con_Printf("\"skyroom\" is \"\"\n");
break;
case 4:
case 5:
case 6:
Sky_LoadSkyBox(Cmd_Argv(1));
skyroom_enabled = true;
skyroom_origin[0] = atof(Cmd_Argv(1));
skyroom_origin[1] = atof(Cmd_Argv(2));
skyroom_origin[2] = atof(Cmd_Argv(3));
skyroom_origin[3] = atof(Cmd_Argv(4)); //paralax
skyroom_orientation[3] = atof(Cmd_Argv(5)); //speed
skyroom_orientation[0] = atof(Cmd_Argv(6));
skyroom_orientation[1] = atof(Cmd_Argv(7));
skyroom_orientation[2] = atof(Cmd_Argv(8));
break;
case 2:
default:
Con_Printf("usage: skyroom origin_x origin_y origin_z paralax_scale speed axis_x axis_y axis_z\n");
}
}
/*
====================
R_SetSkyfog_f -- ericw
@ -338,6 +381,7 @@ void Sky_Init (void)
Cvar_SetCallback (&r_skyfog, R_SetSkyfog_f);
Cmd_AddCommand ("sky",Sky_SkyCommand_f);
Cmd_AddCommand ("skyroom",Sky_SkyRoomCommand_f);
skybox_name[0] = 0;
for (i=0; i<6; i++)

View file

@ -437,7 +437,8 @@ void Sky_LoadTexture (texture_t *mt);
void Sky_LoadSkyBox (const char *name);
extern qboolean skyroom_drawn; //we draw a skyroom this frame
extern qboolean skyroom_enabled; //we know where the skyroom is ...
extern vec3_t skyroom_origin; //... and it is here.
extern vec4_t skyroom_origin; //... and it is here. [3] is paralax scale
extern vec4_t skyroom_orientation;
void TexMgr_RecalcWarpImageSize (void);

View file

@ -88,6 +88,61 @@ void PerpendicularVector( vec3_t dst, const vec3_t src )
//johnfitz -- removed RotatePointAroundVector() becuase it's no longer used and my compiler fucked it up anyway
//spike -- readded, because it is useful, and my version of gcc has never had a problem with it.
void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees )
{
float m[3][3];
float im[3][3];
float zrot[3][3];
float tmpmat[3][3];
float rot[3][3];
int i;
vec3_t vr, vup, vf;
vf[0] = dir[0];
vf[1] = dir[1];
vf[2] = dir[2];
PerpendicularVector( vr, dir );
CrossProduct( vr, vf, vup );
m[0][0] = vr[0];
m[1][0] = vr[1];
m[2][0] = vr[2];
m[0][1] = vup[0];
m[1][1] = vup[1];
m[2][1] = vup[2];
m[0][2] = vf[0];
m[1][2] = vf[1];
m[2][2] = vf[2];
memcpy( im, m, sizeof( im ) );
im[0][1] = m[1][0];
im[0][2] = m[2][0];
im[1][0] = m[0][1];
im[1][2] = m[2][1];
im[2][0] = m[0][2];
im[2][1] = m[1][2];
memset( zrot, 0, sizeof( zrot ) );
zrot[0][0] = zrot[1][1] = zrot[2][2] = 1.0F;
zrot[0][0] = cos( DEG2RAD( degrees ) );
zrot[0][1] = sin( DEG2RAD( degrees ) );
zrot[1][0] = -sin( DEG2RAD( degrees ) );
zrot[1][1] = cos( DEG2RAD( degrees ) );
R_ConcatRotations( m, zrot, tmpmat );
R_ConcatRotations( tmpmat, im, rot );
for ( i = 0; i < 3; i++ )
{
dst[i] = rot[i][0] * point[0] + rot[i][1] * point[1] + rot[i][2] * point[2];
}
}
/*-----------------------------------------------------------------*/

View file

@ -92,6 +92,7 @@ int Q_log2(int val);
void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3]);
void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4]);
void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
void FloorDivMod (double numer, double denom, int *quotient,
int *rem);

View file

@ -4380,63 +4380,6 @@ static void PScript_EffectSpawned(part_type_t *ptype, vec3_t org, vec3_t axis[3]
}
#ifdef USE_DECALS
void PerpendicularVector( vec3_t dst, const vec3_t src );
#define DEG2RAD( a ) ( (a) * M_PI_DIV_180 )
static void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees )
{
float m[3][3];
float im[3][3];
float zrot[3][3];
float tmpmat[3][3];
float rot[3][3];
int i;
vec3_t vr, vup, vf;
vf[0] = dir[0];
vf[1] = dir[1];
vf[2] = dir[2];
PerpendicularVector( vr, dir );
CrossProduct( vr, vf, vup );
m[0][0] = vr[0];
m[1][0] = vr[1];
m[2][0] = vr[2];
m[0][1] = vup[0];
m[1][1] = vup[1];
m[2][1] = vup[2];
m[0][2] = vf[0];
m[1][2] = vf[1];
m[2][2] = vf[2];
memcpy( im, m, sizeof( im ) );
im[0][1] = m[1][0];
im[0][2] = m[2][0];
im[1][0] = m[0][1];
im[1][2] = m[2][1];
im[2][0] = m[0][2];
im[2][1] = m[1][2];
memset( zrot, 0, sizeof( zrot ) );
zrot[0][0] = zrot[1][1] = zrot[2][2] = 1.0F;
zrot[0][0] = cos( DEG2RAD( degrees ) );
zrot[0][1] = sin( DEG2RAD( degrees ) );
zrot[1][0] = -sin( DEG2RAD( degrees ) );
zrot[1][1] = cos( DEG2RAD( degrees ) );
R_ConcatRotations( m, zrot, tmpmat );
R_ConcatRotations( tmpmat, im, rot );
for ( i = 0; i < 3; i++ )
{
dst[i] = rot[i][0] * point[0] + rot[i][1] * point[1] + rot[i][2] * point[2];
}
}
typedef struct
{
part_type_t *ptype;