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 484 of file StdMeshMath.cpp.

485 {
486  StdMeshMatrix m;
487 
488  m(0,0) = lhs(0,0)*rhs(0,0) + lhs(0,1)*rhs(1,0) + lhs(0,2)*rhs(2,0);
489  m(1,0) = lhs(1,0)*rhs(0,0) + lhs(1,1)*rhs(1,0) + lhs(1,2)*rhs(2,0);
490  m(2,0) = lhs(2,0)*rhs(0,0) + lhs(2,1)*rhs(1,0) + lhs(2,2)*rhs(2,0);
491 
492  m(0,1) = lhs(0,0)*rhs(0,1) + lhs(0,1)*rhs(1,1) + lhs(0,2)*rhs(2,1);
493  m(1,1) = lhs(1,0)*rhs(0,1) + lhs(1,1)*rhs(1,1) + lhs(1,2)*rhs(2,1);
494  m(2,1) = lhs(2,0)*rhs(0,1) + lhs(2,1)*rhs(1,1) + lhs(2,2)*rhs(2,1);
495 
496  m(0,2) = lhs(0,0)*rhs(0,2) + lhs(0,1)*rhs(1,2) + lhs(0,2)*rhs(2,2);
497  m(1,2) = lhs(1,0)*rhs(0,2) + lhs(1,1)*rhs(1,2) + lhs(1,2)*rhs(2,2);
498  m(2,2) = lhs(2,0)*rhs(0,2) + lhs(2,1)*rhs(1,2) + lhs(2,2)*rhs(2,2);
499 
500  m(0,3) = lhs(0,0)*rhs(0,3) + lhs(0,1)*rhs(1,3) + lhs(0,2)*rhs(2,3) + lhs(0,3);
501  m(1,3) = lhs(1,0)*rhs(0,3) + lhs(1,1)*rhs(1,3) + lhs(1,2)*rhs(2,3) + lhs(1,3);
502  m(2,3) = lhs(2,0)*rhs(0,3) + lhs(2,1)*rhs(1,3) + lhs(2,2)*rhs(2,3) + lhs(2,3);
503 
504  return m;
505 }
StdMeshMatrix operator* ( float  lhs,
const StdMeshMatrix &  rhs 
)

Definition at line 507 of file StdMeshMath.cpp.

508 {
509  StdMeshMatrix m;
510  m(0,0) = lhs * rhs(0,0);
511  m(1,0) = lhs * rhs(1,0);
512  m(2,0) = lhs * rhs(2,0);
513  m(0,1) = lhs * rhs(0,1);
514  m(1,1) = lhs * rhs(1,1);
515  m(2,1) = lhs * rhs(2,1);
516  m(0,2) = lhs * rhs(0,2);
517  m(1,2) = lhs * rhs(1,2);
518  m(2,2) = lhs * rhs(2,2);
519  m(0,3) = lhs * rhs(0,3);
520  m(1,3) = lhs * rhs(1,3);
521  m(2,3) = lhs * rhs(2,3);
522  return m;
523 }
StdMeshMatrix operator* ( const StdMeshMatrix &  lhs,
float  rhs 
)

Definition at line 525 of file StdMeshMath.cpp.

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

Definition at line 554 of file StdMeshMath.cpp.

555 {
556  StdProjectionMatrix m;
557 
558  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);
559  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);
560  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);
561  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);
562 
563  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);
564  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);
565  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);
566  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);
567 
568  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);
569  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);
570  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);
571  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);
572 
573  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);
574  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);
575  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);
576  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);
577 
578  return m;
579 }
StdMeshQuaternion operator* ( const StdMeshQuaternion &  lhs,
const StdMeshQuaternion &  rhs 
)

Definition at line 597 of file StdMeshMath.cpp.

