Graphics/AbstractViewer: Add ProjectDepth method
This commit is contained in:
parent
e46aa6772e
commit
db0e3267da
|
|
@ -105,6 +105,7 @@ Nazara Engine:
|
|||
- Added LuaState::Traceback method
|
||||
- Added ModelLibrary, ModelManager and ModelSaver
|
||||
- Added AbstractViewer::Project and AbstractViewer::Unproject methods
|
||||
- Added AbstractViewer::ProjectDepth method
|
||||
|
||||
Nazara Development Kit:
|
||||
- Added ImageWidget (#139)
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ namespace Nz
|
|||
virtual float GetZNear() const = 0;
|
||||
|
||||
Nz::Vector3f Project(const Nz::Vector3f& worldPosition) const;
|
||||
float ProjectDepth(float depth);
|
||||
|
||||
Nz::Vector3f Unproject(const Nz::Vector3f& screenPos) const;
|
||||
|
||||
AbstractViewer& operator=(const AbstractViewer&) = default;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,15 @@ namespace Nz
|
|||
return screenPosition;
|
||||
}
|
||||
|
||||
float AbstractViewer::ProjectDepth(float depth)
|
||||
{
|
||||
const Matrix4f& projectionMatrix = GetProjectionMatrix();
|
||||
float a = projectionMatrix(2, 2);
|
||||
float b = projectionMatrix(2, 3);
|
||||
|
||||
return (0.5f * (-a * depth + b) / depth + 0.5f);
|
||||
}
|
||||
|
||||
Vector3f AbstractViewer::Unproject(const Nz::Vector3f& screenPos) const
|
||||
{
|
||||
Rectf viewport = Rectf(GetViewport());
|
||||
|
|
|
|||
Loading…
Reference in New Issue