Panda3D
cMotionTrail.h
1 // Filename: cMotionTrail.h
2 // Created by: aignacio (29Jan07)
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 CMOTIONTRAIL_H
16 #define CMOTIONTRAIL_H
17 
18 #include "directbase.h"
19 
20 #include "geomNode.h"
21 #include "geomVertexData.h"
22 #include "geomVertexWriter.h"
23 #include "geomTriangles.h"
24 #include "luse.h"
25 #include "nurbsCurveEvaluator.h"
26 #include "plist.h"
27 #include "epvector.h"
28 
30 public:
31  LPoint4 _vertex;
32  LVecBase4 _start_color;
33  LVecBase4 _end_color;
34  PN_stdfloat _v;
35 
36  PT(NurbsCurveEvaluator) _nurbs_curve_evaluator;
37 };
38 
40 public:
41  UnalignedLMatrix4 _transform;
42  PN_stdfloat _time;
43 };
44 
45 ////////////////////////////////////////////////////////////////////
46 // Class : CMotionTrail
47 // Description : The method used in creating the motion trail is
48 // based on taking samples of time and transformations
49 // (the position and orientation matrix) in real-time.
50 // The method also requires a number of vertices
51 // (positions) that determines "shape" of the motion
52 // trail (i.e. the edge of a blade). A start color
53 // and end color is also required for each vertex.
54 // The color is interpolated as function of time.
55 // The colors are typically used to fade the motion
56 // trail so the end color is typically black.
57 //
58 // The vertices are submitted via the "add_vertex"
59 // function. For each frame, a sample is submited via
60 // the "update_motion_trail" function. During the
61 // "update_motion_trail" function, the motion trail
62 // geometry is created dynamically from the sample
63 // history and the vertices.
64 //
65 // The user must specifiy a GeomNode via
66 // "set_geom_node".
67 //
68 // The duration of the sample history is specified by
69 // a time window. A larger time window creates longer
70 // motion trails (given constant speed). Samples that
71 // are no longer within the time window are
72 // automatically discarded.
73 //
74 // The nurbs option can be used to create smooth
75 // interpolated curves from the samples. The nurbs
76 // option is useful for animations that lack sampling
77 // to begin with, animations that move very quickly,
78 // or low frame rates.
79 //
80 // The texture option be used to create variation to
81 // the motion trail. The u coordinate of the texture
82 // corresponds to time and the v coordinate
83 // corresponds to the "shape" of the motion trail.
84 ////////////////////////////////////////////////////////////////////
85 class EXPCL_DIRECT CMotionTrail : public TypedReferenceCount {
86 PUBLISHED:
87  CMotionTrail();
88  ~CMotionTrail();
89 
90  void reset();
91  void reset_vertex_list();
92 
93  void enable(bool enable);
94 
95  void set_geom_node(GeomNode *geom_node);
96  void add_vertex(LVector4 *vertex, LVector4 *start_color, LVector4 *end_color, PN_stdfloat v);
97 
98  void set_parameters(PN_stdfloat sampling_time, PN_stdfloat time_window, bool use_texture, bool calculate_relative_matrix, bool use_nurbs, PN_stdfloat resolution_distance);
99 
100  int check_for_update(PN_stdfloat current_time);
101  void update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform);
102 
103 public:
104 
105  void begin_geometry();
106  void add_geometry_quad(LVector3 &v0, LVector3 &v1, LVector3 &v2, LVector3 &v3, LVector4 &c0, LVector4 &c1, LVector4 &c2, LVector4 &c3, LVector2 &t0, LVector2 &t1, LVector2 &t2, LVector2 &t3);
107  void add_geometry_quad(LVector4 &v0, LVector4 &v1, LVector4 &v2, LVector4 &v3, LVector4 &c0, LVector4 &c1, LVector4 &c2, LVector4 &c3, LVector2 &t0, LVector2 &t1, LVector2 &t2, LVector2 &t3);
108  void end_geometry();
109 
110  int _active;
111  int _enable;
112 
113  int _pause;
114  PN_stdfloat _pause_time;
115 
116  int _fade;
117  int _fade_end;
118  PN_stdfloat _fade_time;
119  PN_stdfloat _fade_start_time;
120  PN_stdfloat _fade_color_scale;
121 
122  PN_stdfloat _last_update_time;
123 
124  typedef epvector<CMotionTrailVertex> VertexList;
125  VertexList _vertex_list;
127  FrameList _frame_list;
128 
129  // parameters
130  PN_stdfloat _color_scale;
131  PN_stdfloat _sampling_time;
132  PN_stdfloat _time_window;
133  bool _square_t;
134  bool _use_texture;
135  int _calculate_relative_matrix;
136 
137  // nurbs parameters
138  bool _use_nurbs;
139  PN_stdfloat _resolution_distance;
140 
141  // geom
142  PT(GeomNode) _geom_node;
143 
144  // real-time data
145  int _vertex_index;
146  PT(GeomVertexData) _vertex_data;
147  GeomVertexWriter _vertex_writer;
148  GeomVertexWriter _color_writer;
149  GeomVertexWriter _texture_writer;
150  PT(GeomTriangles) _triangles;
151 
152  CMotionTrailVertex *_vertex_array;
153 
154 public:
155  static TypeHandle get_class_type() {
156  return _type_handle;
157  }
158  static void init_type() {
159  TypedReferenceCount::init_type();
160  register_type(_type_handle, "CMotionTrail",
161  TypedReferenceCount::get_class_type());
162  }
163  virtual TypeHandle get_type() const {
164  return get_class_type();
165  }
166  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
167 
168 private:
169  static TypeHandle _type_handle;
170 
171 };
172 
173 #endif
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
This is an "unaligned" LMatrix4.
Definition: lmatrix.h:756
This class is an abstraction for evaluating NURBS curves.
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
This is a four-component vector distance.
Definition: lvector4.h:91
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
This is a two-component vector offset.
Definition: lvector2.h:91
This is a four-component point in space.
Definition: lpoint4.h:91
Defines a series of disconnected triangles.
Definition: geomTriangles.h:25
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:37
The method used in creating the motion trail is based on taking samples of time and transformations (...
Definition: cMotionTrail.h:85