OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
StdMeshMath.cpp File Reference
#include "C4Include.h"
#include "lib/StdMeshMath.h"
Include dependency graph for StdMeshMath.cpp:

Go to the source code of this file.

Functions

StdMeshMatrix operator* (const StdMeshMatrix &lhs, const StdMeshMatrix &rhs)
 
StdMeshMatrix operator* (float lhs, const StdMeshMatrix &rhs)
 
StdMeshMatrix operator* (const StdMeshMatrix &lhs, float rhs)
 
StdMeshMatrix & operator*= (StdMeshMatrix &lhs, const StdMeshMatrix &rhs)
 
StdMeshMatrix operator+ (const StdMeshMatrix &lhs, const StdMeshMatrix &rhs)
 
StdProjectionMatrix operator* (const StdProjectionMatrix &lhs, const StdProjectionMatrix &rhs)
 
StdProjectionMatrix & operator*= (StdProjectionMatrix &lhs, const StdProjectionMatrix &rhs)
 
StdMeshQuaternion operator- (const StdMeshQuaternion &rhs)
 
StdMeshQuaternion operator* (const StdMeshQuaternion &lhs, const StdMeshQuaternion &rhs)
 
StdMeshQuaternion & operator*= (StdMeshQuaternion &lhs, float rhs)
 
StdMeshQuaternion operator* (const StdMeshQuaternion &lhs, float rhs)
 
StdMeshQuaternion operator* (float lhs, const StdMeshQuaternion &rhs)
 
StdMeshQuaternion & operator+= (StdMeshQuaternion &lhs, const StdMeshQuaternion &rhs)
 
StdMeshQuaternion operator+ (const StdMeshQuaternion &lhs, const StdMeshQuaternion &rhs)
 
StdMeshQuaternion operator- (const StdMeshQuaternion &lhs, const StdMeshQuaternion &rhs)
 
StdMeshTransformation operator* (const StdMeshTransformation &lhs, const StdMeshTransformation &rhs)
 
StdMeshVector operator- (const StdMeshVector &rhs)
 
StdMeshVectoroperator+= (StdMeshVector &lhs, const StdMeshVector &rhs)
 
StdMeshVector operator+ (const StdMeshVector &lhs, const StdMeshVector &rhs)
 
StdMeshVectoroperator-= (StdMeshVector &lhs, const StdMeshVector &rhs)
 
StdMeshVector operator- (const StdMeshVector &lhs, const StdMeshVector &rhs)
 
StdMeshVector operator* (const StdMeshVector &lhs, const StdMeshVector &rhs)
 
StdMeshVectoroperator*= (StdMeshVector &lhs, float rhs)
 
StdMeshVector operator* (const StdMeshVector &lhs, float rhs)
 
StdMeshVector operator* (float lhs, const StdMeshVector &rhs)
 
StdMeshVector operator/ (const StdMeshVector &lhs, const StdMeshVector &rhs)
 
StdMeshVector operator/ (float lhs, const StdMeshVector &rhs)
 
StdMeshVector operator/ (const StdMeshVector &lhs, float rhs)
 
StdMeshVector operator* (const StdMeshMatrix &lhs, const StdMeshVector &rhs)
 
StdMeshVector operator* (const StdMeshQuaternion &lhs, const StdMeshVector &rhs)
 
StdMeshVertexoperator+= (StdMeshVertex &lhs, const StdMeshVertex &rhs)
 
StdMeshVertex operator+ (const StdMeshVertex &lhs, const StdMeshVertex &rhs)
 
StdMeshVertex operator* (float lhs, const StdMeshVertex &rhs)
 
StdMeshVertex operator* (const StdMeshVertex &lhs, float rhs)
 
StdMeshVertex operator* (const StdMeshMatrix &lhs, const StdMeshVertex &rhs)
 

Function Documentation

StdMeshMatrix operator* ( const StdMeshMatrix &  lhs,
const StdMeshMatrix &  rhs 
)

Definition at line 478 of file StdMeshMath.cpp.

