Skip to content

Commit

Permalink
Merge branch 'master' into common-episode-definition
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Aug 25, 2014
2 parents c3a2a9e + e013bdc commit 5c4c804
Show file tree
Hide file tree
Showing 19 changed files with 189 additions and 64 deletions.
2 changes: 1 addition & 1 deletion doomsday/build/scripts/buildpackage.py
Expand Up @@ -50,7 +50,7 @@ def descend(path):
# Check for the required metadata file.
foundInfo = False
for full, internal in contents:
if internal.lower() == 'info':
if internal.lower() == 'info' or internal.lower() == 'info.dei':
foundInfo = True
break
if not foundInfo:
Expand Down
9 changes: 6 additions & 3 deletions doomsday/client/include/render/rend_main.h
Expand Up @@ -142,11 +142,14 @@ void Rend_RenderMap(de::Map &map);
float Rend_FieldOfView();

/**
* @param useAngles @c true= Apply viewer angle rotation.
* @param inWorldSpace Apply viewer angles and head position to produce a transformation
* from world space to view space.
*/
void Rend_ModelViewMatrix(bool useAngles = true);
void Rend_ModelViewMatrix(bool inWorldSpace = true);

de::Matrix4f Rend_GetModelViewMatrix(int consoleNum, bool useAngles = true);
de::Matrix4f Rend_GetModelViewMatrix(int consoleNum, bool inWorldSpace = true);

de::Vector3d Rend_EyeOrigin();

#define Rend_PointDist2D(c) (fabs((vOrigin.z-(c)[VY])*viewsidex - (vOrigin.x-(c)[VX])*viewsidey))

Expand Down
10 changes: 10 additions & 0 deletions doomsday/client/include/world/worldsystem.h
Expand Up @@ -34,6 +34,7 @@
#include <de/liblegacy.h>
#include <de/Error>
#include <de/Observers>
#include <de/Vector>
#include <de/System>

#ifdef __CLIENT__
Expand Down Expand Up @@ -152,6 +153,15 @@ class WorldSystem : public de::System
*/
Hand &hand(coord_t *distance = 0) const;

/**
* Determines if a point is in the void.
*
* @param pos Point.
*
* @return @c true, if the point is outside any of the world's maps.
*/
bool isPointInVoid(de::Vector3d const &pos) const;

#endif // __CLIENT__

private:
Expand Down
5 changes: 5 additions & 0 deletions doomsday/client/net.dengine.client.pack/modules/appconfig.de
Expand Up @@ -78,5 +78,10 @@ def setDefaults(d)
# Master server settings.
record d.masterServer
d.masterServer.apiUrl = "www.dengine.net/master.php"

# VR/3D settings.
record d.vr
record d.vr.oculusRift
d.vr.oculusRift.pixelDensity = 1.0
end

6 changes: 3 additions & 3 deletions doomsday/client/src/render/fx/lensflares.cpp
Expand Up @@ -363,18 +363,18 @@ DENG2_PIMPL(LensFlares)
/// @todo If so, it might be time to purge it from the PVS.
if(pvl->seenFrame != thisFrame) continue;

coord_t const distanceSquared = (vOrigin - pvl->light->lightSourceOrigin().xzy()).lengthSquared();
coord_t const distanceSquared = (Rend_EyeOrigin() - pvl->light->lightSourceOrigin().xzy()).lengthSquared();
coord_t const distance = std::sqrt(distanceSquared);

// Light intensity is always quadratic per distance.
float intensity = pvl->light->lightSourceIntensity(vOrigin) / distanceSquared;
float intensity = pvl->light->lightSourceIntensity(Rend_EyeOrigin()) / distanceSquared;

// Projected radius of the light.
float const RADIUS_FACTOR = 128; // Light radius of 1 at this distance produces a visible radius of 1.
/// @todo The factor should be FOV-dependent.
float radius = pvl->light->lightSourceRadius() / distance * RADIUS_FACTOR;

float const dot = (pvl->light->lightSourceOrigin().xzy() - vOrigin).normalize().dot(eyeFront);
float const dot = (pvl->light->lightSourceOrigin().xzy() - Rend_EyeOrigin()).normalize().dot(eyeFront);
float const angle = radianToDegree(std::acos(dot));

