Giter Site home page Giter Site logo

nicklockwood / vectormath Goto Github PK

View Code? Open in Web Editor NEW
364.0 364.0 45.0 67 KB

A Swift library for Mac and iOS that implements common 2D and 3D vector and matrix functions, useful for games or vector-based graphics

License: MIT License

Swift 100.00%

vectormath's People

Contributors

billhsu avatar harlanhaskins avatar jiropole avatar milpitas avatar nicklockwood avatar toco 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vectormath's Issues

Matrix3 / 4 multiplier order

Correct me if I'm wrong or midunderstangind something, but I think the order of matrix multiplication of VectorMath library seems reversed.

    public static func *(lhs: Matrix3, rhs: Matrix3) -> Matrix3 {
        
        return Matrix3(
            lhs.m11 * rhs.m11 + lhs.m21 * rhs.m12 + lhs.m31 * rhs.m13,
            .....
    }

    public static func *(lhs: Matrix4, rhs: Matrix4) -> Matrix4 {
        
        var m = Matrix4.identity
        
        m.m11 = lhs.m11 * rhs.m11 + lhs.m21 * rhs.m12
        m.m11 += lhs.m31 * rhs.m13 + lhs.m41 * rhs.m14
       ....
    }

According to this, algorithm of two matrices is something like this:

screen shot 2017-03-13 at 9 22 22 pm

where I believe VectorMath's * operator represents ABin this equation. (meaning you can write A * B in swift to do same calculation.) If so, the function's lhs and rhs is reversed and since Matrix multiplication is not commutative, it'll produce different results.

I did write a simple Matrix4 <-> CATransform3D conversion code and check something like this:

    let m1 = Matrix4( /* init with some values */)
    let m2 = Matrix4( /* init with some other values */)

    let con1 = CATransform3DConcat(CATransform3D(m1), CATransform3D(m2) )
    let con2 = m1 * m2
    XCTAssertTrue(Matrix4(con1) == con2)  // this should pass, but fails

    let con3 = m2 * m1
    XCTAssertFalse(Matrix4(con1) == con3)  // this should pass, but fails

Here's what CATransform3DConcats document says:

Concatenate 'b' to 'a' and return the result: t' = a * b.

I think it would be better to have reversed order for those methods.

Swift 3 compatibility

Hey, I'd love to see this lib available in Swift 3 so I can implement it in my project.

Thanks ๐Ÿ˜„

normalize() maybe wrong?

func normalized() -> Vector4 {
    let lengthSquared = self.lengthSquared
    if lengthSquared ~= 0 || lengthSquared ~= 1 {
        return self
    }
    return self / sqrt(lengthSquared)
}

should be " lengthSquared == 0 || lengthSquared == 1 "

Make extensions public

put the "public" keyword before the extension declarations, so that they export properly from bundle to bundle/app

example:

public extension SCNVector3 {
    init(_ v: Vector3) {
        self.init(x: SCNFloat(v.x), y: SCNFloat(v.y), z: SCNFloat(v.z))
    }
}

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.