Skip to content

Commit

Permalink
Use Plane instead of vec4.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcy committed Apr 7, 2016
1 parent 58387c1 commit 9f1a126
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions code/math/Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,8 @@ class Plane
// Returns 1, 2, or 1 + 2
int testBounds(Bounds bounds);

vec4 toVec4() const { return vec4(normal, distance); }

vec3 normal;
float distance;

Expand Down
8 changes: 4 additions & 4 deletions code/renderer_bgfx/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ static void SetDrawCallGeometry(const DrawCall &dc)
}
}

void Main::renderCamera(uint8_t visCacheId, vec3 pvsPosition, vec3 position, mat3 rotation, Rect rect, vec2 fov, const uint8_t *areaMask, vec4 clippingPlane, int flags)
void Main::renderCamera(uint8_t visCacheId, vec3 pvsPosition, vec3 position, mat3 rotation, Rect rect, vec2 fov, const uint8_t *areaMask, Plane clippingPlane, int flags)
{
assert(areaMask);
const float zMin = 4;
Expand Down Expand Up @@ -962,7 +962,7 @@ void Main::renderCamera(uint8_t visCacheId, vec3 pvsPosition, vec3 position, mat
if (g_cvars.waterReflections.getBool())
{
Transform reflectionCamera;
vec4 reflectionPlane;
Plane reflectionPlane;

if (world::CalculateReflectionCamera(visCacheId, position, rotation, vpMatrix, &reflectionCamera, &reflectionPlane))
{
Expand All @@ -987,7 +987,7 @@ void Main::renderCamera(uint8_t visCacheId, vec3 pvsPosition, vec3 position, mat
// Render a portal camera if there's a portal surface visible.
vec3 pvsPosition;
Transform portalCamera;
vec4 portalPlane;
Plane portalPlane;
bool isCameraMirrored;

if (world::CalculatePortalCamera(visCacheId, position, rotation, vpMatrix, sceneEntities_, &pvsPosition, &portalCamera, &isCameraMirrored, &portalPlane))
Expand Down Expand Up @@ -1040,7 +1040,7 @@ void Main::renderCamera(uint8_t visCacheId, vec3 pvsPosition, vec3 position, mat
if (flags & RenderCameraFlags::UseClippingPlane)
{
uniforms_->portalClip.set(vec4(1, 0, 0, 0));
uniforms_->portalPlane.set(clippingPlane);
uniforms_->portalPlane.set(clippingPlane.toVec4());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion code/renderer_bgfx/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class Main
void debugDraw(bgfx::TextureHandle texture, int x = 0, int y = 0, ShaderProgramId::Enum program = ShaderProgramId::Texture);
uint8_t pushView(const FrameBuffer &frameBuffer, uint16_t clearFlags, const mat4 &viewMatrix, const mat4 &projectionMatrix, Rect rect, int flags = 0);
void flushStretchPics();
void renderCamera(uint8_t visCacheId, vec3 pvsPosition, vec3 position, mat3 rotation, Rect rect, vec2 fov, const uint8_t *areaMask, vec4 clippingPlane = vec4::empty, int flags = 0);
void renderCamera(uint8_t visCacheId, vec3 pvsPosition, vec3 position, mat3 rotation, Rect rect, vec2 fov, const uint8_t *areaMask, Plane clippingPlane = Plane(), int flags = 0);
void renderPolygons();
void renderScreenSpaceQuad(const FrameBuffer &frameBuffer, ShaderProgramId::Enum program, uint64_t state, uint16_t clearFlags = BGFX_CLEAR_NONE, bool originBottomLeft = false, Rect rect = Rect());
void renderToStencil(const uint8_t viewId);
Expand Down
4 changes: 2 additions & 2 deletions code/renderer_bgfx/Precompiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -1571,8 +1571,8 @@ namespace world
Bounds GetBounds(uint8_t visCacheId);
size_t GetNumSkies(uint8_t visCacheId);
void GetSky(uint8_t visCacheId, size_t index, Material **material, const std::vector<Vertex> **vertices);
bool CalculatePortalCamera(uint8_t visCacheId, vec3 mainCameraPosition, mat3 mainCameraRotation, const mat4 &mvp, const std::vector<Entity> &entities, vec3 *pvsPosition, Transform *portalCamera, bool *isMirror, vec4 *portalPlane);
bool CalculateReflectionCamera(uint8_t visCacheId, vec3 mainCameraPosition, mat3 mainCameraRotation, const mat4 &mvp, Transform *camera, vec4 *plane);
bool CalculatePortalCamera(uint8_t visCacheId, vec3 mainCameraPosition, mat3 mainCameraRotation, const mat4 &mvp, const std::vector<Entity> &entities, vec3 *pvsPosition, Transform *portalCamera, bool *isMirror, Plane *portalPlane);
bool CalculateReflectionCamera(uint8_t visCacheId, vec3 mainCameraPosition, mat3 mainCameraRotation, const mat4 &mvp, Transform *camera, Plane *plane);
void RenderPortal(uint8_t visCacheId, DrawCallList *drawCallList);
void RenderReflective(uint8_t visCacheId, DrawCallList *drawCallList);
uint8_t CreateVisCache();
Expand Down
12 changes: 6 additions & 6 deletions code/renderer_bgfx/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ class World
}
}

bool calculatePortalCamera(uint8_t visCacheId, vec3 mainCameraPosition, mat3 mainCameraRotation, const mat4 &mvp, const std::vector<Entity> &entities, vec3 *pvsPosition, Transform *portalCamera, bool *isMirror, vec4 *portalPlane) const
bool calculatePortalCamera(uint8_t visCacheId, vec3 mainCameraPosition, mat3 mainCameraRotation, const mat4 &mvp, const std::vector<Entity> &entities, vec3 *pvsPosition, Transform *portalCamera, bool *isMirror, Plane *portalPlane) const
{
assert(pvsPosition);
assert(portalCamera);
Expand Down Expand Up @@ -927,11 +927,11 @@ class World
portalCamera->rotation[1] = MirroredVector(mainCameraRotation[1], surfaceTransform, cameraTransform);
portalCamera->rotation[2] = MirroredVector(mainCameraRotation[2], surfaceTransform, cameraTransform);
*isMirror = portal.isMirror;
*portalPlane = vec4(-cameraTransform.rotation[0], vec3::dotProduct(cameraTransform.position, -cameraTransform.rotation[0]));
*portalPlane = Plane(-cameraTransform.rotation[0], vec3::dotProduct(cameraTransform.position, -cameraTransform.rotation[0]));
return true;
}

bool calculateReflectionCamera(uint8_t visCacheId, vec3 mainCameraPosition, mat3 mainCameraRotation, const mat4 &mvp, Transform *camera, vec4 *plane)
bool calculateReflectionCamera(uint8_t visCacheId, vec3 mainCameraPosition, mat3 mainCameraRotation, const mat4 &mvp, Transform *camera, Plane *plane)
{
assert(camera);
assert(plane);
Expand Down Expand Up @@ -988,7 +988,7 @@ class World
camera->rotation[0] = MirroredVector(mainCameraRotation[0], surfaceTransform, cameraTransform);
camera->rotation[1] = MirroredVector(mainCameraRotation[1], surfaceTransform, cameraTransform);
camera->rotation[2] = MirroredVector(mainCameraRotation[2], surfaceTransform, cameraTransform);
*plane = vec4(-cameraTransform.rotation[0], vec3::dotProduct(cameraTransform.position, -cameraTransform.rotation[0]));
*plane = Plane(-cameraTransform.rotation[0], vec3::dotProduct(cameraTransform.position, -cameraTransform.rotation[0]));
return true;
}

Expand Down Expand Up @@ -2459,13 +2459,13 @@ void GetSky(uint8_t visCacheId, size_t index, Material **material, const std::ve
s_world->getSky(visCacheId, index, material, vertices);
}

bool CalculatePortalCamera(uint8_t visCacheId, vec3 mainCameraPosition, mat3 mainCameraRotation, const mat4 &mvp, const std::vector<Entity> &entities, vec3 *pvsPosition, Transform *portalCamera, bool *isMirror, vec4 *portalPlane)
bool CalculatePortalCamera(uint8_t visCacheId, vec3 mainCameraPosition, mat3 mainCameraRotation, const mat4 &mvp, const std::vector<Entity> &entities, vec3 *pvsPosition, Transform *portalCamera, bool *isMirror, Plane *portalPlane)
{
assert(IsLoaded());
return s_world->calculatePortalCamera(visCacheId, mainCameraPosition, mainCameraRotation, mvp, entities, pvsPosition, portalCamera, isMirror, portalPlane);
}

bool CalculateReflectionCamera(uint8_t visCacheId, vec3 mainCameraPosition, mat3 mainCameraRotation, const mat4 &mvp, Transform *camera, vec4 *plane)
bool CalculateReflectionCamera(uint8_t visCacheId, vec3 mainCameraPosition, mat3 mainCameraRotation, const mat4 &mvp, Transform *camera, Plane *plane)
{
assert(IsLoaded());
return s_world->calculateReflectionCamera(visCacheId, mainCameraPosition, mainCameraRotation, mvp, camera, plane);
Expand Down

0 comments on commit 9f1a126

Please sign in to comment.