types.h

Mon, 06 May 2013 03:32:00 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 06 May 2013 03:32:00 +0300
changeset 166
72ec7b60da54
parent 163
46955613626d
permissions
-rw-r--r--

add missing license headers from new files

135
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
1 /*
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
2 * LDForge: LDraw parts authoring CAD
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
3 * Copyright (C) 2013 Santeri Piippo
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
4 *
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
5 * This program is free software: you can redistribute it and/or modify
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
6 * it under the terms of the GNU General Public License as published by
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
8 * (at your option) any later version.
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
9 *
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
10 * This program is distributed in the hope that it will be useful,
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
13 * GNU General Public License for more details.
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
14 *
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
15 * You should have received a copy of the GNU General Public License
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
17 */
64
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
135
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
19 #ifndef TYPES_H
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
20 #define TYPES_H
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
21
64
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "common.h"
162
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
23 #include "misc.h"
64
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24
135
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
25 typedef unsigned int uint;
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
26 typedef short unsigned int ushort;
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
27 typedef long unsigned int ulong;
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
28
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
29 // Typedef out the _t suffices :)
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
30 typedef int8_t int8;
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
31 typedef int16_t int16;
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
32 typedef int32_t int32;
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
33 typedef int64_t int64;
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
34 typedef uint8_t uint8;
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
35 typedef uint16_t uint16;
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
36 typedef uint32_t uint32;
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
37 typedef uint64_t uint64;
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
38
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
39 template<class T> using initlist = std::initializer_list<T>;
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
40 using std::vector;
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
41
147
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
42 enum Axis { X, Y, Z };
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
43 static const Axis g_Axes[3] = {X, Y, Z};
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
44
64
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 // =============================================================================
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 // =============================================================================
162
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
48 // matrix
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
49 //
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
50 // A templated, mathematical N x N matrix
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
51 // =============================================================================
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
52 template<int N> class matrix {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
53 public:
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
54 // Constructors
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
55 matrix () {}
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
56 matrix (initlist<double> vals) {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
57 assert (vals.size() == N * N);
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
58 memcpy (&m_vals[0], &(*vals.begin ()), sizeof m_vals);
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
59 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
60
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
61 matrix (double fillval) {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
62 for (short i = 0; i < (N * N); ++i)
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
63 m_vals[i] = fillval;
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
64 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
65
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
66 matrix (double vals[]) {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
67 for (short i = 0; i < (N * N); ++i)
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
68 m_vals[i] = vals[i];
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
69 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
70
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
71 template<int M> matrix (matrix<M> other) {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
72 assert (M >= N);
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
73
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
74 for (short i = 0; i < M; ++i)
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
75 for (short j = 0; j < M; ++j) {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
76 const short idx = (i * M) + j;
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
77 m_vals[idx] = other[idx];
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
78 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
79 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
80
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
81 matrix<N> mult (matrix<N> other) {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
82 matrix val;
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
83 val.zero ();
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
84
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
85 for (short i = 0; i < N; ++i)
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
86 for (short j = 0; j < N; ++j)
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
87 for (short k = 0; k < N; ++k)
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
88 val[(i * N) + j] += m_vals[(i * N) + k] * other[(k * N) + j];
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
89
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
90 return val;
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
91 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
92
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
93 matrix<N>& operator= (matrix<N> other) {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
94 memcpy (&m_vals[0], &other.m_vals[0], sizeof (double) * N * N);
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
95 return *this;
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
96 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
97
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
98 matrix<N> operator* (matrix<N> other) {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
99 return mult (other);
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
100 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
101
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
102 double& operator[] (const uint idx) {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
103 return m_vals[idx];
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
104 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
105
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
106 const double& operator[] (const uint idx) const {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
107 return m_vals[idx];
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
108 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
109
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
110 void zero () {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
111 memset (&m_vals[0], 0, sizeof (double) * N * N);
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
112 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
113
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
114 void puts () const {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
115 for (short i = 0; i < N; ++i) {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
116 for (short j = 0; j < N; ++j)
163
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
117 printf ("%*f\t", 10, m_vals[(i * N) + j]);
162
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
118
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
119 printf ("\n");
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
120 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
121 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
122
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
123 str stringRep () const {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
124 str val;
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
125 for (short i = 0; i < N * N; ++i) {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
126 if (i > 0)
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
127 val += ' ';
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
128
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
129 val.appendformat ("%s", ftoa (m_vals[i]).chars());
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
130 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
131
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
132 return val;
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
133 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
134
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
135 private:
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
136 double m_vals[N * N];
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
137 };
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
138
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
139 // =============================================================================
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
141 // =============================================================================
64
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 // vertex
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 //
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 147
diff changeset
144 // Vertex class, contains a single point in 3D space. Not to be confused with
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 147
diff changeset
145 // LDVertex, which is a vertex used in an LDraw part file.
64
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 // =============================================================================
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 class vertex {
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 public:
147
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
149 double m_coords[3];
64
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 vertex () {}
147
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
152 vertex (double x, double y, double z) {
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
153 m_coords[X] = x;
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
154 m_coords[Y] = y;
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
155 m_coords[Z] = z;
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
156 }
64
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157
120
607301744394 Rotation and rounding. Rotation needs work to get proper origin stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
158 void move (vertex other) {
147
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
159 for (const Axis ax : g_Axes)
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
160 m_coords[ax] += other[ax];
120
607301744394 Rotation and rounding. Rotation needs work to get proper origin stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
161 }
607301744394 Rotation and rounding. Rotation needs work to get proper origin stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
162
607301744394 Rotation and rounding. Rotation needs work to get proper origin stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
163 vertex& operator+= (vertex other) {
607301744394 Rotation and rounding. Rotation needs work to get proper origin stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
164 move (other);
102
cacd4681ccb4 Added basic object moving with MLCAD-like controls.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
165 return *this;
cacd4681ccb4 Added basic object moving with MLCAD-like controls.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
166 }
cacd4681ccb4 Added basic object moving with MLCAD-like controls.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
167
162
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
168 vertex operator/ (const double d) const {
121
7e87c85ad092 Rotation improvements; allow radials be inlined
Santeri Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
169 vertex other (*this);
7e87c85ad092 Rotation improvements; allow radials be inlined
Santeri Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
170 return other /= d;
7e87c85ad092 Rotation improvements; allow radials be inlined
Santeri Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
171 }
7e87c85ad092 Rotation improvements; allow radials be inlined
Santeri Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
172
7e87c85ad092 Rotation improvements; allow radials be inlined
Santeri Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
173 vertex& operator/= (const double d) {
147
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
174 for (const Axis ax : g_Axes)
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
175 m_coords[ax] /= d;
121
7e87c85ad092 Rotation improvements; allow radials be inlined
Santeri Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
176 return *this;
7e87c85ad092 Rotation improvements; allow radials be inlined
Santeri Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
177 }
7e87c85ad092 Rotation improvements; allow radials be inlined
Santeri Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
178
163
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
179 bool operator== (const vertex& other) const {
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
180 return coord (X) == other[X] &&
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
181 coord (Y) == other[Y] &&
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
182 coord (Z) == other[Z];
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
183 }
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
184
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
185 bool operator!= (const vertex& other) const {
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
186 return !operator== (other);
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
187 }
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
188
102
cacd4681ccb4 Added basic object moving with MLCAD-like controls.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
189 vertex operator- () const {
147
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
190 return vertex (-m_coords[X], -m_coords[Y], -m_coords[Z]);
102
cacd4681ccb4 Added basic object moving with MLCAD-like controls.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
191 }
cacd4681ccb4 Added basic object moving with MLCAD-like controls.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
192
162
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
193 double& coord (const ushort n) {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
194 return m_coords[n];
147
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
195 }
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
196
162
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
197 const double& coord (const ushort n) const {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
198 return m_coords[n];
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
199 }
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
200
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
201 double& operator[] (const Axis ax) {
147
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
202 return coord ((ushort) ax);
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
203 }
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
204
162
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
205 const double& operator[] (const Axis ax) const {
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
206 return coord ((ushort) ax);
140
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
207 }
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
208
163
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
209 double& x () { return m_coords[X]; }
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
210 double& y () { return m_coords[Y]; }
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
211 double& z () { return m_coords[Z]; }
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
212 const double& x () const { return m_coords[X]; }
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
213 const double& y () const { return m_coords[Y]; }
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
214 const double& z () const { return m_coords[Z]; }
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
215
64
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 vertex midpoint (vertex& other);
140
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
217 str stringRep (const bool mangled);
162
b7d65e89861a matrix is now templated with N=int (usually 3)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
218 void transform (matrix<3> matr, vertex pos);
163
46955613626d Plane drawing is functional at last!!!11 Also added meta function findAction to find an action by name so I don't have to extern all of them manually in gui.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 162
diff changeset
219 void transform (matrix<4> matr);
64
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220 };
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221
135
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
222 #endif // TYPES_H

mercurial