479 {
480  StdMeshMatrix m;
481 
482  m(0,0) = lhs(0,0)*rhs(0,0) + lhs(0,1)*rhs(1,0) + lhs(0,2)*rhs(2,0);
483  m(1,0) = lhs(1,0)*rhs(0,0) + lhs(1,1)*rhs(1,0) + lhs(1,2)*rhs(2,0);
484  m(2,0) = lhs(2,0)*rhs(0,0) + lhs(2,1)*rhs(1,0) + lhs(2,2)*rhs(2,0);
485 
486  m(0,1) = lhs(0,0)*rhs(0,1) + lhs(0,1)*rhs(1,1) + lhs(0,2)*rhs(2,1);
487  m(1,1) = lhs(1,0)*rhs(0,1) + lhs(1,1)*rhs(1,1) + lhs(1,2)*rhs(2,1);
488  m(2,1) = lhs(2,0)*rhs(0,1) + lhs(2,1)*rhs(1,1) + lhs(2,2)*rhs(2,1);
489 
490  m(0,2) = lhs(0,0)*rhs(0,2) + lhs(0,1)*rhs(1,2) + lhs(0,2)*rhs(2,2);
491  m(1,2) = lhs(1,0)*rhs(0,2) + lhs(1,1)*rhs(1,2) + lhs(1,2)*rhs(2,2);
492  m(2,2) = lhs(2,0)*rhs(0,2) + lhs(2,1)*rhs(1,2) + lhs(2,2)*rhs(2,2);
493 
494  m(0,3) = lhs(0,0)*rhs(0,3) + lhs(0,1)*rhs(1,3) + lhs(0,2)*rhs(2,3) + lhs(0,3);
495  m(1,3) = lhs(1,0)*rhs(0,3) + lhs(1,1)*rhs(1,3) + lhs(1,2)*rhs(2,3) + lhs(1,3);
496  m(2,3) = lhs(2,0)*rhs(0,3) + lhs(2,1)*rhs(1,3) + lhs(2,2)*rhs(2,3) + lhs(2,3);
497 
498  return m;
499 }
StdMeshMatrix operator* ( float  lhs,
const StdMeshMatrix &  rhs 
)

Definition at line 501 of file StdMeshMath.cpp.

502 {
503  StdMeshMatrix m;
504  m(0,0) = lhs * rhs(0,0);
505  m(1,0) = lhs * rhs(1,0);
506  m(2,0) = lhs * rhs(2,0);
507  m(0,1) = lhs * rhs(0,1);
508  m(1,1) = lhs * rhs(1,1);
509  m(2,1) = lhs * rhs(2,1);
510  m(0,2) = lhs * rhs(0,2);
511  m(1,2) = lhs * rhs(1,2);
512  m(2,2) = lhs * rhs(2,2);
513  m(0,3) = lhs * rhs(0,3);
514  m(1,3) = lhs * rhs(1,3);
515  m(2,3) = lhs * rhs(2,3);
516  return m;
517 }
StdMeshMatrix operator* ( const StdMeshMatrix &  lhs,
float  rhs 
)

Definition at line 519 of file StdMeshMath.cpp.

520 {
521  return rhs * lhs;
522 }
StdProjectionMatrix operator* ( const StdProjectionMatrix &  lhs,
const StdProjectionMatrix &  rhs 
)

Definition at line 548 of file StdMeshMath.cpp.

