/* Sets up a zooming derotated infrared telescope seen against a cloudy sky background*/

global_settings{ max_trace_level 32}
#declare Anim = 1; #if ( Anim = 0 ) #declare k = 0.0; #else #declare k = clock; #end
#declare Ajusfocus = 0; #declare DeltaFocus = 5; // 0/1 Move focuscreen through focus
#declare Fieldcova = 1; // 0/1 Move object through field
#declare Maxtrace = 6;
#declare Defocus = 0;
#declare Slitmira = no;

#declare Band = 1; #declare Evalac = 0.001;
#declare Globalight = 0; #declare Nlytes = 12; #declare Nsunls = 2; // These are dummy values to be
#declare Reflmin = 0.05; #declare Reflmax = 0.25; #declare Reflfal = 0; // consistent with
#declare LensEmiss = 0; #declare Brlem = 0.0; #declare kEdgEmis = 0; #declare Amb = 0;
#declare Lnsam = 0; #declare kEdgam = 0.4;
#declare Ambnt = 0; #declare Maxtrace = 6; #declare ReflOn = yes; #declare Gst = 0;

#declare Aspherix = no; #declare IsoMaxtrace = 6; #declare IsoMaxgrad = 1.5;
#include "genfins.inc"

/* This is the zoom section */

#declare kz = pow(sin(pi*k),2);

#declare ThisOrigin = 0; #declare NextOrigin = 5.793;

// Surfaces 2324
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare LensBlnk = texture { GeBlnk } #declare LensOpen = material { GeLens92 }
#declare R1 = 34.049; #declare Thk = 3.000; #declare D1 = 19.0; #declare AspR1 = 0;
#declare R2 = 30.509; #declare Nex =11.375; #declare D2 = 19.5; #declare AspR2 = 0;
#include "lensmm.inc" #declare Lens2324 = object { LensMM translate z*ThisOrigin }

// Surfaces 2526
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare LensBlnk = texture { SeBlnk } #declare LensOpen = material { SeLens92 }
#declare R1 = 42.467; #declare Thk = 3.000; #declare D1 = 23.0; #declare AspR1 = 0;
#declare R2 = 62.775; #declare Nex = 1.166; #declare D2 = 24.0; #declare AspR2 = 0;
#include "lensmm.inc" #declare Lens2526 = object { LensMM translate z*ThisOrigin }

// Surfaces 2728
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare LensBlnk = texture { GeBlnk } #declare LensOpen = material { GeLens92 }
#declare R1 = 56.976; #declare Thk = 5.024; #declare D1 = 24.0; #declare AspR1 = 0;
#declare R2 = 39.356; #declare Nex =30.791-28.875*kz; #declare D2 = 25.0; #declare AspR2 = 0;
#include "lensmm.inc" #declare Lens2728 = object { LensMM translate z*ThisOrigin }

// Surface 2930
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare LensBlnk = texture { SeBlnk } #declare LensOpen = material { SeLens92 }
#declare R1 = 96.959; #declare Thk = 7.129; #declare D1 = 26.0; #declare AspR1 = 0;
#declare R2 = 214.915; #declare Nex =27.112-23.112*kz; #declare D2 = 26.0; #declare AspR2 = 0;
#include "lenspm.inc" #declare Lens2930 = object { LensPM translate z*ThisOrigin }

// Surface 3132
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare LensBlnk = texture { GaBlnk } #declare LensOpen = material { GaLens92 }
#declare R1 = 26.032; #declare Thk = 2.000; #declare D1 = 12.0; #declare AspR1 = 0;
#declare R2 = 88.704; #declare Nex = 2.000 ; #declare D2 = 13.0; #declare AspR2 = 0;
#include "lensmp.inc" #declare Lens3132 = object { LensMP translate z*ThisOrigin }

// Surface 3334
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare LensBlnk = texture { SeBlnk } #declare LensOpen = material { SeLens92 }
#declare R1 = 56.121; #declare Thk = 3.000; #declare D1 = 13.0; #declare AspR1 = 0;
#declare R2 = 37.221; #declare Nex =10.115+17.508*kz; #declare D2 = 14.0; #declare AspR2 = 0;
#include "lensmm.inc" #declare Lens3334 = object { LensMM translate z*ThisOrigin }

