Skip to content

Commit

Permalink
Refactor|Renderer: Renamed obscure 'gzt' parameter
Browse files Browse the repository at this point in the history
VisEntityPose now has methods for calculating the middle point or
middle Z of the entity. The 'gzt' member (global z top) was renamed
to be more understandable 'topZ'.
  • Loading branch information
skyjake committed Aug 12, 2014
1 parent d182c48 commit d39dd52
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion doomsday/client/include/render/rend_main.h
Expand Up @@ -54,7 +54,7 @@ class LightGrid;

#define SHADOW_SURFACE_LUMINOSITY_ATTRIBUTION_MIN (.05f)

DENG_EXTERN_C de::Vector3d vOrigin;
DENG_EXTERN_C de::Vector3d vOrigin; // Y/Z swizzled for drawing
DENG_EXTERN_C float vang, vpitch, yfov;
DENG_EXTERN_C float viewsidex, viewsidey;
DENG_EXTERN_C float fogColor[4];
Expand Down
18 changes: 11 additions & 7 deletions doomsday/client/include/render/vissprite.h
Expand Up @@ -43,9 +43,9 @@ typedef enum {
struct VisEntityPose
{
de::Vector3d origin;
float gzt; // The real center point and global top z for silhouette clipping.
de::Vector3d srvo; // Short-range visual offset.
coord_t distance; // Distance from viewer.
float topZ; ///< Global top Z coordinate (origin Z is the bottom).
de::Vector3d srvo; ///< Short-range visual offset.
coord_t distance; ///< Distance from viewer.
float yaw;
float extraYawAngle;
float yawAngleOffset; ///< @todo We do not need three sets of angles...
Expand All @@ -54,20 +54,20 @@ struct VisEntityPose
float pitchAngleOffset;
float extraScale;
bool viewAligned;
bool mirrored; // If true the model will be mirrored about its Z axis (in model space).
bool mirrored; ///< If true the model will be mirrored about its Z axis (in model space).

VisEntityPose() { de::zap(*this); }

VisEntityPose(de::Vector3d const &origin_,
de::Vector3d const &visOffset,
bool viewAlign_ = false,
float gzt_ = 0,
float topZ_ = 0,
float yaw_ = 0,
float yawAngleOffset_ = 0,
float pitch_ = 0,
float pitchAngleOffset_= 0)
: origin(origin_)
, gzt(gzt_)
, topZ(topZ_)
, srvo(visOffset)
, distance(Rend_PointDist2D(origin_))
, yaw(yaw_)
Expand All @@ -80,6 +80,10 @@ struct VisEntityPose
, viewAligned(viewAlign_)
, mirrored(false)
{}

inline coord_t midZ() const { return (origin.z + topZ) / 2; }

de::Vector3d mid() const { return de::Vector3d(origin.x, origin.y, midZ()); }
};

struct VisEntityLighting
Expand Down Expand Up @@ -158,7 +162,7 @@ typedef struct vispsprite_s {
} sprite;
struct vispsprite_model_s {
BspLeaf *bspLeaf;
coord_t gzt; // global top for silhouette clipping
coord_t topZ; // global top for silhouette clipping
int flags; // for color translation and shadow draw
uint id;
int selector;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/r_main.cpp
Expand Up @@ -208,7 +208,7 @@ static void setupModelParamsForVisPSprite(vissprite_t &vis, vispsprite_t const *
vis.pose.srvo[VX] = spr->data.model.visOff[VX];
vis.pose.srvo[VY] = spr->data.model.visOff[VY];
vis.pose.srvo[VZ] = spr->data.model.visOff[VZ] - spr->data.model.floorClip;
vis.pose.gzt = spr->data.model.gzt;
vis.pose.topZ = spr->data.model.topZ;
vis.pose.distance = -10;
vis.pose.yaw = spr->data.model.yaw;
vis.pose.extraYawAngle = 0;
Expand Down
22 changes: 11 additions & 11 deletions doomsday/client/src/render/r_things.cpp
Expand Up @@ -323,7 +323,7 @@ void R_ProjectSprite(mobj_t *mo)
findMobjZOrigin(mo, floorAdjust, vis);
}

coord_t gzt = vis->pose.origin.z + -tex.origin().y;
coord_t topZ = vis->pose.origin.z + -tex.origin().y; // global z top

// Determine floor clipping.
coord_t floorClip = mo->floorClip;
Expand Down Expand Up @@ -378,7 +378,7 @@ void R_ProjectSprite(mobj_t *mo)
if(mf->testSubFlag(0, MFF_ALIGN_PITCH))
{
viewdata_t const *viewData = R_ViewData(viewPlayer - ddPlayers);
Vector2d delta((vis->pose.origin.z + gzt) / 2 - viewData->current.origin.z, distFromEye);
Vector2d delta(vis->pose.midZ() - viewData->current.origin.z, distFromEye);

pitch = -BANG2DEG(bamsAtan2(delta.x * 10, delta.y * 10));
}
Expand Down Expand Up @@ -438,16 +438,16 @@ void R_ProjectSprite(mobj_t *mo)
if(ms.height() < ceiling.heightSmoothed() - floor.heightSmoothed())
{
// Sprite fits in, adjustment possible?
if(fitTop && gzt > ceiling.heightSmoothed())
gzt = ceiling.heightSmoothed();
if(fitTop && topZ > ceiling.heightSmoothed())
topZ = ceiling.heightSmoothed();

if(floorAdjust && fitBottom && gzt - ms.height() < floor.heightSmoothed())
gzt = floor.heightSmoothed() + ms.height();
if(floorAdjust && fitBottom && topZ - ms.height() < floor.heightSmoothed())
topZ = floor.heightSmoothed() + ms.height();
}
// Adjust by the floor clip.
gzt -= floorClip;
topZ -= floorClip;

Vector3d const origin(vis->pose.origin.x, vis->pose.origin.y, gzt - ms.height() / 2.0f);
Vector3d const origin(vis->pose.origin.x, vis->pose.origin.y, topZ - ms.height() / 2.0f);
Vector4f ambientColor;
uint vLightListIdx = 0;
evaluateLighting(origin, &Mobj_BspLeafAtOrigin(*mo), vis->pose.distance, fullbright,
Expand All @@ -460,7 +460,7 @@ void R_ProjectSprite(mobj_t *mo)
VisEntityPose(origin, visOff, viewAlign),
VisEntityLighting(ambientColor, vLightListIdx),
floor.heightSmoothed(), ceiling.heightSmoothed(),
floorClip, gzt, *mat, matFlipS, matFlipT, blendMode,
floorClip, topZ, *mat, matFlipS, matFlipT, blendMode,
mo->tclass, mo->tmap,
&Mobj_BspLeafAtOrigin(*mo),
floorAdjust, fitTop, fitBottom);
Expand All @@ -480,7 +480,7 @@ void R_ProjectSprite(mobj_t *mo)
// Set up a GL2 model for drawing.
vis->pose = VisEntityPose(vis->pose.origin,
Vector3d(visOff.x, visOff.y, visOff.z - floorClip),
viewAlign, gzt, yaw, 0, pitch, 0);
viewAlign, topZ, yaw, 0, pitch, 0);
vis->light = VisEntityLighting(ambientColor, vLightListIdx);

vis->data.model2.object = mo;
Expand All @@ -493,7 +493,7 @@ void R_ProjectSprite(mobj_t *mo)
VisSprite_SetupModel(vis,
VisEntityPose(vis->pose.origin,
Vector3d(visOff.x, visOff.y, visOff.z - floorClip),
viewAlign, gzt, yaw, 0, pitch, 0),
viewAlign, topZ, yaw, 0, pitch, 0),
VisEntityLighting(ambientColor, vLightListIdx),
mf, nextmf, interp,
mo->thinker.id, mo->selector,
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_model.cpp
Expand Up @@ -811,7 +811,7 @@ static void drawSubmodel(uint number, vissprite_t const &spr)
}

