mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-14 08:31:23 +00:00
Implement new CVAR gl_billboard_faces_camera, which orients sprites toward camera, rather than along view direction.
# Conflicts: # gz3doom/GZ3DoomRiftMonitor1.bat # src/gl/scene/gl_sprite.cpp # src/gl/scene/gl_stereo3d.cpp
This commit is contained in:
parent
51991ef22d
commit
b320787102
1 changed files with 33 additions and 9 deletions
|
@ -73,6 +73,7 @@ CVAR(Float, gl_sclipthreshold, 10.0, CVAR_ARCHIVE)
|
||||||
CVAR(Float, gl_sclipfactor, 1.8, CVAR_ARCHIVE)
|
CVAR(Float, gl_sclipfactor, 1.8, CVAR_ARCHIVE)
|
||||||
CVAR(Int, gl_particles_style, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // 0 = square, 1 = round, 2 = smooth
|
CVAR(Int, gl_particles_style, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // 0 = square, 1 = round, 2 = smooth
|
||||||
CVAR(Int, gl_billboard_mode, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
CVAR(Int, gl_billboard_mode, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||||
|
CVAR(Bool, gl_billboard_faces_camera, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||||
CVAR(Bool, gl_billboard_particles, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
CVAR(Bool, gl_billboard_particles, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||||
CVAR(Int, gl_enhanced_nv_stealth, 3, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
CVAR(Int, gl_enhanced_nv_stealth, 3, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||||
CUSTOM_CVAR(Int, gl_fuzztype, 0, CVAR_ARCHIVE)
|
CUSTOM_CVAR(Int, gl_fuzztype, 0, CVAR_ARCHIVE)
|
||||||
|
@ -262,6 +263,8 @@ void GLSprite::Draw(int pass)
|
||||||
//&& GLRenderer->mViewActor != NULL
|
//&& GLRenderer->mViewActor != NULL
|
||||||
&& (gl_billboard_mode == 1 || (actor && actor->renderflags & RF_FORCEXYBILLBOARD))));
|
&& (gl_billboard_mode == 1 || (actor && actor->renderflags & RF_FORCEXYBILLBOARD))));
|
||||||
|
|
||||||
|
const bool drawBillboardFacingCamera = gl_billboard_faces_camera;
|
||||||
|
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
|
|
||||||
Vector v1;
|
Vector v1;
|
||||||
|
@ -269,11 +272,9 @@ void GLSprite::Draw(int pass)
|
||||||
Vector v3;
|
Vector v3;
|
||||||
Vector v4;
|
Vector v4;
|
||||||
|
|
||||||
if (drawWithXYBillboard)
|
if (drawWithXYBillboard || drawBillboardFacingCamera)
|
||||||
{
|
{
|
||||||
// Rotate the sprite about the vector starting at the center of the sprite
|
// Compute center of sprite
|
||||||
// triangle strip and with direction orthogonal to where the player is looking
|
|
||||||
// in the x/y plane.
|
|
||||||
float xcenter = (x1 + x2)*0.5;
|
float xcenter = (x1 + x2)*0.5;
|
||||||
float ycenter = (y1 + y2)*0.5;
|
float ycenter = (y1 + y2)*0.5;
|
||||||
float zcenter = (z1 + z2)*0.5;
|
float zcenter = (z1 + z2)*0.5;
|
||||||
|
@ -281,9 +282,33 @@ void GLSprite::Draw(int pass)
|
||||||
|
|
||||||
Matrix3x4 mat;
|
Matrix3x4 mat;
|
||||||
mat.MakeIdentity();
|
mat.MakeIdentity();
|
||||||
|
|
||||||
|
if (drawWithXYBillboard)
|
||||||
|
{
|
||||||
|
// Rotate the sprite about the vector starting at the center of the sprite
|
||||||
|
// triangle strip and with direction orthogonal to where the player is looking
|
||||||
|
// in the x/y plane.
|
||||||
mat.Translate(xcenter, zcenter, ycenter);
|
mat.Translate(xcenter, zcenter, ycenter);
|
||||||
mat.Rotate(-sin(angleRad), 0, cos(angleRad), -GLRenderer->mAngles.Pitch.Degrees);
|
mat.Rotate(-sin(angleRad), 0, cos(angleRad), -GLRenderer->mAngles.Pitch.Degrees);
|
||||||
mat.Translate(-xcenter, -zcenter, -ycenter);
|
mat.Translate(-xcenter, -zcenter, -ycenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drawBillboardFacingCamera) {
|
||||||
|
// [CMB] Rotate relative to camera XY position, not just camera direction,
|
||||||
|
// which is nicer in VR
|
||||||
|
float xrel = xcenter - FIXED2FLOAT(GLRenderer->mViewActor->X());
|
||||||
|
float yrel = ycenter - FIXED2FLOAT(GLRenderer->mViewActor->Y());
|
||||||
|
float zrel = zcenter - FIXED2FLOAT(GLRenderer->mViewActor->Z());
|
||||||
|
|
||||||
|
float absAngleDeg = RAD2DEG(atan2(-yrel, xrel));
|
||||||
|
float counterRotationDeg = 270. - float(GLRenderer->mAngles.Yaw); // counteracts existing sprite rotation
|
||||||
|
float relAngleDeg = counterRotationDeg + absAngleDeg;
|
||||||
|
|
||||||
|
mat.Translate(xcenter, zcenter, ycenter);
|
||||||
|
mat.Rotate(0, 1, 0, relAngleDeg);
|
||||||
|
mat.Translate(-xcenter, -zcenter, -ycenter);
|
||||||
|
}
|
||||||
|
|
||||||
v1 = mat * Vector(x1, z1, y1);
|
v1 = mat * Vector(x1, z1, y1);
|
||||||
v2 = mat * Vector(x2, z1, y2);
|
v2 = mat * Vector(x2, z1, y2);
|
||||||
v3 = mat * Vector(x1, z2, y1);
|
v3 = mat * Vector(x1, z2, y1);
|
||||||
|
@ -291,7 +316,6 @@ void GLSprite::Draw(int pass)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
v1 = Vector(x1, z1, y1);
|
v1 = Vector(x1, z1, y1);
|
||||||
v2 = Vector(x2, z1, y2);
|
v2 = Vector(x2, z1, y2);
|
||||||
v3 = Vector(x1, z2, y1);
|
v3 = Vector(x1, z2, y1);
|
||||||
|
|
Loading…
Reference in a new issue