549 {
550  StdProjectionMatrix m;
551 
552  m(0,0) = lhs(0,0)*rhs(0,0) + lhs(0,1)*rhs(1,0) + lhs(0,2)*rhs(2,0) + lhs(0,3)*rhs(3,0);
553  m(1,0) = lhs(1,0)*rhs(0,0) + lhs(1,1)*rhs(1,0) + lhs(1,2)*rhs(2,0) + lhs(1,3)*rhs(3,0);
554  m(2,0) = lhs(2,0)*rhs(0,0) + lhs(2,1)*rhs(1,0) + lhs(2,2)*rhs(2,0) + lhs(2,3)*rhs(3,0);
555  m(3,0) = lhs(3,0)*rhs(0,0) + lhs(3,1)*rhs(1,0) + lhs(3,2)*rhs(2,0) + lhs(3,3)*rhs(3,0);
556 
557  m(0,1) = lhs(0,0)*rhs(0,1) + lhs(0,1)*rhs(1,1) + lhs(0,2)*rhs(2,1) + lhs(0,3)*rhs(3,1);
558  m(1,1) = lhs(1,0)*rhs(0,1) + lhs(1,1)*rhs(1,1) + lhs(1,2)*rhs(2,1) + lhs(1,3)*rhs(3,1);
559  m(2,1) = lhs(2,0)*rhs(0,1) + lhs(2,1)*rhs(1,1) + lhs(2,2)*rhs(2,1) + lhs(2,3)*rhs(3,1);
560  m(3,1) = lhs(3,0)*rhs(0,1) + lhs(3,1)*rhs(1,1) + lhs(3,2)*rhs(2,1) + lhs(3,3)*rhs(3,1);
561 
562  m(0,2) = lhs(0,0)*rhs(0,2) + lhs(0,1)*rhs(1,2) + lhs(0,2)*rhs(2,2) + lhs(0,3)*rhs(3,2);
563  m(1,2) = lhs(1,0)*rhs(0,2) + lhs(1,1)*rhs(1,2) + lhs(1,2)*rhs(2,2) + lhs(1,3)*rhs(3,2);
564  m(2,2) = lhs(2,0)*rhs(0,2) + lhs(2,1)*rhs(1,2) + lhs(2,2)*rhs(2,2) + lhs(2,3)*rhs(3,2);
565  m(3,2) = lhs(3,0)*rhs(0,2) + lhs(3,1)*rhs(1,2) + lhs(3,2)*rhs(2,2) + lhs(3,3)*rhs(3,2);
566 
567  m(0,3) = lhs(0,0)*rhs(0,3) + lhs(0,1)*rhs(1,3) + lhs(0,2)*rhs(2,3) + lhs(0,3)*rhs(3,3);
568  m(1,3) = lhs(1,0)*rhs(0,3) + lhs(1,1)*rhs(1,3) + lhs(1,2)*rhs(2,3) + lhs(1,3)*rhs(3,3);
569  m(2,3) = lhs(2,0)*rhs(0,3) + lhs(2,1)*rhs(1,3) + lhs(2,2)*rhs(2,3) + lhs(2,3)*rhs(3,3);
570  m(3,3) = lhs(3,0)*rhs(0,3) + lhs(3,1)*rhs(1,3) + lhs(3,2)*rhs(2,3) + lhs(3,3)*rhs(3,3);
571 
572  return m;
573 }
StdMeshQuaternion operator* ( const StdMeshQuaternion &  lhs,
const StdMeshQuaternion &  rhs 
)

Definition at line 591 of file StdMeshMath.cpp.

592 {
593  StdMeshQuaternion q;
594  q.w = lhs.w*rhs.w - lhs.x*rhs.x - lhs.y*rhs.y - lhs.z*rhs.z;
595  q.x = lhs.w*rhs.x + lhs.x*rhs.w + lhs.y*rhs.z - lhs.z*rhs.y;
596  q.y = lhs.w*rhs.y + lhs.y*rhs.w + lhs.z*rhs.x - lhs.x*rhs.z;
597  q.z = lhs.w*rhs.z + lhs.z*rhs.w + lhs.x*rhs.y - lhs.y*rhs.x;
598  return q;
599 }
StdMeshQuaternion operator* ( const StdMeshQuaternion &  lhs,
float  rhs 
)

Definition at line 610 of file StdMeshMath.cpp.

611 {
612  StdMeshQuaternion q(lhs);
613  q *= rhs;
614  return q;
615 }
StdMeshQuaternion operator* ( float  lhs,
const StdMeshQuaternion &  rhs 
)

Definition at line 617 of file StdMeshMath.cpp.

618 {
619  return rhs * lhs;
620 }
StdMeshTransformation operator* ( const StdMeshTransformation &  lhs,
const StdMeshTransformation &  rhs 
)

Definition at line 648 of file StdMeshMath.cpp.

649 {
650  StdMeshTransformation t;
651  t.rotate = lhs.rotate * rhs.rotate;
652  t.scale = lhs.scale * rhs.scale;
653  t.translate = lhs.translate + lhs.rotate * (lhs.scale * rhs.translate);
654  return t;
655 }
StdMeshVector operator* ( const StdMeshVector lhs,
const StdMeshVector rhs 
)

