This file contains hidden or 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
| macro CANVAS_SET_ALPHA col { ; prepare mmx registers (alpha) by col (0xAAxxxxxx) | |
| push col | |
| shr col, 24 | |
| pxor mm5, mm5 | |
| movd mm7, col | |
| pshufw mm7, mm7, 0 | |
| neg col | |
| add col, 256 | |
| movd mm6, col | |
| pshufw mm6, mm6, 0 |
This file contains hidden or 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
| b = 1 << i; | |
| x = (0x287A & b) != 0 | |
| y = (0x02AF & b) != 0 | |
| z = (0x31E3 & b) != 0 |
This file contains hidden or 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
| vec3 cuteSort(vec3 n) { | |
| float a = min(min(n.x, n.y), n.z); | |
| float b = max(max(n.x, n.y), n.z); | |
| return vec3(a, n.x + n.y + n.z - a - b, b); | |
| } |
This file contains hidden or 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
| void getBasis(const vec3 &n, vec3 &t, vec3 &b) { | |
| if (n.z < -0.9999999f) { | |
| t = vec3( 0.0f, -1.0f, 0.0f); | |
| b = vec3(-1.0f, 0.0f, 0.0f); | |
| return; | |
| } | |
| const float x = 1.0f / (1.0f + n.z); | |
| const float y = -n.x*n.y*x; | |
| t = vec3(1.0f - n.x*n.x*x, y, -n.x); | |
| b = vec3(b, 1.0f - n.y*n.y*x, -n.y); |
This file contains hidden or 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
| // Computes signed distance between a point and a plane | |
| // vPlane: Contains plane coefficients (a,b,c,d) where: ax + by + cz = d | |
| // vPoint: Point to be tested against the plane. | |
| float DistanceToPlane( vec4 vPlane, vec3 vPoint ) | |
| { | |
| return dot(vec4(vPoint, 1.0), vPlane); | |
| } | |
| // Frustum cullling on a sphere. Returns > 0 if visible, <= 0 otherwise | |
| float CullSphere( vec4 vPlanes[6], vec3 vCenter, float fRadius ) |
This file contains hidden or 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
| vec4 dx = vec4(0.25, 0.96, -0.25, -0.96) * uTexelSize.xyxy + vTexCoord.xyxy; | |
| vec4 dy = vec4(0.25, 0.96, -0.25, -0.96) * uTexelSize.yxyx + vTexCoord.yxyx; | |
| vec4 average = (texture2D(sTex, dx.zy) + texture2D(sTex, dx.xw) + | |
| texture2D(sTex, dy.yx) + texture2D(sTex, dy.wz)) * 0.25; |
This file contains hidden or 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
| bool AABB::intersect(const vec3 &rayPos, const vec3 &rayDir, float &t) const { | |
| float t1 = INF, t0 = -t1; | |
| for (int i = 0; i < 3; i++) | |
| if (rayDir[i] != 0) { | |
| float lo = (min[i] - rayPos[i]) / rayDir[i]; | |
| float hi = (max[i] - rayPos[i]) / rayDir[i]; | |
| t0 = _max(t0, _min(lo, hi)); | |
| t1 = _min(t1, _max(lo, hi)); | |
| } else | |
| if (rayPos[i] < min[i] || rayPos[i] > max[i]) |
This file contains hidden or 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
| // quat | |
| const quat quat::IDENTITY(0.0f, 0.0f, 0.0f, 1.0f); | |
| const quat quat::ZERO(0.0f, 0.0f, 0.0f, 0.0f); | |
| quat::quat() {} | |
| quat::quat(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {} | |
| quat::quat(const vec3 &axis, float angle) { | |
| angle *= 0.5f; | |
| float s = sinf(angle); |
This file contains hidden or 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
| bool Circle::intersect(const Segment2D &segment, vec2 &n, float &t) const { | |
| vec2 ap = center - segment.a; | |
| vec2 ab = segment.b - segment.a; | |
| float dab = ab.dot(ab); | |
| if (dab == 0.0f) return false; | |
| t = clamp(ap.dot(ab) / dab, 0.0f, 1.0f); | |
| n = center - (segment.a + ab * t); | |
| t = n.length2(); |
This file contains hidden or 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
| #include <stdio.h> | |
| #include <math.h> | |
| #include <windows.h> | |
| #include <gl/GL.h> | |
| // simulation | |
| #define SIZE_X 129 | |
| #define SIZE_Y 129 | |
| #define RIGID_FACTOR 0.5f | |
| #define DAMPING_FACTOR 0.998f |