15 #include "billboardEffect.h"
16 #include "cullTraverser.h"
17 #include "cullTraverserData.h"
20 #include "bamReader.h"
21 #include "bamWriter.h"
23 #include "datagramIterator.h"
34 make(const
LVector3 &up_vector,
bool eye_relative,
35 bool axial_rotate, PN_stdfloat offset, const
NodePath &look_at,
38 effect->_up_vector = up_vector;
39 effect->_eye_relative = eye_relative;
40 effect->_axial_rotate = axial_rotate;
41 effect->_offset = offset;
42 effect->_look_at = look_at;
43 effect->_look_at_point = look_at_point;
45 return return_new(effect);
69 prepare_flatten_transform(const TransformState *net_transform)
const {
73 return net_transform->set_hpr(
LVecBase3(0, 0, 0));
81 void BillboardEffect::
82 output(ostream &out)
const {
83 out << get_type() <<
":";
93 out <<
" up " << _up_vector;
98 if (_offset != 0.0f) {
99 out <<
" offset " << _offset;
102 out <<
" look at " << _look_at;
105 out <<
" look at point " << _look_at_point;
144 CPT(TransformState) &node_transform,
146 CPT(TransformState) modelview_transform = data.get_modelview_transform(trav);
147 if (modelview_transform->is_singular()) {
155 CPT(TransformState) camera_transform = TransformState::make_identity();
163 compute_billboard(node_transform, modelview_transform, camera_transform);
196 CPT(TransformState) &node_transform,
206 CPT(TransformState) camera_transform = _look_at.get_net_transform();
208 compute_billboard(node_transform, net_transform, camera_transform);
227 int BillboardEffect::
230 DCAST_INTO_R(ta, other, 0);
232 if (_axial_rotate != ta->_axial_rotate) {
233 return (
int)_axial_rotate - (int)ta->_axial_rotate;
235 if (_eye_relative != ta->_eye_relative) {
236 return (
int)_eye_relative - (int)ta->_eye_relative;
238 if (_offset != ta->_offset) {
239 return _offset < ta->_offset ? -1 : 1;
241 int compare = _up_vector.
compare_to(ta->_up_vector);
249 compare = _look_at_point.
compare_to(ta->_look_at_point);
265 void BillboardEffect::
266 compute_billboard(CPT(TransformState) &node_transform,
267 const TransformState *net_transform,
268 const TransformState *camera_transform)
const {
272 CPT(TransformState) translate = TransformState::make_pos(node_transform->get_pos());
277 node_transform = node_transform->set_pos(
LPoint3(0.0f, 0.0f, 0.0f));
279 CPT(TransformState) rel_transform =
280 net_transform->compose(translate)->invert_compose(camera_transform);
281 if (!rel_transform->has_mat()) {
286 const LMatrix4 &rel_mat = rel_transform->get_mat();
298 up = _up_vector * rel_mat;
303 camera_pos = -(_look_at_point * rel_mat);
309 heads_up(rotate, camera_pos, up);
311 look_at(rotate, camera_pos, up);
316 if (_offset != 0.0f) {
317 LVector3 translate(rel_mat(3, 0), rel_mat(3, 1), rel_mat(3, 2));
318 translate.normalize();
319 translate *= _offset;
323 node_transform = translate->compose(TransformState::make_mat(rotate))->compose(node_transform);
372 parse_params(params, scan, manager);
373 effect->fillin(scan, manager);
385 void BillboardEffect::
387 RenderEffect::fillin(scan, manager);
A basic node of the scene graph or data graph.
This is the base class for all three-component vectors and points.
bool get_bool()
Extracts a boolean value.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
int compare_to(const NodePath &other) const
Returns a number less than zero if this NodePath sorts before the other one, greater than zero if it ...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
void read_datagram(DatagramIterator &source)
Reads the vector from the Datagram using get_stdfloat().
Base class for objects that can be written to and read from Bam files.
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 collects together the pieces of data that are accumulated for each node while walking the scene ...
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
This is the base class for a number of special render effects that may be set on scene graph nodes to...
Indicates that geometry at this node should automatically rotate to face the camera, or any other arbitrary node.
static LVector3f forward(CoordinateSystem cs=CS_default)
Returns the forward vector for the given coordinate system.
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
const TransformState * get_camera_transform() const
Returns the position of the camera relative to the starting node.
void add_bool(bool value)
Adds a boolean value to the datagram.
int compare_to(const LVecBase3f &other) const
This flavor of compare_to uses a default threshold value based on the numeric type.
This is a 4-by-4 transform matrix.
virtual bool has_adjust_transform() const
Should be overridden by derived classes to return true if adjust_transform() has been defined...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
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 WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
bool almost_equal(const LVecBase3f &other, float threshold) const
Returns true if two vectors are memberwise equal within a specified tolerance.
bool is_empty() const
Returns true if the NodePath contains no nodes.
void set_row(int row, const LVecBase4f &v)
Replaces the indicated row of the matrix.
A class to retrieve the individual data elements previously stored in a Datagram. ...
bool is_off() const
Returns true if the BillboardEffect is an 'off' BillboardEffect, indicating that it does not enable b...
virtual bool has_cull_callback() const
Should be overridden by derived classes to return true if cull_callback() has been defined...
TypeHandle is the identifier used to differentiate C++ class types.
virtual void adjust_transform(CPT(TransformState)&net_transform, CPT(TransformState)&node_transform, PandaNode *node) const
Performs some operation on the node's apparent net and/or local transforms.
static void register_with_read_factory()
Tells the BamReader how to create objects of type BillboardEffect.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
virtual void cull_callback(CullTraverser *trav, CullTraverserData &data, CPT(TransformState)&node_transform, CPT(RenderState)&node_state) const
If has_cull_callback() returns true, this function will be called during the cull traversal to perfor...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
static LVector3f up(CoordinateSystem cs=CS_default)
Returns the up vector for the given coordinate system.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
void write_datagram(Datagram &destination) const
Writes the vector to the Datagram using add_stdfloat().
virtual bool safe_to_transform() const
Returns true if it is generally safe to transform this particular kind of RenderEffect by calling the...