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.

Guess Your Card - A Multiplayer Python Game

Guess Your Card - A Multiplayer Python Game This is a guessing card game having two levels - Developed in Python and can be played between two to four

Hammad Ahmed ~ 1 Oct 20, 2021
Find live blooket games easy with python.

Blooket-pin-finder Find live blooket games easy with python. info when you start you will see what looks like error DON'T STOP those are just the thre

Crazedpotato 1 Mar 07, 2022
A python script to solve Wordle puzzles

Wordle solver A python script to solve Wordle puzzles.

Felix Weinberger 1 Feb 12, 2022
An asynchronous Minecraft server wrapper written in python3 with asyncio

mark3 (WIP) A modern Minecraft server wrapper written in python3 with asyncio TODO Note: The order of the following checklist doesn't necessarily mean

Colin Andress 7 Jul 29, 2022
Lutris desktop client in Python / PyGObject

Lutris Lutris is an open source gaming platform that makes gaming on Linux easier by managing, installing and providing optimal settings for games. Lu

Lutris 6.1k Dec 30, 2022
A menu for pygame. Simple, and easy to use

pygame-menu Source repo on GitHub, and run it on Repl.it Introduction Pygame-menu is a python-pygame library for creating menus and GUIs. It supports

Pablo Pizarro R. 411 Dec 27, 2022
Code d'un jeu en python par Graveen (avec mes modifications)

ATTENTION Vous ne devez pas copier coller le code sans le comprendre, apprennez déjà, le python et pygame, et seulement ensuite, vous pourrrez l'utili

TheBigWolfy 7 Nov 02, 2022
Fully functional BlackJack game with a graphical user interface.

BlackJack Welcome to BlackJack! This game is fully functional, with a casino sound package integrated using Pygame, dynamic game logic developed using

Shwetang Desai 2 Jan 10, 2022
Jogo da velha escrito em python para 1 ou 2 jogadores

O Jogo da Velha Esse jogo da velha foi desenvolvido por mim em python, como um desafio de programar um jogo da velha em menos de 24 horas, no qual o c

Gabriel Castelo Branco 5 Jun 18, 2021
A game developed while learning python

Alien_Invasion a game developed while learning python you must have python-3 installed in your computer. and pygame module is also required for this.

Jani Shubham 0 Oct 10, 2022
Code for an arcade pop-a-shot style basketball game on Raspberry Pi

Basketball-Game Code for an arcade pop-a-shot style basketball game on Raspberry Pi, made over the course of winter break 2022. How To Run: Running th

Seth Reis 1 Jan 21, 2022
This Country Hangman game written in Python.

country-name-guess-hangman-game This Country Hangman game written in Python. Visit https://example.com to play the game. Description How to play this

Aytaç Kaşoğlu 1 Oct 30, 2021
A minimal open source mtg-like tcg game made in python that can be played on a terminal emulator using a keyboard.

A minimal open source mtg-like tcg game made in python that can be played on a terminal emulator using a keyboard.

Amos 3 Aug 29, 2021
A multiplayer RPG Discord bot, where you play as a god.

To run Ensure your Python is up to date, and install packages from requirements.txt Duplicate secrets-template.yaml, and name it secrets.yaml Insert y

4 Jan 18, 2022
My first Minecraft CPU. Created in collaboration with Peer Carnes as a final project in CS 281: Architecture and Assembly at the University of Puget Sound

Minecraft CPU This is my first ever Minecraft CPU, created in collaboration with Peer Carnes. We created a custom assembly language, including an asse

Andy Chamberlain 4 Oct 10, 2022
Finding a method to objectively quantify skill expression in games, using reinforcement learning

Analyzing Skill Expression in Games This is a repo where I describe a method to measure the amount of skill expression games have. Table of Contents M

Marcus Chiam 4 Nov 19, 2022
Visualizing and learning from games on chess.com

Better Your Chess What for? This project aims to help you learn from all the chess games you've played online, starting with a simple way to download

Luc d'Hauthuille 0 Apr 17, 2022
Use different orders of N-gram model to play Hangman game.

Hangman game The Hangman game is a game whereby one person thinks of a word, which is kept secret from another person, who tries to guess the word one

ZavierYang 4 Oct 11, 2022
HackNC 2021 Project

pyTunes HackNC 2021 Project Setting Up Once the repo is cloned, install the requirements through pip install -r ./requirements.txt Once that is done,

Demo 1 Nov 07, 2021
🎅 Celebrating 2021 Christmas with the development of this game

ChristmasGame (DEVELOPING) 🎅 Celebrating Christmas with the development of this game You can also use this engine to create your game too, just empty

Érik Freitas 5 Jan 10, 2022