void updateCam( Camera *cam ) { State *state = cam->state; /* update target orientation */ applyTorque( state ); quatSlerp( state->orientation, state->targetOrien, state->orientation, cam->smoothing ); quatNorm( state->orientation ); /* rotation matrix */ GLfloat rotaMatrix[16]; quatToMat(rotaMatrix, state->orientation); /* update orientation vectors */ mat4multVec3(rotaMatrix, baseUpVec, state->up ); mat4multVec3(rotaMatrix, baseRightVec, state->right ); mat4multVec3(rotaMatrix, baseForwardVec, state->forward ); // calc & update velocity float newVel[] = { state->velocity[0] + lerpStep(state->velocity[0], state->targetVelocity[0], cam->smoothing ), state->velocity[1] + lerpStep(state->velocity[1], state->targetVelocity[1], cam->smoothing ), state->velocity[2] + lerpStep(state->velocity[2], state->targetVelocity[2], cam->smoothing ) }; cpyBuf( state->velocity, newVel, 3 ); calcPosition( state->position, state, 1.0f); watch( "Camera Position ( %.1f, %.1f, %.1f )\n", state->position[0], state->position[1], state->position[2] ); // calc & store perspective cam->fov[0] += lerpStep( cam->fov[0], cam->fov[1], cam->smoothing ); mat4perspinf( cam->perspective, cam->nearClip, cam->fov[0], cam->aspectRatio ); }
uint32_t ComputeStep(uint32_t current_time) { if (current_time>next_lookup_time) { prev_lookup_time = next_lookup_time; prev_lookup_steps = next_lookup_steps; GetNextLookupValues(current_time); } if (next_lookup_time==current_time) return next_lookup_steps; return lerpStep(prev_lookup_time, next_lookup_time, prev_lookup_steps, next_lookup_steps, current_time); }