Panda3D
|
00001 // Filename: cMotionTrail.h 00002 // Created by: aignacio (29Jan07) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef CMOTIONTRAIL_H 00016 #define CMOTIONTRAIL_H 00017 00018 #include "directbase.h" 00019 00020 #include "geomNode.h" 00021 #include "geomVertexData.h" 00022 #include "geomVertexWriter.h" 00023 #include "geomTriangles.h" 00024 #include "luse.h" 00025 #include "nurbsCurveEvaluator.h" 00026 #include "plist.h" 00027 #include "pvector.h" 00028 00029 class CMotionTrailVertex { 00030 public: 00031 LPoint4 _vertex; 00032 LVecBase4 _start_color; 00033 LVecBase4 _end_color; 00034 PN_stdfloat _v; 00035 00036 PT(NurbsCurveEvaluator) _nurbs_curve_evaluator; 00037 }; 00038 00039 class CMotionTrailFrame { 00040 public: 00041 UnalignedLMatrix4 _transform; 00042 PN_stdfloat _time; 00043 }; 00044 00045 //////////////////////////////////////////////////////////////////// 00046 // Class : CMotionTrail 00047 // Description : The method used in creating the motion trail is 00048 // based on taking samples of time and transformations 00049 // (the position and orientation matrix) in real-time. 00050 // The method also requires a number of vertices 00051 // (positions) that determines "shape" of the motion 00052 // trail (i.e. the edge of a blade). A start color 00053 // and end color is also required for each vertex. 00054 // The color is interpolated as function of time. 00055 // The colors are typically used to fade the motion 00056 // trail so the end color is typically black. 00057 // 00058 // The vertices are submitted via the "add_vertex" 00059 // function. For each frame, a sample is submited via 00060 // the "update_motion_trail" function. During the 00061 // "update_motion_trail" function, the motion trail 00062 // geometry is created dynamically from the sample 00063 // history and the vertices. 00064 // 00065 // The user must specifiy a GeomNode via 00066 // "set_geom_node". 00067 // 00068 // The duration of the sample history is specified by 00069 // a time window. A larger time window creates longer 00070 // motion trails (given constant speed). Samples that 00071 // are no longer within the time window are 00072 // automatically discarded. 00073 // 00074 // The nurbs option can be used to create smooth 00075 // interpolated curves from the samples. The nurbs 00076 // option is useful for animations that lack sampling 00077 // to begin with, animations that move very quickly, 00078 // or low frame rates. 00079 // 00080 // The texture option be used to create variation to 00081 // the motion trail. The u coordinate of the texture 00082 // corresponds to time and the v coordinate 00083 // corresponds to the "shape" of the motion trail. 00084 //////////////////////////////////////////////////////////////////// 00085 00086 class EXPCL_DIRECT CMotionTrail : public TypedReferenceCount { 00087 00088 PUBLISHED: 00089 00090 CMotionTrail ( ); 00091 ~CMotionTrail ( ); 00092 00093 void reset ( ); 00094 void reset_vertex_list ( ); 00095 00096 void enable (bool enable); 00097 00098 void set_geom_node (PT(GeomNode) geom_node); 00099 void add_vertex (LVector4 *vertex, LVector4 *start_color, LVector4 *end_color, PN_stdfloat v); 00100 00101 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); 00102 00103 int check_for_update (PN_stdfloat current_time); 00104 void update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform); 00105 00106 public: 00107 00108 void begin_geometry ( ); 00109 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); 00110 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); 00111 void end_geometry ( ); 00112 00113 int _active; 00114 int _enable; 00115 00116 int _pause; 00117 PN_stdfloat _pause_time; 00118 00119 int _fade; 00120 int _fade_end; 00121 PN_stdfloat _fade_time; 00122 PN_stdfloat _fade_start_time; 00123 PN_stdfloat _fade_color_scale; 00124 00125 PN_stdfloat _last_update_time; 00126 00127 typedef epvector<CMotionTrailVertex> VertexList; 00128 VertexList _vertex_list; 00129 typedef plist<CMotionTrailFrame> FrameList; 00130 FrameList _frame_list; 00131 00132 // parameters 00133 PN_stdfloat _color_scale; 00134 PN_stdfloat _sampling_time; 00135 PN_stdfloat _time_window; 00136 bool _square_t; 00137 bool _use_texture; 00138 int _calculate_relative_matrix; 00139 00140 // nurbs parameters 00141 bool _use_nurbs; 00142 PN_stdfloat _resolution_distance; 00143 00144 // geom 00145 PT(GeomNode) _geom_node; 00146 00147 // real-time data 00148 int _vertex_index; 00149 PT(GeomVertexData) _vertex_data; 00150 GeomVertexWriter _vertex_writer; 00151 GeomVertexWriter _color_writer; 00152 GeomVertexWriter _texture_writer; 00153 PT(GeomTriangles) _triangles; 00154 00155 CMotionTrailVertex *_vertex_array; 00156 00157 public: 00158 static TypeHandle get_class_type() { 00159 return _type_handle; 00160 } 00161 static void init_type() { 00162 TypedReferenceCount::init_type(); 00163 register_type(_type_handle, "CMotionTrail", 00164 TypedReferenceCount::get_class_type()); 00165 } 00166 virtual TypeHandle get_type() const { 00167 return get_class_type(); 00168 } 00169 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00170 00171 private: 00172 static TypeHandle _type_handle; 00173 00174 }; 00175 00176 #endif