Panda3D
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
MatrixLens Class Reference

A completely generic linear lens. More...

#include "matrixLens.h"

Inheritance diagram for MatrixLens:
Lens TypedWritableReferenceCount TypedWritable ReferenceCount TypedObject MemoryBase MemoryBase

Public Member Functions

 MatrixLens (const MatrixLens &copy)
 
void clear_left_eye_mat ()
 Removes the custom projection matrix set for the left eye, and uses the center matrix (set by set_user_mat) instead. More...
 
void clear_right_eye_mat ()
 Removes the custom projection matrix set for the right eye, and uses the center matrix (set by set_user_mat) instead. More...
 
virtual TypeHandle force_init_type ()
 
const LMatrix4 & get_left_eye_mat () const
 Returns the custom projection matrix for the left eye, if any, or the center matrix if there is no custom matrix set for the left eye. More...
 
const LMatrix4 & get_right_eye_mat () const
 Returns the custom projection matrix for the right eye, if any, or the center matrix if there is no custom matrix set for the right eye. More...
 
virtual TypeHandle get_type () const
 
const LMatrix4 & get_user_mat () const
 
bool has_left_eye_mat () const
 Returns true if the camera has a custom projection matrix set for the left eye, or false if the center matrix (set by set_user_mat) will be used for the left eye. More...
 
bool has_right_eye_mat () const
 Returns true if the camera has a custom projection matrix set for the right eye, or false if the center matrix (set by set_user_mat) will be used for the right eye. More...
 
