This commit is contained in:
Christoph Oelckers 2016-07-04 00:45:37 +02:00
commit cc784fff14

View file

@ -269,7 +269,8 @@ void GLSprite::Draw(int pass)
&& (gl_billboard_mode == 1 || (actor && actor->renderflags & RF_FORCEXYBILLBOARD))));
const bool drawBillboardFacingCamera = gl_billboard_faces_camera;
// [Nash] has +ROLLSPRITE
const bool drawRollSpriteActor = (actor != NULL && actor->renderflags & RF_ROLLSPRITE);
gl_RenderState.Apply();
FVector3 v1;
@ -277,7 +278,16 @@ void GLSprite::Draw(int pass)
FVector3 v3;
FVector3 v4;
if (drawWithXYBillboard || drawBillboardFacingCamera)
// [fgsfds] check sprite type mask
DWORD spritetype = (DWORD)-1;
if (actor != NULL) spritetype = actor->renderflags & RF_SPRITETYPEMASK;
// [Nash] is a flat sprite
const bool isFlatSprite = (actor != NULL) && (spritetype == RF_WALLSPRITE || spritetype == RF_FLATSPRITE);
const bool dontFlip = (actor != nullptr) && (actor->renderflags & RF_DONTFLIP);
// [Nash] check for special sprite drawing modes
if (drawWithXYBillboard || drawBillboardFacingCamera || drawRollSpriteActor || isFlatSprite)
{
// Compute center of sprite
float xcenter = (x1 + x2)*0.5;
@ -289,7 +299,8 @@ void GLSprite::Draw(int pass)
mat.Translate(xcenter, zcenter, ycenter); // move to sprite center
// Order of rotations matters. Perform yaw rotation (Y, face camera) before pitch (X, tilt up/down).
if (drawBillboardFacingCamera) {
if (drawBillboardFacingCamera)
{
// [CMB] Rotate relative to camera XY position, not just camera direction,
// which is nicer in VR
float xrel = xcenter - ViewPos.X;
@ -301,13 +312,62 @@ void GLSprite::Draw(int pass)
mat.Rotate(0, 1, 0, relAngleDeg);
}
// [fgsfds] calculate yaw vectors
float yawvecX = 0, yawvecY = 0, rollDegrees = 0;
float angleRad = (270. - GLRenderer->mAngles.Yaw).Radians();
if (actor) rollDegrees = actor->Angles.Roll.Degrees;
if (isFlatSprite)
{
yawvecX = actor->Angles.Yaw.Cos();
yawvecY = actor->Angles.Yaw.Sin();
}
// [MC] This is the only thing that I changed in Nash's submission which
// was constantly applying roll to everything. That was wrong. Flat sprites
// with roll literally look like paper thing space ships trying to swerve.
// However, it does well with wall sprites.
// Also, renamed FLOORSPRITE to FLATSPRITE because that's technically incorrect.
// I plan on adding proper FLOORSPRITEs which can actually curve along sloped
// 3D floors later... if possible.
// Here we need some form of priority in order to work.
if (spritetype == RF_FLATSPRITE)
{
DVector3 diff = actor->Vec3To(GLRenderer->mViewActor);
DAngle angto = diff.Angle();
angto = deltaangle(actor->Angles.Yaw, angto);
float pitchDegrees = actor->Angles.Pitch.Degrees;
bool noFlipSprite = (!dontFlip || (fabs(angto) < 90.));
mat.Rotate(0, 1, 0, (noFlipSprite) ? 0 : 180);
mat.Rotate(-yawvecY, 0, yawvecX, (noFlipSprite) ? -pitchDegrees : pitchDegrees);
if (drawRollSpriteActor)
{
mat.Rotate(yawvecX, 0, yawvecY, (noFlipSprite) ? -rollDegrees : rollDegrees);
}
}
// [fgsfds] Rotate the sprite about the sight vector (roll)
else if (spritetype == RF_WALLSPRITE)
{
mat.Rotate(0, 1, 0, 0);
if (drawRollSpriteActor)
mat.Rotate(yawvecX, 0, yawvecY, rollDegrees);
}
else if (drawRollSpriteActor)
{
if (drawWithXYBillboard)
{
mat.Rotate(-sin(angleRad), 0, cos(angleRad), -GLRenderer->mAngles.Pitch.Degrees);
}
mat.Rotate(cos(angleRad), 0, sin(angleRad), rollDegrees);
}
// apply the transform
else 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.
float angleRad = (270. - GLRenderer->mAngles.Yaw).Radians();
mat.Rotate(-sin(angleRad), 0, cos(angleRad), -GLRenderer->mAngles.Pitch.Degrees);
}
mat.Translate(-xcenter, -zcenter, -ycenter); // retreat from sprite center
@ -630,16 +690,24 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal)
bottomclip = rendersector->PortalBlocksMovement(sector_t::floor) ? -LARGE_VALUE : rendersector->GetPortalPlaneZ(sector_t::floor);
x = thingpos.X;
z = thingpos.Z - thing->Floorclip;
y = thingpos.Y;
DWORD spritetype = thing->renderflags & RF_SPRITETYPEMASK;
switch (spritetype)
{
case RF_FLATSPRITE:
z = thingpos.Z;
default:
z = thingpos.Z - thing->Floorclip;
// [RH] Make floatbobbing a renderer-only effect.
if (thing->flags2 & MF2_FLOATBOB)
{
float fz = thing->GetBobOffset(r_TicFracF);
z += fz;
}
break;
}
modelframe = gl_FindModelFrame(thing->GetClass(), spritenum, thing->frame, !!(thing->flags & MF_DROPPED));
if (!modelframe)
{
@ -684,7 +752,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal)
float viewvecX;
float viewvecY;
switch (thing->renderflags & RF_SPRITETYPEMASK)
switch (spritetype)
{
case RF_FACESPRITE:
viewvecX = GLRenderer->mViewVector.X;
@ -696,6 +764,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal)
y2 = y + viewvecX*rightfac;
break;
case RF_FLATSPRITE:
case RF_WALLSPRITE:
viewvecX = thing->Angles.Yaw.Cos();
viewvecY = thing->Angles.Yaw.Sin();