//qDebug() << "i:" << intensity << "r:" << radius << "IR:" << radius*intensity;
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/src/render/modelrenderer.cpp
Expand Up @@ -208,6 +208,7 @@ DENG2_PIMPL(ModelRenderer)
auto mats = asset.subrecord(DEF_MATERIAL).subrecords();
DENG2_FOR_EACH_CONST(Record::Subrecords, mat, mats)
{
handleMaterialTexture(model, mat.key(), *mat.value(), "diffuseMap", ModelDrawable::Diffuse);
handleMaterialTexture(model, mat.key(), *mat.value(), "normalMap", ModelDrawable::Normals);
handleMaterialTexture(model, mat.key(), *mat.value(), "heightMap", ModelDrawable::Height);
handleMaterialTexture(model, mat.key(), *mat.value(), "specularMap", ModelDrawable::Specular);
Expand Down
10 changes: 5 additions & 5 deletions doomsday/client/src/render/rend_clip.cpp
Expand Up @@ -763,7 +763,7 @@ int C_SafeAddRange(binangle_t startAngle, binangle_t endAngle)

void C_AddRangeFromViewRelPoints(Vector2d const &from, Vector2d const &to)
{
Vector2d const eyeOrigin(vOrigin.x, vOrigin.z);
Vector2d const eyeOrigin(Rend_EyeOrigin().x, Rend_EyeOrigin().z);
C_SafeAddRange(pointToAngle(to - eyeOrigin),
pointToAngle(from - eyeOrigin));
}
Expand Down Expand Up @@ -803,7 +803,7 @@ void C_AddViewRelOcclusion(Vector2d const &from, Vector2d const &to, coord_t hei

// Calculate the occlusion plane normal.
// We'll use the game's coordinate system (left-handed, but Y and Z are swapped).
Vector3d const eyeOrigin = vOrigin.xzy();
Vector3d const eyeOrigin = Rend_EyeOrigin().xzy();
Vector3d eyeToV1 = Vector3d(from, height) - eyeOrigin;
Vector3d eyeToV2 = Vector3d(to, height) - eyeOrigin;

Expand Down Expand Up @@ -863,7 +863,7 @@ int C_IsPointVisible(Vector3d const &point)
{
if(devNoCulling) return true;

Vector3d const eyeOrigin = vOrigin.xzy();
Vector3d const eyeOrigin = Rend_EyeOrigin().xzy();
Vector3d const viewRelPoint = point - eyeOrigin;

binangle_t const angle = pointToAngle(viewRelPoint);
Expand Down Expand Up @@ -906,7 +906,7 @@ int C_CheckRangeFromViewRelPoints(Vector2d const &from, Vector2d const &to)
{
if(devNoCulling) return true;

Vector2d const eyeOrigin(vOrigin.x, vOrigin.z);
Vector2d const eyeOrigin(Rend_EyeOrigin().x, Rend_EyeOrigin().z);
return C_SafeCheckRange(pointToAngle(to - eyeOrigin) - BANG_45/90,
pointToAngle(from - eyeOrigin) + BANG_45/90);
}
Expand Down Expand Up @@ -942,7 +942,7 @@ int C_IsPolyVisible(Face const &poly)
}

// Find angles to all corners.
Vector2d const eyeOrigin(vOrigin.x, vOrigin.z);
Vector2d const eyeOrigin(Rend_EyeOrigin().x, Rend_EyeOrigin().z);
int n = 0;
HEdge const *hedge = poly.hedge();
do
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/render/rend_fakeradio.cpp
Expand Up @@ -1320,7 +1320,7 @@ void Rend_RadioBspLeafEdges(BspLeaf const &bspLeaf)
// Any need to continue?
if(shadowDark < .0001f) return;

Vector3f const eyeToSurface(Vector2d(vOrigin.x, vOrigin.z) - bspLeaf.poly().center());
Vector3f const eyeToSurface(Vector2d(Rend_EyeOrigin().x, Rend_EyeOrigin().z) - bspLeaf.poly().center());

// We need to check all the shadow lines linked to this BspLeaf for
// the purpose of fakeradio shadowing.
Expand All @@ -1336,7 +1336,7 @@ void Rend_RadioBspLeafEdges(BspLeaf const &bspLeaf)
for(int pln = 0; pln < cluster.visPlaneCount(); ++pln)
{
Plane const &plane = cluster.visPlane(pln);
if(Vector3f(eyeToSurface, vOrigin.y - plane.heightSmoothed())
if(Vector3f(eyeToSurface, Rend_EyeOrigin().y - plane.heightSmoothed())
.dot(plane.surface().normal()) >= 0)
{
writeShadowSection(pln, *side, shadowDark);
Expand All @@ -1354,7 +1354,7 @@ static void drawPoint(Vector3d const &point, int radius, float const color[4])
Vector3d const leftOff = viewData->upVec + viewData->sideVec;
Vector3d const rightOff = viewData->upVec - viewData->sideVec;

//Vector3d const viewToCenter = point - vOrigin;
//Vector3d const viewToCenter = point - Rend_EyeOrigin();
//float scale = float(viewToCenter.dot(viewData->frontVec)) /
// viewData->frontVec.dot(viewData->frontVec);

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_halo.cpp
Expand Up @@ -156,7 +156,7 @@ bool H_RenderHalo(Vector3d const &origin, float size, DGLuint tex,

// Calculate the mirrored position.
// Project viewtocenter vector onto viewSideVec.
Vector3f const viewToCenter = center - vOrigin;
Vector3f const viewToCenter = center - Rend_EyeOrigin();

// Calculate the 'mirror' vector.
float const scale = viewToCenter.dot(viewData->frontVec)
Expand Down
94 changes: 61 additions & 33 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -508,19 +508,45 @@ float Rend_FieldOfView()
}
}

Matrix4f Rend_GetModelViewMatrix(int consoleNum, bool useAngles)
static Vector3d vEyeOrigin;

Vector3d Rend_EyeOrigin()
{
return vEyeOrigin;
}

Matrix4f Rend_GetModelViewMatrix(int consoleNum, bool inWorldSpace)
{
viewdata_t const *viewData = R_ViewData(consoleNum);

float bodyAngle = viewData->current.angleWithoutHeadTracking() / (float) ANGLE_MAX * 360 - 90;

/// @todo vOrigin et al. shouldn't be changed in a getter function. -jk

vOrigin = viewData->current.origin.xzy();
vang = viewData->current.angle() / (float) ANGLE_MAX * 360 - 90; // head tracking included
vpitch = viewData->current.pitch * 85.0 / 110.0;

vEyeOrigin = vOrigin;

OculusRift &ovr = vrCfg().oculusRift();
bool const applyHead = (vrCfg().mode() == VRConfig::OculusRift && ovr.isReady());

Matrix4f modelView;
Matrix4f headOrientation;
Matrix4f headOffset;

if(useAngles)
if(applyHead)
{
Vector3f headPos = swizzle(Matrix4f::rotate(bodyAngle, Vector3f(0, 1, 0)) *
ovr.headPosition() * vrCfg().mapUnitsPerMeter(),
AxisNegX, AxisNegY, AxisZ);
headOffset = Matrix4f::translate(headPos);

vEyeOrigin -= headPos;
}

if(inWorldSpace)
{
float yaw = vang;
float pitch = vpitch;
Expand All @@ -534,43 +560,45 @@ Matrix4f Rend_GetModelViewMatrix(int consoleNum, bool useAngles)
* these values and is syncing with them independently (however, game has more
* latency).
*/
OculusRift &ovr = vrCfg().oculusRift();

if((vrCfg().mode() == VRConfig::OculusRift) && ovr.isReady())
if(applyHead)
{
Vector3f const pry = ovr.headOrientation();

// Use angles directly from the Rift for best response.
Vector3f const pry = ovr.headOrientation();
roll = -radianToDegree(pry[1]);
pitch = radianToDegree(pry[0]);
}

modelView = Matrix4f::rotate(roll, Vector3f(0, 0, 1)) *
Matrix4f::rotate(pitch, Vector3f(1, 0, 0)) *
Matrix4f::rotate(yaw, Vector3f(0, 1, 0)) *
Matrix4f::translate(swizzle(Matrix4f::rotate(bodyAngle, Vector3f(0, 1, 0)) *
(ovr.headPosition() * vrCfg().mapUnitsPerMeter()),
AxisNegX, AxisNegY, AxisZ));
headOrientation = Matrix4f::rotate(roll, Vector3f(0, 0, 1)) *
Matrix4f::rotate(pitch, Vector3f(1, 0, 0)) *
Matrix4f::rotate(yaw, Vector3f(0, 1, 0));

modelView = headOrientation * headOffset;
}

if(applyHead)
{
// Apply the current eye offset to the eye origin.
vEyeOrigin -= headOrientation.inverse() * (ovr.eyeOffset() * vrCfg().mapUnitsPerMeter());
}

return (modelView *
Matrix4f::scale(Vector3f(1.0f, 1.2f, 1.0f)) * // This is the aspect correction.
Matrix4f::translate(-vOrigin));
}

void Rend_ModelViewMatrix(bool useAngles)
void Rend_ModelViewMatrix(bool inWorldSpace)
{
DENG_ASSERT_IN_MAIN_THREAD();
DENG_ASSERT_GL_CONTEXT_ACTIVE();

glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(Rend_GetModelViewMatrix(viewPlayer - ddPlayers, useAngles).values());
glLoadMatrixf(Rend_GetModelViewMatrix(viewPlayer - ddPlayers, inWorldSpace).values());
}

static inline double viewFacingDot(Vector2d const &v1, Vector2d const &v2)
{
// The dot product.
return (v1.y - v2.y) * (v1.x - vOrigin.x) + (v2.x - v1.x) * (v1.y - vOrigin.z);
return (v1.y - v2.y) * (v1.x - Rend_EyeOrigin().x) + (v2.x - v1.x) * (v1.y - Rend_EyeOrigin().z);
}

float Rend_ExtraLightDelta()
Expand Down Expand Up @@ -929,8 +957,8 @@ static void quadShinyTexCoords(Vector2f *tc, Vector3f const *topLeft,
for(i = 0; i < 2; ++i)
{
// View vector.
V2f_Set(view, vOrigin.x - (i == 0? topLeft->x : bottomRight->x),
vOrigin.z - (i == 0? topLeft->y : bottomRight->y));
V2f_Set(view, Rend_EyeOrigin().x - (i == 0? topLeft->x : bottomRight->x),
Rend_EyeOrigin().z - (i == 0? topLeft->y : bottomRight->y));

distance = V2f_Normalize(view);

Expand Down Expand Up @@ -960,8 +988,8 @@ static void quadShinyTexCoords(Vector2f *tc, Vector3f const *topLeft,
tc[ (i == 0 ? 0 : 3) ].x = angle + .3f; /*acos(-dot)/PI*/

// Vertical coordinates.
tc[ (i == 0 ? 0 : 2) ].y = shinyVertical(vOrigin.y - bottomRight->z, distance);
tc[ (i == 0 ? 1 : 3) ].y = shinyVertical(vOrigin.y - topLeft->z, distance);
tc[ (i == 0 ? 0 : 2) ].y = shinyVertical(Rend_EyeOrigin().y - bottomRight->z, distance);
tc[ (i == 0 ? 1 : 3) ].y = shinyVertical(Rend_EyeOrigin().y - topLeft->z, distance);
}
}

Expand All @@ -970,7 +998,7 @@ static void flatShinyTexCoords(Vector2f *tc, Vector3f const &point)
DENG_ASSERT(tc);

// Determine distance to viewer.
float distToEye = Vector2f(vOrigin.x - point.x, vOrigin.z - point.y)
float distToEye = Vector2f(Rend_EyeOrigin().x - point.x, Rend_EyeOrigin().z - point.y)
.normalize().length();
if(distToEye < 10)
{
Expand All @@ -980,13 +1008,13 @@ static void flatShinyTexCoords(Vector2f *tc, Vector3f const &point)
}

// Offset from the normal view plane.
Vector2f start(vOrigin.x, vOrigin.z);
Vector2f start(Rend_EyeOrigin().x, Rend_EyeOrigin().z);

float offset = ((start.y - point.y) * sin(.4f)/*viewFrontVec[VX]*/ -
(start.x - point.x) * cos(.4f)/*viewFrontVec[VZ]*/);

tc->x = ((shinyVertical(offset, distToEye) - .5f) * 2) + .5f;
tc->y = shinyVertical(vOrigin.y - point.z, distToEye);
tc->y = shinyVertical(Rend_EyeOrigin().y - point.z, distToEye);
}

struct rendworldpoly_params_t
Expand Down Expand Up @@ -1740,7 +1768,7 @@ static void projectDynamics(Surface const &surface, float glowStrength,
static bool nearFadeOpacity(WallEdge const &leftEdge, WallEdge const &rightEdge,
float &opacity)
{
if(vOrigin.y < leftEdge.bottom().z() || vOrigin.y > rightEdge.top().z())
if(Rend_EyeOrigin().y < leftEdge.bottom().z() || Rend_EyeOrigin().y > rightEdge.top().z())
return false;

mobj_t const *mo = viewPlayer->shared.mo;
Expand Down Expand Up @@ -2704,16 +2732,16 @@ static void occludeLeaf(bool frontFacing)
Vertex const &to = frontFacing? hedge->twin().vertex() : hedge->vertex();

// Does the floor create an occlusion?
if(((openBottom > cluster.visFloor().heightSmoothed() && vOrigin.y <= openBottom)
|| (openBottom > backCluster.visFloor().heightSmoothed() && vOrigin.y >= openBottom))
if(((openBottom > cluster.visFloor().heightSmoothed() && Rend_EyeOrigin().y <= openBottom)
|| (openBottom > backCluster.visFloor().heightSmoothed() && Rend_EyeOrigin().y >= openBottom))
&& canOccludeEdgeBetweenPlanes(cluster.visFloor(), backCluster.visFloor()))
{
C_AddViewRelOcclusion(from.origin(), to.origin(), openBottom, false);
}

// Does the ceiling create an occlusion?
if(((openTop < cluster.visCeiling().heightSmoothed() && vOrigin.y >= openTop)
|| (openTop < backCluster.visCeiling().heightSmoothed() && vOrigin.y <= openTop))
if(((openTop < cluster.visCeiling().heightSmoothed() && Rend_EyeOrigin().y >= openTop)
|| (openTop < backCluster.visCeiling().heightSmoothed() && Rend_EyeOrigin().y <= openTop))
&& canOccludeEdgeBetweenPlanes(cluster.visCeiling(), backCluster.visCeiling()))
{
C_AddViewRelOcclusion(from.origin(), to.origin(), openTop, true);
Expand Down Expand Up @@ -2975,7 +3003,7 @@ static void traverseBspAndDrawLeafs(MapElement *bspElement)
*/
static void generateDecorationFlares(Map &map)
{
Vector3d const viewPos = vOrigin.xzy();
Vector3d const viewPos = Rend_EyeOrigin().xzy();

foreach(Lumobj *lum, map.lumobjs())
{
Expand Down Expand Up @@ -3934,7 +3962,7 @@ static void drawLabel(Vector3d const &origin, String const &label, float scale,

static void drawLabel(Vector3d const &origin, String const &label)
{
ddouble distToEye = (vOrigin.xzy() - origin).length();
ddouble distToEye = (Rend_EyeOrigin().xzy() - origin).length();
drawLabel(origin, label, distToEye / (DENG_GAMEVIEW_WIDTH / 2), 1 - distToEye / 2000);
}

Expand Down Expand Up @@ -4010,11 +4038,11 @@ static void drawBiasEditingVisuals(Map &map)
glMatrixMode(GL_MODELVIEW);
glPushMatrix();

glTranslatef(vOrigin.x, vOrigin.y, vOrigin.z);
glTranslatef(Rend_EyeOrigin().x, Rend_EyeOrigin().y, Rend_EyeOrigin().z);
glScalef(1, 1.0f/1.2f, 1);
glTranslatef(-vOrigin.x, -vOrigin.y, -vOrigin.z);
glTranslatef(-Rend_EyeOrigin().x, -Rend_EyeOrigin().y, -Rend_EyeOrigin().z);

HueCircleVisual::draw(*hueCircle, vOrigin, viewData->frontVec);
HueCircleVisual::draw(*hueCircle, Rend_EyeOrigin(), viewData->frontVec);

glMatrixMode(GL_MODELVIEW);
glPopMatrix();
Expand Down

0 comments on commit 5c4c804

Please sign in to comment.