void Camera_view_projection(Camera* const camera, mat4x4 matrix) { mat4x4 position_matrix, orientation_matrix, scale_matrix; mat4x4_translate( position_matrix, -camera->transform.position[0], -camera->transform.position[1], -camera->transform.position[2] ); quat q; quat_conj(q, camera->transform.orientation); mat4x4_from_quat(orientation_matrix, q); vec3 v = { 1.0f / camera->transform.scale[0], 1.0f / camera->transform.scale[1], 1.0f / camera->transform.scale[2] }; mat4x4 m; mat4x4_identity(m); mat4x4_scale_aniso(scale_matrix, m, v[0], v[1], v[2]); mat4x4_mul(matrix, scale_matrix, orientation_matrix); mat4x4_mul(matrix, matrix, position_matrix); mat4x4_mul(matrix, camera->projection, matrix); }
void quat_rotate(vec3_t *res, const quat_t *q, const vec3_t *v) { quat_t tq, itq, tv; quat_conj(&itq, q); tv = QUAT(0, *v); quat_mult(&tq, q, &tv); quat_mult(&tq, &tq, &itq); *res = tq.v; }
void vec_rotate(vector *v, const quat *q) { vector tmpv; quat vecq, q_inv; /* v = q * v * q' */ tmpv = *v; vecq.x = tmpv.x; vecq.y = tmpv.y; vecq.z = tmpv.z; vecq.w = 0.0f; q_inv = *q; quat_conj(&q_inv, &q_inv); quat_mul(&vecq, &vecq, &q_inv); quat_mul(&vecq, q, &vecq); v->x = vecq.x; v->y = vecq.y; v->z = vecq.z; }
void rTarcom::drawHUD() { if (!active) return; //glColor4f(0,0.1,0,0.2); glBegin(GL_QUADS); glVertex3f(1, 1, 0); glVertex3f(0, 1, 0); glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glEnd(); glPushMatrix(); { glScalef(0.5, 0.5, 1); glTranslatef(1, 1, 0); glColor4f(0.8, 0.8, 0.8, 0.5); glBegin(GL_LINE_STRIP); glVertex3f(-0.7, +0.7, 0); glVertex3f(+0.0, +0.0, 0); glVertex3f(+0.7, +0.7, 0); glEnd(); glColor4f(0.0, 0.4, 0.0, 0.5); Primitive::glDisk(16, 1.0f); const float r2 = 0.7; glColor4f(0.0, 0.6, 0.0, 0.5); glScalef(r2, r2, 1); Primitive::glDisk(16, 1.0f); glScalef(1.0 / r2, 1.0 / r2, 1); quat ori_; quat_cpy(ori_, ori0); quat_conj(ori_); glRotatef(90, 1, 0, 0); GLS::glRotateq(ori_); glRotatef(-90, 1, 0, 0); glPointSize(3); glBegin(GL_POINTS); { glColor4f(1, 1, 1, 1); glVertex3f(0, 0, 0); } glEnd(); for(rTarget* o: *far) { glBegin(GL_POINTS); { glColor4f(0.5, 0.5, 0.5, 1); if (o->hasTag(World::getInstance()->getGroup(FAC_RED))) glColor4f(1, 0, 0, 1); else if (o->hasTag(World::getInstance()->getGroup(FAC_GREEN))) glColor4f(0, 1, 0, 1); else if (o->hasTag(World::getInstance()->getGroup(FAC_BLUE))) glColor4f(0, 0, 1, 1); else if (o->hasTag(World::getInstance()->getGroup(FAC_YELLOW))) glColor4f(0, 1, 0, 1); assert(o->object != NULL); if (o->object->oid == selected) glColor4f(1, 0, 1, 1); float dx = o->pos0[0] - pos0[0]; float dz = o->pos0[2] - pos0[2]; float r = sqrtf(dx * dx + dz * dz); dx /= r; dz /= r; float f = 0.01 * r; if (f < r2) { glVertex3f(f * dx, -f * dz, 0); } else { float r3 = r2 + (1.1 - r2) * log(1 + (f - r2)); if (r3 < 1.0) { glVertex3f(r3 * dx, -r3 * dz, 0); } } } glEnd(); } } glPopMatrix(); }