// File: /workspace/github_cpp_makefile_star2_O1/matthewarcus[P]mmps/transform.cpp
// Function: Transform::Init(TransformParams const&)
void Transform::Init(const TransformParams& params)
{
  m.Identity();
  m = m * Matrix3(ZAxis, params.turn);
  m = m * Matrix3(XAxis, params.tilt);
  m = m * Matrix3(YAxis, params.lat);
  m = m * Matrix3(ZAxis, params.lon);

  // Construct the inverse matrix
  minv.Identity();
  minv = minv * Matrix3(ZAxis,-params.lon);
  minv = minv * Matrix3(YAxis,-params.lat);
  minv = minv * Matrix3(XAxis,-params.tilt);
  minv = minv * Matrix3(ZAxis,-params.turn);

  // Construct the sun parameters
  if (!params.sun) {
    sunx = 0.0;
    suny = 0.0;
    sunz = 0.0;
  } else {
    // We will use the astronomical day, starting at midnight (at Greenwich)
    // And start the year at the spring equinox
    // Need the vector to the sun.
    double date = params.date-80;
    while (date < 0) date += 365;
    while (date >= 365) date -= 365;
    date = 2 * pi *date / 365;
    double sheight = sunheight(date);
    double q = sqrt(1-sqr(sheight));
    // params.time is mean time, convert to apparent time
    double eot = equationoftime(date) * 2.0 * pi/(60.0 * 60.0 * 24.0);
    // AT = MT + EOT
    double atime = params.time + eot;
    sunx = -cos(atime) * q;
    suny =  sin(atime) * q;
    sunz =  sheight;
    // fprintf (stderr, "Sun: %f %f\n", degrees(asin(sunz)), hours(atan2(suny,-sunx)));
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe0, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x8(%rdi), %r15
movq %r15, %rdi
callq 0x5470
movsd 0x8(%r14), %xmm0
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movl $0x2, %esi
callq 0x54b0
leaq 0x90(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x5756
movl $0x9, %ecx
movq %r15, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movb 0x48(%r13), %al
movb %al, 0x50(%rbx)
movsd (%r14), %xmm0
leaq 0x40(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x54b0
leaq 0x90(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x5756
movl $0x9, %ecx
movq %r15, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movb 0x48(%r13), %al
movb %al, 0x50(%rbx)
movsd 0x18(%r14), %xmm0
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movl $0x1, %esi
callq 0x54b0
leaq 0x90(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x5756
movl $0x9, %ecx
movq %r15, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movb 0x48(%r13), %al
movb %al, 0x50(%rbx)
movsd 0x20(%r14), %xmm0
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movl $0x2, %esi
callq 0x54b0
leaq 0x90(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x5756
movl $0x9, %ecx
movq %r15, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movb 0x48(%r13), %al
movb %al, 0x50(%rbx)
leaq 0x58(%rbx), %r15
movq %r15, %rdi
callq 0x5470
movsd 0x20(%r14), %xmm0
xorps 0x72cb(%rip), %xmm0     # 0xd070
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movl $0x2, %esi
callq 0x54b0
leaq 0x90(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x5756
movl $0x9, %ecx
movq %r15, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movb 0x48(%r13), %al
movb %al, 0xa0(%rbx)
movsd 0x18(%r14), %xmm0
xorps 0x727e(%rip), %xmm0     # 0xd070
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movl $0x1, %esi
callq 0x54b0
leaq 0x90(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x5756
movl $0x9, %ecx
movq %r15, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movb 0x48(%r13), %al
movb %al, 0xa0(%rbx)
movsd (%r14), %xmm0
xorps 0x7232(%rip), %xmm0     # 0xd070
leaq 0x40(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x54b0
leaq 0x90(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x5756
movl $0x9, %ecx
movq %r15, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movb 0x48(%r13), %al
movb %al, 0xa0(%rbx)
movsd 0x8(%r14), %xmm0
xorps 0x71e8(%rip), %xmm0     # 0xd070
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movl $0x2, %esi
callq 0x54b0
leaq 0x90(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x5756
movl $0x9, %ecx
movq %r15, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movb 0x48(%r13), %al
movb %al, 0xa0(%rbx)
cmpb $0x0, 0x78(%r14)
je 0x5f79
movsd 0x90(%r14), %xmm0
addsd 0x753c(%rip), %xmm0     # 0xd420
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x5f00
movsd 0x7532(%rip), %xmm2     # 0xd428
addsd %xmm2, %xmm0
ucomisd %xmm0, %xmm1
ja 0x5ef6
ucomisd 0x7520(%rip), %xmm0     # 0xd428
jb 0x5f24
movsd 0x751e(%rip), %xmm1     # 0xd430
movsd 0x750e(%rip), %xmm2     # 0xd428
addsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jae 0x5f1a
movsd %xmm0, 0x38(%rsp)
fldl 0x38(%rsp)
fmull 0x7104(%rip)            # 0xd038
fdivs 0x758e(%rip)            # 0xd4c8
fstpl 0x30(%rsp)
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0xa52a
movsd %xmm0, 0x18(%rsp)
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd 0x70e3(%rip), %xmm0     # 0xd048
subsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x5f93
sqrtsd %xmm0, %xmm0
jmp 0x5f98
xorps %xmm0, %xmm0
movups %xmm0, 0xa8(%rbx)
movq $0x0, 0xb8(%rbx)
jmp 0x601e
callq 0x4190
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0xa2c6
addsd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
fldl 0x28(%rsp)
fmull 0x704b(%rip)            # 0xd008
fdivs 0x7509(%rip)            # 0xd4cc
fstpl 0x20(%rsp)
movsd 0x88(%r14), %xmm0
addsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x4380
xorpd 0x7087(%rip), %xmm0     # 0xd070
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, 0xa8(%rbx)
movsd 0x8(%rsp), %xmm0
callq 0x4070
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, 0xb0(%rbx)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0xb8(%rbx)
addq $0xe0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop