rl_raylib  1.1.10
rl_Ray.cc
1 // File: rl_Ray.cc
2 // Author: Terry Gaetz
3 
4 // --8<--8<--8<--8<--
5 //
6 // Copyright (C) 2006, 2007 Smithsonian Astrophysical Observatory
7 //
8 // This file is part of rl_raylib
9 //
10 // rl_raylib is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License
12 // as published by the Free Software Foundation; either version 2
13 // of the License, or (at your option) any later version.
14 //
15 // rl_raylib is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the
22 // Free Software Foundation, Inc.
23 // 51 Franklin Street, Fifth Floor
24 // Boston, MA 02110-1301, USA
25 //
26 // -->8-->8-->8-->8--
27 
28 #include <rl_raylib/rl_Ray.h>
29 #include <iostream>
30 #include <iomanip>
31 
32 using namespace std;
33 
34 //=========================================================================
35 // dtor, ctors, initializers...
36 
37 //-------------------------------------------------------------------------
38 // virtual destructor
39 
42 {}
43 
44 //=========================================================================
45 // mutators...
46 
47 //-------------------------------------------------------------------------
48 // reflect this ray's direction vector and polarization state.
49 
50 void rl_Ray::
51 reflect( dvm3_Vector const& normal,
52  rl_ReflectionCoefPOD const& rflcoef )
53 {
54  dvm3_Vector old_dir( dir_ );
55  reflect_direction_vector( normal );
56  pol_.reflect( normal, old_dir, dir_, rflcoef );
57 }
58 
59 //-------------------------------------------------------------------------
60 // translate to to bcs origin; rotate from std to bcs coordinates
61 
62 void rl_Ray::
63 translate_rotate( dvm3_Vector const& trans,
64  dvm3_RotMat const& rotmat )
65 {
66  rl_BasicRay::translate_rotate( trans, rotmat );
67  rl_Polarization tmp( pol_ );
68  tmp.rotate( pol_, rotmat );
69 }
70 
71 //-------------------------------------------------------------------------
72 // derotate back to std coordinates; detranslate back to std origin
73 
74 void rl_Ray::
75 derotate_detranslate( dvm3_Vector const& trans,
76  dvm3_RotMat const& rotmat )
77 {
78  rl_BasicRay::derotate_detranslate( trans, rotmat );
79  rl_Polarization tmp( pol_ );
80  tmp.derotate( pol_, rotmat );
81 }
82 
83 //-------------------------------------------------------------------------
84 // write out ray contents with optional pre and post comment strings
85 std::ostream& rl_Ray::
86 print_on( std::ostream& os, //i output stream
87  char const pre[], //i optional prefix comment
88  char const pst[] //i optional postfix comment
89  ) const
90 {
91  if ( ::strlen(pre) ) { os << pre; }
92  os.setf(ios::showpoint);
93  os.setf(ios::fixed);
94  os << setw(8) << id_ << " : ";
95  os << " " << setw(18) << energy_ << " : (";
96  pos_.print_on( os );
97  os << ") (" << setw(18);
98  dir_.print_on( os );
99  os << ")";
100  if ( ::strlen(pst) ) { os << pst; }
101  os << endl;
102 
103  if ( ::strlen(pre) ) { os << pre; }
104  os << setw(8) << id_ << " : ";
105  pol_.print_on( os );
106  if ( ::strlen(pst) ) { os << pst; }
107  os << endl;
108 
109  return os;
110 }
void translate_rotate(dvm3_Vector const &trans, dvm3_RotMat const &rotmat)
Translate to BCS origin and rotate from STD to BCS coordinates.
Definition: rl_Ray.cc:63
void derotate(rl_Polarization &derotated, dvm3_RotMat const &rot_mtx)
Rotate polarization state back from frame described by rot_mtx.
std::ostream & print_on(std::ostream &os, char const pre[]="", char const pst[]="") const
Write the ray contents with optional pre and post comment strings.
Definition: rl_Ray.cc:86
virtual ~rl_Ray()
Destructor.
Definition: rl_Ray.cc:41
void reflect(dvm3_Vector const &normal, rl_ReflectionCoefPOD const &rflcoef)
Reflect this ray's direction vector and polarization state.
Definition: rl_Ray.cc:51
void rotate(rl_Polarization &rotated, dvm3_RotMat const &rot_mtx)
Rotate polarization state to frame described by rot_mtx.
A Plain Ol' Data class representing complex reflection coefficients.
Encapsulates the polarization state of a ray.
void derotate_detranslate(dvm3_Vector const &trans, dvm3_RotMat const &rotmat)
Derotate back to std coordinates; detranslate back to std origin.
Definition: rl_Ray.cc:75