From 6612d1e0a9fa8f4085d0a951ff14c0dcd58e3431 Mon Sep 17 00:00:00 2001 From: blobt Date: Wed, 17 Feb 2021 13:10:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9B=E5=85=83=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vs/3dMath/v15/.suo | Bin 39936 -> 39424 bytes GMath.cpp | 117 ++++++++++++++++++++++++++++++++++++++++++++ GMath.h | 21 +++++++- main.cpp | 13 ++--- 4 files changed, 141 insertions(+), 10 deletions(-) diff --git a/.vs/3dMath/v15/.suo b/.vs/3dMath/v15/.suo index ed7b39461a9173fb34da11887f9e48f94bb6ecd8..89e839a31fa9246176dec8954fd08919367c3d76 100644 GIT binary patch delta 2173 zcmdT_Z){Ul6o2>jb^Wu~b^o_+jBV^+S-a7h`OOOyhSl{ zYXX{}l|YY)5`upgK8Rloy~OYZS%@(UCd#4)6Z~R=n#czusU{^dJ?HJU>oQ0ne)1;2 zckVm)ymRk4zjN-3UgFV<{N!e4zp%y0Sq{|lYTI0N?1SIr8>~W1@*q?4BuQ#P{DT7) zHq=AXEFBIRmHKx0sDqc}qHQHvno^wmjQ4dYd$QK(tMaUOa$kt3K`fr?Z)a8Lt_*&# zZgy=)RX2i;y#vvU2q4hx+l1ZE9gN`{C6Sy`#)Xz2V~IRJ2fy+<%;!%jbWl^41!#`g zYz2=O`W?)J`gCe^zO=$!Fz@j~66Hdq4t(4OT2au!)}y60%Zo_5LR_grO`58u@3(#f z{;JCmEv^wY#pjsPiWWp#`g~?Oz6z;=-bdX%onG3L8}Xq{chtQ$B0l`-M!jWMWKuF~(-pq>FSZnwF4Kfy(Ty;Yn3y<&YW+!aVna z*1XG_E=K*EWOLB0Q=jpzd4jaF?LG7~gplA~W%sJo32jY`#T&a6Drqd+OvXTKye?Bu zEIVupDbz&NIGMas)k}~n2`JQW>7LP(bpjO}j+9>0D_ScH=}Ds&$$Sm?;u5K%0J~4U z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w3G_e1zo75U*QRsAiPxEwTE9(DlCgsMjmkXV#kGtanIhL!vc9+C|K(Fz{=QIbB^n z?cGke6KsZn)>xsnJ7xz)CSIq=QG4s^r}DxpMG6E49p#jCDqG6Tsgd!?j?t+pRoa8T zwOr|8(aL3&ktGjwmTRbhO4)){HdeEOTBR zrsLu2TJ(6BnNqMV%Z0fY z!*G6XUX;G{CugeIx)9<;XXqg^+UE6laIA`%g-LGvImJpHH-5*lA3^4r#NVUuF@;_c z$`qGO5_D)@)zRx}@9s5H8+;BrwJOut?3=I^?6q3&y}e#@&edxfzVe-RKe`N`jFrK$ z& 1.0f) { + return false; + } + + v = w ^ e1; + b = l.v * v / det; + if (b < 0.0f || b > 1.0f) { + return false; + } + + t = e2 * v / det; + p = l(t); + + return true; +} + +GQuater::GQuater(float w, float x, float y, float z) +{ + this->w = w; + this->x = x; + this->y = y; + this->z = z; +} + +GQuater::GQuater(const GQuater & copy) +{ + w = copy.w; + x = copy.x; + y = copy.y; + z = copy.z; +} + +GQuater::GQuater(GVector3 axis, float theta, bool radian) +{ + //q=(cosX, sinX(a,b,c)) + + float rad, sn, cs; + axis.normalize(); + + if (!radian) { + rad = theta * M_PI / 360; //因为旋转的是2倍X,所以这里除以360 + } + + sn = sin(rad); + cs = cos(rad); + + sn = (abs(sn) < PRECISION) ? 0.0f : sn; + cs = (abs(cs) < PRECISION) ? 0.0f : cs; + + w = cs; + x = sn * axis[0]; + y = sn * axis[1]; + z = sn * axis[2]; + +} + +GQuater & GQuater::operator=(const GQuater & rhs) +{ + w = rhs.w; + x = rhs.x; + y = rhs.y; + z = rhs.z; + + return *this; +} + +GQuater & GQuater::operator+=(const GQuater & rhs) +{ + w += rhs.w; + x += rhs.x; + y += rhs.y; + z += rhs.z; + + return *this; +} + +GQuater & GQuater::operator-=(const GQuater & rhs) +{ + w -= rhs.w; + x -= rhs.x; + y -= rhs.y; + z -= rhs.z; + + return *this; +} + +GQuater & GQuater::operator*=(const GQuater & rhs) +{ + float nw, nx, ny, nz = 0; + nw = w * rhs.w - x*rhs.x - y * rhs.y - z * rhs.z; + nx = w * rhs.x + rhs.w*x + y * rhs.z - z * rhs.y; + ny = w * rhs.y + rhs.w*y + z * rhs.x - x * rhs.z; + nz = w * rhs.z + rhs.w*z + x * rhs.y - y * rhs.x; + w = nw; + x = nx; + y = ny; + z = nz; + return *this; +} diff --git a/GMath.h b/GMath.h index 102ed3c..2b0340f 100644 --- a/GMath.h +++ b/GMath.h @@ -13,8 +13,9 @@ #define EQ(X,Y,EPS) (ABS((X)-(Y))