Coder Social home page Coder Social logo

hlslmath's Introduction

HLSL's Math library Build Status License: Unlicense

Vectors and matrices for based on HLSL language for C++.

License

This library is unlicensed.

Build

cd tools

# Unix or OS X (require gcc)
make
./build --output=<output> --namespace=<namespace>

# Windows (has prebuilt)
# `make` if you build new executor
build.exe --output=<output> --namespace=<namespace>

Scalar types

  • int
  • uint
  • bool
  • float
  • double
  • fixed
  • half
  • short
  • ushort
  • long
  • ulong

Template types

  • Vector 2, 3, 4 (float, int, uint, bool)
  • Matrix 2x2, 3x3, 4x4 (float, int, uint, bool)
  • Matrix 2x3, 2x4
  • Matrix 3x2, 3x4
  • Matrix 4x2, 4x3
  • Quaternion: present as float4, qmul, qinverse, qconj, qeuler

Examples

...
float3 position;
float3 scalation;
float3 axis;
float  angle;

// Initialize your transform with deprecated API
//  - Have some issues to implements
//  - More cleaner for some guys are familiar with '::'
//  - Will be remove because data & code should be seperate from the API, you can use your own code on float4x4 (or any type) if you know that give better result

float4x4 translateMatrix = float4x4::translate(position);
float4x4 scalationMatrix = float4x4::scale(scalation);
float4x4 axisAngleMatrix = float4x4::rotate(axis, angle);

float4x4 modelMatrix = mul(mul(translateMatrix, scalationMatrix), axisAngleMatrix);
float4x4 projectionMatrix = float4x4::perspective(radian(45.0f), WIDTH / HEIGHT, 0.0f, 100.0f);
float4x4 projectionMatrix2DOrIsometric = float4x4::ortho(0.0f, WIDTH, 0.0f, HEIGHT, 0.0f, 1.0f);

// Initialize your transform with new API
//  - Data and code seperates
//  - Easier to add extensions
//  - Prefix with type name, familiar to OpenGL, Vulkan guys

float4x4 positionMatrix = float4x4Translation(position);
float4x4 scalationMatrix = float4x4Scalation(scalation);

float4x4 xAxisRotationMatrix = float4x4RotationX(angle);
float4x4 yAxisRotationMatrix = float4x4RotationY(angle);
float4x4 zAxisRotationMatrix = float4x4RotationZ(angle);
float4x4 eulerRotationMatrix = float4x4Rotation(euler);
float4x4 quaternionRotationMatrix = float4x4Rotation(quaterion);
float4x4 axisAngleRotationMatrix = float4x4Rotation(axis, angle);

float4x4 modelMatrix = mul(mul(translateMatrix, scalationMatrix), axisAngleMatrix);
float4x4 projectionMatrix = float4x4Perspective(radian(45.0f), WIDTH / HEIGHT, 0.0f, 100.0f);
float4x4 projectionMatrix2DOrIsometric = float4x4Ortho(0.0f, WIDTH, 0.0f, HEIGHT, 0.0f, 1.0f);

// Apply matrix to your render pipeline
...

Documentation

Work in progress.

hlslmath's People

Contributors

maihd avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

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.