// File: /workspace/github_c_makefile_star2_O2/AlexCharlton[P]Hyperscene/src/camera.c
// Function: hpsUpdateCamera
void hpsUpdateCamera(HPScamera *camera){
    HPScamera *c = camera;
    float cameraMat[16];
    switch (camera->style){
    case HPS_ORBIT:
    {
        float cosPitch = cos(c->rotation.y);
        float sinPitch = sin(c->rotation.y);
        float sinYaw = sin(c->rotation.x);
        float cosYaw = cos(c->rotation.x);
        c->position.x = c->object.x + c->rotation.w * cosPitch * sinYaw;
        c->position.y = c->object.y + c->rotation.w * sinPitch;
        c->position.z = c->object.z + c->rotation.w * cosPitch * cosYaw;
        hpmYPRRotation(c->rotation.x, -c->rotation.y, c->rotation.z, cameraMat);
        hpmTranslate((float *) &c->position, cameraMat);
        hpmCameraInverse(cameraMat, c->view);
        break;
    }
    case HPS_LOOK_AT:
        hpmLookAt((float *) &c->position, (float *) &c->object, (float *) &c->up, 
                  c->view);
        break;
    case HPS_POSITION:
        hpmQuaternionRotation((float *) &c->rotation, cameraMat);
        hpmTranslate((float *) &c->position, cameraMat);
        hpmCameraInverse(cameraMat, c->view);
        break;
    case HPS_FIRST_PERSON:
        hpmYPRRotation(-c->rotation.x, c->rotation.y, c->rotation.z, cameraMat);
        hpmTranslate((float *) &c->position, cameraMat);
        hpmCameraInverse(cameraMat, c->view);
        break;
    default:
        fprintf(stderr, "Camera does not have a valid style\n");
        exit(EXIT_FAILURE);
    }
    hpmMultMat4(c->projection, c->view, c->viewProjection);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x70, %rsp
movl 0x8(%rdi), %eax
cmpq $0x3, %rax
ja 0x80a4
movq %rdi, %rbx
leaq 0x222a(%rip), %rcx      # 0xa180
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x68(%rbx), %rdi
leaq 0x30(%rsp), %r14
movq %r14, %rsi
callq 0x4050
jmp 0x8051
cvtss2sd 0x6c(%rbx), %xmm0
callq 0x43b0
cvtsd2ss %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
cvtss2sd 0x6c(%rbx), %xmm0
callq 0x4260
movaps %xmm0, 0x10(%rsp)
cvtss2sd 0x68(%rbx), %xmm0
callq 0x4260
movaps %xmm0, (%rsp)
cvtss2sd 0x68(%rbx), %xmm0
callq 0x43b0
cvtsd2ss %xmm0, %xmm0
movss 0x74(%rbx), %xmm1
movaps 0x20(%rsp), %xmm5
mulss %xmm1, %xmm5
movapd (%rsp), %xmm2
unpcklpd 0x10(%rsp), %xmm2       # xmm2 = xmm2[0],mem[0]
cvtpd2ps %xmm2, %xmm2
leaq 0xc(%rbx), %r14
movsd 0x24(%rbx), %xmm3
movaps %xmm5, %xmm4
unpcklps %xmm1, %xmm4            # xmm4 = xmm4[0],xmm1[0],xmm4[1],xmm1[1]
mulps %xmm2, %xmm4
addps %xmm3, %xmm4
movlps %xmm4, 0xc(%rbx)
mulss %xmm0, %xmm5
addss 0x2c(%rbx), %xmm5
movss %xmm5, 0x14(%rbx)
movss 0x68(%rbx), %xmm0
movss 0x6c(%rbx), %xmm1
xorps 0x2038(%rip), %xmm1     # 0xa040
movss 0x70(%rbx), %xmm2
leaq 0x30(%rsp), %r15
movq %r15, %rdi
callq 0x4160
movq %r14, %rdi
movq %r15, %rsi
callq 0x4060
leaq 0x78(%rbx), %rsi
movq %r15, %rdi
jmp 0x8064
movss 0x68(%rbx), %xmm0
xorps 0x2006(%rip), %xmm0     # 0xa040
movss 0x6c(%rbx), %xmm1
movss 0x70(%rbx), %xmm2
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x4160
leaq 0xc(%rbx), %rdi
movq %r14, %rsi
callq 0x4060
leaq 0x78(%rbx), %rsi
movq %r14, %rdi
callq 0x41c0
jmp 0x8080
leaq 0xc(%rbx), %rdi
leaq 0x24(%rbx), %rsi
leaq 0x18(%rbx), %rdx
leaq 0x78(%rbx), %rcx
callq 0x41b0
leaq 0xb8(%rbx), %rdi
leaq 0x78(%rbx), %rsi
addq $0xf8, %rbx
movq %rbx, %rdx
callq 0x4130
addq $0x70, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq 0x5f4d(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x20ef(%rip), %rdi      # 0xa1a4
pushq $0x23
popq %rsi
pushq $0x1
popq %rdx
callq 0x44a0
pushq $0x1
popq %rdi
callq 0x4490