30make(
const LVector3 &up_vector,
bool eye_relative,
31 bool axial_rotate, PN_stdfloat offset,
const NodePath &look_at,
32 const LPoint3 &look_at_point,
bool fixed_depth) {
33 BillboardEffect *effect =
new BillboardEffect;
34 effect->_up_vector = up_vector;
35 effect->_eye_relative = eye_relative;
36 effect->_axial_rotate = axial_rotate;
37 effect->_offset = offset;
38 effect->_look_at = look_at;
39 effect->_look_at_point = look_at_point;
40 effect->_fixed_depth = fixed_depth;
42 return return_new(effect);
63 return net_transform->set_hpr(LVecBase3(0, 0, 0));
70output(std::ostream &out)
const {
71 out << get_type() <<
":";
80 if (!_up_vector.almost_equal(LVector3::up())) {
81 out <<
" up " << _up_vector;
87 out <<
" depth " << -_offset;
88 }
else if (_offset != 0.0f) {
89 out <<
" offset " << _offset;
91 if (!_look_at.is_empty()) {
92 out <<
" look at " << _look_at;
94 if (!_look_at_point.almost_equal(LPoint3(0.0f, 0.0f, 0.0f))) {
95 out <<
" look at point " << _look_at_point;
127 CPT(
TransformState) modelview_transform = data.get_modelview_transform(trav);
128 if (modelview_transform->is_singular()) {
135 CPT(
TransformState) camera_transform = TransformState::make_identity();
139 if (!_look_at.is_empty()) {
143 compute_billboard(node_transform, modelview_transform, camera_transform);
156 return !_look_at.is_empty();
174 if (_look_at.is_empty()) {
178 CPT(
TransformState) camera_transform = _look_at.get_net_transform();
180 compute_billboard(node_transform, net_transform, camera_transform);
199 DCAST_INTO_R(ta, other, 0);
201 if (_axial_rotate != ta->_axial_rotate) {
202 return (
int)_axial_rotate - (int)ta->_axial_rotate;
204 if (_eye_relative != ta->_eye_relative) {
205 return (
int)_eye_relative - (int)ta->_eye_relative;
207 if (_fixed_depth != ta->_fixed_depth) {
208 return (
int)_fixed_depth - (int)ta->_fixed_depth;
210 if (_offset != ta->_offset) {
211 return _offset < ta->_offset ? -1 : 1;
213 int compare = _up_vector.compare_to(ta->_up_vector);
217 compare = _look_at.compare_to(ta->_look_at);
221 compare = _look_at_point.compare_to(ta->_look_at_point);
234void BillboardEffect::
245 node_transform = node_transform->set_pos(LPoint3(0.0f, 0.0f, 0.0f));
248 net_transform->compose(translate)->invert_compose(camera_transform);
249 if (!rel_transform->has_mat()) {
254 const LMatrix4 &rel_mat = rel_transform->get_mat();
257 LVector3 camera_pos, up;
265 up = _up_vector * rel_mat;
266 camera_pos = LVector3::forward() * rel_mat;
270 camera_pos = -(_look_at_point * rel_mat);
276 heads_up(rotate, camera_pos, up);
278 look_at(rotate, camera_pos, up);
283 if (_offset != 0.0f || _fixed_depth) {
284 LVector3 translate(rel_mat(3, 0), rel_mat(3, 1), rel_mat(3, 2));
287 pos = translate / rel_mat(3, 3);
291 translate.normalize();
292 translate *= _offset;
293 rotate.set_row(3, pos + translate);
296 node_transform = translate->compose(TransformState::make_mat(rotate))->compose(node_transform);
316 _up_vector.write_datagram(dg);
320 _look_at_point.write_datagram(dg);
323 _look_at.write_datagram(manager, dg);
337 pi += _look_at.complete_pointers(p_list + pi, manager);
355 effect->fillin(scan, manager);
364void BillboardEffect::
366 RenderEffect::fillin(scan, manager);
369 _up_vector.read_datagram(scan);
373 _look_at_point.read_datagram(scan);
376 _look_at.fillin(scan, manager);
379 _fixed_depth =
false;
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being written.
Indicates that geometry at this node should automatically rotate to face the camera,...
static ConstPointerTo< RenderEffect > make(const LVector3 &up_vector, bool eye_relative, bool axial_rotate, PN_stdfloat offset, const NodePath &look_at, const LPoint3 &look_at_point, bool fixed_depth=false)
Constructs a new BillboardEffect object with the indicated properties.
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
virtual void adjust_transform(ConstPointerTo< TransformState > &net_transform, ConstPointerTo< TransformState > &node_transform, const PandaNode *node) const
Performs some operation on the node's apparent net and/or local transforms.
virtual ConstPointerTo< TransformState > prepare_flatten_transform(const TransformState *net_transform) const
Preprocesses the accumulated transform that is about to be applied to (or through) this node due to a...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
static void register_with_read_factory()
Tells the BamReader how to create objects of type BillboardEffect.
bool is_off() const
Returns true if the BillboardEffect is an 'off' BillboardEffect, indicating that it does not enable b...
virtual bool has_adjust_transform() const
Should be overridden by derived classes to return true if adjust_transform() has been defined,...
virtual bool has_cull_callback() const
Should be overridden by derived classes to return true if cull_callback() has been defined.
virtual bool safe_to_transform() const
Returns true if it is generally safe to transform this particular kind of RenderEffect by calling the...
virtual void cull_callback(CullTraverser *trav, CullTraverserData &data, ConstPointerTo< TransformState > &node_transform, ConstPointerTo< RenderState > &node_state) const
If has_cull_callback() returns true, this function will be called during the cull traversal to perfor...
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
const TransformState * get_camera_transform() const
Returns the position of the camera relative to the starting node.
A class to retrieve the individual data elements previously stored in a Datagram.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
bool get_bool()
Extracts a boolean value.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
void add_bool(bool value)
Adds a boolean value to the datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
A basic node of the scene graph or data graph.
This is the base class for a number of special render effects that may be set on scene graph nodes to...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
TypeHandle is the identifier used to differentiate C++ class types.
Base class for objects that can be written to and read from Bam files.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.