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