Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/Camera.h
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2022 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 11 Lines | |||||
*/ | */ | ||||
#ifndef INCLUDED_CAMERA | #ifndef INCLUDED_CAMERA | ||||
#define INCLUDED_CAMERA | #define INCLUDED_CAMERA | ||||
#include "maths/BoundingBoxAligned.h" | #include "maths/BoundingBoxAligned.h" | ||||
#include "maths/Frustum.h" | #include "maths/Frustum.h" | ||||
#include "maths/Matrix3D.h" | #include "maths/Matrix3D.h" | ||||
#include "maths/Vector2D.h" | |||||
#include <array> | #include <array> | ||||
// view port | // view port | ||||
struct SViewPort | struct SViewPort | ||||
{ | { | ||||
int m_X; | int m_X; | ||||
int m_Y; | int m_Y; | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | public: | ||||
float GetAspectRatio() const; | float GetAspectRatio() const; | ||||
float GetNearPlane() const { return m_NearPlane; } | float GetNearPlane() const { return m_NearPlane; } | ||||
float GetFarPlane() const { return m_FarPlane; } | float GetFarPlane() const { return m_FarPlane; } | ||||
float GetFOV() const { return m_FOV; } | float GetFOV() const { return m_FOV; } | ||||
float GetOrthoScale() const { return m_OrthoScale; } | float GetOrthoScale() const { return m_OrthoScale; } | ||||
// Returns a quad of view in camera space at given distance from camera. | // Returns a quad of view in camera space at given distance from camera. | ||||
void GetViewQuad(float dist, Quad& quad) const; | Quad GetViewQuad(float dist) const; | ||||
// Builds a ray passing through the screen coordinate (px, py), calculates | // Builds a ray passing through the screen coordinate (px, py), calculates | ||||
// origin and direction of the ray. | // origin and direction of the ray. | ||||
void BuildCameraRay(int px, int py, CVector3D& origin, CVector3D& dir) const; | std::tuple<CVector3D, CVector3D> BuildCameraRay(int px, int py) const; | ||||
// General helpers that seem to fit here | // General helpers that seem to fit here | ||||
// Get the screen-space coordinates corresponding to a given world-space position | // Get the screen-space coordinates corresponding to a given world-space position | ||||
void GetScreenCoordinates(const CVector3D& world, float& x, float& y) const; | CVector2D GetScreenCoordinates(const CVector3D& world) const; | ||||
// Get the point on the terrain corresponding to pixel (px,py) (or the mouse coordinates) | // Get the point on the terrain corresponding to pixel (px,py) (or the mouse coordinates) | ||||
// The aboveWater parameter determines whether we want to stop at the water plane or also get underwater points | // The aboveWater parameter determines whether we want to stop at the water plane or also get underwater points | ||||
CVector3D GetWorldCoordinates(int px, int py, bool aboveWater=false) const; | CVector3D GetWorldCoordinates(int px, int py, bool aboveWater=false) const; | ||||
// Get the point on the plane at height h corresponding to pixel (px,py) | // Get the point on the plane at height h corresponding to pixel (px,py) | ||||
CVector3D GetWorldCoordinates(int px, int py, float h) const; | CVector3D GetWorldCoordinates(int px, int py, float h) const; | ||||
// Get the point on the terrain (or water plane) the camera is pointing towards | // Get the point on the terrain (or water plane) the camera is pointing towards | ||||
CVector3D GetFocus() const; | CVector3D GetFocus() const; | ||||
Show All 31 Lines |
Wildfire Games · Phabricator