00001
00002
00003
00004
00005
00006
00007 #include "imagemap.h"
00008 #include <cmath>
00009
00010 using Magick::Color;
00011 using Magick::ColorRGB;
00012
00013 ImageMap::StaticInit ImageMap::m_init;
00014
00015
00016 Color ImageMap::get_color(const Point3D &intersection_point, const Renderable * const obj) const {
00017 if(obj == NULL) {
00018 return Color("red");
00019 }
00020 Vector normal = obj->get_normal(intersection_point).direction();
00021
00022 Vector north(0, 1, 0);
00023 Vector equator(-1, 0, 0);
00024
00025 double phi = acos(-(dot_product(normal, north)));
00026 double lattitude = phi * M_1_PI;
00027 double longitude;
00028
00029 if(lattitude == 0.0 || lattitude == 1.0) {
00030 return m_image.pixelColor(0,0);
00031 }
00032
00033 double theta = acos((dot_product(normal, equator))/sin(phi)) * (0.5 * M_1_PI);
00034 if(dot_product(cross_product(north, equator), normal) > 0) {
00035 longitude = theta;
00036 }
00037 else {
00038 longitude = 1 - theta;
00039 }
00040
00041 int x, y;
00042 x = m_image.baseColumns() - (int)(longitude * m_image.baseColumns());
00043 y = (int)(lattitude * m_image.baseRows());
00044 if(x > m_image.baseColumns() || y > m_image.baseRows() || x < 0 || y < 0) {
00045 return Color("red");
00046 }
00047 else {
00048 return m_image.pixelColor(x, y);
00049 }
00050 }
00051
00052
00053 bool ImageMap::is_light(const Point3D& intersection_point) const
00054 {
00055 return m_is_light_source;
00056 }
00057 void ImageMap::set_is_light(bool v)
00058 {
00059 m_is_light_source = v;
00060 }
00061
00062 double ImageMap::get_diffuse(const Point3D& intersection_point) const
00063 {
00064 return m_diffusion_factor;
00065 }
00066
00067 void ImageMap::set_diffuse(double diffuse)
00068 {
00069 m_diffusion_factor = diffuse;
00070 }
00071
00072 double ImageMap::get_reflection(const Point3D& intersection_point) const
00073 {
00074 return m_reflection_coefficient;
00075 }
00076
00077 double ImageMap::get_reflectivity(const Point3D& intersection_point) const
00078 {
00079 return m_reflectivity;
00080 }
00081
00082 double ImageMap::get_refraction_index(const Point3D& intersection_point) const
00083 {
00084 return m_refraction_index;
00085 }
00086
00087 double ImageMap::get_opacity(const Point3D& intersection_point) const
00088 {
00089 return m_opacity;
00090 }
00091
00092 void ImageMap::set_opacity(double opacity)
00093 {
00094 m_opacity = opacity; normalize_opacity();
00095 }
00096
00097