mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
motiontrail: Further cleanup of CMotionTrail code
This commit is contained in:
parent
8354e175cf
commit
c366dab405
@ -28,60 +28,6 @@ static PN_stdfloat one_minus_x(PN_stdfloat x) {
|
|||||||
|
|
||||||
TypeHandle CMotionTrail::_type_handle;
|
TypeHandle CMotionTrail::_type_handle;
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*/
|
|
||||||
CMotionTrail::
|
|
||||||
CMotionTrail() {
|
|
||||||
|
|
||||||
_active = true;
|
|
||||||
_enable = true;
|
|
||||||
|
|
||||||
_pause = false;
|
|
||||||
_pause_time = 0.0f;
|
|
||||||
|
|
||||||
_fade = false;
|
|
||||||
_fade_end = false;
|
|
||||||
_fade_time = 0.0f;
|
|
||||||
_fade_start_time = 0.0f;
|
|
||||||
_fade_color_scale = 1.0f;
|
|
||||||
|
|
||||||
_last_update_time = 0.0f;
|
|
||||||
|
|
||||||
_vertex_list.clear();
|
|
||||||
_frame_list.clear();
|
|
||||||
|
|
||||||
// parameters
|
|
||||||
_color_scale = 1.0;
|
|
||||||
_sampling_time = 0.0;
|
|
||||||
_time_window = 1.0;
|
|
||||||
_square_t = true;
|
|
||||||
_use_texture = false;
|
|
||||||
_calculate_relative_matrix = false;
|
|
||||||
|
|
||||||
// nurbs parameters
|
|
||||||
_use_nurbs = false;
|
|
||||||
_resolution_distance = 0.5f;
|
|
||||||
|
|
||||||
// node path states
|
|
||||||
_geom_node = nullptr;
|
|
||||||
|
|
||||||
// real-time data
|
|
||||||
_vertex_index = 0;
|
|
||||||
_vertex_data = nullptr;
|
|
||||||
_triangles = nullptr;
|
|
||||||
|
|
||||||
_vertex_array = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructor
|
|
||||||
*/
|
|
||||||
CMotionTrail::
|
|
||||||
~CMotionTrail() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset the frame sample history.
|
* Reset the frame sample history.
|
||||||
*/
|
*/
|
||||||
@ -118,18 +64,15 @@ set_geom_node(GeomNode *geom_node) {
|
|||||||
* Add a vertex.
|
* Add a vertex.
|
||||||
*/
|
*/
|
||||||
void CMotionTrail::
|
void CMotionTrail::
|
||||||
add_vertex(LVector4 *vertex, LVector4 *start_color, LVector4 *end_color, PN_stdfloat v) {
|
add_vertex(const LVector4 &vertex, const LVector4 &start_color,
|
||||||
|
const LVector4 &end_color, PN_stdfloat v) {
|
||||||
CMotionTrailVertex motion_trail_vertex;
|
CMotionTrailVertex motion_trail_vertex;
|
||||||
|
motion_trail_vertex._vertex = vertex;
|
||||||
motion_trail_vertex._vertex = *vertex;
|
motion_trail_vertex._start_color = start_color;
|
||||||
motion_trail_vertex._start_color = *start_color;
|
motion_trail_vertex._end_color = end_color;
|
||||||
motion_trail_vertex._end_color = *end_color;
|
|
||||||
motion_trail_vertex._v = v;
|
motion_trail_vertex._v = v;
|
||||||
|
|
||||||
motion_trail_vertex._nurbs_curve_evaluator = new NurbsCurveEvaluator();
|
motion_trail_vertex._nurbs_curve_evaluator = new NurbsCurveEvaluator();
|
||||||
|
_vertex_list.push_back(std::move(motion_trail_vertex));
|
||||||
_vertex_list.push_back(motion_trail_vertex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -182,14 +125,6 @@ check_for_update(PN_stdfloat current_time) {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void CMotionTrail::
|
|
||||||
begin_geometry() {
|
|
||||||
begin_geometry(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -198,7 +133,6 @@ begin_geometry(int num_quads) {
|
|||||||
const int num_vertices = num_quads * 4;
|
const int num_vertices = num_quads * 4;
|
||||||
const GeomVertexFormat *format;
|
const GeomVertexFormat *format;
|
||||||
|
|
||||||
_vertex_index = 0;
|
|
||||||
if (_use_texture) {
|
if (_use_texture) {
|
||||||
format = GeomVertexFormat::get_v3c4t2();
|
format = GeomVertexFormat::get_v3c4t2();
|
||||||
}
|
}
|
||||||
@ -266,10 +200,14 @@ begin_geometry(int num_quads) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LVector3 vertex version.
|
*
|
||||||
*/
|
*/
|
||||||
void CMotionTrail::
|
void CMotionTrail::
|
||||||
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) {
|
add_geometry_quad(
|
||||||
|
const LPoint3 &v0, const LPoint3 &v1, const LPoint3 &v2, const LPoint3 &v3,
|
||||||
|
const LVector4 &c0, const LVector4 &c1, const LVector4 &c2, const LVector4 &c3,
|
||||||
|
const LVector2 &t0, const LVector2 &t1, const LVector2 &t2, const LVector2 &t3) {
|
||||||
|
|
||||||
_vertex_writer.set_data3(v0);
|
_vertex_writer.set_data3(v0);
|
||||||
_vertex_writer.set_data3(v1);
|
_vertex_writer.set_data3(v1);
|
||||||
_vertex_writer.set_data3(v2);
|
_vertex_writer.set_data3(v2);
|
||||||
@ -288,29 +226,6 @@ add_geometry_quad(LVector3 &v0, LVector3 &v1, LVector3 &v2, LVector3 &v3, LVecto
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* LVector4 vertex version.
|
|
||||||
*/
|
|
||||||
void CMotionTrail::
|
|
||||||
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) {
|
|
||||||
_vertex_writer.set_data3(v0[0], v0[1], v0[2]);
|
|
||||||
_vertex_writer.set_data3(v1[0], v1[1], v1[2]);
|
|
||||||
_vertex_writer.set_data3(v2[0], v2[1], v2[2]);
|
|
||||||
_vertex_writer.set_data3(v3[0], v3[1], v3[2]);
|
|
||||||
|
|
||||||
_color_writer.set_data4(c0);
|
|
||||||
_color_writer.set_data4(c1);
|
|
||||||
_color_writer.set_data4(c2);
|
|
||||||
_color_writer.set_data4(c3);
|
|
||||||
|
|
||||||
if (_use_texture) {
|
|
||||||
_texture_writer.set_data2(t0);
|
|
||||||
_texture_writer.set_data2(t1);
|
|
||||||
_texture_writer.set_data2(t2);
|
|
||||||
_texture_writer.set_data2(t3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -338,11 +253,11 @@ end_geometry() {
|
|||||||
* See class header comments.
|
* See class header comments.
|
||||||
*/
|
*/
|
||||||
void CMotionTrail::
|
void CMotionTrail::
|
||||||
update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform) {
|
update_motion_trail(PN_stdfloat current_time, const LMatrix4 &transform) {
|
||||||
int debug = false;
|
bool debug = false;
|
||||||
|
|
||||||
if (!_frame_list.empty()) {
|
if (!_frame_list.empty()) {
|
||||||
if (_frame_list.front()._transform == UnalignedLMatrix4(*transform)) {
|
if (_frame_list.front()._transform == transform) {
|
||||||
// duplicate transform
|
// duplicate transform
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -387,7 +302,7 @@ update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform) {
|
|||||||
{
|
{
|
||||||
CMotionTrailFrame motion_trail_frame;
|
CMotionTrailFrame motion_trail_frame;
|
||||||
motion_trail_frame._time = current_time;
|
motion_trail_frame._time = current_time;
|
||||||
motion_trail_frame._transform = *transform;
|
motion_trail_frame._transform = transform;
|
||||||
_frame_list.push_front(std::move(motion_trail_frame));
|
_frame_list.push_front(std::move(motion_trail_frame));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,45 +337,32 @@ update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform) {
|
|||||||
delta_time = current_time - minimum_time;
|
delta_time = current_time - minimum_time;
|
||||||
|
|
||||||
if (_calculate_relative_matrix) {
|
if (_calculate_relative_matrix) {
|
||||||
inverse_matrix = *transform;
|
inverse_matrix.invert_from(transform);
|
||||||
inverse_matrix.invert_in_place();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_use_nurbs && total_frames >= 5) {
|
if (_use_nurbs && total_frames >= 5) {
|
||||||
// nurbs version
|
// nurbs version
|
||||||
LVector3 vector;
|
LVector4 v0, v1, v2, v3;
|
||||||
LVector4 v;
|
|
||||||
LVector4 v0;
|
|
||||||
LVector4 v1;
|
|
||||||
LVector4 v2;
|
|
||||||
LVector4 v3;
|
|
||||||
|
|
||||||
PN_stdfloat total_distance = 0.0f;
|
PN_stdfloat total_distance = 0.0f;
|
||||||
|
|
||||||
// reset NurbsCurveEvaluators for each vertex (the starting point for
|
// reset NurbsCurveEvaluators for each vertex (the starting point for
|
||||||
// the trail)
|
// the trail)
|
||||||
{
|
for (int index = 0; index < total_vertices; ++index) {
|
||||||
CMotionTrailVertex *motion_trail_vertex;
|
CMotionTrailVertex *motion_trail_vertex = &vertex_array[index];
|
||||||
PT(NurbsCurveEvaluator) nurbs_curve_evaluator;
|
NurbsCurveEvaluator *nurbs_curve_evaluator;
|
||||||
|
nurbs_curve_evaluator = motion_trail_vertex->_nurbs_curve_evaluator;
|
||||||
for (int index = 0; index < total_vertices; ++index) {
|
nurbs_curve_evaluator->set_order(4);
|
||||||
motion_trail_vertex = &vertex_array[index];
|
nurbs_curve_evaluator->reset(total_segments);
|
||||||
nurbs_curve_evaluator = motion_trail_vertex->_nurbs_curve_evaluator;
|
|
||||||
nurbs_curve_evaluator->set_order(4);
|
|
||||||
nurbs_curve_evaluator->reset(total_segments);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add vertices to each NurbsCurveEvaluator
|
// add vertices to each NurbsCurveEvaluator
|
||||||
CMotionTrailFrame motion_trail_frame_start;
|
|
||||||
CMotionTrailFrame motion_trail_frame_end;
|
|
||||||
|
|
||||||
FrameList::iterator frame_iterator;
|
FrameList::iterator frame_iterator;
|
||||||
frame_iterator = _frame_list.begin();
|
frame_iterator = _frame_list.begin();
|
||||||
for (int segment_index = 0; segment_index < total_segments; ++segment_index) {
|
for (int segment_index = 0; segment_index < total_segments; ++segment_index) {
|
||||||
motion_trail_frame_start = *frame_iterator;
|
const CMotionTrailFrame &motion_trail_frame_start = *frame_iterator;
|
||||||
frame_iterator++;
|
frame_iterator++;
|
||||||
motion_trail_frame_end = *frame_iterator;
|
const CMotionTrailFrame &motion_trail_frame_end = *frame_iterator;
|
||||||
|
|
||||||
if (_calculate_relative_matrix) {
|
if (_calculate_relative_matrix) {
|
||||||
start_transform.multiply(motion_trail_frame_start._transform, inverse_matrix);
|
start_transform.multiply(motion_trail_frame_start._transform, inverse_matrix);
|
||||||
@ -471,15 +373,13 @@ update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform) {
|
|||||||
end_transform = motion_trail_frame_end._transform;
|
end_transform = motion_trail_frame_end._transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
CMotionTrailVertex *motion_trail_vertex_start;
|
CMotionTrailVertex *motion_trail_vertex_start = &vertex_array[0];
|
||||||
CMotionTrailVertex *motion_trail_vertex_end;
|
CMotionTrailVertex *motion_trail_vertex_end;
|
||||||
PT(NurbsCurveEvaluator) nurbs_curve_evaluator;
|
|
||||||
|
|
||||||
motion_trail_vertex_start = &vertex_array[0];
|
|
||||||
|
|
||||||
v0 = start_transform.xform(motion_trail_vertex_start->_vertex);
|
v0 = start_transform.xform(motion_trail_vertex_start->_vertex);
|
||||||
v2 = end_transform.xform(motion_trail_vertex_start->_vertex);
|
v2 = end_transform.xform(motion_trail_vertex_start->_vertex);
|
||||||
|
|
||||||
|
NurbsCurveEvaluator *nurbs_curve_evaluator;
|
||||||
nurbs_curve_evaluator = motion_trail_vertex_start->_nurbs_curve_evaluator;
|
nurbs_curve_evaluator = motion_trail_vertex_start->_nurbs_curve_evaluator;
|
||||||
nurbs_curve_evaluator->set_vertex(segment_index, v0);
|
nurbs_curve_evaluator->set_vertex(segment_index, v0);
|
||||||
|
|
||||||
@ -493,15 +393,12 @@ update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform) {
|
|||||||
v3 = end_transform.xform(motion_trail_vertex_end->_vertex);
|
v3 = end_transform.xform(motion_trail_vertex_end->_vertex);
|
||||||
|
|
||||||
nurbs_curve_evaluator = motion_trail_vertex_end->_nurbs_curve_evaluator;
|
nurbs_curve_evaluator = motion_trail_vertex_end->_nurbs_curve_evaluator;
|
||||||
|
|
||||||
nurbs_curve_evaluator->set_vertex(segment_index, v1);
|
nurbs_curve_evaluator->set_vertex(segment_index, v1);
|
||||||
if (vertex_segment_index == (total_vertex_segments - 1)) {
|
|
||||||
PN_stdfloat distance;
|
|
||||||
|
|
||||||
v = v1 - v3;
|
if (vertex_segment_index == total_vertex_segments - 1) {
|
||||||
vector.set (v[0], v[1], v[2]);
|
LVector3 v = v1.get_xyz() - v3.get_xyz();
|
||||||
distance = vector.length();
|
LVector3 vector(v[0], v[1], v[2]);
|
||||||
total_distance += distance;
|
total_distance += vector.length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -511,26 +408,19 @@ update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform) {
|
|||||||
|
|
||||||
nurbs_curve_result_array = new PT(NurbsCurveResult)[total_vertices];
|
nurbs_curve_result_array = new PT(NurbsCurveResult)[total_vertices];
|
||||||
for (int index = 0; index < total_vertices; ++index) {
|
for (int index = 0; index < total_vertices; ++index) {
|
||||||
|
CMotionTrailVertex *motion_trail_vertex = &vertex_array[index];
|
||||||
|
|
||||||
CMotionTrailVertex *motion_trail_vertex;
|
PT(NurbsCurveResult) nurbs_curve_result =
|
||||||
PT(NurbsCurveEvaluator) nurbs_curve_evaluator;
|
motion_trail_vertex->_nurbs_curve_evaluator->evaluate();
|
||||||
PT(NurbsCurveResult) nurbs_curve_result;
|
|
||||||
|
|
||||||
motion_trail_vertex = &vertex_array[index];
|
|
||||||
|
|
||||||
nurbs_curve_evaluator = motion_trail_vertex->_nurbs_curve_evaluator;
|
|
||||||
nurbs_curve_result = nurbs_curve_evaluator->evaluate();
|
|
||||||
nurbs_curve_result_array[index] = nurbs_curve_result;
|
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
PN_stdfloat nurbs_start_t;
|
PN_stdfloat nurbs_start_t = nurbs_curve_result->get_start_t();
|
||||||
PN_stdfloat nurbs_end_t;
|
PN_stdfloat nurbs_end_t = nurbs_curve_result->get_end_t();
|
||||||
|
|
||||||
nurbs_start_t = nurbs_curve_result->get_start_t();
|
|
||||||
nurbs_end_t = nurbs_curve_result->get_end_t();
|
|
||||||
|
|
||||||
printf("nurbs_start_t %f, nurbs_end_t %f \n", nurbs_start_t, nurbs_end_t);
|
printf("nurbs_start_t %f, nurbs_end_t %f \n", nurbs_start_t, nurbs_end_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nurbs_curve_result_array[index] = std::move(nurbs_curve_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create quads from NurbsCurveResult
|
// create quads from NurbsCurveResult
|
||||||
@ -543,7 +433,7 @@ update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform) {
|
|||||||
begin_geometry(total_curve_segments_int * total_vertex_segments);
|
begin_geometry(total_curve_segments_int * total_vertex_segments);
|
||||||
|
|
||||||
{
|
{
|
||||||
LVector3 v0, v1, v2, v3;
|
LPoint3 v0, v1, v2, v3;
|
||||||
LVector4 c0, c1, c2, c3;
|
LVector4 c0, c1, c2, c3;
|
||||||
LVector2 t0, t1, t2, t3;
|
LVector2 t0, t1, t2, t3;
|
||||||
|
|
||||||
@ -553,35 +443,25 @@ update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform) {
|
|||||||
for (int curve_segment_index = 0;
|
for (int curve_segment_index = 0;
|
||||||
curve_segment_index < total_curve_segments_int;
|
curve_segment_index < total_curve_segments_int;
|
||||||
++curve_segment_index) {
|
++curve_segment_index) {
|
||||||
PN_stdfloat st;
|
|
||||||
PN_stdfloat et;
|
|
||||||
PN_stdfloat start_t;
|
|
||||||
PN_stdfloat end_t;
|
|
||||||
PN_stdfloat color_start_t;
|
|
||||||
PN_stdfloat color_end_t;
|
|
||||||
|
|
||||||
CMotionTrailVertex *motion_trail_vertex_start;
|
PN_stdfloat st = curve_segment_index / total_curve_segments;
|
||||||
CMotionTrailVertex *motion_trail_vertex_end;
|
PN_stdfloat et = (curve_segment_index + 1) / total_curve_segments;
|
||||||
PT(NurbsCurveResult) start_nurbs_curve_result;
|
|
||||||
PT(NurbsCurveResult) end_nurbs_curve_result;
|
|
||||||
|
|
||||||
st = curve_segment_index / total_curve_segments;
|
PN_stdfloat start_t = st;
|
||||||
et = (curve_segment_index + 1) / total_curve_segments;
|
PN_stdfloat end_t = et;
|
||||||
|
|
||||||
start_t = st;
|
|
||||||
end_t = et;
|
|
||||||
|
|
||||||
if (_square_t) {
|
if (_square_t) {
|
||||||
start_t *= start_t;
|
start_t *= start_t;
|
||||||
end_t *= end_t;
|
end_t *= end_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
motion_trail_vertex_start = &vertex_array[0];
|
CMotionTrailVertex *motion_trail_vertex_start = &vertex_array[0];
|
||||||
|
CMotionTrailVertex *motion_trail_vertex_end;
|
||||||
|
|
||||||
vertex_start_color = motion_trail_vertex_start->_end_color + (motion_trail_vertex_start->_start_color - motion_trail_vertex_start ->_end_color);
|
vertex_start_color = motion_trail_vertex_start->_end_color + (motion_trail_vertex_start->_start_color - motion_trail_vertex_start ->_end_color);
|
||||||
|
|
||||||
color_start_t = color_scale * start_t;
|
PN_stdfloat color_start_t = color_scale * start_t;
|
||||||
color_end_t = color_scale * end_t;
|
PN_stdfloat color_end_t = color_scale * end_t;
|
||||||
|
|
||||||
c0 = vertex_start_color * one_minus_x(color_start_t);
|
c0 = vertex_start_color * one_minus_x(color_start_t);
|
||||||
c2 = vertex_start_color * one_minus_x(color_end_t);
|
c2 = vertex_start_color * one_minus_x(color_end_t);
|
||||||
@ -593,27 +473,19 @@ update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform) {
|
|||||||
vertex_segment_index < total_vertex_segments;
|
vertex_segment_index < total_vertex_segments;
|
||||||
++vertex_segment_index) {
|
++vertex_segment_index) {
|
||||||
|
|
||||||
PN_stdfloat start_nurbs_start_t;
|
|
||||||
PN_stdfloat start_nurbs_end_t;
|
|
||||||
PN_stdfloat end_nurbs_start_t;
|
|
||||||
PN_stdfloat end_nurbs_end_t;
|
|
||||||
|
|
||||||
motion_trail_vertex_start = &vertex_array[vertex_segment_index];
|
motion_trail_vertex_start = &vertex_array[vertex_segment_index];
|
||||||
motion_trail_vertex_end = &vertex_array[vertex_segment_index + 1];
|
motion_trail_vertex_end = &vertex_array[vertex_segment_index + 1];
|
||||||
|
|
||||||
start_nurbs_curve_result = nurbs_curve_result_array[vertex_segment_index];
|
NurbsCurveResult *start_nurbs_curve_result = nurbs_curve_result_array[vertex_segment_index];
|
||||||
end_nurbs_curve_result = nurbs_curve_result_array[vertex_segment_index + 1];
|
NurbsCurveResult *end_nurbs_curve_result = nurbs_curve_result_array[vertex_segment_index + 1];
|
||||||
|
|
||||||
start_nurbs_start_t = start_nurbs_curve_result->get_start_t();
|
PN_stdfloat start_nurbs_start_t = start_nurbs_curve_result->get_start_t();
|
||||||
start_nurbs_end_t = start_nurbs_curve_result->get_end_t();
|
PN_stdfloat start_nurbs_end_t = start_nurbs_curve_result->get_end_t();
|
||||||
end_nurbs_start_t = end_nurbs_curve_result->get_start_t();
|
PN_stdfloat end_nurbs_start_t = end_nurbs_curve_result->get_start_t();
|
||||||
end_nurbs_end_t = end_nurbs_curve_result->get_end_t();
|
PN_stdfloat end_nurbs_end_t = end_nurbs_curve_result->get_end_t();
|
||||||
|
|
||||||
PN_stdfloat start_delta_t;
|
PN_stdfloat start_delta_t = (start_nurbs_end_t - start_nurbs_start_t);
|
||||||
PN_stdfloat end_delta_t;
|
PN_stdfloat end_delta_t = (end_nurbs_end_t - end_nurbs_start_t);
|
||||||
|
|
||||||
start_delta_t = (start_nurbs_end_t - start_nurbs_start_t);
|
|
||||||
end_delta_t = (end_nurbs_end_t - end_nurbs_start_t);
|
|
||||||
|
|
||||||
start_nurbs_curve_result->eval_point(start_nurbs_start_t + (start_delta_t * st), v0);
|
start_nurbs_curve_result->eval_point(start_nurbs_start_t + (start_delta_t * st), v0);
|
||||||
end_nurbs_curve_result->eval_point(end_nurbs_start_t + (end_delta_t * st), v1);
|
end_nurbs_curve_result->eval_point(end_nurbs_start_t + (end_delta_t * st), v1);
|
||||||
@ -655,13 +527,6 @@ update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform) {
|
|||||||
|
|
||||||
begin_geometry(total_segments * total_vertex_segments);
|
begin_geometry(total_segments * total_vertex_segments);
|
||||||
|
|
||||||
PN_stdfloat st;
|
|
||||||
PN_stdfloat et;
|
|
||||||
PN_stdfloat start_t;
|
|
||||||
PN_stdfloat end_t;
|
|
||||||
PN_stdfloat color_start_t;
|
|
||||||
PN_stdfloat color_end_t;
|
|
||||||
|
|
||||||
LVector4 v0, v1, v2, v3;
|
LVector4 v0, v1, v2, v3;
|
||||||
LVector4 c0, c1, c2, c3;
|
LVector4 c0, c1, c2, c3;
|
||||||
LVector2 t0, t1, t2, t3;
|
LVector2 t0, t1, t2, t3;
|
||||||
@ -669,23 +534,17 @@ update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform) {
|
|||||||
LVector4 vertex_start_color;
|
LVector4 vertex_start_color;
|
||||||
LVector4 vertex_end_color;
|
LVector4 vertex_end_color;
|
||||||
|
|
||||||
CMotionTrailFrame motion_trail_frame_start;
|
|
||||||
CMotionTrailFrame motion_trail_frame_end;
|
|
||||||
|
|
||||||
FrameList::iterator frame_iterator = _frame_list.begin();
|
FrameList::iterator frame_iterator = _frame_list.begin();
|
||||||
for (int segment_index = 0; segment_index < total_segments; ++segment_index) {
|
for (int segment_index = 0; segment_index < total_segments; ++segment_index) {
|
||||||
CMotionTrailVertex *motion_trail_vertex_start;
|
const CMotionTrailFrame &motion_trail_frame_start = *frame_iterator;
|
||||||
CMotionTrailVertex *motion_trail_vertex_end;
|
|
||||||
|
|
||||||
motion_trail_frame_start = *frame_iterator;
|
|
||||||
frame_iterator++;
|
frame_iterator++;
|
||||||
motion_trail_frame_end = *frame_iterator;
|
const CMotionTrailFrame &motion_trail_frame_end = *frame_iterator;
|
||||||
|
|
||||||
start_t = (motion_trail_frame_start._time - minimum_time) / delta_time;
|
PN_stdfloat start_t = (motion_trail_frame_start._time - minimum_time) / delta_time;
|
||||||
end_t = (motion_trail_frame_end._time - minimum_time) / delta_time;
|
PN_stdfloat end_t = (motion_trail_frame_end._time - minimum_time) / delta_time;
|
||||||
|
|
||||||
st = start_t;
|
PN_stdfloat st = start_t;
|
||||||
et = end_t;
|
PN_stdfloat et = end_t;
|
||||||
|
|
||||||
if (_square_t) {
|
if (_square_t) {
|
||||||
start_t *= start_t;
|
start_t *= start_t;
|
||||||
@ -701,14 +560,15 @@ update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform) {
|
|||||||
end_transform = motion_trail_frame_end._transform;
|
end_transform = motion_trail_frame_end._transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
motion_trail_vertex_start = &vertex_array[0];
|
CMotionTrailVertex *motion_trail_vertex_start = &vertex_array[0];
|
||||||
|
CMotionTrailVertex *motion_trail_vertex_end;
|
||||||
|
|
||||||
v0 = start_transform.xform(motion_trail_vertex_start->_vertex);
|
v0 = start_transform.xform(motion_trail_vertex_start->_vertex);
|
||||||
v2 = end_transform.xform(motion_trail_vertex_start->_vertex);
|
v2 = end_transform.xform(motion_trail_vertex_start->_vertex);
|
||||||
|
|
||||||
vertex_start_color = motion_trail_vertex_start->_end_color + (motion_trail_vertex_start->_start_color - motion_trail_vertex_start->_end_color);
|
vertex_start_color = motion_trail_vertex_start->_end_color + (motion_trail_vertex_start->_start_color - motion_trail_vertex_start->_end_color);
|
||||||
color_start_t = color_scale * start_t;
|
PN_stdfloat color_start_t = color_scale * start_t;
|
||||||
color_end_t = color_scale * end_t;
|
PN_stdfloat color_end_t = color_scale * end_t;
|
||||||
c0 = vertex_start_color * color_start_t;
|
c0 = vertex_start_color * color_start_t;
|
||||||
c2 = vertex_start_color * color_end_t;
|
c2 = vertex_start_color * color_end_t;
|
||||||
|
|
||||||
@ -734,7 +594,9 @@ update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform) {
|
|||||||
t1.set(st, motion_trail_vertex_end->_v);
|
t1.set(st, motion_trail_vertex_end->_v);
|
||||||
t3.set(et, motion_trail_vertex_end->_v);
|
t3.set(et, motion_trail_vertex_end->_v);
|
||||||
|
|
||||||
add_geometry_quad(v0, v1, v2, v3, c0, c1, c2, c3, t0, t1, t2, t3);
|
add_geometry_quad((const LPoint3 &)v0, (const LPoint3 &)v1,
|
||||||
|
(const LPoint3 &)v2, (const LPoint3 &)v3,
|
||||||
|
c0, c1, c2, c3, t0, t1, t2, t3);
|
||||||
|
|
||||||
// reuse calculations
|
// reuse calculations
|
||||||
v0 = v1;
|
v0 = v1;
|
||||||
|
@ -21,13 +21,11 @@
|
|||||||
#include "geomVertexWriter.h"
|
#include "geomVertexWriter.h"
|
||||||
#include "geomTriangles.h"
|
#include "geomTriangles.h"
|
||||||
#include "luse.h"
|
#include "luse.h"
|
||||||
#include "memoryBase.h"
|
|
||||||
#include "nurbsCurveEvaluator.h"
|
#include "nurbsCurveEvaluator.h"
|
||||||
#include "plist.h"
|
#include "plist.h"
|
||||||
#include "epvector.h"
|
#include "epvector.h"
|
||||||
|
|
||||||
class CMotionTrailVertex : public MemoryBase {
|
struct CMotionTrailVertex : public MemoryBase {
|
||||||
public:
|
|
||||||
LPoint4 _vertex;
|
LPoint4 _vertex;
|
||||||
LVecBase4 _start_color;
|
LVecBase4 _start_color;
|
||||||
LVecBase4 _end_color;
|
LVecBase4 _end_color;
|
||||||
@ -36,9 +34,8 @@ public:
|
|||||||
PT(NurbsCurveEvaluator) _nurbs_curve_evaluator;
|
PT(NurbsCurveEvaluator) _nurbs_curve_evaluator;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CMotionTrailFrame {
|
struct CMotionTrailFrame : public MemoryBase {
|
||||||
public:
|
LMatrix4 _transform;
|
||||||
UnalignedLMatrix4 _transform;
|
|
||||||
PN_stdfloat _time;
|
PN_stdfloat _time;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -72,8 +69,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
class EXPCL_DIRECT_MOTIONTRAIL CMotionTrail : public TypedReferenceCount {
|
class EXPCL_DIRECT_MOTIONTRAIL CMotionTrail : public TypedReferenceCount {
|
||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
CMotionTrail();
|
CMotionTrail() = default;
|
||||||
~CMotionTrail();
|
~CMotionTrail() = default;
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
void reset_vertex_list();
|
void reset_vertex_list();
|
||||||
@ -81,65 +78,65 @@ PUBLISHED:
|
|||||||
void enable(bool enable);
|
void enable(bool enable);
|
||||||
|
|
||||||
void set_geom_node(GeomNode *geom_node);
|
void set_geom_node(GeomNode *geom_node);
|
||||||
void add_vertex(LVector4 *vertex, LVector4 *start_color, LVector4 *end_color, PN_stdfloat v);
|
void add_vertex(const LVector4 &vertex, const LVector4 &start_color,
|
||||||
|
const LVector4 &end_color, PN_stdfloat v);
|
||||||
|
|
||||||
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);
|
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);
|
||||||
|
|
||||||
int check_for_update(PN_stdfloat current_time);
|
int check_for_update(PN_stdfloat current_time);
|
||||||
void update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform);
|
void update_motion_trail(PN_stdfloat current_time, const LMatrix4 &transform);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void begin_geometry();
|
|
||||||
void begin_geometry(int num_quads);
|
void begin_geometry(int num_quads);
|
||||||
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);
|
void add_geometry_quad(
|
||||||
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);
|
const LPoint3 &v0, const LPoint3 &v1, const LPoint3 &v2, const LPoint3 &v3,
|
||||||
|
const LVector4 &c0, const LVector4 &c1, const LVector4 &c2, const LVector4 &c3,
|
||||||
|
const LVector2 &t0, const LVector2 &t1, const LVector2 &t2, const LVector2 &t3);
|
||||||
void end_geometry();
|
void end_geometry();
|
||||||
|
|
||||||
int _active;
|
bool _active = true;
|
||||||
int _enable;
|
bool _enable = true;
|
||||||
|
|
||||||
int _pause;
|
bool _pause = false;
|
||||||
PN_stdfloat _pause_time;
|
PN_stdfloat _pause_time = 0.0f;
|
||||||
|
|
||||||
int _fade;
|
bool _fade = false;
|
||||||
int _fade_end;
|
bool _fade_end = false;
|
||||||
PN_stdfloat _fade_time;
|
PN_stdfloat _fade_time = 0.0f;
|
||||||
PN_stdfloat _fade_start_time;
|
PN_stdfloat _fade_start_time = 0.0f;
|
||||||
PN_stdfloat _fade_color_scale;
|
PN_stdfloat _fade_color_scale = 1.0f;
|
||||||
|
|
||||||
PN_stdfloat _last_update_time;
|
PN_stdfloat _last_update_time = 0.0f;
|
||||||
|
|
||||||
typedef epvector<CMotionTrailVertex> VertexList;
|
typedef epvector<CMotionTrailVertex> VertexList;
|
||||||
VertexList _vertex_list;
|
VertexList _vertex_list;
|
||||||
typedef plist<CMotionTrailFrame> FrameList;
|
typedef pdeque<CMotionTrailFrame> FrameList;
|
||||||
FrameList _frame_list;
|
FrameList _frame_list;
|
||||||
|
|
||||||
// parameters
|
// parameters
|
||||||
PN_stdfloat _color_scale;
|
PN_stdfloat _color_scale = 1.0f;
|
||||||
PN_stdfloat _sampling_time;
|
PN_stdfloat _sampling_time = 0.0f;
|
||||||
PN_stdfloat _time_window;
|
PN_stdfloat _time_window = 1.0f;
|
||||||
bool _square_t;
|
bool _square_t = true;
|
||||||
bool _use_texture;
|
bool _use_texture = false;
|
||||||
int _calculate_relative_matrix;
|
bool _calculate_relative_matrix = false;
|
||||||
|
|
||||||
// nurbs parameters
|
// nurbs parameters
|
||||||
bool _use_nurbs;
|
bool _use_nurbs = false;
|
||||||
PN_stdfloat _resolution_distance;
|
PN_stdfloat _resolution_distance = 0.5f;
|
||||||
|
|
||||||
// geom
|
// geom
|
||||||
PT(GeomNode) _geom_node;
|
PT(GeomNode) _geom_node;
|
||||||
|
|
||||||
// real-time data
|
// real-time data
|
||||||
int _vertex_index;
|
|
||||||
PT(GeomVertexData) _vertex_data;
|
PT(GeomVertexData) _vertex_data;
|
||||||
GeomVertexWriter _vertex_writer;
|
GeomVertexWriter _vertex_writer;
|
||||||
GeomVertexWriter _color_writer;
|
GeomVertexWriter _color_writer;
|
||||||
GeomVertexWriter _texture_writer;
|
GeomVertexWriter _texture_writer;
|
||||||
PT(GeomTriangles) _triangles;
|
PT(GeomTriangles) _triangles;
|
||||||
|
|
||||||
CMotionTrailVertex *_vertex_array;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static TypeHandle get_class_type() {
|
static TypeHandle get_class_type() {
|
||||||
return _type_handle;
|
return _type_handle;
|
||||||
@ -156,7 +153,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static TypeHandle _type_handle;
|
static TypeHandle _type_handle;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user