Panda3D
Loading...
Searching...
No Matches
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
29public:
30 LPoint4 _vertex;
31 LVecBase4 _start_color;
32 LVecBase4 _end_color;
33 PN_stdfloat _v;
34
35 PT(NurbsCurveEvaluator) _nurbs_curve_evaluator;
36};
37
39public:
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 */
72class EXPCL_DIRECT_MOTIONTRAIL CMotionTrail : public TypedReferenceCount {
73PUBLISHED:
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
90public:
91
92 void begin_geometry();
93 void begin_geometry(int num_quads);
94 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);
95 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);
96 void end_geometry();
97
98 int _active;
99 int _enable;
100
101 int _pause;
102 PN_stdfloat _pause_time;
103
104 int _fade;
105 int _fade_end;
106 PN_stdfloat _fade_time;
107 PN_stdfloat _fade_start_time;
108 PN_stdfloat _fade_color_scale;
109
110 PN_stdfloat _last_update_time;
111
112 typedef epvector<CMotionTrailVertex> VertexList;
113 VertexList _vertex_list;
115 FrameList _frame_list;
116
117 // parameters
118 PN_stdfloat _color_scale;
119 PN_stdfloat _sampling_time;
120 PN_stdfloat _time_window;
121 bool _square_t;
122 bool _use_texture;
123 int _calculate_relative_matrix;
124
125 // nurbs parameters
126 bool _use_nurbs;
127 PN_stdfloat _resolution_distance;
128
129 // geom
130 PT(GeomNode) _geom_node;
131
132 // real-time data
133 int _vertex_index;
134 PT(GeomVertexData) _vertex_data;
135 GeomVertexWriter _vertex_writer;
136 GeomVertexWriter _color_writer;
137 GeomVertexWriter _texture_writer;
138 PT(GeomTriangles) _triangles;
139
140 CMotionTrailVertex *_vertex_array;
141
142public:
143 static TypeHandle get_class_type() {
144 return _type_handle;
145 }
146 static void init_type() {
147 TypedReferenceCount::init_type();
148 register_type(_type_handle, "CMotionTrail",
149 TypedReferenceCount::get_class_type());
150 }
151 virtual TypeHandle get_type() const {
152 return get_class_type();
153 }
154 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
155
156private:
157 static TypeHandle _type_handle;
158
159};
160
161#endif
The method used in creating the motion trail is based on taking samples of time and transformations (...
A node that holds Geom objects, renderable pieces of geometry.
Definition geomNode.h:34
Defines a series of disconnected triangles.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
This class is an abstraction for evaluating NURBS curves.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This is our own Panda specialization on the default STL list.
Definition plist.h:35
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...