summaryrefslogtreecommitdiffstats
path: root/src/display/nr-light.h
blob: ae119ce404356282064e76182d4977da5505f208 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
 * TODO: insert short description here
 *//*
 * Authors: see git history
 *
 * Copyright (C) 2017 Authors
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */
#ifndef SEEN_NR_LIGHT_H
#define SEEN_NR_LIGHT_H

/** \file
 * These classes provide tools to compute interesting objects relative to light
 * sources. Each class provides a constructor converting information contained
 * in a sp light object into information useful in the current setting, a
 * method to get the light vector (at a given point) and a method to get the
 * light color components (at a given point).
 */

#include <2geom/forward.h>

#include "display/nr-3dutils.h"
#include "display/nr-light-types.h"

class SPFeDistantLight;
class SPFePointLight;
class SPFeSpotLight;
typedef unsigned int guint32;

namespace Inkscape {
namespace Filters {

enum LightComponent {
    LIGHT_RED = 0,
    LIGHT_GREEN,
    LIGHT_BLUE
};

class DistantLight {
    public:
        /**
         * Constructor
         *
         * \param light the sp light object
         * \param lighting_color the lighting_color used
         */
        DistantLight(SPFeDistantLight *light, guint32 lighting_color);
        virtual ~DistantLight();

        /**
         * Computes the light vector of the distant light
         *
         * \param v a Fvector reference where we store the result
         */
        void light_vector(NR::Fvector &v);

        /**
         * Computes the light components of the distant light
         *
         * \param lc a Fvector reference where we store the result, X=R, Y=G, Z=B
         */
        void light_components(NR::Fvector &lc);

    private:
        guint32 color;
        double azimuth; //azimuth in rad
        double elevation; //elevation in rad
};

class PointLight {
    public:
        /**
         * Constructor
         *
         * \param light the sp light object
         * \param lighting_color the lighting_color used
         * \param trans the transformation between absolute coordinate (those
         * employed in the sp light object) and current coordinate (those
         * employed in the rendering)
         * \param device_scale for high DPI monitors.
         */
        PointLight(SPFePointLight *light, guint32 lighting_color, const Geom::Affine &trans, int device_scale = 1);
        virtual ~PointLight();
        /**
         * Computes the light vector of the distant light at point (x,y,z).
         * x, y and z are given in the arena_item coordinate, they are used as
         * is
         *
         * \param v a Fvector reference where we store the result
         * \param x x coordinate of the current point
         * \param y y coordinate of the current point
         * \param z z coordinate of the current point
         */
        void light_vector(NR::Fvector &v, double x, double y, double z);

        /**
         * Computes the light components of the distant light
         *
         * \param lc a Fvector reference where we store the result, X=R, Y=G, Z=B
         */
        void light_components(NR::Fvector &lc);

    private:
        guint32 color;
        //light position coordinates in render setting
        double l_x;
        double l_y;
        double l_z;
};

class SpotLight {
    public:
        /**
         * Constructor
         *
         * \param light the sp light object
         * \param lighting_color the lighting_color used
         * \param trans the transformation between absolute coordinate (those
         * employed in the sp light object) and current coordinate (those
         * employed in the rendering)
         * \param device_scale for high DPI monitors.
         */
        SpotLight(SPFeSpotLight *light, guint32 lighting_color, const Geom::Affine &trans, int device_scale = 1);
        virtual ~SpotLight();

        /**
         * Computes the light vector of the distant light at point (x,y,z).
         * x, y and z are given in the arena_item coordinate, they are used as
         * is
         *
         * \param v a Fvector reference where we store the result
         * \param x x coordinate of the current point
         * \param y y coordinate of the current point
         * \param z z coordinate of the current point
         */
        void light_vector(NR::Fvector &v, double x, double y, double z);

        /**
         * Computes the light components of the distant light at the current
         * point. We only need the light vector to compute these
         *
         * \param lc a Fvector reference where we store the result, X=R, Y=G, Z=B
         * \param L the light vector of the current point
         */
        void light_components(NR::Fvector &lc, const NR::Fvector &L);

    private:
        guint32 color;
        //light position coordinates in render setting
        double l_x;
        double l_y;
        double l_z;
        double cos_lca; //cos of the limiting cone angle
        double speExp; //specular exponent;
        NR::Fvector S; //unit vector from light position in the direction
                   //the spot point at
};


} /* namespace Filters */
} /* namespace Inkscape */

#endif // __NR_LIGHT_H__
/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :