// File: IsaacLaw12[P]RayTracer/./src/WaveObject.cpp
// Function: WaveObject::wave_function(double, double)
Eigen::Vector3d WaveObject::wave_function(double offset_one, double offset_two){
    double current_time = time / 60;
    double total = 0;
    Eigen::Vector3d point = first_corner + offset_one * direction_one + offset_two * direction_two;
    // direction one waves
    for (auto wave:component_waves){
        //double sine = sin(offset_one * offset_two + time);
        double sine = (sin(wave.direction.dot(point)*wave.frequency + current_time*wave.phase_constant)+1)/2;
        total += wave_height * wave.amplitude * pow(sine, 2);
    }
    total = total / component_waves.size();
    Eigen::Vector3d result = point + total * surface_normal;
    return result;
}

// Assembly:
subq $0x228, %rsp            # imm = 0x228
movq %rdi, 0x18(%rsp)
movq %rdi, %rax
movq %rax, 0x20(%rsp)
movq %rdi, 0x220(%rsp)
movq %rsi, 0x218(%rsp)
movsd %xmm0, 0x210(%rsp)
movsd %xmm1, 0x208(%rsp)
movq 0x218(%rsp), %rdx
movq %rdx, 0x30(%rsp)
movsd 0x190(%rdx), %xmm0
movsd 0x1ecb5(%rip), %xmm1    # 0x6ed48
divsd %xmm1, %xmm0
movsd %xmm0, 0x200(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x1f8(%rsp)
movq %rdx, %rax
addq $0x1e0, %rax            # imm = 0x1E0
movq %rax, 0x28(%rsp)
addq $0x210, %rdx            # imm = 0x210
leaq 0x110(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0xa310
movq 0x28(%rsp), %rsi
leaq 0x138(%rsp), %rdi
leaq 0x110(%rsp), %rdx
callq 0xa2a0
movq 0x30(%rsp), %rdx
addq $0x228, %rdx            # imm = 0x228
leaq 0xe8(%rsp), %rdi
leaq 0x208(%rsp), %rsi
callq 0xa310
leaq 0x170(%rsp), %rdi
leaq 0x138(%rsp), %rsi
leaq 0xe8(%rsp), %rdx
callq 0xa3d0
leaq 0x1e0(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x50b90
movq 0x30(%rsp), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rdi
callq 0x510f0
movq %rax, 0xd8(%rsp)
movq 0xe0(%rsp), %rdi
callq 0x51120
movq %rax, 0xd0(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x51150
testb $0x1, %al
jne 0x5019e
jmp 0x5027d
leaq 0xd8(%rsp), %rdi
callq 0x51190
movq %rax, %rsi
leaq 0xa0(%rsp), %rdi
callq 0x511a0
leaq 0xa0(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
callq 0x1e440
movsd 0xc0(%rsp), %xmm2
movsd 0x200(%rsp), %xmm1
mulsd 0xc8(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x40b0
movq 0x30(%rsp), %rax
movsd 0xce03(%rip), %xmm1     # 0x5d008
addsd %xmm1, %xmm0
movsd 0x16a4f(%rip), %xmm1    # 0x66c60
divsd %xmm1, %xmm0
movsd %xmm0, 0x98(%rsp)
movsd 0x1c0(%rax), %xmm0
mulsd 0xb8(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x98(%rsp), %xmm0
movl $0x2, %edi
callq 0x511f0
movaps %xmm0, %xmm2
movsd 0x10(%rsp), %xmm0
movsd 0x1f8(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x1f8(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x51220
jmp 0x50180
movq 0x30(%rsp), %rdi
movsd 0x1f8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
addq $0x1a0, %rdi            # imm = 0x1A0
callq 0x51240
movsd 0x8(%rsp), %xmm0
movq 0x30(%rsp), %rdx
movq %rax, %xmm1
movaps 0x1eaac(%rip), %xmm2    # 0x6ed60
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x1eab0(%rip), %xmm2    # 0x6ed70
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x1f8(%rsp)
addq $0x240, %rdx            # imm = 0x240
leaq 0x38(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0xa310
leaq 0x60(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
leaq 0x38(%rsp), %rdx
callq 0xa2a0
movq 0x18(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x51260
movq 0x20(%rsp), %rax
addq $0x228, %rsp            # imm = 0x228
retq
nopl (%rax,%rax)