Преглед на файлове

move matrix computation

David Rose преди 21 години
родител
ревизия
63ee254de2
променени са 3 файла, в които са добавени 35 реда и са изтрити 5 реда
  1. 31 0
      panda/src/parametrics/nurbsCurveEvaluator.cxx
  2. 2 0
      panda/src/parametrics/nurbsCurveEvaluator.h
  3. 2 5
      panda/src/parametrics/ropeNode.cxx

+ 31 - 0
panda/src/parametrics/nurbsCurveEvaluator.cxx

@@ -173,6 +173,37 @@ evaluate(const NodePath &rel_to) const {
                               (int)_vertices.size());
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: NurbsCurveEvaluator::evaluate
+//       Access: Published
+//  Description: Returns a NurbsCurveResult object that represents the
+//               result of applying the knots to all of the current
+//               values of the vertices, transformed into the
+//               indicated coordinate space, and then further
+//               transformed by the indicated matrix.
+////////////////////////////////////////////////////////////////////
+PT(NurbsCurveResult) NurbsCurveEvaluator::
+evaluate(const NodePath &rel_to, const LMatrix4f &mat) const {
+  if (_basis_dirty) {
+    ((NurbsCurveEvaluator *)this)->recompute_basis();
+  }
+
+  // First, transform the vertices as appropriate.
+  pvector<LVecBase4f> vecs;
+  get_vertices(vecs, rel_to);
+
+  // And then apply the indicated matrix.
+  pvector<LVecBase4f>::iterator vi;
+  for (vi = vecs.begin(); vi != vecs.end(); ++vi) {
+    (*vi) = (*vi) * mat;
+  }
+
+  // And apply those transformed vertices to the basis matrices to
+  // derive the result.
+  return new NurbsCurveResult(_basis, &vecs[0], &_vertices[0],
+                              (int)_vertices.size());
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: NurbsCurveEvaluator::output
 //       Access: Published

+ 2 - 0
panda/src/parametrics/nurbsCurveEvaluator.h

@@ -78,6 +78,8 @@ PUBLISHED:
   INLINE int get_num_segments() const;
 
   PT(NurbsCurveResult) evaluate(const NodePath &rel_to = NodePath()) const;
+  PT(NurbsCurveResult) evaluate(const NodePath &rel_to,
+                                const LMatrix4f &mat) const;
 
   void output(ostream &out) const;
 

+ 2 - 5
panda/src/parametrics/ropeNode.cxx

@@ -154,7 +154,8 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) {
   if (get_num_subdiv() > 0) {
     NurbsCurveEvaluator *curve = get_curve();
     if (curve != (NurbsCurveEvaluator *)NULL) {
-      PT(NurbsCurveResult) result = curve->evaluate(data._node_path.get_node_path());
+      PT(NurbsCurveResult) result = 
+        curve->evaluate(data._node_path.get_node_path(), get_matrix());
 
       if (result->get_num_segments() > 0) {
         switch (get_render_mode()) {
@@ -555,12 +556,9 @@ get_connected_segments(RopeNode::CurveSegments &curve_segments,
   CurveSegment *curve_segment = NULL;
   LPoint3f last_point;
 
-  const LMatrix4f &matrix = get_matrix();
-
   for (int segment = 0; segment < num_segments; ++segment) {
     LPoint3f point;
     result->eval_segment_point(segment, 0.0f, point);
-    point = point * matrix;
 
     if (curve_segment == (CurveSegment *)NULL || 
         !point.almost_equal(last_point)) {
@@ -586,7 +584,6 @@ get_connected_segments(RopeNode::CurveSegments &curve_segments,
 
       CurveVertex vtx;
       result->eval_segment_point(segment, t, vtx._p);
-      vtx._p = vtx._p * matrix;
       vtx._t = result->get_segment_t(segment, t);
       if (use_vertex_color) {
         result->eval_segment_extended_points(segment, t, 0, &vtx._c[0], 4);