598 {
599  StdMeshQuaternion q;
600  q.w = lhs.w*rhs.w - lhs.x*rhs.x - lhs.y*rhs.y - lhs.z*rhs.z;
601  q.x = lhs.w*rhs.x + lhs.x*rhs.w + lhs.y*rhs.z - lhs.z*rhs.y;
602  q.y = lhs.w*rhs.y + lhs.y*rhs.w + lhs.z*rhs.x - lhs.x*rhs.z;
603  q.z = lhs.w*rhs.z + lhs.z*rhs.w + lhs.x*rhs.y - lhs.y*rhs.x;
604  return q;
605 }
StdMeshQuaternion operator* ( const StdMeshQuaternion &  lhs,
float  rhs 
)

Definition at line 616 of file StdMeshMath.cpp.

617 {
618  StdMeshQuaternion q(lhs);
619  q *= rhs;
620  return q;
621 }
StdMeshQuaternion operator* ( float  lhs,
const StdMeshQuaternion &  rhs 
)

Definition at line 623 of file StdMeshMath.cpp.

624 {
625  return rhs * lhs;
626 }
StdMeshTransformation operator* ( const StdMeshTransformation &  lhs,
const StdMeshTransformation &  rhs 
)

Definition at line 654 of file StdMeshMath.cpp.

655 {
656  StdMeshTransformation t;
657  t.rotate = lhs.rotate * rhs.rotate;
658  t.scale = lhs.scale * rhs.scale;
659  t.translate = lhs.translate + lhs.rotate * (lhs.scale * rhs.translate);
660  return t;
661 }
StdMeshVector operator* ( const StdMeshVector lhs,
const StdMeshVector rhs 
)

Definition at line 702 of file StdMeshMath.cpp.

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

703 {
704  StdMeshVector v;
705  v.x = lhs.x * rhs.x;
706  v.y = lhs.y * rhs.y;
707  v.z = lhs.z * rhs.z;
708  return v;
709 }
StdMeshVector operator* ( const StdMeshVector lhs,
float  rhs 
)

Definition at line 719 of file StdMeshMath.cpp.

720 {
721  StdMeshVector v(lhs);
722  v *= rhs;
723  return v;
724 }
StdMeshVector operator* ( float  lhs,
const StdMeshVector rhs 
)

Definition at line 726 of file StdMeshMath.cpp.

727 {
728  return rhs * lhs;
729 }
StdMeshVector operator* ( const StdMeshMatrix &  lhs,
const StdMeshVector rhs 
)

Definition at line 758 of file StdMeshMath.cpp.

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

759 {
760  StdMeshVector v;
761  v.x = lhs(0,0)*rhs.x + lhs(0,1)*rhs.y + lhs(0,2)*rhs.z;
762  v.y = lhs(1,0)*rhs.x + lhs(1,1)*rhs.y + lhs(1,2)*rhs.z;
763  v.z = lhs(2,0)*rhs.x + lhs(2,1)*rhs.y + lhs(2,2)*rhs.z;
764  return v;
765 }
StdMeshVector operator* ( const StdMeshQuaternion &  lhs,
const StdMeshVector rhs 
)

Definition at line 767 of file StdMeshMath.cpp.

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

768 {
769  StdMeshVector v = { lhs.x, lhs.y, lhs.z };
770  StdMeshVector uv = 2.0f * StdMeshVector::Cross(v, rhs);
771  StdMeshVector uuv = StdMeshVector::Cross(v, uv);
772  return rhs + lhs.w * uv + uuv;
773 }
static StdMeshVector Cross(const StdMeshVector &lhs, const StdMeshVector &rhs)
Definition: StdMeshMath.cpp:53

Here is the call graph for this function:

StdMeshVertex operator* ( float  lhs,
const StdMeshVertex rhs 
)

Definition at line 793 of file StdMeshMath.cpp.

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

794 {
795  StdMeshVertex vtx;
796  vtx.nx = lhs*rhs.nx;
797  vtx.ny = lhs*rhs.ny;
798  vtx.nz = lhs*rhs.nz;
799  vtx.x = lhs*rhs.x;
800  vtx.y = lhs*rhs.y;
801  vtx.z = lhs*rhs.z;
802  return vtx;
803 }
StdMeshVertex operator* ( const StdMeshVertex lhs,
float  rhs 
)

