浏览代码

add MatrixLens

David Rose 24 年之前
父节点
当前提交
771ff8b9a1

+ 3 - 2
panda/src/gobj/Sources.pp

@@ -14,6 +14,7 @@
      geomQuad.h geomSphere.h geomSprite.I geomSprite.h geomTri.h  \
      geomTrifan.h geomTristrip.h imageBuffer.I imageBuffer.h  \
      material.I material.h materialPool.I materialPool.h  \
+     matrixLens.I matrixLens.h \
      orthographicLens.I orthographicLens.h perspectiveLens.I  \
      perspectiveLens.h pixelBuffer.I pixelBuffer.N  \
      pixelBuffer.h lens.h lens.I \
@@ -27,7 +28,7 @@
      geomLine.cxx geomLinestrip.cxx geomPoint.cxx geomPolygon.cxx  \
      geomQuad.cxx geomSphere.cxx geomSprite.cxx geomTri.cxx  \
      geomTrifan.cxx geomTristrip.cxx imageBuffer.cxx material.cxx  \
-     materialPool.cxx orthographicLens.cxx  \
+     materialPool.cxx matrixLens.cxx orthographicLens.cxx  \
      perspectiveLens.cxx pixelBuffer.cxx lens.cxx  \
      savedContext.cxx texture.cxx textureContext.cxx texturePool.cxx
 
@@ -37,7 +38,7 @@
     geomLinestrip.h geomPoint.h geomPolygon.h geomQuad.h geomSphere.h \
     geomSprite.I geomSprite.h geomTri.h geomTrifan.h geomTristrip.h \
     geomprimitives.h imageBuffer.I imageBuffer.h material.I material.h \
-    materialPool.I materialPool.h \
+    materialPool.I materialPool.h matrixLens.I matrixLens.h \
     orthographicLens.I orthographicLens.h perspectiveLens.I \
     perspectiveLens.h pixelBuffer.I pixelBuffer.h \
     lens.h lens.I \

+ 2 - 0
panda/src/gobj/config_gobj.cxx

@@ -25,6 +25,7 @@
 #include "imageBuffer.h"
 #include "material.h"
 #include "orthographicLens.h"
+#include "matrixLens.h"
 #include "perspectiveLens.h"
 #include "pixelBuffer.h"
 #include "lens.h"
