33 #ifndef LE_GEOMETRY_SCALAR_H
34 #define LE_GEOMETRY_SCALAR_H
69 r.
x = cosf(azi) * cosf(inc) * dist;
70 r.
y = sinf(inc) * dist;
71 r.
z = -sinf(azi) * cosf(inc) * dist;
190 return x == v.
x && y == v.
y && z == v.
z;
195 return x * v.
x + y * v.
y + z * v.
z;
201 c.
x = y * v.
z - v.
y *
z;
202 c.
y = -x * v.
z + v.
x *
z;
203 c.
z = x * v.
y - v.
x *
y;
210 c.
x = copysignf(1.0f, x);
211 c.
y = copysignf(1.0f, y);
212 c.
z = copysignf(1.0f, z);
213 c.
w = copysignf(1.0f, w);
220 c.
x = floorf(x + 0.5f);
221 c.
y = floorf(y + 0.5f);
222 c.
z = floorf(z + 0.5f);
223 c.
w = floorf(w + 0.5f);
255 return sqrtf(
dot(*
this));
287 float dx = v2.
x - v1.
x;
288 float dy = v2.
y - v1.
y;
289 float dz = v2.
z - v1.
z;
290 norm = sqrtf(dx * dx + dy * dy + dz * dz);
380 for (
int i = 0; i < 4; i++)
381 for (
int j = 0; j < 4; j++)
388 for (
int i = 0; i < 4; i++)
389 for (
int j = 0; j < 4; j++)
390 m.
mat[j][i] = mat[i][j];
497 float c = cosf(angle);
498 float s = sinf(angle);
502 m.
mat[0][0] = c + axis.
x * axis.
x * d;
503 m.
mat[1][0] = axis.
y * axis.
x * d + axis.
z * s;
504 m.
mat[2][0] = axis.
z * axis.
x * d - axis.
y * s;
507 m.
mat[0][1] = axis.
x * axis.
y * d - axis.
z * s;
508 m.
mat[1][1] = c + axis.
y * axis.
y * d;
509 m.
mat[2][1] = axis.
z * axis.
y * d + axis.
x * s;
512 m.
mat[0][2] = axis.
x * axis.
z * d + axis.
y * s;
513 m.
mat[1][2] = axis.
y * axis.
z * d - axis.
x * s;
514 m.
mat[2][2] = c + axis.
z * axis.
z * d;
527 float l = sqrtf(mat[0][0] * mat[0][0] + mat[1][0] * mat[1][0]);
529 angle.
x = atan2f(mat[2][1], mat[2][2]);
530 angle.
y = atan2f(-mat[2][0], l);
531 angle.
z = atan2f(mat[1][0], mat[0][0]);
533 angle.
x = atan2f(-mat[1][2], mat[1][1]);
534 angle.
y = atan2f(-mat[2][0], l);
547 m.
mat[0][0] = right.
x;
548 m.
mat[1][0] = right.
y;
549 m.
mat[2][0] = right.
z;
557 m.
mat[0][2] = back.
x;
558 m.
mat[1][2] = back.
y;
559 m.
mat[2][2] = back.
z;
576 m.
mat[0][0] = right.
x;
577 m.
mat[1][0] = right.
y;
578 m.
mat[2][0] = right.
z;
586 m.
mat[0][2] = back.
x;
587 m.
mat[1][2] = back.
y;
588 m.
mat[2][2] = back.
z;
602 float d = mat[0][0]*(mat[1][1]*mat[2][2]-mat[2][1]*mat[1][2])
603 - mat[0][1]*(mat[1][0]*mat[2][2]-mat[1][2]*mat[2][0])
604 + mat[0][2]*(mat[1][0]*mat[2][1]-mat[1][1]*mat[2][0]);
607 if (d == 0.0f) {m.
zero();
return m;}
610 m.mat[0][0] = (mat[1][1] * mat[2][2] - mat[2][1] * mat[1][2]) * d;
611 m.mat[0][1] = -(mat[0][1] * mat[2][2] - mat[2][1] * mat[0][2]) * d;
612 m.mat[0][2] = (mat[0][1] * mat[1][2] - mat[1][1] * mat[0][2]) * d;
614 m.mat[1][0] = -(mat[1][0] * mat[2][2] - mat[2][0] * mat[1][2]) * d;
615 m.mat[1][1] = (mat[0][0] * mat[2][2] - mat[2][0] * mat[0][2]) * d;
616 m.mat[1][2] = -(mat[0][0] * mat[1][2] - mat[1][0] * mat[0][2]) * d;
618 m.mat[2][0] = (mat[1][0] * mat[2][1] - mat[2][0] * mat[1][1]) * d;
619 m.mat[2][1] = -(mat[0][0] * mat[2][1] - mat[2][0] * mat[0][1]) * d;
620 m.mat[2][2] = (mat[0][0] * mat[1][1] - mat[1][0] * mat[0][1]) * d;
628 float x = v.
x * mat[0][0] + v.
y * mat[0][1] + v.
z * mat[0][2] + mat[0][3];
629 float y = v.
x * mat[1][0] + v.
y * mat[1][1] + v.
z * mat[1][2] + mat[1][3];
630 float z = v.
x * mat[2][0] + v.
y * mat[2][1] + v.
z * mat[2][2] + mat[2][3];
637 for (
int i = 0; i < 4; i++) {
638 r.
mat[i][0] = mat[i][0] + m.
mat[i][0];
639 r.
mat[i][1] = mat[i][1] + m.
mat[i][1];
640 r.
mat[i][2] = mat[i][2] + m.
mat[i][2];
641 r.
mat[i][3] = mat[i][3] + m.
mat[i][3];
649 for (
int i = 0; i < 4; i++) {
650 r.
mat[i][0] = mat[i][0] * m.
mat[0][0] + mat[i][1] * m.
mat[1][0] + mat[i][2] * m.
mat[2][0] + mat[i][3] * m.
mat[3][0];
651 r.
mat[i][1] = mat[i][0] * m.
mat[0][1] + mat[i][1] * m.
mat[1][1] + mat[i][2] * m.
mat[2][1] + mat[i][3] * m.
mat[3][1];
652 r.
mat[i][2] = mat[i][0] * m.
mat[0][2] + mat[i][1] * m.
mat[1][2] + mat[i][2] * m.
mat[2][2] + mat[i][3] * m.
mat[3][2];
653 r.
mat[i][3] = mat[i][0] * m.
mat[0][3] + mat[i][1] * m.
mat[1][3] + mat[i][2] * m.
mat[2][3] + mat[i][3] * m.
mat[3][3];
670 #endif //LE_GEOMETRY_SCALAR_H
const LeVertex up
Definition: geometry_scalar.h:661
LeVertex floor() const
Definition: geometry_scalar.h:227
LeVertex operator-=(LeVertex v)
Definition: geometry_scalar.h:110
LeVertex(float px, float py, float pz)
Definition: geometry_scalar.h:58
LeVertex operator-() const
Definition: geometry_scalar.h:101
LeAxis xAxis
Definition: geometry_scalar.h:304
void rotateEulerXYZ(LeVertex a)
Definition: geometry_scalar.h:411
LeVertex origin
Definition: geometry_scalar.h:267
void rotateY(float a)
Definition: geometry_scalar.h:467
LeVertex operator+(LeVertex v) const
Definition: geometry_scalar.h:75
void scale(LeVertex s)
Definition: geometry_scalar.h:401
bool operator==(LeVertex v)
Definition: geometry_scalar.h:188
LeMatrix inverse3x3()
Definition: geometry_scalar.h:600
LeVertex()
Definition: geometry_scalar.h:50
LeVertex operator/(LeVertex v) const
Definition: geometry_scalar.h:127
LeAxis()
Definition: geometry_scalar.h:271
LeAxis(LeVertex v1, LeVertex v2)
Definition: geometry_scalar.h:282
LightEngine 3D: General engine configuration file.
float x
Definition: geometry_scalar.h:48
LightEngine 3D: Global helpers and definitions.
Definition: geometry_scalar.h:660
const LeVertex down
Definition: geometry_scalar.h:662
LePlane(LeVertex v1, LeVertex v2, LeVertex v3)
Definition: geometry_scalar.h:323
void alignBackRight(LeVertex back, LeVertex right)
Definition: geometry_scalar.h:569
const LeVertex back
Definition: geometry_scalar.h:664
const LeVertex front
Definition: geometry_scalar.h:663
void rotateEulerZXY(LeVertex a)
Definition: geometry_scalar.h:439
LeVertex cross(LeVertex v) const
Definition: geometry_scalar.h:198
LeAxis yAxis
Definition: geometry_scalar.h:305
float norm() const
Definition: geometry_scalar.h:253
LeAxis zAxis
Definition: geometry_scalar.h:306
void rotateZ(float a)
Definition: geometry_scalar.h:481
float y
Definition: geometry_scalar.h:48
LeMatrix()
Definition: geometry_scalar.h:350
LeVertex normalize()
Definition: geometry_scalar.h:237
void rotateX(float a)
Definition: geometry_scalar.h:453
void rotateEulerYXZ(LeVertex a)
Definition: geometry_scalar.h:432
Represent a vertex in 3D space.
Definition: geometry_scalar.h:46
Represent a 4x4 matrix to handle 3D transforms.
Definition: geometry_scalar.h:346
LeVertex operator*(LeVertex v) const
Definition: geometry_scalar.h:118
LeVertex axis
Definition: geometry_scalar.h:268
float norm
Definition: geometry_scalar.h:269
float z
Definition: geometry_scalar.h:48
void rotate(LeVertex axis, float angle)
Definition: geometry_scalar.h:495
void toEulerZYX(LeVertex &angle)
Definition: geometry_scalar.h:525
LeVertex sign() const
Definition: geometry_scalar.h:207
float w
Definition: geometry_scalar.h:48
void identity()
Definition: geometry_scalar.h:355
void translate(LeVertex d)
Definition: geometry_scalar.h:394
LeVertex operator/=(LeVertex v)
Definition: geometry_scalar.h:163
LeVertex operator*(LeVertex v) const
Definition: geometry_scalar.h:626
Represent an axis in 3D space.
Definition: geometry_scalar.h:265
void rotateEulerZYX(LeVertex a)
Definition: geometry_scalar.h:446
float dot(LeVertex v) const
Definition: geometry_scalar.h:193
LeMatrix operator+(LeMatrix m) const
Definition: geometry_scalar.h:634
void rotateEulerYZX(LeVertex a)
Definition: geometry_scalar.h:425
static LeVertex spherical(float azi, float inc, float dist)
Definition: geometry_scalar.h:66
void rotateEulerXZY(LeVertex a)
Definition: geometry_scalar.h:418
LeVertex operator+=(LeVertex v)
Definition: geometry_scalar.h:84
const LeVertex left
Definition: geometry_scalar.h:665
const LeVertex zero
Definition: geometry_scalar.h:667
LePlane()
Definition: geometry_scalar.h:308
float mat[4][4]
Definition: geometry_scalar.h:348
const LeVertex right
Definition: geometry_scalar.h:666
Represent a plane in 3D space.
Definition: geometry_scalar.h:302
void transpose()
Definition: geometry_scalar.h:385
LeVertex round() const
Definition: geometry_scalar.h:217
void alignBackUp(LeVertex back, LeVertex up)
Definition: geometry_scalar.h:540
LeVertex operator*=(LeVertex v)
Definition: geometry_scalar.h:155
void zero()
Definition: geometry_scalar.h:378