-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
mat2 mat2Identity() { | ||
return mat2( 1., 0., 0., 1. ); | ||
} | ||
|
||
// https://thebookofshaders.com/08/ | ||
mat2 mat2Rotate(float angle){ | ||
float c = cos(angle); | ||
float s = sin(angle); | ||
|
||
return mat2( c, -s, s, c ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma include <tests/fragment> | ||
#pragma include "mat2" | ||
|
||
void testMatEquals( inout TestSuite suite, int id, mat2 m, mat2 target ) { | ||
for( int i = 0; i < 2; i ++ ) { | ||
for( int j = 0; j < 2; j ++ ) { | ||
assert( suite, id + i*2 + j, m[i][j] == target[i][j] ); | ||
} | ||
} | ||
} | ||
|
||
void tests( inout TestSuite suite ) { | ||
|
||
mat2 uninitialized; | ||
|
||
mat2 zero = mat2( 0., 0., 0., 0. ); | ||
testMatEquals( suite, 10, uninitialized, zero ); | ||
|
||
mat2 reference = mat2( 0., 1., 2., 3. ); | ||
|
||
mat2 refByIdentity = reference * mat2Identity(); | ||
testMatEquals( suite, 30, refByIdentity, reference ); | ||
|
||
mat2 vec = mat2( vec2( 0., 1. ), vec2( 2., 3. ) ); | ||
testMatEquals( suite, 40, vec, reference ); | ||
|
||
mat2 manual; | ||
manual[0] = vec2( 0., 1. ); | ||
manual[1].yx = vec2( 3., 2. ); | ||
testMatEquals( suite, 50, manual, reference ); | ||
|
||
} |