Definition at line 696 of file StdMeshMath.cpp.

References StdMeshVector::x, StdMeshVector::y, and StdMeshVector::z.

697 {
698  StdMeshVector v;
699  v.x = lhs.x * rhs.x;
700  v.y = lhs.y * rhs.y;
701  v.z = lhs.z * rhs.z;
702  return v;
703 }
StdMeshVector operator* ( const StdMeshVector lhs,
float  rhs 
)

Definition at line 713 of file StdMeshMath.cpp.

714 {
715  StdMeshVector v(lhs);
716  v *= rhs;
717  return v;
718 }
StdMeshVector operator* ( float  lhs,
const StdMeshVector rhs 
)

Definition at line 720 of file StdMeshMath.cpp.

721 {
722  return rhs * lhs;
723 }
StdMeshVector operator* ( const StdMeshMatrix &  lhs,
const StdMeshVector rhs 
)

Definition at line 752 of file StdMeshMath.cpp.

References StdMeshVector::x, StdMeshVector::y, and StdMeshVector::z.

753 {
754  StdMeshVector v;
755  v.x = lhs(0,0)*rhs.x + lhs(0,1)*rhs.y + lhs(0,2)*rhs.z;
756  v.y = lhs(1,0)*rhs.x + lhs(1,1)*rhs.y + lhs(1,2)*rhs.z;
757  v.z = lhs(2,0)*rhs.x + lhs(2,1)*rhs.y + lhs(2,2)*rhs.z;
758  return v;
759 }
StdMeshVector operator* ( const StdMeshQuaternion &  lhs,
const StdMeshVector rhs 
)

Definition at line 761 of file StdMeshMath.cpp.

References StdMeshVector::Cross(), and StdMeshVector::x.

762 {
763  StdMeshVector v = { lhs.x, lhs.y, lhs.z };
764  StdMeshVector uv = 2.0f * StdMeshVector::Cross(v, rhs);
765  StdMeshVector uuv = StdMeshVector::Cross(v, uv);
766  return rhs + lhs.w * uv + uuv;
767 }
static StdMeshVector Cross(const StdMeshVector &lhs, const StdMeshVector &rhs)
Definition: StdMeshMath.cpp:47

Here is the call graph for this function:

StdMeshVertex operator* ( float  lhs,
const StdMeshVertex rhs 
)

Definition at line 787 of file StdMeshMath.cpp.

References StdMeshVertex::nx, StdMeshVertex::ny, StdMeshVertex::nz, StdMeshVertex::x, StdMeshVertex::y, and StdMeshVertex::z.

788 {
789  StdMeshVertex vtx;
790  vtx.nx = lhs*rhs.nx;
791  vtx.ny = lhs*rhs.ny;
792  vtx.nz = lhs*rhs.nz;
793  vtx.x = lhs*rhs.x;
794  vtx.y = lhs*rhs.y;
795  vtx.z = lhs*rhs.z;
796  return vtx;
797 }
StdMeshVertex operator* ( const StdMeshVertex lhs,
float  rhs 
)

Definition at line 799 of file StdMeshMath.cpp.

800 {
801  return rhs * lhs;
802 }
StdMeshVertex operator* ( const StdMeshMatrix &  lhs,
const StdMeshVertex rhs 
)

Definition at line 804 of file StdMeshMath.cpp.

References StdMeshVertex::nx, StdMeshVertex::ny, StdMeshVertex::nz, StdMeshVertex::u, StdMeshVertex::v, StdMeshVertex::x, StdMeshVertex::y, and StdMeshVertex::z.

