MinGfx Toolkit  1.0
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
Public Member Functions | Static Public Member Functions | List of all members
mingfx::Point3 Class Reference

Detailed Description

A 3D Point with floating point coordinates, used for storing vertices and all sorts of other 3D graphics operations.

Point3s can be transformed by a Matrix4. Example:

Point3 a(0,0,1);
std::cout << a << std::endl;
Matrix4 M = Matrix4::Translation(Vector3(0,0,-1));
Point3 b = M * a;
std::cout << b << std::endl;
// you can access the individual components of the point in two ways:
Point3 p(1,2,3);
float option1 = p.x();
float option2 = p[0];
// to set an individual component of the point use the [] operator:
Point3 p2;
p2[0] = 0.4;
p2[1] = 1.2;
p2[2] = 3.1;
static Matrix4 Translation(const Vector3 &v)
Returns the translation matrix described by the vector.
Point3()
Default point at the origin.

Definition at line 52 of file point3.h.

#include <point3.h>

Public Member Functions

 Point3 ()
 Default point at the origin. More...
 
 Point3 (float x, float y, float z)
 Constructs a point given (x,y,z,1), where the 1 comes from the use of homogeneous coordinates in computer graphics. More...
 
 Point3 (float *p)
 Constructs a point given a pointer to x,y,z data. More...
 
 Point3 (const Point3 &p)
 Copy constructor for point. More...
 
virtual ~Point3 ()
 Point destructor. More...
 
bool operator== (const Point3 &p) const
 Check for "equality", taking floating point imprecision into account. More...
 
bool operator!= (const Point3 &p) const
 Check for "inequality", taking floating point imprecision into account. More...
 
Point3operator= (const Point3 &p)
 Assignment operator. More...
 
float operator[] (const int i) const
 Read only access to the ith coordinate of the point. More...
 
float & operator[] (const int i)
 Returns a reference to the ith coordinate of the point. Use this accessor if you wish to set the coordinate rather than just request its value. Example: More...
 
float x () const
 Read only access to the x coordinate. Can also use my_point[0]. Use the my_point[0] = 1.0; form if you need to set the value. More...
 
float y () const
 Read only access to the y coordinate. Can also use my_point[1]. Use the my_point[1] = 1.0; form if you need to set the value. More...
 
float z () const
 Read only access to the z coordinate. Can also use my_point[2]. Use the my_point[2] = 1.0; form if you need to set the value. More...
 
float w () const
 In homogeneous coordinates, the w coordinate for all points is 1.0. More...
 
const float * value_ptr () const
 Returns a const pointer to the raw data array. More...
 
Point3 Lerp (const Point3 &b, float alpha) const
 Linear interpolation between this point and another. Alpha=0.0 returns this point, and alpha=1.0 returns the other point, other values blend between the two. More...
 
float DistanceToPlane (const Point3 &plane_origin, const Vector3 &plane_normal)
 Returns the shortest (i.e., perpendicular) distance from this point to a plane defined by a point and a normal. More...
 
Point3 ClosestPointOnPlane (const Point3 &plane_origin, const Vector3 &plane_normal)
 Returns the perpendicular projection of this point onto a plane defined by a point and a normal. More...
 
Point3 ClosestPoint (const std::vector< Point3 > &point_list)
 Given a list of points, returns the closest in the last to the current point. More...
 

Static Public Member Functions

static const Point3Origin ()
 (0,0,0) - a shortcut for a special point that is frequently needed More...
 
static const Point3Zero ()
 (0,0,0) - a shortcut for a special point that is frequently needed More...
 
static const Point3One ()
 (1,1,1) - a shortcut for a special point that is frequently needed More...
 
static Point3 Lerp (const Point3 &a, const Point3 &b, float alpha)
 Linear interpolation between two points. Alpha=0.0 returns 'a' and alpha=1.0 returns 'b', other values blend between the two. More...
 

Constructor & Destructor Documentation

◆ Point3() [1/4]

mingfx::Point3::Point3 ( )

Default point at the origin.

