Panda3D
spotlight.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file spotlight.h
10 * @author mike
11 * @date 1997-01-09
12 */
13
14#ifndef SPOTLIGHT_H
15#define SPOTLIGHT_H
16
17#include "pandabase.h"
18
19#include "lightLensNode.h"
20#include "texture.h"
21
22/**
23 * A light originating from a single point in space, and shining in a
24 * particular direction, with a cone-shaped falloff.
25 *
26 * The Spotlight frustum is defined using a Lens, so it can have any of the
27 * properties that a camera lens can have.
28 *
29 * Note that the class is named Spotlight instead of SpotLight, because
30 * "spotlight" is a single English word, instead of two words.
31 */
32class EXPCL_PANDA_PGRAPHNODES Spotlight : public LightLensNode {
33PUBLISHED:
34 Spotlight(const std::string &name);
35
36protected:
37 Spotlight(const Spotlight &copy);
38
39public:
40 virtual PandaNode *make_copy() const;
41 virtual void xform(const LMatrix4 &mat);
42 virtual void write(std::ostream &out, int indent_level) const;
43
44 virtual bool get_vector_to_light(LVector3 &result,
45 const LPoint3 &from_object_point,
46 const LMatrix4 &to_object_space);
47
48PUBLISHED:
49 INLINE PN_stdfloat get_exponent() const final;
50 INLINE void set_exponent(PN_stdfloat exponent);
51 MAKE_PROPERTY(exponent, get_exponent, set_exponent);
52
53 INLINE const LColor &get_specular_color() const final;
54 INLINE void set_specular_color(const LColor &color);
55 INLINE void clear_specular_color();
56 MAKE_PROPERTY(specular_color, get_specular_color, set_specular_color);
57
58 INLINE const LVecBase3 &get_attenuation() const final;
59 INLINE void set_attenuation(const LVecBase3 &attenuation);
60 MAKE_PROPERTY(attenuation, get_attenuation, set_attenuation);
61
62 INLINE PN_stdfloat get_max_distance() const;
63 INLINE void set_max_distance(PN_stdfloat max_distance);
64 MAKE_PROPERTY(max_distance, get_max_distance, set_max_distance);
65
66 virtual int get_class_priority() const;
67
68 static PT(Texture) make_spot(int pixel_width, PN_stdfloat full_radius,
69 LColor &fg, LColor &bg);
70
71public:
72 virtual void bind(GraphicsStateGuardianBase *gsg, const NodePath &light,
73 int light_id);
74
75protected:
76 virtual void fill_viz_geom(GeomNode *viz_geom);
77
78private:
79 CPT(RenderState) get_viz_state();
80
81private:
82 // This is the data that must be cycled between pipeline stages.
83 class EXPCL_PANDA_PGRAPHNODES CData : public CycleData {
84 public:
85 INLINE CData();
86 INLINE CData(const CData &copy);
87 virtual CycleData *make_copy() const;
88 virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
89 virtual void fillin(DatagramIterator &scan, BamReader *manager);
90 virtual TypeHandle get_parent_type() const {
91 return Spotlight::get_class_type();
92 }
93
94 PN_stdfloat _exponent;
95 LColor _specular_color;
96 LVecBase3 _attenuation;
97 PN_stdfloat _max_distance;
98 };
99
100 PipelineCycler<CData> _cycler;
101 typedef CycleDataReader<CData> CDReader;
102 typedef CycleDataWriter<CData> CDWriter;
103
104public:
105 static void register_with_read_factory();
106 virtual void write_datagram(BamWriter *manager, Datagram &dg);
107
108protected:
109 static TypedWritable *make_from_bam(const FactoryParams &params);
110 void fillin(DatagramIterator &scan, BamReader *manager);
111
112public:
113 static TypeHandle get_class_type() {
114 return _type_handle;
115 }
116 static void init_type() {
117 LightLensNode::init_type();
118 register_type(_type_handle, "Spotlight",
119 LightLensNode::get_class_type());
120 }
121 virtual TypeHandle get_type() const {
122 return get_class_type();
123 }
124 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
125
126private:
127 static TypeHandle _type_handle;
128};
129
130INLINE std::ostream &operator << (std::ostream &out, const Spotlight &light) {
131 light.output(out);
132 return out;
133}
134
135#include "spotlight.I"
136
137#endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
virtual PandaNode * make_copy() const
Returns a newly-allocated Node that is a shallow copy of this one.
Definition: camera.cxx:69
static void register_with_read_factory()
Tells the BamReader how to create objects of type Camera.
Definition: camera.cxx:262
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:34
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this PandaNode by the indicated matrix, if it means anything to do so.
Definition: lensNode.cxx:53
A derivative of Light and of Camera.
Definition: lightLensNode.h:33
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual bool get_vector_to_light(LVector3 &result, const LPoint3 &from_object_point, const LMatrix4 &to_object_space)
Computes the vector from a particular vertex to this light.
Definition: light.cxx:189
virtual PN_stdfloat get_exponent() const
For spotlights, returns the exponent that controls the amount of light falloff from the center of the...
Definition: light.cxx:137
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:159
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:47
A light originating from a single point in space, and shining in a particular direction,...
Definition: spotlight.h:32
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:71
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.