|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
& J. j! k, a9 L C) p' k! J7 n
6 }& g1 z. ^' P/ T. y5 b9 X/ w X: g
* W2 l2 \( h4 k
#include <math.h> 2 W7 j' f; J$ p# V) w6 j; W+ L
//矩阵复制
. w+ P% C. Q2 _void Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])% V) m, S. i- r6 ]9 {! d
{7 c( s% [6 v9 O8 p
int i,j;
5 C( y7 X+ N3 Q5 @: I
" m' `! m% I" [ for(i=0;i<4;i++)
/ M6 _1 e- z. ^- R5 l, K8 n, ` for(j=0;j<4;j++) v8 I6 P' u c6 f6 T5 m5 O
to_mtx[i][j]=from_mtx[i][j];
- Q2 a; e5 h* F, Q) c& t}
& _8 h" E5 z# }& v' A$ }7 w//矩阵初始化
& w0 U3 I$ S1 g1 w$ F: u; ~void Project_Matrix_Identity(double mtx[4][4])
! o- _1 t9 _% i, S7 q0 {{# x8 V" C W' k9 }) ?( d
int i,j;
1 s x% b) |7 [, ] 0 O' Q) z; H) U. L/ K6 b
for(i=0;i<4;i++)
/ e9 `; Y3 Y7 S7 }! L9 j1 |( J for(j=0;j<4;j++)
# ]* k! s( j! z0 N2 K7 u if(i==j)' k) L2 i0 N: T( w5 U/ I
mtx[i][j]=1.0;# `$ d3 C! p2 Z) c! Q+ y0 c
else
7 R$ l. W% g1 Y mtx[i][j]=0.0;
' f, _) F, d- x$ d+ j5 s}6 v/ O/ A5 Z7 H; L$ P( y; K) i4 R5 w
//矩阵相乘% B" h6 T6 }1 N3 v: p
void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])
9 Q& c- t, r1 a6 h1 v: ~/ P{
7 L, P: U |; w# u" N* M9 F: W- W L
int i,j,k;
7 s3 j7 R1 S' J double left[4][4],right[4][4];
`/ s9 Q( p& B8 e+ [( V
/ K+ ?6 g/ U- P2 n% P Project_Matrix_Copy(left_mtx,left);
% T- h X4 _+ u/ K Project_Matrix_Copy(right_mtx,right);. K6 ], N+ y" A7 M) U1 m" b+ D
for(i=0;i<4;i++) p% d3 Q2 D# D' B& F. H+ {2 I) V
for(j=0;j<4;j++)- g+ c4 c; H/ L; |8 r
{3 I4 X4 r9 ^) K) _% j ^. y
get_mtx[i][j]=0.0;, J7 D$ R( G. N/ H( Y
for(k=0;k<4;k++)/ L5 Y x1 s: j, S/ h
get_mtx[i][j]+=left[i][k]*right[k][j];9 _6 A5 ^5 K& V F
}# |/ H8 m1 ~5 B! G2 |
} O- X) B: R( j2 g2 P0 ]! w! `! e
//转置矩阵% M: G5 s; D" I: Q3 g1 g$ i. @
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])
: P' B5 S1 q2 T+ J; E u& w* g{3 |' O7 C' r7 Y2 d# Y. P
int i,j;
0 E+ S e. P$ ^+ I& \' r, p for(i=0;i<4;i++)
5 z2 P& {1 L. p {4 z! \# K B w: i. {' l3 |
for(j=0;j<4;j++). j' u) ~9 Z J; a) O
{
1 t0 `0 b Y3 ^+ [1 X) n, o transpose_mtx[i][j]=mtx[j][i];
$ m2 ^ z- [) t/ X# _+ w }
, O" l9 j' E1 B# X, B }8 V+ G4 B8 ~) ~& C1 L8 G
}
- A9 y% a/ ?, @* i, d/ x//从11元组获取变换矩阵
/ g5 v$ E* Q! L9 r; Q3 Xvoid Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])" E; {/ w; d# T' D; A4 M( g" Z
{+ q4 K. a3 T N; t3 m6 Z6 V
9 P, m7 J; v6 z$ x6 B# n
//Project_Matrix_Get_Rotation(rotation,point,angle,pos);. n" n& P, t% a* m# R! F* Z
int i,j;- D' B0 Y/ Y% M$ n
for(i=0;i<4;i++)
) {% T! }) Q# ?5 ?$ K& P4 c4 t for(j=0;j<4;j++)7 w2 W6 t' T) g- L" [
if(i==j)5 p$ [. Q- _5 G
pos[i][j]=1.0;
: P* _( M- k x5 Y) _% q else6 R! W3 B v0 f3 B
pos[i][j]=0.0;6 a& W: B: V/ X8 t4 P c# x6 R/ W
pos[3][0]+=translation[0];% i& P8 ]) M1 k& T! g/ w6 ~6 ]
pos[3][1]+=translation[1];
* `5 }' K# K& @4 T pos[3][2]+=translation[2];- i/ f B- c1 H7 {1 {
}
: z8 J' Q8 U7 \! }8 m//向量缩放
% |& N% R7 P3 A) H3 H* Tvoid Project_Vector_Scale(double a[3],double scale,double b[3])
% ?+ k: R% m7 }0 ~{# b) k _) n% J- k9 {8 B1 S
b[0]=a[0]*scale;& } H6 L6 f; A& L. @0 f
b[1]=a[1]*scale;
; v- y4 a. s8 o; Q& k$ ^2 a b[2]=a[2]*scale;- w) m' i; ^/ ^- d7 i- ]
}
5 t% |( [, F/ }9 V) t" g) Q
. `; Q" W O) Q |
|