Browse Source

Fixed Camera's InverseWorldTransform(), which should be GetInverseWorldTransform().

Lasse Öörni 14 years ago
parent
commit
141d192225

+ 3 - 3
Engine/Graphics/Batch.cpp

@@ -150,7 +150,7 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
     if ((shadowMap) && (graphics->NeedParameterUpdate(VSP_SHADOWPROJ, light_)))
     {
         Camera* shadowCamera = light_->GetShadowCamera();
-        Matrix3x4 shadowView(shadowCamera->InverseWorldTransform());
+        Matrix3x4 shadowView(shadowCamera->GetInverseWorldTransform());
         Matrix4 shadowProj(shadowCamera->GetProjection());
         
         Matrix4 texAdjust(Matrix4::IDENTITY);
@@ -193,7 +193,7 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
     {
         if (graphics->NeedParameterUpdate(VSP_VIEWPROJ, camera_))
             graphics->SetShaderParameter(VSP_VIEWPROJ, camera_->GetProjection() *
-                camera_->InverseWorldTransform());
+                camera_->GetInverseWorldTransform());
     }
     
     if (graphics->NeedParameterUpdate(VSP_VIEWRIGHTVECTOR, camera_))
@@ -287,7 +287,7 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
         if (graphics->NeedParameterUpdate(PSP_SHADOWPROJ, light_))
         {
             Camera* shadowCamera = light_->GetShadowCamera();
-            Matrix3x4 shadowView(shadowCamera->InverseWorldTransform());
+            Matrix3x4 shadowView(shadowCamera->GetInverseWorldTransform());
             Matrix4 shadowProj(shadowCamera->GetProjection());
             
             Matrix3x4 viewPos(Matrix3x4::IDENTITY);

+ 4 - 4
Engine/Graphics/Camera.cpp

@@ -182,9 +182,9 @@ Frustum Camera::GetSplitFrustum(float nearClip, float farClip)
 
 Ray Camera::GetScreenRay(float x, float y)
 {
-    Matrix4 viewProjInverse = (GetProjection() * InverseWorldTransform()).Inverse();
+    Matrix4 viewProjInverse = (GetProjection() * GetInverseWorldTransform()).Inverse();
     
-    // The parameters range from 0.0 to 1.0. Expand to Normalized device coordinates (-1.0 to 1.0) & flip Y axis
+    // The parameters range from 0.0 to 1.0. Expand to normalized device coordinates (-1.0 to 1.0) & flip Y axis
     x = 2.0f * x - 1.0f;
     y = 1.0f - 2.0f * y;
     
@@ -304,7 +304,7 @@ float Camera::GetDistance(const Vector3& worldPos)
     if (!orthographic_)
         return (worldPos - GetWorldPosition()).LengthFast();
     else
-        return fabsf((InverseWorldTransform() * worldPos).z_);
+        return fabsf((GetInverseWorldTransform() * worldPos).z_);
 }
 
 float Camera::GetDistanceSquared(const Vector3& worldPos)
@@ -313,7 +313,7 @@ float Camera::GetDistanceSquared(const Vector3& worldPos)
         return (worldPos - GetWorldPosition()).LengthSquared();
     else
     {
-        float distance = (InverseWorldTransform() * worldPos).z_;
+        float distance = (GetInverseWorldTransform() * worldPos).z_;
         return distance * distance;
     }
 }

+ 3 - 6
Engine/Graphics/Camera.h

@@ -124,12 +124,9 @@ public:
     /// Return a scene node's LOD scaled distance
     float GetLodDistance(float distance, float scale, float bias) const;
     
-    /// Return inverse world transform
-    Matrix3x4 InverseWorldTransform() const
-    {
-        return GetWorldTransform().Inverse();
-    }
-
+    /// Return inverse world transform (view matrix)
+    Matrix3x4 GetInverseWorldTransform() const { return GetWorldTransform().Inverse(); }
+    
 private:
     /// Near clip distance
     float nearClip_;

+ 1 - 1
Engine/Graphics/DebugRenderer.cpp

@@ -59,7 +59,7 @@ void DebugRenderer::SetView(Camera* camera)
     if (!camera)
         return;
     
-    view_ = camera->InverseWorldTransform();
+    view_ = camera->GetInverseWorldTransform();
     projection_ = camera->GetProjection(false);
     frustum_ = camera->GetFrustum();
 }

+ 1 - 1
Engine/Graphics/OcclusionBuffer.cpp

@@ -106,7 +106,7 @@ void OcclusionBuffer::SetView(Camera* camera)
     if (!camera)
         return;
     
-    view_ = camera->InverseWorldTransform();
+    view_ = camera->GetInverseWorldTransform();
     projection_ = camera->GetProjection();
     viewProj_ = projection_ * view_;
     nearClip_ = camera->GetNearClip();

