mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-28 15:53:55 -04:00
motiontrail: Clean up and optimization of C++ implementation
This commit is contained in:
parent
9cb60ccd93
commit
19186781f3
@ -15,7 +15,16 @@
|
||||
#include "cMotionTrail.h"
|
||||
#include "renderState.h"
|
||||
#include "colorAttrib.h"
|
||||
#include "cmath.h"
|
||||
|
||||
static PN_stdfloat one_minus_x(PN_stdfloat x) {
|
||||
x = 1.0 - x;
|
||||
if (x < 0.0) {
|
||||
x = 0.0;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
TypeHandle CMotionTrail::_type_handle;
|
||||
|
||||
@ -173,21 +182,20 @@ check_for_update (PN_stdfloat current_time) {
|
||||
return state;
|
||||
}
|
||||
|
||||
PN_stdfloat one_minus_x (PN_stdfloat x) {
|
||||
x = 1.0 - x;
|
||||
if (x < 0.0) {
|
||||
x = 0.0;
|
||||
}
|
||||
|
||||
return x;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void CMotionTrail::
|
||||
begin_geometry() {
|
||||
begin_geometry(0);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void CMotionTrail::
|
||||
begin_geometry ( ) {
|
||||
|
||||
begin_geometry(int num_quads) {
|
||||
const int num_vertices = num_quads * 4;
|
||||
const GeomVertexFormat *format;
|
||||
|
||||
_vertex_index = 0;
|
||||
@ -205,14 +213,56 @@ begin_geometry ( ) {
|
||||
_color_writer.clear();
|
||||
_texture_writer.clear();
|
||||
|
||||
Thread *current_thread = Thread::get_current_thread();
|
||||
|
||||
_vertex_data = new GeomVertexData("vertices", format, Geom::UH_static);
|
||||
_vertex_writer = GeomVertexWriter (_vertex_data, "vertex");
|
||||
_color_writer = GeomVertexWriter (_vertex_data, "color");
|
||||
_vertex_data->unclean_set_num_rows(num_vertices);
|
||||
_vertex_writer = GeomVertexWriter(_vertex_data, "vertex", current_thread);
|
||||
_color_writer = GeomVertexWriter(_vertex_data, "color", current_thread);
|
||||
if (_use_texture) {
|
||||
_texture_writer = GeomVertexWriter (_vertex_data, "texcoord");
|
||||
_texture_writer = GeomVertexWriter(_vertex_data, "texcoord", current_thread);
|
||||
}
|
||||
|
||||
// We know how many triangles we'll be adding, so add them up front.
|
||||
_triangles = new GeomTriangles(Geom::UH_static);
|
||||
if (num_quads * 6 <= 65535) {
|
||||
_triangles->set_index_type(GeomEnums::NT_uint16);
|
||||
} else {
|
||||
_triangles->set_index_type(GeomEnums::NT_uint32);
|
||||
}
|
||||
|
||||
{
|
||||
PT(GeomVertexArrayDataHandle) idx_handle = _triangles->modify_vertices_handle(current_thread);
|
||||
idx_handle->unclean_set_num_rows(num_quads * 6);
|
||||
if (num_quads * 6 <= 65535) {
|
||||
// 16-bit index case.
|
||||
uint16_t *idx_ptr = (uint16_t *)idx_handle->get_write_pointer();
|
||||
|
||||
for (int i = 0; i < num_vertices; i += 4) {
|
||||
*(idx_ptr++) = i + 0;
|
||||
*(idx_ptr++) = i + 1;
|
||||
*(idx_ptr++) = i + 2;
|
||||
*(idx_ptr++) = i + 1;
|
||||
*(idx_ptr++) = i + 3;
|
||||
*(idx_ptr++) = i + 2;
|
||||
}
|
||||
} else {
|
||||
// 32-bit index case.
|
||||
uint32_t *idx_ptr = (uint32_t *)idx_handle->get_write_pointer();
|
||||
|
||||
for (int i = 0; i < num_vertices; i += 4) {
|
||||
*(idx_ptr++) = i + 0;
|
||||
*(idx_ptr++) = i + 1;
|
||||
*(idx_ptr++) = i + 2;
|
||||
*(idx_ptr++) = i + 1;
|
||||
*(idx_ptr++) = i + 3;
|
||||
*(idx_ptr++) = i + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We can compute this value much faster than GeomPrimitive can.
|
||||
_triangles->set_minmax(0, num_vertices - 1, nullptr, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -220,38 +270,22 @@ begin_geometry ( ) {
|
||||
*/
|
||||
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) {
|
||||
_vertex_writer.set_data3(v0);
|
||||
_vertex_writer.set_data3(v1);
|
||||
_vertex_writer.set_data3(v2);
|
||||
_vertex_writer.set_data3(v3);
|
||||
|
||||
_vertex_writer.add_data3 (v0);
|
||||
_vertex_writer.add_data3 (v1);
|
||||
_vertex_writer.add_data3 (v2);
|
||||
_vertex_writer.add_data3 (v3);
|
||||
|
||||
_color_writer.add_data4 (c0);
|
||||
_color_writer.add_data4 (c1);
|
||||
_color_writer.add_data4 (c2);
|
||||
_color_writer.add_data4 (c3);
|
||||
_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.add_data2 (t0);
|
||||
_texture_writer.add_data2 (t1);
|
||||
_texture_writer.add_data2 (t2);
|
||||
_texture_writer.add_data2 (t3);
|
||||
_texture_writer.set_data2(t0);
|
||||
_texture_writer.set_data2(t1);
|
||||
_texture_writer.set_data2(t2);
|
||||
_texture_writer.set_data2(t3);
|
||||
}
|
||||
|
||||
int vertex_index;
|
||||
vertex_index = _vertex_index;
|
||||
|
||||
_triangles -> add_vertex (vertex_index + 0);
|
||||
_triangles -> add_vertex (vertex_index + 1);
|
||||
_triangles -> add_vertex (vertex_index + 2);
|
||||
_triangles -> close_primitive ( );
|
||||
|
||||
_triangles -> add_vertex (vertex_index + 1);
|
||||
_triangles -> add_vertex (vertex_index + 3);
|
||||
_triangles -> add_vertex (vertex_index + 2);
|
||||
_triangles -> close_primitive ( );
|
||||
|
||||
_vertex_index += 4;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -259,52 +293,39 @@ add_geometry_quad (LVector3 &v0, LVector3 &v1, LVector3 &v2, LVector3 &v3, LVect
|
||||
*/
|
||||
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]);
|
||||
|
||||
_vertex_writer.add_data3 (v0 [0], v0 [1], v0 [2]);
|
||||
_vertex_writer.add_data3 (v1 [0], v1 [1], v1 [2]);
|
||||
_vertex_writer.add_data3 (v2 [0], v2 [1], v2 [2]);
|
||||
_vertex_writer.add_data3 (v3 [0], v3 [1], v3 [2]);
|
||||
|
||||
_color_writer.add_data4 (c0);
|
||||
_color_writer.add_data4 (c1);
|
||||
_color_writer.add_data4 (c2);
|
||||
_color_writer.add_data4 (c3);
|
||||
_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.add_data2 (t0);
|
||||
_texture_writer.add_data2 (t1);
|
||||
_texture_writer.add_data2 (t2);
|
||||
_texture_writer.add_data2 (t3);
|
||||
_texture_writer.set_data2(t0);
|
||||
_texture_writer.set_data2(t1);
|
||||
_texture_writer.set_data2(t2);
|
||||
_texture_writer.set_data2(t3);
|
||||
}
|
||||
|
||||
int vertex_index;
|
||||
vertex_index = _vertex_index;
|
||||
|
||||
_triangles -> add_vertex (vertex_index + 0);
|
||||
_triangles -> add_vertex (vertex_index + 1);
|
||||
_triangles -> add_vertex (vertex_index + 2);
|
||||
_triangles -> close_primitive ( );
|
||||
|
||||
_triangles -> add_vertex (vertex_index + 1);
|
||||
_triangles -> add_vertex (vertex_index + 3);
|
||||
_triangles -> add_vertex (vertex_index + 2);
|
||||
_triangles -> close_primitive ( );
|
||||
|
||||
_vertex_index += 4;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void CMotionTrail::end_geometry ( ) {
|
||||
void CMotionTrail::
|
||||
end_geometry() {
|
||||
static CPT(RenderState) state;
|
||||
if (state == nullptr) {
|
||||
state = RenderState::make(ColorAttrib::make_vertex());
|
||||
}
|
||||
|
||||
PT(Geom) geometry;
|
||||
_vertex_writer.clear();
|
||||
_color_writer.clear();
|
||||
_texture_writer.clear();
|
||||
|
||||
geometry = new Geom (_vertex_data);
|
||||
PT(Geom) geometry = new Geom(_vertex_data);
|
||||
geometry->add_primitive(_triangles);
|
||||
|
||||
if (_geom_node) {
|
||||
@ -318,32 +339,20 @@ void CMotionTrail::end_geometry ( ) {
|
||||
*/
|
||||
void CMotionTrail::
|
||||
update_motion_trail(PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
int debug = false;
|
||||
|
||||
int debug;
|
||||
int total_frames;
|
||||
|
||||
debug = false;
|
||||
|
||||
total_frames = _frame_list.size ( );
|
||||
if (total_frames >= 1) {
|
||||
FrameList::iterator frame_iterator;
|
||||
CMotionTrailFrame motion_trail_frame;
|
||||
|
||||
frame_iterator = _frame_list.begin ( );
|
||||
motion_trail_frame = *frame_iterator;
|
||||
if (motion_trail_frame._transform == UnalignedLMatrix4(*transform)) {
|
||||
if (!_frame_list.empty()) {
|
||||
if (_frame_list.front()._transform == UnalignedLMatrix4(*transform)) {
|
||||
// duplicate transform
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int total_vertices;
|
||||
PN_stdfloat color_scale;
|
||||
LMatrix4 start_transform;
|
||||
LMatrix4 end_transform;
|
||||
LMatrix4 inverse_matrix;
|
||||
|
||||
total_vertices = _vertex_list.size ( );
|
||||
color_scale = _color_scale;
|
||||
if (_fade) {
|
||||
PN_stdfloat elapsed_time;
|
||||
@ -364,15 +373,10 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
_last_update_time = current_time;
|
||||
|
||||
// remove expired frames
|
||||
PN_stdfloat minimum_time;
|
||||
|
||||
minimum_time = current_time - _time_window;
|
||||
|
||||
CMotionTrailFrame motion_trail_frame;
|
||||
PN_stdfloat minimum_time = current_time - _time_window;
|
||||
|
||||
while (!_frame_list.empty()) {
|
||||
motion_trail_frame = _frame_list.back();
|
||||
if (motion_trail_frame._time >= minimum_time) {
|
||||
if (_frame_list.back()._time >= minimum_time) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -382,22 +386,20 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
// add new frame to beginning of list
|
||||
{
|
||||
CMotionTrailFrame motion_trail_frame;
|
||||
|
||||
motion_trail_frame._time = current_time;
|
||||
motion_trail_frame._transform = *transform;
|
||||
|
||||
_frame_list.push_front(motion_trail_frame);
|
||||
_frame_list.push_front(std::move(motion_trail_frame));
|
||||
}
|
||||
|
||||
// convert frames and vertices to geometry
|
||||
total_frames = _frame_list.size ( );
|
||||
int total_frames = (int)_frame_list.size();
|
||||
int total_vertices = (int)_vertex_list.size();
|
||||
|
||||
if (debug) {
|
||||
printf("update_motion_trail, total_frames = %d, total_vertices = %d, nurbs = %d, _calculate_relative_matrix = %d \n", total_frames, total_vertices, _use_nurbs, _calculate_relative_matrix);
|
||||
}
|
||||
|
||||
if ((total_frames >= 2) && (total_vertices >= 2)) {
|
||||
int total_segments;
|
||||
if (total_frames >= 2 && total_vertices >= 2) {
|
||||
PN_stdfloat minimum_time;
|
||||
PN_stdfloat delta_time;
|
||||
CMotionTrailFrame last_motion_trail_frame;
|
||||
@ -406,16 +408,14 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
|
||||
// convert vertex list to vertex array
|
||||
int index = 0;
|
||||
_vertex_array = new CMotionTrailVertex [total_vertices];
|
||||
CMotionTrailVertex *vertex_array = new CMotionTrailVertex[total_vertices];
|
||||
for (vertex_iterator = _vertex_list.begin(); vertex_iterator != _vertex_list.end(); vertex_iterator++) {
|
||||
_vertex_array [index] = *vertex_iterator;
|
||||
index++;
|
||||
vertex_array[index] = *vertex_iterator;
|
||||
++index;
|
||||
}
|
||||
|
||||
// begin geometry
|
||||
this -> begin_geometry ( );
|
||||
|
||||
total_segments = total_frames - 1;
|
||||
const int total_segments = total_frames - 1;
|
||||
const int total_vertex_segments = total_vertices - 1;
|
||||
|
||||
last_motion_trail_frame = _frame_list.back();
|
||||
minimum_time = last_motion_trail_frame._time;
|
||||
@ -426,11 +426,8 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
inverse_matrix.invert_in_place();
|
||||
}
|
||||
|
||||
if (_use_nurbs && (total_frames >= 5)) {
|
||||
|
||||
if (_use_nurbs && total_frames >= 5) {
|
||||
// nurbs version
|
||||
int total_vertex_segments;
|
||||
PN_stdfloat total_distance;
|
||||
LVector3 vector;
|
||||
LVector4 v;
|
||||
LVector4 v0;
|
||||
@ -438,8 +435,7 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
LVector4 v2;
|
||||
LVector4 v3;
|
||||
|
||||
total_vertex_segments = total_vertices - 1;
|
||||
total_distance = 0.0f;
|
||||
PN_stdfloat total_distance = 0.0f;
|
||||
|
||||
// reset NurbsCurveEvaluators for each vertex (the starting point for
|
||||
// the trail)
|
||||
@ -447,8 +443,8 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
CMotionTrailVertex *motion_trail_vertex;
|
||||
PT(NurbsCurveEvaluator) nurbs_curve_evaluator;
|
||||
|
||||
for (index = 0; index < total_vertices; index++) {
|
||||
motion_trail_vertex = &_vertex_array [index];
|
||||
for (int index = 0; index < total_vertices; ++index) {
|
||||
motion_trail_vertex = &vertex_array[index];
|
||||
nurbs_curve_evaluator = motion_trail_vertex->_nurbs_curve_evaluator;
|
||||
nurbs_curve_evaluator->set_order(4);
|
||||
nurbs_curve_evaluator->reset(total_segments);
|
||||
@ -456,17 +452,12 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
}
|
||||
|
||||
// add vertices to each NurbsCurveEvaluator
|
||||
int segment_index;
|
||||
CMotionTrailFrame motion_trail_frame_start;
|
||||
CMotionTrailFrame motion_trail_frame_end;
|
||||
|
||||
segment_index = 0;
|
||||
|
||||
FrameList::iterator frame_iterator;
|
||||
frame_iterator = _frame_list.begin();
|
||||
while (segment_index < total_segments) {
|
||||
int vertex_segement_index;
|
||||
|
||||
for (int segment_index = 0; segment_index < total_segments; ++segment_index) {
|
||||
motion_trail_frame_start = *frame_iterator;
|
||||
frame_iterator++;
|
||||
motion_trail_frame_end = *frame_iterator;
|
||||
@ -484,7 +475,7 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
CMotionTrailVertex *motion_trail_vertex_end;
|
||||
PT(NurbsCurveEvaluator) nurbs_curve_evaluator;
|
||||
|
||||
motion_trail_vertex_start = &_vertex_array [0];
|
||||
motion_trail_vertex_start = &vertex_array[0];
|
||||
|
||||
v0 = start_transform.xform(motion_trail_vertex_start->_vertex);
|
||||
v2 = end_transform.xform(motion_trail_vertex_start->_vertex);
|
||||
@ -492,10 +483,11 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
nurbs_curve_evaluator = motion_trail_vertex_start->_nurbs_curve_evaluator;
|
||||
nurbs_curve_evaluator->set_vertex(segment_index, v0);
|
||||
|
||||
vertex_segement_index = 0;
|
||||
while (vertex_segement_index < total_vertex_segments) {
|
||||
motion_trail_vertex_start = &_vertex_array [vertex_segement_index];
|
||||
motion_trail_vertex_end = &_vertex_array [vertex_segement_index + 1];
|
||||
for (int vertex_segment_index = 0;
|
||||
vertex_segment_index < total_vertex_segments;
|
||||
++vertex_segment_index) {
|
||||
motion_trail_vertex_start = &vertex_array[vertex_segment_index];
|
||||
motion_trail_vertex_end = &vertex_array[vertex_segment_index + 1];
|
||||
|
||||
v1 = start_transform.xform(motion_trail_vertex_end->_vertex);
|
||||
v3 = end_transform.xform(motion_trail_vertex_end->_vertex);
|
||||
@ -503,7 +495,7 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
nurbs_curve_evaluator = motion_trail_vertex_end->_nurbs_curve_evaluator;
|
||||
|
||||
nurbs_curve_evaluator->set_vertex(segment_index, v1);
|
||||
if (vertex_segement_index == (total_vertex_segments - 1)) {
|
||||
if (vertex_segment_index == (total_vertex_segments - 1)) {
|
||||
PN_stdfloat distance;
|
||||
|
||||
v = v1 - v3;
|
||||
@ -511,24 +503,20 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
distance = vector.length();
|
||||
total_distance += distance;
|
||||
}
|
||||
|
||||
vertex_segement_index += 1;
|
||||
}
|
||||
|
||||
segment_index += 1;
|
||||
}
|
||||
|
||||
// evaluate NurbsCurveEvaluator for each vertex
|
||||
PT(NurbsCurveResult) *nurbs_curve_result_array;
|
||||
|
||||
nurbs_curve_result_array = new PT(NurbsCurveResult)[total_vertices];
|
||||
for (index = 0; index < total_vertices; index++) {
|
||||
for (int index = 0; index < total_vertices; ++index) {
|
||||
|
||||
CMotionTrailVertex *motion_trail_vertex;
|
||||
PT(NurbsCurveEvaluator) nurbs_curve_evaluator;
|
||||
PT(NurbsCurveResult) nurbs_curve_result;
|
||||
|
||||
motion_trail_vertex = &_vertex_array [index];
|
||||
motion_trail_vertex = &vertex_array[index];
|
||||
|
||||
nurbs_curve_evaluator = motion_trail_vertex->_nurbs_curve_evaluator;
|
||||
nurbs_curve_result = nurbs_curve_evaluator->evaluate();
|
||||
@ -546,37 +534,25 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
}
|
||||
|
||||
// create quads from NurbsCurveResult
|
||||
PN_stdfloat total_curve_segments;
|
||||
|
||||
total_curve_segments = (total_distance / _resolution_distance);
|
||||
PN_stdfloat total_curve_segments = total_distance / _resolution_distance;
|
||||
if (total_curve_segments < total_segments) {
|
||||
total_curve_segments = total_segments;
|
||||
}
|
||||
|
||||
const int total_curve_segments_int = (int)cceil(total_curve_segments);
|
||||
begin_geometry(total_curve_segments_int * total_vertex_segments);
|
||||
|
||||
{
|
||||
LVector3 v0;
|
||||
LVector3 v1;
|
||||
LVector3 v2;
|
||||
LVector3 v3;
|
||||
|
||||
LVector4 c0;
|
||||
LVector4 c1;
|
||||
LVector4 c2;
|
||||
LVector4 c3;
|
||||
|
||||
LVector2 t0;
|
||||
LVector2 t1;
|
||||
LVector2 t2;
|
||||
LVector2 t3;
|
||||
LVector3 v0, v1, v2, v3;
|
||||
LVector4 c0, c1, c2, c3;
|
||||
LVector2 t0, t1, t2, t3;
|
||||
|
||||
LVector4 vertex_start_color;
|
||||
LVector4 vertex_end_color;
|
||||
|
||||
PN_stdfloat curve_segment_index;
|
||||
|
||||
curve_segment_index = 0.0;
|
||||
while (curve_segment_index < total_curve_segments) {
|
||||
|
||||
for (int curve_segment_index = 0;
|
||||
curve_segment_index < total_curve_segments_int;
|
||||
++curve_segment_index) {
|
||||
PN_stdfloat st;
|
||||
PN_stdfloat et;
|
||||
PN_stdfloat start_t;
|
||||
@ -584,17 +560,13 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
PN_stdfloat color_start_t;
|
||||
PN_stdfloat color_end_t;
|
||||
|
||||
int vertex_segement_index;
|
||||
|
||||
CMotionTrailVertex *motion_trail_vertex_start;
|
||||
CMotionTrailVertex *motion_trail_vertex_end;
|
||||
PT(NurbsCurveResult) start_nurbs_curve_result;
|
||||
PT(NurbsCurveResult) end_nurbs_curve_result;
|
||||
|
||||
vertex_segement_index = 0;
|
||||
|
||||
st = curve_segment_index / total_curve_segments;
|
||||
et = (curve_segment_index + 1.0) / total_curve_segments;
|
||||
et = (curve_segment_index + 1) / total_curve_segments;
|
||||
|
||||
start_t = st;
|
||||
end_t = et;
|
||||
@ -604,7 +576,7 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
end_t *= end_t;
|
||||
}
|
||||
|
||||
motion_trail_vertex_start = &_vertex_array [0];
|
||||
motion_trail_vertex_start = &vertex_array[0];
|
||||
|
||||
vertex_start_color = motion_trail_vertex_start->_end_color + (motion_trail_vertex_start->_start_color - motion_trail_vertex_start ->_end_color);
|
||||
|
||||
@ -617,18 +589,20 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
t0.set(one_minus_x(st), motion_trail_vertex_start->_v);
|
||||
t2.set(one_minus_x(et), motion_trail_vertex_start->_v);
|
||||
|
||||
while (vertex_segement_index < total_vertex_segments) {
|
||||
for (int vertex_segment_index = 0;
|
||||
vertex_segment_index < total_vertex_segments;
|
||||
++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_segement_index];
|
||||
motion_trail_vertex_end = &_vertex_array [vertex_segement_index + 1];
|
||||
motion_trail_vertex_start = &vertex_array[vertex_segment_index];
|
||||
motion_trail_vertex_end = &vertex_array[vertex_segment_index + 1];
|
||||
|
||||
start_nurbs_curve_result = nurbs_curve_result_array [vertex_segement_index];
|
||||
end_nurbs_curve_result = nurbs_curve_result_array [vertex_segement_index + 1];
|
||||
start_nurbs_curve_result = nurbs_curve_result_array[vertex_segment_index];
|
||||
end_nurbs_curve_result = nurbs_curve_result_array[vertex_segment_index + 1];
|
||||
|
||||
start_nurbs_start_t = start_nurbs_curve_result->get_start_t();
|
||||
start_nurbs_end_t = start_nurbs_curve_result->get_end_t();
|
||||
@ -657,7 +631,7 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
t1.set(one_minus_x(st), motion_trail_vertex_end->_v);
|
||||
t3.set(one_minus_x(et), motion_trail_vertex_end->_v);
|
||||
|
||||
this -> add_geometry_quad (v0, v1, v2, v3, c0, c1, c2, c3, t0, t1, t2, t3);
|
||||
add_geometry_quad(v0, v1, v2, v3, c0, c1, c2, c3, t0, t1, t2, t3);
|
||||
|
||||
// reuse calculations
|
||||
c0 = c1;
|
||||
@ -665,26 +639,21 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
|
||||
t0 = t1;
|
||||
t2 = t3;
|
||||
|
||||
vertex_segement_index += 1;
|
||||
}
|
||||
|
||||
curve_segment_index += 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
for (index = 0; index < total_vertices; index++) {
|
||||
for (int index = 0; index < total_vertices; ++index) {
|
||||
nurbs_curve_result_array[index] = nullptr;
|
||||
}
|
||||
|
||||
delete[] nurbs_curve_result_array;
|
||||
}
|
||||
else {
|
||||
|
||||
// non-nurbs version
|
||||
int segment_index;
|
||||
int vertex_segment_index;
|
||||
int total_vertex_segments;
|
||||
const int total_vertex_segments = total_vertices - 1;
|
||||
|
||||
begin_geometry(total_segments * total_vertex_segments);
|
||||
|
||||
PN_stdfloat st;
|
||||
PN_stdfloat et;
|
||||
@ -693,20 +662,9 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
PN_stdfloat color_start_t;
|
||||
PN_stdfloat color_end_t;
|
||||
|
||||
LVector4 v0;
|
||||
LVector4 v1;
|
||||
LVector4 v2;
|
||||
LVector4 v3;
|
||||
|
||||
LVector4 c0;
|
||||
LVector4 c1;
|
||||
LVector4 c2;
|
||||
LVector4 c3;
|
||||
|
||||
LVector2 t0;
|
||||
LVector2 t1;
|
||||
LVector2 t2;
|
||||
LVector2 t3;
|
||||
LVector4 v0, v1, v2, v3;
|
||||
LVector4 c0, c1, c2, c3;
|
||||
LVector2 t0, t1, t2, t3;
|
||||
|
||||
LVector4 vertex_start_color;
|
||||
LVector4 vertex_end_color;
|
||||
@ -714,11 +672,8 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
CMotionTrailFrame motion_trail_frame_start;
|
||||
CMotionTrailFrame motion_trail_frame_end;
|
||||
|
||||
segment_index = 0;
|
||||
FrameList::iterator frame_iterator;
|
||||
frame_iterator = _frame_list.begin ( );
|
||||
while (segment_index < total_segments) {
|
||||
|
||||
FrameList::iterator frame_iterator = _frame_list.begin();
|
||||
for (int segment_index = 0; segment_index < total_segments; ++segment_index) {
|
||||
CMotionTrailVertex *motion_trail_vertex_start;
|
||||
CMotionTrailVertex *motion_trail_vertex_end;
|
||||
|
||||
@ -737,9 +692,6 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
end_t *= end_t;
|
||||
}
|
||||
|
||||
vertex_segment_index = 0;
|
||||
total_vertex_segments = total_vertices - 1;
|
||||
|
||||
if (_calculate_relative_matrix) {
|
||||
start_transform.multiply(motion_trail_frame_start._transform, inverse_matrix);
|
||||
end_transform.multiply(motion_trail_frame_end._transform, inverse_matrix);
|
||||
@ -749,7 +701,7 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
end_transform = motion_trail_frame_end._transform;
|
||||
}
|
||||
|
||||
motion_trail_vertex_start = &_vertex_array [0];
|
||||
motion_trail_vertex_start = &vertex_array[0];
|
||||
|
||||
v0 = start_transform.xform(motion_trail_vertex_start->_vertex);
|
||||
v2 = end_transform.xform(motion_trail_vertex_start->_vertex);
|
||||
@ -763,10 +715,11 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
t0.set(st, motion_trail_vertex_start->_v);
|
||||
t2.set(et, motion_trail_vertex_start->_v);
|
||||
|
||||
while (vertex_segment_index < total_vertex_segments) {
|
||||
|
||||
motion_trail_vertex_start = &_vertex_array [vertex_segment_index];
|
||||
motion_trail_vertex_end = &_vertex_array [vertex_segment_index + 1];
|
||||
for (int vertex_segment_index = 0;
|
||||
vertex_segment_index < total_vertex_segments;
|
||||
++vertex_segment_index) {
|
||||
motion_trail_vertex_start = &vertex_array[vertex_segment_index];
|
||||
motion_trail_vertex_end = &vertex_array[vertex_segment_index + 1];
|
||||
|
||||
v1 = start_transform.xform(motion_trail_vertex_end->_vertex);
|
||||
v3 = end_transform.xform(motion_trail_vertex_end->_vertex);
|
||||
@ -781,7 +734,7 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
t1.set(st, motion_trail_vertex_end->_v);
|
||||
t3.set(et, motion_trail_vertex_end->_v);
|
||||
|
||||
this -> add_geometry_quad (v0, v1, v2, v3, c0, c1, c2, c3, t0, t1, t2, t3);
|
||||
add_geometry_quad(v0, v1, v2, v3, c0, c1, c2, c3, t0, t1, t2, t3);
|
||||
|
||||
// reuse calculations
|
||||
v0 = v1;
|
||||
@ -792,18 +745,12 @@ update_motion_trail (PN_stdfloat current_time, LMatrix4 *transform) {
|
||||
|
||||
t0 = t1;
|
||||
t2 = t3;
|
||||
|
||||
vertex_segment_index += 1;
|
||||
}
|
||||
|
||||
segment_index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// end geometry
|
||||
this -> end_geometry ( );
|
||||
end_geometry();
|
||||
|
||||
delete[] _vertex_array;
|
||||
_vertex_array = nullptr;
|
||||
delete[] vertex_array;
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ PUBLISHED:
|
||||
public:
|
||||
|
||||
void begin_geometry();
|
||||
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(LVector4 &v0, LVector4 &v1, LVector4 &v2, LVector4 &v3, LVector4 &c0, LVector4 &c1, LVector4 &c2, LVector4 &c3, LVector2 &t0, LVector2 &t1, LVector2 &t2, LVector2 &t3);
|
||||
void end_geometry();
|
||||
|
Loading…
x
Reference in New Issue
Block a user