virtual bool is_linear () const
 Returns true if the lens represents a linear projection (e.g. More...
 
void operator= (const MatrixLens &copy)
 
virtual PT (Lens) make_copy() const
 
void set_left_eye_mat (const LMatrix4 &user_mat)
 Sets a custom projection matrix for the left eye. More...
 
void set_right_eye_mat (const LMatrix4 &user_mat)
 Sets a custom projection matrix for the right eye. More...
 
void set_user_mat (const LMatrix4 &user_mat)
 
virtual void write (std::ostream &out, int indent_level=0) const
 
virtual void write_datagram (BamWriter *manager, Datagram &dg)
 Writes the contents of this object to the datagram for shipping out to a Bam file. More...
 
- Public Member Functions inherited from Lens
 Lens (const Lens &copy)
 
void clear ()
 Resets all lens parameters to their initial default settings. More...
 
void clear_custom_film_mat ()
 Disables the lens custom_film_mat correction. More...
 
void clear_keystone ()
 Disables the lens keystone correction. More...
 
void clear_view_mat ()
 Resets the lens transform to identity. More...
 
bool extrude (const LPoint2 &point2d, LPoint3 &near_point, LPoint3 &far_point) const
 Given a 2-d point in the range (-1,1) in both dimensions, where (0,0) is the center of the lens and (-1,-1) is the lower-left corner, compute the corresponding vector in space that maps to this point, if such a vector can be determined. More...
 
bool extrude (const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) const
 Given a 2-d point in the range (-1,1) in both dimensions, where (0,0) is the center of the lens and (-1,-1) is the lower-left corner, compute the corresponding vector in space that maps to this point, if such a vector can be determined. More...
 
bool extrude_depth (const LPoint3 &point2d, LPoint3 &point3d) const
 Uses the depth component of the 3-d result from project() to compute the original point in 3-d space corresponding to a particular point on the lens. More...
 
bool extrude_vec (const LPoint2 &point2d, LVector3 &vec3d) const
 Given a 2-d point in the range (-1,1) in both dimensions, where (0,0) is the center of the lens and (-1,-1) is the lower-left corner, compute the vector that corresponds to the view direction. More...
 
bool extrude_vec (const LPoint3 &point2d, LVector3 &vec3d) const
 Given a 2-d point in the range (-1,1) in both dimensions, where (0,0) is the center of the lens and (-1,-1) is the lower-left corner, compute the vector that corresponds to the view direction. More...
 
PN_stdfloat get_aspect_ratio () const
 
const std::string & get_change_event () const
 
PN_stdfloat get_convergence_distance () const
 
CoordinateSystem get_coordinate_system () const
 
const LMatrix4 & get_custom_film_mat () const
 Returns the custom_film_mat specified for the lens. More...
 
PN_stdfloat get_far () const
 
const LMatrix4 & get_film_mat () const
 Returns the matrix that transforms from a point behind the lens to a point on the film. More...
 
const LMatrix4 & get_film_mat_inv () const
 Returns the matrix that transforms from a point on the film to a point behind the lens. More...
 
const LVector2 & get_film_offset () const
 
const LVecBase2 & get_film_size () const
 
PN_stdfloat get_focal_length () const
 
const LVecBase2 & get_fov () const
 
PN_stdfloat get_hfov () const
 Returns the horizontal component of fov only. More...
 
PN_stdfloat get_interocular_distance () const
 
const LVecBase2 & get_keystone () const
 
UpdateSeq get_last_change () const
 Returns the UpdateSeq that is incremented whenever the lens properties are changed. More...
 
const LMatrix4 & get_lens_mat () const
 Returns the matrix that transforms from a point in front of the lens to a point in space. More...
 
const LMatrix4 & get_lens_mat_inv () const
 Returns the matrix that transforms from a point in space to a point in front of the lens. More...
 
PN_stdfloat get_min_fov () const
 
PN_stdfloat get_near () const
 
LPoint3 get_nodal_point () const
 
const LMatrix4 & get_projection_mat (StereoChannel channel=SC_mono) const
 Returns the complete transformation matrix from a 3-d point in space to a point on the film, if such a matrix exists, or the identity matrix if the lens is nonlinear. More...
 
const LMatrix4 & get_projection_mat_inv (StereoChannel channel=SC_mono) const
 Returns the matrix that transforms from a 2-d point on the film to a 3-d vector in space, if such a matrix exists. More...
 
const LVector3 & get_up_vector () const
 Returns the axis perpendicular to the camera's view vector that indicates the "up" direction. More...
 
PN_stdfloat get_vfov () const
 Returns the vertical component of fov only. More...
 
const LVecBase3 & get_view_hpr () const
 
const LMatrix4 & get_view_mat () const
 
const LVector3 & get_view_vector () const
 Returns the axis along which the lens is facing. More...
 
virtual bool is_orthographic () const
 Returns true if the lens represents a orthographic projection (i.e. More...
 
virtual bool is_perspective () const
 Returns true if the lens represents a perspective projection (i.e. More...
 
void operator= (const Lens &copy)
 
virtual void output (std::ostream &out) const
 
bool project (const LPoint3 &point3d, LPoint3 &point2d) const
 Given a 3-d point in space, determine the 2-d point this maps to, in the range (-1,1) in both dimensions, where (0,0) is the center of the lens and (-1,-1) is the lower-left corner. More...
 
bool project (const LPoint3 &point3d, LPoint2 &point2d) const
 Given a 3-d point in space, determine the 2-d point this maps to, in the range (-1,1) in both dimensions, where (0,0) is the center of the lens and (-1,-1) is the lower-left corner. More...
 
virtual PT (Geom) make_geometry()
 
virtual PT (BoundingVolume) make_bounds() const
 
void recompute_all ()
 Forces all internal parameters of the Lens to be recomputed. More...
 
void set_aspect_ratio (PN_stdfloat aspect_ratio)
 
void set_change_event (const std::string &event)
 
void set_convergence_distance (PN_stdfloat convergence_distance)
 
void set_coordinate_system (CoordinateSystem cs)
 
void set_custom_film_mat (const LMatrix4 &custom_film_mat)
 Specifies a custom matrix to transform the points on the film after they have been converted into nominal film space (-1 . More...
 
void set_far (PN_stdfloat far_distance)
 
void set_film_offset (PN_stdfloat x, PN_stdfloat y)
 
void set_film_offset (const LVecBase2 &film_offset)
 
void set_film_size (PN_stdfloat width)
 
void set_film_size (PN_stdfloat width, PN_stdfloat height)
 
void set_film_size (const LVecBase2 &film_size)
 
void set_focal_length (PN_stdfloat focal_length)
 
void set_fov (PN_stdfloat fov)
 
void set_fov (PN_stdfloat hfov, PN_stdfloat vfov)
 
void set_fov (const LVecBase2 &fov)
 
void set_frustum_from_corners (const LVecBase3 &ul, const LVecBase3 &ur, const LVecBase3 &ll, const LVecBase3 &lr, int flags)
 Sets up the lens to use the frustum defined by the four indicated points. More...
 
void set_interocular_distance (PN_stdfloat interocular_distance)
 
void set_keystone (const LVecBase2 &keystone)
 
void set_min_fov (PN_stdfloat min_fov)
 
void set_near (PN_stdfloat near_distance)
 
void set_near_far (PN_stdfloat near_distance, PN_stdfloat far_distance)
 Simultaneously changes the near and far planes. More...
 
void set_view_hpr (PN_stdfloat h, PN_stdfloat p, PN_stdfloat r)
 
void set_view_hpr (const LVecBase3 &view_hpr)
 
void set_view_mat (const LMatrix4 &view_mat)
 
void set_view_vector (PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat i, PN_stdfloat j, PN_stdfloat k)
 Specifies the direction in which the lens is facing by giving an axis to look along, and a perpendicular (or at least non-parallel) up axis. More...
 
void set_view_vector (const LVector3 &view_vector, const LVector3 &up_vector)
 Specifies the direction in which the lens is facing by giving an axis to look along, and a perpendicular (or at least non-parallel) up axis. More...
 
- Public Member Functions inherited from TypedWritableReferenceCount
 TypedWritableReferenceCount (const TypedWritableReferenceCount &copy)
 
virtual ReferenceCountas_reference_count ()
 Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that type. More...
 
void operator= (const TypedWritableReferenceCount &copy)
 
- Public Member Functions inherited from TypedWritable
 TypedWritable (const TypedWritable &copy)
 
virtual int complete_pointers (TypedWritable **p_list, BamReader *manager)
 Receives an array of pointers, one for each time manager->read_pointer() was called in fillin(). More...
 
vector_uchar encode_to_bam_stream () const
 Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that data as a bytes object. More...
 
bool encode_to_bam_stream (vector_uchar &data, BamWriter *writer=nullptr) const
 Converts the TypedWritable object into a single stream of data using a BamWriter, and stores that data in the indicated string. More...
 
virtual void finalize (BamReader *manager)
 Called by the BamReader to perform any final actions needed for setting up the object after all objects have been read and all pointers have been completed. More...
 
UpdateSeq get_bam_modified () const
 Returns the current bam_modified counter. More...
 
void mark_bam_modified ()
 Increments the bam_modified counter, so that this object will be invalidated and retransmitted on any open bam streams. More...
 
void operator= (const TypedWritable &copy)
 
virtual bool require_fully_complete () const
 Some objects require all of their nested pointers to have been completed before the objects themselves can be completed. More...
 
virtual void update_bam_nested (BamWriter *manager)
 Called by the BamWriter when this object has not itself been modified recently, but it should check its nested objects for updates. More...
 
- Public Member Functions inherited from TypedObject
 TypedObject (const TypedObject &copy)=default
 
TypedObjectas_typed_object ()
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
const TypedObjectas_typed_object () const
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
int get_best_parent_from_Set (const std::set< int > &) const
 
int get_type_index () const
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More...
 
bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly. More...
 
bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type. More...
 
TypedObjectoperator= (const TypedObject &copy)=default
 
- Public Member Functions inherited from ReferenceCount
int get_ref_count () const
 
WeakReferenceListget_weak_list () const
 Returns the WeakReferenceList associated with this ReferenceCount object. More...
 
bool has_weak_list () const
 Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise. More...
 
void local_object ()
 This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack. More...
 
void ref () const
 Explicitly increments the reference count. More...
 
bool ref_if_nonzero () const
 Atomically increases the reference count of this object if it is not zero. More...
 
bool test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus. More...
 
bool test_ref_count_nonzero () const
 Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More...
 
virtual bool unref () const
 Explicitly decrements the reference count. More...
 
WeakReferenceListweak_ref ()
 Adds the indicated PointerToVoid as a weak reference to this object. More...
 
void weak_unref ()
 Removes the indicated PointerToVoid as a weak reference to this object. More...
 

Static Public Member Functions

static TypeHandle get_class_type ()
 
static void init_type ()
 
static void register_with_read_factory ()
 Tells the BamReader how to create objects of type Lens. More...
 
- Static Public Member Functions inherited from Lens
static TypeHandle get_class_type ()
 
static PN_stdfloat get_default_far ()
 Returns the default far plane distance that will be assigned to each newly- created lens. More...
 
static PN_stdfloat get_default_near ()
 Returns the default near plane distance that will be assigned to each newly-created lens. More...
 
static void init_type ()
 
- Static Public Member Functions inherited from TypedWritableReferenceCount
static TypeHandle get_class_type ()
 
static void init_type ()
 
static PT (TypedWritableReferenceCount) decode_from_bam_stream(vector_uchar data
 
- Static Public Member Functions inherited from TypedWritable
static bool decode_raw_from_bam_stream (TypedWritable *&ptr, ReferenceCount *&ref_ptr, vector_uchar data, BamReader *reader=nullptr)
 Reads the bytes created by a previous call to encode_to_bam_stream(), and extracts the single object on those bytes. More...
 
static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from TypedObject
static TypeHandle get_class_type ()
 
static void init_type ()
 This function is declared non-inline to work around a compiler bug in g++ 2.96. More...
 
- Static Public Member Functions inherited from ReferenceCount
static TypeHandle get_class_type ()
 
static void init_type ()
 

Public Attributes

 get_user_mat
 Returns the explicit projection matrix as set by the user. More...
 
 set_user_mat
 Explicitly specifies the projection matrix. More...
 
- Public Attributes inherited from Lens
 get_aspect_ratio
 Returns the aspect ratio of the Lens. More...
 
 get_change_event
 Returns the name of the event that will be generated whenever any properties of this particular Lens have changed. More...
 
 get_convergence_distance
 See set_convergence_distance(). More...
 
 get_coordinate_system
 Returns the coordinate system that all 3-d computations are performed within for this Lens. More...
 
 get_far
 Returns the position of the far plane (or cylinder, sphere, whatever). More...
 
 get_film_offset
 Returns the horizontal and vertical offset amounts of this Lens. More...
 
 get_film_size
 Returns the horizontal and vertical film size of the virtual film. More...
 
 get_focal_length
 Returns the focal length of the lens. More...
 
 get_fov
 Returns the horizontal and vertical film size of the virtual film. More...
 
 get_interocular_distance
 See set_interocular_distance(). More...
 
 get_keystone
 Returns the keystone correction specified for the lens. More...
 
 get_min_fov
 Returns the field of view of the narrowest dimension of the window. More...
 
 get_near
 Returns the position of the near plane (or cylinder, sphere, whatever). More...
 
 get_nodal_point
 Returns the center point of the lens: the point from which the lens is viewing. More...
 
 get_view_hpr
 Returns the direction in which the lens is facing. More...
 
 get_view_mat
 Returns the direction in which the lens is facing. More...
 
 set_aspect_ratio
 Sets the aspect ratio of the lens. More...
 
 set_change_event
 Sets the name of the event that will be generated whenever any properties of the Lens have changed. More...
 
 set_convergence_distance
 Sets the distance between between the camera plane and the point in the distance that the left and right eyes are both looking at. More...
 
 set_coordinate_system
 Specifies the coordinate system that all 3-d computations are performed within for this Lens. More...
 
 set_far
 Defines the position of the far plane (or cylinder, sphere, whatever). More...
 
 set_film_offset
 Sets the horizontal and vertical offset amounts of this Lens. More...
 
 set_film_size
 Sets the horizontal size of the film without changing its shape. More...
 
 set_focal_length
 Sets the focal length of the lens. More...
 
 set_fov
 Sets the horizontal field of view of the lens without changing the aspect ratio. More...
 
 set_interocular_distance
 Sets the distance between the left and right eyes of a stereo camera. More...
 
 set_keystone
 Indicates the ratio of keystone correction to perform on the lens, in each of three axes. More...
 
 set_min_fov
 Sets the field of view of the smallest dimension of the window. More...
 
 set_near
 Defines the position of the near plane (or cylinder, sphere, whatever). More...
 
 set_view_hpr
 Sets the direction in which the lens is facing. More...
 
 set_view_mat
 Sets an arbitrary transformation on the lens. More...
 
- Public Attributes inherited from TypedWritableReferenceCount
static BamReaderreader = nullptr)
 
- Public Attributes inherited from TypedObject
 get_type
 
- Public Attributes inherited from ReferenceCount
 get_ref_count
 Returns the current reference count. More...
 

Additional Inherited Members

- Public Types inherited from Lens
enum  FromCorners {
  FC_roll = 0x0001, FC_camera_plane = 0x0002, FC_off_axis = 0x0004, FC_aspect_ratio = 0x0008,
  FC_shear = 0x0010, FC_keystone = 0x0020
}
 
enum  StereoChannel { SC_mono = 0x00, SC_left = 0x01, SC_right = 0x02, SC_stereo = 0x03 }
 
- Static Public Attributes inherited from TypedWritable
static TypedWritable *const Null = nullptr
 

Detailed Description

A completely generic linear lens.

This is provided for the benefit of 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.

Definition at line 28 of file matrixLens.h.

Member Function Documentation

◆ clear_left_eye_mat()

void MatrixLens::clear_left_eye_mat ( )
inline

Removes the custom projection matrix set for the left eye, and uses the center matrix (set by set_user_mat) instead.

Definition at line 102 of file matrixLens.I.

◆ clear_right_eye_mat()

void MatrixLens::clear_right_eye_mat ( )
inline

Removes the custom projection matrix set for the right eye, and uses the center matrix (set by set_user_mat) instead.

Definition at line 152 of file matrixLens.I.

◆ get_left_eye_mat()

const LMatrix4 & MatrixLens::get_left_eye_mat ( ) const
inline

Returns the custom projection matrix for the left eye, if any, or the center matrix if there is no custom matrix set for the left eye.

Definition at line 123 of file matrixLens.I.

◆ get_right_eye_mat()

const LMatrix4 & MatrixLens::get_right_eye_mat ( ) const
inline

Returns the custom projection matrix for the right eye, if any, or the center matrix if there is no custom matrix set for the right eye.

Definition at line 173 of file matrixLens.I.

◆ has_left_eye_mat()

bool MatrixLens::has_left_eye_mat ( ) const
inline

Returns true if the camera has a custom projection matrix set for the left eye, or false if the center matrix (set by set_user_mat) will be used for the left eye.

Definition at line 114 of file matrixLens.I.

◆ has_right_eye_mat()

bool MatrixLens::has_right_eye_mat ( ) const
inline

Returns true if the camera has a custom projection matrix set for the right eye, or false if the center matrix (set by set_user_mat) will be used for the right eye.

Definition at line 164 of file matrixLens.I.

◆ is_linear()

virtual bool MatrixLens::is_linear ( ) const
virtual

Returns true if the lens represents a linear projection (e.g.

PerspectiveLens, OrthographicLens), and therefore there is a valid matrix returned by get_projection_mat(), or false otherwise.

Reimplemented from Lens.

◆ register_with_read_factory()

void MatrixLens::register_with_read_factory ( )
static

Tells the BamReader how to create objects of type Lens.

Definition at line 77 of file matrixLens.cxx.

References BamReader::get_factory(), and Factory< Type >::register_factory().

◆ set_left_eye_mat()

void MatrixLens::set_left_eye_mat ( const LMatrix4 &  left_eye_mat)
inline

Sets a custom projection matrix for the left eye.

This is only used if the lens is attached to a stereo camera, in which case the left eye matrix will be used to draw the scene in the left eye (but the center matrix–the user_mat–will still be used to cull the scene).

This matrix should not be too different from the center matrix (set by set_user_mat()) or culling errors may become obvious.

Definition at line 90 of file matrixLens.I.

◆ set_right_eye_mat()

void MatrixLens::set_right_eye_mat ( const LMatrix4 &  right_eye_mat)
inline

Sets a custom projection matrix for the right eye.

This is only used if the lens is attached to a stereo camera, in which case the right eye matrix will be used to draw the scene in the right eye (but the center matrix–the user_mat–will still be used to cull the scene).

This matrix should not be too different from the center matrix (set by set_user_mat()) or culling errors may become obvious.

Definition at line 140 of file matrixLens.I.

◆ write_datagram()

void MatrixLens::write_datagram ( BamWriter manager,
Datagram dg 
)
virtual

Writes the contents of this object to the datagram for shipping out to a Bam file.

Reimplemented from Lens.

Definition at line 86 of file matrixLens.cxx.

References Datagram::add_uint8(), BamWriter::get_file_minor_ver(), and Lens::write_datagram().

Member Data Documentation

◆ get_user_mat

const LMatrix4 & MatrixLens::get_user_mat
inline

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).

Definition at line 39 of file matrixLens.h.

◆ set_user_mat

void MatrixLens::set_user_mat
inline

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.

Definition at line 39 of file matrixLens.h.


The documentation for this class was generated from the following files: