Panda3D
directionalLight.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 directionalLight.h
10  * @author mike
11  * @date 1997-01-09
12  */
13 
14 #ifndef DIRECTIONALLIGHT_H
15 #define DIRECTIONALLIGHT_H
16 
17 #include "pandabase.h"
18 
19 #include "lightLensNode.h"
20 
21 /**
22  * A light shining from infinitely far away in a particular direction, like
23  * sunlight.
24  */
25 class EXPCL_PANDA_PGRAPHNODES DirectionalLight : public LightLensNode {
26 PUBLISHED:
27  explicit DirectionalLight(const std::string &name);
28 
29 protected:
31 
32 public:
33  virtual PandaNode *make_copy() const;
34  virtual void xform(const LMatrix4 &mat);
35  virtual void write(std::ostream &out, int indent_level) const;
36 
37  virtual bool get_vector_to_light(LVector3 &result,
38  const LPoint3 &from_object_point,
39  const LMatrix4 &to_object_space);
40 
41 PUBLISHED:
42  INLINE const LColor &get_specular_color() const final;
43  INLINE void set_specular_color(const LColor &color);
44  INLINE void clear_specular_color();
45  MAKE_PROPERTY(specular_color, get_specular_color, set_specular_color);
46 
47  INLINE const LPoint3 &get_point() const;
48  INLINE void set_point(const LPoint3 &point);
49  MAKE_PROPERTY(point, get_point, set_point);
50 
51  INLINE const LVector3 &get_direction() const;
52  INLINE void set_direction(const LVector3 &direction);
53  MAKE_PROPERTY(direction, get_direction, set_direction);
54 
55  virtual int get_class_priority() const;
56 
57 public:
58  virtual void bind(GraphicsStateGuardianBase *gsg, const NodePath &light,
59  int light_id);
60 
61 private:
62  // This is the data that must be cycled between pipeline stages.
63  class EXPCL_PANDA_PGRAPHNODES CData : public CycleData {
64  public:
65  INLINE CData();
66  INLINE CData(const CData &copy);
67  virtual CycleData *make_copy() const;
68  virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
69  virtual void fillin(DatagramIterator &scan, BamReader *manager);
70  virtual TypeHandle get_parent_type() const {
71  return DirectionalLight::get_class_type();
72  }
73 
74  LColor _specular_color;
75  LPoint3 _point;
76  LVector3 _direction;
77  };
78 
79  PipelineCycler<CData> _cycler;
80  typedef CycleDataReader<CData> CDReader;
81  typedef CycleDataWriter<CData> CDWriter;
82 
83 public:
84  static void register_with_read_factory();
85  virtual void write_datagram(BamWriter *manager, Datagram &dg);
86 
87 protected:
88  static TypedWritable *make_from_bam(const FactoryParams &params);
89  void fillin(DatagramIterator &scan, BamReader *manager);
90 
91 public:
92  static TypeHandle get_class_type() {
93  return _type_handle;
94  }
95  static void init_type() {
96  LightLensNode::init_type();
97  register_type(_type_handle, "DirectionalLight",
98  LightLensNode::get_class_type());
99  }
100  virtual TypeHandle get_type() const {
101  return get_class_type();
102  }
103  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
104 
105 private:
106  static TypeHandle _type_handle;
107 };
108 
109 INLINE std::ostream &operator << (std::ostream &out, const DirectionalLight &light) {
110  light.output(out);
111  return out;
112 }
113 
114 #include "directionalLight.I"
115 
116 #endif
A light shining from infinitely far away in a particular direction, like sunlight.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual const LColor & get_specular_color() const
Returns the color of specular highlights generated by the light.
Definition: light.cxx:146
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:47
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
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.
virtual TypeHandle get_parent_type() const
Returns the type of the container that owns the CycleData.
Definition: cycleData.cxx:76
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
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:32
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
Definition: cycleData.cxx:58
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
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:81
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161