@@ -177,6 +178,7 @@ ConfigureFn(config_gobj) {
   LOD::init_type();
   Material::init_type();
   OrthographicLens::init_type();
+  MatrixLens::init_type();
   PerspectiveLens::init_type();
   PixelBuffer::init_type();
   Lens::init_type();

+ 1 - 0
panda/src/gobj/gobj_composite2.cxx

@@ -6,6 +6,7 @@
 #include "material.cxx"
 #include "materialPool.cxx"
 #include "orthographicLens.cxx"
+#include "matrixLens.cxx"
 #include "perspectiveLens.cxx"
 #include "pixelBuffer.cxx"
 #include "lens.cxx"

+ 2 - 2
panda/src/gobj/lens.cxx

@@ -925,7 +925,7 @@ get_projection_mat_inv() const {
 
 ////////////////////////////////////////////////////////////////////
 //     Function: Lens::output
-//       Access: Public, Virtual
+//       Access: Published, Virtual
 //  Description: 
 ////////////////////////////////////////////////////////////////////
 void Lens::
@@ -935,7 +935,7 @@ output(ostream &out) const {
 
 ////////////////////////////////////////////////////////////////////
 //     Function: Lens::write
-//       Access: Public, Virtual
+//       Access: Published, Virtual
 //  Description: 
 ////////////////////////////////////////////////////////////////////
 void Lens::

+ 3 - 3
panda/src/gobj/lens.h

@@ -129,12 +129,12 @@ PUBLISHED:
   const LMatrix4f &get_projection_mat() const;
   const LMatrix4f &get_projection_mat_inv() const;
 
-public:
-  INLINE const UpdateSeq &get_last_change() const;
-
   virtual void output(ostream &out) const;
   virtual void write(ostream &out, int indent_level = 0) const;
 
+public:
+  INLINE const UpdateSeq &get_last_change() const;
+
 protected:
   INLINE void adjust_user_flags(int clear_flags, int set_flags);
   INLINE void adjust_comp_flags(int clear_flags, int set_flags);

+ 90 - 0
panda/src/gobj/matrixLens.I

@@ -0,0 +1,90 @@
+// Filename: matrixLens.I
+// Created by:  drose (12Dec01)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////
+//     Function: MatrixLens::Constructor
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE MatrixLens::
+MatrixLens() :
+  _user_mat(LMatrix4f::ident_mat())
+{
+  // The default film size for a MatrixLens is 2, which makes the
+  // default range for both X and Y be [-1, 1].  This also,
+  // incidentally, makes the film_mat be identity.
+  set_film_size(2.0f);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MatrixLens::Copy Constructor
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE MatrixLens::
+MatrixLens(const MatrixLens &copy) : 
+  Lens(copy),
+  _user_mat(copy._user_mat)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MatrixLens::Copy Assignment Operator
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE void MatrixLens::
+operator = (const MatrixLens &copy) {
+  Lens::operator = (copy);
+  _user_mat = copy.get_user_mat();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MatrixLens::set_user_mat
+//       Access: Published
+//  Description: Explicitly specifies the projection matrix.  This
+//               matrix should convert X and Y to the range
+//               [-film_size/2, film_size/2], where (-fs/2,-fs/2) is
+//               the lower left corner of the screen and (fs/2, fs/2)
+//               is the upper right.  Z should go to the range [-1,
+//               1], where -1 is the far plane and 1 is the near
+//               plane.  Note that this is a left-handed Y-up
+//               coordinate system.
+//
+//               The default film_size for a MatrixLens is 2, so the
+//               default range is [-1, 1] for both X and Y.  This is
+//               consistent with the GL conventions for projection
+//               matrices.
+////////////////////////////////////////////////////////////////////
+INLINE void MatrixLens::
+set_user_mat(const LMatrix4f &user_mat) {
+  _user_mat = user_mat;
+  adjust_comp_flags(CF_mat, 0);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MatrixLens::get_user_mat
+//       Access: Published
+//  Description: Returns the explicit projection matrix as set by the
+//               user.  This does not include transforms on the lens
+//               or film (e.g. a film offset or view hpr).
+////////////////////////////////////////////////////////////////////
+INLINE const LMatrix4f &MatrixLens::
+get_user_mat() const {
+  return _user_mat;
+}

+ 70 - 0
panda/src/gobj/matrixLens.cxx

@@ -0,0 +1,70 @@
+// Filename: matrixLens.cxx
+// Created by:  drose (12Dec01)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "matrixLens.h"
+#include "indent.h"
+
+TypeHandle MatrixLens::_type_handle;
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: MatrixLens::make_copy
+//       Access: Public, Virtual
+//  Description: Allocates a new Lens just like this one.
+////////////////////////////////////////////////////////////////////
+PT(Lens) MatrixLens::
+make_copy() const {
+  return new MatrixLens(*this);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MatrixLens::is_linear
+//       Access: Published, Virtual
+//  Description: Returns true if the lens represents a linear
+//               projection (e.g. PerspectiveLens, MatrixLens),
+//               and therefore there is a valid matrix returned by
+//               get_projection_mat(), or false otherwise.
+////////////////////////////////////////////////////////////////////
+bool MatrixLens::
+is_linear() const {
+  return true;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MatrixLens::write
+//       Access: Public, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void MatrixLens::
+write(ostream &out, int indent_level) const {
+  indent(out, indent_level) << get_type() << ":\n";
+  _projection_mat.write(out, indent_level + 2);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MatrixLens::compute_projection_mat
+//       Access: Protected, Virtual
+//  Description: Computes the complete transformation matrix from 3-d
+//               point to 2-d point, if the lens is linear.
+////////////////////////////////////////////////////////////////////
+void MatrixLens::
+compute_projection_mat() {
+  _projection_mat = get_lens_mat_inv() * _user_mat * get_film_mat();
+  adjust_comp_flags(CF_projection_mat_inv, 
+                    CF_projection_mat);
+}

+ 79 - 0
panda/src/gobj/matrixLens.h

@@ -0,0 +1,79 @@
+// Filename: matrixLens.h
+// Created by:  drose (12Dec01)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef MATRIXLENS_H
+#define MATRIXLENS_H
+
+#include "pandabase.h"
+
+#include "lens.h"
+
+
+////////////////////////////////////////////////////////////////////
+//       Class : MatrixLens
+// Description : A completely generic linear lens.  This is provided
+//               for the benefit low-level code that wants to specify
+//               a perspective or orthographic frustum via an explicit
+//               projection matrix, but not mess around with fov's or
+//               focal lengths or any of that nonsense.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA MatrixLens : public Lens {
+PUBLISHED:
+  INLINE MatrixLens();
+
+public:
+  INLINE MatrixLens(const MatrixLens &copy);
+  INLINE void operator = (const MatrixLens &copy);
+
+PUBLISHED:
+  INLINE void set_user_mat(const LMatrix4f &user_mat);
+  INLINE const LMatrix4f &get_user_mat() const;
+
+public:
+  virtual PT(Lens) make_copy() const;
+  virtual bool is_linear() const;
+
+  virtual void write(ostream &out, int indent_level = 0) const;
+
+protected:
+  virtual void compute_projection_mat();
+
+private:
+  LMatrix4f _user_mat;
+
+public:
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    Lens::init_type();
+    register_type(_type_handle, "MatrixLens",
+                  Lens::get_class_type());
+  }
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "matrixLens.I"
+
+#endif