Skip to content

Commit c7f1936

Browse files
committed
Update: Added 2 gl funcs to webgl, rotation for vector, improved handling of opengl shaders
1 parent 323536e commit c7f1936

File tree

6 files changed

+120
-145
lines changed

6 files changed

+120
-145
lines changed

build/wasm/build/webgl.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ function initializeWebglContext()
147147
glEnable ( cap ) {
148148
gl.enable(cap);
149149
},
150+
glFrontFace( face ) {
151+
gl.frontFace(face);
152+
},
153+
glCullFace( cull ) {
154+
gl.cullFace(cull);
155+
},
150156
glDisable ( cap )
151157
{
152158
gl.disable(cap);

modules/math/source/hip/math/matrix.d

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,21 @@ struct Matrix4
296296
(left+right)/(left-right), (top+bottom)/(bottom-top), -znear/(znear-zfar), 1
297297
]);
298298
}
299+
static Matrix4 perspective(float fovInRadians, uint width, uint height, float znear, float zfar)
300+
{
301+
import hip.math.utils;
302+
float aspect = cast(float)width / cast(float)height;
303+
float fovRatio = 1.0 / tan(fovInRadians/2);
304+
float rangeInv = 1.0 / cast(float)(zfar - znear);
305+
306+
return Matrix4([
307+
aspect * fovRatio, 0, 0, 0,
308+
0, fovRatio, 0, 0,
309+
0, 0, (znear + zfar) * rangeInv, 1,
310+
0, 0, -znear*zfar*rangeInv, 0
311+
]);
312+
313+
}
299314

300315
static Matrix4 alternateHandedness(Matrix4 mat)
301316
{

modules/math/source/hip/math/utils.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import hip.math.vector;
33

44
///There are some errors occurring when compiling with LDC
55
public import core.math: sqrt, cos, sin;
6+
public import core.stdc.math:tan;
67

78
pure @safe nothrow @nogc:
89

modules/math/source/hip/math/vector.d

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,18 @@ struct Vector(uint N, T)
227227
static if(N == 3)
228228
return VectorN(x*c - y*s, y*c + s*x, z);
229229
else
230-
return Vector!(N, T)(x*c - y*s, y*c + s*x, z, w);
230+
return VectorN(x*c - y*s, y*c + s*x, z, w);
231+
}
232+
233+
VectorN rotateXZ(float radians)
234+
{
235+
const float c = cos(radians);
236+
const float s = sin(radians);
237+
238+
static if(N == 3)
239+
return VectorN(x*c - z*s, y, z*c + s*x);
240+
else
241+
return VectorN(x*c - z*s, y, z*c + s*x, w);
231242
}
232243
}
233244

0 commit comments

Comments
 (0)