Simple python 3D vector3 math library wrapping some types from GLM library using pybind11.

Overview

vmath

Simple python 3D vector3 math library wrapping some types from GLM library using pybind11.

Description

Both pure python version and C++ version provided.

Not a direct glm wrapping. There are some Object-Oriented enhencements to the types.

Should be useful for other pybind11 bindings that use glm types, the conversion will be automatic (if done right).

Types:

  • Vector3 - glm::vec3
  • Quaternion - glm::quat
  • Matrix4 - glm::mat4
  • Transform - translation-rotation-scale
  • Vector2 - glm::vec2
  • Vector4 - glm::vec4
  • Ray - position-direction

Main source files comes from:

  • toy/wrap/wrap_vmath.h
  • toy/wrap/wrap_vmath.cpp
  • toy/glm_util.h
  • toy/glm_util.cpp

Documentation

See vmath.py for interfaces.

See src/wrap_vmath.cpp for pybind11 binding code.

Usage

Main classes:

  • Vector3: 3D Vector3.
  • Matrix4: 4x4 column major matrix4, M1 * M2 means first apply M2, then apply M1.
  • Quaternion: Quaternion for rotation.
  • Transform: Transform represented as Translation-Rotation-Scale.
>>> from vmath import Vector3, Matrix4, Quaternion, Transform
>>> v1 = Vector3(1.0, 2.0, 3.0)
>>> v2 = Vector3(4.0, 5.0, 6.0)
>>> v1 + v2
Vector3(5.0000, 7.0000, 9.0000)

>>> q = Quaternion.from_euler_angles(Vector3(0.0, 0.8, 0.0))
>>> q
Quaternion(0.9211, 0.0000, 0.3894, 0.0000)

>>> xf = Transform(v1, q, Vector3(1.0, 1.0, 1.0))
>>> m = xf.to_matrix4()
>>> print(m)
Matrix4<0.6967, 0.0000, 0.7174, 1.0000
       0.0000, 1.0000, 0.0000, 2.0000
       -0.7174, 0.0000, 0.6967, 3.0000
       0.0000, 0.0000, 0.0000, 1.0000>

>>> m.decompose()
Transform(Vector3(1.0000, 2.0000, 3.0000), Quaternion(0.9211, 0.0000, 0.3894, 0.0000), Vector3(1.0000, 1.0000, 1.0000))

>>> m.transform_vector3(v1)
Vector3(2.8488, 2.0000, 1.3728)
>>> m.transform_point(v1)
Vector3(3.8488, 4.0000, 4.3728)

Euler angles should be stored in Vector3(pitch, yaw, roll), order yaw-pitch-roll. Therefore the corresponding rotation matrix4 is M(yaw) * M(pitch) * M(roll).

Automatic conversion

One may want to use pybind11 binded glm types in multiple different extension modules, or embedded modules.

The conversion should just works thanks to internal pybind11 mechanisms, but with some carvets. Some notes:

  • Don't mix Debug and Release extension modules. The types won't be recongnised as the same by pybind11.

  • If one want more control, just drop the cpp files in the target project and compile _vmath as builtin (embedded) as vmath.

Build

Checkout pip_install_debug.bat file. One need to provide GLM path to build the extension.

Note

The interface of the types between the pure python module and extension module is somewhat different.

License

MIT License.

You might also like...
A full featured game of falling pieces using python's pygame library.
A full featured game of falling pieces using python's pygame library.

A full featured game of falling shapes using python's pygame library. Key Features • How To Play • Download • Contributing • License Key Features Sing

Building a Mario-like, classic platformer game in Python using the PyGame Library

Building a Mario-like, classic platformer game in Python using the PyGame Library

OS Algo Visualization - Operating system algorithm visualization using python pygame library

OS_Algo_Visualization Operating system algorithm visualization using python pyga

Wordle-Python - A simple low-key clone of the popular game WORDLE made with python and a 2D Graphics module Pygame
Wordle-Python - A simple low-key clone of the popular game WORDLE made with python and a 2D Graphics module Pygame

Wordle-Python A simple low-key clone of the popular game WORDLE made with python

A Gomoku game GUI using pygame where the user can choose to play against another player or an AI using minimax with alpha-beta pruning

Gomoku A GUI based Gomoku game using pygame where the user can choose to play against another player or an AI using minimax with alpha-beta pruning. R

A zombie game using Kinetic. You can control players using fingers

This is Eden Park's portpolio: Works, projects and practices This repository can be used to show the potential employers to check my works, code and p

N-Queens game made using pygame library
N-Queens game made using pygame library

N-Queens N-Queens game using pygame for AIML201 Testing: 1. git clone https://github.com/python-game-dev/N-Queens.git 2. cd N-Queens 3. python main.py

A "guess the number" game on a GUI interface using Tkinter library🙂

A "guess the number" game on a GUI interface using Tkinter library🙂

Python module providing simple game networking

nethelper Python module providing simple game networking This module was originally created to facilitate a class on creating multiplayer games in Pyg

Owner
null
Utility to find games owned by all (or at least some) of the passed players.

SteamCommonGameFinder Utility to find games that are owned by all (or at least some) of the players you pass into this programm. You can already find

Daniel O'Grady 4 Jan 4, 2022
Given some input, spit out the possible words for a Wordle puzzle

Wordle Helper, because why not. Given some input, spit out the possible words for a Wordle puzzle First time setup # Download the dictionary to a file

Richard Duarte 1 Jan 25, 2022
Simple Game created using Python & PyGame, as my Beginner Python Project!

Space Invaders This is a simple SPACE INVADER game create using PYGAME whihc have sound and lot's of keyboard functions. Prerequisites More Experience

Gaurav Pandey 2 Jan 8, 2022
A simple matrix code rain created using Python with Pygame.

Matrix4_code_rain A simple matrix code rain created using Python with Pygame. To run the code you will need Pygame and MS Mincho font. Create a projec

null 7 Nov 6, 2022
Simple darts game using Tkinter and sqlite3. Also associated with Python.

Ever wanted to play a simple and fun game before, and it even keeps a database of your score? Well here it is!! Introducing; Darts! A simple and fun g

an aspirin 2 Dec 19, 2021
A Simple 2048 Game Built Using Python

Game 2048_Python Dựa trên trò chơi nổi tiếng 2048 của Gabriele Cirulli. Mục tiêu của trò chơi là trượt các khối được đánh số trên một lưới để kết hợp

Le Phuong Anh 3 Dec 13, 2021
A Simple Scissor Paper Rock Game On Python Using Pygame.

Scissor Paper Stone Game Using Pygame This is a simple GUI based game made on pygame python. Installation Run code on your machine: git clone https:

Dipin Adhikari 0 Mar 21, 2022
Gamelib is a pure-Python single-file library/framework for writing simple games.

Gamelib is a pure-Python single-file library/framework for writing simple games. It is intended for educational purposes (e.g. to be used in b

Diego Essaya 15 Dec 22, 2022
This is a simple game made using pygame.

Ball breaker This is a simple game made using pygame game view The game view have been updated wait for the new view to be uploaded Game_show.mp4 Lear

Rishikesh Kumar 3 Nov 5, 2021
pygame is a Free and Open Source python programming language library for making multimedia applications like games built on top of the excellent SDL library. C, Python, Native, OpenGL.

pygame is a Free and Open Source python programming language library for making multimedia applications like games built on top of the excellent SDL library. C, Python, Native, OpenGL.

pygame 5.6k Jan 1, 2023