Definition at line 805 of file StdMeshMath.cpp.

806 {
807  return rhs * lhs;
808 }
StdMeshVertex operator* ( const StdMeshMatrix &  lhs,
const StdMeshVertex rhs 
)

Definition at line 810 of file StdMeshMath.cpp.

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

811 {
812  StdMeshVertex vtx;
813  vtx.nx = lhs(0,0)*rhs.nx + lhs(0,1)*rhs.ny + lhs(0,2)*rhs.nz;
814  vtx.ny = lhs(1,0)*rhs.nx + lhs(1,1)*rhs.ny + lhs(0,2)*rhs.nz;
815  vtx.nz = lhs(2,0)*rhs.nx + lhs(2,1)*rhs.ny + lhs(2,2)*rhs.nz;
816  vtx.x = lhs(0,0)*rhs.x + lhs(0,1)*rhs.y + lhs(0,2)*rhs.z + lhs(0,3);
817  vtx.y = lhs(1,0)*rhs.x + lhs(1,1)*rhs.y + lhs(1,2)*rhs.z + lhs(1,3);
818  vtx.z = lhs(2,0)*rhs.x + lhs(2,1)*rhs.y + lhs(2,2)*rhs.z + lhs(2,3);
819  vtx.u = rhs.u; vtx.v = rhs.v;
820  return vtx;
821 }
StdMeshMatrix& operator*= ( StdMeshMatrix &  lhs,
const StdMeshMatrix &  rhs 
)

Definition at line 530 of file StdMeshMath.cpp.

531 {
532  lhs = lhs * rhs;
533  return lhs;
534 }
StdProjectionMatrix& operator*= ( StdProjectionMatrix &  lhs,
const StdProjectionMatrix &  rhs 
)

Definition at line 581 of file StdMeshMath.cpp.

582 {
583  lhs = lhs * rhs;
584  return lhs;
585 }
StdMeshQuaternion& operator*= ( StdMeshQuaternion &  lhs,
float  rhs 
)

Definition at line 607 of file StdMeshMath.cpp.

608 {
609  lhs.w *= rhs;
610  lhs.x *= rhs;
611  lhs.y *= rhs;
612  lhs.z *= rhs;
613  return lhs;
614 }
StdMeshVector& operator*= ( StdMeshVector lhs,
float  rhs 
)

Definition at line 711 of file StdMeshMath.cpp.

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

712 {
713  lhs.x *= rhs;
714  lhs.y *= rhs;
715  lhs.z *= rhs;
716  return lhs;
717 }
StdMeshMatrix operator+ ( const StdMeshMatrix &  lhs,
const StdMeshMatrix &  rhs 
)

Definition at line 536 of file StdMeshMath.cpp.

537 {
538  StdMeshMatrix m;
539  m(0,0) = lhs(0,0) + rhs(0,0);
540  m(1,0) = lhs(1,0) + rhs(1,0);
541  m(2,0) = lhs(2,0) + rhs(2,0);
542  m(0,1) = lhs(0,1) + rhs(0,1);
543  m(1,1) = lhs(1,1) + rhs(1,1);
544  m(2,1) = lhs(2,1) + rhs(2,1);
545  m(0,2) = lhs(0,2) + rhs(0,2);
546  m(1,2) = lhs(1,2) + rhs(1,2);
547  m(2,2) = lhs(2,2) + rhs(2,2);
548  m(0,3) = lhs(0,3) + rhs(0,3);
549  m(1,3) = lhs(1,3) + rhs(1,3);
550  m(2,3) = lhs(2,3) + rhs(2,3);
551  return m;
552 }
StdMeshQuaternion operator+ ( const StdMeshQuaternion &  lhs,
const StdMeshQuaternion &  rhs 
)

Definition at line 637 of file StdMeshMath.cpp.

638 {
639  StdMeshQuaternion q(lhs);
640  q += rhs;
641  return q;
642 }
StdMeshVector operator+ ( const StdMeshVector lhs,
const StdMeshVector rhs 
)

Definition at line 680 of file StdMeshMath.cpp.