805 {
806  StdMeshVertex vtx;
807  vtx.nx = lhs(0,0)*rhs.nx + lhs(0,1)*rhs.ny + lhs(0,2)*rhs.nz;
808  vtx.ny = lhs(1,0)*rhs.nx + lhs(1,1)*rhs.ny + lhs(0,2)*rhs.nz;
809  vtx.nz = lhs(2,0)*rhs.nx + lhs(2,1)*rhs.ny + lhs(2,2)*rhs.nz;
810  vtx.x = lhs(0,0)*rhs.x + lhs(0,1)*rhs.y + lhs(0,2)*rhs.z + lhs(0,3);
811  vtx.y = lhs(1,0)*rhs.x + lhs(1,1)*rhs.y + lhs(1,2)*rhs.z + lhs(1,3);
812  vtx.z = lhs(2,0)*rhs.x + lhs(2,1)*rhs.y + lhs(2,2)*rhs.z + lhs(2,3);
813  vtx.u = rhs.u; vtx.v = rhs.v;
814  return vtx;
815 }
StdMeshMatrix& operator*= ( StdMeshMatrix &  lhs,
const StdMeshMatrix &  rhs 
)

Definition at line 524 of file StdMeshMath.cpp.

525 {
526  lhs = lhs * rhs;
527  return lhs;
528 }
StdProjectionMatrix& operator*= ( StdProjectionMatrix &  lhs,
const StdProjectionMatrix &  rhs 
)

Definition at line 575 of file StdMeshMath.cpp.

576 {
577  lhs = lhs * rhs;
578  return lhs;
579 }
StdMeshQuaternion& operator*= ( StdMeshQuaternion &  lhs,
float  rhs 
)

Definition at line 601 of file StdMeshMath.cpp.

602 {
603  lhs.w *= rhs;
604  lhs.x *= rhs;
605  lhs.y *= rhs;
606  lhs.z *= rhs;
607  return lhs;
608 }
StdMeshVector& operator*= ( StdMeshVector lhs,
float  rhs 
)

Definition at line 705 of file StdMeshMath.cpp.

References StdMeshVector::x, StdMeshVector::y, and StdMeshVector::z.

706 {
707  lhs.x *= rhs;
708  lhs.y *= rhs;
709  lhs.z *= rhs;
710  return lhs;
711 }
StdMeshMatrix operator+ ( const StdMeshMatrix &  lhs,
const StdMeshMatrix &  rhs 
)

Definition at line 530 of file StdMeshMath.cpp.

531 {
532  StdMeshMatrix m;
533  m(0,0) = lhs(0,0) + rhs(0,0);
534  m(1,0) = lhs(1,0) + rhs(1,0);
535  m(2,0) = lhs(2,0) + rhs(2,0);
536  m(0,1) = lhs(0,1) + rhs(0,1);
537  m(1,1) = lhs(1,1) + rhs(1,1);
538  m(2,1) = lhs(2,1) + rhs(2,1);
539  m(0,2) = lhs(0,2) + rhs(0,2);
540  m(1,2) = lhs(1,2) + rhs(1,2);
541  m(2,2) = lhs(2,2) + rhs(2,2);
542  m(0,3) = lhs(0,3) + rhs(0,3);
543  m(1,3) = lhs(1,3) + rhs(1,3);
544  m(2,3) = lhs(2,3) + rhs(2,3);
545  return m;
546 }
StdMeshQuaternion operator+ ( const StdMeshQuaternion &  lhs,
const StdMeshQuaternion &  rhs 
)

Definition at line 631 of file StdMeshMath.cpp.

632 {
633  StdMeshQuaternion q(lhs);
634  q += rhs;
635  return q;
636 }
StdMeshVector operator+ ( const StdMeshVector lhs,
const StdMeshVector rhs 
)

Definition at line 674 of file StdMeshMath.cpp.

675 {
676  StdMeshVector v(lhs);
677  v += rhs;
678  return v;
679 }
StdMeshVertex operator+ ( const StdMeshVertex lhs,
const StdMeshVertex rhs 
)

Definition at line 780 of file StdMeshMath.cpp.

781 {
782  StdMeshVertex vtx(lhs);
783  vtx += rhs;
784  return vtx;
785 }
StdMeshQuaternion& operator+= ( StdMeshQuaternion &  lhs,
const StdMeshQuaternion &  rhs 
)

Definition at line 622 of file StdMeshMath.cpp.

623 {
624  lhs.w += rhs.w;
625  lhs.x += rhs.x;
626  lhs.y += rhs.y;
627  lhs.z += rhs.z;
628  return lhs;
629 }
StdMeshVector& operator+= ( StdMeshVector lhs,
const StdMeshVector rhs 
)

