Selaa lähdekoodia

added offset to billboard, and added do_billboard_*

David Rose 24 vuotta sitten
vanhempi
sitoutus
2a9f41802f
3 muutettua tiedostoa jossa 66 lisäystä ja 24 poistoa
  1. 6 6
      panda/src/sgmanip/nodePath.I
  2. 35 12
      panda/src/sgmanip/nodePath.cxx
  3. 25 6
      panda/src/sgmanip/nodePath.h

+ 6 - 6
panda/src/sgmanip/nodePath.I

@@ -1284,9 +1284,9 @@ has_two_sided() const {
 //               will rotate in two dimensions around the up axis.
 //               will rotate in two dimensions around the up axis.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void NodePath::
 INLINE void NodePath::
-set_billboard_axis() {
+set_billboard_axis(float offset) {
   nassertv(has_arcs());
   nassertv(has_arcs());
-  arc()->set_transition(new BillboardTransition(BillboardTransition::axis()));
+  arc()->set_transition(new BillboardTransition(BillboardTransition::axis(offset)));
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -1298,9 +1298,9 @@ set_billboard_axis() {
 //               camera.
 //               camera.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void NodePath::
 INLINE void NodePath::
-set_billboard_point_eye() {
+set_billboard_point_eye(float offset) {
   nassertv(has_arcs());
   nassertv(has_arcs());
-  arc()->set_transition(new BillboardTransition(BillboardTransition::point_eye()));
+  arc()->set_transition(new BillboardTransition(BillboardTransition::point_eye(offset)));
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -1311,9 +1311,9 @@ set_billboard_point_eye() {
 //               keeping its up vector oriented to the sky.
 //               keeping its up vector oriented to the sky.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void NodePath::
 INLINE void NodePath::
-set_billboard_point_world() {
+set_billboard_point_world(float offset) {
   nassertv(has_arcs());
   nassertv(has_arcs());
-  arc()->set_transition(new BillboardTransition(BillboardTransition::point_world()));
+  arc()->set_transition(new BillboardTransition(BillboardTransition::point_world(offset)));
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 35 - 12
panda/src/sgmanip/nodePath.cxx

@@ -2482,13 +2482,13 @@ get_two_sided() const {
 //  Description: Performs a billboard-type rotate to the indicated
 //  Description: Performs a billboard-type rotate to the indicated
 //               camera node, one time only, and leaves the object
 //               camera node, one time only, and leaves the object
 //               rotated.  This is similar in principle to heads_up().
 //               rotated.  This is similar in principle to heads_up().
+//               However, it does lose both translate and scale
+//               components of the matrix.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void NodePath::
 void NodePath::
-do_billboard_axis(const NodePath &camera) {
+do_billboard_axis(const NodePath &camera, float offset) {
   nassertv(has_arcs());
   nassertv(has_arcs());
 
 
-  LPoint3f pos = get_pos();
-
   NodePath parent(*this);
   NodePath parent(*this);
   parent.shorten(1);
   parent.shorten(1);
   LMatrix4f rel_mat = camera.get_mat(parent);
   LMatrix4f rel_mat = camera.get_mat(parent);
@@ -2498,7 +2498,16 @@ do_billboard_axis(const NodePath &camera) {
 
 
   LMatrix4f mat;
   LMatrix4f mat;
   ::heads_up(mat, rel_pos, up);
   ::heads_up(mat, rel_pos, up);
-  mat.set_row(3, pos);
+
+  // Also slide the geometry towards the camera according to the
+  // offset factor.
+  if (offset != 0.0f) {
+    LVector3f translate = rel_mat.get_row3(3);
+    translate.normalize();
+    translate *= offset;
+    mat.set_row(3, translate);
+  }
+
   set_mat(mat);
   set_mat(mat);
 }
 }
 
 
@@ -2512,11 +2521,9 @@ do_billboard_axis(const NodePath &camera) {
 //               achieved using the ordinary look_at() call.
 //               achieved using the ordinary look_at() call.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void NodePath::
 void NodePath::
-do_billboard_point_eye(const NodePath &camera) {
+do_billboard_point_eye(const NodePath &camera, float offset) {
   nassertv(has_arcs());
   nassertv(has_arcs());
 
 
-  LPoint3f pos = get_pos();
-
   NodePath parent(*this);
   NodePath parent(*this);
   parent.shorten(1);
   parent.shorten(1);
   LMatrix4f rel_mat = camera.get_mat(parent);
   LMatrix4f rel_mat = camera.get_mat(parent);
@@ -2526,7 +2533,16 @@ do_billboard_point_eye(const NodePath &camera) {
 
 
   LMatrix4f mat;
   LMatrix4f mat;
   ::look_at(mat, rel_pos, up);
   ::look_at(mat, rel_pos, up);
-  mat.set_row(3, pos);
+
+  // Also slide the geometry towards the camera according to the
+  // offset factor.
+  if (offset != 0.0f) {
+    LVector3f translate = rel_mat.get_row3(3);
+    translate.normalize();
+    translate *= offset;
+    mat.set_row(3, translate);
+  }
+
   set_mat(mat);
   set_mat(mat);
 }
 }
 
 
@@ -2538,11 +2554,9 @@ do_billboard_point_eye(const NodePath &camera) {
 //               rotated.  This is similar in principle to look_at().
 //               rotated.  This is similar in principle to look_at().
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void NodePath::
 void NodePath::
-do_billboard_point_world(const NodePath &camera) {
+do_billboard_point_world(const NodePath &camera, float offset) {
   nassertv(has_arcs());
   nassertv(has_arcs());
 
 
-  LPoint3f pos = get_pos();
-
   NodePath parent(*this);
   NodePath parent(*this);
   parent.shorten(1);
   parent.shorten(1);
   LMatrix4f rel_mat = camera.get_mat(parent);
   LMatrix4f rel_mat = camera.get_mat(parent);
@@ -2552,7 +2566,16 @@ do_billboard_point_world(const NodePath &camera) {
 
 
   LMatrix4f mat;
   LMatrix4f mat;
   ::look_at(mat, rel_pos, up);
   ::look_at(mat, rel_pos, up);
-  mat.set_row(3, pos);
+
+  // Also slide the geometry towards the camera according to the
+  // offset factor.
+  if (offset != 0.0f) {
+    LVector3f translate = rel_mat.get_row3(3);
+    translate.normalize();
+    translate *= offset;
+    mat.set_row(3, translate);
+  }
+
   set_mat(mat);
   set_mat(mat);
 }
 }
 
 

+ 25 - 6
panda/src/sgmanip/nodePath.h

@@ -73,6 +73,13 @@ class GraphicsStateGuardianBase;
 // just a special case of this.)  The globbing characters may not be
 // just a special case of this.)  The globbing characters may not be
 // used with the typename matches.
 // used with the typename matches.
 //
 //
+// The special characters "@@", appearing at the beginning of a node
+// name, indicate a stashed node.  Normally, stashed nodes are not
+// returned by a find (but see the special flags, below), but a
+// stashed node may be found if it is explicitly named with its
+// leading @@ characters.  By extension, "@@*" may be used to identify
+// any stashed node.
+//
 // Examples:
 // Examples:
 //
 //
 // "room//graph" will look for a node named "graph", which is a child
 // "room//graph" will look for a node named "graph", which is a child
@@ -96,6 +103,18 @@ class GraphicsStateGuardianBase;
 // paths, it will sort them so that the shortest paths appear first in
 // paths, it will sort them so that the shortest paths appear first in
 // the output.
 // the output.
 //
 //
+//
+// Special flags.  The entire string may optionally be followed by the
+// ";" character, followed by one or more of the following special
+// control flags, with no intervening spaces or punctuation:
+//
+//    -h    Do not return hidden nodes.
+//    +h    Do return hidden nodes.
+//    -s    Do not return stashed nodes unless explicitly referenced with @@.
+//    +s    Return stashed nodes even without any explicit @@ characters.
+//
+// The default flags are +h-s.
+//
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //       Class : NodePath
 //       Class : NodePath
@@ -448,12 +467,12 @@ PUBLISHED:
   INLINE bool has_two_sided() const;
   INLINE bool has_two_sided() const;
   bool get_two_sided() const;
   bool get_two_sided() const;
 
 
-  void do_billboard_axis(const NodePath &camera);
-  void do_billboard_point_eye(const NodePath &camera);
-  void do_billboard_point_world(const NodePath &camera);
-  INLINE void set_billboard_axis();
-  INLINE void set_billboard_point_eye();
-  INLINE void set_billboard_point_world();
+  void do_billboard_axis(const NodePath &camera, float offset);
+  void do_billboard_point_eye(const NodePath &camera, float offset);
+  void do_billboard_point_world(const NodePath &camera, float offset);
+  INLINE void set_billboard_axis(float offset = 0.0);
+  INLINE void set_billboard_point_eye(float offset = 0.0);
+  INLINE void set_billboard_point_world(float offset = 0.0);
   INLINE void clear_billboard();
   INLINE void clear_billboard();
   INLINE bool has_billboard() const;
   INLINE bool has_billboard() const;