GZDoom Roll Submission

This commit is contained in:
MajorCooke 2016-05-01 14:08:09 -05:00
parent 26acf8e994
commit 980a310755

View file

@ -264,7 +264,8 @@ void GLSprite::Draw(int pass)
&& (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; const bool drawBillboardFacingCamera = gl_billboard_faces_camera;
// [Nash] has +ROLLSPRITE
const bool drawRollSpriteActor = (actor != NULL && actor->renderflags & RF_ROLLSPRITE);
gl_RenderState.Apply(); gl_RenderState.Apply();
FVector3 v1; FVector3 v1;
@ -272,7 +273,15 @@ void GLSprite::Draw(int pass)
FVector3 v3; FVector3 v3;
FVector3 v4; 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 || spritetype == RF_PITCHFLATSPRITE);
// [Nash] check for special sprite drawing modes
if (drawWithXYBillboard || drawBillboardFacingCamera || drawRollSpriteActor || isFlatSprite)
{ {
// Compute center of sprite // Compute center of sprite
float xcenter = (x1 + x2)*0.5; float xcenter = (x1 + x2)*0.5;
@ -284,7 +293,8 @@ void GLSprite::Draw(int pass)
mat.Translate(xcenter, zcenter, ycenter); // move to sprite center 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). // 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, // [CMB] Rotate relative to camera XY position, not just camera direction,
// which is nicer in VR // which is nicer in VR
float xrel = xcenter - GLRenderer->mViewActor->X(); float xrel = xcenter - GLRenderer->mViewActor->X();
@ -296,13 +306,64 @@ void GLSprite::Draw(int pass)
mat.Rotate(0, 1, 0, relAngleDeg); mat.Rotate(0, 1, 0, relAngleDeg);
} }
if (drawWithXYBillboard) // [fgsfds] calculate yaw vectors
float yawvecX = 0, yawvecY = 0, FlatAngle = 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();
FlatAngle = actor->FlatAngle.Degrees;
}
// [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_PITCHFLATSPRITE)
{
float pitchDegrees = actor->Angles.Pitch.Degrees;
mat.Rotate(0, 1, 0, -FlatAngle);
if (drawRollSpriteActor)
{
mat.Rotate(yawvecX, 0, yawvecY, rollDegrees);
}
mat.Rotate(-yawvecY, 0, yawvecX, pitchDegrees);
}
else if (spritetype == RF_FLATSPRITE)
{ // [fgsfds] rotate the sprite so it faces upwards/downwards
mat.Rotate(-yawvecY, 0, yawvecX, -90.f);
if (drawRollSpriteActor)
mat.Rotate(yawvecX, 0, yawvecY, rollDegrees);
}
// [fgsfds] Rotate the sprite about the sight vector (roll)
else if (spritetype == RF_WALLSPRITE)
{
mat.Rotate(0, 1, 0, -FlatAngle);
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 // 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 // triangle strip and with direction orthogonal to where the player is looking
// in the x/y plane. // in the x/y plane.
float angleRad = (270. - GLRenderer->mAngles.Yaw).Radians();
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); // retreat from sprite center mat.Translate(-xcenter, -zcenter, -ycenter); // retreat from sprite center
@ -623,16 +684,25 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal)
bottomclip = rendersector->PortalBlocksMovement(sector_t::floor) ? -LARGE_VALUE : rendersector->GetPortalPlaneZ(sector_t::floor); bottomclip = rendersector->PortalBlocksMovement(sector_t::floor) ? -LARGE_VALUE : rendersector->GetPortalPlaneZ(sector_t::floor);
x = thingpos.X; x = thingpos.X;
z = thingpos.Z - thing->Floorclip;
y = thingpos.Y; y = thingpos.Y;
// [RH] Make floatbobbing a renderer-only effect. DWORD spritetype = thing->renderflags & RF_SPRITETYPEMASK;
if (thing->flags2 & MF2_FLOATBOB)
{
float fz = thing->GetBobOffset(r_TicFracF);
z += fz;
}
switch (spritetype)
{
case RF_FLATSPRITE:
case RF_PITCHFLATSPRITE:
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)); modelframe = gl_FindModelFrame(thing->GetClass(), spritenum, thing->frame, !!(thing->flags & MF_DROPPED));
if (!modelframe) if (!modelframe)
{ {
@ -677,7 +747,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal)
float viewvecX; float viewvecX;
float viewvecY; float viewvecY;
switch (thing->renderflags & RF_SPRITETYPEMASK) switch (spritetype)
{ {
case RF_FACESPRITE: case RF_FACESPRITE:
viewvecX = GLRenderer->mViewVector.X; viewvecX = GLRenderer->mViewVector.X;
@ -689,6 +759,8 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal)
y2 = y + viewvecX*rightfac; y2 = y + viewvecX*rightfac;
break; break;
case RF_FLATSPRITE:
case RF_PITCHFLATSPRITE:
case RF_WALLSPRITE: case RF_WALLSPRITE:
viewvecX = thing->Angles.Yaw.Cos(); viewvecX = thing->Angles.Yaw.Cos();
viewvecY = thing->Angles.Yaw.Sin(); viewvecY = thing->Angles.Yaw.Sin();