diff options
author | Matt Strapp <matt@mattstrapp.net> | 2021-09-24 10:05:55 -0500 |
---|---|---|
committer | Matt Strapp <matt@mattstrapp.net> | 2021-09-24 10:05:55 -0500 |
commit | 458496b2db6d67736fd1ffc18c6e51a7a4e1180c (patch) | |
tree | 3d6ee4e37a48d71a6ac781cbd93a6d6dcb234f98 /dev/MinGfx/src/gfxmath.h | |
parent | Pushed feedback file submission-w1.1 (diff) | |
parent | publish a2 (diff) | |
download | csci4611-458496b2db6d67736fd1ffc18c6e51a7a4e1180c.tar csci4611-458496b2db6d67736fd1ffc18c6e51a7a4e1180c.tar.gz csci4611-458496b2db6d67736fd1ffc18c6e51a7a4e1180c.tar.bz2 csci4611-458496b2db6d67736fd1ffc18c6e51a7a4e1180c.tar.lz csci4611-458496b2db6d67736fd1ffc18c6e51a7a4e1180c.tar.xz csci4611-458496b2db6d67736fd1ffc18c6e51a7a4e1180c.tar.zst csci4611-458496b2db6d67736fd1ffc18c6e51a7a4e1180c.zip |
Merge branch 'support-code' of github.umn.edu:umn-csci-4611-f21/shared-upstream
Diffstat (limited to 'dev/MinGfx/src/gfxmath.h')
-rw-r--r-- | dev/MinGfx/src/gfxmath.h | 176 |
1 files changed, 96 insertions, 80 deletions
diff --git a/dev/MinGfx/src/gfxmath.h b/dev/MinGfx/src/gfxmath.h index 8bb6c25..86c1061 100644 --- a/dev/MinGfx/src/gfxmath.h +++ b/dev/MinGfx/src/gfxmath.h @@ -1,81 +1,97 @@ -/*
- This file is part of the MinGfx Project.
-
- Copyright (c) 2017,2018 Regents of the University of Minnesota.
- All Rights Reserved.
-
- Original Author(s) of this File:
- Dan Keefe, 2018, University of Minnesota
-
- Author(s) of Significant Updates/Modifications to the File:
- ...
- */
-
-#ifndef SRC_GFXMATH_H_
-#define SRC_GFXMATH_H_
-
-#include "point2.h"
-#include "point3.h"
-#include "vector3.h"
-#include "matrix4.h"
-
-namespace mingfx {
-
-
-/** This class holds a variety of static math functions that are useful to have
- defined with creating graphics programs.
- */
-class GfxMath {
-public:
-
- /// Returns a if x is less than a and b if x is greater than b.
- static float Clamp(float x, float a, float b);
-
- static float ToRadians(float degrees);
-
- static float ToDegrees(float radians);
-
- static Vector3 ToRadians(Vector3 degrees);
-
- static Vector3 ToDegrees(Vector3 radians);
-
- static float Lerp(float a, float b, float alpha);
-
- static int iLerp(int a, int b, float alpha);
-
- /// Converts a 2D point on the filmplane represented in Normalized Device
- /// Coorindates, which means (-1,1) for the top left corner of the screen and
- /// (1,-1) for the bottom right corner, to a 3D point that lies on the camera's
- /// near plane. Useful for converting mouse coordinates into a 3D point.
- /// Remember that this uses NORMALIZED device coordinates for the screenPt,
- /// not pixels. GraphicsApp and most other graphics engines report mouse move
- /// events in pixels, so you need to convert these to normalized device coordinates
- /// first. If you are using GraphicsApp, you can do this with:
- /// Point2 normPos = graphicsApp->pixels_to_normalized_coordinates(mousePos);
- static Point3 ScreenToNearPlane(const Matrix4 &viewMatrix, const Matrix4 &projMatrix, const Point2 &normalizedScreenPt);
-
- /// Similar to filmplane2D_to_nearplane3D() but here rather than using the
- /// nearplane, you specify the depth of the plane to use as a distance away
- /// from the camera's focal point.
- static Point3 ScreenToDepthPlane(const Matrix4 &viewMatrix, const Matrix4 &projMatrix, const Point2 &normalizedScreenPt, float planeDepth);
-
- /// Converts a 2D point on the filmplane represented in Normalized Device
- /// Coorindates, which means (-1,1) for the top left corner of the screen and
- /// (1,-1) for the bottom right corner, to a 3D point in the world. The depth
- /// buffer value under the pixel must be supplied. If you are using GraphicsApp,
- /// you can use the mouse pos in pixels to get the required arguments like this:
- /// Point2 normPos = graphicsApp->pixels_to_normalized_coordinates(mousePos);
- /// float normZ = graphicsApp->z_value_at_pixel(mousePos);
- static Point3 ScreenToWorld(const Matrix4 &viewMatrix, const Matrix4 &projMatrix, const Point2 &normalizedScreenPt, float normalizedZ);
-
-
- static const float PI;
- static const float TWO_PI;
- static const float HALF_PI;
-};
-
-
-
-} // end namespace
-
+/* + This file is part of the MinGfx Project. + + Copyright (c) 2017,2018 Regents of the University of Minnesota. + All Rights Reserved. + + Original Author(s) of this File: + Dan Keefe, 2018, University of Minnesota + + Author(s) of Significant Updates/Modifications to the File: + ... + */ + +#ifndef SRC_GFXMATH_H_ +#define SRC_GFXMATH_H_ + +#include "point2.h" +#include "point3.h" +#include "vector3.h" +#include "matrix4.h" + +namespace mingfx { + + +/** This class holds a variety of static math functions that are useful to have + defined with creating graphics programs. + */ +class GfxMath { +public: + + /// MinGfx specific implementations of trigonometric functions included to + /// solve compilation issues between different platforms. + static float sin(float a); + + static float cos(float a); + + static float tan(float a); + + static float asin(float a); + + static float acos(float a); + + static float atan(float a); + + static float atan2(float a, float b); + + /// Returns a if x is less than a and b if x is greater than b. + static float Clamp(float x, float a, float b); + + static float ToRadians(float degrees); + + static float ToDegrees(float radians); + + static Vector3 ToRadians(Vector3 degrees); + + static Vector3 ToDegrees(Vector3 radians); + + static float Lerp(float a, float b, float alpha); + + static int iLerp(int a, int b, float alpha); + + /// Converts a 2D point on the filmplane represented in Normalized Device + /// Coorindates, which means (-1,1) for the top left corner of the screen and + /// (1,-1) for the bottom right corner, to a 3D point that lies on the camera's + /// near plane. Useful for converting mouse coordinates into a 3D point. + /// Remember that this uses NORMALIZED device coordinates for the screenPt, + /// not pixels. GraphicsApp and most other graphics engines report mouse move + /// events in pixels, so you need to convert these to normalized device coordinates + /// first. If you are using GraphicsApp, you can do this with: + /// Point2 normPos = graphicsApp->pixels_to_normalized_coordinates(mousePos); + static Point3 ScreenToNearPlane(const Matrix4 &viewMatrix, const Matrix4 &projMatrix, const Point2 &normalizedScreenPt); + + /// Similar to filmplane2D_to_nearplane3D() but here rather than using the + /// nearplane, you specify the depth of the plane to use as a distance away + /// from the camera's focal point. + static Point3 ScreenToDepthPlane(const Matrix4 &viewMatrix, const Matrix4 &projMatrix, const Point2 &normalizedScreenPt, float planeDepth); + + /// Converts a 2D point on the filmplane represented in Normalized Device + /// Coorindates, which means (-1,1) for the top left corner of the screen and + /// (1,-1) for the bottom right corner, to a 3D point in the world. The depth + /// buffer value under the pixel must be supplied. If you are using GraphicsApp, + /// you can use the mouse pos in pixels to get the required arguments like this: + /// Point2 normPos = graphicsApp->pixels_to_normalized_coordinates(mousePos); + /// float normZ = graphicsApp->z_value_at_pixel(mousePos); + static Point3 ScreenToWorld(const Matrix4 &viewMatrix, const Matrix4 &projMatrix, const Point2 &normalizedScreenPt, float normalizedZ); + + + static const float PI; + static const float TWO_PI; + static const float HALF_PI; +}; + + + +} // end namespace + #endif
\ No newline at end of file |