Code Monkey home page Code Monkey logo

pygamemath's Introduction

ScreenShot

pyGameMath Build Status Code Health Codacy Badge

This is a math library written in python for 2D/3D game development which is also compatible with pypy. I made it while I was learning more about the math used in graphics development and for personal use in OpenGL related projects.
It’s still a work in progress.

Dependencies:

It uses six to allow support between python2.x and python3.x.

Install:

To install the library just do

pip install gem

It will install the dependicies automatically.

Documentation and Examples:

The examples on how to use the library and more info are maintained on the github wiki:

Wiki Link

Supported features:

NxN Matrices:

  • Transpose
  • Scale
  • NxN Matrix Multiplication
  • NxN Matrix * N Dimensions Vector Multiplication
  • 4x4 Perspective Projection Matrix
  • lookAt 4x4 Matrix
  • Translation (3x3, 4x4)
  • Rotation (2x2, 3x3, 4x4)
  • Shear (2x2, 3x3, 4x4)
  • Project
  • Unproject
  • Orthographic Projection
  • Perspective Projection
  • lookAt 4x4 matrix
  • Determinant 2x2, 3x3, 4x4
  • Inverse 2x2, 3x3, 4x4

N Dimensions Vectors:

  • Dot Product
  • Cross Product (3D, No 7D as of now)
  • 2D get angle of vector
  • 2D -90 degree rotation
  • 2D +90 degree rotation
  • Refraction
  • Reflection
  • Negate
  • Normalize
  • Linear Interpolation
  • Max Vector/Scalar
  • Min Vector/Scalar
  • Clamp
  • Transform
  • Barycentric
  • isInSameDirection test
  • isInOppositeDirection test
  • 3D Vector swizzling, similar to GLSL
  • 3D Vector idenitities

Quaternions:

  • Normalize
  • Dot Product
  • Rotation
  • Conjugate
  • Inverse
  • Negate
  • Rotate X, Y, Z
  • Arbitary Axis Rotation
  • From angle Rotation
  • To Rotation Matrix (4x4)
  • From Rotation Matrix (4x4)
  • Cross Product
  • Vector3D, Scalar Multiplication
  • Logarithm
  • Exponential
  • Power
  • Liner Interpolation (LERP)
  • Spherical Interpolation (SLERP)
  • Spherical Interpoliaton No Invert
  • Quaternion Splines (SQUAD)

Plane:

  • Define using
    • 3 Vectors
    • Point and Normal
    • Manual input
  • Dot Product
  • Normalize
  • Best fit normal and D value
  • Distance from plane to a point
  • Point location
  • Output
  • Flip

Ray:

  • Rotate using Matrix
  • Rotate using Quaternions
  • Translate
  • Output

Legendre Polynomial (Experimental, not complete):

  • For spherical harmonics
  • (l - m)PML(x) = x(2l - 1)PML-1(x
  • Irradiance maps

pygamemath's People

Contributors

alexmarinescu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pygamemath's Issues

Affine Matrix Encoding Issues

It would seem you're encoding translation in the last row of a matrix but multiplying as if it were stored in the last column. e.g.

>>> matrix.Matrix(3).translate(vector.Vector(3, data=[35, -60, 1])) * vector.Vector(3, data=[0, 0, 1])
Vector: size:3 , data:[0.0, 0.0, 1.0]

The result of that multiplication really ought to be a vector (35, -60, 1).

It's also incorrect that a 3x3 matrix requires a 3D vector for translation, it should take a 2D vector. In the above example I had to add an extra 1 to the end of my translation vector.

Spherical Harmonics

Update the experimental section of the library, in other words I have to redo the entire Spherical Harmonics section.

Rewrite Vector

Vector, Matrix, Quaternion need to be rewritten and use proper OOP instead of functional structure as it is now plus a lot of bug fixes, mostly spelling errors and style.

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.