Code

Node tool: fix Tab and Shift+Tab
[inkscape.git] / src / display / nr-light.cpp
1 #define __NR_LIGHT_CPP__
3 /*
4  * Light rendering helpers
5  *
6  * Author:
7  *   Jean-Rene Reinhard <jr@komite.net>
8  *
9  * Copyright (C) 2006 Jean-Rene Reinhard
10  *
11  * Released under GNU GPL, read the file 'COPYING' for more information
12  */
14 #include <cmath>
16 #include "libnr/nr-pixops.h"
17 #include "display/nr-light.h"
18 #include "display/nr-3dutils.h"
19 #include "filters/distantlight.h"
20 #include "filters/pointlight.h"
21 #include "filters/spotlight.h"
23 namespace Inkscape {
24 namespace Filters {
25    
26 DistantLight::DistantLight(SPFeDistantLight *light, guint32 lighting_color) {
27     color = lighting_color;
28     azimuth = M_PI / 180 * light->azimuth;
29     elevation = M_PI / 180 * light->elevation;
30 }
32 DistantLight::~DistantLight() {}
34 void DistantLight::light_vector(NR::Fvector &v) {
35     v[X_3D] = std::cos(azimuth)*std::cos(elevation);
36     v[Y_3D] = std::sin(azimuth)*std::cos(elevation);
37     v[Z_3D] = std::sin(elevation);
38
40 void DistantLight::light_components(NR::Fvector &lc) {
41     lc[LIGHT_RED] = NR_RGBA32_R(color);
42     lc[LIGHT_GREEN] = NR_RGBA32_G(color);
43     lc[LIGHT_BLUE] = NR_RGBA32_B(color);
44 }
46 PointLight::PointLight(SPFePointLight *light, guint32 lighting_color, const Geom::Matrix &trans) {
47     color = lighting_color;
48     l_x = light->x;
49     l_y = light->y;
50     l_z = light->z;
51     NR::convert_coord(l_x, l_y, l_z, trans);
52 }
54 PointLight::~PointLight() {}
56 void PointLight::light_vector(NR::Fvector &v, gdouble x, gdouble y, gdouble z) {
57     v[X_3D] = l_x - x;
58     v[Y_3D] = l_y - y;
59     v[Z_3D] = l_z - z;
60     NR::normalize_vector(v);
61
63 void PointLight::light_components(NR::Fvector &lc) {
64     lc[LIGHT_RED] = NR_RGBA32_R(color);
65     lc[LIGHT_GREEN] = NR_RGBA32_G(color);
66     lc[LIGHT_BLUE] = NR_RGBA32_B(color);
67 }
69 SpotLight::SpotLight(SPFeSpotLight *light, guint32 lighting_color, const Geom::Matrix &trans) {
70     gdouble p_x, p_y, p_z;
71     color = lighting_color;
72     l_x = light->x;
73     l_y = light->y;
74     l_z = light->z;
75     p_x = light->pointsAtX;
76     p_y = light->pointsAtY;
77     p_z = light->pointsAtZ;
78     cos_lca = std::cos(M_PI / 180 * light->limitingConeAngle);
79     speExp = light->specularExponent;
80     NR::convert_coord(l_x, l_y, l_z, trans);
81     NR::convert_coord(p_x, p_y, p_z, trans);
82     S[X_3D] = p_x - l_x;
83     S[Y_3D] = p_y - l_y;
84     S[Z_3D] = p_z - l_z;
85     NR::normalize_vector(S);
86     
87 }
89 SpotLight::~SpotLight() {}
91 void SpotLight::light_vector(NR::Fvector &v, gdouble x, gdouble y, gdouble z) {
92     v[X_3D] = l_x - x;
93     v[Y_3D] = l_y - y;
94     v[Z_3D] = l_z - z;
95     NR::normalize_vector(v);
96
98 void SpotLight::light_components(NR::Fvector &lc, const NR::Fvector &L) {
99     gdouble spmod = (-1) * NR::scalar_product(L, S);
100     if (spmod <= cos_lca)
101         spmod = 0;
102     else
103         spmod = std::pow(spmod, speExp);
104     lc[LIGHT_RED] = spmod * NR_RGBA32_R(color);
105     lc[LIGHT_GREEN] = spmod * NR_RGBA32_G(color);
106     lc[LIGHT_BLUE] = spmod * NR_RGBA32_B(color);
109 } /* namespace Filters */
110 } /* namespace Inkscape */
112 /*
113   Local Variables:
114   mode:c++
115   c-file-style:"stroustrup"
116   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
117   indent-tabs-mode:nil
118   fill-column:99
119   End:
120 */
121 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :