Add comments, formatting, cleanup, ...
This commit is contained in:
parent
9449c113df
commit
9c9101452d
|
|
@ -1,10 +1,33 @@
|
|||
// Filename: cMotionTrail.h
|
||||
// Created by: aignacio (29Jan07)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2007, Disney Enterprises, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "directbase.h"
|
||||
#include "cMotionTrail.h"
|
||||
|
||||
|
||||
// TypeHandle CMotionTrail::_type_handle;
|
||||
TypeHandle CMotionTrail::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CMotionTrail::Constructor
|
||||
// Access: Published
|
||||
// Description: Constructor
|
||||
////////////////////////////////////////////////////////////////////
|
||||
CMotionTrail::
|
||||
CMotionTrail ( ) {
|
||||
|
||||
|
|
@ -20,88 +43,89 @@ CMotionTrail ( ) {
|
|||
_fade_start_time = 0.0f;
|
||||
_fade_color_scale = 1.0f;
|
||||
|
||||
_vertex_array = 0;
|
||||
_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;
|
||||
|
||||
_playing = false;
|
||||
|
||||
// default options
|
||||
_continuous_motion_trail = true;
|
||||
_color_scale = 1.0;
|
||||
_time_window = 1.0;
|
||||
_sampling_time = 0.0;
|
||||
_square_t = true;
|
||||
|
||||
// _task_transform = false;
|
||||
|
||||
// root_node_path = None
|
||||
// nurbs parameters
|
||||
_use_nurbs = false;
|
||||
_resolution_distance = 0.5f;
|
||||
|
||||
// node path states
|
||||
_geom_node = 0;
|
||||
// geom_node_path =
|
||||
|
||||
_relative_to_render = false;
|
||||
|
||||
// nurbs parameters
|
||||
_use_nurbs = !false;
|
||||
_resolution_distance = 0.5f;
|
||||
|
||||
// real-time data
|
||||
_vertex_index = 0;
|
||||
_vertex_data = 0;
|
||||
_triangles = 0;
|
||||
|
||||
_vertex_array = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CMotionTrail::Destructor
|
||||
// Access: Published
|
||||
// Description: Destructor
|
||||
////////////////////////////////////////////////////////////////////
|
||||
CMotionTrail::
|
||||
~CMotionTrail ( ) {
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CMotionTrail::reset
|
||||
// Access: Published
|
||||
// Description: Reset the frame sample history.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CMotionTrail::
|
||||
reset ( ) {
|
||||
_frame_list.clear ( );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CMotionTrail::reset_vertex_list
|
||||
// Access: Published
|
||||
// Description: Reset the vertex list.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CMotionTrail::
|
||||
reset_vertex_list ( ) {
|
||||
_vertex_list.clear ( );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CMotionTrail::enable
|
||||
// Access: Published
|
||||
// Description: Enable/disable the motion trail.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CMotionTrail::
|
||||
enable (bool enable) {
|
||||
_enable = enable;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CMotionTrail::set_geom_node
|
||||
// Access: Published
|
||||
// Description: Set the GeomNode.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CMotionTrail::
|
||||
set_geom_node (PT(GeomNode) geom_node) {
|
||||
_geom_node = geom_node;
|
||||
}
|
||||
|
||||
void CMotionTrail::
|
||||
use_nurbs (bool enable) {
|
||||
_use_nurbs = enable;
|
||||
}
|
||||
|
||||
void CMotionTrail::
|
||||
use_texture (bool enable) {
|
||||
_use_texture = enable;
|
||||
}
|
||||
|
||||
void CMotionTrail::
|
||||
calculate_relative_matrix (bool enable) {
|
||||
_calculate_relative_matrix = enable;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CMotionTrail::add_vertex
|
||||
// Access: Published
|
||||
// Description: Add a vertex.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CMotionTrail::
|
||||
add_vertex (LVector4f *vertex, LVector4f *start_color, LVector4f *end_color, float v) {
|
||||
|
||||
|
|
@ -117,6 +141,47 @@ add_vertex (LVector4f *vertex, LVector4f *start_color, LVector4f *end_color, flo
|
|||
_vertex_list.push_back (motion_trail_vertex);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CMotionTrail::set_parameters
|
||||
// Access: Published
|
||||
// Description: Set motion trail parameters.
|
||||
//
|
||||
// sampling_time = Can be used to specify a lower
|
||||
// sampling rate than the frame rate. Use 0.0 with
|
||||
// nurbs.
|
||||
//
|
||||
// time_window = a component for the "length" of the
|
||||
// motion trail. The motion trail length =
|
||||
// time_window * velocity of the object.
|
||||
//
|
||||
// use_texture = texture option on/off.
|
||||
//
|
||||
// calculate_relative_matrix = calculate relative
|
||||
// matrix on/off.
|
||||
//
|
||||
// use_nurbs = nurbs option on/off
|
||||
//
|
||||
// resolution_distance = the distance used to
|
||||
// determine the number of geometry samples.
|
||||
// samples = motion trail length / resolution_distance.
|
||||
// Applicable only if nurbs is on.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CMotionTrail::
|
||||
set_parameters (float sampling_time, float time_window, bool use_texture, bool calculate_relative_matrix, bool use_nurbs, float resolution_distance) {
|
||||
|
||||
_sampling_time = sampling_time;
|
||||
_time_window = time_window;
|
||||
_use_texture = use_texture;
|
||||
_calculate_relative_matrix = calculate_relative_matrix;
|
||||
_use_nurbs = use_nurbs;
|
||||
_resolution_distance = resolution_distance;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CMotionTrail::check_for_update
|
||||
// Access: Published
|
||||
// Description: Check if a sample can be submitted.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int CMotionTrail::
|
||||
check_for_update (float current_time) {
|
||||
|
||||
|
|
@ -143,6 +208,11 @@ float one_minus_x (float x) {
|
|||
return x;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CMotionTrail::begin_geometry
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CMotionTrail::
|
||||
begin_geometry ( ) {
|
||||
|
||||
|
|
@ -166,6 +236,11 @@ begin_geometry ( ) {
|
|||
_triangles = new GeomTriangles (Geom::UH_static);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CMotionTrail::add_geometry_quad
|
||||
// Access: Public
|
||||
// Description: LVector3f vertex version.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CMotionTrail::
|
||||
add_geometry_quad (LVector3f &v0, LVector3f &v1, LVector3f &v2, LVector3f &v3, LVector4f &c0, LVector4f &c1, LVector4f &c2, LVector4f &c3, LVector2f &t0, LVector2f &t1, LVector2f &t2, LVector2f &t3) {
|
||||
|
||||
|
|
@ -202,6 +277,11 @@ add_geometry_quad (LVector3f &v0, LVector3f &v1, LVector3f &v2, LVector3f &v3, L
|
|||
_vertex_index += 4;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CMotionTrail::add_geometry_quad
|
||||
// Access: Public
|
||||
// Description: LVector4f vertex version.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CMotionTrail::
|
||||
add_geometry_quad (LVector4f &v0, LVector4f &v1, LVector4f &v2, LVector4f &v3, LVector4f &c0, LVector4f &c1, LVector4f &c2, LVector4f &c3, LVector2f &t0, LVector2f &t1, LVector2f &t2, LVector2f &t3) {
|
||||
|
||||
|
|
@ -238,6 +318,11 @@ add_geometry_quad (LVector4f &v0, LVector4f &v1, LVector4f &v2, LVector4f &v3, L
|
|||
_vertex_index += 4;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CMotionTrail::end_geometry
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CMotionTrail::end_geometry ( ) {
|
||||
|
||||
PT(Geom) geometry;
|
||||
|
|
@ -251,6 +336,11 @@ void CMotionTrail::end_geometry ( ) {
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CMotionTrail::update_motion_trail
|
||||
// Access: Published
|
||||
// Description: See class header comments.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CMotionTrail::
|
||||
update_motion_trail (float current_time, LMatrix4f *transform) {
|
||||
|
||||
|
|
@ -280,21 +370,17 @@ update_motion_trail (float current_time, LMatrix4f *transform) {
|
|||
|
||||
total_vertices = _vertex_list.size ( );
|
||||
color_scale = _color_scale;
|
||||
if (_fade)
|
||||
{
|
||||
if (_fade) {
|
||||
float elapsed_time;
|
||||
|
||||
elapsed_time = current_time - _fade_start_time;
|
||||
if (elapsed_time < 0.0)
|
||||
{
|
||||
if (elapsed_time < 0.0) {
|
||||
elapsed_time = 0.0;
|
||||
}
|
||||
if (elapsed_time < _fade_time)
|
||||
{
|
||||
if (elapsed_time < _fade_time) {
|
||||
color_scale = (1.0f - (elapsed_time / _fade_time)) * color_scale;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
color_scale = 0.0;
|
||||
_fade_end = true;
|
||||
}
|
||||
|
|
@ -315,16 +401,13 @@ update_motion_trail (float current_time, LMatrix4f *transform) {
|
|||
index = 0;
|
||||
last_frame_index = total_frames - 1;
|
||||
frame_iterator = _frame_list.end ( );
|
||||
while (index <= last_frame_index)
|
||||
{
|
||||
while (index <= last_frame_index) {
|
||||
frame_iterator--;
|
||||
motion_trail_frame = *frame_iterator;
|
||||
if (motion_trail_frame._time >= minimum_time)
|
||||
{
|
||||
if (motion_trail_frame._time >= minimum_time) {
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
_frame_list.pop_back ( );
|
||||
}
|
||||
|
||||
|
|
@ -344,13 +427,11 @@ update_motion_trail (float current_time, LMatrix4f *transform) {
|
|||
// convert frames and vertices to geometry
|
||||
total_frames = _frame_list.size ( );
|
||||
|
||||
if (debug)
|
||||
{
|
||||
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))
|
||||
{
|
||||
if ((total_frames >= 2) && (total_vertices >= 2)) {
|
||||
int total_segments;
|
||||
float minimum_time;
|
||||
float delta_time;
|
||||
|
|
@ -358,11 +439,10 @@ update_motion_trail (float current_time, LMatrix4f *transform) {
|
|||
|
||||
list <CMotionTrailVertex>::iterator vertex_iterator;
|
||||
|
||||
// vertex list to vertex array
|
||||
// convert vertex list to vertex array
|
||||
index = 0;
|
||||
_vertex_array = new CMotionTrailVertex [total_vertices];
|
||||
for (vertex_iterator = _vertex_list.begin ( ); vertex_iterator != _vertex_list.end ( ); vertex_iterator++)
|
||||
{
|
||||
for (vertex_iterator = _vertex_list.begin ( ); vertex_iterator != _vertex_list.end ( ); vertex_iterator++) {
|
||||
_vertex_array [index] = *vertex_iterator;
|
||||
index++;
|
||||
}
|
||||
|
|
@ -379,17 +459,15 @@ update_motion_trail (float current_time, LMatrix4f *transform) {
|
|||
minimum_time = last_motion_trail_frame._time;
|
||||
delta_time = current_time - minimum_time;
|
||||
|
||||
if (_calculate_relative_matrix)
|
||||
{
|
||||
if (_calculate_relative_matrix) {
|
||||
inverse_matrix = *transform;
|
||||
inverse_matrix.invert_in_place ( );
|
||||
}
|
||||
|
||||
if (_use_nurbs && (total_frames >= 5))
|
||||
{
|
||||
if (_use_nurbs && (total_frames >= 5)) {
|
||||
|
||||
// nurbs version
|
||||
int total_vertex_segments;
|
||||
|
||||
float total_distance;
|
||||
LVector3f vector;
|
||||
LVector4f v;
|
||||
|
|
@ -398,22 +476,22 @@ update_motion_trail (float current_time, LMatrix4f *transform) {
|
|||
LVector4f v2;
|
||||
LVector4f v3;
|
||||
|
||||
total_vertex_segments = total_vertices - 1;
|
||||
total_distance = 0.0f;
|
||||
|
||||
// reset NurbsCurveEvaluators for each vertex (the starting point for the trail)
|
||||
total_vertex_segments = total_vertices - 1;
|
||||
for (index = 0; index < total_vertices; index++)
|
||||
{
|
||||
CMotionTrailVertex *motion_trail_vertex;
|
||||
PT(NurbsCurveEvaluator) nurbs_curve_evaluator;
|
||||
|
||||
{
|
||||
CMotionTrailVertex *motion_trail_vertex;
|
||||
PT(NurbsCurveEvaluator) nurbs_curve_evaluator;
|
||||
|
||||
for (index = 0; index < total_vertices; index++) {
|
||||
motion_trail_vertex = &_vertex_array [index];
|
||||
nurbs_curve_evaluator = motion_trail_vertex -> _nurbs_curve_evaluator;
|
||||
nurbs_curve_evaluator -> reset (total_segments);
|
||||
}
|
||||
}
|
||||
|
||||
// add vertices to each NurbsCurveEvaluator
|
||||
|
||||
|
||||
// add vertices to each NurbsCurveEvaluator
|
||||
int segment_index;
|
||||
CMotionTrailFrame motion_trail_frame_start;
|
||||
CMotionTrailFrame motion_trail_frame_end;
|
||||
|
|
@ -421,99 +499,93 @@ update_motion_trail (float current_time, LMatrix4f *transform) {
|
|||
segment_index = 0;
|
||||
|
||||
frame_iterator = _frame_list.begin ( );
|
||||
while (segment_index < total_segments)
|
||||
{
|
||||
int vertex_segement_index;
|
||||
|
||||
motion_trail_frame_start = *frame_iterator;
|
||||
frame_iterator++;
|
||||
motion_trail_frame_end = *frame_iterator;
|
||||
|
||||
if (_calculate_relative_matrix) {
|
||||
start_transform.multiply (motion_trail_frame_start._transform, inverse_matrix);
|
||||
end_transform.multiply (motion_trail_frame_end._transform, inverse_matrix);
|
||||
}
|
||||
else {
|
||||
start_transform = motion_trail_frame_start._transform;
|
||||
end_transform = motion_trail_frame_end._transform;
|
||||
while (segment_index < total_segments) {
|
||||
int vertex_segement_index;
|
||||
|
||||
motion_trail_frame_start = *frame_iterator;
|
||||
frame_iterator++;
|
||||
motion_trail_frame_end = *frame_iterator;
|
||||
|
||||
if (_calculate_relative_matrix) {
|
||||
start_transform.multiply (motion_trail_frame_start._transform, inverse_matrix);
|
||||
end_transform.multiply (motion_trail_frame_end._transform, inverse_matrix);
|
||||
}
|
||||
else {
|
||||
start_transform = motion_trail_frame_start._transform;
|
||||
end_transform = motion_trail_frame_end._transform;
|
||||
}
|
||||
|
||||
CMotionTrailVertex *motion_trail_vertex_start;
|
||||
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);
|
||||
v2 = end_transform.xform (motion_trail_vertex_start -> _vertex);
|
||||
|
||||
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];
|
||||
|
||||
v1 = start_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 -> set_vertex (segment_index, v1);
|
||||
if (vertex_segement_index == (total_vertex_segments - 1)) {
|
||||
float distance;
|
||||
|
||||
v = v1 - v3;
|
||||
vector.set (v[0], v[1], v[2]);
|
||||
distance = vector.length();
|
||||
total_distance += distance;
|
||||
}
|
||||
|
||||
CMotionTrailVertex *motion_trail_vertex_start;
|
||||
CMotionTrailVertex *motion_trail_vertex_end;
|
||||
PT(NurbsCurveEvaluator) nurbs_curve_evaluator;
|
||||
|
||||
motion_trail_vertex_start = &_vertex_array [0];
|
||||
vertex_segement_index += 1;
|
||||
}
|
||||
|
||||
v0 = start_transform.xform (motion_trail_vertex_start -> _vertex);
|
||||
v2 = end_transform.xform (motion_trail_vertex_start -> _vertex);
|
||||
|
||||
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];
|
||||
|
||||
v1 = start_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 -> set_vertex (segment_index, v1);
|
||||
if (vertex_segement_index == (total_vertex_segments - 1))
|
||||
{
|
||||
float distance;
|
||||
|
||||
v = v1 - v3;
|
||||
vector.set (v[0], v[1], v[2]);
|
||||
distance = vector.length();
|
||||
total_distance += distance;
|
||||
}
|
||||
|
||||
vertex_segement_index += 1;
|
||||
}
|
||||
|
||||
segment_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++)
|
||||
{
|
||||
CMotionTrailVertex *motion_trail_vertex;
|
||||
PT(NurbsCurveEvaluator) nurbs_curve_evaluator;
|
||||
PT(NurbsCurveResult) nurbs_curve_result;
|
||||
|
||||
motion_trail_vertex = &_vertex_array [index];
|
||||
for (index = 0; index < total_vertices; index++) {
|
||||
|
||||
CMotionTrailVertex *motion_trail_vertex;
|
||||
PT(NurbsCurveEvaluator) nurbs_curve_evaluator;
|
||||
PT(NurbsCurveResult) nurbs_curve_result;
|
||||
|
||||
nurbs_curve_evaluator = motion_trail_vertex -> _nurbs_curve_evaluator;
|
||||
nurbs_curve_result = nurbs_curve_evaluator -> evaluate ( );
|
||||
nurbs_curve_result_array [index] = nurbs_curve_result;
|
||||
motion_trail_vertex = &_vertex_array [index];
|
||||
|
||||
if (debug)
|
||||
{
|
||||
float nurbs_start_t;
|
||||
float nurbs_end_t;
|
||||
nurbs_curve_evaluator = motion_trail_vertex -> _nurbs_curve_evaluator;
|
||||
nurbs_curve_result = nurbs_curve_evaluator -> evaluate ( );
|
||||
nurbs_curve_result_array [index] = nurbs_curve_result;
|
||||
|
||||
nurbs_start_t = nurbs_curve_result -> get_start_t();
|
||||
nurbs_end_t = nurbs_curve_result -> get_end_t();
|
||||
if (debug) {
|
||||
float nurbs_start_t;
|
||||
float nurbs_end_t;
|
||||
|
||||
printf ("nurbs_start_t %f, nurbs_end_t %f \n", nurbs_start_t, nurbs_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);
|
||||
}
|
||||
}
|
||||
|
||||
// create quads from NurbsCurveResult
|
||||
float total_curve_segments;
|
||||
|
||||
total_curve_segments = (total_distance / _resolution_distance);
|
||||
if (total_curve_segments < total_segments)
|
||||
{
|
||||
total_curve_segments = total_segments;
|
||||
if (total_curve_segments < total_segments) {
|
||||
total_curve_segments = total_segments;
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -538,109 +610,108 @@ update_motion_trail (float current_time, LMatrix4f *transform) {
|
|||
float curve_segment_index;
|
||||
|
||||
curve_segment_index = 0.0;
|
||||
while (curve_segment_index < total_curve_segments)
|
||||
{
|
||||
float st;
|
||||
float et;
|
||||
float start_t;
|
||||
float end_t;
|
||||
float color_start_t;
|
||||
float color_end_t;
|
||||
while (curve_segment_index < total_curve_segments) {
|
||||
|
||||
float st;
|
||||
float et;
|
||||
float start_t;
|
||||
float end_t;
|
||||
float color_start_t;
|
||||
float color_end_t;
|
||||
|
||||
int vertex_segement_index;
|
||||
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;
|
||||
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;
|
||||
vertex_segement_index = 0;
|
||||
|
||||
st = curve_segment_index / total_curve_segments;
|
||||
et = (curve_segment_index + 1.0) / total_curve_segments;
|
||||
st = curve_segment_index / total_curve_segments;
|
||||
et = (curve_segment_index + 1.0) / total_curve_segments;
|
||||
|
||||
start_t = st;
|
||||
end_t = et;
|
||||
start_t = st;
|
||||
end_t = et;
|
||||
|
||||
if (_square_t)
|
||||
{
|
||||
start_t *= start_t;
|
||||
end_t *= end_t;
|
||||
}
|
||||
if (_square_t) {
|
||||
start_t *= start_t;
|
||||
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);
|
||||
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;
|
||||
color_end_t = color_scale * end_t;
|
||||
color_start_t = color_scale * start_t;
|
||||
color_end_t = color_scale * end_t;
|
||||
|
||||
c0 = vertex_start_color * one_minus_x (color_start_t);
|
||||
c2 = vertex_start_color * one_minus_x (color_end_t);
|
||||
c0 = vertex_start_color * one_minus_x (color_start_t);
|
||||
c2 = vertex_start_color * one_minus_x (color_end_t);
|
||||
|
||||
t0.set (one_minus_x (st), motion_trail_vertex_start -> _v);
|
||||
t2.set (one_minus_x (et), motion_trail_vertex_start -> _v);
|
||||
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)
|
||||
{
|
||||
float start_nurbs_start_t;
|
||||
float start_nurbs_end_t;
|
||||
float end_nurbs_start_t;
|
||||
float end_nurbs_end_t;
|
||||
|
||||
motion_trail_vertex_start = &_vertex_array [vertex_segement_index];
|
||||
motion_trail_vertex_end = &_vertex_array [vertex_segement_index + 1];
|
||||
while (vertex_segement_index < total_vertex_segments) {
|
||||
|
||||
start_nurbs_curve_result = nurbs_curve_result_array [vertex_segement_index];
|
||||
end_nurbs_curve_result = nurbs_curve_result_array [vertex_segement_index + 1];
|
||||
float start_nurbs_start_t;
|
||||
float start_nurbs_end_t;
|
||||
float end_nurbs_start_t;
|
||||
float end_nurbs_end_t;
|
||||
|
||||
start_nurbs_start_t = start_nurbs_curve_result -> get_start_t();
|
||||
start_nurbs_end_t = start_nurbs_curve_result -> get_end_t();
|
||||
end_nurbs_start_t = end_nurbs_curve_result -> get_start_t();
|
||||
end_nurbs_end_t = end_nurbs_curve_result -> get_end_t();
|
||||
motion_trail_vertex_start = &_vertex_array [vertex_segement_index];
|
||||
motion_trail_vertex_end = &_vertex_array [vertex_segement_index + 1];
|
||||
|
||||
float start_delta_t;
|
||||
float end_delta_t;
|
||||
start_nurbs_curve_result = nurbs_curve_result_array [vertex_segement_index];
|
||||
end_nurbs_curve_result = nurbs_curve_result_array [vertex_segement_index + 1];
|
||||
|
||||
start_delta_t = (start_nurbs_end_t - start_nurbs_start_t);
|
||||
end_delta_t = (end_nurbs_end_t - end_nurbs_start_t);
|
||||
start_nurbs_start_t = start_nurbs_curve_result -> get_start_t();
|
||||
start_nurbs_end_t = start_nurbs_curve_result -> get_end_t();
|
||||
end_nurbs_start_t = end_nurbs_curve_result -> get_start_t();
|
||||
end_nurbs_end_t = end_nurbs_curve_result -> get_end_t();
|
||||
|
||||
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);
|
||||
float start_delta_t;
|
||||
float end_delta_t;
|
||||
|
||||
start_nurbs_curve_result -> eval_point (start_nurbs_start_t + (start_delta_t * et), v2);
|
||||
end_nurbs_curve_result -> eval_point (end_nurbs_start_t + (end_delta_t * et), v3);
|
||||
start_delta_t = (start_nurbs_end_t - start_nurbs_start_t);
|
||||
end_delta_t = (end_nurbs_end_t - end_nurbs_start_t);
|
||||
|
||||
// color
|
||||
vertex_end_color = motion_trail_vertex_end -> _end_color + (motion_trail_vertex_end -> _start_color - motion_trail_vertex_end -> _end_color);
|
||||
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);
|
||||
|
||||
c1 = vertex_end_color * one_minus_x (color_start_t);
|
||||
c3 = vertex_end_color * one_minus_x (color_end_t);
|
||||
start_nurbs_curve_result -> eval_point (start_nurbs_start_t + (start_delta_t * et), v2);
|
||||
end_nurbs_curve_result -> eval_point (end_nurbs_start_t + (end_delta_t * et), v3);
|
||||
|
||||
// uv
|
||||
t1.set (one_minus_x (st), motion_trail_vertex_end -> _v);
|
||||
t3.set (one_minus_x (et), motion_trail_vertex_end -> _v);
|
||||
// color
|
||||
vertex_end_color = motion_trail_vertex_end -> _end_color + (motion_trail_vertex_end -> _start_color - motion_trail_vertex_end -> _end_color);
|
||||
|
||||
this -> add_geometry_quad (v0, v1, v2, v3, c0, c1, c2, c3, t0, t1, t2, t3);
|
||||
c1 = vertex_end_color * one_minus_x (color_start_t);
|
||||
c3 = vertex_end_color * one_minus_x (color_end_t);
|
||||
|
||||
// reuse calculations
|
||||
c0 = c1;
|
||||
c2 = c3;
|
||||
// uv
|
||||
t1.set (one_minus_x (st), motion_trail_vertex_end -> _v);
|
||||
t3.set (one_minus_x (et), motion_trail_vertex_end -> _v);
|
||||
|
||||
t0 = t1;
|
||||
t2 = t3;
|
||||
this -> add_geometry_quad (v0, v1, v2, v3, c0, c1, c2, c3, t0, t1, t2, t3);
|
||||
|
||||
vertex_segement_index += 1;
|
||||
}
|
||||
// reuse calculations
|
||||
c0 = c1;
|
||||
c2 = c3;
|
||||
|
||||
curve_segment_index += 1.0;
|
||||
t0 = t1;
|
||||
t2 = t3;
|
||||
|
||||
vertex_segement_index += 1;
|
||||
}
|
||||
|
||||
curve_segment_index += 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
delete nurbs_curve_result_array;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
|
||||
// non-nurbs version
|
||||
int segment_index;
|
||||
int vertex_segment_index;
|
||||
|
|
@ -676,94 +747,91 @@ update_motion_trail (float current_time, LMatrix4f *transform) {
|
|||
|
||||
segment_index = 0;
|
||||
frame_iterator = _frame_list.begin ( );
|
||||
while (segment_index < total_segments)
|
||||
{
|
||||
CMotionTrailVertex *motion_trail_vertex_start;
|
||||
CMotionTrailVertex *motion_trail_vertex_end;
|
||||
while (segment_index < total_segments) {
|
||||
|
||||
CMotionTrailVertex *motion_trail_vertex_start;
|
||||
CMotionTrailVertex *motion_trail_vertex_end;
|
||||
|
||||
motion_trail_frame_start = *frame_iterator;
|
||||
frame_iterator++;
|
||||
motion_trail_frame_end = *frame_iterator;
|
||||
motion_trail_frame_start = *frame_iterator;
|
||||
frame_iterator++;
|
||||
motion_trail_frame_end = *frame_iterator;
|
||||
|
||||
start_t = (motion_trail_frame_start._time - minimum_time) / delta_time;
|
||||
end_t = (motion_trail_frame_end._time - minimum_time) / delta_time;
|
||||
start_t = (motion_trail_frame_start._time - minimum_time) / delta_time;
|
||||
end_t = (motion_trail_frame_end._time - minimum_time) / delta_time;
|
||||
|
||||
st = start_t;
|
||||
et = end_t;
|
||||
st = start_t;
|
||||
et = end_t;
|
||||
|
||||
if (_square_t)
|
||||
{
|
||||
start_t *= start_t;
|
||||
end_t *= end_t;
|
||||
}
|
||||
if (_square_t) {
|
||||
start_t *= start_t;
|
||||
end_t *= end_t;
|
||||
}
|
||||
|
||||
vertex_segment_index = 0;
|
||||
total_vertex_segments = total_vertices - 1;
|
||||
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);
|
||||
}
|
||||
else {
|
||||
start_transform = motion_trail_frame_start._transform;
|
||||
end_transform = motion_trail_frame_end._transform;
|
||||
}
|
||||
if (_calculate_relative_matrix) {
|
||||
start_transform.multiply (motion_trail_frame_start._transform, inverse_matrix);
|
||||
end_transform.multiply (motion_trail_frame_end._transform, inverse_matrix);
|
||||
}
|
||||
else {
|
||||
start_transform = motion_trail_frame_start._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);
|
||||
v0 = start_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);
|
||||
color_start_t = color_scale * start_t;
|
||||
color_end_t = color_scale * end_t;
|
||||
c0 = vertex_start_color * color_start_t;
|
||||
c2 = vertex_start_color * color_end_t;
|
||||
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;
|
||||
color_end_t = color_scale * end_t;
|
||||
c0 = vertex_start_color * color_start_t;
|
||||
c2 = vertex_start_color * color_end_t;
|
||||
|
||||
t0.set (st, motion_trail_vertex_start -> _v);
|
||||
t2.set (et, motion_trail_vertex_start -> _v);
|
||||
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];
|
||||
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];
|
||||
|
||||
v1 = start_transform.xform (motion_trail_vertex_end -> _vertex);
|
||||
v3 = end_transform.xform (motion_trail_vertex_end -> _vertex);
|
||||
v1 = start_transform.xform (motion_trail_vertex_end -> _vertex);
|
||||
v3 = end_transform.xform (motion_trail_vertex_end -> _vertex);
|
||||
|
||||
// color
|
||||
vertex_end_color = motion_trail_vertex_end -> _end_color + (motion_trail_vertex_end -> _start_color - motion_trail_vertex_end -> _end_color);
|
||||
|
||||
c1 = vertex_end_color * color_start_t;
|
||||
c3 = vertex_end_color * color_end_t;
|
||||
// color
|
||||
vertex_end_color = motion_trail_vertex_end -> _end_color + (motion_trail_vertex_end -> _start_color - motion_trail_vertex_end -> _end_color);
|
||||
|
||||
// uv
|
||||
t1.set (st, motion_trail_vertex_end -> _v);
|
||||
t3.set (et, motion_trail_vertex_end -> _v);
|
||||
c1 = vertex_end_color * color_start_t;
|
||||
c3 = vertex_end_color * color_end_t;
|
||||
|
||||
this -> add_geometry_quad (v0, v1, v2, v3, c0, c1, c2, c3, t0, t1, t2, t3);
|
||||
// uv
|
||||
t1.set (st, motion_trail_vertex_end -> _v);
|
||||
t3.set (et, motion_trail_vertex_end -> _v);
|
||||
|
||||
// reuse calculations
|
||||
v0 = v1;
|
||||
v2 = v3;
|
||||
this -> add_geometry_quad (v0, v1, v2, v3, c0, c1, c2, c3, t0, t1, t2, t3);
|
||||
|
||||
c0 = c1;
|
||||
c2 = c3;
|
||||
// reuse calculations
|
||||
v0 = v1;
|
||||
v2 = v3;
|
||||
|
||||
t0 = t1;
|
||||
t2 = t3;
|
||||
c0 = c1;
|
||||
c2 = c3;
|
||||
|
||||
vertex_segment_index += 1;
|
||||
}
|
||||
t0 = t1;
|
||||
t2 = t3;
|
||||
|
||||
segment_index += 1;
|
||||
vertex_segment_index += 1;
|
||||
}
|
||||
|
||||
segment_index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// end geometry
|
||||
{
|
||||
this -> end_geometry ( );
|
||||
}
|
||||
this -> end_geometry ( );
|
||||
|
||||
delete _vertex_array;
|
||||
_vertex_array = 0;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,21 @@
|
|||
// Filename: cMotionTrail.h
|
||||
// Created by: aignacio (29Jan07)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2007, Disney Enterprises, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef CMOTIONTRAIL_H
|
||||
#define CMOTIONTRAIL_H
|
||||
|
|
@ -31,6 +49,47 @@ public:
|
|||
LMatrix4f _transform;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : CMotionTrail
|
||||
// Description : The method used in creating the motion trail is
|
||||
// based on taking samples of time and transformations
|
||||
// (the position and orientation matrix) in real-time.
|
||||
// The method also requires a number of vertices
|
||||
// (positions) that determines "shape" of the motion
|
||||
// trail (i.e. the edge of a blade). A start color
|
||||
// and end color is also required for each vertex.
|
||||
// The color is interpolated as function of time.
|
||||
// The colors are typically used to fade the motion
|
||||
// trail so the end color is typically black.
|
||||
//
|
||||
// The vertices are submitted via the "add_vertex"
|
||||
// function. For each frame, a sample is submited via
|
||||
// the "update_motion_trail" function. During the
|
||||
// "update_motion_trail" function, the motion trail
|
||||
// geometry is created dynamically from the sample
|
||||
// history and the vertices.
|
||||
//
|
||||
// The user must specifiy a GeomNode via
|
||||
// "set_geom_node".
|
||||
//
|
||||
// The duration of the sample history is specified by
|
||||
// a time window. A larger time window creates longer
|
||||
// motion trails (given constant speed). Samples that
|
||||
// are no longer within the time window are
|
||||
// automatically discarded.
|
||||
//
|
||||
// The nurbs option can be used to create smooth
|
||||
// interpolated curves from the samples. The nurbs
|
||||
// option is useful for animations that lack sampling
|
||||
// to begin with, animations that move very quickly,
|
||||
// or low frame rates.
|
||||
//
|
||||
// The texture option be used to create variation to
|
||||
// the motion trail. The u coordinate of the texture
|
||||
// corresponds to time and the v coordinate
|
||||
// corresponds to the "shape" of the motion trail.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class EXPCL_DIRECT CMotionTrail : public TypedReferenceCount {
|
||||
|
||||
PUBLISHED:
|
||||
|
|
@ -42,12 +101,12 @@ PUBLISHED:
|
|||
void reset_vertex_list ( );
|
||||
|
||||
void enable (bool enable);
|
||||
|
||||
void set_geom_node (PT(GeomNode) geom_node);
|
||||
void use_nurbs (bool enable);
|
||||
void use_texture (bool enable);
|
||||
void calculate_relative_matrix (bool enable);
|
||||
void add_vertex (LVector4f *vertex, LVector4f *start_color, LVector4f *end_color, float v);
|
||||
|
||||
void set_parameters (float sampling_time, float time_window, bool use_texture, bool calculate_relative_matrix, bool use_nurbs, float resolution_distance);
|
||||
|
||||
int check_for_update (float current_time);
|
||||
void update_motion_trail (float current_time, LMatrix4f *transform);
|
||||
|
||||
|
|
@ -70,45 +129,26 @@ public:
|
|||
float _fade_start_time;
|
||||
float _fade_color_scale;
|
||||
|
||||
CMotionTrailVertex *_vertex_array;
|
||||
|
||||
float _last_update_time;
|
||||
|
||||
bool _use_texture;
|
||||
|
||||
|
||||
list <CMotionTrailVertex> _vertex_list;
|
||||
list <CMotionTrailFrame> _frame_list;
|
||||
|
||||
// parent_node_path = parent_node_path
|
||||
|
||||
int _calculate_relative_matrix;
|
||||
|
||||
int _playing;
|
||||
|
||||
// default options
|
||||
int _continuous_motion_trail;
|
||||
// parameters
|
||||
float _color_scale;
|
||||
float _time_window;
|
||||
float _sampling_time;
|
||||
int _square_t;
|
||||
|
||||
// int _task_transform;
|
||||
|
||||
// root_node_path = None
|
||||
|
||||
// node path states
|
||||
PT(GeomNode) _geom_node;
|
||||
|
||||
// geom_node_path =
|
||||
|
||||
int _relative_to_render;
|
||||
float _time_window;
|
||||
bool _square_t;
|
||||
bool _use_texture;
|
||||
int _calculate_relative_matrix;
|
||||
|
||||
// nurbs parameters
|
||||
bool _use_nurbs;
|
||||
float _resolution_distance;
|
||||
|
||||
|
||||
|
||||
// geom
|
||||
PT(GeomNode) _geom_node;
|
||||
|
||||
// real-time data
|
||||
int _vertex_index;
|
||||
PT(GeomVertexData) _vertex_data;
|
||||
|
|
@ -117,7 +157,8 @@ public:
|
|||
GeomVertexWriter _texture_writer;
|
||||
PT(GeomTriangles) _triangles;
|
||||
|
||||
/*
|
||||
CMotionTrailVertex *_vertex_array;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
|
|
@ -134,7 +175,6 @@ public:
|
|||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue