void rotateQ(mat4 target, quat q) { normQ(q); float xx = q[1] * q[1]; float yy = q[2] * q[2]; float zz = q[3] * q[3]; float xy = q[1] * q[2]; float xz = q[1] * q[3]; float wx = q[0] * q[1]; float wy = q[0] * q[2]; float wz = q[0] * q[3]; float yz = q[2] * q[3]; /* again, transposed */ float data[] = { 1 - 2.0f * (yy + zz), 2.0f * (xy + wz), 2.0f * (xz - wy), 0, 2.0f * (xy - wz), 1 - 2.0f * (xx + zz), 2.0f * (yz + wx), 0, 2.0f * (xz + wy), 2.0f * (yz - wx), 1 - 2.0f * (xx + yy), 0, 0, 0, 0, 1 }; _setData(target, data); }
void translate(mat4 target, float x, float y, float z) { float data[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1 }; _setData(target, data); }
void scale(mat4 target, float x, float y, float z) { float data[] = { x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1 }; _setData(target, data); }
// Hadshake response packet (see http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse) static void _requestHandshake(mysql_t *mysql) { ASSERT(mysql->state == MySQL_Handshake); _initRequest(mysql, 1); _setUInt4(&mysql->request, CLIENT_LONG_PASSWORD | CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION); // capabilities _setUInt4(&mysql->request, 8192); // maxpacketsize _setUInt1(&mysql->request, 8); // characterset _setPadding(&mysql->request, 23); // reserved bytes if (mysql->port->parameters.mysql.username) _setData(&mysql->request, mysql->port->parameters.mysql.username, strlen(mysql->port->parameters.mysql.username)); // username _setPadding(&mysql->request, 1); // NUL if (mysql->port->parameters.mysql.password) { _setUInt1(&mysql->request, SHA1_DIGEST_SIZE); // authdatalen _setData(&mysql->request, _password((char[SHA1_DIGEST_SIZE]){0}, mysql->port->parameters.mysql.password, mysql->response.data.handshake.authdata), SHA1_DIGEST_SIZE); // password
void perspective(mat4 target, float near, float far, float fov, float ratio) { float z_d = far - near; float e00 = 1 / tanf(RAD(fov / 2.0f)); float e11 = ratio * e00; float e22 = -1.0f * (far + near) / z_d; float e32 = -2.0f * near * far / z_d; /* already transposed to column-major */ float data[] = { e00, 0, 0, 0, 0, e11, 0, 0, 0, 0, e22, -1.0f, 0, 0, e32, 0 }; _setData(target, data); }
void perspectiveInf(mat4 target, float near, float fov, float ratio) { /* here, e22 and e32 are derived from taking the * limit of original e22 and e32 to infinity */ float e00 = 1 / tanf(RAD(fov / 2.0f)); float e11 = ratio * e00; float e22 = -1.0f; float e32 = -2.0f * near; /* already transposed to column-major */ float data[] = { e00, 0, 0, 0, 0, e11, 0, 0, 0, 0, e22, -1.0f, 0, 0, e32, 0 }; _setData(target, data); }