// Surface 3536
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare LensBlnk = texture { GeBlnk } #declare LensOpen = material { GeLens92 }
#declare R1 = 57.983; #declare Thk = 3.000; #declare D1 = 19.0; #declare AspR1 = 0;
#declare R2 = 49.296; #declare Nex = 1.000; #declare D2 = 20.0; #declare AspR2 = 0;
#include "lensmm.inc" #declare Lens3536 = object { LensMM translate z*ThisOrigin }

// Surface 3738
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare LensBlnk = texture { GeBlnk } #declare LensOpen = material { GeLens92 }
#declare R1 = 275.281; #declare Thk = 2.500; #declare D1 = 21.0; #declare AspR1 = 0;
#declare R2 = 110.072; #declare Nex = 22.000+34.777*kz; #declare D2 = 22.0; #declare AspR2 = 0;
#include "lensmm.inc" #declare Lens3738 = object { LensMM translate z*ThisOrigin }


#declare Group1 = object { Lens2324 }


#declare Zoomgp = union { object { Lens2526 }
object { Lens2728 }
object { Lens2930 }
object { Lens3132 }
object { Lens3334 }
object { Lens3536 }
object { Lens3738 }
}

// This is the first foldmirror

#declare Round = 0.5;
#declare Mirablank = intersection { superellipsoid { <Round, Round> scale 23}
plane { z,-3 inverse }
texture { Section }
}
#declare FoldMirror1 =
intersection { object { Mirablank }
plane { z,0 texture { Mirror } }
rotate -x*45
}


/* This is the section after the foldmirror */

#declare ThisOrigin = 0; #declare NextOrigin = 25.071;

// Surfaces 4142
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare LensBlnk = texture { SeBlnk } #declare LensOpen = material { SeLens92 }
#declare R1 = 122.093; #declare Thk = 4.450; #declare D1 = 19.0; #declare AspR1 = 0;
#declare R2 = 52.759; #declare Nex =49.519; #declare D2 = 20.0; #declare AspR2 = 0;
#include "lensmm.inc" #declare Lens4142 = object { LensMM translate z*ThisOrigin }

// Surfaces 57/58
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare LensBlnk = texture { GeBlnk } #declare LensOpen = material { GeLens92 }
#declare R1 = 132.860; #declare Thk = 3.000; #declare D1 = 19.0; #declare AspR1 = 0;
#declare R2 =2090.191; #declare Nex = 0.400; #declare D2 = 19.0; #declare AspR2 = 0;
#include "lenspp.inc" #declare Lens5758 = object { LensPP translate z*ThisOrigin }
#declare NextOrigin = ThisOrigin + Thk + Nex;

// Surfaces 5960
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare LensBlnk = texture { GeBlnk } #declare LensOpen = material { GeLens92 }
#declare R1 = 26.182; #declare Thk = 2.900; #declare D1 = 18.0; #declare AspR1 = 0;
#declare R2 = 23.107; #declare Nex =22.860; #declare D2 = 16.0; #declare AspR2 = 0;
#include "lenspp.inc" #declare Lens5960 = object { LensPP translate z*ThisOrigin }
#declare ScanMiraPos = NextOrigin; #debug concat (str(NextOrigin,9,3),"\n")

#declare Round = 0.25;
#declare Mirablank2 = intersection { superellipsoid { <Round, Round> scale 23}
plane { z,-2 inverse }
texture { Section }
}
#declare ScanMirror =
intersection { object { Mirablank2 }
plane { z,0 texture { Mirror } }
rotate y*(135+sin(34.2*k*pi)*6.5) translate z*ScanMiraPos
}

#declare DeroSecn = union { object { Lens4142 }
object { Lens5758 }
object { Lens5960 }
object { ScanMirror }
}

// This is the detector lens

#declare ThisOrigin = 0; #declare NextOrigin = 0.0;

