summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmpoint.h
blob: 45a89e4ec48a48bff623c19a1a8dba93300eb535 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2000-2001 by Andreas Zehender
    email                : zehender@kde.org
**************************************************************************

**************************************************************************
*                                                                        *
*  This program is free software; you can redistribute it and/or modify  *
*  it under the terms of the GNU General Public License as published by  *
*  the Free Software Foundation; either version 2 of the License, or     *
*  (at your option) any later version.                                   *
*                                                                        *
**************************************************************************/


#ifndef PMPOINT_H
#define PMPOINT_H

#include "GL/gl.h"
#include <tqmemarray.h>

class PMVector;
class PMMatrix;

/**
 * Class for 3d points.
 *
 * Used in @ref PMViewStructure.
 *
 * Optimized for rendering with opengl
 */

class PMPoint
{
public:
   /**
    * Creates a point with coordinates [0,0,0]
    */
   PMPoint( );
   /**
    * Creates a point with coordinates [x,y,z]
    */
   PMPoint( GLdouble x, GLdouble y, GLdouble z );
   /**
    * Creates a point from a vector. The size of the vector has to be 3
    */
   PMPoint( const PMVector& v );
   /**
    * Copy constructor
    */
   PMPoint( const PMPoint& p );

   /**
    * Returns a reference to a coordinate, 0:x, 1:y, 2:z
    */
   GLdouble& operator[] ( int index ) { return m_coord[index];}
   /**
    * Returns a reference to a coordinate, 0:x, 1:y, 2:z
    */
   const GLdouble& operator[] ( int index ) const { return m_coord[index];}

   /**
    * Returns the x coordinate
    */
   GLdouble x( ) const { return m_coord[0]; }
   /**
    * Returns the y coordinate
    */
   GLdouble y( ) const { return m_coord[1]; }
   /**
    * Returns the z coordinate
    */
   GLdouble z( ) const { return m_coord[2]; }

   /**
    * Sets the x coordinate
    */
   void setX( const GLdouble newx ) { m_coord[0] = newx; }
   /**
    * Sets the y coordinate
    */
   void setY( const GLdouble newy ) { m_coord[1] = newy; }
   /**
    * Sets the z coordinate
    */
   void setZ( const GLdouble newz ) { m_coord[2] = newz; }

   /**
    * Transforms the point p with the matrix m
    * @see transform
    */
   friend PMPoint operator* ( const PMMatrix& m, const PMPoint& p );
   /**
    * Assigns c to the point
    */
   PMPoint& operator= ( const PMPoint& c );
   /**
    * Transforms the point with the matrix m. Same as p = m * p
    *
    * size must be 3!
    */
   void transform( const PMMatrix& m );
   
private:
   /**
    * The coords. THIS MEMBER HAS TO BE THE FIRST AND ONLY ONE
    * (for rendering with OpenGL)!
    */
   GLdouble m_coord[3];
};

/**
 * @ref TQMemArray of PMPoints
 */
typedef TQMemArray<PMPoint> PMPointArray;


#endif