+ 1 - 1
Engine/Graphics/Renderer.cpp

@@ -1332,7 +1332,7 @@ Node* Renderer::CreateTempNode()
 void Renderer::SetupLightBatch(Batch& batch)
 {
     graphics_->ClearTransformSources();
-    Matrix3x4 view(batch.camera_->InverseWorldTransform());
+    Matrix3x4 view(batch.camera_->GetInverseWorldTransform());
     
     Light* light = batch.light_;
     float lightExtent = light->GetVolumeExtent();

+ 8 - 8
Engine/Graphics/View.cpp

@@ -320,7 +320,7 @@ void View::GetDrawables()
     sceneBox_.defined_ = false;
     sceneViewBox_.min_ = sceneViewBox_.max_ = Vector3::ZERO;
     sceneViewBox_.defined_ = false;
-    Matrix3x4 view(camera_->InverseWorldTransform());
+    Matrix3x4 view(camera_->GetInverseWorldTransform());
     unsigned cameraViewMask = camera_->GetViewMask();
     
     for (unsigned i = 0; i < tempDrawables_.Size(); ++i)
@@ -1051,7 +1051,7 @@ void View::RenderBatchesDeferred()
             renderer_->GetPixelShader(shaderName), false);
         
         // Store view transform for next frame
-        lastCameraView_ = camera_->InverseWorldTransform();
+        lastCameraView_ = camera_->GetInverseWorldTransform();
     }
 }
 
@@ -1254,7 +1254,7 @@ unsigned View::ProcessLight(Light* light)
                 bool generateBoxes = (isSplitShadowed) && (split->GetShadowFocus().focus_);
                 Matrix3x4 lightView;
                 if (shadowCamera)
-                    lightView = shadowCamera->InverseWorldTransform();
+                    lightView = shadowCamera->GetInverseWorldTransform();
                 
                 if (!optimize)
                 {
@@ -1400,7 +1400,7 @@ void View::ProcessLightQuery(unsigned splitIndex, const PODVector<Drawable*>& re
     if (shadowCamera)
     {
         bool projectBoxes = !shadowCamera->IsOrthographic();
-        lightView = shadowCamera->InverseWorldTransform();
+        lightView = shadowCamera->GetInverseWorldTransform();
         lightProj = shadowCamera->GetProjection();
         
         // Transform scene frustum into shadow camera's view space for shadow caster visibility check
@@ -1567,7 +1567,7 @@ void View::SetupShadowCamera(Light* light, bool shadowOcclusion)
             if ((shadowOcclusion) || (parameters.focus_))
                 sceneMaxZ = Min(sceneViewBox_.max_.z_, sceneMaxZ);
             
-            Matrix3x4 lightView(shadowCamera->InverseWorldTransform());
+            Matrix3x4 lightView(shadowCamera->GetInverseWorldTransform());
             Frustum lightViewSplitFrustum = camera_->GetSplitFrustum(light->GetNearSplit() - light->GetNearFadeRange(),
                 Min(light->GetFarSplit(), sceneMaxZ)).Transformed(lightView);
             
@@ -1605,7 +1605,7 @@ void View::SetupShadowCamera(Light* light, bool shadowOcclusion)
             if ((light->GetLightType() == LIGHT_SPOT) && (parameters.zoomOut_))
             {
                 // Make sure the out-zooming does not start while we are inside the spot
-                float distance = Max((camera_->InverseWorldTransform() * light->GetWorldPosition()).z_ - light->GetRange(), 1.0f);
+                float distance = Max((camera_->GetInverseWorldTransform() * light->GetWorldPosition()).z_ - light->GetRange(), 1.0f);
                 float lightPixels = (((float)height_ * light->GetRange() * camera_->GetZoom() * 0.5f) / distance);
                 
                 // Clamp pixel amount to a sufficient minimum to avoid self-shadowing artifacts due to loss of precision
@@ -1735,7 +1735,7 @@ const Rect& View::GetLightScissor(Light* light)
     if (i != lightScissorCache_.End())
         return i->second_;
     
-    Matrix3x4 view(camera_->InverseWorldTransform());
+    Matrix3x4 view(camera_->GetInverseWorldTransform());
     Matrix4 projection(camera_->GetProjection());
     
     switch (light->GetLightType())
@@ -2014,7 +2014,7 @@ void View::SetShaderParameters()
 void View::DrawSplitLightToStencil(Camera& camera, Light* light, bool clear)
 {
     graphics_->ClearTransformSources();
-    Matrix3x4 view(camera.InverseWorldTransform());
+    Matrix3x4 view(camera.GetInverseWorldTransform());
     
     switch (light->GetLightType())
     {