681 {
682  StdMeshVector v(lhs);
683  v += rhs;
684  return v;
685 }
StdMeshVertex operator+ ( const StdMeshVertex lhs,
const StdMeshVertex rhs 
)

Definition at line 786 of file StdMeshMath.cpp.

787 {
788  StdMeshVertex vtx(lhs);
789  vtx += rhs;
790  return vtx;
791 }
StdMeshQuaternion& operator+= ( StdMeshQuaternion &  lhs,
const StdMeshQuaternion &  rhs 
)

Definition at line 628 of file StdMeshMath.cpp.

629 {
630  lhs.w += rhs.w;
631  lhs.x += rhs.x;
632  lhs.y += rhs.y;
633  lhs.z += rhs.z;
634  return lhs;
635 }
StdMeshVector& operator+= ( StdMeshVector lhs,
const StdMeshVector rhs 
)

Definition at line 672 of file StdMeshMath.cpp.

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

673 {
674  lhs.x += rhs.x;
675  lhs.y += rhs.y;
676  lhs.z += rhs.z;
677  return lhs;
678 }
StdMeshVertex& operator+= ( StdMeshVertex lhs,
const StdMeshVertex rhs 
)

Definition at line 775 of file StdMeshMath.cpp.

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

776 {
777  lhs.nx += rhs.nx;
778  lhs.ny += rhs.ny;
779  lhs.nz += rhs.nz;
780  lhs.x += rhs.x;
781  lhs.y += rhs.y;
782  lhs.z += rhs.z;
783  return lhs;
784 }
StdMeshQuaternion operator- ( const StdMeshQuaternion &  rhs)

Definition at line 587 of file StdMeshMath.cpp.

588 {
589  StdMeshQuaternion q;
590  q.w = -rhs.w;
591  q.x = -rhs.x;
592  q.y = -rhs.y;
593  q.z = -rhs.z;
594  return q;
595 }
StdMeshQuaternion operator- ( const StdMeshQuaternion &  lhs,
const StdMeshQuaternion &  rhs 
)

Definition at line 644 of file StdMeshMath.cpp.

645 {
646  StdMeshQuaternion q;
647  q.w = lhs.w - rhs.w;
648  q.x = lhs.x - rhs.x;
649  q.y = lhs.y - rhs.y;
650  q.z = lhs.z - rhs.z;
651  return q;
652 }
StdMeshVector operator- ( const StdMeshVector rhs)

Definition at line 663 of file StdMeshMath.cpp.

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

664 {
665  StdMeshVector v;
666  v.x = -rhs.x;
667  v.y = -rhs.y;
668  v.z = -rhs.z;
669  return v;
670 }
StdMeshVector operator- ( const StdMeshVector lhs,
const StdMeshVector rhs 
)

Definition at line 695 of file StdMeshMath.cpp.

696 {
697  StdMeshVector v(lhs);
698  v -= rhs;
699  return v;
700 }
StdMeshVector& operator-= ( StdMeshVector lhs,
const StdMeshVector rhs 
)

Definition at line 687 of file StdMeshMath.cpp.

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

688 {
689  lhs.x -= rhs.x;
690  lhs.y -= rhs.y;
691  lhs.z -= rhs.z;
692  return lhs;
693 }
StdMeshVector operator/ ( const StdMeshVector lhs,
const StdMeshVector rhs 
)

Definition at line 731 of file StdMeshMath.cpp.

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

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

Definition at line 740 of file StdMeshMath.cpp.

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

741 {
742  StdMeshVector v;
743  v.x = lhs/rhs.x;
744  v.y = lhs/rhs.y;
745  v.z = lhs/rhs.z;
746  return v;
747 }
StdMeshVector operator/ ( const StdMeshVector lhs,
float  rhs 
)

Definition at line 749 of file StdMeshMath.cpp.

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

750 {
751  StdMeshVector v;
752  v.x = lhs.x/rhs;
753  v.y = lhs.y/rhs;
754  v.z = lhs.z/rhs;
755  return v;
756 }