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