Definition at line 666 of file StdMeshMath.cpp.

References StdMeshVector::x, StdMeshVector::y, and StdMeshVector::z.

667 {
668  lhs.x += rhs.x;
669  lhs.y += rhs.y;
670  lhs.z += rhs.z;
671  return lhs;
672 }
StdMeshVertex& operator+= ( StdMeshVertex lhs,
const StdMeshVertex rhs 
)

Definition at line 769 of file StdMeshMath.cpp.

References StdMeshVertex::nx, StdMeshVertex::ny, StdMeshVertex::nz, StdMeshVertex::x, StdMeshVertex::y, and StdMeshVertex::z.

770 {
771  lhs.nx += rhs.nx;
772  lhs.ny += rhs.ny;
773  lhs.nz += rhs.nz;
774  lhs.x += rhs.x;
775  lhs.y += rhs.y;
776  lhs.z += rhs.z;
777  return lhs;
778 }
StdMeshQuaternion operator- ( const StdMeshQuaternion &  rhs)

Definition at line 581 of file StdMeshMath.cpp.

582 {
583  StdMeshQuaternion q;
584  q.w = -rhs.w;
585  q.x = -rhs.x;
586  q.y = -rhs.y;
587  q.z = -rhs.z;
588  return q;
589 }
StdMeshQuaternion operator- ( const StdMeshQuaternion &  lhs,
const StdMeshQuaternion &  rhs 
)

Definition at line 638 of file StdMeshMath.cpp.

639 {
640  StdMeshQuaternion q;
641  q.w = lhs.w - rhs.w;
642  q.x = lhs.x - rhs.x;
643  q.y = lhs.y - rhs.y;
644  q.z = lhs.z - rhs.z;
645  return q;
646 }
StdMeshVector operator- ( const StdMeshVector rhs)

Definition at line 657 of file StdMeshMath.cpp.

References StdMeshVector::x, StdMeshVector::y, and StdMeshVector::z.

658 {
659  StdMeshVector v;
660  v.x = -rhs.x;
661  v.y = -rhs.y;
662  v.z = -rhs.z;
663  return v;
664 }
StdMeshVector operator- ( const StdMeshVector lhs,
const StdMeshVector rhs 
)

Definition at line 689 of file StdMeshMath.cpp.

690 {
691  StdMeshVector v(lhs);
692  v -= rhs;
693  return v;
694 }
StdMeshVector& operator-= ( StdMeshVector lhs,
const StdMeshVector rhs 
)

Definition at line 681 of file StdMeshMath.cpp.

References StdMeshVector::x, StdMeshVector::y, and StdMeshVector::z.

682 {
683  lhs.x -= rhs.x;
684  lhs.y -= rhs.y;
685  lhs.z -= rhs.z;
686  return lhs;
687 }
StdMeshVector operator/ ( const StdMeshVector lhs,
const StdMeshVector rhs 
)

Definition at line 725 of file StdMeshMath.cpp.

References StdMeshVector::x, StdMeshVector::y, and StdMeshVector::z.

726 {
727  StdMeshVector v;
728  v.x = lhs.x/rhs.x;
729  v.y = lhs.y/rhs.y;
730  v.z = lhs.z/rhs.z;
731  return v;
732 }
StdMeshVector operator/ ( float  lhs,
const StdMeshVector rhs 
)

Definition at line 734 of file StdMeshMath.cpp.

References StdMeshVector::x, StdMeshVector::y, and StdMeshVector::z.

735 {
736  StdMeshVector v;
737  v.x = lhs/rhs.x;
738  v.y = lhs/rhs.y;
739  v.z = lhs/rhs.z;
740  return v;
741 }
StdMeshVector operator/ ( const StdMeshVector lhs,
float  rhs 
)

Definition at line 743 of file StdMeshMath.cpp.

References StdMeshVector::x, StdMeshVector::y, and StdMeshVector::z.

744 {
745  StdMeshVector v;
746  v.x = lhs.x/rhs;
747  v.y = lhs.y/rhs;
748  v.z = lhs.z/rhs;
749  return v;
750 }