// Surfaces 0203
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare Lensblnk = texture { GeBlnk } #declare LensOpen = material { GeLens92 }
#declare R1 = 83.457; #declare Thk = 3.500; #declare D1 = 20.0; #declare AspR1 = 0;
#declare R2 = 233.241; #declare Nex =39.000; #declare D2 = 19.0; #declare AspR2 = 0;
#include "lenspp.inc" #declare Lens0203 = object { LensPP translate z*ThisOrigin }
#debug concat (str(NextOrigin,9,3),"\n")
#declare Round = 0.25;
#declare Mirablank3 = intersection { superellipsoid { <Round, Round> scale 20 texture { Section } }
plane { z,-2 inverse pigment { image_map { jpeg "logo.jpg" } scale 40 }
finish { ambient 1.5 diffuse 0 }
}
}

#declare FoldPrism = intersection { box{-17,17 material { SeLens92 }}
plane { z,0
pigment { image_map { jpeg "logo.jpg" once} rotate y*180 translate <0.5,-0.5,0.5> scale 30}
finish { ambient 1.5 diffuse 0 }
rotate -y*45
}
translate z*25

}

// Surfaces 0506
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare Lensblnk = texture { GeBlnk } #declare LensOpen = material { GeLens92 }
#declare R1 = 16.708; #declare Thk = 4.548; #declare D1 = 12.0; #declare AspR1 = 0;
#declare R2 = 25.141; #declare Nex =16.970; #declare D2 = 11.0; #declare AspR2 = 0;
#include "lenspp.inc" #declare Lens0506 = object { LensPP translate z*ThisOrigin }


// Surfaces 0708
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare Lensblnk = texture { GeBlnk } #declare LensOpen = material { GeLens92 }
#declare R1 = 8.037; #declare Thk =10.000; #declare D1 = 7.0; #declare AspR1 = 0;
#declare R2 = 18.831; #declare Nex = 3.273; #declare D2 = 13.0; #declare AspR2 = 0;
#include "lensmm.inc" #declare Lens0708 = object { LensMM translate z*ThisOrigin }

// Surfaces 0910
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare Lensblnk = texture { GeBlnk } #declare LensOpen = material { GeLens92 }
#declare R1 = 32.688; #declare Thk = 7.598; #declare D1 = 18.0; #declare AspR1 = 0;
#declare R2 = 654.512; #declare Nex = 2.982; #declare D2 = 16.0; #declare AspR2 = 0;
#include "lenspm.inc" #declare Lens0910 = object { LensPM translate z*ThisOrigin }

// Surfaces 1112
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare Lensblnk = texture { GeBlnk } #declare LensOpen = material { GeLens92 }
#declare R1 = 38.855; #declare Thk = 3.000; #declare D1 = 14.0; #declare AspR1 = 0;
#declare R2 = 28.674; #declare Nex = 1.000; #declare D2 = 13.0; #declare AspR2 = 0;
#include "lenspp.inc" #declare Lens1112 = object { LensPP translate z*ThisOrigin }

// Surfaces 1314
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare Lensblnk = texture { SeBlnk } #declare LensOpen = material { SeLens92 }
#declare R1 = 28.674; #declare Thk = 5.256; #declare D1 = 13.0; #declare AspR1 = 0;
#declare R2 = 603.598; #declare Nex = 4.860; #declare D2 = 13.0; #declare AspR2 = 0;
#include "lenspm.inc" #declare Lens1314 = object { LensPM translate z*ThisOrigin }

// Surfaces 1516
#declare Refltype = 0; #declare Edgetype = 0; #include "lwglasses.inc"
#declare Lensblnk = texture { GeBlnk } #declare LensOpen = material { GeLens92 }
#declare R1 = 0.0; #declare Thk = 2.000; #declare D1 = 13.0; #declare AspR1 = 0;
#declare R2 = 0.0; #declare Nex = 1.425; #declare D2 = 13.0; #declare AspR2 = 0;
#include "plano.inc" #declare Lens1516 = object { Plano translate z*ThisOrigin }

#declare Detrpos = NextOrigin;

#declare DetrLens = union { object { Lens0203 }
object { FoldPrism }
union { object { Lens0506 }
object { Lens0708 }
object { Lens0910 }
object { Lens1112 }
object { Lens1314 }
object { Lens1516 }
translate -z*42.5
rotate y*90
translate z*25.5
translate x*17
}
rotate y*90
translate z*108
translate x*35
}

