void Matrix4x4_ConcatRotate( matrix4x4 out, float angle, float x, float y, float z ) { matrix4x4 base, temp; Matrix4x4_Copy( base, out ); Matrix4x4_CreateRotate( temp, angle, x, y, z ); Matrix4x4_Concat( out, base, temp ); }
void recalcLightViewMats(light_t *l){ // printf("updatin"); //todo if it is attached, just grab the attached matrix (same as entities do it) Matrix4x4_CreateRotate(&l->view, l->angle[2], 0.0f, 0.0f, 1.0f); Matrix4x4_ConcatRotate(&l->view, l->angle[0], 1.0f, 0.0f, 0.0f); Matrix4x4_ConcatRotate(&l->view, l->angle[1], 0.0f, 1.0f, 0.0f); Matrix4x4_ConcatTranslate(&l->view, -l->pos[0], -l->pos[1], -l->pos[2]); // Matrix4x4_CreateFromQuakeEntity(&l->cam, l->pos[0], l->pos[1], l->pos[2], l->angle[2], l->angle[1], l->angle[0], 1.0); // Matrix4x4_CreateFromQuakeEntity(&l->cam, l->pos[0], l->pos[1], l->pos[2], l->angle[2], l->angle[1], l->angle[0], l->scale); Matrix4x4_Invert_Simple(&l->cam, &l->view); //temp? hack }
static void R_RotateSprite(const mspriteframe_t *frame, vec3_t origin, vec3_t left, vec3_t up, int edge, float dir_angle) { if(!(r_track_sprites_flags.integer & TSF_ROTATE)) { // move down by its size if on top, otherwise it's invisible if(edge == SIDE_TOP) VectorMA(origin, -(fabs(frame->up)+fabs(frame->down)), up, origin); } else { static float rotation_angles[5] = { 0, // no edge -90.0f, //top 0.0f, // left 90.0f, // bottom 180.0f, // right }; // rotate around the hotspot according to which edge it's on // since the hotspot == the origin, only rotate the vectors matrix4x4_t rotm; vec3_t axis; vec3_t temp; vec2_t dir; float angle; if(edge < 1 || edge > 4) return; // this usually means something went wrong somewhere, there's no way to get a wrong edge value currently dir[0] = frame->right + frame->left; dir[1] = frame->down + frame->up; // only rotate when the hotspot isn't the center though. if(dir[0] < MIN_EPSILON && dir[1] < MIN_EPSILON) { return; } // Now that we've kicked center-hotspotted sprites, rotate using the appropriate matrix :) // determine the angle of a sprite, we could only do that once though and // add a `qboolean initialized' to the mspriteframe_t struct... let's get the direction vector of it :) angle = atan(dir[1] / dir[0]) * 180.0f/M_PI; // we need the real, full angle if(dir[0] < 0.0f) angle += 180.0f; // Rotate around rotation_angle - frame_angle // The axis SHOULD equal r_refdef.view.forward, but let's generalize this: CrossProduct(up, left, axis); if(r_track_sprites_flags.integer & TSF_ROTATE_CONTINOUSLY) Matrix4x4_CreateRotate(&rotm, dir_angle - angle, axis[0], axis[1], axis[2]); else Matrix4x4_CreateRotate(&rotm, rotation_angles[edge] - angle, axis[0], axis[1], axis[2]); Matrix4x4_Transform(&rotm, up, temp); VectorCopy(temp, up); Matrix4x4_Transform(&rotm, left, temp); VectorCopy(temp, left); } }