Home > matrix_math

matrix_math

Matrix_math is a project mainly written in OBJECTIVE-C and C, it's free.

Objective C example on how to make a 3D effect using matrix multiplication

== MatrixMath

This app is an example of how to produce a 3D effect using simple math.

== How does it work?

In the core of this example is the following function:

  • (void) transform:(NSArray *)pts yrt:(CGFloat)yrt zrt:(CGFloat)zrt { if (pts==nil) return;

    CGFloat c1, s1, c2, s2;

    c1 = (CGFloat) cos(zrt); s1 = (CGFloat) sin(zrt); c2 = (CGFloat) cos(yrt); s2 = (CGFloat) sin(yrt);

    for (Point3D p in pts) { float x = p.x c1 c2 - p.y s2 - p.z c2 s1; float y = p.x c1 s2 + p.y c2 - p.z s1 s2; float z = p.x s1 + 0 + p.z * c1;

    p.x = x; 
    p.y = y; 
    p.z = z; 

    } }

It accepts a list of 3D points, Y rotation delta and Z rotation delta. It then transforms all of the points based on the rotation deltas. To display the points, use the x and z coordinates.

== How to test this example?

Download the code and run it. Drag your finger on the screen and see what you get.

Previous:Test-project