wx_BGI_Graphics
Classic BGI-compatible graphics API with modern OpenGL extension API
Loading...
Searching...
No Matches
bgi_camera.h
Go to the documentation of this file.
1#pragma once
2
3#include "bgi_types.h"
4
5#include <glm/glm.hpp>
6#include <glm/gtc/matrix_transform.hpp>
7#include <glm/gtc/type_ptr.hpp>
8#include <vector>
9
27namespace bgi
28{
29
30 // -------------------------------------------------------------------------
31 // Viewport helpers
32 // -------------------------------------------------------------------------
33
38 void cameraEffectiveViewport(const Camera3D &cam, int winW, int winH,
39 int &x, int &y, int &w, int &h);
40
42 float cameraAspectRatio(const Camera3D &cam, int winW, int winH);
43
44 // -------------------------------------------------------------------------
45 // Matrix construction
46 // -------------------------------------------------------------------------
47
52 glm::mat4 cameraViewMatrix(const Camera3D &cam);
53
64 glm::mat4 cameraProjMatrix(const Camera3D &cam, float aspectRatio);
65
67 glm::mat4 cameraVPMatrix(const Camera3D &cam, float aspectRatio);
68
69 // -------------------------------------------------------------------------
70 // Coordinate utilities
71 // -------------------------------------------------------------------------
72
88 bool cameraWorldToScreen(const Camera3D &cam, int winW, int winH,
89 float wx, float wy, float wz,
90 float &screenX, float &screenY);
91
102 bool cameraWorldToScreenForced(const Camera3D &cam, int winW, int winH,
103 float wx, float wy, float wz,
104 float &screenX, float &screenY);
105
110 glm::vec4 cameraWorldToClip(const Camera3D &cam, int winW, int winH,
111 float wx, float wy, float wz);
112
120 void clipPolyByPlane(std::vector<glm::vec4> &poly, const glm::vec4 &plane);
121
127 void clipPolyZPlanes(std::vector<glm::vec4> &poly);
128
133 bool clipLineByPlane(glm::vec4 &A, glm::vec4 &B, const glm::vec4 &plane);
134
139 bool clipLineZPlanes(glm::vec4 &A, glm::vec4 &B);
140
148 bool cameraClipToScreen(const Camera3D &cam, int winW, int winH,
149 const glm::vec4 &clip,
150 float &screenX, float &screenY);
151
165 void cameraScreenToRay(const Camera3D &cam, int winW, int winH,
166 float screenX, float screenY,
167 float &rayOx, float &rayOy, float &rayOz,
168 float &rayDx, float &rayDy, float &rayDz);
169
170 // -------------------------------------------------------------------------
171 // Utility
172 // -------------------------------------------------------------------------
173
175 void matToFloatArray(const glm::mat4 &m, float *out16);
176
177} // namespace bgi
Definition bgi_camera.h:28
glm::mat4 cameraVPMatrix(const Camera3D &cam, float aspectRatio)
Returns the combined view-projection matrix (proj × view).
void clipPolyZPlanes(std::vector< glm::vec4 > &poly)
Clip a convex polygon in clip space against the near plane (Z+W>0) and far plane (-Z+W>0).
bool clipLineZPlanes(glm::vec4 &A, glm::vec4 &B)
Clip a line segment against near and far Z planes.
glm::mat4 cameraProjMatrix(const Camera3D &cam, float aspectRatio)
Builds the projection matrix.
bool clipLineByPlane(glm::vec4 &A, glm::vec4 &B, const glm::vec4 &plane)
Clip a LINE SEGMENT in clip space against one half-space in place.
void cameraEffectiveViewport(const Camera3D &cam, int winW, int winH, int &x, int &y, int &w, int &h)
Returns the effective screen-space viewport rectangle (pixels) for a camera.
glm::mat4 cameraViewMatrix(const Camera3D &cam)
Builds the view matrix from eye / target / up, or from the 2-D pan / zoom / rotation fields when cam....
void cameraScreenToRay(const Camera3D &cam, int winW, int winH, float screenX, float screenY, float &rayOx, float &rayOy, float &rayOz, float &rayDx, float &rayDy, float &rayDz)
Unprojects a screen pixel to a world-space ray.
void clipPolyByPlane(std::vector< glm::vec4 > &poly, const glm::vec4 &plane)
Sutherland-Hodgman clip step: clip a convex polygon (in 4-D clip space) against one half-space.
glm::vec4 cameraWorldToClip(const Camera3D &cam, int winW, int winH, float wx, float wy, float wz)
Transform a world-space point to 4-D clip space via the camera's VP matrix.
void matToFloatArray(const glm::mat4 &m, float *out16)
Writes a GLM mat4 into a caller-supplied column-major float[16] array.
bool cameraWorldToScreen(const Camera3D &cam, int winW, int winH, float wx, float wy, float wz, float &screenX, float &screenY)
Projects a world-space point to a screen pixel.
bool cameraWorldToScreenForced(const Camera3D &cam, int winW, int winH, float wx, float wy, float wz, float &screenX, float &screenY)
Like cameraWorldToScreen but skips the NDC frustum boundary test.
bool cameraClipToScreen(const Camera3D &cam, int winW, int winH, const glm::vec4 &clip, float &screenX, float &screenY)
Project a 4-D clip-space point (after SH clipping) to a screen pixel.
float cameraAspectRatio(const Camera3D &cam, int winW, int winH)
Returns the aspect ratio (width / height) of the camera's effective viewport.
3-D camera definition (Z-up, right-handed world coordinate system).
Definition bgi_types.h:348