#declare Dewar = union { cylinder { 0, -z*80.0,13.5}
cone { -z*22,13.0,-z*30.0,22 }
cylinder { -z*30, -z*73.0,22.0}
cone { -z*73,22.0,-z*78.0,13.0}
cylinder { -z*70, -z*97.0,16.0}
cone { -z*90,17.0,-z*97.0,23.0}
texture { Nirelma }
}

#declare Hole = cylinder { -z*110,-z*90,2 inverse texture { Mirror }}
#declare Chamfa = plane { x,60 rotate z*45 translate y*3 }
#declare Flange = intersection { box {<-43,-50,-96>,<43,50,-105>}
object { Hole translate <-37, 43,0> }
object { Hole translate < 37, 43,0> }
object { Hole translate <-37,-43,0> }
object { Hole translate < 37,-43,0> }
object { Chamfa }
object { Chamfa rotate z*90 }
object { Chamfa rotate z*180}
object { Chamfa rotate z*270}
texture { Nirelma }
}

#declare DetrPack = union { object { Dewar }
object { Flange}
translate z*(NextOrigin-76.46+2) +x*60.5
}

union { object { Group1 rotate x*90 translate y*140 }
object { Zoomgp rotate x*90 translate y*140 }
object { FoldMirror1 }
object { #include "pekan.inc" Pekan scale 16 rotate z*90 rotate x*90 rotate z*90 translate z*77.04 rotate z*360*k}
object { DeroSecn }
object { DetrLens }
object { DetrPack }
rotate y*15
}


light_source { <3000,2000,2000 > color rgb 2.0 shadowless}
#declare Cam1 = camera {location <1000,100,200>*0.33 look_at z*80 angle 18*3 rotate z*20 look_at y*30}
#declare Cam2 = camera {location y*10000+z*20 sky -x look_at x*30+z*27 angle 1.2 }
#declare Cam3 = camera {location z*10000+z*20+y*50 sky y right 1.33*x look_at x*40+z*27+y*45 angle 0.85}
#declare Cam4 = camera {location <1000,100,500>*0.24 look_at z*80 angle 70 rotate z*20 look_at y*30}

camera { Cam4 }


#declare R2L = 1000; #declare WAL = 2*R2L; #declare Sun = 2*R2L*0.01;
#switch(Band)
#case(1) #declare Cula1 = rgb 1.0/3; #declare Cula2 = rgb<0.4,0.4,0.3>/3; #break
#case(0) #declare Cula1 = rgb 0.5/32; #declare Cula2 = rgb 0.4/3; #break
#case(3) #declare Cula1 = rgb 1.0; #declare Cula2 = rgb<0.4,0.4,0.3>; #break
#end

#declare Band = 1;
#switch( Band)
#case(1) #declare Skyscale = 0.5; #declare klowd = 0.25; #include "nuclouds.inc" #break
#case(3) #declare Skyscale = 0.5; #declare klowd = 0.25; #include "nuclouds.inc" #break
// #case(3) sphere { 0,1e5 pigment { rgb 0} finish { ambient 1 } hollow on} #break
#end


#if ( Globalight = 1 )
light_source { y*R2L 0.2 area_light x*Sun, z*Sun, Nsunls, Nsunls rotate -20 adaptive 1 jitter }
light_source { y*R2L Cula1 area_light x*WAL, z*WAL, Nlytes, Nlytes adaptive 1 jitter }
light_source { x*R2L Cula1 area_light y*WAL, z*WAL, Nlytes, Nlytes adaptive 1 jitter }
light_source { -x*R2L Cula1 area_light y*WAL, z*WAL, Nlytes, Nlytes adaptive 1 jitter }
light_source { z*R2L Cula1 area_light y*WAL, x*WAL, Nlytes, Nlytes adaptive 1 jitter }
light_source { -z*R2L Cula1 area_light y*WAL, x*WAL, Nlytes, Nlytes adaptive 1 jitter }
plane { y,-50 pigment { rgb <0.8,0.8,0.85> } finish { ambient 0 diffuse 0.8 } }
#end