00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 inline
00024 Photon::Photon() :
00025 m_flags(0)
00026 {
00027 }
00028
00029 inline
00030 void Photon::SetPosition(const sheep::Point3 &position) {
00031 m_position[0] = static_cast<sheep::float32>(position.m_x);
00032 m_position[1] = static_cast<sheep::float32>(position.m_y);
00033 m_position[2] = static_cast<sheep::float32>(position.m_z);
00034 }
00035
00036 inline
00037 sheep::Point3 Photon::GetPosition() const {
00038 return sheep::Point3(m_position[0], m_position[1], m_position[2]);
00039 }
00040
00041 inline
00042 void Photon::SetPower(const Color3 &power) {
00043 #ifdef COMPRESS_PHOTON_POWER
00044 power.ConvertToRGBE(&m_power[0], &m_power[1], &m_power[2], &m_power[3]);
00045 #else
00046 m_power[0] = static_cast<sheep::float32>(power.m_r);
00047 m_power[1] = static_cast<sheep::float32>(power.m_g);
00048 m_power[2] = static_cast<sheep::float32>(power.m_b);
00049 #endif // COMPRESS_PHOTON_POWER
00050 }
00051
00052 inline
00053 void Photon::ScalePower(sheep::Real scale) {
00054 #ifdef COMPRESS_PHOTON_POWER
00055 Color3 c = Color3::ConvertFromRGBE(m_power[0], m_power[1], m_power[2], m_power[3]);
00056
00057 c *= scale;
00058
00059 c.ConvertToRGBE(
00060 &m_power[0],
00061 &m_power[1],
00062 &m_power[2],
00063 &m_power[3]);
00064 #else
00065 m_power[0] *= static_cast<sheep::float32>(scale);
00066 m_power[1] *= static_cast<sheep::float32>(scale);
00067 m_power[2] *= static_cast<sheep::float32>(scale);
00068 #endif // COMPRESS_PHOTON_POWER
00069 }
00070
00071 inline
00072 Color3 Photon::GetPower() const {
00073 #ifdef COMPRESS_PHOTON_POWER
00074 return Color3::ConvertFromRGBE(m_power[0], m_power[1], m_power[2], m_power[3]);
00075 #else
00076 return Color3(m_power[0], m_power[1], m_power[2]);
00077 #endif // COMPRESS_PHOTON_POWER
00078 }
00079
00080 inline
00081 void Photon::SetIncidentDirection(const sheep::Vector3 &direction) {
00082 PackDirection(direction, &m_qphi, &m_qtheta);
00083 }
00084
00085 inline
00086 sheep::Vector3 Photon::GetIncidentDirection() const {
00087 return UnpackDirection(m_qphi, m_qtheta);
00088 }
00089
00090 inline
00091 void Photon::SetSplittingPlaneAxis(int axis) {
00092 assert(axis >= 0 && axis < 4);
00093 m_flags &= ~ sheep::uint16(3);
00094 m_flags |= axis;
00095 }
00096
00097 inline
00098 int Photon::GetSplittingPlaneAxis() const {
00099
00100 return m_flags & 3;
00101 }
00102
00103 #ifdef ENABLE_RADIANCES_PRECOMPUTATION
00104
00105 inline
00106 bool Photon::HasPrecomputedRadiance() const {
00107
00108 return (m_flags & 4) != 0;
00109 }
00110
00111 inline
00112 void Photon::SetPrecomputedRadiance(const Color3 &radiance) {
00113 #ifdef COMPRESS_PRECOMPUTED_RADIANCES
00114 radiance.ConvertToRGBE(&m_radiance[0], &m_radiance[1], &m_radiance[2], &m_radiance[3]);
00115 #else
00116 m_radiance[0] = static_cast<sheep::float32>(radiance.m_r);
00117 m_radiance[1] = static_cast<sheep::float32>(radiance.m_g);
00118 m_radiance[2] = static_cast<sheep::float32>(radiance.m_b);
00119 #endif // COMPRESS_PRECOMPUTED_RADIANCES
00120
00121 m_flags |= 4;
00122 }
00123
00124 inline
00125 Color3 Photon::GetPrecomputedRadiance() const {
00126 assert(HasPrecomputedRadiance());
00127
00128 #ifdef COMPRESS_PRECOMPUTED_RADIANCES
00129 return Color3::ConvertFromRGBE(m_radiance[0], m_radiance[1], m_radiance[2], m_radiance[3]);
00130 #else
00131 return Color3(m_radiance[0], m_radiance[1], m_radiance[2]);
00132 #endif // COMPRESS_PRECOMPUTED_RADIANCES
00133 }
00134
00135 inline
00136 void Photon::SetSurfaceNormal(const sheep::Vector3 &normal) {
00137 PackDirection(normal, &m_qnormal);
00138 }
00139
00140 inline
00141 sheep::Vector3 Photon::GetSurfaceNormal() const {
00142 return UnpackDirection(m_qnormal);
00143 }
00144
00145 #endif // ENABLE_RADIANCES_PRECOMPUTATION
00146
00147 inline
00148 void Photon::WriteToStream(sheep::BinaryStream &os) const {
00149
00150 os.Write(m_position[0]);
00151 os.Write(m_position[1]);
00152 os.Write(m_position[2]);
00153
00154 #ifdef COMPRESS_PHOTON_POWER
00155
00156 os.Write(m_power[0]);
00157 os.Write(m_power[1]);
00158 os.Write(m_power[2]);
00159 os.Write(m_power[3]);
00160 #else
00161
00162 os.Write(m_power[0]);
00163 os.Write(m_power[1]);
00164 os.Write(m_power[2]);
00165 #endif // COMPRESS_PHOTON_POWER
00166
00167
00168 os.Write(m_qphi);
00169 os.Write(m_qtheta);
00170
00171 #ifdef ENABLE_RADIANCES_PRECOMPUTATION
00172 #ifdef COMPRESS_PRECOMPUTED_RADIANCES
00173
00174 os.Write(m_radiance[0]);
00175 os.Write(m_radiance[1]);
00176 os.Write(m_radiance[2]);
00177 os.Write(m_radiance[3]);
00178 #else
00179
00180 os.Write(m_radiance[0]);
00181 os.Write(m_radiance[1]);
00182 os.Write(m_radiance[2]);
00183 #endif // COMPRESS_PRECOMPUTED_RADIANCES
00184
00185 os.Write(m_qnormal);
00186 #endif // ENABLE_RADIANCES_PRECOMPUTATION
00187
00188
00189 os.Write(m_flags);
00190
00191
00192 }
00193
00194 inline
00195 void Photon::ReadFromStream(sheep::BinaryStream &is) {
00196
00197 is.Read(&m_position[0]);
00198 is.Read(&m_position[1]);
00199 is.Read(&m_position[2]);
00200
00201 #ifdef COMPRESS_PHOTON_POWER
00202
00203 is.Read(&m_power[0]);
00204 is.Read(&m_power[1]);
00205 is.Read(&m_power[2]);
00206 is.Read(&m_power[3]);
00207 #else
00208
00209 is.Read(&m_power[0]);
00210 is.Read(&m_power[1]);
00211 is.Read(&m_power[2]);
00212 #endif // COMPRESS_PHOTON_POWER
00213
00214
00215 is.Read(&m_qphi);
00216 is.Read(&m_qtheta);
00217
00218 #ifdef ENABLE_RADIANCES_PRECOMPUTATION
00219 #ifdef COMPRESS_PRECOMPUTED_RADIANCES
00220
00221 is.Read(&m_radiance[0]);
00222 is.Read(&m_radiance[1]);
00223 is.Read(&m_radiance[2]);
00224 is.Read(&m_radiance[3]);
00225 #else
00226
00227 is.Read(&m_radiance[0]);
00228 is.Read(&m_radiance[1]);
00229 is.Read(&m_radiance[2]);
00230 #endif // COMPRESS_PRECOMPUTED_RADIANCES
00231
00232 is.Read(&m_qnormal);
00233 #endif // ENABLE_RADIANCES_PRECOMPUTATION
00234
00235
00236 is.Read(&m_flags);
00237
00238
00239 }