// Coordinates to the center of the model (game coords).
modelCenter = Vector3f(spr.pose.origin[VX], spr.pose.origin[VY], (spr.pose.origin[VZ] + spr.pose.gzt) * 2)
modelCenter = Vector3f(spr.pose.origin[VX], spr.pose.origin[VY], spr.pose.midZ())
+ Vector3d(spr.pose.srvo) + Vector3f(mf->offset.x, mf->offset.z, mf->offset.y);

// Calculate lighting.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_particle.cpp
Expand Up @@ -385,7 +385,7 @@ static void setupModelParamsForParticle(vissprite_t &spr,
// Render the particle as a model.
spr.pose.origin[VX] = origin.x;
spr.pose.origin[VY] = origin.z;
spr.pose.origin[VZ] = spr.pose.gzt = origin.y;
spr.pose.origin[VZ] = spr.pose.topZ = origin.y;
spr.pose.distance = dist;

spr.pose.extraScale = size; // Extra scaling factor.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/sky.cpp
Expand Up @@ -384,7 +384,7 @@ DENG2_PIMPL(Sky)
temp.pose.origin[VX] = vOrigin.x * -minfo.def->coordFactor[VX];
temp.pose.origin[VY] = vOrigin.z * -minfo.def->coordFactor[VZ];
temp.pose.origin[VZ] = vOrigin.y * -minfo.def->coordFactor[VY];
temp.pose.gzt = temp.pose.origin[VZ];
temp.pose.topZ = temp.pose.origin[VZ];
temp.pose.distance = 1;

temp.pose.extraYawAngle = temp.pose.yawAngleOffset = minfo.def->rotate[0];
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/viewports.cpp
Expand Up @@ -801,7 +801,7 @@ static void setupPlayerSprites()
spr->data.model.bspLeaf = &Mobj_BspLeafAtOrigin(*mo);
spr->data.model.flags = 0;
// 32 is the raised weapon height.
spr->data.model.gzt = viewData->current.origin.z;
spr->data.model.topZ = viewData->current.origin.z;
spr->data.model.secFloor = cluster.visFloor().heightSmoothed();
spr->data.model.secCeil = cluster.visCeiling().heightSmoothed();
spr->data.model.pClass = 0;
Expand Down

0 comments on commit d39dd52

Please sign in to comment.