2021-12-10 05:34:04 +00:00
|
|
|
/*
|
|
|
|
r_billboard.c
|
|
|
|
|
|
|
|
Billboard frame setup
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "QF/render.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
|
|
|
|
#include "r_internal.h"
|
|
|
|
|
|
|
|
|
|
|
|
int
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
R_BillboardFrame (transform_t transform, int orientation, vec4f_t cameravec,
|
2022-03-30 14:50:12 +00:00
|
|
|
vec4f_t *bbup, vec4f_t *bbright, vec4f_t *bbfwd)
|
2021-12-10 05:34:04 +00:00
|
|
|
{
|
2022-03-30 14:50:12 +00:00
|
|
|
vec4f_t tvec;
|
2021-12-10 05:34:04 +00:00
|
|
|
float dot;
|
|
|
|
|
|
|
|
switch (orientation) {
|
|
|
|
case SPR_FACING_UPRIGHT:
|
2021-12-10 05:54:18 +00:00
|
|
|
// the billboard has its up vector parallel with world up, and
|
|
|
|
// its right vector perpendicular to cameravec.
|
|
|
|
// Undefined if the camera is too close to the entity.
|
2022-03-30 14:50:12 +00:00
|
|
|
tvec = -normalf (cameravec);
|
2021-12-10 05:54:18 +00:00
|
|
|
dot = tvec[2]; // DotProduct (tvec, world up)
|
2021-12-10 05:34:04 +00:00
|
|
|
if ((dot > 0.999848) || (dot < -0.999848)) // cos(1 degree)
|
|
|
|
return 0;
|
2022-03-30 14:50:12 +00:00
|
|
|
*bbup = (vec4f_t) { 0, 0, 1, 0 };
|
2021-12-10 05:34:04 +00:00
|
|
|
//CrossProduct(bbup, -cameravec, bbright)
|
2022-03-30 14:50:12 +00:00
|
|
|
*bbright = normalf ((vec4f_t) { tvec[1], -tvec[0], 0, 0 });
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
//CrossProduct (bbright, bbup, bbfwd)
|
2022-03-30 14:50:12 +00:00
|
|
|
*bbfwd = (vec4f_t) { -(*bbright)[1], (*bbright)[0], 0, 0};
|
2021-12-10 05:34:04 +00:00
|
|
|
break;
|
|
|
|
case SPR_VP_PARALLEL:
|
2021-12-10 05:54:18 +00:00
|
|
|
// the billboard always has the same orientation as the camera
|
2022-03-30 14:50:12 +00:00
|
|
|
*bbup = r_refdef.frame.up;
|
|
|
|
*bbright = r_refdef.frame.right;
|
|
|
|
*bbfwd = r_refdef.frame.forward;
|
2021-12-10 05:34:04 +00:00
|
|
|
break;
|
|
|
|
case SPR_VP_PARALLEL_UPRIGHT:
|
2021-12-10 05:54:18 +00:00
|
|
|
// the billboar has its up vector parallel with world up, and
|
|
|
|
// its right vector parallel with the view plane.
|
|
|
|
// Undefined if the camera is looking straight up or down.
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
dot = r_refdef.frame.forward[2];
|
2021-12-10 05:54:18 +00:00
|
|
|
if ((dot > 0.999848) || (dot < -0.999848)) // cos(1 degree)
|
2021-12-10 05:34:04 +00:00
|
|
|
return 0;
|
2022-03-30 14:50:12 +00:00
|
|
|
*bbup = (vec4f_t) { 0, 0, 1, 0 };
|
|
|
|
*bbright = normalf ((vec4f_t) {r_refdef.frame.forward[1],
|
|
|
|
-r_refdef.frame.forward[0], 0, 0 });
|
|
|
|
*bbfwd = (vec4f_t) { -(*bbright)[1], (*bbright)[0], 0, 0};
|
2021-12-10 05:34:04 +00:00
|
|
|
break;
|
|
|
|
case SPR_ORIENTED:
|
|
|
|
{
|
2021-12-10 05:54:18 +00:00
|
|
|
// The billboard's orientation is fully specified by the
|
|
|
|
// entity's orientation.
|
2021-12-10 05:34:04 +00:00
|
|
|
mat4f_t mat;
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
Transform_GetWorldMatrix (transform, mat);
|
2022-03-30 14:50:12 +00:00
|
|
|
*bbfwd = mat[0];
|
|
|
|
*bbright = mat[1];
|
|
|
|
*bbup = mat[2];
|
2021-12-10 05:34:04 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SPR_VP_PARALLEL_ORIENTED:
|
|
|
|
{
|
2021-12-10 05:54:18 +00:00
|
|
|
// The billboard is rotated relative to the camera using
|
|
|
|
// the entity's local rotation.
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
mat4f_t entmat;
|
|
|
|
mat4f_t spmat;
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
Transform_GetLocalMatrix (transform, entmat);
|
2021-12-10 05:34:04 +00:00
|
|
|
// FIXME needs proper testing (need to find, make, or fake a
|
|
|
|
// parallel oriented sprite)
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
mmulf (spmat, r_refdef.camera, entmat);
|
2022-03-30 14:50:12 +00:00
|
|
|
*bbfwd = spmat[0];
|
|
|
|
*bbright = spmat[1];
|
|
|
|
*bbup = spmat[2];
|
2021-12-10 05:34:04 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Sys_Error ("R_BillboardFrame: Bad orientation %d", orientation);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|