Implement CreateFrustumFromCamera
This commit is contained in:
@@ -3,12 +3,13 @@
|
||||
#pragma once
|
||||
|
||||
namespace Geometry {
|
||||
using Point2D = LinearAlgebra::Vector2;
|
||||
using Vector2 = LinearAlgebra::Vector2;
|
||||
using Vector3 = LinearAlgebra::Vector3;
|
||||
|
||||
class LineSegment2D
|
||||
{
|
||||
Point2D A;
|
||||
Point2D B;
|
||||
Vector2 A;
|
||||
Vector2 B;
|
||||
};
|
||||
|
||||
class Rectangle; //AABB2D;
|
||||
@@ -29,7 +30,7 @@ namespace Geometry {
|
||||
|
||||
|
||||
|
||||
using Point3D = LinearAlgebra::Vector3;
|
||||
|
||||
|
||||
// A 3D axis-aligned bounding box
|
||||
// This data structure can be used to represent coarse bounds of objects, in situations where detailed triangle-level
|
||||
@@ -44,18 +45,59 @@ namespace Geometry {
|
||||
class Line;
|
||||
class LineSegment
|
||||
{
|
||||
Point3D A;
|
||||
Point3D B;
|
||||
Vector3 A;
|
||||
Vector3 B;
|
||||
};
|
||||
class Ray
|
||||
{
|
||||
Point3D Origin;
|
||||
Point3D Direction;
|
||||
Vector3 Origin;
|
||||
Vector3 Direction;
|
||||
};
|
||||
|
||||
class OBB;
|
||||
class Frustum;
|
||||
class Plane;
|
||||
class Plane
|
||||
{
|
||||
public:
|
||||
Vector3 Position;
|
||||
Vector3 Normal;
|
||||
float distance = 0.f;
|
||||
|
||||
};
|
||||
class Frustum {
|
||||
public:
|
||||
Plane TopFace;
|
||||
Plane BottomFace;
|
||||
Plane RightFace;
|
||||
Plane LeftFace;
|
||||
Plane FarFace;
|
||||
Plane NearFace;
|
||||
};
|
||||
|
||||
class Camera {
|
||||
public:
|
||||
Vector3 Position;
|
||||
Vector3 Front;
|
||||
Vector3 Right;
|
||||
Vector3 Up;
|
||||
};
|
||||
|
||||
static Frustum CreateFrustumFromCamera(const Camera& cam, float aspect, float fovY, float zNear, float zFar)
|
||||
{
|
||||
Frustum frustum;
|
||||
const float halfVSide = zFar * tanf(fovY * 0.5f);
|
||||
const float halfHSide = halfVSide * aspect;
|
||||
|
||||
const Vector3 frontMultFar = cam.Front * zFar;
|
||||
|
||||
frustum.NearFace = Plane{cam.Position + cam.Front * zNear, cam.Front};
|
||||
frustum.FarFace = Plane{cam.Position + frontMultFar, -cam.Front};
|
||||
frustum.RightFace = Plane{cam.Position, Vector3::Cross(frontMultFar - cam.Right * halfHSide, cam.Up)};
|
||||
frustum.LeftFace = Plane{cam.Position, Vector3::Cross(cam.Up, frontMultFar+cam.Right*halfHSide)};
|
||||
frustum.TopFace = Plane{cam.Position, Vector3::Cross(cam.Right, frontMultFar - cam.Up * halfVSide)};
|
||||
frustum.BottomFace = Plane{cam.Position, Vector3::Cross(frontMultFar + cam.Up * halfVSide, cam.Right)};
|
||||
return frustum;
|
||||
}
|
||||
|
||||
class Polygon;
|
||||
class Polyhedron;
|
||||
class QuadTree;
|
||||
|
@@ -10,7 +10,7 @@ namespace LinearAlgebra {
|
||||
* The elements of this matrix are
|
||||
* m_00, m_01, m_02, m_03
|
||||
* m_10, m_11, m_12, m_13
|
||||
* m_20, m_21, m_22, m_23,
|
||||
* m_20, m_21, m_22, xm_23,
|
||||
* m_30, m_31, m_32, m_33
|
||||
*
|
||||
* The element m_yx is the value on the row y and column x.
|
||||
@@ -18,8 +18,42 @@ namespace LinearAlgebra {
|
||||
*/
|
||||
class Matrix4x4 {
|
||||
public:
|
||||
enum { Rows = 4 };
|
||||
enum { Cols = 4 };
|
||||
|
||||
static const Matrix4x4 Zero;
|
||||
static const Matrix4x4 Identity;
|
||||
static const Matrix4x4 NaN;
|
||||
|
||||
Matrix4x4() {}
|
||||
Matrix4x4(float val);
|
||||
Matrix4x4(float m00, float m01, float m02, float m03,
|
||||
float m10, float m11, float m12, float m13,
|
||||
float m20, float m21, float m22, float m23,
|
||||
float m30, float m31, float m32, float m33);
|
||||
Matrix4x4(const Vector4& r1, const Vector4& r2, const Vector4& r3, const Vector4& r4);
|
||||
explicit Matrix4x4(const Quaternion& orientation);
|
||||
|
||||
Vector4 GetRow(int index) const;
|
||||
Vector4 GetColumn(int index) const;
|
||||
float At(int x, int y) const;
|
||||
|
||||
Vector4 Diagonal() const;
|
||||
Vector4 WorldX() const;
|
||||
Vector4 WorldY() const;
|
||||
Vector4 WorldZ() const;
|
||||
|
||||
/// Computes the determinant of this matrix.
|
||||
// If the determinant is nonzero, this matrix is invertible.
|
||||
float Determinant() const;
|
||||
|
||||
Matrix4x4 Inverse() const;
|
||||
|
||||
Matrix4x4 Transpose() const;
|
||||
|
||||
Vector2 Transform(const Vector2& rhs) const;
|
||||
Vector3 Transform(const Vector3& rhs) const;
|
||||
Vector4 Transform(const Vector4& rhs) const;
|
||||
|
||||
Vector3 GetTranslationComponent() const;
|
||||
Matrix3x3 GetRotationComponent() const;
|
||||
|
13
include/J3ML/LinearAlgebra/Vector.h
Normal file
13
include/J3ML/LinearAlgebra/Vector.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
template <typename T, int Dims>
|
||||
class templated_vector
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
|
||||
using v2f = templated_vector<float, 2>;
|
||||
using v3f = templated_vector<float, 3>;
|
||||
using v4f = templated_vector<float, 4>;
|
Reference in New Issue
Block a user