GithubHelp home page GithubHelp logo

dyeo / dym Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 2.0 246 KB

The DYM Math Library for Graphics and Game Programming

License: MIT License

C++ 99.90% C 0.10%
vector math graphics gmtk angle matrix quaternion half-precision templated dimensions math-library math-toolkit game-development cpp cplusplus x86

dym's Introduction

DYM Math Library

DYM (pronounced "dim") is a C++ library that provides efficient and flexible math utility for the purpose of graphics programming, game programming, and fields with similar requirements. The toolkit boasts matrix and vector classes which are templated by value type and by dimension. The entire library is defined in header files, and math code is implemented generically in a manner which allows for efficient runtime calculations. The entire library is free-to-use under the terms of the MIT License.

How to Use

Simply add the include/dym folder to your project's includes, and #include "dym/dym.h".

Features

  • Unambiguous Angles
  • Unambiguous Percentages
  • Half-Precision Floating Point Numbers
    • Full specification
  • Matrices (Column-Major)
    • Dimension-Templated
    • Type-Templated
    • Perspective/Orthographic Projections
    • 2D, 3D, 3D Homogeneous Transformations
    • Linear Algebra Operations
    • Matrix Product
    • Matrix-Vector Product
    • All GLSL Matrix Operations
    • Catmull-Rom and Bezier Matrices
    • Row-Major Conversion
  • Vectors
    • Dimension-Templated
    • Type-Templated
    • Dot and Cross Product
    • All GLSL Vector Operations
    • Vector Swizzling
  • Generic Quaternions
    • Type-Templated
    • Quaternion SLERP
    • Axis-Angle Representation
    • 3D Vector Transformation
    • Matrix Conversion

License

DYM uses the following version of the MIT License:

Copyright (c) 2015-2020 Dan Yeomans

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Code Sample

#include <iostream>


// one header gets the entire library, no hassle!
// optionally disable custom literals by defining DYM_DISABLE_LITERALS before including
// optionally disable swizzling by defining DYM_DISABLE_SWIZZLING before including
#include "path/to/dym/dym.h"

int main()
{
	// define a 3d float vector
	// synonymous with dym::vec3, dym::vec3f, and dym::vec<3>
	dym::vec<3, float> vecA;

	// initialize a 3d float matrix
	// synonymous with dym::mat3 and dym::mat3f, and dym::mat<3>
	dym::mat<3, 3, float> matA(1, 0, 1,
				2, 4, 0,
				3, 5, 6);

	// initialize a 3d float matrix as the inverse of matA
	dym::mat3 matB = dym::inverse(matA);

	// initialize a homogeneous transformation matrix (rotation and position)
	dym::mat4 matH(dym::mat3::rotatex(1.5_rad), dym::vec3(1, 2, 3));

	// fast invert the homogeneous transformation matrix
	dym::mat4 imatH = dym::fastinverse(matH);

	// retrieve the first column of matB as a 3d vector and store it in vecA
	vecA = matB[0];

	// initialize sclA the first column, last row of matA
	float sclA = matA[0][2];

	// define a perspective transformation matrix (openGL)
	dym::mat4::perspective(
		90_deg, // y-axis field of view, in degrees (dym::ang)
		16 / (float)9, // aspect ratio
		0.01, // near clipping range for z-axis
		10000 // far clipping range for z-axis
	);

	// output our results
	std::cout << matA * matB << std::endl << std::endl
		<< matH * imatH << std::endl << std::endl
		<< 45_deg << std::endl;

	// constructs a column-major 3d float matrix from rows, using 3d float vectors
	dym::mat3::fromrows(
		dym::vec3(0, 1, 2),
		dym::vec3(3, 4, 5),
		dym::vec3(4, 5, 6)
	);

	// pi constant, change to d_pi for double precision
	// all commonly used constants supported
	dym::f_pi;
	
	// vector swizzling
	dym::vec4 vecS = { 0, 1, 2, 3 };
	dym::vec3 vecT = vecS.yzx;
	vecT.yzx = vecS.xyz;
}

dym's People

Contributors

dyeo avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

phnod heywax123

dym's Issues

Simple physics library implementation.

Things like projectile motion, kinematics equations, and various other useful physics calculations in an easy-to-understand naming scheme and using the gmtk math library types.

Fully-baked half floats.

Currently, the half struct is missing the full expected feature set of a floating-point type.

AES-conforming encryption implementation.

Would be a fun project to tackle. This would go in an experimental branch with a disclaimer until I could confirm that it's 100% accurate to AES in terms of security, performance, and feature set.

Percentage class

A class similar to how the angle class works, using percentages (0 to 1 and 0 to 100) would be great! Additionally, the ability to stack percentages on top of each other additively/multiplicatively would be useful. (Ex: 10% and 50% could be stacked on top of each other multiplicatively to make 55%, or additively to make 60%)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.