◆ Point3() [2/4]

mingfx::Point3::Point3 ( float  x,
float  y,
float  z 
)

Constructs a point given (x,y,z,1), where the 1 comes from the use of homogeneous coordinates in computer graphics.

◆ Point3() [3/4]

mingfx::Point3::Point3 ( float *  p)

Constructs a point given a pointer to x,y,z data.

◆ Point3() [4/4]

mingfx::Point3::Point3 ( const Point3 p)

Copy constructor for point.

◆ ~Point3()

virtual mingfx::Point3::~Point3 ( )
virtual

Point destructor.

Member Function Documentation

◆ ClosestPoint()

Point3 mingfx::Point3::ClosestPoint ( const std::vector< Point3 > &  point_list)

Given a list of points, returns the closest in the last to the current point.

◆ ClosestPointOnPlane()

Point3 mingfx::Point3::ClosestPointOnPlane ( const Point3 plane_origin,
const Vector3 plane_normal 
)

Returns the perpendicular projection of this point onto a plane defined by a point and a normal.

◆ DistanceToPlane()

float mingfx::Point3::DistanceToPlane ( const Point3 plane_origin,
const Vector3 plane_normal 
)

Returns the shortest (i.e., perpendicular) distance from this point to a plane defined by a point and a normal.

◆ Lerp() [1/2]

static Point3 mingfx::Point3::Lerp ( const Point3 a,
const Point3 b,
float  alpha 
)
static

Linear interpolation between two points. Alpha=0.0 returns 'a' and alpha=1.0 returns 'b', other values blend between the two.

◆ Lerp() [2/2]

Point3 mingfx::Point3::Lerp ( const Point3 b,
float  alpha 
) const

Linear interpolation between this point and another. Alpha=0.0 returns this point, and alpha=1.0 returns the other point, other values blend between the two.

◆ One()

static const Point3& mingfx::Point3::One ( )
static

(1,1,1) - a shortcut for a special point that is frequently needed

◆ operator!=()

bool mingfx::Point3::operator!= ( const Point3 p) const

Check for "inequality", taking floating point imprecision into account.

◆ operator=()

Point3& mingfx::Point3::operator= ( const Point3 p)

Assignment operator.

◆ operator==()

bool mingfx::Point3::operator== ( const Point3 p) const

Check for "equality", taking floating point imprecision into account.

◆ operator[]() [1/2]

float& mingfx::Point3::operator[] ( const int  i)

Returns a reference to the ith coordinate of the point. Use this accessor if you wish to set the coordinate rather than just request its value. Example:

a[0] = 5.0; // set the x-coordinate of the point

◆ operator[]() [2/2]

float mingfx::Point3::operator[] ( const int  i) const

Read only access to the ith coordinate of the point.

◆ Origin()

static const Point3& mingfx::Point3::Origin ( )
static

(0,0,0) - a shortcut for a special point that is frequently needed

◆ value_ptr()

const float* mingfx::Point3::value_ptr ( ) const

Returns a const pointer to the raw data array.

◆ w()

float mingfx::Point3::w ( ) const
inline

In homogeneous coordinates, the w coordinate for all points is 1.0.

Definition at line 104 of file point3.h.

◆ x()

float mingfx::Point3::x ( ) const
inline

Read only access to the x coordinate. Can also use my_point[0]. Use the my_point[0] = 1.0; form if you need to set the value.

Definition at line 93 of file point3.h.

◆ y()

float mingfx::Point3::y ( ) const
inline

Read only access to the y coordinate. Can also use my_point[1]. Use the my_point[1] = 1.0; form if you need to set the value.

Definition at line 97 of file point3.h.

◆ z()

float mingfx::Point3::z ( ) const
inline

Read only access to the z coordinate. Can also use my_point[2]. Use the my_point[2] = 1.0; form if you need to set the value.

Definition at line 101 of file point3.h.

◆ Zero()

static const Point3& mingfx::Point3::Zero ( )
static

(0,0,0) - a shortcut for a special point that is frequently needed


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