Code Monkey home page Code Monkey logo

vecmath's Introduction

VecMath

VecMath is a versatile C++ utility for vector and matrix mathematics. It provides a collection of templated functions to perform common operations on 3D and 4D vectors, as well as 4x4 matrices. This library is ideal for applications in graphics programming, physics simulations, and any other domain requiring efficient and robust vector and matrix math.

Features

  • Vector Operations (Vec3 & Vec4):

    • Dot product
    • Cross product (Vec3)
    • Normalization
    • Addition
    • Subtraction
    • Scalar multiplication
    • Component-wise multiplication
    • Projection
    • Reflection
    • Linear interpolation (lerp)
    • Clamping
    • Absolute value
    • Matrix-vector multiplication
  • Matrix Operations (Mat4):

    • Transpose
    • Identity matrix creation
    • Scaling transformation
    • Translation transformation
    • Matrix-matrix multiplication

Usage

Including VecMath

To use VecMath in your project, include the header file:

#include "VecMath.h"

Example Usage

Here's an example of how you might use VecMath to perform some basic operations:

#include "VecMath.h"
#include <iostream>

int main() {
    Vec3<float> vec1(1.0f, 2.0f, 3.0f);
    Vec3<float> vec2(4.0f, 5.0f, 6.0f);

    // Dot product
    float dotProduct = VecMath::dot(vec1, vec2);
    std::cout << "Dot product: " << dotProduct << std::endl;

    // Cross product
    Vec3<float> crossProduct = VecMath::cross(vec1, vec2);
    std::cout << "Cross product: (" << crossProduct.x << ", " << crossProduct.y << ", " << crossProduct.z << ")" << std::endl;

    // Normalization
    Vec3<float> normalizedVec = VecMath::normalize(vec1);
    std::cout << "Normalized vector: (" << normalizedVec.x << ", " << normalizedVec.y << ", " << normalizedVec.z << ")" << std::endl;

    return 0;
}

vecmath's People

Contributors

cvs0 avatar

Stargazers

LockScript avatar  avatar

Watchers

 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.