From ebf849765839d8a93e0274728c7c3d47b23dc7e0 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Mon, 16 Apr 2018 20:41:30 +0200 Subject: [PATCH 01/84] Adding sprites --- Engine/Engine.vcxproj | 12 ++++++------ Engine/sprite/Circle.png | Bin 0 -> 1100 bytes Engine/sprite/Circle_1.png | Bin 0 -> 1051 bytes Engine/sprite/Circle_2.png | Bin 0 -> 1115 bytes Engine/sprite/Ellipse.png | Bin 0 -> 602 bytes Engine/sprite/Ellipse_1.png | Bin 0 -> 828 bytes Engine/sprite/Ellipse_2.png | Bin 0 -> 597 bytes Engine/sprite/select.png | Bin 0 -> 696 bytes Engine/sprite/select_1.png | Bin 0 -> 875 bytes Engine/sprite/select_2.png | Bin 0 -> 696 bytes 10 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 Engine/sprite/Circle.png create mode 100644 Engine/sprite/Circle_1.png create mode 100644 Engine/sprite/Circle_2.png create mode 100644 Engine/sprite/Ellipse.png create mode 100644 Engine/sprite/Ellipse_1.png create mode 100644 Engine/sprite/Ellipse_2.png create mode 100644 Engine/sprite/select.png create mode 100644 Engine/sprite/select_1.png create mode 100644 Engine/sprite/select_2.png diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index c6e66c51..6e656998 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -21,32 +21,32 @@ {FFCA512B-49FC-4FC8-8A73-C4F87D322FF2} Engine - 8.1 + 10.0.16299.0 Application true - v140 + v141 Unicode Application false - v140 + v141 true Unicode Application true - v140 + v141 Unicode Application false - v140 + v141 true Unicode diff --git a/Engine/sprite/Circle.png b/Engine/sprite/Circle.png new file mode 100644 index 0000000000000000000000000000000000000000..2b7b4afdd259e1e03abba6784fabb23a45cb3c48 GIT binary patch literal 1100 zcmV-S1he~zP)N2bZe?^J zG%heMF*7s+TY3Nh1IbB5K~zXfy;jLm6HyekV8NbJ*Q}`0&r$Y*egG=U?5qTEDgtgD zaG|0*ElbNPMMJ{mKoSU`D1(5JKsxD8I#YKa?|pPI&@Z5tda6#k`}ON{-f-`I*|n<& z_^;%jJS@wy@BR*0FHeTU@Lxk}NTbOy?Z>~0Vuo93nWmLC3{$16&ZMTS-Tk-VFf1?; z%ozsKnJn~F220Cfbai#3v-2{#+-`V01IDLMGhr=}296IY4YkNbQ5mIS3 z`UY2f2b!8&Fgf)R{y-4ZA7>DnoW{`bC@!_R#Jic#vxq7R4K4-KG&gD4+Lp|a0h5@a znT`2_I9^wW0q-D`n2MyHc2G;`m|s{#ch3z}R#u|Cyd1r~y<)(uRfwX7290oXY8rJX zPGWBUtJG*KM@QeGw6s*1?AyN|>2#Lw4O?13W=LKpR#&5NclY4S?7UQbD-+2SYHN?; zU{w|N?A+$ai9OO^u+cB{$k8LQ|-(Z{XmG+R_3t!-&^6D3-HO zw2)CH4jvTq(4lHEvqCdw_%;VTeHb1YwUyT)HLN{)4Bo+EsmQN#f%f;= z^B3?@JkUy*w!GAEB`_Ysg^QP@LcdDZXmhoT(ny9I%PKK6mN}13HZYZDlW1sc!U|O@gHD@m4Ji+W;Tq-IISQWZ zU2dspF>>8KcDxRcpF9=$$YwT$t89kLag{zMeqUKbYwKw$bJs*7=i7@h7z~NLe9-qu zJZG|^c;}gBedi1fL*uFuQxk#_S{AOWyhQzPJor32hbWc2{CghA2Rg#qTpg&VefI~( zMLQo^`QwR6B~H{-harOsu0~6{NE`l*7|vvKk*E@j`uzcAWMo8jySw$~mR76v)M?zl za~JpS_u*B)hs;+Ii_<`edP$z;l615N?{JHiJy z4Y<&-cv{%tMCE^Nn-0%nU_sX8bCj<(8Fr7K_@fyX0~@USIGwnO+cymVAAujLRPBIR Sn3L)N0000Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E-^DS16z6k00WCjL_t(YORdq{PZMbv2Ji+*xHNHfvsWg1 zfr)>EmnM40YCIClYN$pif=FqtEeEH&f`F%3Phpqk5CL6Rq)-7%#n!e$k3w5$r={gk zhC*RVp@p`vWIr-rJ|~~LYn0^IWZvg}=SkCY;)x_3iPkG^`S<(wmv?+K@cQEp^GqlL z3ONglQNFxSb{5d>9YOZpo#UH!n*GVMQf))(m;b`4#Mp4VHQ%>z^`@&t3VoI$tE! z*vC|s5v|kLKkVt$S%gFtzeJ*OjDZ8dJ`=%Sgr(%-8m8Aga_&+|``bZhD2A{aQvnli+Qd3hmHa7O`-G{AU>BzzwV(2j}JLkTQ3%_bSSVnSi@q7mt``P0+W!GHbJuHD!QXi^P|s^w^erGvo)gD<__ zZgis&d8!*eka=v|4?7Eq8f*oCQsIqzXoRJPnFJ#%ueh<#gvPJY>k2+-SIZu^pahoc zs08ELfIC-OiN>!1Udb!1(oDus0!y{iafaHz#4Qwe+NV+SzZ%|HiMlp+0!#Y?apZTE zDMv)8Cs)|vm$VL$+)Gz`ykT|-OVv|x%nqZs+x?m zDaplbK{=ne-Q}jS71FGCpUf8#^)Ij-fTg_?s~Dv>l1JRmDwN#oGCZ?Qb^BvXu5i3<;?^%EvTVV%(?w<6;tH|+NmObjVXMqTV=D9Xx9H>nt3_4vL#v_ zVcuO8$KeTFtkbqQBY%5WzSC3JlA!6m$uYs9!^^hOsjS)_@U_3w;i^}LAwL~n{ugD| VGz8gattS8g002ovPDHLkV1kQ1>v#YF literal 0 HcmV?d00001 diff --git a/Engine/sprite/Circle_2.png b/Engine/sprite/Circle_2.png new file mode 100644 index 0000000000000000000000000000000000000000..47590435448b81d9dc2c185154d2d4524eb41b14 GIT binary patch literal 1115 zcmV-h1f=_kP)N2bZe?^J zG%heMF*7s+TY3Nh1K3GKK~zXfy;faQ6IU2!;DUQbz2=IU`g1Dxg8c!gRK7%8zX;$* zhhT5pN-wJDosQE^XDS*JzFJEX2%sn*0!9MaWH;G-?e63Io;{%Xmv-;)~D)Zk0fHI#51N8WuJuwIb@<%XXfDnp8DacDwJckwtI4FH zynOxtq1>>GykBju1=VIb^JK8**xD{Qrd;Wki2Z{?8M<6zKz!_ zYfABQrqUU-wVlR^=4Ko{c1+xxG){UMDea=%kT;(b>n7!^Vtv# z`cOq)Le9q8+FFrRs&}|%{~CKr+Y-o0X%{NP@4ml;2xX{Bh`C5LSYKZ+vazwTQTYzj zHy*&mEd@O(tfM8&_K&*JM7%{X%8C_JZ8fBcC6-gZ&@o1tu3yj zbDdpyy}FJhW#7k;d+fc@`^e`DVz2k0Fx=!10<@%@JX+FF3LeC{`2}=#bz_^ll|`q` zfreCv!f=;r?Gh!=4?|w1Xf<-*J#)4l4<9`i^~h$DuB&2(TS=WhCcfL=MQ`s#YICs#%Ni%uksR&J@et!$|~a2@`}H6 zApg=4*5?^O2km<>G$+RS$SNLBOlom%Pc1iOP{TE7X*X!Y-x8y_d?6Os67gU#q)ksx z>t64$*>k?v>Ai3fzufs1zug_hlQAEe?;w$+K!|2WoD`*orVv*d9tQe2Lp^dcnbZ?$ z)3np+jKc<80{nM`4{i#$)UbM4NN}O@zqb8{XBDs@Yw|hDS4oC^qXZu_!)jmy*Qe5n hhs5}v;TK~K-UD-$uMnch3%~#X002ovPDHLkV1nGd4JiNs literal 0 HcmV?d00001 diff --git a/Engine/sprite/Ellipse.png b/Engine/sprite/Ellipse.png new file mode 100644 index 0000000000000000000000000000000000000000..eb461960d98d24ca6ec550d1a9b8a875e6eb75d5 GIT binary patch literal 602 zcmV-g0;TN2bZe?^J zG%heMF*7s+TY3Nh0oO@HK~zXf?UGGS+fWpRy$#YK?4iI)paiD0QJ@4yR3J9Mk7z;> zpr9@QC`PWj1VA{LAV8f~9Yl^3J9d&We2;eW6nB3vE-sCYrH6)xQ>hPtU}VXac<54jx+snG(niz* zOd{;_i|o{NZg$T4{pafDZ^f+!VG|IHEV;s9mz>U0f=WD+!JEN`poV4o&OF=GN-kx>sw+rZ?Cy6Co&@uF@vt^BcUY?$fBoIAA71P)4oP z51No3pRh|8qT@q^py+2x`}+r~ULZO?L2#)Yq2+1S3nX#Pi5ArLLzvpYe5c om8#dh9j!FM^Iob-6Q*!`2S&_^H!fe)HUIzs07*qoM6N<$g8xPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E-^DS16z6k00OK@L_t(YORbaLOOsI?$DhBUi-__n=%&k{ zi^$99CI}%ZjKmfak=1&&EMcJ+rOXmkqPdk?Z5sHN=+jIYZuzpNlWZHq&G|Ox<8rgj z?b&P8SI^0821M^HGS5y#-V&gZ_c3ps>iY{Y(U8Q17XY~ zcHit;)ED`kGpLU`g~xA<%R-P-_e~jWE8fktBv==MRc$8jd=2jk#23S9slZpk;cq^a zmJlj+htd*4rL(_MIm2Zfl2EBLm?FIG)@Pz@elLGgRZvuN>_q1WlKoTn4^5E|=XYm6x~l4h_$Etlp4)Jqd8Zh!9U$=r`LlrKC%xw)GT2 z-KC%LCu*BN6kn6;tuB`T6D(j2E_O&xr87U11Xbtf>IO}vvT1r%WZ@2A4a=yY$U-We z_9qF7dX-H6a7u`=WLL0^3W_YD(y6s1;p|0O_k@FuS%M0RY@|}lT9S}=_{jK*$i^%| z1w}SesaZ%6@HXm=vN20gL6MDAI<}f1oGFrZjM>?kC8(gtMk@X4OAsE_y}op_+~^fq zvMX3d1x1!nsc|Jvc+t*Ryj0(P-e_2iuy6;khGkSxWFeIrym3H(!Q1Ct=`HQJljQ#c z3s|dcdN;fzD%*LMQ|a(>9Kgl?;aWz16kff3;rfHRkAph1YhX4wv=jrl=*(_}c)|kK zNVitUlMA5IFH3QdDXr1+prWCzi}Kk4XrX_IqLyvL!uT-Phxee)7bmVoR!MHEArXJ#(TY=xiHT>Ib<=+rkZ%QELx% zy2U-x;SAqv9Wz0000IqP)N2bZe?^J zG%heMF*7s+TY3Nh0n$lCK~zXf?U2Dv8c`U9c@5|i-@)pWRH1Hb2}RMBM$;E)Yb><} z8jKI1=$J7+f*Oa8G}^c|F32!2!wk4?zu_l@OOQ--mfm~`=l}0HCv%DYi$zcGC))E` zDy3fMF%qIFrD1Rw)l&Zvv=e=p^4|XD=I2x@Ju^F-NW1|ABTKHt6EyTrQ0l9tZNCec zL>RxXv!8PLl~w)p?B?%X-DCX=oGxs~Np zV8BMh;ILFm-F6p_HT~yq@!Qt6-E7NdGT1N^At;-X(hd{~JG`sq&=`ziz)Xaoj7q8F zb|C$J!Khw~4i6E6qQ{gblT!`b6&)TT1Vt;QE!PL`EZY$s9wG!qtEG+)>GZ;tVTuk9 z5rU$X(x&6V_V*vl`ISb~kueOIi4c@gDYaW399Fc#&hD45TXm}?o5^6qOoX6pMoQc0 z!TGS5shTyG6TpD2^sCH&+A9r~N@=4Rlm@Hb^8C{Hn91gr@<*C()^6?}>Xz*S!mQo0 zFXerzcwD3;1=>l^Rp=BMAz#N!D-FtX%IJOjp*TDJ0h#^*6o8oci1 jD5X)J*V3RgT4J&P&{j&v*xp1000000NkvXXu0mjftMd_8 literal 0 HcmV?d00001 diff --git a/Engine/sprite/select.png b/Engine/sprite/select.png new file mode 100644 index 0000000000000000000000000000000000000000..fd5322e953d4e11cccef669104df521f3b720eb9 GIT binary patch literal 696 zcmV;p0!RIcP)N2bZe?^J zG%heMF*7s+TY3Nh0yRlQK~zXf?UcQ5(?A%9E2bY9b{L=wj36N~q7EQI z7-6VT1*xcLNYpm1fP7Y^X&Rb1P}ft)s6Ru%D0yN?x2?ztuUuXtNp;fa`R~|kaZSn0)})5Nps@o zAA^L5xPa&hQcZkm4BtFPgP$sDt}MCJy|ASgAzVXEG^`kp_z5GTJd$;@BCuDTEj3K? zJXqT(=?P&{H;SZ)wd}7~o4lLgg)Jq7^fa<35?axOZWMGW4kbdj&Q0)gW~EP7tKs6b zN&^|iAFR0vUe2sk>9gy4Np)&N2OvlHx~ln#Z+e z+zz2{x`|^L(n<@L@8i-v6r1h{lZ`xlcX8z*lv&O`z0(xU3HmVw({gSJYMkln`+Lr% e|4cgP@Z&ds2RX(u4&g5V0000N2bZe?^J zG%heMF*7s+TY3Nh0_aIZK~zXft(MJC6G0fpNlY*%#-o3TH)7%${{S&P=>ZctcmPQ# zO@+49@=-{@M7~4{*0!LD1PodbjHL}MmW4`z)r31>0rAjocXqn#v%4*kmfhmUoAlc!-WC#bS6xV)P?#sNiRcgk4csf(leHfC-ZhjlS;RIxk>!n#1$dc z~p_6qv^Ug2Lr6|Ahh4d@Q-JXoS%*x!t|0= zzS1T=XJJJ!g2DxY9!`_0p1syc*0IDpV}gefZHt+nHELZ*cYUQT5&r3NwlSQ()q7Ak zOYsNtf7W235b=6jaL@nrFvPnqcd>Hknv9o@xLV?!RVv*v-m{nraVpMu`e;*|1y3a1 zzDfZCu~a~}Gh#LTzZ@86%p_Qo*e4GmjswP5eSoIPGVJuDHI_xZEA5 zSh`c9+N+$?d;UF#q0{DtOl@%g-<fHIl*^&3fY$N#Tu)<#Qh%yI07KKKZ6k_A;b#25EYN{ivlW_8HQ&Vdki1?znYH ztn$g#Z>2%SieZ|LZxQ7FHM?}xCb^@;zmreFqB6*l`j4ctNxJUH^|SeUqlLnBkp2*Y z@Tn&(CSpL;aum{qY7xGqA|8_Jwu z>)qc+G;RQ>Dhe_ob-LN2bZe?^J zG%heMF*7s+TY3Nh0yRlQK~zXf?UX%l(@+$KBc?7ah+n{OVPt@j9R}zEBS=V$r~^oR zj4)KFf>cyABx;*hKt8L`G!0E0^3k9qt{ulwLlooKv3>n=om?r%aiR=?sjrUgtD|!s zoqNx@*9YI?ZTMTP&Y}MUYTFo?Ff3;=Lxc>&h*#JowAsa-H9Ss2?lX_4vUS{A!^$Ca zi+RSHgq9>MEo12cILQvBnz3A`BB*b|ysDE|pK5Ya#3hf;Z7nX7H5qdgH9BUHV z)9~&axxP}}Eos|7)V;EvtQ#MWlu3xKkFQnTT>cE(wz9^ z=O8X3CLnT(WD{Q-!!M7K^K(Vbl_eJLk|)$6glnkrh85)zJN2*#k3`+92vbho6Ka^` zd7!pc(&K^~H?o9?jqLB&+dNBf$rDNl>1iY-5?YZ9H!^w@M-ri}V+k%ztMtiwHB_8c zsXwE<4AfYHOVcV9JA-{;R;34mC3g*$;F2fQG|AhDynABMF1v6eqdN$4{f%UsCAj1X zrL~4LXM0tXZj*AOe~lEa-5DtnJ0(4O++pD^O+qyTS>EPklwuv z{z5-o)bec<+BoTg%yakaXSn(dH&)U3Wp5^$(Ojo2(CKN=UcU%9*YsmjiXF>o9@kcJ zJBYr?633c^R$91xAD8Z-*km40ZRN3a7gruandk1)H%-wTql+0bE$5Y>#JQfn1?U|5 e&!CGnpYIO{p!-Loeu`KC0000 Date: Tue, 17 Apr 2018 21:24:26 +0200 Subject: [PATCH 02/84] Weard bug --- Engine/ChiliWin.h | 69 +++++++++++++++++----------------- Engine/Engine.vcxproj | 9 +++++ Engine/Engine.vcxproj.filters | 38 +++++++++++++++++-- Engine/Game.cpp | 22 +++++++++++ Engine/Game.h | 4 ++ Engine/Graphics.cpp | 2 + Engine/Graphics.h | 5 ++- Engine/MainWindow.cpp | 35 ++++++++++++++++- Engine/Resource.h | Bin 904 -> 1014 bytes 9 files changed, 143 insertions(+), 41 deletions(-) diff --git a/Engine/ChiliWin.h b/Engine/ChiliWin.h index 4a21edc9..afd0db71 100644 --- a/Engine/ChiliWin.h +++ b/Engine/ChiliWin.h @@ -26,40 +26,41 @@ // The following #defines disable a bunch of unused windows stuff. If you // get weird errors when trying to do some windows stuff, try removing some // (or all) of these defines (it will increase build time though). -#define WIN32_LEAN_AND_MEAN -#define NOGDICAPMASKS -#define NOSYSMETRICS -#define NOMENUS -#define NOICONS -#define NOSYSCOMMANDS -#define NORASTEROPS -#define OEMRESOURCE -#define NOATOM -#define NOCLIPBOARD -#define NOCOLOR -#define NOCTLMGR -#define NODRAWTEXT -#define NOKERNEL -#define NONLS -#define NOMEMMGR -#define NOMETAFILE -#define NOMINMAX -#define NOOPENFILE -#define NOSCROLL -#define NOSERVICE -#define NOSOUND -#define NOTEXTMETRIC -#define NOWH -#define NOCOMM -#define NOKANJI -#define NOHELP -#define NOPROFILER -#define NODEFERWINDOWPOS -#define NOMCX -#define NORPC -#define NOPROXYSTUB -#define NOIMAGE -#define NOTAPE + +#define WIN32_LEAN_AND_MEAN //to exclude APIs such as Cryptography, DDE, RPC, Shell, and Windows Sockets. +#define NOGDICAPMASKS +#define NOSYSMETRICS +//#define NOMENUS +#define NOICONS +#define NOSYSCOMMANDS +#define NORASTEROPS +#define OEMRESOURCE +#define NOATOM +#define NOCLIPBOARD +#define NOCOLOR +#define NOCTLMGR +//#define NODRAWTEXT +#define NOKERNEL +#define NONLS +#define NOMEMMGR +#define NOMETAFILE +#define NOMINMAX +#define NOOPENFILE +#define NOSCROLL +#define NOSERVICE +#define NOSOUND +#define NOTEXTMETRIC +#define NOWH +#define NOCOMM +#define NOKANJI +#define NOHELP +#define NOPROFILER +#define NODEFERWINDOWPOS +#define NOMCX +#define NORPC +#define NOPROXYSTUB +#define NOIMAGE +#define NOTAPE #define STRICT diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index 6e656998..332932a1 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -228,6 +228,15 @@ + + + + + + + + + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index 2026aaba..8e4ea1c9 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -1,10 +1,6 @@  - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - {93995380-89BD-4b04-88EB-625FBE52EBFB} h;hh;hpp;hxx;hm;inl;inc;xsd @@ -16,6 +12,13 @@ {8b6c92a8-f65d-451e-80e3-d65773602b92} + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {7429fb29-146a-47ac-b5ad-e8731b226a6d} + @@ -104,5 +107,32 @@ Resource Files + + Added Sprites + + + Added Sprites + + + Added Sprites + + + Added Sprites + + + Added Sprites + + + Added Sprites + + + Added Sprites + + + Added Sprites + + + Added Sprites + \ No newline at end of file diff --git a/Engine/Game.cpp b/Engine/Game.cpp index dbdb5218..566c8de9 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -38,8 +38,30 @@ void Game::Go() void Game::UpdateModel() { + + if (wnd.mouse.LeftIsPressed()) + { + R++; + } + if (wnd.mouse.RightIsPressed()) + { + R--; + } + + + } void Game::ComposeFrame() { + while (theta < 360.0) + { + + int x = R * std::cos(PI*theta / 180); + int y = R * std::sin(PI*theta / 180); + + gfx.PutPixel(x+xpos,y+ypos,255,0,0); + + theta += 0.2; + } } diff --git a/Engine/Game.h b/Engine/Game.h index 1702e223..f519712c 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -42,5 +42,9 @@ class Game Graphics gfx; /********************************/ /* User Variables */ + int xpos = gfx.ScreenWidth / 2, ypos = gfx.ScreenHeight / 2; + double R = 300.0, theta = 0; + double PI = 3.1415926536; /********************************/ + }; \ No newline at end of file diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index bdff4ebf..a3511976 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -317,6 +317,8 @@ void Graphics::PutPixel( int x,int y,Color c ) } + + ////////////////////////////////////////////////// // Graphics Exception Graphics::Exception::Exception( HRESULT hr,const std::wstring& note,const wchar_t* file,unsigned int line ) diff --git a/Engine/Graphics.h b/Engine/Graphics.h index 9a44e3fe..8d9c02c4 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -57,6 +57,7 @@ class Graphics PutPixel( x,y,{ unsigned char( r ),unsigned char( g ),unsigned char( b ) } ); } void PutPixel( int x,int y,Color c ); + ~Graphics(); private: Microsoft::WRL::ComPtr pSwapChain; @@ -73,6 +74,6 @@ class Graphics D3D11_MAPPED_SUBRESOURCE mappedSysBufferTexture; Color* pSysBuffer = nullptr; public: - static constexpr int ScreenWidth = 800; - static constexpr int ScreenHeight = 600; + static constexpr int ScreenWidth = 1440; + static constexpr int ScreenHeight = 900; }; \ No newline at end of file diff --git a/Engine/MainWindow.cpp b/Engine/MainWindow.cpp index c2dc5f18..c08e8599 100644 --- a/Engine/MainWindow.cpp +++ b/Engine/MainWindow.cpp @@ -128,10 +128,39 @@ LRESULT WINAPI MainWindow::_HandleMsgThunk( HWND hWnd,UINT msg,WPARAM wParam,LPA return pWnd->HandleMsg( hWnd,msg,wParam,lParam ); } + LRESULT MainWindow::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) { switch( msg ) { + + case WM_CREATE: + HMENU hMenu, hSubMenu; + + hMenu = CreateMenu(); + + hSubMenu = CreatePopupMenu(); + AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, L"E&xit"); + AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu,L"&File"); + + hSubMenu = CreatePopupMenu(); + AppendMenu(hSubMenu, MF_STRING, ID_STUFF_GO, L"&Go"); + AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"&Stuff"); + + SetMenu(hWnd, hMenu); + + case WM_COMMAND: + switch (LOWORD(wParam)) + { + case ID_FILE_EXIT: + PostMessage(hWnd, WM_CLOSE, 0, 0); + break; + case ID_STUFF_GO: + MessageBox(hWnd, L"You clicked Go!", L"Woo!", MB_OK); + break; + } + break; + case WM_DESTROY: PostQuitMessage( 0 ); break; @@ -229,4 +258,8 @@ LRESULT MainWindow::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) } return DefWindowProc( hWnd,msg,wParam,lParam ); -} \ No newline at end of file +} + + + + diff --git a/Engine/Resource.h b/Engine/Resource.h index b1731dc04d85d775088715bf52dc74c28c3e8fc7..f4d9a81607d7ac9e32f4e440661597c532cad12c 100644 GIT binary patch delta 86 zcmeBR|Hi(dgL!fQlZc`xg9}4EgByb Date: Sat, 21 Apr 2018 16:16:37 +0200 Subject: [PATCH 03/84] Vector class added --- Engine/JezierMath.h | 17 ++++++++ Engine/JezierVec2.h | 100 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 Engine/JezierMath.h create mode 100644 Engine/JezierVec2.h diff --git a/Engine/JezierMath.h b/Engine/JezierMath.h new file mode 100644 index 00000000..6a544750 --- /dev/null +++ b/Engine/JezierMath.h @@ -0,0 +1,17 @@ +#pragma once + +#include "math.h" + +constexpr double PI_F = 3.1415926536; +constexpr double PI_D = 3.1415926535897932; + + +template +inline auto Sq(const T& x) +{ + return x * x; +} + + + + diff --git a/Engine/JezierVec2.h b/Engine/JezierVec2.h new file mode 100644 index 00000000..07445abc --- /dev/null +++ b/Engine/JezierVec2.h @@ -0,0 +1,100 @@ +#pragma once + +#include "JezierMath.h" + +template +class _Vec2 +{ +public: + inline _Vec2(){} + inline _Vec2(T inx, T iny) + : + x(inx), + y(iny) + {} + inline _Vec2(const _Vec2& vect) + : + _Vec2 (vect.x,vect.y) + {} + + template + explicit operator _Vec2() const + { + return { T2 x,T2 y }; + } + + /*Vector Vector Operators*/ + + inline _Vec2 operator-() + { + return Vec2(-x, -y); + } + inline _Vec2 operator= (const _Vec2 &rhs) + { + x = rhs.x; + y = rhs.y; + return *this; + } + + inline _Vec2 operator-(const _Vec2 &rhs)const + { + return _Vec2(x - rhs.x , y - rhs.y); + } + inline _Vec2& operator-=(const _Vec2 &rhs) + { + return *this = *this - rhs; + + } + + inline _Vec2 operator+(const _Vec2 &rhs)const + { + return _Vec2(x + rhs.x, y + rhs.y); + } + inline _Vec2& operator+=(const _Vec2 &rhs) + { + return *this = *this + rhs; + } + + /*Vector scalar operators*/ + + inline _Vec2 operator*(const T rhs) const + { + return _Vec2(x * rhs, y * rhs); + } + inline _Vec2& operator*=(const T rhs) + { + return *this = *this * rhs; + } + + inline _Vec2 operator/(const T rhs) const + { + return _Vec2(x / rhs, y / rhs); + } + inline _Vec2& operator/=(const T rhs) + { + return *this = *this / rhs; + } + + + /* + inline T SqLen() + { + return Sq(*this) + } + + inline T Length() + { + return std::sqrt(SqLenght); + } + */ + +public: + T x; + T y; + + +}; + +typedef _Vec2 Ved2; +typedef _Vec2 Vec2; +typedef _Vec2 Vei2; \ No newline at end of file From 8beadab8317f8d4968cb8156966831772e99c820 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 21 Apr 2018 16:17:37 +0200 Subject: [PATCH 04/84] furder changes to vec2 class --- Engine/JezierVec2.h | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/Engine/JezierVec2.h b/Engine/JezierVec2.h index 07445abc..104e80bd 100644 --- a/Engine/JezierVec2.h +++ b/Engine/JezierVec2.h @@ -75,18 +75,35 @@ class _Vec2 return *this = *this / rhs; } + /*Lenght operations*/ - /* - inline T SqLen() + inline T GetLengthSq() const { - return Sq(*this) + return x * x + y * y; } + + inline T GetLength() const + { + return std::sqrt(GetLengthSq); + } + + /*Normalise operations*/ - inline T Length() + inline _Vec2& Normalize() { - return std::sqrt(SqLenght); + return *this = GetNormalize(); } - */ + inline _Vec2 GetNormalize() const + { + const double len = GetLength(); + if (len != 0.0) + { + return *this * (1.0 / len); + } + return len; + } + + public: T x; From 45ec69a266bea14d5c65f2844ed6fdf0dcba99d7 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 21 Apr 2018 16:18:05 +0200 Subject: [PATCH 05/84] some chnges --- Engine/Engine.vcxproj | 2 ++ Engine/Engine.vcxproj.filters | 6 ++++++ Engine/Game.cpp | 28 +++++----------------------- Engine/Game.h | 5 ++--- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index 332932a1..90df5022 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -143,6 +143,8 @@ + + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index 8e4ea1c9..186d1156 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -60,6 +60,12 @@ Header Files + + Header Files + + + Header Files + diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 566c8de9..50d83067 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -20,12 +20,14 @@ ******************************************************************************************/ #include "MainWindow.h" #include "Game.h" +#include "JezierVec2.h" -Game::Game( MainWindow& wnd ) +Game::Game(MainWindow& wnd) : - wnd( wnd ), - gfx( wnd ) + wnd(wnd), + gfx(wnd) { + } void Game::Go() @@ -38,30 +40,10 @@ void Game::Go() void Game::UpdateModel() { - - if (wnd.mouse.LeftIsPressed()) - { - R++; - } - if (wnd.mouse.RightIsPressed()) - { - R--; - } - - } void Game::ComposeFrame() { - while (theta < 360.0) - { - - int x = R * std::cos(PI*theta / 180); - int y = R * std::sin(PI*theta / 180); - - gfx.PutPixel(x+xpos,y+ypos,255,0,0); - theta += 0.2; - } } diff --git a/Engine/Game.h b/Engine/Game.h index f519712c..9a64273c 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -23,6 +23,7 @@ #include "Keyboard.h" #include "Mouse.h" #include "Graphics.h" +#include "JezierVec2.h" class Game { @@ -42,9 +43,7 @@ class Game Graphics gfx; /********************************/ /* User Variables */ - int xpos = gfx.ScreenWidth / 2, ypos = gfx.ScreenHeight / 2; - double R = 300.0, theta = 0; - double PI = 3.1415926536; + /********************************/ }; \ No newline at end of file From 5c708a4d20c4af1eaa53ee65e44b5c9d73b3befa Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 21 Apr 2018 16:30:24 +0200 Subject: [PATCH 06/84] Boolean operations added to vec2 --- Engine/JezierVec2.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Engine/JezierVec2.h b/Engine/JezierVec2.h index 104e80bd..ad4af807 100644 --- a/Engine/JezierVec2.h +++ b/Engine/JezierVec2.h @@ -103,6 +103,17 @@ class _Vec2 return len; } + /*Boolean operations*/ + + inline bool operator==(const _Vec2 &rhs)const + { + return (x == rhs.x && y== rhs.y) ; + } + + inline bool operator!=(const _Vec2 &rhs)const + { + return (x != rhs.x || y != rhs.y); + } public: From b3613419c0d5e92ae25a4fd83f2429855f35d569 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 22 Apr 2018 16:43:03 +0200 Subject: [PATCH 07/84] code for help --- Engine/Game.cpp | 25 ++++++++++++++++++++++--- Engine/Game.h | 3 ++- Engine/Graphics.cpp | 33 +++++++++++++++++++++++++++++++++ Engine/Graphics.h | 2 ++ 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 50d83067..ac13d155 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -25,9 +25,12 @@ Game::Game(MainWindow& wnd) : wnd(wnd), - gfx(wnd) + gfx(wnd), + v1(3,4), + x1(720), + y1(450) { - + double len = &v1.GetLength; } void Game::Go() @@ -40,10 +43,26 @@ void Game::Go() void Game::UpdateModel() { + if (wnd.kbd.KeyIsPressed(VK_RIGHT)) + { + x2++; + } + if (wnd.kbd.KeyIsPressed(VK_LEFT)) + { + x2--; + } + if (wnd.kbd.KeyIsPressed(VK_UP)) + { + y2++; + } + if (wnd.kbd.KeyIsPressed(VK_DOWN)) + { + y2--; + } } void Game::ComposeFrame() { - + //gfx.DrawLine(x1, y1, x2, y2,White); } diff --git a/Engine/Game.h b/Engine/Game.h index 9a64273c..07b13605 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -43,7 +43,8 @@ class Game Graphics gfx; /********************************/ /* User Variables */ - + Ved2 v1; + float x1, y1, x2, y2; /********************************/ }; \ No newline at end of file diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index a3511976..96a8cc96 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -316,6 +316,39 @@ void Graphics::PutPixel( int x,int y,Color c ) pSysBuffer[Graphics::ScreenWidth * y + x] = c; } +void Graphics::DrawLine(float x1, float x2, float y1, float y2, Color c) +{ + const float dx = x2 - x1; + const float dy = y2 - y1; + + if (dx == 0.0f, dy == 0.0f) + { + PutPixel((int)x1, (int)y1, c); + } + else if (dx>dy) + { + const float m = dy / dx; + const float b = y1 - m * x1; + + for (float x = x1; x < x2; x++) + { + float y = m * x + b; + PutPixel((int)x, (int)y, c); + } + } + else + { + const float m = dy / dx; + const float b = y1 - m * x1; + + for (float y = y1; y < y2; y++) + { + float x = m * y + b; + PutPixel((int)x, (int)y, c); + } + } +} + diff --git a/Engine/Graphics.h b/Engine/Graphics.h index 8d9c02c4..64cb5c51 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -57,6 +57,8 @@ class Graphics PutPixel( x,y,{ unsigned char( r ),unsigned char( g ),unsigned char( b ) } ); } void PutPixel( int x,int y,Color c ); + + void DrawLine(float x1, float x2, float y1, float y2, Color c); ~Graphics(); private: From e8a3aa3eae9837ad8f9b3ccfcd55128b35f1d039 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 22 Apr 2018 21:24:09 +0200 Subject: [PATCH 08/84] Done Vec and line in graphics fully functional --- Engine/Game.cpp | 24 ++---------------------- Engine/Game.h | 1 + Engine/Graphics.cpp | 31 ++++++++++++++++++++++--------- Engine/JezierVec2.h | 3 ++- 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index ac13d155..dcd51df4 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -25,12 +25,9 @@ Game::Game(MainWindow& wnd) : wnd(wnd), - gfx(wnd), - v1(3,4), - x1(720), - y1(450) + gfx(wnd) + { - double len = &v1.GetLength; } void Game::Go() @@ -43,26 +40,9 @@ void Game::Go() void Game::UpdateModel() { - if (wnd.kbd.KeyIsPressed(VK_RIGHT)) - { - x2++; - } - if (wnd.kbd.KeyIsPressed(VK_LEFT)) - { - x2--; - } - if (wnd.kbd.KeyIsPressed(VK_UP)) - { - y2++; - } - if (wnd.kbd.KeyIsPressed(VK_DOWN)) - { - y2--; - } } void Game::ComposeFrame() { - //gfx.DrawLine(x1, y1, x2, y2,White); } diff --git a/Engine/Game.h b/Engine/Game.h index 07b13605..26fbb32a 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -45,6 +45,7 @@ class Game /* User Variables */ Ved2 v1; float x1, y1, x2, y2; + double len; /********************************/ }; \ No newline at end of file diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index 96a8cc96..542cdef5 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -26,6 +26,7 @@ #include #include + // Ignore the intellisense error "cannot open source file" for .shh files. // They will be created during the build sequence before the preprocessor runs. namespace FramebufferShaders @@ -316,21 +317,27 @@ void Graphics::PutPixel( int x,int y,Color c ) pSysBuffer[Graphics::ScreenWidth * y + x] = c; } -void Graphics::DrawLine(float x1, float x2, float y1, float y2, Color c) +void Graphics::DrawLine(float x1, float y1, float x2, float y2, Color c) { const float dx = x2 - x1; const float dy = y2 - y1; - if (dx == 0.0f, dy == 0.0f) + if (dx == 0.0f && dy == 0.0f) { PutPixel((int)x1, (int)y1, c); } - else if (dx>dy) + else if (abs(dx)>abs(dy)) { - const float m = dy / dx; - const float b = y1 - m * x1; + if (dx < 0.0f) + { + std::swap(x1, x2); + std::swap(y1, y2); + } + + float m = dy / dx; + float b = y1 - m * x1; - for (float x = x1; x < x2; x++) + for (float x = x1; x <= x2; x++) { float y = m * x + b; PutPixel((int)x, (int)y, c); @@ -338,10 +345,16 @@ void Graphics::DrawLine(float x1, float x2, float y1, float y2, Color c) } else { - const float m = dy / dx; - const float b = y1 - m * x1; + if (dy < 0.0f) + { + std::swap(x1, x2); + std::swap(y1, y2); + } + + float m = dx / dy; + float b = x1 - m * y1; - for (float y = y1; y < y2; y++) + for (float y = y1; y <= y2; y++) { float x = m * y + b; PutPixel((int)x, (int)y, c); diff --git a/Engine/JezierVec2.h b/Engine/JezierVec2.h index ad4af807..10e89b35 100644 --- a/Engine/JezierVec2.h +++ b/Engine/JezierVec2.h @@ -2,6 +2,7 @@ #include "JezierMath.h" + template class _Vec2 { @@ -84,7 +85,7 @@ class _Vec2 inline T GetLength() const { - return std::sqrt(GetLengthSq); + return std::sqrt(GetLengthSq()); } /*Normalise operations*/ From 43281ba50b602cda34521d4f2ae559efb2810a88 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 22 Apr 2018 21:26:34 +0200 Subject: [PATCH 09/84] Clean --- Engine/Game.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/Engine/Game.h b/Engine/Game.h index 26fbb32a..10d360e9 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -43,9 +43,6 @@ class Game Graphics gfx; /********************************/ /* User Variables */ - Ved2 v1; - float x1, y1, x2, y2; - double len; /********************************/ }; \ No newline at end of file From eb0d0dbbf16ba070db42f85590beb7a21a90fc39 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 28 Apr 2018 18:25:18 +0200 Subject: [PATCH 10/84] aded utility functions for draw arc circle and line, some visual bugs --- Engine/Graphics.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++- Engine/Graphics.h | 24 +++++++++++++++++++++++- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index 542cdef5..3bc7448c 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -324,7 +324,7 @@ void Graphics::DrawLine(float x1, float y1, float x2, float y2, Color c) if (dx == 0.0f && dy == 0.0f) { - PutPixel((int)x1, (int)y1, c); + PutPixel((int)x1, (int)y1, Colors::Red); } else if (abs(dx)>abs(dy)) { @@ -362,6 +362,49 @@ void Graphics::DrawLine(float x1, float y1, float x2, float y2, Color c) } } +void Graphics::DrawCircle(float xpos, float ypos, float R, Color c) +{ + + if (R > 0.0) + { + + for (double theta = 0; theta < 360; theta += 0.2) + { + float x = (float)(R * std::cos(PI_F*theta / 180)); + float y = (float)(R * std::sin(PI_F*theta / 180)); + + PutPixel((int)(xpos), (int)(ypos), Colors::White); + PutPixel((int)(x+0.5f + xpos), (int)(y+0.5f + ypos), c); + } + } + else + { + PutPixel(int(xpos), int(ypos), Colors::White); + } + + +} + +void Graphics::DrawArc(float x1, float y1, float Ox, float Oy, float theta_begin, float theta_end, Color c) +{ + + bool theta_range = theta_end - theta_begin > 0.0; + float R = std::sqrt((Ox - x1)*(Ox - x1) + (Oy - y1)*(Oy - y1)); + + for (float theta = theta_begin; + theta_range ? theta < theta_end : theta > theta_end; + theta_range > 0.0 ? theta += 0.2 : theta -= 0.2 ) + { + float x = (float)(R * std::cos(PI_F*theta / 180)); + float y = (float)(R * std::sin(PI_F*theta / 180)); + + //Draw pixel at the begining of radius + PutPixel((int)(Ox), (int)(Oy), Colors::Red); + //Draw arc + PutPixel((int)(x + Ox), (int)(y + Oy), c); + } +} + diff --git a/Engine/Graphics.h b/Engine/Graphics.h index 64cb5c51..9f4bcb05 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -24,6 +24,9 @@ #include #include "ChiliException.h" #include "Colors.h" +#include "JezierVec2.h" +#include +#include class Graphics { @@ -57,9 +60,28 @@ class Graphics PutPixel( x,y,{ unsigned char( r ),unsigned char( g ),unsigned char( b ) } ); } void PutPixel( int x,int y,Color c ); + + /*Draw Line Functions*/ + template + void DrawLine(const _Vec2 v1, const _Vec2 v2, Color c) + { + DrawLine((float)v1.x, (float)v1.y, (float)v2.x, (float)v2.y, c); + } + void DrawLine(float x1, float y1, float x2, float y2, Color c); + + /*Draw Circle Functions*/ + template + void DrawCircle(_Vec2 vpos, T2 R, Color c) + { + DrawCircle((float)vpos.x, (float)vpos.y, c); + } + void DrawCircle(float xpos, float ypos, float R, Color c); + + /*Draw Arc Functions*/ + void DrawArc(float x1, float y1, float Ox, float Oy, float theta_begin,float theta_end, Color c); - void DrawLine(float x1, float x2, float y1, float y2, Color c); + ~Graphics(); private: Microsoft::WRL::ComPtr pSwapChain; From bd225614276e4dba5bf032b378f7340a0aa3c92a Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 28 Apr 2018 18:26:53 +0200 Subject: [PATCH 11/84] test code --- Engine/Game.cpp | 31 ++++++++++++++++++++++++++++--- Engine/Game.h | 6 ++++++ Engine/MainWindow.cpp | 3 ++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index dcd51df4..769b3f0e 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -25,8 +25,11 @@ Game::Game(MainWindow& wnd) : wnd(wnd), - gfx(wnd) - + gfx(wnd), + xpos(720), + ypos(450), + x1(100), y1(450), x2(1300), y2(300), + c(Colors::White) { } @@ -40,9 +43,31 @@ void Game::Go() void Game::UpdateModel() { - + if (wnd.mouse.LeftIsPressed()) + { + xpos = wnd.mouse.GetPosX(); + ypos = wnd.mouse.GetPosY(); + c = Colors::Yellow; + } + else + c = Colors::White; + if (wnd.kbd.KeyIsPressed(VK_UP)) + { + y2--; + y1--; + } + if (wnd.kbd.KeyIsPressed(VK_DOWN)) + { + y2++; + y1++; + } } void Game::ComposeFrame() { + + gfx.DrawLine(x1, y1, x2, y2, Colors::White); + gfx.DrawCircle(xpos, ypos, 100, c); + gfx.DrawArc(520,450,720,450,45,120, Colors::White); + } diff --git a/Engine/Game.h b/Engine/Game.h index 10d360e9..143068ba 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -43,6 +43,12 @@ class Game Graphics gfx; /********************************/ /* User Variables */ + + int xpos; + int ypos; + int x1,y1,x2,y2; + Color c; + /********************************/ }; \ No newline at end of file diff --git a/Engine/MainWindow.cpp b/Engine/MainWindow.cpp index c08e8599..d48d99d1 100644 --- a/Engine/MainWindow.cpp +++ b/Engine/MainWindow.cpp @@ -156,7 +156,8 @@ LRESULT MainWindow::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) PostMessage(hWnd, WM_CLOSE, 0, 0); break; case ID_STUFF_GO: - MessageBox(hWnd, L"You clicked Go!", L"Woo!", MB_OK); + ShowMessageBox(L"You clicked Go!", L"Woo!"); + break; } break; From ce54adc5a7c8b79dfdb7dbf19b5f708aa1203283 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Wed, 2 May 2018 00:37:44 +0200 Subject: [PATCH 12/84] Fixed Bug caused by menu (gaps in shapes) --- Engine/MainWindow.cpp | 96 ++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 42 deletions(-) diff --git a/Engine/MainWindow.cpp b/Engine/MainWindow.cpp index d48d99d1..87819108 100644 --- a/Engine/MainWindow.cpp +++ b/Engine/MainWindow.cpp @@ -41,12 +41,13 @@ MainWindow::MainWindow( HINSTANCE hInst,wchar_t * pArgs ) // create window & get hWnd RECT wr; + MENUINFO; wr.left = 350; wr.right = Graphics::ScreenWidth + wr.left; wr.top = 100; wr.bottom = Graphics::ScreenHeight + wr.top; - AdjustWindowRect( &wr,WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,FALSE ); - hWnd = CreateWindow( wndClassName,L"Chili DirectX Framework", + AdjustWindowRect(&wr, WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, TRUE); + hWnd = CreateWindow( wndClassName,L"JCAD", WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, wr.left,wr.top,wr.right - wr.left,wr.bottom - wr.top, nullptr,nullptr,hInst,this ); @@ -129,27 +130,36 @@ LRESULT WINAPI MainWindow::_HandleMsgThunk( HWND hWnd,UINT msg,WPARAM wParam,LPA } -LRESULT MainWindow::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) +LRESULT MainWindow::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - switch( msg ) + switch (msg) { - + case WM_CREATE: + { HMENU hMenu, hSubMenu; hMenu = CreateMenu(); hSubMenu = CreatePopupMenu(); - AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, L"E&xit"); - AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu,L"&File"); + AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"&File"); + { + AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, L"E&xit"); + } hSubMenu = CreatePopupMenu(); - AppendMenu(hSubMenu, MF_STRING, ID_STUFF_GO, L"&Go"); + AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"&Stuff"); + { + AppendMenu(hSubMenu, MF_STRING, ID_STUFF_GO, L"&Go"); + } SetMenu(hWnd, hMenu); + break; + } case WM_COMMAND: + { switch (LOWORD(wParam)) { case ID_FILE_EXIT: @@ -157,13 +167,15 @@ LRESULT MainWindow::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) break; case ID_STUFF_GO: ShowMessageBox(L"You clicked Go!", L"Woo!"); - + break; } + break; + } case WM_DESTROY: - PostQuitMessage( 0 ); + PostQuitMessage(0); break; case WM_KILLFOCUS: kbd.ClearState(); @@ -171,94 +183,94 @@ LRESULT MainWindow::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) // ************ KEYBOARD MESSAGES ************ // case WM_KEYDOWN: - if( !(lParam & 0x40000000) || kbd.AutorepeatIsEnabled() ) // no thank you on the autorepeat + if (!(lParam & 0x40000000) || kbd.AutorepeatIsEnabled()) // no thank you on the autorepeat { - kbd.OnKeyPressed( static_cast(wParam) ); + kbd.OnKeyPressed(static_cast(wParam)); } break; case WM_KEYUP: - kbd.OnKeyReleased( static_cast(wParam) ); + kbd.OnKeyReleased(static_cast(wParam)); break; case WM_CHAR: - kbd.OnChar( static_cast(wParam) ); + kbd.OnChar(static_cast(wParam)); break; // ************ END KEYBOARD MESSAGES ************ // // ************ MOUSE MESSAGES ************ // case WM_MOUSEMOVE: { - POINTS pt = MAKEPOINTS( lParam ); - if( pt.x > 0 && pt.x < Graphics::ScreenWidth && pt.y > 0 && pt.y < Graphics::ScreenHeight ) + POINTS pt = MAKEPOINTS(lParam); + if (pt.x > 0 && pt.x < Graphics::ScreenWidth && pt.y > 0 && pt.y < Graphics::ScreenHeight) { - mouse.OnMouseMove( pt.x,pt.y ); - if( !mouse.IsInWindow() ) + mouse.OnMouseMove(pt.x, pt.y); + if (!mouse.IsInWindow()) { - SetCapture( hWnd ); + SetCapture(hWnd); mouse.OnMouseEnter(); } } else { - if( wParam & (MK_LBUTTON | MK_RBUTTON) ) + if (wParam & (MK_LBUTTON | MK_RBUTTON)) { - pt.x = std::max( short( 0 ),pt.x ); - pt.x = std::min( short( Graphics::ScreenWidth - 1 ),pt.x ); - pt.y = std::max( short( 0 ),pt.y ); - pt.y = std::min( short( Graphics::ScreenHeight - 1 ),pt.y ); - mouse.OnMouseMove( pt.x,pt.y ); + pt.x = std::max(short(0), pt.x); + pt.x = std::min(short(Graphics::ScreenWidth - 1), pt.x); + pt.y = std::max(short(0), pt.y); + pt.y = std::min(short(Graphics::ScreenHeight - 1), pt.y); + mouse.OnMouseMove(pt.x, pt.y); } else { ReleaseCapture(); mouse.OnMouseLeave(); - mouse.OnLeftReleased( pt.x,pt.y ); - mouse.OnRightReleased( pt.x,pt.y ); + mouse.OnLeftReleased(pt.x, pt.y); + mouse.OnRightReleased(pt.x, pt.y); } } break; } case WM_LBUTTONDOWN: { - const POINTS pt = MAKEPOINTS( lParam ); - mouse.OnLeftPressed( pt.x,pt.y ); - SetForegroundWindow( hWnd ); + const POINTS pt = MAKEPOINTS(lParam); + mouse.OnLeftPressed(pt.x, pt.y); + SetForegroundWindow(hWnd); break; } case WM_RBUTTONDOWN: { - const POINTS pt = MAKEPOINTS( lParam ); - mouse.OnRightPressed( pt.x,pt.y ); + const POINTS pt = MAKEPOINTS(lParam); + mouse.OnRightPressed(pt.x, pt.y); break; } case WM_LBUTTONUP: { - const POINTS pt = MAKEPOINTS( lParam ); - mouse.OnLeftReleased( pt.x,pt.y ); + const POINTS pt = MAKEPOINTS(lParam); + mouse.OnLeftReleased(pt.x, pt.y); break; } case WM_RBUTTONUP: { - const POINTS pt = MAKEPOINTS( lParam ); - mouse.OnRightReleased( pt.x,pt.y ); + const POINTS pt = MAKEPOINTS(lParam); + mouse.OnRightReleased(pt.x, pt.y); break; } case WM_MOUSEWHEEL: { - const POINTS pt = MAKEPOINTS( lParam ); - if( GET_WHEEL_DELTA_WPARAM( wParam ) > 0 ) + const POINTS pt = MAKEPOINTS(lParam); + if (GET_WHEEL_DELTA_WPARAM(wParam) > 0) { - mouse.OnWheelUp( pt.x,pt.y ); + mouse.OnWheelUp(pt.x, pt.y); } - else if( GET_WHEEL_DELTA_WPARAM( wParam ) < 0 ) + else if (GET_WHEEL_DELTA_WPARAM(wParam) < 0) { - mouse.OnWheelDown( pt.x,pt.y ); + mouse.OnWheelDown(pt.x, pt.y); } break; } // ************ END MOUSE MESSAGES ************ // } - return DefWindowProc( hWnd,msg,wParam,lParam ); + return DefWindowProc(hWnd, msg, wParam, lParam); } From 758de4268a2f4bcb6c8939ba3f4a237b150329ea Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Wed, 2 May 2018 00:40:48 +0200 Subject: [PATCH 13/84] Added thin line shape drawing algorithms radius and centre controlled circle,two point line , angle controled arc, flat ellipse --- Engine/Graphics.cpp | 87 ++++++++++++++++++++++++++++++++++++--------- Engine/Graphics.h | 21 +++++++---- 2 files changed, 85 insertions(+), 23 deletions(-) diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index 3bc7448c..9d72779d 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -241,6 +241,35 @@ Graphics::Graphics( HWNDKey& key ) _aligned_malloc( sizeof( Color ) * Graphics::ScreenWidth * Graphics::ScreenHeight,16u ) ); } +void Graphics::DrawFlatEllipse(float Ox, float Oy, float Rx, float Ry, Color c) +{ + if (Ry==0.0) + { + DrawLine(Ox - Rx, Oy, Ox + Rx, Oy, c); + } + else if (Rx==0.0) + { + + DrawLine(Ox, Oy - Ry, Ox, Oy + Ry, c); + } + else if (Rx == 0.0 && Ry == 0.0) + { + PutPixel((int)(Ox), (int)(Oy), c); + } + else + { + for (double theta = 0; theta < 360; theta += 0.2) + { + float x = (float)(Rx * std::cos(PI_F*theta / 180)); + float y = (float)(Ry * std::sin(PI_F*theta / 180)); + + PutPixel((int)(Ox), (int)(Oy), c); + PutPixel((int)(x + 0.5f + Ox), (int)(y + 0.5f + Oy), c); + } + } + +} + Graphics::~Graphics() { // free sysbuffer memory (aligned free) @@ -340,7 +369,7 @@ void Graphics::DrawLine(float x1, float y1, float x2, float y2, Color c) for (float x = x1; x <= x2; x++) { float y = m * x + b; - PutPixel((int)x, (int)y, c); + PutPixel((int)(x + 0.5f), (int)(y + 0.5f), c); } } else @@ -357,12 +386,12 @@ void Graphics::DrawLine(float x1, float y1, float x2, float y2, Color c) for (float y = y1; y <= y2; y++) { float x = m * y + b; - PutPixel((int)x, (int)y, c); + PutPixel((int)(x + 0.5f), (int)(y + 0.5f), c); } } } -void Graphics::DrawCircle(float xpos, float ypos, float R, Color c) +void Graphics::DrawCircle(float Ox, float Oy, float R, Color c) { if (R > 0.0) @@ -373,35 +402,59 @@ void Graphics::DrawCircle(float xpos, float ypos, float R, Color c) float x = (float)(R * std::cos(PI_F*theta / 180)); float y = (float)(R * std::sin(PI_F*theta / 180)); - PutPixel((int)(xpos), (int)(ypos), Colors::White); - PutPixel((int)(x+0.5f + xpos), (int)(y+0.5f + ypos), c); + PutPixel((int)(Ox), (int)(Oy),c); + PutPixel((int)(x+0.5f + Ox), (int)(y+0.5f + Oy), c); } } else { - PutPixel(int(xpos), int(ypos), Colors::White); + PutPixel(int(Ox), int(Oy), c); } } -void Graphics::DrawArc(float x1, float y1, float Ox, float Oy, float theta_begin, float theta_end, Color c) +void Graphics::DrawCircle(float x1, float y1, float x2, float y2, float x3, float y3, Color c) +{ + // find slope of any two lines conecting points + + // calculate perpendicular line slope... + + // ...throught mid point + + // find crossection of two lines + + // Calculate radius using pair of centre and onarc points + + //pass centre and radius to DrawCircle function + + +} + +void Graphics::DrawArc(float Ox, float Oy, float R ,float theta_begin, float theta_end, Color c) { bool theta_range = theta_end - theta_begin > 0.0; - float R = std::sqrt((Ox - x1)*(Ox - x1) + (Oy - y1)*(Oy - y1)); - for (float theta = theta_begin; - theta_range ? theta < theta_end : theta > theta_end; - theta_range > 0.0 ? theta += 0.2 : theta -= 0.2 ) + + if (theta_begin == theta_end) + { + DrawCircle(Ox, Oy ,R,c); + } + else { - float x = (float)(R * std::cos(PI_F*theta / 180)); - float y = (float)(R * std::sin(PI_F*theta / 180)); + for (float theta = theta_begin; + theta_range ? theta < theta_end : theta > theta_end; + theta_range ? theta += 0.2 : theta -= 0.2) + { + float x = (float)(R * std::cos(PI_F*theta / 180)); + float y = (float)(R * std::sin(PI_F*theta / 180)); - //Draw pixel at the begining of radius - PutPixel((int)(Ox), (int)(Oy), Colors::Red); - //Draw arc - PutPixel((int)(x + Ox), (int)(y + Oy), c); + //Draw pixel at the begining of radius + PutPixel((int)(Ox), (int)(Oy), Colors::Red); + //Draw arc + PutPixel((int)(x + 0.5f + Ox), (int)(y + 0.5f + Oy), c); + } } } diff --git a/Engine/Graphics.h b/Engine/Graphics.h index 9f4bcb05..4fbdf386 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -71,15 +71,24 @@ class Graphics /*Draw Circle Functions*/ template - void DrawCircle(_Vec2 vpos, T2 R, Color c) + void DrawCircle(_Vec2 vO, T2 R, Color c) { - DrawCircle((float)vpos.x, (float)vpos.y, c); + DrawCircle((float)vO.x, (float)vO.y, c); } - void DrawCircle(float xpos, float ypos, float R, Color c); - + void DrawCircle(float Ox, float Oy, float R, Color c); + //Three point circle + void DrawCircle(float x1, float y1, float x2, float y2, float x3, float y3, Color c); + /*Draw Arc Functions*/ - void DrawArc(float x1, float y1, float Ox, float Oy, float theta_begin,float theta_end, Color c); + void DrawArc(float Ox, float Oy,float R, float theta_begin,float theta_end, Color c); + template + void DrawArc(_Vec2 vO, T3 R, Color c) + { + DrawArc((float)vO.x, (float)vO.y, (float)R, c); + } + /*Elipse Drawing functions*/ + void DrawFlatEllipse(float Ox, float Oy, float Rx, float Ry, Color c); ~Graphics(); @@ -98,6 +107,6 @@ class Graphics D3D11_MAPPED_SUBRESOURCE mappedSysBufferTexture; Color* pSysBuffer = nullptr; public: - static constexpr int ScreenWidth = 1440; + static constexpr int ScreenWidth =1440; static constexpr int ScreenHeight = 900; }; \ No newline at end of file From eeab153347c053a0061594e2697d499abcdfe3f6 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 6 May 2018 19:45:14 +0200 Subject: [PATCH 14/84] Changed pair to Vei2 --- Engine/Mouse.cpp | 2 +- Engine/Mouse.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Engine/Mouse.cpp b/Engine/Mouse.cpp index 68d528d1..1667d4a7 100644 --- a/Engine/Mouse.cpp +++ b/Engine/Mouse.cpp @@ -21,7 +21,7 @@ #include "Mouse.h" -std::pair Mouse::GetPos() const +Vei2 Mouse::GetPos() const { return { x,y }; } diff --git a/Engine/Mouse.h b/Engine/Mouse.h index 187939ef..568a70f2 100644 --- a/Engine/Mouse.h +++ b/Engine/Mouse.h @@ -20,6 +20,7 @@ ******************************************************************************************/ #pragma once #include +#include "JezierVec2.h" class Mouse { @@ -95,7 +96,7 @@ class Mouse Mouse() = default; Mouse( const Mouse& ) = delete; Mouse& operator=( const Mouse& ) = delete; - std::pair GetPos() const; + Vei2 GetPos() const; int GetPosX() const; int GetPosY() const; bool LeftIsPressed() const; From edd66a4db432f626f0d4b598a51b86e16f768ac9 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 6 May 2018 19:45:45 +0200 Subject: [PATCH 15/84] Cleanup --- Engine/MainWindow.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Engine/MainWindow.cpp b/Engine/MainWindow.cpp index 87819108..7943c26a 100644 --- a/Engine/MainWindow.cpp +++ b/Engine/MainWindow.cpp @@ -41,7 +41,6 @@ MainWindow::MainWindow( HINSTANCE hInst,wchar_t * pArgs ) // create window & get hWnd RECT wr; - MENUINFO; wr.left = 350; wr.right = Graphics::ScreenWidth + wr.left; wr.top = 100; From 4cd9e6b5aed5211a36d33492fbad2deaf4e68758 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 6 May 2018 19:46:41 +0200 Subject: [PATCH 16/84] Spotted little bug passing collor without radius --- Engine/Graphics.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/Graphics.h b/Engine/Graphics.h index 4fbdf386..676c3211 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -73,7 +73,7 @@ class Graphics template void DrawCircle(_Vec2 vO, T2 R, Color c) { - DrawCircle((float)vO.x, (float)vO.y, c); + DrawCircle((float)vO.x, (float)vO.y, (float)R, c); } void DrawCircle(float Ox, float Oy, float R, Color c); //Three point circle From 52d0117f80d6773c6fecb1cc233d4dc3fbc98642 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 18 May 2018 00:08:32 +0200 Subject: [PATCH 17/84] Finally 3 point circle done Circle class in progrss --- Engine/Graphics.cpp | 56 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index 9d72779d..54261aff 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -391,6 +391,11 @@ void Graphics::DrawLine(float x1, float y1, float x2, float y2, Color c) } } +void Graphics::DrawCircle(Vec2 vO, Vec2 Comp_Rad, Color c) +{ + DrawCircle(vO.x, vO.y, Comp_Rad.x, Comp_Rad.y, c); +} + void Graphics::DrawCircle(float Ox, float Oy, float R, Color c) { @@ -414,20 +419,59 @@ void Graphics::DrawCircle(float Ox, float Oy, float R, Color c) } +void Graphics::DrawCircle(float Ox, float Oy, float x1, float y1, Color c) +{ + + float Rx = std::abs(x1 - Ox); + float Ry = std::abs(y1 - Oy); + //calculate radius + float R = std::sqrt(Rx*Rx + Ry * Ry); + + DrawCircle(Ox, Oy, R, c); +} + void Graphics::DrawCircle(float x1, float y1, float x2, float y2, float x3, float y3, Color c) { - // find slope of any two lines conecting points + // find slope of the line created by 2 points - // calculate perpendicular line slope... + float m1 = Slope(x1, y1, x3, y3); + float m2 = Slope(x2, y2, x3, y3); - // ...throught mid point + //If slopes are the same lines are parallel ,draw Line (infinite radius) + if (m2 - m1 == 0) + { + DrawLine(x1,y1,x2,y2,c); + } + else + { + // calculate perpendicular line slope... - // find crossection of two lines + float m1_perp = -(1.0f / m1); + float m2_perp = -(1.0f / m2); - // Calculate radius using pair of centre and onarc points + //mid point of orginally inserted lines - //pass centre and radius to DrawCircle function + float AC_x = (x3 + x1) / 2; + float AC_y = (y3 + y1) / 2; + + float BC_x = (x3 + x2) / 2; + float BC_y = (y3 + y2) / 2; + + // y=mx+b find b part of perpendicular line + // y-y1 = m(x-x1) = > y = mx - (mx1 - y1) + //https://www.varsitytutors.com/hotmath/hotmath_help/topics/point-slope-form.html + float a = -(m1_perp * AC_x - AC_y); + float b = -(m2_perp * BC_x - BC_y); + + // find crossection + //http://www.ambrsoft.com/MathCalc/Line/TwoLinesIntersection/TwoLinesIntersection.htm + + float x = (a-b) / (m2_perp - m1_perp); + float y = ((m2_perp * a) - (m1_perp * b) ) / (m2_perp - m1_perp ); + + DrawCircle(x,y,x3,y3,c); + } } From 430634faaaff3dd125869fed297214bd3a131ee0 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 18 May 2018 00:09:32 +0200 Subject: [PATCH 18/84] Function calculating slope of line --- Engine/JezierMath.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Engine/JezierMath.h b/Engine/JezierMath.h index 6a544750..352e4883 100644 --- a/Engine/JezierMath.h +++ b/Engine/JezierMath.h @@ -1,6 +1,7 @@ #pragma once #include "math.h" +#include constexpr double PI_F = 3.1415926536; constexpr double PI_D = 3.1415926535897932; @@ -12,6 +13,23 @@ inline auto Sq(const T& x) return x * x; } +//TO DO +// function two points as parameter retuens slope of the coresponding line - +inline float Slope(const float x1, const float y1, const float x2, const float y2) +{ + float dx = x2 - x1; + float dy = y2 - y1; + if (abs(dx) > abs(dy)) + { + float m = dy / dx; + return m; + } + else + { + + float m = dx / dy; + return m; + } +} From fbe4c74b9523aa357982c4a77f6bd3614d0c1451 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 18 May 2018 00:16:27 +0200 Subject: [PATCH 19/84] Oops forgot to commit --- Engine/Graphics.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Engine/Graphics.h b/Engine/Graphics.h index 676c3211..12a42f73 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -25,8 +25,8 @@ #include "ChiliException.h" #include "Colors.h" #include "JezierVec2.h" -#include -#include +#include + class Graphics { @@ -61,7 +61,8 @@ class Graphics } void PutPixel( int x,int y,Color c ); - /*Draw Line Functions*/ + /***** Start Draw Line Functions *****/ + template void DrawLine(const _Vec2 v1, const _Vec2 v2, Color c) { @@ -69,15 +70,28 @@ class Graphics } void DrawLine(float x1, float y1, float x2, float y2, Color c); - /*Draw Circle Functions*/ + /***** END Draw Line Functions ****/ + + + /***** Start Draw Circle Functions *****/ template void DrawCircle(_Vec2 vO, T2 R, Color c) { DrawCircle((float)vO.x, (float)vO.y, (float)R, c); } + //Copmponet Radius circle + void DrawCircle(Vec2 vO,Vec2 Comp_Rad,Color c); + void DrawCircle(float Ox, float Oy, float x1, float y1, Color c); void DrawCircle(float Ox, float Oy, float R, Color c); - //Three point circle - void DrawCircle(float x1, float y1, float x2, float y2, float x3, float y3, Color c); + + //Three point circle + void DrawCircle(float x1, float y1, //first point + float x2, float y2, //second point + float x3, float y3, //curvature direction + Color c); + + /***** END Draw Circle Functions ****/ + /*Draw Arc Functions*/ void DrawArc(float Ox, float Oy,float R, float theta_begin,float theta_end, Color c); From c8d24501137892e4c1f57602758c2fd017282656 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Thu, 24 May 2018 22:26:41 +0200 Subject: [PATCH 20/84] Change of naming convencion Added JC_Point2 class --- Engine/Engine.vcxproj | 5 +- Engine/Engine.vcxproj.filters | 10 +- Engine/Game.cpp | 53 +++--- Engine/Game.h | 13 +- Engine/Graphics.cpp | 85 +++++---- Engine/Graphics.h | 21 ++- Engine/{JezierMath.h => JC_Math.h} | 1 - Engine/JC_Vector2.h | 274 +++++++++++++++++++++++++++++ Engine/JezierVec2.h | 129 -------------- Engine/Mouse.h | 2 +- 10 files changed, 390 insertions(+), 203 deletions(-) rename Engine/{JezierMath.h => JC_Math.h} (95%) create mode 100644 Engine/JC_Vector2.h delete mode 100644 Engine/JezierVec2.h diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index 90df5022..4a0496ae 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -138,13 +138,14 @@ + - - + + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index 186d1156..87c3679f 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -19,6 +19,9 @@ {7429fb29-146a-47ac-b5ad-e8731b226a6d} + + {b9b4aa28-3d6d-4412-b8b4-6ff6c3af9881} + @@ -60,10 +63,13 @@ Header Files - + + Header Files\Shapes + + Header Files - + Header Files diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 769b3f0e..17d23cf8 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -20,16 +20,15 @@ ******************************************************************************************/ #include "MainWindow.h" #include "Game.h" -#include "JezierVec2.h" +#include "JC_Vector2.h" + Game::Game(MainWindow& wnd) : wnd(wnd), gfx(wnd), - xpos(720), - ypos(450), - x1(100), y1(450), x2(1300), y2(300), - c(Colors::White) + P(720,450) + { } @@ -43,31 +42,39 @@ void Game::Go() void Game::UpdateModel() { + + +} + +void Game::ComposeFrame() + +{ /* if (wnd.mouse.LeftIsPressed()) { - xpos = wnd.mouse.GetPosX(); - ypos = wnd.mouse.GetPosY(); - c = Colors::Yellow; + gfx.DrawLine((float)wnd.mouse.GetPosX(), (float)wnd.mouse.GetPosY(), 840, 330, Colors::White); + gfx.DrawLine((float)wnd.mouse.GetPosX(), (float)wnd.mouse.GetPosY(), 600, 570, Colors::White); + gfx.DrawCircle(600, 570, 840, 330, (float)wnd.mouse.GetPosX(), (float)wnd.mouse.GetPosY(), Colors::White); } else - c = Colors::White; - if (wnd.kbd.KeyIsPressed(VK_UP)) { - y2--; - y1--; + gfx.DrawLine(600, 330, 840, 330, Colors::White); + gfx.DrawLine(600, 330, 600, 570, Colors::White); + gfx.DrawCircle(600, 570, 840, 330,600,330 , Colors::White); } - if (wnd.kbd.KeyIsPressed(VK_DOWN)) + + + if (wnd.mouse.LeftIsPressed()) { - y2++; - y1++; + gfx.DrawLine(600, 450, (float)wnd.mouse.GetPosX(), (float)wnd.mouse.GetPosY(), Colors::White); + gfx.DrawLine(840, 450, (float)wnd.mouse.GetPosX(), (float)wnd.mouse.GetPosY(), Colors::White); + gfx.DrawCircle(600, 450, 840, 450, (float)wnd.mouse.GetPosX(), (float)wnd.mouse.GetPosY(), Colors::White); } -} - -void Game::ComposeFrame() -{ - - gfx.DrawLine(x1, y1, x2, y2, Colors::White); - gfx.DrawCircle(xpos, ypos, 100, c); - gfx.DrawArc(520,450,720,450,45,120, Colors::White); + else + { + gfx.DrawLine(600, 450, 720, 800, Colors::White); + gfx.DrawLine(840, 450, 720, 800, Colors::White); + gfx.DrawCircle(600, 450, 840, 450, 720, 800, Colors::White); + }*/ + } diff --git a/Engine/Game.h b/Engine/Game.h index 143068ba..1dcb8df4 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -23,7 +23,8 @@ #include "Keyboard.h" #include "Mouse.h" #include "Graphics.h" -#include "JezierVec2.h" +#include "JC_Vector2.h" +#include "Circle.h" class Game { @@ -32,6 +33,8 @@ class Game Game( const Game& ) = delete; Game& operator=( const Game& ) = delete; void Go(); + + private: void ComposeFrame(); void UpdateModel(); @@ -43,12 +46,8 @@ class Game Graphics gfx; /********************************/ /* User Variables */ - - int xpos; - int ypos; - int x1,y1,x2,y2; - Color c; - + //std::vector circles; + JC_Point2f P; /********************************/ }; \ No newline at end of file diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index 54261aff..dceaadf9 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -429,52 +429,75 @@ void Graphics::DrawCircle(float Ox, float Oy, float x1, float y1, Color c) DrawCircle(Ox, Oy, R, c); } - -void Graphics::DrawCircle(float x1, float y1, float x2, float y2, float x3, float y3, Color c) +/* +bool Graphics::DrawCircle(float x1, float y1, float x2, float y2, float x3, float y3, Color c) { // find slope of the line created by 2 points - - float m1 = Slope(x1, y1, x3, y3); - float m2 = Slope(x2, y2, x3, y3); - - //If slopes are the same lines are parallel ,draw Line (infinite radius) - if (m2 - m1 == 0) + float m1 = 0.0f; + float m2 = 0.0f; + //when we have 2 flat lines in order + if (x1 == x3 && y2 == y3) { - DrawLine(x1,y1,x2,y2,c); + float x = (x3 + x2) / 2; + float y = (y1 + y3) / 2; + DrawCircle(x, y, x3, y3, c); + return true; } - else + //when we have 2 flat lines in reverce order + else if (y1 == y3 && x2 == x3) { - // calculate perpendicular line slope... + float x= x3 + x1 / 2; + float y = y2 + y3 / 2; + DrawCircle(x, y, x3, y3, c); + return true; + } + else if (x1 != x2 && y1 != y2 || x2 != x3 && y2 != y3) + { + m1 = Slope(x1, y1, x3, y3); + m2 = Slope(x2, y2, x3, y3); + + //If slopes are the same lines are parallel ,do nothing (infinite radius) + if (m2 - m1 == 0.0) + { + return false; + } + else + { + // calculate perpendicular line slope... + + float m1_perp = (-1.0f / m1); + float m2_perp = (-1.0f / m2); - float m1_perp = -(1.0f / m1); - float m2_perp = -(1.0f / m2); + //mid point of orginally inserted lines - //mid point of orginally inserted lines + float mid_AC_x = (x3 + x1) / 2; + float mid_AC_y = (y3 + y1) / 2; - float AC_x = (x3 + x1) / 2; - float AC_y = (y3 + y1) / 2; - - float BC_x = (x3 + x2) / 2; - float BC_y = (y3 + y2) / 2; - - // y=mx+b find b part of perpendicular line - // y-y1 = m(x-x1) = > y = mx - (mx1 - y1) - //https://www.varsitytutors.com/hotmath/hotmath_help/topics/point-slope-form.html + float mid_BC_x = (x3 + x2) / 2; + float mid_BC_y = (y3 + y2) / 2; - float a = -(m1_perp * AC_x - AC_y); - float b = -(m2_perp * BC_x - BC_y); + // y=mx+b find b part of perpendicular line + // y-y1 = m(x-x1) = > y = mx - (m*x1 + y1) + //https://www.varsitytutors.com/hotmath/hotmath_help/topics/point-slope-form.html - // find crossection - //http://www.ambrsoft.com/MathCalc/Line/TwoLinesIntersection/TwoLinesIntersection.htm + float a = (-m1_perp * mid_AC_x + mid_AC_y); + float b = (-m2_perp * mid_BC_x + mid_BC_y); - float x = (a-b) / (m2_perp - m1_perp); - float y = ((m2_perp * a) - (m1_perp * b) ) / (m2_perp - m1_perp ); + // find crossection + //http://www.ambrsoft.com/MathCalc/Line/TwoLinesIntersection/TwoLinesIntersection.htm + + float x = (a - b) / (m2_perp - m1_perp); + float y = ((m1_perp * b) - (m2_perp * a)) / (m1_perp - m2_perp); + + DrawCircle(x, y, x3, y3, c); + return true; + } - DrawCircle(x,y,x3,y3,c); } + return false; } - +*/ void Graphics::DrawArc(float Ox, float Oy, float R ,float theta_begin, float theta_end, Color c) { diff --git a/Engine/Graphics.h b/Engine/Graphics.h index 12a42f73..851aab07 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -19,13 +19,15 @@ * along with The Chili DirectX Framework. If not, see . * ******************************************************************************************/ #pragma once -#include "ChiliWin.h" #include #include +#include + +#include "ChiliWin.h" #include "ChiliException.h" #include "Colors.h" -#include "JezierVec2.h" -#include +#include "JC_Vector2.h" +#include "JC_Math.h" class Graphics @@ -64,7 +66,7 @@ class Graphics /***** Start Draw Line Functions *****/ template - void DrawLine(const _Vec2 v1, const _Vec2 v2, Color c) + void DrawLine(const JC_Vector2 v1, const JC_Vector2 v2, Color c) { DrawLine((float)v1.x, (float)v1.y, (float)v2.x, (float)v2.y, c); } @@ -75,7 +77,7 @@ class Graphics /***** Start Draw Circle Functions *****/ template - void DrawCircle(_Vec2 vO, T2 R, Color c) + void DrawCircle(JC_Vector2 vO, T2 R, Color c) { DrawCircle((float)vO.x, (float)vO.y, (float)R, c); } @@ -85,18 +87,23 @@ class Graphics void DrawCircle(float Ox, float Oy, float R, Color c); //Three point circle - void DrawCircle(float x1, float y1, //first point + + /* + bool DrawCircle( + float x1, float y1, //first point float x2, float y2, //second point float x3, float y3, //curvature direction Color c); + */ + /***** END Draw Circle Functions ****/ /*Draw Arc Functions*/ void DrawArc(float Ox, float Oy,float R, float theta_begin,float theta_end, Color c); template - void DrawArc(_Vec2 vO, T3 R, Color c) + void DrawArc(JC_Vector2 vO, T3 R, Color c) { DrawArc((float)vO.x, (float)vO.y, (float)R, c); } diff --git a/Engine/JezierMath.h b/Engine/JC_Math.h similarity index 95% rename from Engine/JezierMath.h rename to Engine/JC_Math.h index 352e4883..ac279701 100644 --- a/Engine/JezierMath.h +++ b/Engine/JC_Math.h @@ -1,7 +1,6 @@ #pragma once #include "math.h" -#include constexpr double PI_F = 3.1415926536; constexpr double PI_D = 3.1415926535897932; diff --git a/Engine/JC_Vector2.h b/Engine/JC_Vector2.h new file mode 100644 index 00000000..1cc1b798 --- /dev/null +++ b/Engine/JC_Vector2.h @@ -0,0 +1,274 @@ +#pragma once + + + +template +class JC_Vector2 +{ +public: + T x; + T y; + + + +public: + inline JC_Vector2(){} + inline JC_Vector2(T inx, T iny) + : + x(inx), + y(iny) + {} + inline JC_Vector2 (const JC_Vector2& vect) + : + JC_Vector2 (vect.x,vect.y) + {} + + template + explicit operator JC_Vector2() const + { + return { T2 x,T2 y }; + } + + + + /* + inline JC_Vector2(const JC_Point& P , const JC_Point &Q) + : + JC_Vector2(P.x-Q.x, P.y-Q.y) + {} + */ + + + /*Vector Vector Operators*/ + + inline JC_Vector2 operator-() + { + return JC_Vector2(-x, -y); + } + inline JC_Vector2 operator= (const JC_Vector2 &rhs) + { + x = rhs.x; + y = rhs.y; + return *this; + } + + inline JC_Vector2 operator-(const JC_Vector2 &rhs)const + { + return JC_Vector2(x - rhs.x , y - rhs.y); + } + inline JC_Vector2& operator-=(const JC_Vector2 &rhs) + { + return *this = *this - rhs; + + } + + inline JC_Vector2 operator+(const JC_Vector2 &rhs)const + { + return JC_Vector2(x + rhs.x, y + rhs.y); + } + inline JC_Vector2& operator+=(const JC_Vector2 &rhs) + { + return *this = *this + rhs; + } + + /*Vector scalar operators*/ + + inline JC_Vector2 operator*(const T rhs) const + { + return JC_Vector2(x * rhs, y * rhs); + } + inline JC_Vector2& operator*=(const T rhs) + { + return *this = *this * rhs; + } + + inline JC_Vector2 operator/(const T rhs) const + { + return JC_Vector2(x / rhs, y / rhs); + } + inline JC_Vector2& operator/=(const T rhs) + { + return *this = *this / rhs; + } + + /*Lenght operations*/ + + inline T GetLengthSq() const + { + return x * x + y * y; + } + + inline T GetLength() const + { + return std::sqrt(GetLengthSq()); + } + + /*Normalise operations*/ + + inline JC_Vector2& Normalize() + { + return *this = GetNormalize(); + } + inline JC_Vector2 GetNormalize() const + { + const double len = GetLength(); + if (len != 0.0) + { + return *this * (1.0 / len); + } + return len; + } + + /*Boolean operators*/ + + inline bool operator==(const JC_Vector2 &rhs)const + { + return (x == rhs.x && y== rhs.y) ; + } + + inline bool operator!=(const JC_Vector2 &rhs)const + { + return (x != rhs.x || y != rhs.y); + } + + +}; + +typedef JC_Vector2 Ved2; +typedef JC_Vector2 Vec2; +typedef JC_Vector2 Vei2; + + +template +class JC_Point2 +{ +public: + T x; + T y; + +public: + inline JC_Point2() {} + inline JC_Point2(T inx, T iny) + : + x(inx), + y(iny) + {} + inline JC_Point2(const JC_Point2& point) + : + JC_Point2(point.x, point.y) + {} + + template + explicit operator JC_Point2() const + { + return { T2 x,T2 y }; + + } + + + inline JC_Point2 operator-() + { + return JC_Point2(-x, -y); + } + inline JC_Point2 operator= (const JC_Point2 &rhs) + { + x = rhs.x; + y = rhs.y; + return *this; + } + + JC_Point2 operator+(const JC_Point2 &rhs) const + { + return JC_Point2(x + rhs.x, y + rhs.y); + } + + /*JC_Point2 operator+(const JC_Vector2 &rhs) const + { + return JC_Point2(x + rhs.x, y + rhs.y); + } + + + + JC_Point2 operator-(const JC_Vector2 &rhs) const + { + return JC_Point2(x - rhs.x, y - rhs.y); + } + */ + + + JC_Point2 operator*(T rhs) + { + return JC_Point2(p.x*rhs, p.y*rhs); + } + + + + bool operator==(const JC_Point2 &rhs) const + { + return (x == rhs.x && y == rhs.y) ? true : false; + } + + bool operator!=(const JC_Point2 &rhs) const + { + return (x != rhs.x || y != rhs.y); + } + + bool operator<=(const JC_Point2 &rhs) const + { + // dictionary order + return ((x < rhs.x) ? true : ((x == rhs.x && y <= rhs.y) ? true : false)); + } + + bool operator>=(const JC_Point2 &rhs) const + { + // dictionary order + return ((x > rhs.x) ? true : ((x == rhs.x && y >= rhs.y) ? true : false)); + } + + bool operator<(const JC_Point2 &rhs) const + { + // dictionary order + return ((x < rhs.x) ? true : ((x == rhs.x && y < rhs.y) ? true : false)); + } + + bool operator>(const JC_Point2 &rhs) const + { + // dictionary order + return ((x > rhs.x) ? true : ((x == rhs.x && y > rhs.y) ? true : false)); + } + + + + inline T GetDistanceToSq() const + { + return x * x + y * y; + } + + inline T GetDistance() const + { + return std::sqrt(GetDistanceToSq()); + } + + + inline void Zero() + { + x = y = 0.0; + } + + inline bool IsZero() const + { + return (x == 0.0 && y == 0.0); + } + + inline bool IsNotZero() const + { + // the && (x == x && y == y) insures no coordinate is a Nan. + return (x != 0.0 || y != 0.0) && (x == x && y == y); + } + + +}; + +typedef JC_Point2 JC_Point2d; +typedef JC_Point2 JC_Point2f; +typedef JC_Point2 JC_Point2i; diff --git a/Engine/JezierVec2.h b/Engine/JezierVec2.h deleted file mode 100644 index 10e89b35..00000000 --- a/Engine/JezierVec2.h +++ /dev/null @@ -1,129 +0,0 @@ -#pragma once - -#include "JezierMath.h" - - -template -class _Vec2 -{ -public: - inline _Vec2(){} - inline _Vec2(T inx, T iny) - : - x(inx), - y(iny) - {} - inline _Vec2(const _Vec2& vect) - : - _Vec2 (vect.x,vect.y) - {} - - template - explicit operator _Vec2() const - { - return { T2 x,T2 y }; - } - - /*Vector Vector Operators*/ - - inline _Vec2 operator-() - { - return Vec2(-x, -y); - } - inline _Vec2 operator= (const _Vec2 &rhs) - { - x = rhs.x; - y = rhs.y; - return *this; - } - - inline _Vec2 operator-(const _Vec2 &rhs)const - { - return _Vec2(x - rhs.x , y - rhs.y); - } - inline _Vec2& operator-=(const _Vec2 &rhs) - { - return *this = *this - rhs; - - } - - inline _Vec2 operator+(const _Vec2 &rhs)const - { - return _Vec2(x + rhs.x, y + rhs.y); - } - inline _Vec2& operator+=(const _Vec2 &rhs) - { - return *this = *this + rhs; - } - - /*Vector scalar operators*/ - - inline _Vec2 operator*(const T rhs) const - { - return _Vec2(x * rhs, y * rhs); - } - inline _Vec2& operator*=(const T rhs) - { - return *this = *this * rhs; - } - - inline _Vec2 operator/(const T rhs) const - { - return _Vec2(x / rhs, y / rhs); - } - inline _Vec2& operator/=(const T rhs) - { - return *this = *this / rhs; - } - - /*Lenght operations*/ - - inline T GetLengthSq() const - { - return x * x + y * y; - } - - inline T GetLength() const - { - return std::sqrt(GetLengthSq()); - } - - /*Normalise operations*/ - - inline _Vec2& Normalize() - { - return *this = GetNormalize(); - } - inline _Vec2 GetNormalize() const - { - const double len = GetLength(); - if (len != 0.0) - { - return *this * (1.0 / len); - } - return len; - } - - /*Boolean operations*/ - - inline bool operator==(const _Vec2 &rhs)const - { - return (x == rhs.x && y== rhs.y) ; - } - - inline bool operator!=(const _Vec2 &rhs)const - { - return (x != rhs.x || y != rhs.y); - } - - -public: - T x; - T y; - - -}; - -typedef _Vec2 Ved2; -typedef _Vec2 Vec2; -typedef _Vec2 Vei2; \ No newline at end of file diff --git a/Engine/Mouse.h b/Engine/Mouse.h index 568a70f2..9b3c7135 100644 --- a/Engine/Mouse.h +++ b/Engine/Mouse.h @@ -20,7 +20,7 @@ ******************************************************************************************/ #pragma once #include -#include "JezierVec2.h" +#include "JC_Vector2.h" class Mouse { From cd2d471c6bd6d0addf7264e64ab720c0ebf1457f Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 26 May 2018 17:56:08 +0200 Subject: [PATCH 21/84] Fixing return type name --- Engine/Mouse.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/Mouse.cpp b/Engine/Mouse.cpp index 1667d4a7..3e44e0d3 100644 --- a/Engine/Mouse.cpp +++ b/Engine/Mouse.cpp @@ -21,7 +21,7 @@ #include "Mouse.h" -Vei2 Mouse::GetPos() const +JC_Vector2i Mouse::GetPos() const { return { x,y }; } From bc98eb09add8acdb5e759acbb26fa8c0ca3c61f4 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 26 May 2018 17:57:13 +0200 Subject: [PATCH 22/84] Function to draw circle throught 3 points Debugged and almost finished --- Engine/Game.cpp | 15 ++++++++------- Engine/Game.h | 2 ++ Engine/Graphics.cpp | 10 +++++----- Engine/Graphics.h | 6 +++--- Engine/JC_Math.h | 15 ++++----------- 5 files changed, 22 insertions(+), 26 deletions(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 17d23cf8..d9652807 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -27,7 +27,9 @@ Game::Game(MainWindow& wnd) : wnd(wnd), gfx(wnd), - P(720,450) + P(720,450), + Q(840, 570), + V(P,Q) { } @@ -60,7 +62,7 @@ void Game::ComposeFrame() gfx.DrawLine(600, 330, 840, 330, Colors::White); gfx.DrawLine(600, 330, 600, 570, Colors::White); gfx.DrawCircle(600, 570, 840, 330,600,330 , Colors::White); - } + }*/ if (wnd.mouse.LeftIsPressed()) @@ -71,10 +73,9 @@ void Game::ComposeFrame() } else { - gfx.DrawLine(600, 450, 720, 800, Colors::White); - gfx.DrawLine(840, 450, 720, 800, Colors::White); - gfx.DrawCircle(600, 450, 840, 450, 720, 800, Colors::White); - }*/ + gfx.DrawLine(600, 450, 720, 600, Colors::White); + gfx.DrawLine(840, 450, 720, 600, Colors::White); + gfx.DrawCircle(600, 450, 840, 450, 720, 600, Colors::White); + } - } diff --git a/Engine/Game.h b/Engine/Game.h index 1dcb8df4..3a7bdb5f 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -48,6 +48,8 @@ class Game /* User Variables */ //std::vector circles; JC_Point2f P; + JC_Point2f Q; + JC_Vector2f V; /********************************/ }; \ No newline at end of file diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index dceaadf9..2c7146a0 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -391,7 +391,7 @@ void Graphics::DrawLine(float x1, float y1, float x2, float y2, Color c) } } -void Graphics::DrawCircle(Vec2 vO, Vec2 Comp_Rad, Color c) +void Graphics::DrawCircle(JC_Vector2f vO, JC_Vector2f Comp_Rad, Color c) { DrawCircle(vO.x, vO.y, Comp_Rad.x, Comp_Rad.y, c); } @@ -429,7 +429,7 @@ void Graphics::DrawCircle(float Ox, float Oy, float x1, float y1, Color c) DrawCircle(Ox, Oy, R, c); } -/* + bool Graphics::DrawCircle(float x1, float y1, float x2, float y2, float x3, float y3, Color c) { // find slope of the line created by 2 points @@ -477,7 +477,7 @@ bool Graphics::DrawCircle(float x1, float y1, float x2, float y2, float x3, floa float mid_BC_y = (y3 + y2) / 2; // y=mx+b find b part of perpendicular line - // y-y1 = m(x-x1) = > y = mx - (m*x1 + y1) + // y-y1 = m(x-x1) = > y = mx - m*x1 + y1 //https://www.varsitytutors.com/hotmath/hotmath_help/topics/point-slope-form.html float a = (-m1_perp * mid_AC_x + mid_AC_y); @@ -487,7 +487,7 @@ bool Graphics::DrawCircle(float x1, float y1, float x2, float y2, float x3, floa //http://www.ambrsoft.com/MathCalc/Line/TwoLinesIntersection/TwoLinesIntersection.htm float x = (a - b) / (m2_perp - m1_perp); - float y = ((m1_perp * b) - (m2_perp * a)) / (m1_perp - m2_perp); + float y = -((m2_perp * a) - (m1_perp * b)) / (m1_perp - m2_perp); DrawCircle(x, y, x3, y3, c); return true; @@ -497,7 +497,7 @@ bool Graphics::DrawCircle(float x1, float y1, float x2, float y2, float x3, floa return false; } -*/ + void Graphics::DrawArc(float Ox, float Oy, float R ,float theta_begin, float theta_end, Color c) { diff --git a/Engine/Graphics.h b/Engine/Graphics.h index 851aab07..eb3af238 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -82,20 +82,20 @@ class Graphics DrawCircle((float)vO.x, (float)vO.y, (float)R, c); } //Copmponet Radius circle - void DrawCircle(Vec2 vO,Vec2 Comp_Rad,Color c); + void DrawCircle(JC_Vector2f vO, JC_Vector2f Comp_Rad,Color c); void DrawCircle(float Ox, float Oy, float x1, float y1, Color c); void DrawCircle(float Ox, float Oy, float R, Color c); //Three point circle - /* + bool DrawCircle( float x1, float y1, //first point float x2, float y2, //second point float x3, float y3, //curvature direction Color c); - */ + /***** END Draw Circle Functions ****/ diff --git a/Engine/JC_Math.h b/Engine/JC_Math.h index ac279701..2e8e8306 100644 --- a/Engine/JC_Math.h +++ b/Engine/JC_Math.h @@ -19,16 +19,9 @@ inline float Slope(const float x1, const float y1, const float x2, const float y { float dx = x2 - x1; float dy = y2 - y1; - if (abs(dx) > abs(dy)) - { - float m = dy / dx; - return m; - } - else - { - - float m = dx / dy; - return m; - } + + float m = dy / dx; + return m; + } From 9c6953cf9f357a853c9497dc772ef16b7d0e9796 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 26 May 2018 17:57:49 +0200 Subject: [PATCH 23/84] Hange of naming convention --- Engine/Mouse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/Mouse.h b/Engine/Mouse.h index 9b3c7135..37bb14c2 100644 --- a/Engine/Mouse.h +++ b/Engine/Mouse.h @@ -96,7 +96,7 @@ class Mouse Mouse() = default; Mouse( const Mouse& ) = delete; Mouse& operator=( const Mouse& ) = delete; - Vei2 GetPos() const; + JC_Vector2i GetPos() const; int GetPosX() const; int GetPosY() const; bool LeftIsPressed() const; From 3a4b0e19b88f052c2b3737e2a2ec0b11fa9106a4 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 26 May 2018 17:58:14 +0200 Subject: [PATCH 24/84] Debugged and running --- Engine/JC_Vector2.h | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Engine/JC_Vector2.h b/Engine/JC_Vector2.h index 1cc1b798..590e0f5d 100644 --- a/Engine/JC_Vector2.h +++ b/Engine/JC_Vector2.h @@ -18,10 +18,14 @@ class JC_Vector2 x(inx), y(iny) {} + + + /* inline JC_Vector2 (const JC_Vector2& vect) : JC_Vector2 (vect.x,vect.y) {} + */ template explicit operator JC_Vector2() const @@ -30,13 +34,12 @@ class JC_Vector2 } - - /* - inline JC_Vector2(const JC_Point& P , const JC_Point &Q) + template + inline JC_Vector2(const PointType& P , const PointType& Q) : - JC_Vector2(P.x-Q.x, P.y-Q.y) + JC_Vector2(P.x-Q.x , P.y-Q.y) {} - */ + /*Vector Vector Operators*/ @@ -45,12 +48,14 @@ class JC_Vector2 { return JC_Vector2(-x, -y); } + /* inline JC_Vector2 operator= (const JC_Vector2 &rhs) { x = rhs.x; y = rhs.y; return *this; } + */ inline JC_Vector2 operator-(const JC_Vector2 &rhs)const { @@ -134,9 +139,9 @@ class JC_Vector2 }; -typedef JC_Vector2 Ved2; -typedef JC_Vector2 Vec2; -typedef JC_Vector2 Vei2; +typedef JC_Vector2 JC_Vector2d; +typedef JC_Vector2 JC_Vector2f; +typedef JC_Vector2 JC_Vector2i; template From e66c0481f79d697306bc219472617e1e4539d53c Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Mon, 4 Jun 2018 21:35:43 +0200 Subject: [PATCH 25/84] Aded circle class --- Engine/Circle.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++++ Engine/Circle.h | 31 ++++++++++++++++++ Engine/Game.cpp | 34 +++++++++++++++++--- Engine/Game.h | 16 +++++++--- Engine/JC_Math.h | 33 ++++++++++++++++++- Engine/JC_Vector2.h | 60 +++++++++++++++++++++++++++------- 6 files changed, 230 insertions(+), 22 deletions(-) create mode 100644 Engine/Circle.cpp create mode 100644 Engine/Circle.h diff --git a/Engine/Circle.cpp b/Engine/Circle.cpp new file mode 100644 index 00000000..7ca98371 --- /dev/null +++ b/Engine/Circle.cpp @@ -0,0 +1,78 @@ +#include "Circle.h" +#include "JC_Math.h" +#include + +Circle::Circle(const JC_Point2d& P, const JC_Point2d& Q) +{ + pos = P; + radius = CalculateRadius(P,Q); +} + +Circle::Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R) +{ + // find slope of the line created by 2 points + double m1 = 0.0f; + double m2 = 0.0f; + //when we have 2 flat lines in order under right angle + if (P.x == R.x && Q.y == R.y) + { + JC_Point2d C; + C.x = (R.x + Q.x) / 2; + C.y = (P.y + R.y) / 2; + pos = C; + radius = CalculateRadius(C, R); + + } + //when we have 2 flat lines in reverce order under right angle + else if (P.y == R.y && Q.x == R.x) + { + JC_Point2d C; + C.x = R.x + P.x / 2; + C.y = Q.y + R.y / 2; + pos = C; + radius = CalculateRadius(C, R); + } + else if (P.x != Q.x && P.y != Q.y || Q.x != R.x && Q.y != R.y) + { + m1 = LineSlopeBetween2Points(P,R); + m2 = LineSlopeBetween2Points(Q,R); + + //If slopes are the same lines are parallel ,do nothing (infinite radius) + if (m2 - m1 == 0.0) + { + + } + else + { + // calculate perpendicular line slope... + + double m1_perp = InverceLineSlope(m1); + double m2_perp = InverceLineSlope(m2); + + //mid point of orginally inserted lines + + JC_Point2d mid_PR = P.GetMidPoint(R); + + JC_Point2d mid_QR = Q.GetMidPoint(R); + + + // y=mx+b find b part of perpendicular line + // y-y1 = m(x-x1) = > y = mx - m*x1 + y1 + //https://www.varsitytutors.com/hotmath/hotmath_help/topics/point-slope-form.html + + double a = (-m1_perp * mid_PR.x + mid_PR.y); + double b = (-m2_perp * mid_QR.x + mid_QR.y); + + // find crossection + //http://www.ambrsoft.com/MathCalc/Line/TwoLinesIntersection/TwoLinesIntersection.htm + + JC_Point2d C; + C.x = (a - b) / (m2_perp - m1_perp); + C.y = ((m1_perp * b) - (m2_perp * a)) / (m1_perp - m2_perp); + + //Calculate final circle + pos = C; + radius = CalculateRadius(C,R); + } + } +} diff --git a/Engine/Circle.h b/Engine/Circle.h new file mode 100644 index 00000000..c8b690f0 --- /dev/null +++ b/Engine/Circle.h @@ -0,0 +1,31 @@ +#pragma once + +#include "Graphics.h" +#include "Mouse.h" +#include "Colors.h" +#include "JC_Vector2.h" + +class Circle +{ +public: + + Circle(const JC_Point2d& P, const JC_Point2d& Q); + + Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); + + + void Draw(Graphics& gfx ) + { + gfx.DrawCircle(pos, radius, C); + } + + //Circle CalculateSelect(); + + +private: + JC_Point2d pos; + double radius; + static constexpr double halfwidth = 4.0; + Color C = Colors::White; +}; + diff --git a/Engine/Game.cpp b/Engine/Game.cpp index d9652807..a6ca6b5f 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -21,16 +21,16 @@ #include "MainWindow.h" #include "Game.h" #include "JC_Vector2.h" +#include "Mouse.h" Game::Game(MainWindow& wnd) : wnd(wnd), gfx(wnd), - P(720,450), - Q(840, 570), - V(P,Q) - + P (600,450), + Q(840,450), + R (720,330) { } @@ -44,6 +44,19 @@ void Game::Go() void Game::UpdateModel() { + while (!wnd.mouse.IsEmpty()) + { + const auto e = wnd.mouse.Read(); + + if (e.GetType() == Mouse::Event::Type::LPress) + { + input++; + + if (input <= 2) + input = 0; + } + } + } @@ -62,7 +75,7 @@ void Game::ComposeFrame() gfx.DrawLine(600, 330, 840, 330, Colors::White); gfx.DrawLine(600, 330, 600, 570, Colors::White); gfx.DrawCircle(600, 570, 840, 330,600,330 , Colors::White); - }*/ + } if (wnd.mouse.LeftIsPressed()) @@ -77,5 +90,16 @@ void Game::ComposeFrame() gfx.DrawLine(840, 450, 720, 600, Colors::White); gfx.DrawCircle(600, 450, 840, 450, 720, 600, Colors::White); } + */ + + circles.emplace_back(P, Q); + circles.emplace_back(P, Q, R); + + for (auto i : circles) + { + i.Draw(gfx); + } + + P.GetDistanceTo(Q); } diff --git a/Engine/Game.h b/Engine/Game.h index 3a7bdb5f..f464ec45 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -26,6 +26,8 @@ #include "JC_Vector2.h" #include "Circle.h" + + class Game { public: @@ -34,6 +36,12 @@ class Game Game& operator=( const Game& ) = delete; void Go(); + enum class Shapes + { + Circle2Point, + Circle3point, + FlatEllipse + }; private: void ComposeFrame(); @@ -46,10 +54,10 @@ class Game Graphics gfx; /********************************/ /* User Variables */ - //std::vector circles; - JC_Point2f P; - JC_Point2f Q; - JC_Vector2f V; + std::vector circles; + Shapes shapes = Shapes::Circle2Point; + JC_Point2d P, Q, R; + int input = 0; /********************************/ }; \ No newline at end of file diff --git a/Engine/JC_Math.h b/Engine/JC_Math.h index 2e8e8306..ee555d39 100644 --- a/Engine/JC_Math.h +++ b/Engine/JC_Math.h @@ -1,6 +1,8 @@ #pragma once -#include "math.h" +#include "JC_Vector2.h" +#include + constexpr double PI_F = 3.1415926536; constexpr double PI_D = 3.1415926535897932; @@ -25,3 +27,32 @@ inline float Slope(const float x1, const float y1, const float x2, const float y } +inline double LineSlopeBetween2Points(const JC_Point2d& P, const JC_Point2d& Q) +{ + double dx = Q.x - P.x; + double dy = Q.y - P.y; + + assert(dx != 0.0); + + double m = dy / dx; + + + + return m; + +} + +inline double InverceLineSlope(const double& m) +{ + assert(m != 0.0f); + + return -1 / m; +} + +inline double CalculateRadius(const JC_Point2d& P, const JC_Point2d& Q) +{ + double Rx = std::abs(P.x - Q.x); + double Ry = std::abs(P.y - Q.y); + //calculate radius + return std::sqrt(Rx * Rx + Ry * Ry); +} diff --git a/Engine/JC_Vector2.h b/Engine/JC_Vector2.h index 590e0f5d..a9051651 100644 --- a/Engine/JC_Vector2.h +++ b/Engine/JC_Vector2.h @@ -1,6 +1,7 @@ #pragma once - +#include +#include template class JC_Vector2 @@ -136,6 +137,15 @@ class JC_Vector2 return (x != rhs.x || y != rhs.y); } + inline double Vector_Slope(const JC_Vector2& V) + { + + assert(V.x == 0.0f); + float m = V.y / V.x; + + return m; + + } }; @@ -182,28 +192,50 @@ class JC_Point2 return *this; } - JC_Point2 operator+(const JC_Point2 &rhs) const + inline JC_Point2 operator+(const JC_Point2 &rhs) const { return JC_Point2(x + rhs.x, y + rhs.y); } + inline JC_Point2& operator+=(const JC_Point2 &rhs) + { + return *this = *this + rhs; - /*JC_Point2 operator+(const JC_Vector2 &rhs) const + } + + + inline JC_Point2 operator- (const JC_Point2 &rhs) const { - return JC_Point2(x + rhs.x, y + rhs.y); + return JC_Point2(x - rhs.x, y - rhs.y) } + inline JC_Point2& operator-=(const JC_Point2 &rhs) + { + return *this = *this - rhs; + } + inline JC_Point2 operator*(const T rhs) const + { + return JC_Point2(x * rhs, y * rhs); + } + inline JC_Point2& operator*=(const T rhs) + { + return *this = *this * rhs; + } - JC_Point2 operator-(const JC_Vector2 &rhs) const + inline JC_Point2 operator/(const T rhs) const { - return JC_Point2(x - rhs.x, y - rhs.y); + return JC_Point2(x / rhs, y / rhs); } - */ + inline JC_Point2& operator/=(const T rhs) + { + return *this = *this / rhs; + } + JC_Point2 operator*(T rhs) { - return JC_Point2(p.x*rhs, p.y*rhs); + return JC_Point2(x*rhs, y*rhs); } @@ -244,16 +276,20 @@ class JC_Point2 - inline T GetDistanceToSq() const + inline T GetDistanceToSq( const JC_Point2 &rhs) const { - return x * x + y * y; + return ((this->x-rhs.x) * (this->x - rhs.x) + (this->y - rhs.y) * (this->y - rhs.y)); } - inline T GetDistance() const + inline T GetDistanceTo(const JC_Point2 &rhs) const { - return std::sqrt(GetDistanceToSq()); + return std::sqrt(GetDistanceToSq(rhs)); } + inline JC_Point2 GetMidPoint(const JC_Point2& rhs) const + { + return JC_Point2((*this+rhs)/2); + } inline void Zero() { From 11d91b0295824328ffffea41c8e8e6e6a224a817 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Mon, 4 Jun 2018 21:35:56 +0200 Subject: [PATCH 26/84] Cosmetic changes --- Engine/Engine.vcxproj | 1 + Engine/Engine.vcxproj.filters | 6 ++++ Engine/Graphics.cpp | 55 +++++++++++++++++------------------ Engine/Graphics.h | 38 +++++++++++++----------- 4 files changed, 55 insertions(+), 45 deletions(-) diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index 4a0496ae..78c62a3d 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -154,6 +154,7 @@ + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index 87c3679f..1506572b 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -22,6 +22,9 @@ {b9b4aa28-3d6d-4412-b8b4-6ff6c3af9881} + + {a1ba54ce-e6f2-47b3-93dd-e28c6615d142} + @@ -101,6 +104,9 @@ Source Files + + Source Files\Shapes + diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index 2c7146a0..18f10822 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -346,10 +346,10 @@ void Graphics::PutPixel( int x,int y,Color c ) pSysBuffer[Graphics::ScreenWidth * y + x] = c; } -void Graphics::DrawLine(float x1, float y1, float x2, float y2, Color c) +void Graphics::DrawLine(double x1, double y1, double x2, double y2, Color c) { - const float dx = x2 - x1; - const float dy = y2 - y1; + const double dx = x2 - x1; + const double dy = y2 - y1; if (dx == 0.0f && dy == 0.0f) { @@ -363,12 +363,12 @@ void Graphics::DrawLine(float x1, float y1, float x2, float y2, Color c) std::swap(y1, y2); } - float m = dy / dx; - float b = y1 - m * x1; + double m = dy / dx; + double b = y1 - m * x1; - for (float x = x1; x <= x2; x++) + for (double x = x1; x <= x2; x++) { - float y = m * x + b; + double y = m * x + b; PutPixel((int)(x + 0.5f), (int)(y + 0.5f), c); } } @@ -380,23 +380,23 @@ void Graphics::DrawLine(float x1, float y1, float x2, float y2, Color c) std::swap(y1, y2); } - float m = dx / dy; - float b = x1 - m * y1; + double m = dx / dy; + double b = x1 - m * y1; - for (float y = y1; y <= y2; y++) + for (double y = y1; y <= y2; y++) { - float x = m * y + b; + double x = m * y + b; PutPixel((int)(x + 0.5f), (int)(y + 0.5f), c); } } } -void Graphics::DrawCircle(JC_Vector2f vO, JC_Vector2f Comp_Rad, Color c) +void Graphics::DrawCircle(JC_Point2d& P, JC_Point2d& Q, Color& c) { - DrawCircle(vO.x, vO.y, Comp_Rad.x, Comp_Rad.y, c); + DrawCircle(P.x, P.y, Q.x, Q.y, c); } -void Graphics::DrawCircle(float Ox, float Oy, float R, Color c) +void Graphics::DrawCircle(double Ox, double Oy, double R, Color& c) { if (R > 0.0) @@ -404,10 +404,10 @@ void Graphics::DrawCircle(float Ox, float Oy, float R, Color c) for (double theta = 0; theta < 360; theta += 0.2) { - float x = (float)(R * std::cos(PI_F*theta / 180)); - float y = (float)(R * std::sin(PI_F*theta / 180)); + double x = (double)(R * std::cos(PI_D*theta / 180)); + double y = (double)(R * std::sin(PI_D*theta / 180)); - PutPixel((int)(Ox), (int)(Oy),c); + PutPixel((int)(x+0.5f + Ox), (int)(y+0.5f + Oy), c); } } @@ -419,13 +419,13 @@ void Graphics::DrawCircle(float Ox, float Oy, float R, Color c) } -void Graphics::DrawCircle(float Ox, float Oy, float x1, float y1, Color c) +void Graphics::DrawCircle(double Ox, double Oy, double x1, double y1, Color& c) { - float Rx = std::abs(x1 - Ox); - float Ry = std::abs(y1 - Oy); + double Rx = std::abs(x1 - Ox); + double Ry = std::abs(y1 - Oy); //calculate radius - float R = std::sqrt(Rx*Rx + Ry * Ry); + double R = std::sqrt(Rx*Rx + Ry * Ry); DrawCircle(Ox, Oy, R, c); } @@ -487,7 +487,7 @@ bool Graphics::DrawCircle(float x1, float y1, float x2, float y2, float x3, floa //http://www.ambrsoft.com/MathCalc/Line/TwoLinesIntersection/TwoLinesIntersection.htm float x = (a - b) / (m2_perp - m1_perp); - float y = -((m2_perp * a) - (m1_perp * b)) / (m1_perp - m2_perp); + float y = ((m1_perp * b) - (m2_perp * a)) / (m1_perp - m2_perp); DrawCircle(x, y, x3, y3, c); return true; @@ -498,7 +498,7 @@ bool Graphics::DrawCircle(float x1, float y1, float x2, float y2, float x3, floa } -void Graphics::DrawArc(float Ox, float Oy, float R ,float theta_begin, float theta_end, Color c) +void Graphics::DrawArc(double Ox, double Oy, double R , double theta_begin, double theta_end, Color c) { bool theta_range = theta_end - theta_begin > 0.0; @@ -510,15 +510,14 @@ void Graphics::DrawArc(float Ox, float Oy, float R ,float theta_begin, float the } else { - for (float theta = theta_begin; + for (double theta = theta_begin; theta_range ? theta < theta_end : theta > theta_end; theta_range ? theta += 0.2 : theta -= 0.2) { - float x = (float)(R * std::cos(PI_F*theta / 180)); - float y = (float)(R * std::sin(PI_F*theta / 180)); + double x = (double)(R * std::cos(PI_F*theta / 180)); + double y = (double)(R * std::sin(PI_F*theta / 180)); - //Draw pixel at the begining of radius - PutPixel((int)(Ox), (int)(Oy), Colors::Red); + //Draw arc PutPixel((int)(x + 0.5f + Ox), (int)(y + 0.5f + Oy), c); } diff --git a/Engine/Graphics.h b/Engine/Graphics.h index eb3af238..a59865e1 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -66,51 +66,55 @@ class Graphics /***** Start Draw Line Functions *****/ template - void DrawLine(const JC_Vector2 v1, const JC_Vector2 v2, Color c) + void DrawLine(const JC_Point2& P, const JC_Point2& Q, Color c) { - DrawLine((float)v1.x, (float)v1.y, (float)v2.x, (float)v2.y, c); + DrawLine((double)P.x, (double)P.y, (double)Q.x, (double)Q.y, c); } - void DrawLine(float x1, float y1, float x2, float y2, Color c); + void DrawLine(double x1, double y1, double x2, double y2, Color c); /***** END Draw Line Functions ****/ /***** Start Draw Circle Functions *****/ template - void DrawCircle(JC_Vector2 vO, T2 R, Color c) + void DrawCircle(JC_Point2 vO, T2 R, Color c) { DrawCircle((float)vO.x, (float)vO.y, (float)R, c); } - //Copmponet Radius circle - void DrawCircle(JC_Vector2f vO, JC_Vector2f Comp_Rad,Color c); - void DrawCircle(float Ox, float Oy, float x1, float y1, Color c); - void DrawCircle(float Ox, float Oy, float R, Color c); + + void DrawCircle(JC_Point2d& P, JC_Point2d& Q, Color& c); + void DrawCircle(double Ox, double Oy, double x1, double y1, Color& c); + void DrawCircle(double Ox, double Oy, double R, Color& c); //Three point circle - - bool DrawCircle( float x1, float y1, //first point float x2, float y2, //second point float x3, float y3, //curvature direction Color c); - - /***** END Draw Circle Functions ****/ - - /*Draw Arc Functions*/ - void DrawArc(float Ox, float Oy,float R, float theta_begin,float theta_end, Color c); + + /***** Start Draw Arc Functions *****/ + + void DrawArc(double Ox, double Oy, double R, double theta_begin, double theta_end, Color c); template - void DrawArc(JC_Vector2 vO, T3 R, Color c) + void DrawArc(JC_Point2d& P, T3 R, Color c) { DrawArc((float)vO.x, (float)vO.y, (float)R, c); } + + /***** End Draw Arc Functions *****/ + - /*Elipse Drawing functions*/ + + /***** Start Draw Ellipse Functions *****/ + void DrawFlatEllipse(float Ox, float Oy, float Rx, float Ry, Color c); + /***** End Draw Ellipse Functions *****/ + ~Graphics(); private: From ce90b407885acac8ad3ce7c67290d174b651c8f1 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 10 Jun 2018 14:02:11 +0200 Subject: [PATCH 27/84] Fixed halfmemory casting prblem in x64 mode --- Engine/MainWindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Engine/MainWindow.cpp b/Engine/MainWindow.cpp index 7943c26a..2b28fca7 100644 --- a/Engine/MainWindow.cpp +++ b/Engine/MainWindow.cpp @@ -141,14 +141,14 @@ LRESULT MainWindow::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) hMenu = CreateMenu(); hSubMenu = CreatePopupMenu(); - AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"&File"); + AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, L"&File"); { AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, L"E&xit"); } hSubMenu = CreatePopupMenu(); - AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"&Stuff"); + AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, L"&Stuff"); { AppendMenu(hSubMenu, MF_STRING, ID_STUFF_GO, L"&Go"); } From 9ea58670e28c761712ba05d8186962216c8a626e Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 10 Jun 2018 18:46:53 +0200 Subject: [PATCH 28/84] Refactorisation of circle drawing and inicialisation routine --- Engine/Circle.cpp | 138 +++++++++++++++++++++++++++----------------- Engine/Circle.h | 27 +++++---- Engine/Graphics.cpp | 127 +++++++++++++++------------------------- Engine/Graphics.h | 17 +----- 4 files changed, 149 insertions(+), 160 deletions(-) diff --git a/Engine/Circle.cpp b/Engine/Circle.cpp index 7ca98371..438aefbd 100644 --- a/Engine/Circle.cpp +++ b/Engine/Circle.cpp @@ -2,77 +2,111 @@ #include "JC_Math.h" #include -Circle::Circle(const JC_Point2d& P, const JC_Point2d& Q) +Circle::Circle(const JC_Point2d& P, const JC_Point2d& Q, Color color) + : + pos(P), + radius(P.GetDistanceTo(Q)), + C(color) +{} + + + +Circle::Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Color color) + : + pos(CalculatCentre(P, Q, R)), + radius(pos.GetDistanceTo(R)), + C(color) +{} + +void Circle::Draw(Graphics & gfx) { - pos = P; - radius = CalculateRadius(P,Q); + gfx.DrawCircle(pos, radius, C); } -Circle::Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R) +/* +Circle Circle::GetCircle() +{ + selected = true; + return *this; +} +*/ +JC_Point2d Circle::CalculatCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) { - // find slope of the line created by 2 points - double m1 = 0.0f; - double m2 = 0.0f; - //when we have 2 flat lines in order under right angle - if (P.x == R.x && Q.y == R.y) { - JC_Point2d C; - C.x = (R.x + Q.x) / 2; - C.y = (P.y + R.y) / 2; - pos = C; - radius = CalculateRadius(C, R); + //when we have 2 flat lines in order under right angle + if (P.x == R.x && Q.y == R.y) + { + JC_Point2d C; + C.x = (R.x + Q.x) / 2; + C.y = (P.y + R.y) / 2; + return C; - } - //when we have 2 flat lines in reverce order under right angle - else if (P.y == R.y && Q.x == R.x) - { - JC_Point2d C; - C.x = R.x + P.x / 2; - C.y = Q.y + R.y / 2; - pos = C; - radius = CalculateRadius(C, R); - } - else if (P.x != Q.x && P.y != Q.y || Q.x != R.x && Q.y != R.y) - { - m1 = LineSlopeBetween2Points(P,R); - m2 = LineSlopeBetween2Points(Q,R); + } + //when we have 2 flat lines in reverce order under right angle + else if (P.y == R.y && Q.x == R.x) + { + JC_Point2d C; + C.x = R.x + P.x / 2; + C.y = Q.y + R.y / 2; + return C; + } + else if (P.x == R.x && Q.y != R.y) + { - //If slopes are the same lines are parallel ,do nothing (infinite radius) - if (m2 - m1 == 0.0) + JC_Point2d C = CalculateSpecificCentre(P, R, Q); + return C; + + } + else if (P.x != R.x && Q.y == R.y) { - + JC_Point2d C = CalculateSpecificCentre(R, Q, P); + return C; } - else + else //if (P.x != Q.x && P.y != Q.y || Q.x != R.x && Q.y != R.y) { - // calculate perpendicular line slope... + JC_Point2d C = CalculateSpecificCentre(P, Q, R); + return C; + + } + } +} + +JC_Point2d Circle::CalculateSpecificCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) +{ + { - double m1_perp = InverceLineSlope(m1); - double m2_perp = InverceLineSlope(m2); + double m1 = LineSlopeBetween2Points(P, R); + double m2 = LineSlopeBetween2Points(Q, R); - //mid point of orginally inserted lines + //If slopes are the same lines are parallel ,do nothing (infinite radius) + assert(m2 - m1 != 0.0); - JC_Point2d mid_PR = P.GetMidPoint(R); + // calculate perpendicular line slope... - JC_Point2d mid_QR = Q.GetMidPoint(R); + double m1_perp = InverceLineSlope(m1); + double m2_perp = InverceLineSlope(m2); + //mid point of orginally inserted lines - // y=mx+b find b part of perpendicular line - // y-y1 = m(x-x1) = > y = mx - m*x1 + y1 - //https://www.varsitytutors.com/hotmath/hotmath_help/topics/point-slope-form.html + JC_Point2d mid_PR = P.GetMidPoint(R); - double a = (-m1_perp * mid_PR.x + mid_PR.y); - double b = (-m2_perp * mid_QR.x + mid_QR.y); + JC_Point2d mid_QR = Q.GetMidPoint(R); - // find crossection - //http://www.ambrsoft.com/MathCalc/Line/TwoLinesIntersection/TwoLinesIntersection.htm - JC_Point2d C; - C.x = (a - b) / (m2_perp - m1_perp); - C.y = ((m1_perp * b) - (m2_perp * a)) / (m1_perp - m2_perp); + // y=mx+b find b part of perpendicular line + // y-y1 = m(x-x1) = > y = mx - m*x1 + y1 + //https://www.varsitytutors.com/hotmath/hotmath_help/topics/point-slope-form.html - //Calculate final circle - pos = C; - radius = CalculateRadius(C,R); - } + double a = (-m1_perp * mid_PR.x + mid_PR.y); + double b = (-m2_perp * mid_QR.x + mid_QR.y); + + // find crossection + //http://www.ambrsoft.com/MathCalc/Line/TwoLinesIntersection/TwoLinesIntersection.htm + + JC_Point2d C; + C.x = (a - b) / (m2_perp - m1_perp); + C.y = ((m1_perp * b) - (m2_perp * a)) / (m1_perp - m2_perp); + + return C; } } diff --git a/Engine/Circle.h b/Engine/Circle.h index c8b690f0..937bdee8 100644 --- a/Engine/Circle.h +++ b/Engine/Circle.h @@ -1,31 +1,30 @@ #pragma once #include "Graphics.h" -#include "Mouse.h" -#include "Colors.h" #include "JC_Vector2.h" class Circle { public: - Circle(const JC_Point2d& P, const JC_Point2d& Q); - - Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); - - - void Draw(Graphics& gfx ) - { - gfx.DrawCircle(pos, radius, C); - } - - //Circle CalculateSelect(); + Circle(const JC_Point2d& P, const JC_Point2d& Q,Color color = Colors::White); + Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Color color = Colors::White); + + void Draw(Graphics& gfx); + //void CalculateSelectCircle(const JC_Point2i& mouse_imput); +public: + JC_Point2d CalculatCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); + +private: + JC_Point2d CalculateSpecificCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); + //Circle GetCircle(); private: JC_Point2d pos; double radius; static constexpr double halfwidth = 4.0; - Color C = Colors::White; + //bool selected = false; + Color C ; }; diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index 18f10822..db0e6863 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -398,106 +398,73 @@ void Graphics::DrawCircle(JC_Point2d& P, JC_Point2d& Q, Color& c) void Graphics::DrawCircle(double Ox, double Oy, double R, Color& c) { - - if (R > 0.0) - { + /*for (double theta = 0; theta < 360; theta += 0.2) + { + double x = (double)(R * std::cos(PI_D*theta / 180)); + double y = (double)(R * std::sin(PI_D*theta / 180)); - for (double theta = 0; theta < 360; theta += 0.2) - { - double x = (double)(R * std::cos(PI_D*theta / 180)); - double y = (double)(R * std::sin(PI_D*theta / 180)); + int xi = (int)(x + 0.5f + Ox); + int yi = (int)(y + 0.5f + Oy); - - PutPixel((int)(x+0.5f + Ox), (int)(y+0.5f + Oy), c); - } - } - else - { - PutPixel(int(Ox), int(Oy), c); - } + if (xi >= 0 && xi < ScreenWidth && yi >= 0 && yi < ScreenHeight) + PutPixel(xi, yi, c); + } + */ + double x = 0.7071067811865475; -} - -void Graphics::DrawCircle(double Ox, double Oy, double x1, double y1, Color& c) -{ + double Rx = (x * R) + 0.5; - double Rx = std::abs(x1 - Ox); - double Ry = std::abs(y1 - Oy); - //calculate radius - double R = std::sqrt(Rx*Rx + Ry * Ry); - - DrawCircle(Ox, Oy, R, c); -} + double radsqr = R * R; + + //draw Circle with per pixel clipping -bool Graphics::DrawCircle(float x1, float y1, float x2, float y2, float x3, float y3, Color c) -{ - // find slope of the line created by 2 points - float m1 = 0.0f; - float m2 = 0.0f; - //when we have 2 flat lines in order - if (x1 == x3 && y2 == y3) - { - float x = (x3 + x2) / 2; - float y = (y1 + y3) / 2; - DrawCircle(x, y, x3, y3, c); - return true; - } - //when we have 2 flat lines in reverce order - else if (y1 == y3 && x2 == x3) - { - float x= x3 + x1 / 2; - float y = y2 + y3 / 2; - DrawCircle(x, y, x3, y3, c); - return true; - } - else if (x1 != x2 && y1 != y2 || x2 != x3 && y2 != y3) + for (int xi = 0; xi <= (int)Rx; xi++) { - m1 = Slope(x1, y1, x3, y3); - m2 = Slope(x2, y2, x3, y3); - - //If slopes are the same lines are parallel ,do nothing (infinite radius) - if (m2 - m1 == 0.0) - { - return false; - } - else - { - // calculate perpendicular line slope... - - float m1_perp = (-1.0f / m1); - float m2_perp = (-1.0f / m2); + int yi = (int)(std::sqrt(radsqr - (xi*xi)) + 0.5f); - //mid point of orginally inserted lines - float mid_AC_x = (x3 + x1) / 2; - float mid_AC_y = (y3 + y1) / 2; + if (Ox + xi >= 0 && Ox + xi < ScreenWidth && Oy + yi >= 0 && Oy + yi < ScreenHeight) + PutPixel((int)Ox + xi, (int)Oy + yi, c); - float mid_BC_x = (x3 + x2) / 2; - float mid_BC_y = (y3 + y2) / 2; + if (Ox + yi >= 0 && Ox + yi < ScreenWidth && Oy + xi >= 0 && Oy + xi < ScreenHeight) + PutPixel((int)Ox + yi, (int)Oy + xi, c); - // y=mx+b find b part of perpendicular line - // y-y1 = m(x-x1) = > y = mx - m*x1 + y1 - //https://www.varsitytutors.com/hotmath/hotmath_help/topics/point-slope-form.html + if (Ox -xi >= 0 && Ox -xi < ScreenWidth && Oy + yi >= 0 && Oy + yi < ScreenHeight) + PutPixel((int)Ox - xi, (int)Oy + yi, c); - float a = (-m1_perp * mid_AC_x + mid_AC_y); - float b = (-m2_perp * mid_BC_x + mid_BC_y); + if (Ox -yi >= 0 && Ox -yi < ScreenWidth && Oy + xi >= 0 && Oy + xi < ScreenHeight) + PutPixel((int)Ox - yi, (int)Oy + xi, c); - // find crossection - //http://www.ambrsoft.com/MathCalc/Line/TwoLinesIntersection/TwoLinesIntersection.htm + if (Ox -xi >= 0 && Ox -xi < ScreenWidth && Oy -yi >= 0 && Oy -yi < ScreenHeight) + PutPixel((int)Ox - xi, (int)Oy - yi, c); - float x = (a - b) / (m2_perp - m1_perp); - float y = ((m1_perp * b) - (m2_perp * a)) / (m1_perp - m2_perp); + if (Ox -yi >= 0 && Ox-yi < ScreenWidth && Oy -xi >= 0 && Oy -xi < ScreenHeight) + PutPixel((int)Ox - yi, (int)Oy - xi, c); - DrawCircle(x, y, x3, y3, c); - return true; - } + if (Ox + xi >= 0 && Ox + xi < ScreenWidth && Oy -yi >= 0 && Oy -yi < ScreenHeight) + PutPixel((int)Ox + xi, (int)Oy - yi, c); + if (Ox + yi >= 0 && Ox + yi < ScreenWidth && Oy -xi >= 0 && Oy -xi < ScreenHeight) + PutPixel((int)Ox + yi, (int)Oy - xi, c); } - return false; + + +} +void Graphics::DrawCircle(double Ox, double Oy, double x1, double y1, Color& c) +{ + + double Rx = std::abs(x1 - Ox); + double Ry = std::abs(y1 - Oy); + //calculate radius + double R = std::sqrt(Rx*Rx + Ry * Ry); + + DrawCircle(Ox, Oy, R, c); } + + void Graphics::DrawArc(double Ox, double Oy, double R , double theta_begin, double theta_end, Color c) { diff --git a/Engine/Graphics.h b/Engine/Graphics.h index a59865e1..0da21213 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -76,34 +76,23 @@ class Graphics /***** Start Draw Circle Functions *****/ + template void DrawCircle(JC_Point2 vO, T2 R, Color c) { - DrawCircle((float)vO.x, (float)vO.y, (float)R, c); + DrawCircle((double)vO.x, (double)vO.y, (double)R, c); } void DrawCircle(JC_Point2d& P, JC_Point2d& Q, Color& c); void DrawCircle(double Ox, double Oy, double x1, double y1, Color& c); void DrawCircle(double Ox, double Oy, double R, Color& c); - - //Three point circle - bool DrawCircle( - float x1, float y1, //first point - float x2, float y2, //second point - float x3, float y3, //curvature direction - Color c); - + /***** END Draw Circle Functions ****/ /***** Start Draw Arc Functions *****/ void DrawArc(double Ox, double Oy, double R, double theta_begin, double theta_end, Color c); - template - void DrawArc(JC_Point2d& P, T3 R, Color c) - { - DrawArc((float)vO.x, (float)vO.y, (float)R, c); - } /***** End Draw Arc Functions *****/ From 33a5dd469d68e3188197fe48c8541ef9228b28f5 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 10 Jun 2018 18:47:13 +0200 Subject: [PATCH 29/84] Mathematical changes --- Engine/JC_Math.h | 13 ++----------- Engine/JC_Vector2.h | 29 ++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Engine/JC_Math.h b/Engine/JC_Math.h index ee555d39..048c9bba 100644 --- a/Engine/JC_Math.h +++ b/Engine/JC_Math.h @@ -14,8 +14,6 @@ inline auto Sq(const T& x) return x * x; } -//TO DO -// function two points as parameter retuens slope of the coresponding line inline float Slope(const float x1, const float y1, const float x2, const float y2) { @@ -36,8 +34,6 @@ inline double LineSlopeBetween2Points(const JC_Point2d& P, const JC_Point2d& Q) double m = dy / dx; - - return m; } @@ -49,10 +45,5 @@ inline double InverceLineSlope(const double& m) return -1 / m; } -inline double CalculateRadius(const JC_Point2d& P, const JC_Point2d& Q) -{ - double Rx = std::abs(P.x - Q.x); - double Ry = std::abs(P.y - Q.y); - //calculate radius - return std::sqrt(Rx * Rx + Ry * Ry); -} + + diff --git a/Engine/JC_Vector2.h b/Engine/JC_Vector2.h index a9051651..5d40385b 100644 --- a/Engine/JC_Vector2.h +++ b/Engine/JC_Vector2.h @@ -103,7 +103,6 @@ class JC_Vector2 { return x * x + y * y; } - inline T GetLength() const { return std::sqrt(GetLengthSq()); @@ -140,7 +139,7 @@ class JC_Vector2 inline double Vector_Slope(const JC_Vector2& V) { - assert(V.x == 0.0f); + assert(V.x != 0.0f); float m = V.y / V.x; return m; @@ -233,10 +232,27 @@ class JC_Point2 - JC_Point2 operator*(T rhs) + inline JC_Point2 operator+(const JC_Vector2 &rhs) const { - return JC_Point2(x*rhs, y*rhs); + return JC_Point2(x + rhs.x, y + rhs.y); } + inline JC_Point2& operator+=(const JC_Vector2 &rhs) + { + return *this = *this + rhs; + + } + + + inline JC_Point2 operator- (const JC_Vector2 &rhs) const + { + return JC_Point2(x - rhs.x, y - rhs.y) + } + inline JC_Point2& operator-=(const JC_Vector2 &rhs) + { + return *this = *this - rhs; + + } + @@ -275,15 +291,14 @@ class JC_Point2 } - inline T GetDistanceToSq( const JC_Point2 &rhs) const { - return ((this->x-rhs.x) * (this->x - rhs.x) + (this->y - rhs.y) * (this->y - rhs.y)); + return (T)((this->x-rhs.x) * (this->x - rhs.x) + (this->y - rhs.y) * (this->y - rhs.y)); } inline T GetDistanceTo(const JC_Point2 &rhs) const { - return std::sqrt(GetDistanceToSq(rhs)); + return (T)std::sqrt(GetDistanceToSq(rhs)); } inline JC_Point2 GetMidPoint(const JC_Point2& rhs) const From ba392cc670ba95254fb569385135659461c39c8e Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 15 Jun 2018 03:35:55 +0200 Subject: [PATCH 30/84] Utility changes --- Engine/JC_Vector2.h | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Engine/JC_Vector2.h b/Engine/JC_Vector2.h index 5d40385b..3c4b90e8 100644 --- a/Engine/JC_Vector2.h +++ b/Engine/JC_Vector2.h @@ -20,13 +20,13 @@ class JC_Vector2 y(iny) {} - - /* - inline JC_Vector2 (const JC_Vector2& vect) + template + JC_Vector2(const JC_Vector2& src) : - JC_Vector2 (vect.x,vect.y) + x((T)src.x), + y((T)src.y) {} - */ + template explicit operator JC_Vector2() const @@ -105,7 +105,7 @@ class JC_Vector2 } inline T GetLength() const { - return std::sqrt(GetLengthSq()); + return (T)std::sqrt(GetLengthSq()); } /*Normalise operations*/ @@ -117,9 +117,9 @@ class JC_Vector2 inline JC_Vector2 GetNormalize() const { const double len = GetLength(); - if (len != 0.0) + if (len != (T)0) { - return *this * (1.0 / len); + return *this * ((T)1 / len); } return len; } @@ -172,6 +172,13 @@ class JC_Point2 JC_Point2(point.x, point.y) {} + template + JC_Point2(const JC_Point2& src) + : + x((T)src.x), + y((T)src.y) + {} + template explicit operator JC_Point2() const { @@ -180,6 +187,8 @@ class JC_Point2 } + + inline JC_Point2 operator-() { return JC_Point2(-x, -y); From dcc8172994e58a5d03d8f545fdb6815410e4b069 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 15 Jun 2018 03:36:19 +0200 Subject: [PATCH 31/84] Anoying warning fixed --- Engine/ChiliWin.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Engine/ChiliWin.h b/Engine/ChiliWin.h index afd0db71..2a88abcc 100644 --- a/Engine/ChiliWin.h +++ b/Engine/ChiliWin.h @@ -62,6 +62,8 @@ #define NOIMAGE #define NOTAPE +#ifndef STRICT #define STRICT +#endif #include \ No newline at end of file From 750d690b6b02bf7aee45c5c15675188cb1f9149e Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 15 Jun 2018 03:37:04 +0200 Subject: [PATCH 32/84] Added Coordinate trasformer to the pipeline --- Engine/Circle.cpp | 9 ++++--- Engine/Circle.h | 17 +++++++++--- Engine/CordinateTrasformerh.h | 32 +++++++++++++++++++++++ Engine/Engine.vcxproj | 1 + Engine/Engine.vcxproj.filters | 3 +++ Engine/Game.cpp | 49 ++++++----------------------------- Engine/Game.h | 18 ++++++------- 7 files changed, 70 insertions(+), 59 deletions(-) create mode 100644 Engine/CordinateTrasformerh.h diff --git a/Engine/Circle.cpp b/Engine/Circle.cpp index 438aefbd..936a2681 100644 --- a/Engine/Circle.cpp +++ b/Engine/Circle.cpp @@ -18,18 +18,19 @@ Circle::Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Co C(color) {} -void Circle::Draw(Graphics & gfx) +void Circle::Draw(CoordinateTrasformer& ct) { - gfx.DrawCircle(pos, radius, C); + ct.DrawCircle(pos, radius, C); } -/* + + Circle Circle::GetCircle() { selected = true; return *this; } -*/ + JC_Point2d Circle::CalculatCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) { { diff --git a/Engine/Circle.h b/Engine/Circle.h index 937bdee8..44cf7bd3 100644 --- a/Engine/Circle.h +++ b/Engine/Circle.h @@ -2,6 +2,7 @@ #include "Graphics.h" #include "JC_Vector2.h" +#include "CordinateTrasformerh.h" class Circle { @@ -10,21 +11,29 @@ class Circle Circle(const JC_Point2d& P, const JC_Point2d& Q,Color color = Colors::White); Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Color color = Colors::White); - void Draw(Graphics& gfx); + void Draw(CoordinateTrasformer& ct); //void CalculateSelectCircle(const JC_Point2i& mouse_imput); + Circle GetCircle(); public: JC_Point2d CalculatCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); - + double GetRadius() + { + return radius; + } + JC_Point2d GetPos() + { + return pos; + } private: JC_Point2d CalculateSpecificCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); - //Circle GetCircle(); + private: JC_Point2d pos; double radius; static constexpr double halfwidth = 4.0; - //bool selected = false; + bool selected = false; Color C ; }; diff --git a/Engine/CordinateTrasformerh.h b/Engine/CordinateTrasformerh.h new file mode 100644 index 00000000..8379ee1b --- /dev/null +++ b/Engine/CordinateTrasformerh.h @@ -0,0 +1,32 @@ +#pragma once + +#include "Graphics.h" +#include "Colors.h" +#include "JC_Vector2.h" + + +class CoordinateTrasformer +{ +public: + + CoordinateTrasformer (Graphics& gfx) + : + gfx(gfx) + {} + + void DrawCircle(JC_Point2d pos, double radius, Color c) + { + JC_Vector2d offset = { double(Graphics::ScreenWidth / 2),double(Graphics::ScreenHeight / 2) }; + + pos.y *= -1.0; + pos += offset; + + gfx.DrawCircle(pos, radius, c); + } + +private: + Graphics& gfx; + + + +}; \ No newline at end of file diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index 78c62a3d..5723023f 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -141,6 +141,7 @@ + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index 1506572b..ed0a644d 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -75,6 +75,9 @@ Header Files + + Header Files + diff --git a/Engine/Game.cpp b/Engine/Game.cpp index a6ca6b5f..18f1e041 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -28,10 +28,11 @@ Game::Game(MainWindow& wnd) : wnd(wnd), gfx(wnd), - P (600,450), - Q(840,450), - R (720,330) + ct(gfx) { + circles.emplace_back(JC_Point2d{ 0,0 }, JC_Point2d{ 300,300 }); + circles.emplace_back(JC_Point2d{ 600,450 }, JC_Point2d{ 840,450 },JC_Point2d{ 720,330 }); + circles.emplace_back(JC_Point2d{ 200,200 }, JC_Point2d{ 300,300 }, JC_Point2d{ 400,450 }); } void Game::Go() @@ -52,7 +53,7 @@ void Game::UpdateModel() { input++; - if (input <= 2) + if (input >= 2) input = 0; } } @@ -62,44 +63,10 @@ void Game::UpdateModel() } void Game::ComposeFrame() - -{ /* - if (wnd.mouse.LeftIsPressed()) - { - gfx.DrawLine((float)wnd.mouse.GetPosX(), (float)wnd.mouse.GetPosY(), 840, 330, Colors::White); - gfx.DrawLine((float)wnd.mouse.GetPosX(), (float)wnd.mouse.GetPosY(), 600, 570, Colors::White); - gfx.DrawCircle(600, 570, 840, 330, (float)wnd.mouse.GetPosX(), (float)wnd.mouse.GetPosY(), Colors::White); - } - else - { - gfx.DrawLine(600, 330, 840, 330, Colors::White); - gfx.DrawLine(600, 330, 600, 570, Colors::White); - gfx.DrawCircle(600, 570, 840, 330,600,330 , Colors::White); - } - - - if (wnd.mouse.LeftIsPressed()) - { - gfx.DrawLine(600, 450, (float)wnd.mouse.GetPosX(), (float)wnd.mouse.GetPosY(), Colors::White); - gfx.DrawLine(840, 450, (float)wnd.mouse.GetPosX(), (float)wnd.mouse.GetPosY(), Colors::White); - gfx.DrawCircle(600, 450, 840, 450, (float)wnd.mouse.GetPosX(), (float)wnd.mouse.GetPosY(), Colors::White); - } - else - { - gfx.DrawLine(600, 450, 720, 600, Colors::White); - gfx.DrawLine(840, 450, 720, 600, Colors::White); - gfx.DrawCircle(600, 450, 840, 450, 720, 600, Colors::White); - } - */ - - circles.emplace_back(P, Q); - circles.emplace_back(P, Q, R); - - for (auto i : circles) +{ + for (auto c : circles) { - i.Draw(gfx); + c.Draw(ct); } - P.GetDistanceTo(Q); - } diff --git a/Engine/Game.h b/Engine/Game.h index f464ec45..9e67a03f 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -25,7 +25,8 @@ #include "Graphics.h" #include "JC_Vector2.h" #include "Circle.h" - +#include "CordinateTrasformerh.h" +//#include "boost\any.hpp" class Game @@ -36,12 +37,7 @@ class Game Game& operator=( const Game& ) = delete; void Go(); - enum class Shapes - { - Circle2Point, - Circle3point, - FlatEllipse - }; + private: void ComposeFrame(); @@ -54,10 +50,12 @@ class Game Graphics gfx; /********************************/ /* User Variables */ + CoordinateTrasformer ct; + + std::vector circles; - Shapes shapes = Shapes::Circle2Point; - JC_Point2d P, Q, R; - int input = 0; + //std::vector selected; + unsigned short input = 0; /********************************/ }; \ No newline at end of file From 9797e9ddc0f58126fbdfd39625fe8affac88da79 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Tue, 19 Jun 2018 23:06:29 +0200 Subject: [PATCH 33/84] Vector class was rewriten --- Engine/Circle.cpp | 11 +- Engine/Circle.h | 12 +- Engine/JC_Vector2.h | 661 +++++++++++++++++++++++++++----------------- 3 files changed, 425 insertions(+), 259 deletions(-) diff --git a/Engine/Circle.cpp b/Engine/Circle.cpp index 936a2681..8a3693bb 100644 --- a/Engine/Circle.cpp +++ b/Engine/Circle.cpp @@ -5,7 +5,7 @@ Circle::Circle(const JC_Point2d& P, const JC_Point2d& Q, Color color) : pos(P), - radius(P.GetDistanceTo(Q)), + radius(GetDistanceTo(P,Q)), C(color) {} @@ -14,7 +14,7 @@ Circle::Circle(const JC_Point2d& P, const JC_Point2d& Q, Color color) Circle::Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Color color) : pos(CalculatCentre(P, Q, R)), - radius(pos.GetDistanceTo(R)), + radius(GetDistanceTo(pos,R)), C(color) {} @@ -24,12 +24,13 @@ void Circle::Draw(CoordinateTrasformer& ct) } - +/* Circle Circle::GetCircle() { selected = true; return *this; } +*/ JC_Point2d Circle::CalculatCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) { @@ -89,9 +90,9 @@ JC_Point2d Circle::CalculateSpecificCentre(const JC_Point2d & P, const JC_Point2 //mid point of orginally inserted lines - JC_Point2d mid_PR = P.GetMidPoint(R); + JC_Point2d mid_PR = GetMidPoint(P,R); - JC_Point2d mid_QR = Q.GetMidPoint(R); + JC_Point2d mid_QR = GetMidPoint(Q,R); // y=mx+b find b part of perpendicular line diff --git a/Engine/Circle.h b/Engine/Circle.h index 44cf7bd3..840aceb9 100644 --- a/Engine/Circle.h +++ b/Engine/Circle.h @@ -4,6 +4,7 @@ #include "JC_Vector2.h" #include "CordinateTrasformerh.h" + class Circle { public: @@ -14,18 +15,19 @@ class Circle void Draw(CoordinateTrasformer& ct); //void CalculateSelectCircle(const JC_Point2i& mouse_imput); - Circle GetCircle(); + //Circle GetCircle(); public: JC_Point2d CalculatCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); - double GetRadius() + + double GetRadius()const { return radius; - } - JC_Point2d GetPos() + } + JC_Point2d GetPos()const { return pos; - } + } private: JC_Point2d CalculateSpecificCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); diff --git a/Engine/JC_Vector2.h b/Engine/JC_Vector2.h index 3c4b90e8..2c52620a 100644 --- a/Engine/JC_Vector2.h +++ b/Engine/JC_Vector2.h @@ -1,3 +1,165 @@ + + +#pragma once + +#include +#include + +template struct JC_Point2 +{ + JC_Point2() {}; + JC_Point2(T xin, T yin) + : + x(xin), + y(yin) + {} + T x, y; +}; +template struct JC_Vector2 +{ + JC_Vector2() {}; + JC_Vector2( T xin, T yin) + : + x(xin), + y(yin) + {} + T x, y; +}; + +using JC_Point2d = JC_Point2; +using JC_Point2f = JC_Point2; +using JC_Point2i = JC_Point2; + +using JC_Vector2d = JC_Vector2; +using JC_Vector2f = JC_Vector2; +using JC_Vector2i = JC_Vector2; + + +template JC_Vector2& operator+=(JC_Vector2& lhs, const JC_Vector2& rhs) +{ + lhs.x += rhs.x; + lhs.y += rhs.y; + + return lhs; +} +template JC_Point2& operator+=(JC_Point2& lhs, const JC_Vector2& rhs) +{ + lhs.x += rhs.x; + lhs.y += rhs.y; + + return lhs; +} + +template JC_Vector2& operator-=(JC_Vector2& lhs, const JC_Vector2& rhs) +{ + lhs.x -= rhs.x; + lhs.y -= rhs.y; + + return lhs; +} +template JC_Point2& operator-=(JC_Point2& lhs, const JC_Vector2& rhs) +{ + lhs.x -= rhs.x; + lhs.y -= rhs.y; + + return lhs; +} +template JC_Vector2& operator*=(JC_Vector2& v, T s) +{ + v.x *= s; + v.y *= s; + return v; +} +template JC_Vector2& operator/=(JC_Vector2& v, T s) +{ + v.x /= s; + v.y /= s; + return v; +} +template JC_Vector2 operator+(const JC_Vector2& lhs, const JC_Vector2& rhs) +{ + return JC_Vector2(lhs) += rhs; +} +template JC_Point2 operator+(const JC_Point2& lhs, const JC_Vector2& rhs) +{ + return { lhs.x + rhs.x, lhs.y + rhs.y }; + +} +template T operator-(const T& lhs) +{ + return T(-lhs.x, -lhs.y); +} + +template JC_Vector2 operator-(const JC_Vector2& lhs, const JC_Vector2& rhs) +{ + return JC_Vector2(lhs) -= rhs; +} +template JC_Point2 operator-(const JC_Point2& lhs, const JC_Vector2& rhs) +{ + return JC_Point2(lhs) -= rhs; +} +template JC_Vector2 operator-(const JC_Point2& lhs, const JC_Point2& rhs) +{ + return { lhs.x - rhs.x, lhs.y - rhs.y }; +} +template JC_Vector2 operator*(const JC_Vector2& v, T s) +{ + return { v.x * s, v.y * s }; +} +template JC_Vector2 operator*(T s, const JC_Vector2& v) +{ + return JC_Vector2(v) *= s; +} +template JC_Vector2 operator/(const JC_Vector2& v, T s) +{ + return { v.x / s,v.y / s }; +} + +template T dot_product(const JC_Vector2& v0, const JC_Vector2& v1) +{ + return (v0.x * v1.x) + (v0.y + v1.y); +} +template T length_sq(const JC_Vector2& v) +{ + return dot_product(v, v); +} +template T length(const JC_Vector2& v) +{ + return T(std::sqrt(double(length_sq(v)))); +} +template JC_Vector2 normalize(const JC_Vector2& v) +{ + const auto len = length(v); + if (std::is_floating_point_v) + { + return (len == T(0)) ? v : v * (T(1) / len); + } + + return (len == 0) ? v : v / len; +} + + + +template T GetDistanceToSq(const JC_Point2& v0, const JC_Point2& v1) +{ + return ((v1.x - v0.x)*(v1.x - v0.x)+ (v1.y - v0.y)*(v1.y - v0.y)); +} +template T GetDistanceTo(const JC_Point2& v0, const JC_Point2& v1) +{ + return std::sqrt(GetDistanceToSq(v0, v1)); +} +template JC_Point2 GetMidPoint(const JC_Point2& v0, const JC_Point2& v1) +{ + auto v = v1 - v0; + v = (std::is_floating_point_v) ? + v * T(.5) : + v / T(2); + + return v0 + v; +} + + +/* #pragma once #include @@ -7,144 +169,143 @@ template class JC_Vector2 { public: - T x; - T y; +T x; +T y; public: - inline JC_Vector2(){} - inline JC_Vector2(T inx, T iny) - : - x(inx), - y(iny) - {} +inline JC_Vector2(){} +inline JC_Vector2(T inx, T iny) +: +x(inx), +y(iny) +{} + +template +JC_Vector2(const JC_Vector2& src) +: +x((T)src.x), +y((T)src.y) +{} + + +template +explicit operator JC_Vector2() const +{ +return { T2 x,T2 y }; +} - template - JC_Vector2(const JC_Vector2& src) - : - x((T)src.x), - y((T)src.y) - {} - - template - explicit operator JC_Vector2() const - { - return { T2 x,T2 y }; - } +template +inline JC_Vector2(const PointType& P , const PointType& Q) +: +JC_Vector2(P.x-Q.x , P.y-Q.y) +{} - template - inline JC_Vector2(const PointType& P , const PointType& Q) - : - JC_Vector2(P.x-Q.x , P.y-Q.y) - {} - +//Vector Vector Operators - /*Vector Vector Operators*/ +inline JC_Vector2 operator-() +{ +return JC_Vector2(-x, -y); +} - inline JC_Vector2 operator-() - { - return JC_Vector2(-x, -y); - } - /* - inline JC_Vector2 operator= (const JC_Vector2 &rhs) - { - x = rhs.x; - y = rhs.y; - return *this; - } - */ - - inline JC_Vector2 operator-(const JC_Vector2 &rhs)const - { - return JC_Vector2(x - rhs.x , y - rhs.y); - } - inline JC_Vector2& operator-=(const JC_Vector2 &rhs) - { - return *this = *this - rhs; +//inline JC_Vector2 operator= (const JC_Vector2 &rhs) +//{ +// x = rhs.x; +// y = rhs.y; +// return *this; +//} - } +inline JC_Vector2 operator-(const JC_Vector2 &rhs)const +{ +return JC_Vector2(x - rhs.x , y - rhs.y); +} +inline JC_Vector2& operator-=(const JC_Vector2 &rhs) +{ +return *this = *this - rhs; - inline JC_Vector2 operator+(const JC_Vector2 &rhs)const - { - return JC_Vector2(x + rhs.x, y + rhs.y); - } - inline JC_Vector2& operator+=(const JC_Vector2 &rhs) - { - return *this = *this + rhs; - } +} - /*Vector scalar operators*/ +inline JC_Vector2 operator+(const JC_Vector2 &rhs)const +{ +return JC_Vector2(x + rhs.x, y + rhs.y); +} +inline JC_Vector2& operator+=(const JC_Vector2 &rhs) +{ +return *this = *this + rhs; +} - inline JC_Vector2 operator*(const T rhs) const - { - return JC_Vector2(x * rhs, y * rhs); - } - inline JC_Vector2& operator*=(const T rhs) - { - return *this = *this * rhs; - } +//Vector scalar operators - inline JC_Vector2 operator/(const T rhs) const - { - return JC_Vector2(x / rhs, y / rhs); - } - inline JC_Vector2& operator/=(const T rhs) - { - return *this = *this / rhs; - } +inline JC_Vector2 operator*(const T rhs) const +{ +return JC_Vector2(x * rhs, y * rhs); +} +inline JC_Vector2& operator*=(const T rhs) +{ +return *this = *this * rhs; +} - /*Lenght operations*/ +inline JC_Vector2 operator/(const T rhs) const +{ +return JC_Vector2(x / rhs, y / rhs); +} +inline JC_Vector2& operator/=(const T rhs) +{ +return *this = *this / rhs; +} - inline T GetLengthSq() const - { - return x * x + y * y; - } - inline T GetLength() const - { - return (T)std::sqrt(GetLengthSq()); - } +//Lenght operations - /*Normalise operations*/ +inline T GetLengthSq() const +{ +return x * x + y * y; +} +inline T GetLength() const +{ +return (T)std::sqrt(GetLengthSq()); +} - inline JC_Vector2& Normalize() - { - return *this = GetNormalize(); - } - inline JC_Vector2 GetNormalize() const - { - const double len = GetLength(); - if (len != (T)0) - { - return *this * ((T)1 / len); - } - return len; - } +//Normalise operations - /*Boolean operators*/ +inline JC_Vector2& Normalize() +{ +return *this = GetNormalize(); +} +inline JC_Vector2 GetNormalize() const +{ +const double len = GetLength(); +if (len != (T)0) +{ +return *this * ((T)1 / len); +} +return len; +} - inline bool operator==(const JC_Vector2 &rhs)const - { - return (x == rhs.x && y== rhs.y) ; - } - - inline bool operator!=(const JC_Vector2 &rhs)const - { - return (x != rhs.x || y != rhs.y); - } +//Boolean operators - inline double Vector_Slope(const JC_Vector2& V) - { +inline bool operator==(const JC_Vector2 &rhs)const +{ +return (x == rhs.x && y== rhs.y) ; +} + +inline bool operator!=(const JC_Vector2 &rhs)const +{ +return (x != rhs.x || y != rhs.y); +} - assert(V.x != 0.0f); - float m = V.y / V.x; - - return m; +inline double Vector_Slope(const JC_Vector2& V) +{ - } +assert(V.x != 0.0f); +float m = V.y / V.x; + +return m; + +} }; @@ -157,179 +318,179 @@ template class JC_Point2 { public: - T x; - T y; +T x; +T y; public: - inline JC_Point2() {} - inline JC_Point2(T inx, T iny) - : - x(inx), - y(iny) - {} - inline JC_Point2(const JC_Point2& point) - : - JC_Point2(point.x, point.y) - {} - - template - JC_Point2(const JC_Point2& src) - : - x((T)src.x), - y((T)src.y) - {} +inline JC_Point2() {} +inline JC_Point2(T inx, T iny) +: +x(inx), +y(iny) +{} +inline JC_Point2(const JC_Point2& point) +: +JC_Point2(point.x, point.y) +{} + +template +JC_Point2(const JC_Point2& src) +: +x((T)src.x), +y((T)src.y) +{} + +template +explicit operator JC_Point2() const +{ +return { T2 x,T2 y }; - template - explicit operator JC_Point2() const - { - return { T2 x,T2 y }; +} - } +inline JC_Point2 operator-() +{ +return JC_Point2(-x, -y); +} +inline JC_Point2 operator= (const JC_Point2 &rhs) +{ +x = rhs.x; +y = rhs.y; +return *this; +} - inline JC_Point2 operator-() - { - return JC_Point2(-x, -y); - } - inline JC_Point2 operator= (const JC_Point2 &rhs) - { - x = rhs.x; - y = rhs.y; - return *this; - } +inline JC_Point2 operator+(const JC_Point2 &rhs) const +{ +return JC_Point2(x + rhs.x, y + rhs.y); +} +inline JC_Point2& operator+=(const JC_Point2 &rhs) +{ +return *this = *this + rhs; - inline JC_Point2 operator+(const JC_Point2 &rhs) const - { - return JC_Point2(x + rhs.x, y + rhs.y); - } - inline JC_Point2& operator+=(const JC_Point2 &rhs) - { - return *this = *this + rhs; +} - } +inline JC_Point2 operator- (const JC_Point2 &rhs) const +{ +return JC_Point2(x - rhs.x, y - rhs.y) +} +inline JC_Point2& operator-=(const JC_Point2 &rhs) +{ +return *this = *this - rhs; - inline JC_Point2 operator- (const JC_Point2 &rhs) const - { - return JC_Point2(x - rhs.x, y - rhs.y) - } - inline JC_Point2& operator-=(const JC_Point2 &rhs) - { - return *this = *this - rhs; +} - } +inline JC_Point2 operator*(const T rhs) const +{ +return JC_Point2(x * rhs, y * rhs); +} +inline JC_Point2& operator*=(const T rhs) +{ +return *this = *this * rhs; +} - inline JC_Point2 operator*(const T rhs) const - { - return JC_Point2(x * rhs, y * rhs); - } - inline JC_Point2& operator*=(const T rhs) - { - return *this = *this * rhs; - } +inline JC_Point2 operator/(const T rhs) const +{ +return JC_Point2(x / rhs, y / rhs); +} +inline JC_Point2& operator/=(const T rhs) +{ +return *this = *this / rhs; +} - inline JC_Point2 operator/(const T rhs) const - { - return JC_Point2(x / rhs, y / rhs); - } - inline JC_Point2& operator/=(const T rhs) - { - return *this = *this / rhs; - } - - inline JC_Point2 operator+(const JC_Vector2 &rhs) const - { - return JC_Point2(x + rhs.x, y + rhs.y); - } - inline JC_Point2& operator+=(const JC_Vector2 &rhs) - { - return *this = *this + rhs; +inline JC_Point2 operator+(const JC_Vector2 &rhs) const +{ +return JC_Point2(x + rhs.x, y + rhs.y); +} +inline JC_Point2& operator+=(const JC_Vector2 &rhs) +{ +return *this = *this + rhs; - } +} - inline JC_Point2 operator- (const JC_Vector2 &rhs) const - { - return JC_Point2(x - rhs.x, y - rhs.y) - } - inline JC_Point2& operator-=(const JC_Vector2 &rhs) - { - return *this = *this - rhs; +inline JC_Point2 operator- (const JC_Vector2 &rhs) const +{ +return JC_Point2(x - rhs.x, y - rhs.y); +} +inline JC_Point2& operator-=(const JC_Vector2 &rhs) +{ +return *this = *this - rhs; - } +} - bool operator==(const JC_Point2 &rhs) const - { - return (x == rhs.x && y == rhs.y) ? true : false; - } +bool operator==(const JC_Point2 &rhs) const +{ +return (x == rhs.x && y == rhs.y) ? true : false; +} - bool operator!=(const JC_Point2 &rhs) const - { - return (x != rhs.x || y != rhs.y); - } +bool operator!=(const JC_Point2 &rhs) const +{ +return (x != rhs.x || y != rhs.y); +} - bool operator<=(const JC_Point2 &rhs) const - { - // dictionary order - return ((x < rhs.x) ? true : ((x == rhs.x && y <= rhs.y) ? true : false)); - } +bool operator<=(const JC_Point2 &rhs) const +{ +// dictionary order +return ((x < rhs.x) ? true : ((x == rhs.x && y <= rhs.y) ? true : false)); +} - bool operator>=(const JC_Point2 &rhs) const - { - // dictionary order - return ((x > rhs.x) ? true : ((x == rhs.x && y >= rhs.y) ? true : false)); - } +bool operator>=(const JC_Point2 &rhs) const +{ +// dictionary order +return ((x > rhs.x) ? true : ((x == rhs.x && y >= rhs.y) ? true : false)); +} - bool operator<(const JC_Point2 &rhs) const - { - // dictionary order - return ((x < rhs.x) ? true : ((x == rhs.x && y < rhs.y) ? true : false)); - } +bool operator<(const JC_Point2 &rhs) const +{ +// dictionary order +return ((x < rhs.x) ? true : ((x == rhs.x && y < rhs.y) ? true : false)); +} - bool operator>(const JC_Point2 &rhs) const - { - // dictionary order - return ((x > rhs.x) ? true : ((x == rhs.x && y > rhs.y) ? true : false)); - } +bool operator>(const JC_Point2 &rhs) const +{ +// dictionary order +return ((x > rhs.x) ? true : ((x == rhs.x && y > rhs.y) ? true : false)); +} - inline T GetDistanceToSq( const JC_Point2 &rhs) const - { - return (T)((this->x-rhs.x) * (this->x - rhs.x) + (this->y - rhs.y) * (this->y - rhs.y)); - } +inline T GetDistanceToSq( const JC_Point2 &rhs) const +{ +return (T)((this->x-rhs.x) * (this->x - rhs.x) + (this->y - rhs.y) * (this->y - rhs.y)); +} - inline T GetDistanceTo(const JC_Point2 &rhs) const - { - return (T)std::sqrt(GetDistanceToSq(rhs)); - } +inline T GetDistanceTo(const JC_Point2 &rhs) const +{ +return (T)std::sqrt(GetDistanceToSq(rhs)); +} - inline JC_Point2 GetMidPoint(const JC_Point2& rhs) const - { - return JC_Point2((*this+rhs)/2); - } +inline JC_Point2 GetMidPoint(const JC_Point2& rhs) const +{ +return JC_Point2((*this+rhs)/2); +} - inline void Zero() - { - x = y = 0.0; - } +inline void Zero() +{ +x = y = 0.0; +} - inline bool IsZero() const - { - return (x == 0.0 && y == 0.0); - } +inline bool IsZero() const +{ +return (x == 0.0 && y == 0.0); +} - inline bool IsNotZero() const - { - // the && (x == x && y == y) insures no coordinate is a Nan. - return (x != 0.0 || y != 0.0) && (x == x && y == y); - } +inline bool IsNotZero() const +{ +// the && (x == x && y == y) insures no coordinate is a Nan. +return (x != 0.0 || y != 0.0) && (x == x && y == y); +} }; @@ -337,3 +498,5 @@ class JC_Point2 typedef JC_Point2 JC_Point2d; typedef JC_Point2 JC_Point2f; typedef JC_Point2 JC_Point2i; +*/ + From c45e0ab429faad587a8d98c289f11c6501684a64 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Tue, 19 Jun 2018 23:07:42 +0200 Subject: [PATCH 34/84] Added coordinate trasformer and Star --- Engine/CordinateTrasformerh.h | 15 +++++++++++++++ Engine/Engine.vcxproj | 1 + Engine/Engine.vcxproj.filters | 3 +++ Engine/Game.cpp | 9 ++++++--- Engine/Game.h | 10 +++++++--- Engine/Graphics.cpp | 10 ++++++++++ Engine/Graphics.h | 9 ++++++--- Engine/Star.h | 26 ++++++++++++++++++++++++++ 8 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 Engine/Star.h diff --git a/Engine/CordinateTrasformerh.h b/Engine/CordinateTrasformerh.h index 8379ee1b..c16c0516 100644 --- a/Engine/CordinateTrasformerh.h +++ b/Engine/CordinateTrasformerh.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "Graphics.h" #include "Colors.h" #include "JC_Vector2.h" @@ -24,6 +26,19 @@ class CoordinateTrasformer gfx.DrawCircle(pos, radius, c); } + + void DrawClosedPolyline(std::vector poly, Color c) + { + JC_Vector2d offset = { double(Graphics::ScreenWidth / 2),double(Graphics::ScreenHeight / 2) }; + for (auto& v : poly) + { + v.y *= -1.0; + v += offset; + } + gfx.DrawClosedPolyline(poly, c); + } + + private: Graphics& gfx; diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index 5723023f..fd9c55f5 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -153,6 +153,7 @@ + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index ed0a644d..0265cc3a 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -78,6 +78,9 @@ Header Files + + Header Files\Shapes + diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 18f1e041..75b257b0 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -20,7 +20,6 @@ ******************************************************************************************/ #include "MainWindow.h" #include "Game.h" -#include "JC_Vector2.h" #include "Mouse.h" @@ -31,8 +30,10 @@ Game::Game(MainWindow& wnd) ct(gfx) { circles.emplace_back(JC_Point2d{ 0,0 }, JC_Point2d{ 300,300 }); - circles.emplace_back(JC_Point2d{ 600,450 }, JC_Point2d{ 840,450 },JC_Point2d{ 720,330 }); + circles.emplace_back(JC_Point2d{ 100,0 }, JC_Point2d{ 0,100 },JC_Point2d{ 0,0 }); circles.emplace_back(JC_Point2d{ 200,200 }, JC_Point2d{ 300,300 }, JC_Point2d{ 400,450 }); + + } void Game::Go() @@ -68,5 +69,7 @@ void Game::ComposeFrame() { c.Draw(ct); } - + + ct.DrawClosedPolyline(Star::Make(200, 75.0,7), Colors::Red); } + diff --git a/Engine/Game.h b/Engine/Game.h index 9e67a03f..a3feecca 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -23,10 +23,13 @@ #include "Keyboard.h" #include "Mouse.h" #include "Graphics.h" +#include "CordinateTrasformerh.h" + #include "JC_Vector2.h" #include "Circle.h" -#include "CordinateTrasformerh.h" -//#include "boost\any.hpp" +#include "Star.h" + + class Game @@ -54,7 +57,8 @@ class Game std::vector circles; - //std::vector selected; + + unsigned short input = 0; /********************************/ diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index db0e6863..6e5e8d25 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -346,6 +346,16 @@ void Graphics::PutPixel( int x,int y,Color c ) pSysBuffer[Graphics::ScreenWidth * y + x] = c; } + +void Graphics::DrawClosedPolyline(const std::vector& verts, Color c) +{ + for (auto i = verts.begin(); i != std::prev(verts.end()); i++) + { + DrawLine(*i, *std::next(i), c); + } + DrawLine(verts.back(), verts.front(), c); +} + void Graphics::DrawLine(double x1, double y1, double x2, double y2, Color c) { const double dx = x2 - x1; diff --git a/Engine/Graphics.h b/Engine/Graphics.h index 0da21213..0dfac2a9 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -22,6 +22,7 @@ #include #include #include +#include #include "ChiliWin.h" #include "ChiliException.h" @@ -62,13 +63,15 @@ class Graphics PutPixel( x,y,{ unsigned char( r ),unsigned char( g ),unsigned char( b ) } ); } void PutPixel( int x,int y,Color c ); + + void DrawClosedPolyline(const std::vector& verts, Color c); /***** Start Draw Line Functions *****/ - template - void DrawLine(const JC_Point2& P, const JC_Point2& Q, Color c) + + void DrawLine(const JC_Point2d& P, const JC_Point2d& Q, Color c) { - DrawLine((double)P.x, (double)P.y, (double)Q.x, (double)Q.y, c); + DrawLine(P.x, P.y, Q.x, Q.y, c); } void DrawLine(double x1, double y1, double x2, double y2, Color c); diff --git a/Engine/Star.h b/Engine/Star.h new file mode 100644 index 00000000..2494b5a2 --- /dev/null +++ b/Engine/Star.h @@ -0,0 +1,26 @@ +#pragma once + + +#include +#include "JC_Vector2.h" +#include "JC_Math.h" + +class Star +{ +public: + static std::vector Make(float outerRadius, float innerRadius, int nFlares = 5) + { + std::vector star; + star.reserve(nFlares * 2); + const double dTheta = 2.0f * PI_D / double(nFlares * 2); + for (int i = 0; i < nFlares * 2; i++) + { + const double rad = (i % 2 == 0) ? outerRadius : innerRadius; + star.emplace_back( + rad * cos(double(i) * dTheta), + rad * sin(double(i) * dTheta) + ); + } + return star; + } +}; \ No newline at end of file From 55ca4ce790ec80fde5802abbf5b98310a633855f Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Thu, 21 Jun 2018 20:56:23 +0200 Subject: [PATCH 35/84] Changed return value for get pos --- Engine/Mouse.cpp | 2 +- Engine/Mouse.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Engine/Mouse.cpp b/Engine/Mouse.cpp index 3e44e0d3..ef7e179a 100644 --- a/Engine/Mouse.cpp +++ b/Engine/Mouse.cpp @@ -21,7 +21,7 @@ #include "Mouse.h" -JC_Vector2i Mouse::GetPos() const +JC_Point2i Mouse::GetPos() const { return { x,y }; } diff --git a/Engine/Mouse.h b/Engine/Mouse.h index 37bb14c2..e4bb4e6e 100644 --- a/Engine/Mouse.h +++ b/Engine/Mouse.h @@ -96,7 +96,7 @@ class Mouse Mouse() = default; Mouse( const Mouse& ) = delete; Mouse& operator=( const Mouse& ) = delete; - JC_Vector2i GetPos() const; + JC_Point2i GetPos() const; int GetPosX() const; int GetPosY() const; bool LeftIsPressed() const; From 83bc5e6d9bec7b547547979582619288932476ae Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 22 Jun 2018 18:48:24 +0200 Subject: [PATCH 36/84] Deleted un used functions --- Engine/Graphics.cpp | 13 ------------- Engine/Graphics.h | 3 +-- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index 6e5e8d25..8e15fcec 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -401,10 +401,6 @@ void Graphics::DrawLine(double x1, double y1, double x2, double y2, Color c) } } -void Graphics::DrawCircle(JC_Point2d& P, JC_Point2d& Q, Color& c) -{ - DrawCircle(P.x, P.y, Q.x, Q.y, c); -} void Graphics::DrawCircle(double Ox, double Oy, double R, Color& c) { @@ -462,16 +458,7 @@ void Graphics::DrawCircle(double Ox, double Oy, double R, Color& c) } -void Graphics::DrawCircle(double Ox, double Oy, double x1, double y1, Color& c) -{ - - double Rx = std::abs(x1 - Ox); - double Ry = std::abs(y1 - Oy); - //calculate radius - double R = std::sqrt(Rx*Rx + Ry * Ry); - DrawCircle(Ox, Oy, R, c); -} diff --git a/Engine/Graphics.h b/Engine/Graphics.h index 0dfac2a9..ab37efdb 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -86,8 +86,7 @@ class Graphics DrawCircle((double)vO.x, (double)vO.y, (double)R, c); } - void DrawCircle(JC_Point2d& P, JC_Point2d& Q, Color& c); - void DrawCircle(double Ox, double Oy, double x1, double y1, Color& c); + void DrawCircle(double Ox, double Oy, double R, Color& c); /***** END Draw Circle Functions ****/ From d12c6c28fd057921d4bab34b978f4df5c9c8a06d Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 22 Jun 2018 18:48:37 +0200 Subject: [PATCH 37/84] Code for state machine --- Engine/Game.cpp | 71 +++++++++++++++++++++++++++++++++++++++++-------- Engine/Game.h | 20 +++++++++----- 2 files changed, 74 insertions(+), 17 deletions(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 75b257b0..2eca074b 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -21,6 +21,7 @@ #include "MainWindow.h" #include "Game.h" #include "Mouse.h" +#include "CordinateTrasformerh.h" Game::Game(MainWindow& wnd) @@ -29,10 +30,12 @@ Game::Game(MainWindow& wnd) gfx(wnd), ct(gfx) { - circles.emplace_back(JC_Point2d{ 0,0 }, JC_Point2d{ 300,300 }); - circles.emplace_back(JC_Point2d{ 100,0 }, JC_Point2d{ 0,100 },JC_Point2d{ 0,0 }); - circles.emplace_back(JC_Point2d{ 200,200 }, JC_Point2d{ 300,300 }, JC_Point2d{ 400,450 }); + //circles.emplace_back(JC_Point2d{ 0,0 }, JC_Point2d{ 300,300 }); + //circles.emplace_back(JC_Point2d{ 100,0 }, JC_Point2d{ 0,100 },JC_Point2d{ 0,0 }); + //circles.emplace_back(JC_Point2d{ 200,200 }, JC_Point2d{ 300,300 }, JC_Point2d{ 400,450 }); + + //circles.emplace_back(JC_Point2d{ -100,0 }, JC_Point2d{ 100,0 }, JC_Point2d{ 0,100 },Colors::Magenta); } @@ -46,20 +49,66 @@ void Game::Go() void Game::UpdateModel() { - while (!wnd.mouse.IsEmpty()) + switch (shape) { - const auto e = wnd.mouse.Read(); - - if (e.GetType() == Mouse::Event::Type::LPress) + case Shape::TwoPointCircle : { - input++; + while (!wnd.mouse.IsEmpty()) + { + const auto e = wnd.mouse.Read(); + + if (e.GetType() == Mouse::Event::Type::LPress) + { + if (input == 0) + { + P.x = (double)wnd.mouse.GetPosX(); + P.y = (double)wnd.mouse.GetPosY(); + engaged = true; + P = ct.CreatePoint(P); + } + if (input == 1) + { + Q.x = (double)wnd.mouse.GetPosX(); + Q.y = (double)wnd.mouse.GetPosY(); + Q = ct.CreatePoint(Q); + circles.emplace_back(P, Q); + } + + input++; + + if (input >= 2) + { + input = 0; + engaged = false; + } + + + } + if (e.GetType() == Mouse::Event::Type::RPress) + { + input = 0; + engaged = false; + } - if (input >= 2) - input = 0; + } + if (engaged) + { + Q.x = (double)wnd.mouse.GetPosX(); + Q.y = (double)wnd.mouse.GetPosY(); + Q = ct.CreatePoint(Q); + ct.DrawCircle(P, GetDistanceTo(P, Q), Colors::Red); + } + break; } - } + } + if (wnd.kbd.KeyIsPressed(VK_ESCAPE)) + { + input = 0; + Shape::Null; + } + } diff --git a/Engine/Game.h b/Engine/Game.h index a3feecca..fd3e2a60 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -30,8 +30,6 @@ #include "Star.h" - - class Game { public: @@ -40,13 +38,23 @@ class Game Game& operator=( const Game& ) = delete; void Go(); + enum class Shape + { + Null, + TwoPointCircle, + ThreePointCircle, + Count + }; + Shape shape = Shape::Null; - private: void ComposeFrame(); void UpdateModel(); /********************************/ /* User Functions */ + + + /********************************/ private: MainWindow& wnd; @@ -54,12 +62,12 @@ class Game /********************************/ /* User Variables */ CoordinateTrasformer ct; - - std::vector circles; + unsigned short input = 0; + bool engaged = false; - unsigned short input = 0; + JC_Point2d P, Q, R; /********************************/ }; \ No newline at end of file From 3a76bb4169e653e70c623ae07f088876cf32be1e Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 22 Jun 2018 18:49:28 +0200 Subject: [PATCH 38/84] State machine continuation --- Engine/CordinateTrasformerh.h | 8 ++++++++ Engine/MainWindow.cpp | 9 +++++---- Engine/Resource.h | Bin 1014 -> 1040 bytes 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Engine/CordinateTrasformerh.h b/Engine/CordinateTrasformerh.h index c16c0516..bc0d1aa5 100644 --- a/Engine/CordinateTrasformerh.h +++ b/Engine/CordinateTrasformerh.h @@ -38,6 +38,14 @@ class CoordinateTrasformer gfx.DrawClosedPolyline(poly, c); } + template JC_Point2 CreatePoint(JC_Point2 input ) + { + JC_Vector2d offset = { (T)(Graphics::ScreenWidth / 2), (T)(Graphics::ScreenHeight / 2) }; + + input -= offset; + input.y *= -1; + return input; + } private: Graphics& gfx; diff --git a/Engine/MainWindow.cpp b/Engine/MainWindow.cpp index 2b28fca7..77647f5a 100644 --- a/Engine/MainWindow.cpp +++ b/Engine/MainWindow.cpp @@ -148,9 +148,9 @@ LRESULT MainWindow::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) hSubMenu = CreatePopupMenu(); - AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, L"&Stuff"); + AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, L"&Shapes"); { - AppendMenu(hSubMenu, MF_STRING, ID_STUFF_GO, L"&Go"); + AppendMenu(hSubMenu, MF_STRING, ID_SHAPES_TwoPointCircle, L"&Circle from 2 points"); } SetMenu(hWnd, hMenu); @@ -164,8 +164,9 @@ LRESULT MainWindow::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) case ID_FILE_EXIT: PostMessage(hWnd, WM_CLOSE, 0, 0); break; - case ID_STUFF_GO: - ShowMessageBox(L"You clicked Go!", L"Woo!"); + case ID_SHAPES_TwoPointCircle: + //Game::Shape::TwoPointCircle; + ShowMessageBox(L"Info",L"Enter 2 Points"); break; } diff --git a/Engine/Resource.h b/Engine/Resource.h index f4d9a81607d7ac9e32f4e440661597c532cad12c..995a76763f3cf79757549bba37466a9146b77a54 100644 GIT binary patch delta 62 zcmeyyK7nJyEoL(h21kYf23Lk)hIob$hH{2{ATOUGlOd0xguxj|7cnF= Date: Sun, 24 Jun 2018 23:42:08 +0200 Subject: [PATCH 39/84] Calling circle form pop up menu implemented --- Engine/Game.cpp | 8 ++++---- Engine/Game.h | 9 +-------- Engine/MainWindow.cpp | 4 ++-- Engine/MainWindow.h | 9 +++++++++ 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 2eca074b..77f2547a 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -49,9 +49,9 @@ void Game::Go() void Game::UpdateModel() { - switch (shape) + switch (wnd.shape) { - case Shape::TwoPointCircle : + case MainWindow::Shape::TwoPointCircle : { while (!wnd.mouse.IsEmpty()) { @@ -100,13 +100,13 @@ void Game::UpdateModel() } break; } - + break; } if (wnd.kbd.KeyIsPressed(VK_ESCAPE)) { input = 0; - Shape::Null; + wnd.shape = MainWindow::Shape::Null; } diff --git a/Engine/Game.h b/Engine/Game.h index fd3e2a60..253916a2 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -38,14 +38,7 @@ class Game Game& operator=( const Game& ) = delete; void Go(); - enum class Shape - { - Null, - TwoPointCircle, - ThreePointCircle, - Count - }; - Shape shape = Shape::Null; + private: void ComposeFrame(); diff --git a/Engine/MainWindow.cpp b/Engine/MainWindow.cpp index 77647f5a..69693cc3 100644 --- a/Engine/MainWindow.cpp +++ b/Engine/MainWindow.cpp @@ -165,8 +165,8 @@ LRESULT MainWindow::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) PostMessage(hWnd, WM_CLOSE, 0, 0); break; case ID_SHAPES_TwoPointCircle: - //Game::Shape::TwoPointCircle; - ShowMessageBox(L"Info",L"Enter 2 Points"); + shape = Shape::TwoPointCircle ; + ShowMessageBox(L"Info",L"Create circle form 2 points"); break; } diff --git a/Engine/MainWindow.h b/Engine/MainWindow.h index f45db5c4..58b3144e 100644 --- a/Engine/MainWindow.h +++ b/Engine/MainWindow.h @@ -50,6 +50,15 @@ class MainWindow : public HWNDKey virtual std::wstring GetExceptionType() const override { return L"Windows Exception"; } }; public: + enum class Shape + { + Null, + TwoPointCircle, + ThreePointCircle, + Count + }; + Shape shape = Shape::Null; + MainWindow( HINSTANCE hInst,wchar_t* pArgs ); MainWindow( const MainWindow& ) = delete; MainWindow& operator=( const MainWindow& ) = delete; From fca212f6cce7c4c3bcee336f9dc0620354b29266 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Wed, 27 Jun 2018 21:23:44 +0200 Subject: [PATCH 40/84] fixed CT point coordinate conversion template bug --- Engine/CordinateTrasformerh.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Engine/CordinateTrasformerh.h b/Engine/CordinateTrasformerh.h index bc0d1aa5..554ce75a 100644 --- a/Engine/CordinateTrasformerh.h +++ b/Engine/CordinateTrasformerh.h @@ -40,8 +40,7 @@ class CoordinateTrasformer template JC_Point2 CreatePoint(JC_Point2 input ) { - JC_Vector2d offset = { (T)(Graphics::ScreenWidth / 2), (T)(Graphics::ScreenHeight / 2) }; - + JC_Vector2 offset = { (T)(Graphics::ScreenWidth / 2), (T)(Graphics::ScreenHeight / 2) }; input -= offset; input.y *= -1; return input; From 731571a7d99f1dc5b96813b596db08106e86ccf3 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Wed, 27 Jun 2018 21:32:09 +0200 Subject: [PATCH 41/84] Circe drawing and selecting routine fully functional --- Engine/Circle.cpp | 48 +++++++++++++++++++++++++++++++++++++++++----- Engine/Circle.h | 30 +++++++++++++++++------------ Engine/Game.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++----- Engine/Game.h | 2 ++ 4 files changed, 107 insertions(+), 22 deletions(-) diff --git a/Engine/Circle.cpp b/Engine/Circle.cpp index 8a3693bb..dd17e7af 100644 --- a/Engine/Circle.cpp +++ b/Engine/Circle.cpp @@ -23,14 +23,30 @@ void Circle::Draw(CoordinateTrasformer& ct) ct.DrawCircle(pos, radius, C); } +void Circle::UpdateColor() +{ + if (selectedflag) + C = Colors::Yellow; + else + C = Colors::White; +} + +void Circle::SetSelectionFlag(const JC_Point2i& mousein) +{ + JC_Point2d mouseind; + mouseind.x = (double)mousein.x; + mouseind.y = (double)mousein.y; + double distance = GetDistanceTo(pos, mouseind); + if (distance <= (radius + halfwidth)&& + distance >= (radius - halfwidth)) + selectedflag = true; +} -/* -Circle Circle::GetCircle() +void Circle::ResetSelectionFlag() { - selected = true; - return *this; + selectedflag = false; } -*/ + JC_Point2d Circle::CalculatCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) { @@ -73,6 +89,28 @@ JC_Point2d Circle::CalculatCentre(const JC_Point2d & P, const JC_Point2d & Q, co } } +double Circle::GetRadius() const +{ + + return radius; + +} + +JC_Point2d Circle::GetPos() const +{ + return pos; +} + + + +void Circle::SetRemovalFlag() +{ + removalflag = true; + +} + + + JC_Point2d Circle::CalculateSpecificCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) { { diff --git a/Engine/Circle.h b/Engine/Circle.h index 840aceb9..1b12425c 100644 --- a/Engine/Circle.h +++ b/Engine/Circle.h @@ -13,21 +13,22 @@ class Circle Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Color color = Colors::White); void Draw(CoordinateTrasformer& ct); - - //void CalculateSelectCircle(const JC_Point2i& mouse_imput); - //Circle GetCircle(); + void UpdateColor(); + + void SetSelectionFlag(const JC_Point2i& mousein); + void ResetSelectionFlag(); public: JC_Point2d CalculatCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); - double GetRadius()const - { - return radius; - } - JC_Point2d GetPos()const - { - return pos; - } + double GetRadius()const; + JC_Point2d GetPos()const; + + + void SetRemovalFlag(); + + + private: JC_Point2d CalculateSpecificCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); @@ -35,7 +36,12 @@ class Circle JC_Point2d pos; double radius; static constexpr double halfwidth = 4.0; - bool selected = false; + bool selectedflag = false; + bool removalflag = false; Color C ; }; +// if (flag == true) +//{ +// +//} \ No newline at end of file diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 77f2547a..26d7fad9 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -42,12 +42,13 @@ Game::Game(MainWindow& wnd) void Game::Go() { gfx.BeginFrame(); + ProcesInput(); UpdateModel(); ComposeFrame(); gfx.EndFrame(); } -void Game::UpdateModel() +void Game::ProcesInput() { switch (wnd.shape) { @@ -100,25 +101,63 @@ void Game::UpdateModel() } break; } + case MainWindow::Shape::Null: + { + while (!wnd.mouse.IsEmpty()) + { + const auto e = wnd.mouse.Read(); + + if (e.GetType() == Mouse::Event::Type::LPress) + { + for (auto i = circles.begin() , j = circles.end(); i != j; ++i) + { + + i->SetSelectionFlag(ct.CreatePoint(wnd.mouse.GetPos())); + + } + } + + + } + break; + } break; } if (wnd.kbd.KeyIsPressed(VK_ESCAPE)) { - input = 0; + wnd.shape = MainWindow::Shape::Null; + + input = 0; + + for (auto &c : circles) + { + c.ResetSelectionFlag(); + } + } +} + + +void Game::UpdateModel() +{ + + for (auto &c : circles) + { + c.UpdateColor(); } - } + + void Game::ComposeFrame() { - for (auto c : circles) + for (auto &c : circles) { c.Draw(ct); } - ct.DrawClosedPolyline(Star::Make(200, 75.0,7), Colors::Red); + //ct.DrawClosedPolyline(Star::Make(200, 75.0,7), Colors::Red); } diff --git a/Engine/Game.h b/Engine/Game.h index 253916a2..9fb7be27 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -43,6 +43,7 @@ class Game private: void ComposeFrame(); void UpdateModel(); + void ProcesInput(); /********************************/ /* User Functions */ @@ -61,6 +62,7 @@ class Game bool engaged = false; JC_Point2d P, Q, R; + JC_Point2i T; /********************************/ }; \ No newline at end of file From 960c244c48edbedf2a6af56185fedbd0f178c39c Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 29 Jun 2018 03:24:42 +0200 Subject: [PATCH 42/84] added circle erasing functionality thanx chili --- Engine/ChiliUtil.h | 13 +++++++++++++ Engine/Circle.cpp | 25 +++++-------------------- Engine/Circle.h | 12 +++--------- Engine/Engine.vcxproj | 1 + Engine/Engine.vcxproj.filters | 3 +++ Engine/Game.cpp | 19 +++++++++---------- 6 files changed, 34 insertions(+), 39 deletions(-) create mode 100644 Engine/ChiliUtil.h diff --git a/Engine/ChiliUtil.h b/Engine/ChiliUtil.h new file mode 100644 index 00000000..4bfeff77 --- /dev/null +++ b/Engine/ChiliUtil.h @@ -0,0 +1,13 @@ +#pragma once + +// uses remove_if to remove elements matching predicate over entire container +// and then calls erase to remove the 'empty' husks at the end +template +void remove_erase_if(Container& container, Pred pred) +{ + // this destroys all elements matching the predicate + // and fills the spaces with elements from the end + const auto new_end = std::remove_if(container.begin(), container.end(), pred); + // erase garbage husk element at end + container.erase(new_end, container.end()); +} \ No newline at end of file diff --git a/Engine/Circle.cpp b/Engine/Circle.cpp index dd17e7af..de9b62bc 100644 --- a/Engine/Circle.cpp +++ b/Engine/Circle.cpp @@ -47,6 +47,11 @@ void Circle::ResetSelectionFlag() selectedflag = false; } +bool Circle::ReadyForRemoval() const +{ + return selectedflag; +} + JC_Point2d Circle::CalculatCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) { @@ -89,26 +94,6 @@ JC_Point2d Circle::CalculatCentre(const JC_Point2d & P, const JC_Point2d & Q, co } } -double Circle::GetRadius() const -{ - - return radius; - -} - -JC_Point2d Circle::GetPos() const -{ - return pos; -} - - - -void Circle::SetRemovalFlag() -{ - removalflag = true; - -} - JC_Point2d Circle::CalculateSpecificCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) diff --git a/Engine/Circle.h b/Engine/Circle.h index 1b12425c..6aa9c819 100644 --- a/Engine/Circle.h +++ b/Engine/Circle.h @@ -18,16 +18,11 @@ class Circle void SetSelectionFlag(const JC_Point2i& mousein); void ResetSelectionFlag(); + bool ReadyForRemoval() const; + public: JC_Point2d CalculatCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); - - double GetRadius()const; - JC_Point2d GetPos()const; - - - void SetRemovalFlag(); - - + private: JC_Point2d CalculateSpecificCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); @@ -37,7 +32,6 @@ class Circle double radius; static constexpr double halfwidth = 4.0; bool selectedflag = false; - bool removalflag = false; Color C ; }; diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index fd9c55f5..f6d95444 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -145,6 +145,7 @@ + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index 0265cc3a..b4a0affb 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -81,6 +81,9 @@ Header Files\Shapes + + Header Files + diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 26d7fad9..2c6f2e55 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -22,21 +22,16 @@ #include "Game.h" #include "Mouse.h" #include "CordinateTrasformerh.h" +#include "ChiliUtil.h" +#include Game::Game(MainWindow& wnd) : wnd(wnd), gfx(wnd), ct(gfx) -{ - //circles.emplace_back(JC_Point2d{ 0,0 }, JC_Point2d{ 300,300 }); - //circles.emplace_back(JC_Point2d{ 100,0 }, JC_Point2d{ 0,100 },JC_Point2d{ 0,0 }); - //circles.emplace_back(JC_Point2d{ 200,200 }, JC_Point2d{ 300,300 }, JC_Point2d{ 400,450 }); - - - //circles.emplace_back(JC_Point2d{ -100,0 }, JC_Point2d{ 100,0 }, JC_Point2d{ 0,100 },Colors::Magenta); - +{ } void Game::Go() @@ -136,17 +131,21 @@ void Game::ProcesInput() c.ResetSelectionFlag(); } } + + if (wnd.kbd.KeyIsPressed(VK_DELETE)) + { + remove_erase_if(circles, std::mem_fn(&Circle::ReadyForRemoval)); + + } } void Game::UpdateModel() { - for (auto &c : circles) { c.UpdateColor(); } - } From e717aa239a37089eba38862f35c2a93eaf549ab2 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 1 Jul 2018 11:23:32 +0200 Subject: [PATCH 43/84] Conversion equals operator --- Engine/Game.cpp | 11 +++++------ Engine/JC_Vector2.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 2c6f2e55..dcaab0be 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -57,15 +57,15 @@ void Game::ProcesInput() { if (input == 0) { - P.x = (double)wnd.mouse.GetPosX(); - P.y = (double)wnd.mouse.GetPosY(); + + P = wnd.mouse.GetPos(); engaged = true; P = ct.CreatePoint(P); } if (input == 1) { - Q.x = (double)wnd.mouse.GetPosX(); - Q.y = (double)wnd.mouse.GetPosY(); + + Q = wnd.mouse.GetPos(); Q = ct.CreatePoint(Q); circles.emplace_back(P, Q); } @@ -89,8 +89,7 @@ void Game::ProcesInput() } if (engaged) { - Q.x = (double)wnd.mouse.GetPosX(); - Q.y = (double)wnd.mouse.GetPosY(); + Q = wnd.mouse.GetPos(); Q = ct.CreatePoint(Q); ct.DrawCircle(P, GetDistanceTo(P, Q), Colors::Red); } diff --git a/Engine/JC_Vector2.h b/Engine/JC_Vector2.h index 2c52620a..608364a1 100644 --- a/Engine/JC_Vector2.h +++ b/Engine/JC_Vector2.h @@ -13,6 +13,23 @@ template struct JC_Point2 x(xin), y(yin) {} + + + //templateexplicit JC_Point2(const JC_Point2& other) + // : + // x(T(other.x)), y(T(other.y)) + //{} + + // point to point conversion equals operator + template + JC_Point2& operator=(const JC_Point2& other) + { + x = T(other.x); + y = T(other.y); + return *this; + } + + T x, y; }; template struct JC_Vector2 @@ -23,6 +40,24 @@ template struct JC_Vector2 x(xin), y(yin) {} + + + // vector to vector conversion equals operator + template + JC_Vector2& operator=(const JC_Vector2& other) + { + x = T(other.x); + y = T(other.y); + return *this; + } + + + //templateexplicit JC_Vector2(const JC_Vector2& other) + // : + // x(T(other.x)), y(T(other.y)) + //{} + + T x, y; }; From ab28a879b75c276378329254ecd68332dc5ce5ab Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Wed, 4 Jul 2018 19:47:47 +0200 Subject: [PATCH 44/84] Aded -= += operators for points and enabled constructor point/vector conversions --- Engine/JC_Vector2.h | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/Engine/JC_Vector2.h b/Engine/JC_Vector2.h index 608364a1..9035a75c 100644 --- a/Engine/JC_Vector2.h +++ b/Engine/JC_Vector2.h @@ -13,13 +13,7 @@ template struct JC_Point2 x(xin), y(yin) {} - - //templateexplicit JC_Point2(const JC_Point2& other) - // : - // x(T(other.x)), y(T(other.y)) - //{} - // point to point conversion equals operator template JC_Point2& operator=(const JC_Point2& other) @@ -28,8 +22,12 @@ template struct JC_Point2 y = T(other.y); return *this; } + + templateexplicit JC_Point2(const JC_Point2& other) + : + x(T(other.x)), y(T(other.y)) + {} - T x, y; }; template struct JC_Vector2 @@ -40,8 +38,7 @@ template struct JC_Vector2 x(xin), y(yin) {} - - + // vector to vector conversion equals operator template JC_Vector2& operator=(const JC_Vector2& other) @@ -85,6 +82,15 @@ template JC_Point2& operator+=(JC_Point2& lhs, const JC_Vector2 JC_Point2& operator+=(JC_Point2& lhs, const JC_Point2& rhs) +{ + lhs.x += rhs.x; + lhs.y += rhs.y; + + return lhs; +} + + template JC_Vector2& operator-=(JC_Vector2& lhs, const JC_Vector2& rhs) { lhs.x -= rhs.x; @@ -99,6 +105,15 @@ template JC_Point2& operator-=(JC_Point2& lhs, const JC_Vector2 JC_Point2& operator-=(JC_Point2& lhs, const JC_Point2& rhs) +{ + lhs.x -= rhs.x; + lhs.y -= rhs.y; + + return lhs; +} + template JC_Vector2& operator*=(JC_Vector2& v, T s) { v.x *= s; From 8b22e870ef2e71383a95cfd99fd245473a2fc450 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Wed, 4 Jul 2018 20:10:11 +0200 Subject: [PATCH 45/84] Added camera trasformations to the pipeline (via arrow keys) Refactorisation of game files and circle class to allow mannipulations Moved create point to camera renamed as trasfrom point --- Engine/Camera.h | 57 ++++++++++++++++++ Engine/Circle.cpp | 11 ++-- Engine/Circle.h | 13 ++-- Engine/CordinateTrasformerh.h | 10 +--- Engine/Engine.vcxproj | 1 + Engine/Engine.vcxproj.filters | 12 +++- Engine/Game.cpp | 110 ++++++++++++++++++++-------------- Engine/Game.h | 4 ++ 8 files changed, 146 insertions(+), 72 deletions(-) create mode 100644 Engine/Camera.h diff --git a/Engine/Camera.h b/Engine/Camera.h new file mode 100644 index 00000000..5d04ccbb --- /dev/null +++ b/Engine/Camera.h @@ -0,0 +1,57 @@ +#pragma once + +#include "CordinateTrasformerh.h" +#include "JC_Vector2.h" + +//Camera class should be responsible for scaling onad trafromation of the drawn objects +//It is the part of the screen pipeline + +class Camera +{ +public: + Camera (CoordinateTrasformer& ct) + : + ct(ct) + {} + + JC_Point2d GetPos()const + { + return Camera_Pos; + } + + void MoveBy(const JC_Vector2d& offset) + { + Camera_Pos += offset; + } + + void MoweTo(const JC_Point2d pos_in) + { + Camera_Pos = pos_in; + } + + + void DrawCircle(JC_Point2d pos, double radius, Color c) + { + pos -= Camera_Pos; + ct.DrawCircle(std::move(pos), std::move(radius), c); + } + + + // trasforms Point screen coordinates to mathematical coordinates regardles from cmaera position + + template JC_Point2 TrasformPoint(JC_Point2 input) + { + input.x += (T)(Camera_Pos.x); + input.y -= (T)(Camera_Pos.y); + + JC_Vector2 offset = { (T)(Graphics::ScreenWidth / 2), (T)(Graphics::ScreenHeight / 2) }; + input -= offset; + input.y *= -1; + return input; + } + +private: + JC_Point2d Camera_Pos = { 0.0,0.0 }; + CoordinateTrasformer& ct; + +}; \ No newline at end of file diff --git a/Engine/Circle.cpp b/Engine/Circle.cpp index de9b62bc..5225bcd2 100644 --- a/Engine/Circle.cpp +++ b/Engine/Circle.cpp @@ -18,9 +18,9 @@ Circle::Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Co C(color) {} -void Circle::Draw(CoordinateTrasformer& ct) +void Circle::Draw(Camera cam) { - ct.DrawCircle(pos, radius, C); + cam.DrawCircle(pos, radius, C); } void Circle::UpdateColor() @@ -31,12 +31,9 @@ void Circle::UpdateColor() C = Colors::White; } -void Circle::SetSelectionFlag(const JC_Point2i& mousein) +void Circle::SetSelectionFlag(const JC_Point2d& mousein) { - JC_Point2d mouseind; - mouseind.x = (double)mousein.x; - mouseind.y = (double)mousein.y; - double distance = GetDistanceTo(pos, mouseind); + double distance = GetDistanceTo(pos, mousein); if (distance <= (radius + halfwidth)&& distance >= (radius - halfwidth)) selectedflag = true; diff --git a/Engine/Circle.h b/Engine/Circle.h index 6aa9c819..cf7a9b28 100644 --- a/Engine/Circle.h +++ b/Engine/Circle.h @@ -2,7 +2,7 @@ #include "Graphics.h" #include "JC_Vector2.h" -#include "CordinateTrasformerh.h" +#include "Camera.h" class Circle @@ -12,10 +12,10 @@ class Circle Circle(const JC_Point2d& P, const JC_Point2d& Q,Color color = Colors::White); Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Color color = Colors::White); - void Draw(CoordinateTrasformer& ct); + void Draw(Camera cam); void UpdateColor(); - void SetSelectionFlag(const JC_Point2i& mousein); + void SetSelectionFlag(const JC_Point2d& mousein); void ResetSelectionFlag(); bool ReadyForRemoval() const; @@ -33,9 +33,4 @@ class Circle static constexpr double halfwidth = 4.0; bool selectedflag = false; Color C ; -}; - -// if (flag == true) -//{ -// -//} \ No newline at end of file +}; \ No newline at end of file diff --git a/Engine/CordinateTrasformerh.h b/Engine/CordinateTrasformerh.h index 554ce75a..8c240000 100644 --- a/Engine/CordinateTrasformerh.h +++ b/Engine/CordinateTrasformerh.h @@ -26,7 +26,7 @@ class CoordinateTrasformer gfx.DrawCircle(pos, radius, c); } - + void DrawClosedPolyline(std::vector poly, Color c) { JC_Vector2d offset = { double(Graphics::ScreenWidth / 2),double(Graphics::ScreenHeight / 2) }; @@ -38,13 +38,7 @@ class CoordinateTrasformer gfx.DrawClosedPolyline(poly, c); } - template JC_Point2 CreatePoint(JC_Point2 input ) - { - JC_Vector2 offset = { (T)(Graphics::ScreenWidth / 2), (T)(Graphics::ScreenHeight / 2) }; - input -= offset; - input.y *= -1; - return input; - } + private: Graphics& gfx; diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index f6d95444..d2af1e28 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -136,6 +136,7 @@ + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index b4a0affb..779a1f38 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -25,6 +25,9 @@ {a1ba54ce-e6f2-47b3-93dd-e28c6615d142} + + {991129b5-249e-4da4-bad5-8426e98a3a3c} + @@ -75,15 +78,18 @@ Header Files - - Header Files - Header Files\Shapes Header Files + + Header Files\CameraPipeline + + + Header Files\CameraPipeline + diff --git a/Engine/Game.cpp b/Engine/Game.cpp index dcaab0be..420db187 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -30,7 +30,8 @@ Game::Game(MainWindow& wnd) : wnd(wnd), gfx(wnd), - ct(gfx) + ct(gfx), + cam(ct) { } @@ -47,54 +48,54 @@ void Game::ProcesInput() { switch (wnd.shape) { - case MainWindow::Shape::TwoPointCircle : + case MainWindow::Shape::TwoPointCircle: + { + while (!wnd.mouse.IsEmpty()) { - while (!wnd.mouse.IsEmpty()) - { - const auto e = wnd.mouse.Read(); + const auto e = wnd.mouse.Read(); - if (e.GetType() == Mouse::Event::Type::LPress) + if (e.GetType() == Mouse::Event::Type::LPress) + { + if (input == 0) { - if (input == 0) - { - - P = wnd.mouse.GetPos(); - engaged = true; - P = ct.CreatePoint(P); - } - if (input == 1) - { - - Q = wnd.mouse.GetPos(); - Q = ct.CreatePoint(Q); - circles.emplace_back(P, Q); - } - - input++; - - if (input >= 2) - { - input = 0; - engaged = false; - } + P = wnd.mouse.GetPos(); + engaged = true; + P = cam.TrasformPoint(P); + } + if (input == 1) + { + Q = wnd.mouse.GetPos(); + Q = cam.TrasformPoint(Q); + circles.emplace_back(P, Q); } - if (e.GetType() == Mouse::Event::Type::RPress) + + input++; + + if (input >= 2) { input = 0; engaged = false; } + } - if (engaged) + if (e.GetType() == Mouse::Event::Type::RPress) { - Q = wnd.mouse.GetPos(); - Q = ct.CreatePoint(Q); - ct.DrawCircle(P, GetDistanceTo(P, Q), Colors::Red); + input = 0; + engaged = false; } - break; + + } + if (engaged) + { + Q = wnd.mouse.GetPos(); + Q = cam.TrasformPoint(Q); + cam.DrawCircle(P, GetDistanceTo(P, Q), Colors::Red); } + break; + } case MainWindow::Shape::Null: { while (!wnd.mouse.IsEmpty()) @@ -103,28 +104,28 @@ void Game::ProcesInput() if (e.GetType() == Mouse::Event::Type::LPress) { - for (auto i = circles.begin() , j = circles.end(); i != j; ++i) + for (auto i = circles.begin(), j = circles.end(); i != j; ++i) { - - i->SetSelectionFlag(ct.CreatePoint(wnd.mouse.GetPos())); - + + i->SetSelectionFlag(static_cast(cam.TrasformPoint(wnd.mouse.GetPos()))); + } } - + } break; } - break; + break; } if (wnd.kbd.KeyIsPressed(VK_ESCAPE)) { - + wnd.shape = MainWindow::Shape::Null; - + input = 0; - + for (auto &c : circles) { c.ResetSelectionFlag(); @@ -135,7 +136,26 @@ void Game::ProcesInput() { remove_erase_if(circles, std::mem_fn(&Circle::ReadyForRemoval)); - } + } + + const float speed = 3.0f; + if (wnd.kbd.KeyIsPressed(VK_DOWN)) + { + cam.MoveBy({ 0.0f,-speed }); + } + if (wnd.kbd.KeyIsPressed(VK_UP)) + { + cam.MoveBy({ 0.0f,speed }); + } + if (wnd.kbd.KeyIsPressed(VK_LEFT)) + { + cam.MoveBy({ -speed,0.0f }); + } + if (wnd.kbd.KeyIsPressed(VK_RIGHT)) + { + cam.MoveBy({ speed,0.0f }); + } + } @@ -153,7 +173,7 @@ void Game::ComposeFrame() { for (auto &c : circles) { - c.Draw(ct); + c.Draw(cam); } //ct.DrawClosedPolyline(Star::Make(200, 75.0,7), Colors::Red); diff --git a/Engine/Game.h b/Engine/Game.h index 9fb7be27..f51ae643 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -24,6 +24,8 @@ #include "Mouse.h" #include "Graphics.h" #include "CordinateTrasformerh.h" +#include "Camera.h" + #include "JC_Vector2.h" #include "Circle.h" @@ -56,6 +58,8 @@ class Game /********************************/ /* User Variables */ CoordinateTrasformer ct; + Camera cam; + std::vector circles; unsigned short input = 0; From 623f09cdc585f6d26151643d9d9fb7d10aa62357 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Wed, 4 Jul 2018 21:40:03 +0200 Subject: [PATCH 46/84] Re edited Return type for mouse get pos --- Engine/Mouse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/Mouse.h b/Engine/Mouse.h index e4bb4e6e..aefb6339 100644 --- a/Engine/Mouse.h +++ b/Engine/Mouse.h @@ -71,7 +71,7 @@ class Mouse { return type; } - std::pair GetPos() const + JC_Point2i GetPos() const { return{ x,y }; } From 1191191d1811469b930ed903a7c1ac5209164f1a Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Wed, 4 Jul 2018 21:55:54 +0200 Subject: [PATCH 47/84] VIP Camera mouse controling and scaling entites --- Chili Framework 2016.sln | 11 +++++--- Engine/Camera.h | 11 ++++++++ Engine/Engine.vcxproj | 1 + Engine/Engine.vcxproj.filters | 3 +++ Engine/Game.cpp | 3 ++- Engine/Game.h | 4 +-- Engine/MouseCameraControler.h | 51 +++++++++++++++++++++++++++++++++++ 7 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 Engine/MouseCameraControler.h diff --git a/Chili Framework 2016.sln b/Chili Framework 2016.sln index 7351d448..b2e8bd8a 100644 --- a/Chili Framework 2016.sln +++ b/Chili Framework 2016.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.27703.2035 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Engine", "Engine\Engine.vcxproj", "{FFCA512B-49FC-4FC8-8A73-C4F87D322FF2}" EndProject @@ -15,8 +15,8 @@ Global GlobalSection(ProjectConfigurationPlatforms) = postSolution {FFCA512B-49FC-4FC8-8A73-C4F87D322FF2}.Debug|x64.ActiveCfg = Debug|x64 {FFCA512B-49FC-4FC8-8A73-C4F87D322FF2}.Debug|x64.Build.0 = Debug|x64 - {FFCA512B-49FC-4FC8-8A73-C4F87D322FF2}.Debug|x86.ActiveCfg = Debug|Win32 - {FFCA512B-49FC-4FC8-8A73-C4F87D322FF2}.Debug|x86.Build.0 = Debug|Win32 + {FFCA512B-49FC-4FC8-8A73-C4F87D322FF2}.Debug|x86.ActiveCfg = Debug|x64 + {FFCA512B-49FC-4FC8-8A73-C4F87D322FF2}.Debug|x86.Build.0 = Debug|x64 {FFCA512B-49FC-4FC8-8A73-C4F87D322FF2}.Release|x64.ActiveCfg = Release|x64 {FFCA512B-49FC-4FC8-8A73-C4F87D322FF2}.Release|x64.Build.0 = Release|x64 {FFCA512B-49FC-4FC8-8A73-C4F87D322FF2}.Release|x86.ActiveCfg = Release|Win32 @@ -25,4 +25,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8E96B628-7273-433B-B7CE-8284E30105BC} + EndGlobalSection EndGlobal diff --git a/Engine/Camera.h b/Engine/Camera.h index 5d04ccbb..b8c4b9c9 100644 --- a/Engine/Camera.h +++ b/Engine/Camera.h @@ -50,7 +50,18 @@ class Camera return input; } + void SetScale(double new_scale) + { + scale = new_scale; + } + + double GetScale() const + { + return scale; + } + private: + double scale = 1.0; JC_Point2d Camera_Pos = { 0.0,0.0 }; CoordinateTrasformer& ct; diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index d2af1e28..48d5bd56 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -152,6 +152,7 @@ + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index 779a1f38..c826427a 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -90,6 +90,9 @@ Header Files\CameraPipeline + + Header Files\CameraPipeline + diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 420db187..ad462fb8 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -31,7 +31,8 @@ Game::Game(MainWindow& wnd) wnd(wnd), gfx(wnd), ct(gfx), - cam(ct) + cam(ct), + camCtrl(wnd.mouse,cam) { } diff --git a/Engine/Game.h b/Engine/Game.h index f51ae643..fa52664a 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -25,7 +25,7 @@ #include "Graphics.h" #include "CordinateTrasformerh.h" #include "Camera.h" - +#include "MouseCameraControler.h" #include "JC_Vector2.h" #include "Circle.h" @@ -59,7 +59,7 @@ class Game /* User Variables */ CoordinateTrasformer ct; Camera cam; - + MouseCameraController camCtrl; std::vector circles; unsigned short input = 0; diff --git a/Engine/MouseCameraControler.h b/Engine/MouseCameraControler.h new file mode 100644 index 00000000..a22f077e --- /dev/null +++ b/Engine/MouseCameraControler.h @@ -0,0 +1,51 @@ +#pragma once +#include "Camera.h" +#include "Mouse.h" + +class MouseCameraController +{ +public: + MouseCameraController(Mouse& mouse, Camera& cam) + : + mouse(mouse), + cam(cam) + {} + void UpdateInput() + { + while (!mouse.IsEmpty()) + { + const auto e = mouse.Read(); + switch (e.GetType()) + { + case Mouse::Event::Type::LPress: + engaged = true; + lastPos = e.GetPos(); + break; + case Mouse::Event::Type::LRelease: + engaged = false; + break; + case Mouse::Event::Type::WheelUp: + cam.SetScale(cam.GetScale() * zoomFactor); + break; + case Mouse::Event::Type::WheelDown: + cam.SetScale(cam.GetScale() / zoomFactor); + break; + } + } + + if (engaged) + { + const auto curPos = (JC_Point2d)mouse.GetPos(); + auto delta = curPos - lastPos; + delta.x = -delta.x; // fixes the disconnect between screen coords and math coords + cam.MoveBy(delta / cam.GetScale()); + lastPos = curPos; + } + } +private: + static constexpr float zoomFactor = 1.05f; + bool engaged = false; + JC_Point2d lastPos; + Mouse& mouse; + Camera& cam; +}; \ No newline at end of file From a57bce1891d6348302d681c425babb3f89892604 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Wed, 4 Jul 2018 23:18:36 +0200 Subject: [PATCH 48/84] Added missing piace of documentation --- Engine/Camera.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Engine/Camera.h b/Engine/Camera.h index b8c4b9c9..73bef59e 100644 --- a/Engine/Camera.h +++ b/Engine/Camera.h @@ -41,7 +41,8 @@ class Camera template JC_Point2 TrasformPoint(JC_Point2 input) { - input.x += (T)(Camera_Pos.x); + //fixes disconection between screen and math coordinates + input.x += (T)(Camera_Pos.x); input.y -= (T)(Camera_Pos.y); JC_Vector2 offset = { (T)(Graphics::ScreenWidth / 2), (T)(Graphics::ScreenHeight / 2) }; From f83eb06b5addd9f164fcbc213a383c1919c9fcf7 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 7 Jul 2018 19:49:14 +0200 Subject: [PATCH 49/84] Added whell press/release controll --- Engine/MainWindow.cpp | 12 ++++++++++++ Engine/Mouse.cpp | 21 +++++++++++++++++++++ Engine/Mouse.h | 15 ++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Engine/MainWindow.cpp b/Engine/MainWindow.cpp index 69693cc3..d9e37f3e 100644 --- a/Engine/MainWindow.cpp +++ b/Engine/MainWindow.cpp @@ -267,6 +267,18 @@ LRESULT MainWindow::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) } break; } + case WM_MBUTTONDOWN: + { + const POINTS pt = MAKEPOINTS(lParam); + mouse.OnWheelPressed(pt.x, pt.y); + break; + } + case WM_MBUTTONUP: + { + const POINTS pt = MAKEPOINTS(lParam); + mouse.OnWheelReleased(pt.x, pt.y); + break; + } // ************ END MOUSE MESSAGES ************ // } diff --git a/Engine/Mouse.cpp b/Engine/Mouse.cpp index ef7e179a..6d495067 100644 --- a/Engine/Mouse.cpp +++ b/Engine/Mouse.cpp @@ -46,6 +46,11 @@ bool Mouse::RightIsPressed() const return rightIsPressed; } +bool Mouse::WheelIsPressed() const +{ + return wheelIsPressed; +} + bool Mouse::IsInWindow() const { return isInWindow; @@ -121,6 +126,22 @@ void Mouse::OnRightReleased( int x,int y ) TrimBuffer(); } +void Mouse::OnWheelPressed(int x, int y) +{ + wheelIsPressed = true; + + buffer.push(Mouse::Event(Mouse::Event::Type::WheelPress, *this)); + TrimBuffer(); +} + +void Mouse::OnWheelReleased(int x, int y) +{ + wheelIsPressed = false; + + buffer.push(Mouse::Event(Mouse::Event::Type::WheelRelease, *this)); + TrimBuffer(); +} + void Mouse::OnWheelUp( int x,int y ) { buffer.push( Mouse::Event( Mouse::Event::Type::WheelUp,*this ) ); diff --git a/Engine/Mouse.h b/Engine/Mouse.h index aefb6339..8252a60a 100644 --- a/Engine/Mouse.h +++ b/Engine/Mouse.h @@ -35,6 +35,8 @@ class Mouse LRelease, RPress, RRelease, + WheelPress, + WheelRelease, WheelUp, WheelDown, Move, @@ -44,6 +46,7 @@ class Mouse Type type; bool leftIsPressed; bool rightIsPressed; + bool wheelIsPressed; int x; int y; public: @@ -52,6 +55,7 @@ class Mouse type( Type::Invalid ), leftIsPressed( false ), rightIsPressed( false ), + wheelIsPressed( false ), x( 0 ), y( 0 ) {} @@ -59,7 +63,8 @@ class Mouse : type( type ), leftIsPressed( parent.leftIsPressed ), - rightIsPressed( parent.rightIsPressed ), + rightIsPressed( parent.rightIsPressed), + wheelIsPressed( parent.wheelIsPressed), x( parent.x ), y( parent.y ) {} @@ -91,6 +96,10 @@ class Mouse { return rightIsPressed; } + bool WheelIsPressed() const + { + return wheelIsPressed; + } }; public: Mouse() = default; @@ -101,6 +110,7 @@ class Mouse int GetPosY() const; bool LeftIsPressed() const; bool RightIsPressed() const; + bool WheelIsPressed() const; bool IsInWindow() const; Mouse::Event Read(); bool IsEmpty() const @@ -116,6 +126,8 @@ class Mouse void OnLeftReleased( int x,int y ); void OnRightPressed( int x,int y ); void OnRightReleased( int x,int y ); + void OnWheelPressed(int x, int y); + void OnWheelReleased(int x, int y); void OnWheelUp( int x,int y ); void OnWheelDown( int x,int y ); void TrimBuffer(); @@ -125,6 +137,7 @@ class Mouse int y; bool leftIsPressed = false; bool rightIsPressed = false; + bool wheelIsPressed = false; bool isInWindow = false; std::queue buffer; }; \ No newline at end of file From 4c6de368d1768aa8af24308ed97fda5b0eddf3fb Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Mon, 9 Jul 2018 02:26:00 +0200 Subject: [PATCH 50/84] Made calculate centre fully private, changed selection margin from 4pt to 10, changed naming convencion of SetTrueSelectionFlag --- Engine/Circle.cpp | 2 +- Engine/Circle.h | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Engine/Circle.cpp b/Engine/Circle.cpp index 5225bcd2..6c1b2d3d 100644 --- a/Engine/Circle.cpp +++ b/Engine/Circle.cpp @@ -31,7 +31,7 @@ void Circle::UpdateColor() C = Colors::White; } -void Circle::SetSelectionFlag(const JC_Point2d& mousein) +void Circle::SetTrueSelectionFlag(const JC_Point2d& mousein) { double distance = GetDistanceTo(pos, mousein); if (distance <= (radius + halfwidth)&& diff --git a/Engine/Circle.h b/Engine/Circle.h index cf7a9b28..22cd0fd4 100644 --- a/Engine/Circle.h +++ b/Engine/Circle.h @@ -15,22 +15,20 @@ class Circle void Draw(Camera cam); void UpdateColor(); - void SetSelectionFlag(const JC_Point2d& mousein); + void SetTrueSelectionFlag(const JC_Point2d& mousein); void ResetSelectionFlag(); bool ReadyForRemoval() const; -public: - JC_Point2d CalculatCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); - private: + JC_Point2d CalculatCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); JC_Point2d CalculateSpecificCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); private: JC_Point2d pos; double radius; - static constexpr double halfwidth = 4.0; + static constexpr double halfwidth = 10.0; bool selectedflag = false; Color C ; }; \ No newline at end of file From 65c740e5b1141733e6595f687f09e363654e3923 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Mon, 9 Jul 2018 02:28:09 +0200 Subject: [PATCH 51/84] Probbably after adding new functionality to the frame work like OnWheelPress/Release I have missed to add method call to the WM_MOUSEMOVE --- Engine/MainWindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Engine/MainWindow.cpp b/Engine/MainWindow.cpp index d9e37f3e..cce3d454 100644 --- a/Engine/MainWindow.cpp +++ b/Engine/MainWindow.cpp @@ -225,6 +225,7 @@ LRESULT MainWindow::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) mouse.OnMouseLeave(); mouse.OnLeftReleased(pt.x, pt.y); mouse.OnRightReleased(pt.x, pt.y); + mouse.OnWheelReleased(pt.x, pt.y); } } break; From f34be9e4f50a21ad6867ea6874c0f198d80f5947 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Mon, 9 Jul 2018 02:29:52 +0200 Subject: [PATCH 52/84] Refactoring name of method call from circle class SetTrueSelectionFlag instead of SetSelectionflag --- Engine/Game.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index ad462fb8..c87ff651 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -108,7 +108,7 @@ void Game::ProcesInput() for (auto i = circles.begin(), j = circles.end(); i != j; ++i) { - i->SetSelectionFlag(static_cast(cam.TrasformPoint(wnd.mouse.GetPos()))); + i->SetTrueSelectionFlag(static_cast(cam.TrasformPoint(wnd.mouse.GetPos()))); } } From aac5e30bb3e4e5cbfe8b9aad548339a1bdf3a44b Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Mon, 9 Jul 2018 02:44:37 +0200 Subject: [PATCH 53/84] Added new funcionality possibility to remove seletionflag by combining shift and Left Mouse press --- Engine/Circle.cpp | 15 ++++++++------- Engine/Circle.h | 5 +++-- Engine/Game.cpp | 15 +++++++++++---- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Engine/Circle.cpp b/Engine/Circle.cpp index 6c1b2d3d..93f7379c 100644 --- a/Engine/Circle.cpp +++ b/Engine/Circle.cpp @@ -31,19 +31,20 @@ void Circle::UpdateColor() C = Colors::White; } -void Circle::SetTrueSelectionFlag(const JC_Point2d& mousein) +void Circle::SetSelectionFlag( bool flag) { - double distance = GetDistanceTo(pos, mousein); - if (distance <= (radius + halfwidth)&& - distance >= (radius - halfwidth)) - selectedflag = true; + selectedflag = flag; } -void Circle::ResetSelectionFlag() +bool Circle::IsInRange(JC_Point2d mousein) { - selectedflag = false; + double distance = GetDistanceTo(pos, mousein); + return (distance <= (radius + halfwidth) && + distance >= (radius - halfwidth)); } + + bool Circle::ReadyForRemoval() const { return selectedflag; diff --git a/Engine/Circle.h b/Engine/Circle.h index 22cd0fd4..fc6d801c 100644 --- a/Engine/Circle.h +++ b/Engine/Circle.h @@ -15,8 +15,9 @@ class Circle void Draw(Camera cam); void UpdateColor(); - void SetTrueSelectionFlag(const JC_Point2d& mousein); - void ResetSelectionFlag(); + void SetSelectionFlag(bool flag); + + bool IsInRange(JC_Point2d mousein); bool ReadyForRemoval() const; diff --git a/Engine/Game.cpp b/Engine/Game.cpp index c87ff651..82cb9c03 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -107,9 +107,16 @@ void Game::ProcesInput() { for (auto i = circles.begin(), j = circles.end(); i != j; ++i) { - - i->SetTrueSelectionFlag(static_cast(cam.TrasformPoint(wnd.mouse.GetPos()))); - + if (wnd.kbd.KeyIsPressed(VK_SHIFT)) + { + if (i->IsInRange(static_cast(cam.TrasformPoint(wnd.mouse.GetPos())))) + i->SetSelectionFlag(false); + } + else + { + if (i->IsInRange(static_cast(cam.TrasformPoint(wnd.mouse.GetPos())))) + i->SetSelectionFlag(true); + } } } @@ -129,7 +136,7 @@ void Game::ProcesInput() for (auto &c : circles) { - c.ResetSelectionFlag(); + c.SetSelectionFlag(false); } } From 16cdf71a008e14dbf414580ab4d9582b6b628afb Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Mon, 9 Jul 2018 03:16:32 +0200 Subject: [PATCH 54/84] Change of naming convenction of enum class MWShapeState from Shape --- Engine/Game.cpp | 6 +++--- Engine/MainWindow.cpp | 2 +- Engine/MainWindow.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 82cb9c03..369af5ae 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -49,7 +49,7 @@ void Game::ProcesInput() { switch (wnd.shape) { - case MainWindow::Shape::TwoPointCircle: + case MainWindow::MWShapeState::TwoPointCircle: { while (!wnd.mouse.IsEmpty()) { @@ -97,7 +97,7 @@ void Game::ProcesInput() } break; } - case MainWindow::Shape::Null: + case MainWindow::MWShapeState::Null: { while (!wnd.mouse.IsEmpty()) { @@ -130,7 +130,7 @@ void Game::ProcesInput() if (wnd.kbd.KeyIsPressed(VK_ESCAPE)) { - wnd.shape = MainWindow::Shape::Null; + wnd.shape = MainWindow::MWShapeState::Null; input = 0; diff --git a/Engine/MainWindow.cpp b/Engine/MainWindow.cpp index cce3d454..4ad24552 100644 --- a/Engine/MainWindow.cpp +++ b/Engine/MainWindow.cpp @@ -165,7 +165,7 @@ LRESULT MainWindow::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) PostMessage(hWnd, WM_CLOSE, 0, 0); break; case ID_SHAPES_TwoPointCircle: - shape = Shape::TwoPointCircle ; + shape = MWShapeState::TwoPointCircle ; ShowMessageBox(L"Info",L"Create circle form 2 points"); break; diff --git a/Engine/MainWindow.h b/Engine/MainWindow.h index 58b3144e..b5d4b324 100644 --- a/Engine/MainWindow.h +++ b/Engine/MainWindow.h @@ -50,14 +50,14 @@ class MainWindow : public HWNDKey virtual std::wstring GetExceptionType() const override { return L"Windows Exception"; } }; public: - enum class Shape + enum class MWShapeState { Null, TwoPointCircle, ThreePointCircle, Count }; - Shape shape = Shape::Null; + MWShapeState shape = MWShapeState::Null; MainWindow( HINSTANCE hInst,wchar_t* pArgs ); MainWindow( const MainWindow& ) = delete; From 348ac52ffb146d7398fafadd430dd81448ab66a5 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 13 Jul 2018 04:24:03 +0200 Subject: [PATCH 55/84] Polimorphism implementation problems asking for help on the forum --- Engine/Circle.cpp | 29 ++++------------- Engine/Circle.h | 22 +++++-------- Engine/Engine.vcxproj | 2 ++ Engine/Engine.vcxproj.filters | 16 +++++++--- Engine/Game.cpp | 59 ++++++++++++++--------------------- Engine/Game.h | 5 ++- Engine/MouseCameraControler.h | 4 +-- Engine/Shape.cpp | 19 +++++++++++ Engine/Shape.h | 32 +++++++++++++++++++ 9 files changed, 107 insertions(+), 81 deletions(-) create mode 100644 Engine/Shape.cpp create mode 100644 Engine/Shape.h diff --git a/Engine/Circle.cpp b/Engine/Circle.cpp index 93f7379c..98550d36 100644 --- a/Engine/Circle.cpp +++ b/Engine/Circle.cpp @@ -4,51 +4,34 @@ Circle::Circle(const JC_Point2d& P, const JC_Point2d& Q, Color color) : - pos(P), - radius(GetDistanceTo(P,Q)), - C(color) + Shape(P,color), + radius(GetDistanceTo(P, Q)) {} Circle::Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Color color) : - pos(CalculatCentre(P, Q, R)), - radius(GetDistanceTo(pos,R)), - C(color) + Shape(CalculatCentre(P, Q, R), color), + radius(GetDistanceTo(Centre, R)) {} void Circle::Draw(Camera cam) { - cam.DrawCircle(pos, radius, C); + cam.DrawCircle(Centre, radius, C); } -void Circle::UpdateColor() -{ - if (selectedflag) - C = Colors::Yellow; - else - C = Colors::White; -} -void Circle::SetSelectionFlag( bool flag) -{ - selectedflag = flag; -} bool Circle::IsInRange(JC_Point2d mousein) { - double distance = GetDistanceTo(pos, mousein); + double distance = GetDistanceTo(Centre, mousein); return (distance <= (radius + halfwidth) && distance >= (radius - halfwidth)); } -bool Circle::ReadyForRemoval() const -{ - return selectedflag; -} JC_Point2d Circle::CalculatCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) diff --git a/Engine/Circle.h b/Engine/Circle.h index fc6d801c..bc8549dd 100644 --- a/Engine/Circle.h +++ b/Engine/Circle.h @@ -1,35 +1,27 @@ #pragma once + +#include "Shape.h" #include "Graphics.h" #include "JC_Vector2.h" #include "Camera.h" -class Circle +class Circle : public Shape { public: Circle(const JC_Point2d& P, const JC_Point2d& Q,Color color = Colors::White); Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Color color = Colors::White); - void Draw(Camera cam); - void UpdateColor(); - - void SetSelectionFlag(bool flag); - - bool IsInRange(JC_Point2d mousein); - - bool ReadyForRemoval() const; - - + void Draw(Camera cam) override; + bool IsInRange(JC_Point2d mousein) override; + private: JC_Point2d CalculatCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); JC_Point2d CalculateSpecificCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); private: - JC_Point2d pos; double radius; - static constexpr double halfwidth = 10.0; - bool selectedflag = false; - Color C ; + }; \ No newline at end of file diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index 48d5bd56..590b6732 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -154,6 +154,7 @@ + @@ -168,6 +169,7 @@ + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index c826427a..97810f65 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -19,15 +19,15 @@ {7429fb29-146a-47ac-b5ad-e8731b226a6d} - - {b9b4aa28-3d6d-4412-b8b4-6ff6c3af9881} - {a1ba54ce-e6f2-47b3-93dd-e28c6615d142} {991129b5-249e-4da4-bad5-8426e98a3a3c} + + {b9b4aa28-3d6d-4412-b8b4-6ff6c3af9881} + @@ -70,7 +70,7 @@ Header Files - Header Files\Shapes + Header Files\Geometric shapes Header Files @@ -79,7 +79,7 @@ Header Files - Header Files\Shapes + Header Files\Geometric shapes Header Files @@ -93,6 +93,9 @@ Header Files\CameraPipeline + + Header Files\Geometric shapes + @@ -125,6 +128,9 @@ Source Files\Shapes + + Source Files + diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 369af5ae..470451c2 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -59,17 +59,15 @@ void Game::ProcesInput() { if (input == 0) { - P = wnd.mouse.GetPos(); engaged = true; P = cam.TrasformPoint(P); } if (input == 1) { - Q = wnd.mouse.GetPos(); Q = cam.TrasformPoint(Q); - circles.emplace_back(P, Q); + Shapes.push_back(std::make_unique); } input++; @@ -79,15 +77,12 @@ void Game::ProcesInput() input = 0; engaged = false; } - - } if (e.GetType() == Mouse::Event::Type::RPress) { input = 0; engaged = false; } - } if (engaged) { @@ -105,7 +100,7 @@ void Game::ProcesInput() if (e.GetType() == Mouse::Event::Type::LPress) { - for (auto i = circles.begin(), j = circles.end(); i != j; ++i) + for (auto i = Shapes.begin(), j = Shapes.end(); i != j; ++i) { if (wnd.kbd.KeyIsPressed(VK_SHIFT)) { @@ -119,8 +114,6 @@ void Game::ProcesInput() } } } - - } break; } @@ -134,7 +127,7 @@ void Game::ProcesInput() input = 0; - for (auto &c : circles) + for (auto &c : Shapes) { c.SetSelectionFlag(false); } @@ -142,48 +135,44 @@ void Game::ProcesInput() if (wnd.kbd.KeyIsPressed(VK_DELETE)) { - remove_erase_if(circles, std::mem_fn(&Circle::ReadyForRemoval)); - + remove_erase_if(Shapes, std::mem_fn(&Shape::ReadyForRemoval)); } - const float speed = 3.0f; - if (wnd.kbd.KeyIsPressed(VK_DOWN)) - { - cam.MoveBy({ 0.0f,-speed }); - } - if (wnd.kbd.KeyIsPressed(VK_UP)) - { - cam.MoveBy({ 0.0f,speed }); - } - if (wnd.kbd.KeyIsPressed(VK_LEFT)) - { - cam.MoveBy({ -speed,0.0f }); - } - if (wnd.kbd.KeyIsPressed(VK_RIGHT)) - { - cam.MoveBy({ speed,0.0f }); - } + + //const float speed = 3.0f; + //if (wnd.kbd.KeyIsPressed(VK_DOWN)) + //{ + // cam.MoveBy({ 0.0f,-speed }); + //} + //if (wnd.kbd.KeyIsPressed(VK_UP)) + //{ + // cam.MoveBy({ 0.0f,speed }); + //} + //if (wnd.kbd.KeyIsPressed(VK_LEFT)) + //{ + // cam.MoveBy({ -speed,0.0f }); + //} + //if (wnd.kbd.KeyIsPressed(VK_RIGHT)) + //{ + // cam.MoveBy({ speed,0.0f }); + //} } - void Game::UpdateModel() { - for (auto &c : circles) + for (auto &c : Shapes) { c.UpdateColor(); } } - - void Game::ComposeFrame() { - for (auto &c : circles) + for (auto &c : Shapes) { c.Draw(cam); } - //ct.DrawClosedPolyline(Star::Make(200, 75.0,7), Colors::Red); } diff --git a/Engine/Game.h b/Engine/Game.h index fa52664a..196008d0 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -20,6 +20,8 @@ ******************************************************************************************/ #pragma once +#include + #include "Keyboard.h" #include "Mouse.h" #include "Graphics.h" @@ -29,6 +31,7 @@ #include "JC_Vector2.h" #include "Circle.h" +#include "Shape.h" #include "Star.h" @@ -60,7 +63,7 @@ class Game CoordinateTrasformer ct; Camera cam; MouseCameraController camCtrl; - std::vector circles; + std::vector> Shapes; unsigned short input = 0; bool engaged = false; diff --git a/Engine/MouseCameraControler.h b/Engine/MouseCameraControler.h index a22f077e..68660c27 100644 --- a/Engine/MouseCameraControler.h +++ b/Engine/MouseCameraControler.h @@ -17,11 +17,11 @@ class MouseCameraController const auto e = mouse.Read(); switch (e.GetType()) { - case Mouse::Event::Type::LPress: + case Mouse::Event::Type::WheelPress: engaged = true; lastPos = e.GetPos(); break; - case Mouse::Event::Type::LRelease: + case Mouse::Event::Type::WheelRelease: engaged = false; break; case Mouse::Event::Type::WheelUp: diff --git a/Engine/Shape.cpp b/Engine/Shape.cpp new file mode 100644 index 00000000..124340d5 --- /dev/null +++ b/Engine/Shape.cpp @@ -0,0 +1,19 @@ +#include "Shape.h" + +void Shape::UpdateColor() +{ + if (selectedflag) + C = Colors::Yellow; + else + C = Colors::White; +} + +void Shape::SetSelectionFlag(bool flag) +{ + selectedflag = flag; +} + +bool Shape::ReadyForRemoval() const +{ + return selectedflag; +} \ No newline at end of file diff --git a/Engine/Shape.h b/Engine/Shape.h new file mode 100644 index 00000000..0f6d9d1d --- /dev/null +++ b/Engine/Shape.h @@ -0,0 +1,32 @@ +#pragma once +#include "JC_Vector2.h" +#include "Camera.h" + +class Shape + +{ +public: + bool ReadyForRemoval() const; + + void virtual Draw(Camera cam) = 0; + bool virtual IsInRange(JC_Point2d mousein) = 0; + + void UpdateColor(); + void SetSelectionFlag(bool flag); + +protected: + + Shape(JC_Point2d pos_in, Color& c) + : + Centre(pos_in), + C(c) + {} + + JC_Point2d Centre; + Color C; + static constexpr double halfwidth = 10.0; + +private: + bool selectedflag = false; + +}; \ No newline at end of file From 88a4289e6f5318dbdc62e2d78f235c6f166eabfb Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 13 Jul 2018 16:51:54 +0200 Subject: [PATCH 56/84] Program is still working bugs fixed --- Engine/Game.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 470451c2..45954a02 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -67,7 +67,7 @@ void Game::ProcesInput() { Q = wnd.mouse.GetPos(); Q = cam.TrasformPoint(Q); - Shapes.push_back(std::make_unique); + Shapes.push_back(std::make_unique(P, Q)); } input++; @@ -100,17 +100,17 @@ void Game::ProcesInput() if (e.GetType() == Mouse::Event::Type::LPress) { - for (auto i = Shapes.begin(), j = Shapes.end(); i != j; ++i) + for (auto&& i : Shapes) { if (wnd.kbd.KeyIsPressed(VK_SHIFT)) { - if (i->IsInRange(static_cast(cam.TrasformPoint(wnd.mouse.GetPos())))) - i->SetSelectionFlag(false); + if (i.get()->IsInRange(static_cast(cam.TrasformPoint(wnd.mouse.GetPos())))) + i.get()->SetSelectionFlag(false); } else { - if (i->IsInRange(static_cast(cam.TrasformPoint(wnd.mouse.GetPos())))) - i->SetSelectionFlag(true); + if (i.get()->IsInRange(static_cast(cam.TrasformPoint(wnd.mouse.GetPos())))) + i.get()->SetSelectionFlag(true); } } } @@ -129,7 +129,7 @@ void Game::ProcesInput() for (auto &c : Shapes) { - c.SetSelectionFlag(false); + c.get()->SetSelectionFlag(false); } } @@ -163,7 +163,7 @@ void Game::UpdateModel() { for (auto &c : Shapes) { - c.UpdateColor(); + c.get()->UpdateColor(); } } @@ -171,7 +171,7 @@ void Game::ComposeFrame() { for (auto &c : Shapes) { - c.Draw(cam); + c.get()->Draw(cam); } //ct.DrawClosedPolyline(Star::Make(200, 75.0,7), Colors::Red); } From 286f3ec0b543ad63123f07045d08c0623c6ba5e1 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 13 Jul 2018 18:41:04 +0200 Subject: [PATCH 57/84] Change of naming convencion! Changed shape and circle to JC_Circle and JC_Shape --- Engine/Engine.vcxproj | 9 +++++---- Engine/Engine.vcxproj.filters | 23 +++++++++++++---------- Engine/Game.cpp | 10 +++++----- Engine/Game.h | 6 +++--- Engine/{Circle.cpp => JC_Circle.cpp} | 20 +++++++++----------- Engine/{Circle.h => JC_Circle.h} | 8 ++++---- Engine/JC_Shape.cpp | 19 +++++++++++++++++++ Engine/{Shape.h => JC_Shape.h} | 4 ++-- Engine/Shape.cpp | 19 ------------------- 9 files changed, 60 insertions(+), 58 deletions(-) rename Engine/{Circle.cpp => JC_Circle.cpp} (78%) rename Engine/{Circle.h => JC_Circle.h} (62%) create mode 100644 Engine/JC_Shape.cpp rename Engine/{Shape.h => JC_Shape.h} (88%) delete mode 100644 Engine/Shape.cpp diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index 590b6732..76a397e7 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -139,7 +139,7 @@ - + @@ -147,6 +147,7 @@ + @@ -154,13 +155,13 @@ - + - + @@ -169,7 +170,7 @@ - + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index 97810f65..bcedbb1e 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -69,12 +69,6 @@ Header Files - - Header Files\Geometric shapes - - - Header Files - Header Files @@ -93,7 +87,16 @@ Header Files\CameraPipeline - + + Header Files + + + Header Files\Geometric shapes + + + Header Files\Geometric shapes + + Header Files\Geometric shapes @@ -125,11 +128,11 @@ Source Files - + Source Files\Shapes - - Source Files + + Source Files\Shapes diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 45954a02..682d0721 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -47,7 +47,7 @@ void Game::Go() void Game::ProcesInput() { - switch (wnd.shape) + switch (wnd.ShapeState) { case MainWindow::MWShapeState::TwoPointCircle: { @@ -67,7 +67,7 @@ void Game::ProcesInput() { Q = wnd.mouse.GetPos(); Q = cam.TrasformPoint(Q); - Shapes.push_back(std::make_unique(P, Q)); + Shapes.push_back(std::make_unique(P, Q)); } input++; @@ -100,7 +100,7 @@ void Game::ProcesInput() if (e.GetType() == Mouse::Event::Type::LPress) { - for (auto&& i : Shapes) + for (auto& i : Shapes) { if (wnd.kbd.KeyIsPressed(VK_SHIFT)) { @@ -123,7 +123,7 @@ void Game::ProcesInput() if (wnd.kbd.KeyIsPressed(VK_ESCAPE)) { - wnd.shape = MainWindow::MWShapeState::Null; + wnd.ShapeState = MainWindow::MWShapeState::Null; input = 0; @@ -135,7 +135,7 @@ void Game::ProcesInput() if (wnd.kbd.KeyIsPressed(VK_DELETE)) { - remove_erase_if(Shapes, std::mem_fn(&Shape::ReadyForRemoval)); + remove_erase_if(Shapes, std::mem_fn(&JC_Shape::ReadyForRemoval)); } diff --git a/Engine/Game.h b/Engine/Game.h index 196008d0..8633bfa9 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -30,8 +30,8 @@ #include "MouseCameraControler.h" #include "JC_Vector2.h" -#include "Circle.h" -#include "Shape.h" +#include "JC_Circle.h" +#include "JC_Shape.h" #include "Star.h" @@ -63,7 +63,7 @@ class Game CoordinateTrasformer ct; Camera cam; MouseCameraController camCtrl; - std::vector> Shapes; + std::vector> Shapes; unsigned short input = 0; bool engaged = false; diff --git a/Engine/Circle.cpp b/Engine/JC_Circle.cpp similarity index 78% rename from Engine/Circle.cpp rename to Engine/JC_Circle.cpp index 98550d36..12aa3aaf 100644 --- a/Engine/Circle.cpp +++ b/Engine/JC_Circle.cpp @@ -1,29 +1,29 @@ -#include "Circle.h" +#include "JC_Circle.h" #include "JC_Math.h" #include -Circle::Circle(const JC_Point2d& P, const JC_Point2d& Q, Color color) +JC_Circle::JC_Circle(const JC_Point2d& P, const JC_Point2d& Q, Color color) : - Shape(P,color), + JC_Shape(P,color), radius(GetDistanceTo(P, Q)) {} -Circle::Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Color color) +JC_Circle::JC_Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Color color) : - Shape(CalculatCentre(P, Q, R), color), + JC_Shape(CalculatCentre(P, Q, R), color), radius(GetDistanceTo(Centre, R)) {} -void Circle::Draw(Camera cam) +void JC_Circle::Draw(Camera cam) { cam.DrawCircle(Centre, radius, C); } -bool Circle::IsInRange(JC_Point2d mousein) +bool JC_Circle::IsInRange(JC_Point2d mousein) { double distance = GetDistanceTo(Centre, mousein); return (distance <= (radius + halfwidth) && @@ -34,7 +34,7 @@ bool Circle::IsInRange(JC_Point2d mousein) -JC_Point2d Circle::CalculatCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) +JC_Point2d JC_Circle::CalculatCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) { { //when we have 2 flat lines in order under right angle @@ -75,9 +75,7 @@ JC_Point2d Circle::CalculatCentre(const JC_Point2d & P, const JC_Point2d & Q, co } } - - -JC_Point2d Circle::CalculateSpecificCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) +JC_Point2d JC_Circle::CalculateSpecificCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) { { diff --git a/Engine/Circle.h b/Engine/JC_Circle.h similarity index 62% rename from Engine/Circle.h rename to Engine/JC_Circle.h index bc8549dd..b3edec95 100644 --- a/Engine/Circle.h +++ b/Engine/JC_Circle.h @@ -1,18 +1,18 @@ #pragma once -#include "Shape.h" +#include "JC_Shape.h" #include "Graphics.h" #include "JC_Vector2.h" #include "Camera.h" -class Circle : public Shape +class JC_Circle : public JC_Shape { public: - Circle(const JC_Point2d& P, const JC_Point2d& Q,Color color = Colors::White); - Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Color color = Colors::White); + JC_Circle(const JC_Point2d& P, const JC_Point2d& Q,Color color = Colors::White); + JC_Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Color color = Colors::White); void Draw(Camera cam) override; bool IsInRange(JC_Point2d mousein) override; diff --git a/Engine/JC_Shape.cpp b/Engine/JC_Shape.cpp new file mode 100644 index 00000000..572b4f76 --- /dev/null +++ b/Engine/JC_Shape.cpp @@ -0,0 +1,19 @@ +#include "JC_Shape.h" + +void JC_Shape::UpdateColor() +{ + if (selectedflag) + C = Colors::Yellow; + else + C = Colors::White; +} + +void JC_Shape::SetSelectionFlag(bool flag) +{ + selectedflag = flag; +} + +bool JC_Shape::ReadyForRemoval() const +{ + return selectedflag; +} \ No newline at end of file diff --git a/Engine/Shape.h b/Engine/JC_Shape.h similarity index 88% rename from Engine/Shape.h rename to Engine/JC_Shape.h index 0f6d9d1d..fde30274 100644 --- a/Engine/Shape.h +++ b/Engine/JC_Shape.h @@ -2,7 +2,7 @@ #include "JC_Vector2.h" #include "Camera.h" -class Shape +class JC_Shape { public: @@ -16,7 +16,7 @@ class Shape protected: - Shape(JC_Point2d pos_in, Color& c) + JC_Shape(JC_Point2d pos_in, Color& c) : Centre(pos_in), C(c) diff --git a/Engine/Shape.cpp b/Engine/Shape.cpp deleted file mode 100644 index 124340d5..00000000 --- a/Engine/Shape.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "Shape.h" - -void Shape::UpdateColor() -{ - if (selectedflag) - C = Colors::Yellow; - else - C = Colors::White; -} - -void Shape::SetSelectionFlag(bool flag) -{ - selectedflag = flag; -} - -bool Shape::ReadyForRemoval() const -{ - return selectedflag; -} \ No newline at end of file From f5fec8051b56d847df23a3a32a84e74423ba2002 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 14 Jul 2018 09:06:17 +0200 Subject: [PATCH 58/84] Created Menu items for 3point circle and line segment --- Engine/MainWindow.cpp | 23 +++++++++++++++++++++-- Engine/MainWindow.h | 3 ++- Engine/Resource.h | Bin 1040 -> 1198 bytes 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Engine/MainWindow.cpp b/Engine/MainWindow.cpp index 4ad24552..b9c248f6 100644 --- a/Engine/MainWindow.cpp +++ b/Engine/MainWindow.cpp @@ -147,12 +147,18 @@ LRESULT MainWindow::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) } hSubMenu = CreatePopupMenu(); - + AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, L"&Shapes"); { AppendMenu(hSubMenu, MF_STRING, ID_SHAPES_TwoPointCircle, L"&Circle from 2 points"); + AppendMenu(hSubMenu, MF_SEPARATOR, NULL, NULL); + AppendMenu(hSubMenu, MF_STRING, ID_SHAPES_ThreePointCircle, L"&Circle from 3 points"); + AppendMenu(hSubMenu, MF_SEPARATOR, NULL, NULL); + AppendMenu(hSubMenu, MF_STRING, ID_SHAPES_LineSegment, L"&Line Segment"); } + + SetMenu(hWnd, hMenu); break; @@ -165,9 +171,22 @@ LRESULT MainWindow::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) PostMessage(hWnd, WM_CLOSE, 0, 0); break; case ID_SHAPES_TwoPointCircle: - shape = MWShapeState::TwoPointCircle ; + ShapeState = MWShapeState::TwoPointCircle ; ShowMessageBox(L"Info",L"Create circle form 2 points"); + break; + + case ID_SHAPES_ThreePointCircle: + ShapeState = MWShapeState::ThreePointCircle; + ShowMessageBox(L"Info", L"Create circle form 3 points"); + + break; + + + case ID_SHAPES_LineSegment: + ShapeState = MWShapeState::LineSegment; + ShowMessageBox(L"Info", L"Create line Segment"); + break; } diff --git a/Engine/MainWindow.h b/Engine/MainWindow.h index b5d4b324..b7133cab 100644 --- a/Engine/MainWindow.h +++ b/Engine/MainWindow.h @@ -55,9 +55,10 @@ class MainWindow : public HWNDKey Null, TwoPointCircle, ThreePointCircle, + LineSegment, Count }; - MWShapeState shape = MWShapeState::Null; + MWShapeState ShapeState = MWShapeState::Null; MainWindow( HINSTANCE hInst,wchar_t* pArgs ); MainWindow( const MainWindow& ) = delete; diff --git a/Engine/Resource.h b/Engine/Resource.h index 995a76763f3cf79757549bba37466a9146b77a54..51276bc1e7f77fb315fd3ff4242955ba6a7296cb 100644 GIT binary patch delta 88 zcmbQhv5s@Y9%e>^$^J~DlP@t_Fd9NxV(b|VMGUD7sgqwbt4GUNe8 dgMm1mAs0yIF_bVUFjz7e0HHAhF9R1C0{|%Z6O{k} delta 22 ecmZ3-Ie}xt9_GnhEIN~4Fe|YcG4L{QF#rHkLIryO From 45678ed6dafb2fb01983585fa6be9087aae42836 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 14 Jul 2018 09:07:23 +0200 Subject: [PATCH 59/84] Added possibility to draw line in the problam Selecting not yet implemented --- Engine/Camera.h | 10 ++++++++-- Engine/CordinateTrasformerh.h | 14 ++++++++++++++ Engine/JC_Line.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 Engine/JC_Line.h diff --git a/Engine/Camera.h b/Engine/Camera.h index 73bef59e..120e15f7 100644 --- a/Engine/Camera.h +++ b/Engine/Camera.h @@ -29,11 +29,17 @@ class Camera Camera_Pos = pos_in; } + void DrawLine(JC_Point2d P_in, JC_Point2d Q_in, Color Color_in) + { + P_in -= Camera_Pos; + Q_in -= Camera_Pos; + ct.DrawLine(std::move(P_in), std::move(Q_in), std::move(Color_in)); + } - void DrawCircle(JC_Point2d pos, double radius, Color c) + void DrawCircle(JC_Point2d pos, double radius, Color Color_in) { pos -= Camera_Pos; - ct.DrawCircle(std::move(pos), std::move(radius), c); + ct.DrawCircle(std::move(pos), std::move(radius), Color_in); } diff --git a/Engine/CordinateTrasformerh.h b/Engine/CordinateTrasformerh.h index 8c240000..7df70bd0 100644 --- a/Engine/CordinateTrasformerh.h +++ b/Engine/CordinateTrasformerh.h @@ -16,6 +16,20 @@ class CoordinateTrasformer gfx(gfx) {} + void DrawLine(JC_Point2d P_in, JC_Point2d Q_in, Color Color_in) + { + JC_Vector2d offset = { double(Graphics::ScreenWidth / 2),double(Graphics::ScreenHeight / 2) }; + + P_in.y *= -1; + Q_in.y *= -1; + + P_in += offset; + Q_in += offset; + + + gfx.DrawLine(P_in, Q_in, Color_in); + } + void DrawCircle(JC_Point2d pos, double radius, Color c) { JC_Vector2d offset = { double(Graphics::ScreenWidth / 2),double(Graphics::ScreenHeight / 2) }; diff --git a/Engine/JC_Line.h b/Engine/JC_Line.h new file mode 100644 index 00000000..981505d9 --- /dev/null +++ b/Engine/JC_Line.h @@ -0,0 +1,30 @@ +#pragma once + +#include "JC_Shape.h" +#include "Camera.h" + +class JC_Line : public JC_Shape +{ +public: + JC_Line(const JC_Point2d& P_in, const JC_Point2d& Q_in, Color color_in = Colors::White) + : + P(P_in), + Q(Q_in), + JC_Shape(color_in) + {} + + void Draw(Camera cam_in) override + { + cam_in.DrawLine(P, Q, Base_Color); + } + bool IsInRange(const JC_Point2d& mouse_in) override + { + return false; + } + + + +private: + JC_Point2d P, Q; //Start and end points of the line + +}; \ No newline at end of file From dbe91adb8548039824e57c84212566f32f4c0aca Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 14 Jul 2018 09:08:02 +0200 Subject: [PATCH 60/84] Made possible to draw line while circle is created, Utility changes --- Engine/Engine.vcxproj | 1 - Engine/Engine.vcxproj.filters | 15 ++++++--------- Engine/Game.cpp | 35 ++++++++++++++++++----------------- Engine/Game.h | 1 + Engine/Graphics.cpp | 18 ++++++++++++++++-- Engine/JC_Circle.cpp | 24 ++++++++++++++---------- Engine/JC_Circle.h | 11 +++++++---- Engine/JC_Shape.cpp | 19 ------------------- Engine/JC_Shape.h | 35 ++++++++++++++++++++++++----------- 9 files changed, 86 insertions(+), 73 deletions(-) delete mode 100644 Engine/JC_Shape.cpp diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index 76a397e7..2db0c0f5 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -170,7 +170,6 @@ - diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index bcedbb1e..d97f8341 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -87,18 +87,18 @@ Header Files\CameraPipeline - - Header Files - - - Header Files\Geometric shapes - Header Files\Geometric shapes Header Files\Geometric shapes + + Header Files + + + Header Files\Geometric shapes + @@ -128,9 +128,6 @@ Source Files - - Source Files\Shapes - Source Files\Shapes diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 682d0721..4a5676e8 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -89,6 +89,7 @@ void Game::ProcesInput() Q = wnd.mouse.GetPos(); Q = cam.TrasformPoint(Q); cam.DrawCircle(P, GetDistanceTo(P, Q), Colors::Red); + cam.DrawLine(P, Q, Colors::Red); } break; } @@ -139,23 +140,23 @@ void Game::ProcesInput() } - //const float speed = 3.0f; - //if (wnd.kbd.KeyIsPressed(VK_DOWN)) - //{ - // cam.MoveBy({ 0.0f,-speed }); - //} - //if (wnd.kbd.KeyIsPressed(VK_UP)) - //{ - // cam.MoveBy({ 0.0f,speed }); - //} - //if (wnd.kbd.KeyIsPressed(VK_LEFT)) - //{ - // cam.MoveBy({ -speed,0.0f }); - //} - //if (wnd.kbd.KeyIsPressed(VK_RIGHT)) - //{ - // cam.MoveBy({ speed,0.0f }); - //} + const float speed = 7.0f; + if (wnd.kbd.KeyIsPressed(VK_DOWN)) + { + cam.MoveBy({ 0.0f,speed }); + } + if (wnd.kbd.KeyIsPressed(VK_UP)) + { + cam.MoveBy({ 0.0f,-speed }); + } + if (wnd.kbd.KeyIsPressed(VK_LEFT)) + { + cam.MoveBy({ speed,0.0f }); + } + if (wnd.kbd.KeyIsPressed(VK_RIGHT)) + { + cam.MoveBy({ -speed,0.0f }); + } } diff --git a/Engine/Game.h b/Engine/Game.h index 8633bfa9..499d5901 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -31,6 +31,7 @@ #include "JC_Vector2.h" #include "JC_Circle.h" +#include "JC_Line.h" #include "JC_Shape.h" #include "Star.h" diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index 8e15fcec..529663d1 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -356,6 +356,11 @@ void Graphics::DrawClosedPolyline(const std::vector& verts, Color c) DrawLine(verts.back(), verts.front(), c); } + +// line with per pixel clipping + + + void Graphics::DrawLine(double x1, double y1, double x2, double y2, Color c) { const double dx = x2 - x1; @@ -363,6 +368,7 @@ void Graphics::DrawLine(double x1, double y1, double x2, double y2, Color c) if (dx == 0.0f && dy == 0.0f) { + if (x1 >= 0 && x1 < ScreenWidth && y1 >= 0 && y1 < ScreenHeight) PutPixel((int)x1, (int)y1, Colors::Red); } else if (abs(dx)>abs(dy)) @@ -378,8 +384,12 @@ void Graphics::DrawLine(double x1, double y1, double x2, double y2, Color c) for (double x = x1; x <= x2; x++) { + double y = m * x + b; - PutPixel((int)(x + 0.5f), (int)(y + 0.5f), c); + // issue! why there is need for substraction of one ? + if (x >= 0 && x < ScreenWidth-1 && y >= 0 && y < ScreenHeight-1) + PutPixel((int)(x + 0.5), (int)(y + 0.5), c); + } } else @@ -396,7 +406,9 @@ void Graphics::DrawLine(double x1, double y1, double x2, double y2, Color c) for (double y = y1; y <= y2; y++) { double x = m * y + b; - PutPixel((int)(x + 0.5f), (int)(y + 0.5f), c); + // issue! why there is need for substraction of one ? + if (x >= 0 && x < ScreenWidth-1 && y >= 0 && y < ScreenHeight-1) + PutPixel((int)(x + 0.5), (int)(y + 0.5), c); } } } @@ -404,6 +416,8 @@ void Graphics::DrawLine(double x1, double y1, double x2, double y2, Color c) void Graphics::DrawCircle(double Ox, double Oy, double R, Color& c) { + //issue with continuity drawing for large circles + /*for (double theta = 0; theta < 360; theta += 0.2) { double x = (double)(R * std::cos(PI_D*theta / 180)); diff --git a/Engine/JC_Circle.cpp b/Engine/JC_Circle.cpp index 12aa3aaf..815ad153 100644 --- a/Engine/JC_Circle.cpp +++ b/Engine/JC_Circle.cpp @@ -2,30 +2,34 @@ #include "JC_Math.h" #include -JC_Circle::JC_Circle(const JC_Point2d& P, const JC_Point2d& Q, Color color) +JC_Circle::JC_Circle(const JC_Point2d& P_in, const JC_Point2d& Q_in, Color color_in) : - JC_Shape(P,color), - radius(GetDistanceTo(P, Q)) + JC_Shape(color_in), + O(P_in), + radius(GetDistanceTo(P_in, Q_in)) + {} -JC_Circle::JC_Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Color color) +JC_Circle::JC_Circle(const JC_Point2d& P_in, const JC_Point2d& Q_in, const JC_Point2d& R_in, Color color_in) : - JC_Shape(CalculatCentre(P, Q, R), color), - radius(GetDistanceTo(Centre, R)) + JC_Shape(color_in), + O(CalculatCentre(P_in, Q_in, R_in)), + radius(GetDistanceTo(P_in, R_in)) + {} -void JC_Circle::Draw(Camera cam) +void JC_Circle::Draw(Camera cam_in) { - cam.DrawCircle(Centre, radius, C); + cam_in.DrawCircle(O, radius, Base_Color); } -bool JC_Circle::IsInRange(JC_Point2d mousein) +bool JC_Circle::IsInRange(const JC_Point2d& mouse_in) { - double distance = GetDistanceTo(Centre, mousein); + double distance = GetDistanceTo(O, mouse_in); return (distance <= (radius + halfwidth) && distance >= (radius - halfwidth)); } diff --git a/Engine/JC_Circle.h b/Engine/JC_Circle.h index b3edec95..14af5bda 100644 --- a/Engine/JC_Circle.h +++ b/Engine/JC_Circle.h @@ -2,6 +2,8 @@ #include "JC_Shape.h" + + #include "Graphics.h" #include "JC_Vector2.h" #include "Camera.h" @@ -11,17 +13,18 @@ class JC_Circle : public JC_Shape { public: - JC_Circle(const JC_Point2d& P, const JC_Point2d& Q,Color color = Colors::White); - JC_Circle(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R, Color color = Colors::White); + JC_Circle(const JC_Point2d& P_in, const JC_Point2d& Q_in, Color color_in = Colors::White); + JC_Circle(const JC_Point2d& P_in, const JC_Point2d& Q_in, const JC_Point2d& R_in, Color color_in = Colors::White); - void Draw(Camera cam) override; - bool IsInRange(JC_Point2d mousein) override; + void Draw(Camera cam_in) override; + bool IsInRange(const JC_Point2d& mouse_in) override; private: JC_Point2d CalculatCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); JC_Point2d CalculateSpecificCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); private: + JC_Point2d O; double radius; }; \ No newline at end of file diff --git a/Engine/JC_Shape.cpp b/Engine/JC_Shape.cpp deleted file mode 100644 index 572b4f76..00000000 --- a/Engine/JC_Shape.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "JC_Shape.h" - -void JC_Shape::UpdateColor() -{ - if (selectedflag) - C = Colors::Yellow; - else - C = Colors::White; -} - -void JC_Shape::SetSelectionFlag(bool flag) -{ - selectedflag = flag; -} - -bool JC_Shape::ReadyForRemoval() const -{ - return selectedflag; -} \ No newline at end of file diff --git a/Engine/JC_Shape.h b/Engine/JC_Shape.h index fde30274..dfc38636 100644 --- a/Engine/JC_Shape.h +++ b/Engine/JC_Shape.h @@ -6,27 +6,40 @@ class JC_Shape { public: - bool ReadyForRemoval() const; - void virtual Draw(Camera cam) = 0; - bool virtual IsInRange(JC_Point2d mousein) = 0; - void UpdateColor(); - void SetSelectionFlag(bool flag); + void virtual Draw(Camera cam_in) = 0; + bool virtual IsInRange(const JC_Point2d& mouse_in) = 0; + void UpdateColor() + { + if (selectedflag) + Base_Color = Colors::Yellow; + else + Base_Color = Colors::White; + } + + void SetSelectionFlag(bool flag) + { + selectedflag = flag; + } + + + bool ReadyForRemoval() const + { + return selectedflag; + } protected: - JC_Shape(JC_Point2d pos_in, Color& c) + JC_Shape( Color& color_in) : - Centre(pos_in), - C(c) + Base_Color(color_in) {} - JC_Point2d Centre; - Color C; + Color Base_Color; static constexpr double halfwidth = 10.0; private: bool selectedflag = false; -}; \ No newline at end of file +}; From 4ae66a991f2eb929a666ff8800a4d20f12515c14 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 14 Jul 2018 16:37:57 +0200 Subject: [PATCH 61/84] Adding Piaces of documentation to the Circle.h explaining creation of circle from three points --- Engine/Game.cpp | 1 + Engine/JC_Circle.h | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 4a5676e8..4c0cb243 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -68,6 +68,7 @@ void Game::ProcesInput() Q = wnd.mouse.GetPos(); Q = cam.TrasformPoint(Q); Shapes.push_back(std::make_unique(P, Q)); + //Shapes.push_back(std::make_unique(P, Q)); } input++; diff --git a/Engine/JC_Circle.h b/Engine/JC_Circle.h index 14af5bda..9abbfab2 100644 --- a/Engine/JC_Circle.h +++ b/Engine/JC_Circle.h @@ -14,13 +14,23 @@ class JC_Circle : public JC_Shape public: JC_Circle(const JC_Point2d& P_in, const JC_Point2d& Q_in, Color color_in = Colors::White); + + //Constructor which is responsible for creating circle using three points JC_Circle(const JC_Point2d& P_in, const JC_Point2d& Q_in, const JC_Point2d& R_in, Color color_in = Colors::White); void Draw(Camera cam_in) override; bool IsInRange(const JC_Point2d& mouse_in) override; private: + //**We have couple of types of centre calculation: + //**When we can Determine slope of both lines, then we proces points in seen order. + //**When we can't determine slope of any of lines (parallel to the window sides) + // in this situation we are calculating centre using line mid point rule + //**When we are unable to tetermine solope of one from the lines + // in this situation we are simply swaping order of the points. JC_Point2d CalculatCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); + + //Used to calculate centre from points from which created lines have caclulatable slope (at least one line) JC_Point2d CalculateSpecificCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); private: From aadb9c1b49d486bdd66f9839de2b09e0e6e0730e Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 14 Jul 2018 16:41:02 +0200 Subject: [PATCH 62/84] Ortographic mistake in the Circle.h documentation --- Engine/JC_Circle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/JC_Circle.h b/Engine/JC_Circle.h index 9abbfab2..5c651484 100644 --- a/Engine/JC_Circle.h +++ b/Engine/JC_Circle.h @@ -26,7 +26,7 @@ class JC_Circle : public JC_Shape //**When we can Determine slope of both lines, then we proces points in seen order. //**When we can't determine slope of any of lines (parallel to the window sides) // in this situation we are calculating centre using line mid point rule - //**When we are unable to tetermine solope of one from the lines + //**When we are unable to determine solope of one from the lines // in this situation we are simply swaping order of the points. JC_Point2d CalculatCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); From 453088469d3bbc361b4414bec58b0b0d1d27a4aa Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 15 Jul 2018 01:20:44 +0200 Subject: [PATCH 63/84] Getting read of old implementation --- Engine/JC_Vector2.h | 342 -------------------------------------------- 1 file changed, 342 deletions(-) diff --git a/Engine/JC_Vector2.h b/Engine/JC_Vector2.h index 9035a75c..60185c7e 100644 --- a/Engine/JC_Vector2.h +++ b/Engine/JC_Vector2.h @@ -208,345 +208,3 @@ template JC_Point2 GetMidPoint(const JC_Point2& v0, const JC_Poin return v0 + v; } - -/* -#pragma once - -#include -#include - -template -class JC_Vector2 -{ -public: -T x; -T y; - - - -public: -inline JC_Vector2(){} -inline JC_Vector2(T inx, T iny) -: -x(inx), -y(iny) -{} - -template -JC_Vector2(const JC_Vector2& src) -: -x((T)src.x), -y((T)src.y) -{} - - -template -explicit operator JC_Vector2() const -{ -return { T2 x,T2 y }; -} - - -template -inline JC_Vector2(const PointType& P , const PointType& Q) -: -JC_Vector2(P.x-Q.x , P.y-Q.y) -{} - - - -//Vector Vector Operators - -inline JC_Vector2 operator-() -{ -return JC_Vector2(-x, -y); -} - -//inline JC_Vector2 operator= (const JC_Vector2 &rhs) -//{ -// x = rhs.x; -// y = rhs.y; -// return *this; -//} - -inline JC_Vector2 operator-(const JC_Vector2 &rhs)const -{ -return JC_Vector2(x - rhs.x , y - rhs.y); -} -inline JC_Vector2& operator-=(const JC_Vector2 &rhs) -{ -return *this = *this - rhs; - -} - -inline JC_Vector2 operator+(const JC_Vector2 &rhs)const -{ -return JC_Vector2(x + rhs.x, y + rhs.y); -} -inline JC_Vector2& operator+=(const JC_Vector2 &rhs) -{ -return *this = *this + rhs; -} - -//Vector scalar operators - -inline JC_Vector2 operator*(const T rhs) const -{ -return JC_Vector2(x * rhs, y * rhs); -} -inline JC_Vector2& operator*=(const T rhs) -{ -return *this = *this * rhs; -} - -inline JC_Vector2 operator/(const T rhs) const -{ -return JC_Vector2(x / rhs, y / rhs); -} -inline JC_Vector2& operator/=(const T rhs) -{ -return *this = *this / rhs; -} - -//Lenght operations - -inline T GetLengthSq() const -{ -return x * x + y * y; -} -inline T GetLength() const -{ -return (T)std::sqrt(GetLengthSq()); -} - -//Normalise operations - -inline JC_Vector2& Normalize() -{ -return *this = GetNormalize(); -} -inline JC_Vector2 GetNormalize() const -{ -const double len = GetLength(); -if (len != (T)0) -{ -return *this * ((T)1 / len); -} -return len; -} - -//Boolean operators - -inline bool operator==(const JC_Vector2 &rhs)const -{ -return (x == rhs.x && y== rhs.y) ; -} - -inline bool operator!=(const JC_Vector2 &rhs)const -{ -return (x != rhs.x || y != rhs.y); -} - -inline double Vector_Slope(const JC_Vector2& V) -{ - -assert(V.x != 0.0f); -float m = V.y / V.x; - -return m; - -} - -}; - -typedef JC_Vector2 JC_Vector2d; -typedef JC_Vector2 JC_Vector2f; -typedef JC_Vector2 JC_Vector2i; - - -template -class JC_Point2 -{ -public: -T x; -T y; - -public: -inline JC_Point2() {} -inline JC_Point2(T inx, T iny) -: -x(inx), -y(iny) -{} -inline JC_Point2(const JC_Point2& point) -: -JC_Point2(point.x, point.y) -{} - -template -JC_Point2(const JC_Point2& src) -: -x((T)src.x), -y((T)src.y) -{} - -template -explicit operator JC_Point2() const -{ -return { T2 x,T2 y }; - -} - - - - -inline JC_Point2 operator-() -{ -return JC_Point2(-x, -y); -} -inline JC_Point2 operator= (const JC_Point2 &rhs) -{ -x = rhs.x; -y = rhs.y; -return *this; -} - -inline JC_Point2 operator+(const JC_Point2 &rhs) const -{ -return JC_Point2(x + rhs.x, y + rhs.y); -} -inline JC_Point2& operator+=(const JC_Point2 &rhs) -{ -return *this = *this + rhs; - -} - - -inline JC_Point2 operator- (const JC_Point2 &rhs) const -{ -return JC_Point2(x - rhs.x, y - rhs.y) -} -inline JC_Point2& operator-=(const JC_Point2 &rhs) -{ -return *this = *this - rhs; - -} - -inline JC_Point2 operator*(const T rhs) const -{ -return JC_Point2(x * rhs, y * rhs); -} -inline JC_Point2& operator*=(const T rhs) -{ -return *this = *this * rhs; -} - -inline JC_Point2 operator/(const T rhs) const -{ -return JC_Point2(x / rhs, y / rhs); -} -inline JC_Point2& operator/=(const T rhs) -{ -return *this = *this / rhs; -} - - - -inline JC_Point2 operator+(const JC_Vector2 &rhs) const -{ -return JC_Point2(x + rhs.x, y + rhs.y); -} -inline JC_Point2& operator+=(const JC_Vector2 &rhs) -{ -return *this = *this + rhs; - -} - - -inline JC_Point2 operator- (const JC_Vector2 &rhs) const -{ -return JC_Point2(x - rhs.x, y - rhs.y); -} -inline JC_Point2& operator-=(const JC_Vector2 &rhs) -{ -return *this = *this - rhs; - -} - - - - -bool operator==(const JC_Point2 &rhs) const -{ -return (x == rhs.x && y == rhs.y) ? true : false; -} - -bool operator!=(const JC_Point2 &rhs) const -{ -return (x != rhs.x || y != rhs.y); -} - -bool operator<=(const JC_Point2 &rhs) const -{ -// dictionary order -return ((x < rhs.x) ? true : ((x == rhs.x && y <= rhs.y) ? true : false)); -} - -bool operator>=(const JC_Point2 &rhs) const -{ -// dictionary order -return ((x > rhs.x) ? true : ((x == rhs.x && y >= rhs.y) ? true : false)); -} - -bool operator<(const JC_Point2 &rhs) const -{ -// dictionary order -return ((x < rhs.x) ? true : ((x == rhs.x && y < rhs.y) ? true : false)); -} - -bool operator>(const JC_Point2 &rhs) const -{ -// dictionary order -return ((x > rhs.x) ? true : ((x == rhs.x && y > rhs.y) ? true : false)); -} - - -inline T GetDistanceToSq( const JC_Point2 &rhs) const -{ -return (T)((this->x-rhs.x) * (this->x - rhs.x) + (this->y - rhs.y) * (this->y - rhs.y)); -} - -inline T GetDistanceTo(const JC_Point2 &rhs) const -{ -return (T)std::sqrt(GetDistanceToSq(rhs)); -} - -inline JC_Point2 GetMidPoint(const JC_Point2& rhs) const -{ -return JC_Point2((*this+rhs)/2); -} - -inline void Zero() -{ -x = y = 0.0; -} - -inline bool IsZero() const -{ -return (x == 0.0 && y == 0.0); -} - -inline bool IsNotZero() const -{ -// the && (x == x && y == y) insures no coordinate is a Nan. -return (x != 0.0 || y != 0.0) && (x == x && y == y); -} - - -}; - -typedef JC_Point2 JC_Point2d; -typedef JC_Point2 JC_Point2f; -typedef JC_Point2 JC_Point2i; -*/ - From 3cff88523d820cbf2be70bd0255d0962ac850fa4 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 15 Jul 2018 18:18:16 +0200 Subject: [PATCH 64/84] Spotted Creation bug in coinstructor of Circle class (Circle from 3 points) --- Engine/JC_Circle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/JC_Circle.cpp b/Engine/JC_Circle.cpp index 815ad153..f0e06dcd 100644 --- a/Engine/JC_Circle.cpp +++ b/Engine/JC_Circle.cpp @@ -16,7 +16,7 @@ JC_Circle::JC_Circle(const JC_Point2d& P_in, const JC_Point2d& Q_in, const JC_Po : JC_Shape(color_in), O(CalculatCentre(P_in, Q_in, R_in)), - radius(GetDistanceTo(P_in, R_in)) + radius(GetDistanceTo(O, R_in)) {} From 1b6bb3ced82a898314c5a8eeba69213fbfffc551 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 15 Jul 2018 20:31:05 +0200 Subject: [PATCH 65/84] Added posibility to draw Line segment --- Engine/Game.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 4c0cb243..a5cbf235 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -59,9 +59,9 @@ void Game::ProcesInput() { if (input == 0) { - P = wnd.mouse.GetPos(); + engaged = true; - P = cam.TrasformPoint(P); + P = cam.TrasformPoint(wnd.mouse.GetPos()); } if (input == 1) { @@ -87,13 +87,55 @@ void Game::ProcesInput() } if (engaged) { - Q = wnd.mouse.GetPos(); - Q = cam.TrasformPoint(Q); + + Q = cam.TrasformPoint(wnd.mouse.GetPos()); cam.DrawCircle(P, GetDistanceTo(P, Q), Colors::Red); cam.DrawLine(P, Q, Colors::Red); } break; } + + case MainWindow::MWShapeState::LineSegment: + { + while (!wnd.mouse.IsEmpty()) + { + const auto e = wnd.mouse.Read(); + + if (e.GetType() == Mouse::Event::Type::LPress) + { + if (input == 0) + { + engaged = true; + P = cam.TrasformPoint(wnd.mouse.GetPos()); + } + if (input == 1) + { + engaged = false; + Q = cam.TrasformPoint(wnd.mouse.GetPos()); + Shapes.push_back(std::make_unique(P, Q)); + } + + input++; + + if (input >= 2) + { + input = 0; + engaged = false; + } + } + if (e.GetType() == Mouse::Event::Type::RPress) + { + + engaged = false; + } + } + if (engaged) + { + Q = cam.TrasformPoint(wnd.mouse.GetPos()); + cam.DrawLine(P, Q, Colors::Red); + } + break; + } case MainWindow::MWShapeState::Null: { while (!wnd.mouse.IsEmpty()) @@ -175,6 +217,6 @@ void Game::ComposeFrame() { c.get()->Draw(cam); } - //ct.DrawClosedPolyline(Star::Make(200, 75.0,7), Colors::Red); + cam.DrawClosedPolyline(Star::Make(200, 75.0,7), Colors::Red); } From 5bf2de3113a0e5cfea0777a0e301217f4861b88d Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 15 Jul 2018 21:09:31 +0200 Subject: [PATCH 66/84] Added licence coment --- Engine/Star.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Engine/Star.h b/Engine/Star.h index 2494b5a2..ad06e006 100644 --- a/Engine/Star.h +++ b/Engine/Star.h @@ -1,5 +1,25 @@ #pragma once +/****************************************************************************************** +* Chili DirectX Framework Version 16.07.20 * +* Star.h * +* Copyright 2016 PlanetChili * +* * +* This file is part of The Chili DirectX Framework. * +* * +* The Chili DirectX Framework is free software: you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation, either version 3 of the License, or * +* (at your option) any later version. * +* * +* The Chili DirectX Framework is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with The Chili DirectX Framework. If not, see . * +******************************************************************************************/ #include #include "JC_Vector2.h" From 1527172f02717d658669ea8c8479f841894d70cf Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Mon, 16 Jul 2018 17:45:49 +0200 Subject: [PATCH 67/84] Removed math functions from Circle class Moved to math.h What caused linker 2005 error Was fixed by splitting math.h to header and cpp file Removed asertions because they were causing problems now program works just fine. And it is able to draw 3 point circle. --- Engine/Engine.vcxproj | 1 + Engine/Engine.vcxproj.filters | 21 ++++++--- Engine/Graphics.cpp | 47 +++++++++---------- Engine/JC_Circle.cpp | 87 +---------------------------------- Engine/JC_Circle.h | 19 ++------ Engine/JC_Math.cpp | 82 +++++++++++++++++++++++++++++++++ Engine/JC_Math.h | 63 ++++++++++++++----------- 7 files changed, 162 insertions(+), 158 deletions(-) create mode 100644 Engine/JC_Math.cpp diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index 2db0c0f5..dbea3b09 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -166,6 +166,7 @@ + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index d97f8341..33ceac75 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -28,6 +28,12 @@ {b9b4aa28-3d6d-4412-b8b4-6ff6c3af9881} + + {ab08727f-c0bc-4aac-a38c-7a209aa66dcb} + + + {85608aef-b314-4019-9eef-58cd5dee7256} + @@ -69,9 +75,6 @@ Header Files - - Header Files - Header Files\Geometric shapes @@ -93,12 +96,15 @@ Header Files\Geometric shapes - - Header Files - Header Files\Geometric shapes + + Header Files\MathLib + + + Header Files\MathLib + @@ -131,6 +137,9 @@ Source Files\Shapes + + Source Files\MathLib + diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index 529663d1..601a1b9f 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -358,9 +358,6 @@ void Graphics::DrawClosedPolyline(const std::vector& verts, Color c) // line with per pixel clipping - - - void Graphics::DrawLine(double x1, double y1, double x2, double y2, Color c) { const double dx = x2 - x1; @@ -444,28 +441,28 @@ void Graphics::DrawCircle(double Ox, double Oy, double R, Color& c) int yi = (int)(std::sqrt(radsqr - (xi*xi)) + 0.5f); - if (Ox + xi >= 0 && Ox + xi < ScreenWidth && Oy + yi >= 0 && Oy + yi < ScreenHeight) - PutPixel((int)Ox + xi, (int)Oy + yi, c); - - if (Ox + yi >= 0 && Ox + yi < ScreenWidth && Oy + xi >= 0 && Oy + xi < ScreenHeight) - PutPixel((int)Ox + yi, (int)Oy + xi, c); - - if (Ox -xi >= 0 && Ox -xi < ScreenWidth && Oy + yi >= 0 && Oy + yi < ScreenHeight) - PutPixel((int)Ox - xi, (int)Oy + yi, c); - - if (Ox -yi >= 0 && Ox -yi < ScreenWidth && Oy + xi >= 0 && Oy + xi < ScreenHeight) - PutPixel((int)Ox - yi, (int)Oy + xi, c); - - if (Ox -xi >= 0 && Ox -xi < ScreenWidth && Oy -yi >= 0 && Oy -yi < ScreenHeight) - PutPixel((int)Ox - xi, (int)Oy - yi, c); - - if (Ox -yi >= 0 && Ox-yi < ScreenWidth && Oy -xi >= 0 && Oy -xi < ScreenHeight) - PutPixel((int)Ox - yi, (int)Oy - xi, c); - - if (Ox + xi >= 0 && Ox + xi < ScreenWidth && Oy -yi >= 0 && Oy -yi < ScreenHeight) - PutPixel((int)Ox + xi, (int)Oy - yi, c); - - if (Ox + yi >= 0 && Ox + yi < ScreenWidth && Oy -xi >= 0 && Oy -xi < ScreenHeight) + if (Ox + xi >= 0 && Ox + xi < ScreenWidth - 1 && Oy + yi >= 0 && Oy + yi < ScreenHeight-1) + PutPixel((int)Ox + xi, (int)Oy + yi, c); + + if (Ox + yi >= 0 && Ox + yi < ScreenWidth - 1 && Oy + xi >= 0 && Oy + xi < ScreenHeight-1) + PutPixel((int)Ox + yi, (int)Oy + xi, c); + + if (Ox -xi >= 0 && Ox -xi < ScreenWidth - 1 && Oy + yi >= 0 && Oy + yi < ScreenHeight-1) + PutPixel((int)Ox - xi, (int)Oy + yi, c); + + if (Ox -yi >= 0 && Ox -yi < ScreenWidth - 1 && Oy + xi >= 0 && Oy + xi < ScreenHeight-1) + PutPixel((int)Ox - yi, (int)Oy + xi, c); + + if (Ox -xi >= 0 && Ox -xi < ScreenWidth - 1 && Oy -yi >= 0 && Oy -yi < ScreenHeight-1) + PutPixel((int)Ox - xi, (int)Oy - yi, c); + + if (Ox -yi >= 0 && Ox-yi < ScreenWidth - 1 && Oy -xi >= 0 && Oy -xi < ScreenHeight-1) + PutPixel((int)Ox - yi, (int)Oy - xi, c); + + if (Ox + xi >= 0 && Ox + xi < ScreenWidth-1 && Oy -yi >= 0 && Oy -yi < ScreenHeight-1) + PutPixel((int)Ox + xi, (int)Oy - yi, c); + + if (Ox + yi >= 0 && Ox + yi < ScreenWidth-1 && Oy -xi >= 0 && Oy -xi < ScreenHeight-1) PutPixel((int)Ox + yi, (int)Oy - xi, c); } diff --git a/Engine/JC_Circle.cpp b/Engine/JC_Circle.cpp index f0e06dcd..37cec64e 100644 --- a/Engine/JC_Circle.cpp +++ b/Engine/JC_Circle.cpp @@ -15,7 +15,7 @@ JC_Circle::JC_Circle(const JC_Point2d& P_in, const JC_Point2d& Q_in, Color color JC_Circle::JC_Circle(const JC_Point2d& P_in, const JC_Point2d& Q_in, const JC_Point2d& R_in, Color color_in) : JC_Shape(color_in), - O(CalculatCentre(P_in, Q_in, R_in)), + O(CalculateCentre(P_in, Q_in, R_in)), radius(GetDistanceTo(O, R_in)) {} @@ -33,88 +33,3 @@ bool JC_Circle::IsInRange(const JC_Point2d& mouse_in) return (distance <= (radius + halfwidth) && distance >= (radius - halfwidth)); } - - - - - -JC_Point2d JC_Circle::CalculatCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) -{ - { - //when we have 2 flat lines in order under right angle - if (P.x == R.x && Q.y == R.y) - { - JC_Point2d C; - C.x = (R.x + Q.x) / 2; - C.y = (P.y + R.y) / 2; - return C; - - } - //when we have 2 flat lines in reverce order under right angle - else if (P.y == R.y && Q.x == R.x) - { - JC_Point2d C; - C.x = R.x + P.x / 2; - C.y = Q.y + R.y / 2; - return C; - } - else if (P.x == R.x && Q.y != R.y) - { - - JC_Point2d C = CalculateSpecificCentre(P, R, Q); - return C; - - } - else if (P.x != R.x && Q.y == R.y) - { - JC_Point2d C = CalculateSpecificCentre(R, Q, P); - return C; - } - else //if (P.x != Q.x && P.y != Q.y || Q.x != R.x && Q.y != R.y) - { - JC_Point2d C = CalculateSpecificCentre(P, Q, R); - return C; - - } - } -} - -JC_Point2d JC_Circle::CalculateSpecificCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) -{ - { - - double m1 = LineSlopeBetween2Points(P, R); - double m2 = LineSlopeBetween2Points(Q, R); - - //If slopes are the same lines are parallel ,do nothing (infinite radius) - assert(m2 - m1 != 0.0); - - // calculate perpendicular line slope... - - double m1_perp = InverceLineSlope(m1); - double m2_perp = InverceLineSlope(m2); - - //mid point of orginally inserted lines - - JC_Point2d mid_PR = GetMidPoint(P,R); - - JC_Point2d mid_QR = GetMidPoint(Q,R); - - - // y=mx+b find b part of perpendicular line - // y-y1 = m(x-x1) = > y = mx - m*x1 + y1 - //https://www.varsitytutors.com/hotmath/hotmath_help/topics/point-slope-form.html - - double a = (-m1_perp * mid_PR.x + mid_PR.y); - double b = (-m2_perp * mid_QR.x + mid_QR.y); - - // find crossection - //http://www.ambrsoft.com/MathCalc/Line/TwoLinesIntersection/TwoLinesIntersection.htm - - JC_Point2d C; - C.x = (a - b) / (m2_perp - m1_perp); - C.y = ((m1_perp * b) - (m2_perp * a)) / (m1_perp - m2_perp); - - return C; - } -} diff --git a/Engine/JC_Circle.h b/Engine/JC_Circle.h index 5c651484..853d8b18 100644 --- a/Engine/JC_Circle.h +++ b/Engine/JC_Circle.h @@ -2,10 +2,11 @@ #include "JC_Shape.h" +#include "JC_Math.h" - -#include "Graphics.h" #include "JC_Vector2.h" +#include "Graphics.h" + #include "Camera.h" @@ -20,19 +21,7 @@ class JC_Circle : public JC_Shape void Draw(Camera cam_in) override; bool IsInRange(const JC_Point2d& mouse_in) override; - -private: - //**We have couple of types of centre calculation: - //**When we can Determine slope of both lines, then we proces points in seen order. - //**When we can't determine slope of any of lines (parallel to the window sides) - // in this situation we are calculating centre using line mid point rule - //**When we are unable to determine solope of one from the lines - // in this situation we are simply swaping order of the points. - JC_Point2d CalculatCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); - - //Used to calculate centre from points from which created lines have caclulatable slope (at least one line) - JC_Point2d CalculateSpecificCentre(const JC_Point2d& P, const JC_Point2d& Q, const JC_Point2d& R); - + private: JC_Point2d O; double radius; diff --git a/Engine/JC_Math.cpp b/Engine/JC_Math.cpp new file mode 100644 index 00000000..5cc0fc02 --- /dev/null +++ b/Engine/JC_Math.cpp @@ -0,0 +1,82 @@ +#include "JC_Math.h" + +JC_Point2d CalculateCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) +{ + + //when we have 2 flat lines in order under right angle + if (std::abs(P.x) == std::abs(R.x) && std::abs(Q.y) == std::abs(R.y)) + { + JC_Point2d C; + C.x = (R.x + Q.x) / 2; + C.y = (P.y + R.y) / 2; + return C; + + } + //when we have 2 flat lines in reverce order under right angle + else if (std::abs(P.y) == std::abs(R.y) && std::abs(Q.x) == std::abs(R.x)) + { + JC_Point2d C; + C.x = R.x + P.x / 2; + C.y = Q.y + R.y / 2; + return C; + } + else if (std::abs(P.x) == std::abs(R.x) && std::abs(Q.y) != std::abs(R.y)) + { + + JC_Point2d C = CalculateSpecificCentre(P, R, Q); + return C; + + } + else if (std::abs(P.x) != std::abs(R.x) && std::abs(Q.y) == std::abs(R.y)) + { + JC_Point2d C = CalculateSpecificCentre(R, Q, P); + return C; + } + else if (std::abs (P.x) != std::abs(Q.x) && std::abs(P.y) != std::abs(Q.y) || std::abs(Q.x) != std::abs(R.x) && std::abs(Q.y) != std::abs(R.y)) + { + JC_Point2d C = CalculateSpecificCentre(P, Q, R); + return C; + + } + +} + +JC_Point2d CalculateSpecificCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) +{ + + + double m1 = LineSlopeBetween2Points(P, R); + double m2 = LineSlopeBetween2Points(Q, R); + + //If slopes are the same lines are parallel ,do nothing (infinite radius) + assert(m2 - m1 != 0.0); + + // calculate perpendicular line slope... + + double m1_perp = InverceLineSlope(m1); + double m2_perp = InverceLineSlope(m2); + + //mid point of orginally inserted lines + + JC_Point2d mid_PR = GetMidPoint(P, R); + + JC_Point2d mid_QR = GetMidPoint(Q, R); + + + // y=mx+b find b part of perpendicular line + // y-y1 = m(x-x1) = > y = mx - m*x1 + y1 + //https://www.varsitytutors.com/hotmath/hotmath_help/topics/point-slope-form.html + + double a = (-m1_perp * mid_PR.x + mid_PR.y); + double b = (-m2_perp * mid_QR.x + mid_QR.y); + + // find crossection + //http://www.ambrsoft.com/MathCalc/Line/TwoLinesIntersection/TwoLinesIntersection.htm + + JC_Point2d C; + C.x = (a - b) / (m2_perp - m1_perp); + C.y = ((m1_perp * b) - (m2_perp * a)) / (m1_perp - m2_perp); + + return C; + +} diff --git a/Engine/JC_Math.h b/Engine/JC_Math.h index 048c9bba..971bfa2a 100644 --- a/Engine/JC_Math.h +++ b/Engine/JC_Math.h @@ -8,42 +8,53 @@ constexpr double PI_F = 3.1415926536; constexpr double PI_D = 3.1415926535897932; -template -inline auto Sq(const T& x) -{ - return x * x; -} + template + inline auto Sq(const T& x) + { + return x * x; + } -inline float Slope(const float x1, const float y1, const float x2, const float y2) -{ - float dx = x2 - x1; - float dy = y2 - y1; - float m = dy / dx; - return m; - -} + inline float Slope(const float x1, const float y1, const float x2, const float y2) + { + float dx = x2 - x1; + float dy = y2 - y1; + + float m = dy / dx; + return m; -inline double LineSlopeBetween2Points(const JC_Point2d& P, const JC_Point2d& Q) -{ - double dx = Q.x - P.x; - double dy = Q.y - P.y; + } - assert(dx != 0.0); + inline double LineSlopeBetween2Points(const JC_Point2d& P, const JC_Point2d& Q) + { + double dx = Q.x - P.x; + double dy = Q.y - P.y; - double m = dy / dx; + //assert(dx != 0.0); - return m; + double m = dy / dx; -} + return m; -inline double InverceLineSlope(const double& m) -{ - assert(m != 0.0f); + } - return -1 / m; -} + inline double InverceLineSlope(const double& m) + { + //assert(m != 0.0f); + return -1 / m; + } + + // We have couple of types of centre calculation: + // When we can Determine slope of both lines, then we proces points in seen order. + // When we can't determine slope of any of lines (parallel to the window sides) + // in this situation we are calculating centre using line mid point rule + // When we are unable to determine solope of one from the lines + // in this situation we are simply swaping order of the points. + JC_Point2d CalculateCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R); + + //Used to calculate centre from points from which created lines have caclulatable slope (at least one line) + JC_Point2d CalculateSpecificCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R); From b1ee67e48de9565189147a2e6407d7d55fd71e33 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Mon, 16 Jul 2018 17:48:30 +0200 Subject: [PATCH 68/84] Dynamic 3 point circle drawing, implemented boolean operators for point comparasion Used to fix same point position problem. --- Engine/Game.cpp | 72 +++++++++++++++++++++++++++++++++++++++++---- Engine/Game.h | 2 +- Engine/JC_Vector2.h | 12 ++++++++ 3 files changed, 80 insertions(+), 6 deletions(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index a5cbf235..4cec0351 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -95,6 +95,67 @@ void Game::ProcesInput() break; } + + case MainWindow::MWShapeState::ThreePointCircle: + { + while (!wnd.mouse.IsEmpty()) + { + const auto e = wnd.mouse.Read(); + + if (e.GetType() == Mouse::Event::Type::LPress) + { + if (input == 0) + { + + P = cam.TrasformPoint(wnd.mouse.GetPos()); + } + + if (input == 1) + { + engaged = true; + Q = cam.TrasformPoint(wnd.mouse.GetPos()); + } + + if (input == 2) + { + R = cam.TrasformPoint(wnd.mouse.GetPos()); + if (P != Q && Q != R) + Shapes.push_back(std::make_unique(P, Q, R)); + } + + input++; + + if (input >= 3) + { + input = 0; + engaged = false; + } + } + if (e.GetType() == Mouse::Event::Type::RPress) + { + input = 0; + engaged = false; + } + } + if (engaged) + { + + R = cam.TrasformPoint(wnd.mouse.GetPos()); + if (P == Q) + { + input = 0; + engaged = false; + } + else if (Q != R) + { + cam.DrawCircle(CalculateCentre(P, Q, R), GetDistanceTo(CalculateCentre(P, Q, R), R), Colors::Red); + //cam.DrawLine(CalculateCentre(P, Q, R), R, Colors::Red); + } + + } + break; + } + case MainWindow::MWShapeState::LineSegment: { while (!wnd.mouse.IsEmpty()) @@ -170,6 +231,7 @@ void Game::ProcesInput() wnd.ShapeState = MainWindow::MWShapeState::Null; input = 0; + engaged = false; for (auto &c : Shapes) { @@ -186,19 +248,19 @@ void Game::ProcesInput() const float speed = 7.0f; if (wnd.kbd.KeyIsPressed(VK_DOWN)) { - cam.MoveBy({ 0.0f,speed }); + cam.MoveBy({ 0.0f,-speed }); } if (wnd.kbd.KeyIsPressed(VK_UP)) { - cam.MoveBy({ 0.0f,-speed }); + cam.MoveBy({ 0.0f,speed }); } if (wnd.kbd.KeyIsPressed(VK_LEFT)) { - cam.MoveBy({ speed,0.0f }); + cam.MoveBy({ -speed,0.0f }); } if (wnd.kbd.KeyIsPressed(VK_RIGHT)) { - cam.MoveBy({ -speed,0.0f }); + cam.MoveBy({ speed,0.0f }); } } @@ -217,6 +279,6 @@ void Game::ComposeFrame() { c.get()->Draw(cam); } - cam.DrawClosedPolyline(Star::Make(200, 75.0,7), Colors::Red); + //cam.DrawClosedPolyline(Star::Make(200, 75.0,7), Colors::Red); } diff --git a/Engine/Game.h b/Engine/Game.h index 499d5901..b043ac77 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -30,6 +30,7 @@ #include "MouseCameraControler.h" #include "JC_Vector2.h" +#include "JC_Math.h" #include "JC_Circle.h" #include "JC_Line.h" #include "JC_Shape.h" @@ -70,7 +71,6 @@ class Game bool engaged = false; JC_Point2d P, Q, R; - JC_Point2i T; /********************************/ }; \ No newline at end of file diff --git a/Engine/JC_Vector2.h b/Engine/JC_Vector2.h index 60185c7e..e2e9ea66 100644 --- a/Engine/JC_Vector2.h +++ b/Engine/JC_Vector2.h @@ -67,6 +67,18 @@ using JC_Vector2f = JC_Vector2; using JC_Vector2i = JC_Vector2; + +template bool operator== (const JC_Point2& lhs, const JC_Point2& rhs) +{ + return ((lhs.x == rhs.x) && (lhs.y == rhs.y)); +} +template bool operator!= (const JC_Point2& lhs, const JC_Point2& rhs) +{ + return ((lhs.x != rhs.x) || (lhs.y != rhs.y)); +} + + + template JC_Vector2& operator+=(JC_Vector2& lhs, const JC_Vector2& rhs) { lhs.x += rhs.x; From 7b32217aec3d6c2302202edb2f5f47be4329c554 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 20 Jul 2018 17:23:34 +0200 Subject: [PATCH 69/84] Added posibility to draw closed Poliline with camera manipulations --- Engine/Camera.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Engine/Camera.h b/Engine/Camera.h index 120e15f7..cdccf605 100644 --- a/Engine/Camera.h +++ b/Engine/Camera.h @@ -42,6 +42,14 @@ class Camera ct.DrawCircle(std::move(pos), std::move(radius), Color_in); } + void DrawClosedPolyline(std::vector poly, Color c) + { + for (auto& v : poly) + { + v -= Camera_Pos; + } + ct.DrawClosedPolyline(std::move(poly), c); + } // trasforms Point screen coordinates to mathematical coordinates regardles from cmaera position From 1686a130b22b629ce8923b38ac695ed4df677cf0 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 20 Jul 2018 17:39:03 +0200 Subject: [PATCH 70/84] Added ability to draw line when 3 point circle is created --- Engine/Engine.vcxproj.filters | 6 ++--- Engine/Game.cpp | 48 +++++++++++++++++++++-------------- Engine/Game.h | 7 +++-- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index 33ceac75..6a6a0e86 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -63,9 +63,6 @@ Header Files - - Header Files - Header Files @@ -105,6 +102,9 @@ Header Files\MathLib + + Resource Files + diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 4cec0351..27a36f97 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -31,8 +31,8 @@ Game::Game(MainWindow& wnd) wnd(wnd), gfx(wnd), ct(gfx), - cam(ct), - camCtrl(wnd.mouse,cam) + cam(ct)//, + //camCtrl(wnd.mouse,cam) { } @@ -60,7 +60,7 @@ void Game::ProcesInput() if (input == 0) { - engaged = true; + first_point_engagement = true; P = cam.TrasformPoint(wnd.mouse.GetPos()); } if (input == 1) @@ -76,16 +76,16 @@ void Game::ProcesInput() if (input >= 2) { input = 0; - engaged = false; + first_point_engagement = false; } } if (e.GetType() == Mouse::Event::Type::RPress) { input = 0; - engaged = false; + first_point_engagement = false; } } - if (engaged) + if (first_point_engagement) { Q = cam.TrasformPoint(wnd.mouse.GetPos()); @@ -106,13 +106,13 @@ void Game::ProcesInput() { if (input == 0) { - + first_point_engagement = true; P = cam.TrasformPoint(wnd.mouse.GetPos()); } if (input == 1) { - engaged = true; + second_point_engagement = true; Q = cam.TrasformPoint(wnd.mouse.GetPos()); } @@ -128,27 +128,36 @@ void Game::ProcesInput() if (input >= 3) { input = 0; - engaged = false; + second_point_engagement = false; } } if (e.GetType() == Mouse::Event::Type::RPress) { input = 0; - engaged = false; + first_point_engagement = false; + second_point_engagement = false; } } - if (engaged) + if (first_point_engagement) { - + Q = cam.TrasformPoint(wnd.mouse.GetPos()); + cam.DrawLine(P, Q, Colors::Red); + } + if (second_point_engagement) + { + first_point_engagement = false; R = cam.TrasformPoint(wnd.mouse.GetPos()); if (P == Q) { input = 0; - engaged = false; + second_point_engagement = false; } else if (Q != R) { cam.DrawCircle(CalculateCentre(P, Q, R), GetDistanceTo(CalculateCentre(P, Q, R), R), Colors::Red); + cam.DrawCircle(P, 10, Colors::Red); + cam.DrawCircle(Q, 10, Colors::Red); + cam.DrawCircle(R, 10, Colors::Red); //cam.DrawLine(CalculateCentre(P, Q, R), R, Colors::Red); } @@ -166,12 +175,12 @@ void Game::ProcesInput() { if (input == 0) { - engaged = true; + first_point_engagement = true; P = cam.TrasformPoint(wnd.mouse.GetPos()); } if (input == 1) { - engaged = false; + first_point_engagement = false; Q = cam.TrasformPoint(wnd.mouse.GetPos()); Shapes.push_back(std::make_unique(P, Q)); } @@ -181,16 +190,16 @@ void Game::ProcesInput() if (input >= 2) { input = 0; - engaged = false; + first_point_engagement = false; } } if (e.GetType() == Mouse::Event::Type::RPress) { - engaged = false; + first_point_engagement = false; } } - if (engaged) + if (first_point_engagement) { Q = cam.TrasformPoint(wnd.mouse.GetPos()); cam.DrawLine(P, Q, Colors::Red); @@ -231,7 +240,8 @@ void Game::ProcesInput() wnd.ShapeState = MainWindow::MWShapeState::Null; input = 0; - engaged = false; + first_point_engagement = false; + second_point_engagement = false; for (auto &c : Shapes) { diff --git a/Engine/Game.h b/Engine/Game.h index b043ac77..fe03dc33 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -64,13 +64,16 @@ class Game /* User Variables */ CoordinateTrasformer ct; Camera cam; - MouseCameraController camCtrl; + //MouseCameraController camCtrl; std::vector> Shapes; unsigned short input = 0; - bool engaged = false; + bool first_point_engagement = false; + bool second_point_engagement = false; JC_Point2d P, Q, R; + + /********************************/ }; \ No newline at end of file From 0485f20056ebd5ca710e82b8678fd0ebb82696d9 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Fri, 20 Jul 2018 20:20:00 +0200 Subject: [PATCH 71/84] Refactorisation of 3 point creation stages --- Engine/Game.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 27a36f97..d40ee922 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -94,8 +94,6 @@ void Game::ProcesInput() } break; } - - case MainWindow::MWShapeState::ThreePointCircle: { while (!wnd.mouse.IsEmpty()) @@ -141,7 +139,8 @@ void Game::ProcesInput() if (first_point_engagement) { Q = cam.TrasformPoint(wnd.mouse.GetPos()); - cam.DrawLine(P, Q, Colors::Red); + auto Temp = GetMidPoint(P, Q); + cam.DrawCircle(Temp, GetDistanceTo(Temp, Q), Colors::Red); } if (second_point_engagement) { @@ -154,7 +153,8 @@ void Game::ProcesInput() } else if (Q != R) { - cam.DrawCircle(CalculateCentre(P, Q, R), GetDistanceTo(CalculateCentre(P, Q, R), R), Colors::Red); + auto Temp = CalculateCentre(P, Q, R); + cam.DrawCircle(Temp, GetDistanceTo(Temp, R), Colors::Red); cam.DrawCircle(P, 10, Colors::Red); cam.DrawCircle(Q, 10, Colors::Red); cam.DrawCircle(R, 10, Colors::Red); @@ -164,7 +164,6 @@ void Game::ProcesInput() } break; } - case MainWindow::MWShapeState::LineSegment: { while (!wnd.mouse.IsEmpty()) From d3edb406d685f14fa9162913441fc5f4f203b151 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 22 Jul 2018 10:37:09 +0200 Subject: [PATCH 72/84] Added point scalar multiplication --- Engine/JC_Vector2.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Engine/JC_Vector2.h b/Engine/JC_Vector2.h index e2e9ea66..56dc19af 100644 --- a/Engine/JC_Vector2.h +++ b/Engine/JC_Vector2.h @@ -93,7 +93,6 @@ template JC_Point2& operator+=(JC_Point2& lhs, const JC_Vector2 JC_Point2& operator+=(JC_Point2& lhs, const JC_Point2& rhs) { lhs.x += rhs.x; @@ -117,7 +116,6 @@ template JC_Point2& operator-=(JC_Point2& lhs, const JC_Vector2 JC_Point2& operator-=(JC_Point2& lhs, const JC_Point2& rhs) { lhs.x -= rhs.x; @@ -177,6 +175,32 @@ template JC_Vector2 operator/(const JC_Vector2& v, T s) return { v.x / s,v.y / s }; } + +template JC_Point2 operator*=(JC_Point2 lhs, T rhs) +{ + lhs.x *= rhs; + lhs.y *= rhs; + return lhs; +} +template JC_Point2 operator/=(JC_Point2 lhs, T rhs) +{ + lhs.x /= rhs; + lhs.y /= rhs; + return lhs; +} +template JC_Point2 operator*=(T lhs, JC_Point2 rhs) +{ + rhs.x *= lhs; + rhs.y *= lhs; + return rhs; +} +template JC_Point2 operator/=(T lhs , JC_Point2 rhs) +{ + rhs.x /= lhs; + rhs.y /= lhs; + return rhs; +} + template T dot_product(const JC_Vector2& v0, const JC_Vector2& v1) { return (v0.x * v1.x) + (v0.y + v1.y); From 7e222b9e1e3785511be995c8ff483c4bca9387c9 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 22 Jul 2018 10:46:11 +0200 Subject: [PATCH 73/84] To three point circle added statements preventing creation of the circle witch infinite radius --- Engine/Game.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index d40ee922..d33e4f79 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -117,7 +117,7 @@ void Game::ProcesInput() if (input == 2) { R = cam.TrasformPoint(wnd.mouse.GetPos()); - if (P != Q && Q != R) + if (P != Q && Q != R && !(LineSlopeBetween2Points(P, R) == LineSlopeBetween2Points(R, Q))) Shapes.push_back(std::make_unique(P, Q, R)); } @@ -136,6 +136,7 @@ void Game::ProcesInput() second_point_engagement = false; } } + //Draw circle from two points when left mouse button is pressed for the first time if (first_point_engagement) { Q = cam.TrasformPoint(wnd.mouse.GetPos()); @@ -151,7 +152,7 @@ void Game::ProcesInput() input = 0; second_point_engagement = false; } - else if (Q != R) + else if (Q != R && !(LineSlopeBetween2Points(P, R) == LineSlopeBetween2Points(R, Q))) { auto Temp = CalculateCentre(P, Q, R); cam.DrawCircle(Temp, GetDistanceTo(Temp, R), Colors::Red); @@ -271,7 +272,6 @@ void Game::ProcesInput() { cam.MoveBy({ speed,0.0f }); } - } void Game::UpdateModel() From b08c6764948a526b89bf40d5297cb433fda8378f Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 22 Jul 2018 10:49:05 +0200 Subject: [PATCH 74/84] Fixed graphical issue causing 3point circle to do not display when P.y and R.y are equal --- Engine/JC_Math.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Engine/JC_Math.cpp b/Engine/JC_Math.cpp index 5cc0fc02..0f06e77f 100644 --- a/Engine/JC_Math.cpp +++ b/Engine/JC_Math.cpp @@ -2,37 +2,33 @@ JC_Point2d CalculateCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) { - //when we have 2 flat lines in order under right angle if (std::abs(P.x) == std::abs(R.x) && std::abs(Q.y) == std::abs(R.y)) { JC_Point2d C; - C.x = (R.x + Q.x) / 2; - C.y = (P.y + R.y) / 2; + C.x = (R.x + P.x) / 2; + C.y = (Q.y + R.y) / 2; return C; - } //when we have 2 flat lines in reverce order under right angle else if (std::abs(P.y) == std::abs(R.y) && std::abs(Q.x) == std::abs(R.x)) { JC_Point2d C; - C.x = R.x + P.x / 2; - C.y = Q.y + R.y / 2; + C.x = R.x + Q.x / 2; + C.y = P.y + R.y / 2; return C; } - else if (std::abs(P.x) == std::abs(R.x) && std::abs(Q.y) != std::abs(R.y)) + else if (std::abs(P.x) == std::abs(R.x) && std::abs(Q.y) != std::abs(R.y) || std::abs(P.y) == std::abs(R.y) && std::abs(Q.x) != std::abs(R.x)) { - JC_Point2d C = CalculateSpecificCentre(P, R, Q); return C; - } - else if (std::abs(P.x) != std::abs(R.x) && std::abs(Q.y) == std::abs(R.y)) + else if (std::abs(P.x) != std::abs(R.x) && std::abs(Q.y) == std::abs(R.y) || std::abs(P.y) == std::abs(R.y) && std::abs(Q.x) != std::abs(R.x)) { JC_Point2d C = CalculateSpecificCentre(R, Q, P); return C; } - else if (std::abs (P.x) != std::abs(Q.x) && std::abs(P.y) != std::abs(Q.y) || std::abs(Q.x) != std::abs(R.x) && std::abs(Q.y) != std::abs(R.y)) + else if ( P != Q || Q != R ) { JC_Point2d C = CalculateSpecificCentre(P, Q, R); return C; From 72467dcc805b70258623dcbecda9d407e86a8570 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 22 Jul 2018 10:52:16 +0200 Subject: [PATCH 75/84] Getting read of star drawclosed poliline form frame work --- Engine/Camera.h | 33 +++++++++++------------------ Engine/CordinateTrasformerh.h | 14 ------------- Engine/Graphics.cpp | 39 ----------------------------------- Engine/Graphics.h | 10 --------- Engine/JC_Circle.cpp | 3 +-- Engine/JC_Circle.h | 2 +- Engine/JC_Shape.h | 3 +++ 7 files changed, 17 insertions(+), 87 deletions(-) diff --git a/Engine/Camera.h b/Engine/Camera.h index cdccf605..0c190691 100644 --- a/Engine/Camera.h +++ b/Engine/Camera.h @@ -29,6 +29,16 @@ class Camera Camera_Pos = pos_in; } + void SetScale(double new_scale) + { + scale = new_scale; + } + + double GetScale() const + { + return scale; + } + void DrawLine(JC_Point2d P_in, JC_Point2d Q_in, Color Color_in) { P_in -= Camera_Pos; @@ -39,16 +49,7 @@ class Camera void DrawCircle(JC_Point2d pos, double radius, Color Color_in) { pos -= Camera_Pos; - ct.DrawCircle(std::move(pos), std::move(radius), Color_in); - } - - void DrawClosedPolyline(std::vector poly, Color c) - { - for (auto& v : poly) - { - v -= Camera_Pos; - } - ct.DrawClosedPolyline(std::move(poly), c); + ct.DrawCircle(std::move(pos), std::move(radius), std::move(Color_in)); } // trasforms Point screen coordinates to mathematical coordinates regardles from cmaera position @@ -64,17 +65,7 @@ class Camera input.y *= -1; return input; } - - void SetScale(double new_scale) - { - scale = new_scale; - } - - double GetScale() const - { - return scale; - } - + private: double scale = 1.0; JC_Point2d Camera_Pos = { 0.0,0.0 }; diff --git a/Engine/CordinateTrasformerh.h b/Engine/CordinateTrasformerh.h index 7df70bd0..4b0089bc 100644 --- a/Engine/CordinateTrasformerh.h +++ b/Engine/CordinateTrasformerh.h @@ -40,20 +40,6 @@ class CoordinateTrasformer gfx.DrawCircle(pos, radius, c); } - - void DrawClosedPolyline(std::vector poly, Color c) - { - JC_Vector2d offset = { double(Graphics::ScreenWidth / 2),double(Graphics::ScreenHeight / 2) }; - for (auto& v : poly) - { - v.y *= -1.0; - v += offset; - } - gfx.DrawClosedPolyline(poly, c); - } - - - private: Graphics& gfx; diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index 601a1b9f..db81df1f 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -241,35 +241,6 @@ Graphics::Graphics( HWNDKey& key ) _aligned_malloc( sizeof( Color ) * Graphics::ScreenWidth * Graphics::ScreenHeight,16u ) ); } -void Graphics::DrawFlatEllipse(float Ox, float Oy, float Rx, float Ry, Color c) -{ - if (Ry==0.0) - { - DrawLine(Ox - Rx, Oy, Ox + Rx, Oy, c); - } - else if (Rx==0.0) - { - - DrawLine(Ox, Oy - Ry, Ox, Oy + Ry, c); - } - else if (Rx == 0.0 && Ry == 0.0) - { - PutPixel((int)(Ox), (int)(Oy), c); - } - else - { - for (double theta = 0; theta < 360; theta += 0.2) - { - float x = (float)(Rx * std::cos(PI_F*theta / 180)); - float y = (float)(Ry * std::sin(PI_F*theta / 180)); - - PutPixel((int)(Ox), (int)(Oy), c); - PutPixel((int)(x + 0.5f + Ox), (int)(y + 0.5f + Oy), c); - } - } - -} - Graphics::~Graphics() { // free sysbuffer memory (aligned free) @@ -347,16 +318,6 @@ void Graphics::PutPixel( int x,int y,Color c ) } -void Graphics::DrawClosedPolyline(const std::vector& verts, Color c) -{ - for (auto i = verts.begin(); i != std::prev(verts.end()); i++) - { - DrawLine(*i, *std::next(i), c); - } - DrawLine(verts.back(), verts.front(), c); -} - - // line with per pixel clipping void Graphics::DrawLine(double x1, double y1, double x2, double y2, Color c) { diff --git a/Engine/Graphics.h b/Engine/Graphics.h index ab37efdb..6c87a254 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -64,7 +64,6 @@ class Graphics } void PutPixel( int x,int y,Color c ); - void DrawClosedPolyline(const std::vector& verts, Color c); /***** Start Draw Line Functions *****/ @@ -98,15 +97,6 @@ class Graphics /***** End Draw Arc Functions *****/ - - - /***** Start Draw Ellipse Functions *****/ - - void DrawFlatEllipse(float Ox, float Oy, float Rx, float Ry, Color c); - - /***** End Draw Ellipse Functions *****/ - - ~Graphics(); private: Microsoft::WRL::ComPtr pSwapChain; diff --git a/Engine/JC_Circle.cpp b/Engine/JC_Circle.cpp index 37cec64e..34815523 100644 --- a/Engine/JC_Circle.cpp +++ b/Engine/JC_Circle.cpp @@ -11,7 +11,6 @@ JC_Circle::JC_Circle(const JC_Point2d& P_in, const JC_Point2d& Q_in, Color color {} - JC_Circle::JC_Circle(const JC_Point2d& P_in, const JC_Point2d& Q_in, const JC_Point2d& R_in, Color color_in) : JC_Shape(color_in), @@ -20,13 +19,13 @@ JC_Circle::JC_Circle(const JC_Point2d& P_in, const JC_Point2d& Q_in, const JC_Po {} + void JC_Circle::Draw(Camera cam_in) { cam_in.DrawCircle(O, radius, Base_Color); } - bool JC_Circle::IsInRange(const JC_Point2d& mouse_in) { double distance = GetDistanceTo(O, mouse_in); diff --git a/Engine/JC_Circle.h b/Engine/JC_Circle.h index 853d8b18..a9ae88b1 100644 --- a/Engine/JC_Circle.h +++ b/Engine/JC_Circle.h @@ -21,7 +21,7 @@ class JC_Circle : public JC_Shape void Draw(Camera cam_in) override; bool IsInRange(const JC_Point2d& mouse_in) override; - + private: JC_Point2d O; double radius; diff --git a/Engine/JC_Shape.h b/Engine/JC_Shape.h index dfc38636..e9e71fd2 100644 --- a/Engine/JC_Shape.h +++ b/Engine/JC_Shape.h @@ -29,6 +29,9 @@ class JC_Shape { return selectedflag; } + + + protected: JC_Shape( Color& color_in) From db581fec507320f166f12f8b6b9d5a3c987c91ad Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 17 Mar 2019 05:50:18 +0100 Subject: [PATCH 76/84] Selection of line implemented --- Engine/JC_Line.h | 19 +++++++++++++++---- Engine/JC_Math.cpp | 32 +++++++++++++++++++++++++++++++- Engine/JC_Math.h | 6 ++++++ 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/Engine/JC_Line.h b/Engine/JC_Line.h index 981505d9..232c78e5 100644 --- a/Engine/JC_Line.h +++ b/Engine/JC_Line.h @@ -13,13 +13,24 @@ class JC_Line : public JC_Shape JC_Shape(color_in) {} - void Draw(Camera cam_in) override + void Draw(Camera cam) override { - cam_in.DrawLine(P, Q, Base_Color); + cam.DrawLine(P, Q, Base_Color); } - bool IsInRange(const JC_Point2d& mouse_in) override + bool IsInRange(const JC_Point2d& M) override { - return false; + JC_Point2d C = ClosesPoint(P, Q, M); + + if (IsBetween2Points(P, Q, C)) + { + if ((abs(GetDistanceTo(M,C)) < halfwidth)) + return true; + + else + return false; + } + else + return false; } diff --git a/Engine/JC_Math.cpp b/Engine/JC_Math.cpp index 0f06e77f..d57fef55 100644 --- a/Engine/JC_Math.cpp +++ b/Engine/JC_Math.cpp @@ -28,7 +28,7 @@ JC_Point2d CalculateCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_ JC_Point2d C = CalculateSpecificCentre(R, Q, P); return C; } - else if ( P != Q || Q != R ) + else { JC_Point2d C = CalculateSpecificCentre(P, Q, R); return C; @@ -76,3 +76,33 @@ JC_Point2d CalculateSpecificCentre(const JC_Point2d & P, const JC_Point2d & Q, c return C; } + +JC_Point2d ClosesPoint(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) +{ + + + double c = LineSlopeBetween2Points(P, Q); + + //assert(c == 0); + + double a = InverceLineSlope(c); + + double b = R.y - (a * R.x); + double d = Q.y - (c * Q.x); + + double x = ((a*R.x) + b - d) / c; + double y = (a * x) + b; + + return JC_Point2d(x, y); +} + +bool IsBetween2Points(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) +{ + JC_Point2d C = ClosesPoint(P, Q, R); + + if ((GetDistanceTo(P, C) < GetDistanceTo(P, Q)) && (GetDistanceTo(Q, C) < GetDistanceTo(P, Q))) + return true; + else + return false; + +} diff --git a/Engine/JC_Math.h b/Engine/JC_Math.h index 971bfa2a..9f1bbf29 100644 --- a/Engine/JC_Math.h +++ b/Engine/JC_Math.h @@ -46,6 +46,8 @@ constexpr double PI_D = 3.1415926535897932; return -1 / m; } + + // We have couple of types of centre calculation: // When we can Determine slope of both lines, then we proces points in seen order. // When we can't determine slope of any of lines (parallel to the window sides) @@ -58,3 +60,7 @@ constexpr double PI_D = 3.1415926535897932; //Used to calculate centre from points from which created lines have caclulatable slope (at least one line) JC_Point2d CalculateSpecificCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R); + // First two points create line third we are exsamining + JC_Point2d ClosesPoint (const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R); + + bool IsBetween2Points(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R); From 2db66d239b1fdc71e533b07468972a3e2aba9de3 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Tue, 19 Mar 2019 00:44:11 +0100 Subject: [PATCH 77/84] Posibility to make description --- Engine/Game.cpp | 23 +++++++---------------- Engine/JC_Circle.h | 15 ++++++++++++++- Engine/JC_Line.h | 9 +++++++++ Engine/JC_Math.h | 13 +++++++++++++ Engine/JC_Shape.h | 7 +++++-- 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index d33e4f79..a02afa14 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -254,23 +254,14 @@ void Game::ProcesInput() remove_erase_if(Shapes, std::mem_fn(&JC_Shape::ReadyForRemoval)); } - - const float speed = 7.0f; - if (wnd.kbd.KeyIsPressed(VK_DOWN)) + if (wnd.kbd.KeyIsPressed(VK_RETURN)) { - cam.MoveBy({ 0.0f,-speed }); - } - if (wnd.kbd.KeyIsPressed(VK_UP)) - { - cam.MoveBy({ 0.0f,speed }); - } - if (wnd.kbd.KeyIsPressed(VK_LEFT)) - { - cam.MoveBy({ -speed,0.0f }); - } - if (wnd.kbd.KeyIsPressed(VK_RIGHT)) - { - cam.MoveBy({ speed,0.0f }); + for (auto& i : Shapes) + { + if (i.get()->IsSelected()) + wnd.ShowMessageBox(L"Description", i.get()->MakeDescription()); + } + } } diff --git a/Engine/JC_Circle.h b/Engine/JC_Circle.h index a9ae88b1..70cef8ee 100644 --- a/Engine/JC_Circle.h +++ b/Engine/JC_Circle.h @@ -4,6 +4,7 @@ #include "JC_Shape.h" #include "JC_Math.h" + #include "JC_Vector2.h" #include "Graphics.h" @@ -21,9 +22,21 @@ class JC_Circle : public JC_Shape void Draw(Camera cam_in) override; bool IsInRange(const JC_Point2d& mouse_in) override; - + + + std::wstring MakeDescription() override + { + + std::wstring PosO = L" X: " + std::to_wstring(O.x) + L" Y: " + std::to_wstring(O.y); + std::wstring Radius = std::to_wstring(radius); + + return std::wstring(L"PositionO: " + PosO + L"\n" + L"Radius: " + Radius); + + } + private: JC_Point2d O; double radius; + }; \ No newline at end of file diff --git a/Engine/JC_Line.h b/Engine/JC_Line.h index 232c78e5..cb0cf90d 100644 --- a/Engine/JC_Line.h +++ b/Engine/JC_Line.h @@ -33,7 +33,16 @@ class JC_Line : public JC_Shape return false; } + std::wstring MakeDescription() override + { + + std::wstring PosP = std::to_wstring(P.x) + L" " + std::to_wstring(P.y); + std::wstring PosQ = std::to_wstring(Q.x) + L" " + std::to_wstring(Q.y); + std::wstring Lenght = std::to_wstring(GetDistanceTo(P,Q)); + return std::wstring(L"PositionP: " + PosP + L"\n" + L" PositionQ: " + PosQ + L"\n" + L"Lenght: " + Lenght); + + } private: JC_Point2d P, Q; //Start and end points of the line diff --git a/Engine/JC_Math.h b/Engine/JC_Math.h index 9f1bbf29..47aa64b4 100644 --- a/Engine/JC_Math.h +++ b/Engine/JC_Math.h @@ -63,4 +63,17 @@ constexpr double PI_D = 3.1415926535897932; // First two points create line third we are exsamining JC_Point2d ClosesPoint (const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R); + template JC_Point2 TrasformPoint(JC_Point2 input) + { + //fixes disconection between screen and math coordinates + input.x += (T)(Camera_Pos.x); + input.y -= (T)(Camera_Pos.y); + + JC_Vector2 offset = { (T)(Graphics::ScreenWidth / 2), (T)(Graphics::ScreenHeight / 2) }; + input -= offset; + input.y *= -1; + return input; + } + + bool IsBetween2Points(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R); diff --git a/Engine/JC_Shape.h b/Engine/JC_Shape.h index e9e71fd2..72bc812a 100644 --- a/Engine/JC_Shape.h +++ b/Engine/JC_Shape.h @@ -1,7 +1,6 @@ #pragma once #include "JC_Vector2.h" #include "Camera.h" - class JC_Shape { @@ -10,6 +9,7 @@ class JC_Shape void virtual Draw(Camera cam_in) = 0; bool virtual IsInRange(const JC_Point2d& mouse_in) = 0; + std::wstring virtual MakeDescription() = 0; void UpdateColor() { @@ -30,7 +30,10 @@ class JC_Shape return selectedflag; } - + bool IsSelected() const + { + return selectedflag; + } protected: From 625a72478c06d7ebee221e362f947847b6e8d3c5 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Tue, 19 Mar 2019 12:47:11 +0100 Subject: [PATCH 78/84] Update of message layout --- Engine/Game.cpp | 5 ++++- Engine/JC_Circle.h | 4 ++-- Engine/JC_Line.h | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Engine/Game.cpp b/Engine/Game.cpp index a02afa14..793444b0 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -259,7 +259,10 @@ void Game::ProcesInput() for (auto& i : Shapes) { if (i.get()->IsSelected()) - wnd.ShowMessageBox(L"Description", i.get()->MakeDescription()); + { + wnd.ShowMessageBox(L"Description", L"Only single shape wil be show \n\n " + i.get()->MakeDescription()); + break; + } } } diff --git a/Engine/JC_Circle.h b/Engine/JC_Circle.h index 70cef8ee..2b6f9edc 100644 --- a/Engine/JC_Circle.h +++ b/Engine/JC_Circle.h @@ -27,10 +27,10 @@ class JC_Circle : public JC_Shape std::wstring MakeDescription() override { - std::wstring PosO = L" X: " + std::to_wstring(O.x) + L" Y: " + std::to_wstring(O.y); + std::wstring PosO = L"X: " + std::to_wstring(O.x) + L"\n Y: " + std::to_wstring(O.y); std::wstring Radius = std::to_wstring(radius); - return std::wstring(L"PositionO: " + PosO + L"\n" + L"Radius: " + Radius); + return std::wstring(L"Centre:\n " + PosO + L"\n\n" + L"Radius: " + Radius); } diff --git a/Engine/JC_Line.h b/Engine/JC_Line.h index cb0cf90d..f8947da5 100644 --- a/Engine/JC_Line.h +++ b/Engine/JC_Line.h @@ -40,7 +40,7 @@ class JC_Line : public JC_Shape std::wstring PosQ = std::to_wstring(Q.x) + L" " + std::to_wstring(Q.y); std::wstring Lenght = std::to_wstring(GetDistanceTo(P,Q)); - return std::wstring(L"PositionP: " + PosP + L"\n" + L" PositionQ: " + PosQ + L"\n" + L"Lenght: " + Lenght); + return std::wstring(L"Start:\n" + PosP + L"\n\n" + L" End \n " + PosQ + L"\n\n" + L"Lenght: " + Lenght); } From ff71a141d9314c86cd7ab42a0a5717db3fd51320 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Wed, 20 Mar 2019 21:22:06 +0100 Subject: [PATCH 79/84] New circle drawing algorithm --- Engine/Camera.h | 4 +-- Engine/Chili_Rectangle.h | 67 +++++++++++++++++++++++++++++++++++ Engine/CordinateTrasformerh.h | 4 +-- Engine/Game.cpp | 13 +++---- Engine/Graphics.cpp | 46 ++++++++++++++++++++++++ Engine/Graphics.h | 10 ++++-- Engine/JC_Circle.cpp | 2 +- Engine/JC_Circle.h | 4 ++- Engine/JC_Line.h | 1 - Engine/JC_Math.h | 4 +-- 10 files changed, 137 insertions(+), 18 deletions(-) create mode 100644 Engine/Chili_Rectangle.h diff --git a/Engine/Camera.h b/Engine/Camera.h index 0c190691..4ffa094b 100644 --- a/Engine/Camera.h +++ b/Engine/Camera.h @@ -46,10 +46,10 @@ class Camera ct.DrawLine(std::move(P_in), std::move(Q_in), std::move(Color_in)); } - void DrawCircle(JC_Point2d pos, double radius, Color Color_in) + void DrawCircle(JC_Point2d pos, double radius, int t, Color Color_in) { pos -= Camera_Pos; - ct.DrawCircle(std::move(pos), std::move(radius), std::move(Color_in)); + ct.DrawCircle(std::move(pos), std::move(radius), t, std::move(Color_in)); } // trasforms Point screen coordinates to mathematical coordinates regardles from cmaera position diff --git a/Engine/Chili_Rectangle.h b/Engine/Chili_Rectangle.h new file mode 100644 index 00000000..6f627c44 --- /dev/null +++ b/Engine/Chili_Rectangle.h @@ -0,0 +1,67 @@ +#pragma once + +#include "JC_Vector2.h" + +template +class CRectangle +{ +public: + CRectangle(T left_in, T right_in, T top_in, T bottom_in) + : + left(left_in), + right(right_in), + top(top_in), + bottom(bottom_in) + {} + CRectangle(const JC_Vector2& topLeft, const JC_Vector2& bottomRight) + : + CRectangle(topLeft.x, bottomRight.x, topLeft.y, bottomRight.y) + {} + CRectangle(const JC_Vector2& topLeft, T width, T height) + : + CRectangle(topLeft, topLeft + JC_Vector2(width, height)) + {} + bool IsOverlappingWith(const CRectangle& other) const + { + return right > other.left && left < other.right + && bottom > other.top && top < other.bottom; + } + bool IsContainedBy(const CRectangle& other) const + { + return left >= other.left && right <= other.right && + top >= other.top && bottom <= other.bottom; + } + bool Contains(const JC_Vector2& point) const + { + return point.x >= left && point.x < right && point.y >= top && point.y < bottom; + } + CRectangle FromCenter(const JC_Vector2& center, T halfWidth, T halfHeight) + { + const JC_Vector2 half(halfWidth, halfHeight); + return CRectangle(center - half, center + half); + } + CRectangle GetExpanded(T offset) const + { + return CRectangle(left - offset, right + offset, top - offset, bottom + offset); + } + JC_Vector2 GetCenter() const + { + return JC_Vector2((left + right) / (T)2, (top + bottom) / (T)2); + } + T GetWidth() const + { + return right - left; + } + T GetHeight() const + { + return bottom - top; + } +public: + T left; + T right; + T top; + T bottom; +}; + +typedef CRectangle RectI; +typedef CRectangle RectD; \ No newline at end of file diff --git a/Engine/CordinateTrasformerh.h b/Engine/CordinateTrasformerh.h index 4b0089bc..be98d492 100644 --- a/Engine/CordinateTrasformerh.h +++ b/Engine/CordinateTrasformerh.h @@ -30,14 +30,14 @@ class CoordinateTrasformer gfx.DrawLine(P_in, Q_in, Color_in); } - void DrawCircle(JC_Point2d pos, double radius, Color c) + void DrawCircle(JC_Point2d pos, double radius, int t, Color c) { JC_Vector2d offset = { double(Graphics::ScreenWidth / 2),double(Graphics::ScreenHeight / 2) }; pos.y *= -1.0; pos += offset; - gfx.DrawCircle(pos, radius, c); + gfx.DrawCircle(pos, radius, t, c); } private: diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 793444b0..804ae96a 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -89,7 +89,7 @@ void Game::ProcesInput() { Q = cam.TrasformPoint(wnd.mouse.GetPos()); - cam.DrawCircle(P, GetDistanceTo(P, Q), Colors::Red); + cam.DrawCircle(P, GetDistanceTo(P, Q), 2, Colors::Red); cam.DrawLine(P, Q, Colors::Red); } break; @@ -141,7 +141,7 @@ void Game::ProcesInput() { Q = cam.TrasformPoint(wnd.mouse.GetPos()); auto Temp = GetMidPoint(P, Q); - cam.DrawCircle(Temp, GetDistanceTo(Temp, Q), Colors::Red); + cam.DrawCircle(Temp, GetDistanceTo(Temp, Q), 2, Colors::Red); } if (second_point_engagement) { @@ -155,10 +155,10 @@ void Game::ProcesInput() else if (Q != R && !(LineSlopeBetween2Points(P, R) == LineSlopeBetween2Points(R, Q))) { auto Temp = CalculateCentre(P, Q, R); - cam.DrawCircle(Temp, GetDistanceTo(Temp, R), Colors::Red); - cam.DrawCircle(P, 10, Colors::Red); - cam.DrawCircle(Q, 10, Colors::Red); - cam.DrawCircle(R, 10, Colors::Red); + cam.DrawCircle(Temp, GetDistanceTo(Temp, R), 2, Colors::Red); + cam.DrawCircle(P, 10, 1, Colors::Red); + cam.DrawCircle(Q, 10, 1, Colors::Red); + cam.DrawCircle(R, 10, 1, Colors::Red); //cam.DrawLine(CalculateCentre(P, Q, R), R, Colors::Red); } @@ -282,6 +282,7 @@ void Game::ComposeFrame() { c.get()->Draw(cam); } + //cam.DrawClosedPolyline(Star::Make(200, 75.0,7), Colors::Red); } diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index db81df1f..ffee27a6 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -26,6 +26,8 @@ #include #include +#include "Chili_Rectangle.h" + // Ignore the intellisense error "cannot open source file" for .shh files. // They will be created during the build sequence before the preprocessor runs. @@ -372,6 +374,49 @@ void Graphics::DrawLine(double x1, double y1, double x2, double y2, Color c) } +void Graphics::DrawCircle(double _ox, double _oy, double _outer_radius, const CRectangle& _clip, int t,Color C) noexcept +{// For outline thickness of 1 + const auto rSq_inner = Square(_outer_radius - t); + const auto rSq_outer = Square(_outer_radius); + + const auto outer_double = _outer_radius * 2.0; + + // Calculate the bounding rectangle of the circle + const auto left = _ox - _outer_radius; + const auto top = _oy - _outer_radius; + const auto right = _ox + _outer_radius; + const auto bottom = _oy + _outer_radius; + + // Clip the bounding rectangle to screen boundaries and translate + // back to -radius ( left_clip, top_clip ), +radius ( right_clip, bottom_clip ) + const auto left_clip = std::max(0.0, -left) - _outer_radius; + const auto top_clip = std::max(0.0, -top) - _outer_radius; + const auto right_clip = std::min(ScreenWidth - right, outer_double) - _outer_radius; + const auto bottom_clip = std::min(ScreenHeight - bottom, outer_double) - _outer_radius; + + // Loop through clipped bounding rectangle, from top to bottom, + // left to right skipping any pixels contained in the _clip Rect passed + // as parameter to the function + for (double y = top_clip; y < bottom_clip; ++y) + { + for (double x = left_clip; x < right_clip; ++x) + { + const auto sqDist = Square(x) + Square(y); + if (sqDist > rSq_inner && sqDist < rSq_outer) + { + const auto px = x + _ox; + const auto py = y + _oy; + + if (!_clip.Contains(JC_Vector2{ px, py })) + { + PutPixel(int(std::round(px)), int(std::round(py)), C); + } + } + } + } +} + + void Graphics::DrawCircle(double Ox, double Oy, double R, Color& c) { //issue with continuity drawing for large circles @@ -389,6 +434,7 @@ void Graphics::DrawCircle(double Ox, double Oy, double R, Color& c) } */ + double x = 0.7071067811865475; double Rx = (x * R) + 0.5; diff --git a/Engine/Graphics.h b/Engine/Graphics.h index 6c87a254..1f1a5edc 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -29,7 +29,7 @@ #include "Colors.h" #include "JC_Vector2.h" #include "JC_Math.h" - +#include "Chili_Rectangle.h" class Graphics { @@ -80,14 +80,18 @@ class Graphics /***** Start Draw Circle Functions *****/ template - void DrawCircle(JC_Point2 vO, T2 R, Color c) + void DrawCircle(JC_Point2 vO, T2 R, int t , Color c) { - DrawCircle((double)vO.x, (double)vO.y, (double)R, c); + RectD Bound{ (double)ScreenWidth ,0,(double)ScreenHeight,0 }; + DrawCircle((double)vO.x, (double)vO.y, (double)R, Bound, t, c); } void DrawCircle(double Ox, double Oy, double R, Color& c); + + void DrawCircle(double _ox, double _oy, double _outer_radius, const CRectangle& _clip, int t, Color _color) noexcept; + /***** END Draw Circle Functions ****/ diff --git a/Engine/JC_Circle.cpp b/Engine/JC_Circle.cpp index 34815523..caf84fbe 100644 --- a/Engine/JC_Circle.cpp +++ b/Engine/JC_Circle.cpp @@ -22,7 +22,7 @@ JC_Circle::JC_Circle(const JC_Point2d& P_in, const JC_Point2d& Q_in, const JC_Po void JC_Circle::Draw(Camera cam_in) { - cam_in.DrawCircle(O, radius, Base_Color); + cam_in.DrawCircle(O, radius, 2, Base_Color); } diff --git a/Engine/JC_Circle.h b/Engine/JC_Circle.h index 2b6f9edc..5b24b49d 100644 --- a/Engine/JC_Circle.h +++ b/Engine/JC_Circle.h @@ -29,8 +29,10 @@ class JC_Circle : public JC_Shape std::wstring PosO = L"X: " + std::to_wstring(O.x) + L"\n Y: " + std::to_wstring(O.y); std::wstring Radius = std::to_wstring(radius); + std::wstring Diameter = std::to_wstring(radius*2 * PI_D); + std::wstring Area = std::to_wstring( radius * radius * PI_D); - return std::wstring(L"Centre:\n " + PosO + L"\n\n" + L"Radius: " + Radius); + return std::wstring(L"Centre:\n " + PosO + L"\n\nRadius: " + Radius + L"\n\nDiameter: " + Diameter + L"\n\nArea: " + Area); } diff --git a/Engine/JC_Line.h b/Engine/JC_Line.h index f8947da5..3729752b 100644 --- a/Engine/JC_Line.h +++ b/Engine/JC_Line.h @@ -32,7 +32,6 @@ class JC_Line : public JC_Shape else return false; } - std::wstring MakeDescription() override { diff --git a/Engine/JC_Math.h b/Engine/JC_Math.h index 47aa64b4..a20d5c3d 100644 --- a/Engine/JC_Math.h +++ b/Engine/JC_Math.h @@ -10,7 +10,7 @@ constexpr double PI_D = 3.1415926535897932; template - inline auto Sq(const T& x) + inline auto Square(const T& x) { return x * x; } @@ -52,7 +52,7 @@ constexpr double PI_D = 3.1415926535897932; // When we can Determine slope of both lines, then we proces points in seen order. // When we can't determine slope of any of lines (parallel to the window sides) // in this situation we are calculating centre using line mid point rule - // When we are unable to determine solope of one from the lines + // When we are unable to determine solope of one the lines // in this situation we are simply swaping order of the points. JC_Point2d CalculateCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R); From 248670ed8bfa206106b8e0eea513e1391416cfe0 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sun, 24 Mar 2019 00:21:52 +0100 Subject: [PATCH 80/84] Ability to draw bezier cuves --- Engine/Camera.h | 9 ++++- Engine/CordinateTrasformerh.h | 16 +++++++++ Engine/Engine.vcxproj | 3 ++ Engine/Engine.vcxproj.filters | 9 +++++ Engine/Game.cpp | 64 ++++++++++++++++++++++++++++++++-- Engine/Game.h | 1 + Engine/Graphics.cpp | 33 ++++++++++++++---- Engine/Graphics.h | 5 +-- Engine/JC_Bezier.h | 40 +++++++++++++++++++++ Engine/JC_Shape.h | 4 +-- Engine/MainWindow.cpp | 18 +++++++--- Engine/MainWindow.h | 1 + Engine/Resource.h | Bin 1198 -> 1274 bytes 13 files changed, 183 insertions(+), 20 deletions(-) create mode 100644 Engine/JC_Bezier.h diff --git a/Engine/Camera.h b/Engine/Camera.h index 4ffa094b..44dcbcfb 100644 --- a/Engine/Camera.h +++ b/Engine/Camera.h @@ -45,7 +45,14 @@ class Camera Q_in -= Camera_Pos; ct.DrawLine(std::move(P_in), std::move(Q_in), std::move(Color_in)); } - + + void DrawBezier(JC_Point2d P_in, JC_Point2d Q_in, JC_Point2d R_in, Color Color_in) + { + P_in -= Camera_Pos; + Q_in -= Camera_Pos; + R_in -= Camera_Pos; + ct.DrawBezier(std::move(P_in), std::move(Q_in), std::move(R_in) ,std::move(Color_in)); + } void DrawCircle(JC_Point2d pos, double radius, int t, Color Color_in) { pos -= Camera_Pos; diff --git a/Engine/CordinateTrasformerh.h b/Engine/CordinateTrasformerh.h index be98d492..bb56e337 100644 --- a/Engine/CordinateTrasformerh.h +++ b/Engine/CordinateTrasformerh.h @@ -30,6 +30,22 @@ class CoordinateTrasformer gfx.DrawLine(P_in, Q_in, Color_in); } + void DrawBezier(JC_Point2d P_in, JC_Point2d Q_in, JC_Point2d R_in, Color Color_in) + { + JC_Vector2d offset = { double(Graphics::ScreenWidth / 2),double(Graphics::ScreenHeight / 2) }; + + P_in.y *= -1; + Q_in.y *= -1; + R_in.y *= -1; + + P_in += offset; + Q_in += offset; + R_in += offset; + + gfx.DrawBezier(P_in, Q_in, R_in, Color_in); + } + + void DrawCircle(JC_Point2d pos, double radius, int t, Color c) { JC_Vector2d offset = { double(Graphics::ScreenWidth / 2),double(Graphics::ScreenHeight / 2) }; diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index dbea3b09..d89a1fdc 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -139,6 +139,8 @@ + + @@ -154,6 +156,7 @@ + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index 6a6a0e86..4942aa70 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -105,6 +105,15 @@ Resource Files + + Header Files\CameraPipeline + + + Header Files\MathLib + + + Header Files\Geometric shapes + diff --git a/Engine/Game.cpp b/Engine/Game.cpp index 804ae96a..c362522c 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -23,7 +23,6 @@ #include "Mouse.h" #include "CordinateTrasformerh.h" #include "ChiliUtil.h" - #include Game::Game(MainWindow& wnd) @@ -31,8 +30,10 @@ Game::Game(MainWindow& wnd) wnd(wnd), gfx(wnd), ct(gfx), - cam(ct)//, + cam(ct) + //, //camCtrl(wnd.mouse,cam) + { } @@ -206,6 +207,64 @@ void Game::ProcesInput() } break; } + + case MainWindow::MWShapeState::BezierCurve: + { + while (!wnd.mouse.IsEmpty()) + { + const auto e = wnd.mouse.Read(); + + if (e.GetType() == Mouse::Event::Type::LPress) + { + if (input == 0) + { + first_point_engagement = true; + P = cam.TrasformPoint(wnd.mouse.GetPos()); + } + + if (input == 1) + { + second_point_engagement = true; + R = cam.TrasformPoint(wnd.mouse.GetPos()); + } + + if (input == 2) + { + Q = cam.TrasformPoint(wnd.mouse.GetPos()); + Shapes.push_back(std::make_unique(P, Q, R)); + } + + input++; + + if (input >= 3) + { + input = 0; + second_point_engagement = false; + } + } + if (e.GetType() == Mouse::Event::Type::RPress) + { + input = 0; + first_point_engagement = false; + second_point_engagement = false; + } + } + //Draw bezier from two points when left mouse button is pressed for the first time + if (first_point_engagement) + { + R = cam.TrasformPoint(wnd.mouse.GetPos()); + cam.DrawLine(P,R, Colors::Red); + } + if (second_point_engagement) + { + first_point_engagement = false; + Q = cam.TrasformPoint(wnd.mouse.GetPos()); + + cam.DrawBezier(P,Q, R ,Colors::Red); + + } + break; + } case MainWindow::MWShapeState::Null: { while (!wnd.mouse.IsEmpty()) @@ -283,6 +342,5 @@ void Game::ComposeFrame() c.get()->Draw(cam); } - //cam.DrawClosedPolyline(Star::Make(200, 75.0,7), Colors::Red); } diff --git a/Engine/Game.h b/Engine/Game.h index fe03dc33..db784d33 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -33,6 +33,7 @@ #include "JC_Math.h" #include "JC_Circle.h" #include "JC_Line.h" +#include "JC_Bezier.h" #include "JC_Shape.h" #include "Star.h" diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index ffee27a6..773a360f 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -389,10 +389,11 @@ void Graphics::DrawCircle(double _ox, double _oy, double _outer_radius, const CR // Clip the bounding rectangle to screen boundaries and translate // back to -radius ( left_clip, top_clip ), +radius ( right_clip, bottom_clip ) + const auto left_clip = std::max(0.0, -left) - _outer_radius; const auto top_clip = std::max(0.0, -top) - _outer_radius; - const auto right_clip = std::min(ScreenWidth - right, outer_double) - _outer_radius; - const auto bottom_clip = std::min(ScreenHeight - bottom, outer_double) - _outer_radius; + const auto right_clip = std::min(ScreenWidth - left -1.0, outer_double) - _outer_radius; + const auto bottom_clip = std::min(ScreenHeight - top - 1.0, outer_double) - _outer_radius; // Loop through clipped bounding rectangle, from top to bottom, // left to right skipping any pixels contained in the _clip Rect passed @@ -416,12 +417,30 @@ void Graphics::DrawCircle(double _ox, double _oy, double _outer_radius, const CR } } +void Graphics::DrawBezier(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R, Color color) noexcept +{ + const auto range0 = (Q - P); + const auto range1 = (R - Q); + const auto range2 = (range1 - range0); + const auto doubleRange0 = (range0 * 2.0); + + constexpr auto step = .1; + auto prev = P; + for (double t = step; t <= 1.0; t += step) + { + const auto p3 = P + (doubleRange0 + (range2 * t)) * t; + + DrawLine(prev, p3, color); + prev = p3; + } +} +/* void Graphics::DrawCircle(double Ox, double Oy, double R, Color& c) { //issue with continuity drawing for large circles - /*for (double theta = 0; theta < 360; theta += 0.2) + for (double theta = 0; theta < 360; theta += 0.2) { double x = (double)(R * std::cos(PI_D*theta / 180)); double y = (double)(R * std::sin(PI_D*theta / 180)); @@ -432,7 +451,7 @@ void Graphics::DrawCircle(double Ox, double Oy, double R, Color& c) if (xi >= 0 && xi < ScreenWidth && yi >= 0 && yi < ScreenHeight) PutPixel(xi, yi, c); } - */ + double x = 0.7071067811865475; @@ -475,11 +494,11 @@ void Graphics::DrawCircle(double Ox, double Oy, double R, Color& c) } +*/ - - +/* void Graphics::DrawArc(double Ox, double Oy, double R , double theta_begin, double theta_end, Color c) { @@ -505,7 +524,7 @@ void Graphics::DrawArc(double Ox, double Oy, double R , double theta_begin, doub } } } - +*/ diff --git a/Engine/Graphics.h b/Engine/Graphics.h index 1f1a5edc..d26117e1 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -87,8 +87,9 @@ class Graphics } - void DrawCircle(double Ox, double Oy, double R, Color& c); + //void DrawCircle(double Ox, double Oy, double R, Color& c); + void DrawBezier(const JC_Point2d & p0, const JC_Point2d & p1, const JC_Point2d & p2, Color color) noexcept; void DrawCircle(double _ox, double _oy, double _outer_radius, const CRectangle& _clip, int t, Color _color) noexcept; @@ -97,7 +98,7 @@ class Graphics /***** Start Draw Arc Functions *****/ - void DrawArc(double Ox, double Oy, double R, double theta_begin, double theta_end, Color c); + //void DrawArc(double Ox, double Oy, double R, double theta_begin, double theta_end, Color c); /***** End Draw Arc Functions *****/ diff --git a/Engine/JC_Bezier.h b/Engine/JC_Bezier.h new file mode 100644 index 00000000..a066198d --- /dev/null +++ b/Engine/JC_Bezier.h @@ -0,0 +1,40 @@ +#pragma once + +#include "JC_Shape.h" +#include "Camera.h" + +class JC_Bezier : public JC_Shape +{ +public: + JC_Bezier(JC_Point2d P, JC_Point2d Q, JC_Point2d R,Color color_in = Colors::White) + : + P(P), + Q(Q), + R(R), + JC_Shape(color_in) + {} + + void Draw(Camera cam) override + { + cam.DrawBezier(P, Q, R, Base_Color); + } + bool IsInRange(const JC_Point2d& M) override + { + return false; + } + + std::wstring MakeDescription() override + { + + std::wstring PosP = L"X: " + std::to_wstring(P.x) + L"\n Y: " + std::to_wstring(P.y); + std::wstring PosQ = L"X: " + std::to_wstring(Q.x) + L"\n Y: " + std::to_wstring(Q.y); + std::wstring PosR = L"X: " + std::to_wstring(R.x) + L"\n Y: " + std::to_wstring(R.y); + + return std::wstring(L"First point:\n " + PosP + L"Second point:\n " + PosQ + L"Third point:\n " + PosR); + + } + +private: + JC_Point2d P, Q, R; + +}; \ No newline at end of file diff --git a/Engine/JC_Shape.h b/Engine/JC_Shape.h index 72bc812a..ecd4dbac 100644 --- a/Engine/JC_Shape.h +++ b/Engine/JC_Shape.h @@ -7,8 +7,8 @@ class JC_Shape public: - void virtual Draw(Camera cam_in) = 0; - bool virtual IsInRange(const JC_Point2d& mouse_in) = 0; + void virtual Draw(Camera cam) = 0; + bool virtual IsInRange(const JC_Point2d& M) = 0; std::wstring virtual MakeDescription() = 0; void UpdateColor() diff --git a/Engine/MainWindow.cpp b/Engine/MainWindow.cpp index b9c248f6..106d1b30 100644 --- a/Engine/MainWindow.cpp +++ b/Engine/MainWindow.cpp @@ -155,6 +155,8 @@ LRESULT MainWindow::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) AppendMenu(hSubMenu, MF_STRING, ID_SHAPES_ThreePointCircle, L"&Circle from 3 points"); AppendMenu(hSubMenu, MF_SEPARATOR, NULL, NULL); AppendMenu(hSubMenu, MF_STRING, ID_SHAPES_LineSegment, L"&Line Segment"); + AppendMenu(hSubMenu, MF_SEPARATOR, NULL, NULL); + AppendMenu(hSubMenu, MF_STRING, ID_SHAPES_BezierCurve, L"&3Point Bezier Curve"); } @@ -168,11 +170,12 @@ LRESULT MainWindow::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) switch (LOWORD(wParam)) { case ID_FILE_EXIT: + PostMessage(hWnd, WM_CLOSE, 0, 0); break; case ID_SHAPES_TwoPointCircle: - ShapeState = MWShapeState::TwoPointCircle ; - ShowMessageBox(L"Info",L"Create circle form 2 points"); + ShapeState = MWShapeState::TwoPointCircle; + ShowMessageBox(L"Info", L"Create circle form 2 points"); break; @@ -181,17 +184,22 @@ LRESULT MainWindow::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) ShowMessageBox(L"Info", L"Create circle form 3 points"); break; - + case ID_SHAPES_LineSegment: ShapeState = MWShapeState::LineSegment; ShowMessageBox(L"Info", L"Create line Segment"); break; - } - break; + case ID_SHAPES_BezierCurve: + ShapeState = MWShapeState::BezierCurve; + ShowMessageBox(L"Info", L"Create 3 point Bezier Curve"); + break; + + } + break; } case WM_DESTROY: PostQuitMessage(0); diff --git a/Engine/MainWindow.h b/Engine/MainWindow.h index b7133cab..9bc2b0fd 100644 --- a/Engine/MainWindow.h +++ b/Engine/MainWindow.h @@ -56,6 +56,7 @@ class MainWindow : public HWNDKey TwoPointCircle, ThreePointCircle, LineSegment, + BezierCurve, Count }; MWShapeState ShapeState = MWShapeState::Null; diff --git a/Engine/Resource.h b/Engine/Resource.h index 51276bc1e7f77fb315fd3ff4242955ba6a7296cb..9d8f47cce215b4c3cc6c69e98071dcd83fb07909 100644 GIT binary patch delta 60 zcmZ3-`HOSIDwfG1OahY?SVVN37*ZLk7&3um5rZ>BDUd7!vK1IC84Q5Xgn^fV3yuM~ CBMPAa delta 12 TcmeyxxsG$gDi#)A1}+8w9o_>p From 176b0df5995288d32d1dbdd8fcdd5d1920d6c7bd Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Tue, 26 Mar 2019 17:19:29 +0100 Subject: [PATCH 81/84] Project cleanup --- Engine/Engine.vcxproj | 1 + Engine/Engine.vcxproj.filters | 30 ++++++++++++++++++------------ Engine/Graphics.cpp | 6 +++--- Engine/JC_Shape.h | 2 +- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index d89a1fdc..a737eb6e 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -140,6 +140,7 @@ + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index 4942aa70..09cf41f4 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -34,11 +34,11 @@ {85608aef-b314-4019-9eef-58cd5dee7256} + + {b309b936-8445-487c-909c-da4141e3b864} + - - Header Files - Header Files @@ -60,9 +60,6 @@ Header Files - - Header Files - Header Files @@ -75,9 +72,6 @@ Header Files\Geometric shapes - - Header Files - Header Files\CameraPipeline @@ -108,12 +102,24 @@ Header Files\CameraPipeline - - Header Files\MathLib - Header Files\Geometric shapes + + Header Files\Geometric shapes + + + Header Files\Chili util + + + Header Files\Chili util + + + Header Files\Chili util + + + Header Files\Chili util + diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index 773a360f..fd513322 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -428,10 +428,10 @@ void Graphics::DrawBezier(const JC_Point2d & P, const JC_Point2d & Q, const JC_P auto prev = P; for (double t = step; t <= 1.0; t += step) { - const auto p3 = P + (doubleRange0 + (range2 * t)) * t; + const auto S = P + (doubleRange0 + (range2 * t)) * t; - DrawLine(prev, p3, color); - prev = p3; + DrawLine(prev, S, color); + prev = S; } } diff --git a/Engine/JC_Shape.h b/Engine/JC_Shape.h index ecd4dbac..a8a531c8 100644 --- a/Engine/JC_Shape.h +++ b/Engine/JC_Shape.h @@ -43,7 +43,7 @@ class JC_Shape {} Color Base_Color; - static constexpr double halfwidth = 10.0; + static constexpr double halfwidth = 20.0; private: bool selectedflag = false; From a0e726942bbbab4d84396fb061d3d91e2a65e726 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Sat, 30 Mar 2019 18:13:20 +0100 Subject: [PATCH 82/84] Added polio line drawing routine and prepared JC_MP_bbezier for implementation --- Engine/{JC_Bezier.h => ALIB_Bezier.h} | 4 +- Engine/Camera.h | 19 +++++++++ Engine/CordinateTrasformerh.h | 29 +++++++++++++ Engine/Engine.vcxproj | 6 +-- Engine/Engine.vcxproj.filters | 22 +++++----- Engine/Game.cpp | 58 +++++++++++++++++++++++++- Engine/Game.h | 24 ++++++++--- Engine/Graphics.cpp | 44 +++++++++++++++++++ Engine/Graphics.h | 15 +++++-- Engine/JC_Circle.cpp | 2 - Engine/JC_Circle.h | 4 -- Engine/JC_MP_Bezier.h | 40 ++++++++++++++++++ Engine/JC_Math.cpp | 19 ++++++++- Engine/JC_Math.h | 22 +++++----- Engine/JC_Poli.h | 48 +++++++++++++++++++++ Engine/MainWindow.cpp | 11 ++++- Engine/MainWindow.h | 1 + Engine/Resource.h | Bin 1274 -> 1358 bytes 18 files changed, 322 insertions(+), 46 deletions(-) rename Engine/{JC_Bezier.h => ALIB_Bezier.h} (85%) create mode 100644 Engine/JC_MP_Bezier.h create mode 100644 Engine/JC_Poli.h diff --git a/Engine/JC_Bezier.h b/Engine/ALIB_Bezier.h similarity index 85% rename from Engine/JC_Bezier.h rename to Engine/ALIB_Bezier.h index a066198d..4b0ddecf 100644 --- a/Engine/JC_Bezier.h +++ b/Engine/ALIB_Bezier.h @@ -3,10 +3,10 @@ #include "JC_Shape.h" #include "Camera.h" -class JC_Bezier : public JC_Shape +class ALIB_Bezier : public JC_Shape { public: - JC_Bezier(JC_Point2d P, JC_Point2d Q, JC_Point2d R,Color color_in = Colors::White) + ALIB_Bezier(JC_Point2d P, JC_Point2d Q, JC_Point2d R,Color color_in = Colors::White) : P(P), Q(Q), diff --git a/Engine/Camera.h b/Engine/Camera.h index 44dcbcfb..e132c1ce 100644 --- a/Engine/Camera.h +++ b/Engine/Camera.h @@ -45,7 +45,15 @@ class Camera Q_in -= Camera_Pos; ct.DrawLine(std::move(P_in), std::move(Q_in), std::move(Color_in)); } + void DrawPoliLine(std::vector point_data, Color Color_in) + { + for (auto &P : point_data) + { + P -= Camera_Pos; + } + ct.DrawPoliLine(std::move(point_data), std::move(Color_in)); + } void DrawBezier(JC_Point2d P_in, JC_Point2d Q_in, JC_Point2d R_in, Color Color_in) { P_in -= Camera_Pos; @@ -53,6 +61,17 @@ class Camera R_in -= Camera_Pos; ct.DrawBezier(std::move(P_in), std::move(Q_in), std::move(R_in) ,std::move(Color_in)); } + + void DrawMPBezier(std::vector point_data, Color Color_in) + { + for (auto &P : point_data) + { + P -= Camera_Pos; + } + + ct.DrawMPBezier(std::move(point_data), std::move(Color_in)); + } + void DrawCircle(JC_Point2d pos, double radius, int t, Color Color_in) { pos -= Camera_Pos; diff --git a/Engine/CordinateTrasformerh.h b/Engine/CordinateTrasformerh.h index bb56e337..1d8b8cf4 100644 --- a/Engine/CordinateTrasformerh.h +++ b/Engine/CordinateTrasformerh.h @@ -30,6 +30,21 @@ class CoordinateTrasformer gfx.DrawLine(P_in, Q_in, Color_in); } + + void DrawPoliLine(std::vector point_data, Color Color_in) + { + JC_Vector2d offset = { double(Graphics::ScreenWidth / 2),double(Graphics::ScreenHeight / 2) }; + + for (auto &P : point_data) + { + P.y *= -1; + P += offset; + } + + gfx.DrawPoliLine(point_data, Color_in); + } + + void DrawBezier(JC_Point2d P_in, JC_Point2d Q_in, JC_Point2d R_in, Color Color_in) { JC_Vector2d offset = { double(Graphics::ScreenWidth / 2),double(Graphics::ScreenHeight / 2) }; @@ -46,6 +61,20 @@ class CoordinateTrasformer } + void DrawMPBezier(std::vector point_data, Color Color_in) + { + JC_Vector2d offset = { double(Graphics::ScreenWidth / 2),double(Graphics::ScreenHeight / 2) }; + + for (auto &P : point_data) + { + P.y *= -1; + P += offset; + } + + gfx.DrawBezier(point_data, Color_in); + } + + void DrawCircle(JC_Point2d pos, double radius, int t, Color c) { JC_Vector2d offset = { double(Graphics::ScreenWidth / 2),double(Graphics::ScreenHeight / 2) }; diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index a737eb6e..7a66d6cc 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -139,9 +139,7 @@ - - - + @@ -158,6 +156,7 @@ + @@ -171,6 +170,7 @@ + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index 09cf41f4..fa22fa01 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -25,9 +25,6 @@ {991129b5-249e-4da4-bad5-8426e98a3a3c} - - {b9b4aa28-3d6d-4412-b8b4-6ff6c3af9881} - {ab08727f-c0bc-4aac-a38c-7a209aa66dcb} @@ -37,6 +34,9 @@ {b309b936-8445-487c-909c-da4141e3b864} + + {b9b4aa28-3d6d-4412-b8b4-6ff6c3af9881} + @@ -99,15 +99,15 @@ Resource Files - - Header Files\CameraPipeline - - + Header Files\Geometric shapes - + Header Files\Geometric shapes + + Header Files\Chili util + Header Files\Chili util @@ -117,9 +117,6 @@ Header Files\Chili util - - Header Files\Chili util - @@ -155,6 +152,9 @@ Source Files\MathLib + + Header Files\Geometric shapes + diff --git a/Engine/Game.cpp b/Engine/Game.cpp index c362522c..c4ef5bde 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -207,7 +207,63 @@ void Game::ProcesInput() } break; } + case MainWindow::MWShapeState::PoliLine: + { + while (!wnd.mouse.IsEmpty()) + { + const auto e = wnd.mouse.Read(); + + if (e.GetType() == Mouse::Event::Type::LPress) + { + if(input==0) + first_point_engagement = true; + if (input>0) + { + first_point_engagement = false; + second_point_engagement = true; + } + + P = cam.TrasformPoint(wnd.mouse.GetPos()); + point_data.push_back(P); + input++; + + + } + if (second_point_engagement) + { + if (e.GetType() == Mouse::Event::Type::RPress) + { + + if (point_data.size() > 1) + { + Shapes.push_back(std::make_unique(point_data)); + input = 0; + first_point_engagement = false; + second_point_engagement = false; + point_data.clear(); + } + + } + + } + + } + if (first_point_engagement) + { + Q = cam.TrasformPoint(wnd.mouse.GetPos()); + cam.DrawLine(P, Q, Colors::Red); + } + if (second_point_engagement) + { + cam.DrawPoliLine(point_data, Colors::Red); + Q = cam.TrasformPoint(wnd.mouse.GetPos()); + cam.DrawLine(P, Q, Colors::Red); + + } + break; + + } case MainWindow::MWShapeState::BezierCurve: { while (!wnd.mouse.IsEmpty()) @@ -231,7 +287,7 @@ void Game::ProcesInput() if (input == 2) { Q = cam.TrasformPoint(wnd.mouse.GetPos()); - Shapes.push_back(std::make_unique(P, Q, R)); + Shapes.push_back(std::make_unique(P, Q, R)); } input++; diff --git a/Engine/Game.h b/Engine/Game.h index db784d33..226afe75 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -29,13 +29,13 @@ #include "Camera.h" #include "MouseCameraControler.h" +#include "JC_Shape.h" #include "JC_Vector2.h" #include "JC_Math.h" #include "JC_Circle.h" #include "JC_Line.h" -#include "JC_Bezier.h" -#include "JC_Shape.h" -#include "Star.h" +#include "JC_Poli.h" +#include "ALIB_Bezier.h" class Game @@ -71,10 +71,22 @@ class Game bool first_point_engagement = false; bool second_point_engagement = false; - + JC_Point2d P, Q, R; - + std::vector point_data; /********************************/ -}; \ No newline at end of file +}; + + +//enum class GameCreationState + //{ + // Null, + // FirstPoint, + // SecondPoint, + // ThirdPoint, + // NextPoint, + // Count + //}; + //GameCreationState CreoState = GameCreationState::Null; \ No newline at end of file diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index fd513322..31b374ca 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -373,6 +373,28 @@ void Graphics::DrawLine(double x1, double y1, double x2, double y2, Color c) } } +void Graphics::DrawPoliLine(std::vector point_data, Color Color_in) +{ + JC_Point2d Current; + JC_Point2d Previous; + + + if (point_data.size() > 1) + { + for (int i = 1; i < point_data.size(); i++) + { + Current = point_data[i]; + Previous = point_data[i - 1]; + DrawLine(Previous, Current, Color_in); + } + } + else + { + + } + +} + void Graphics::DrawCircle(double _ox, double _oy, double _outer_radius, const CRectangle& _clip, int t,Color C) noexcept {// For outline thickness of 1 @@ -417,6 +439,7 @@ void Graphics::DrawCircle(double _ox, double _oy, double _outer_radius, const CR } } + void Graphics::DrawBezier(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R, Color color) noexcept { const auto range0 = (Q - P); @@ -424,6 +447,25 @@ void Graphics::DrawBezier(const JC_Point2d & P, const JC_Point2d & Q, const JC_P const auto range2 = (range1 - range0); const auto doubleRange0 = (range0 * 2.0); + constexpr auto step = .01; + auto prev = P; + for (double t = step; t <= 1.0; t += step) + { + const auto S = P + (doubleRange0 + (range2 * t)) * t; + + DrawLine(prev, S, color); + prev = S; + } +} + + +void Graphics::DrawBezier(std::vector point_data, Color color) noexcept +{ +/* const auto range0 = (Q - P); + const auto range1 = (R - Q); + const auto range2 = (range1 - range0); + const auto doubleRange0 = (range0 * 2.0); + constexpr auto step = .1; auto prev = P; for (double t = step; t <= 1.0; t += step) @@ -433,8 +475,10 @@ void Graphics::DrawBezier(const JC_Point2d & P, const JC_Point2d & Q, const JC_P DrawLine(prev, S, color); prev = S; } +*/ } + /* void Graphics::DrawCircle(double Ox, double Oy, double R, Color& c) { diff --git a/Engine/Graphics.h b/Engine/Graphics.h index d26117e1..afb1e8d9 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -74,9 +74,12 @@ class Graphics } void DrawLine(double x1, double y1, double x2, double y2, Color c); + void DrawPoliLine(std::vector point_data, Color Color_in); + /***** END Draw Line Functions ****/ + /***** Start Draw Circle Functions *****/ template @@ -85,17 +88,21 @@ class Graphics RectD Bound{ (double)ScreenWidth ,0,(double)ScreenHeight,0 }; DrawCircle((double)vO.x, (double)vO.y, (double)R, Bound, t, c); } - + void DrawCircle(double _ox, double _oy, double _outer_radius, const CRectangle& _clip, int t, Color _color) noexcept; //void DrawCircle(double Ox, double Oy, double R, Color& c); - void DrawBezier(const JC_Point2d & p0, const JC_Point2d & p1, const JC_Point2d & p2, Color color) noexcept; + /***** END Draw Circle Functions ****/ + - void DrawCircle(double _ox, double _oy, double _outer_radius, const CRectangle& _clip, int t, Color _color) noexcept; - /***** END Draw Circle Functions ****/ + void DrawBezier(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R, Color color) noexcept; + void DrawBezier(const std::vector point_data, Color color) noexcept; + + + /***** Start Draw Arc Functions *****/ //void DrawArc(double Ox, double Oy, double R, double theta_begin, double theta_end, Color c); diff --git a/Engine/JC_Circle.cpp b/Engine/JC_Circle.cpp index caf84fbe..8a64b25c 100644 --- a/Engine/JC_Circle.cpp +++ b/Engine/JC_Circle.cpp @@ -1,6 +1,4 @@ #include "JC_Circle.h" -#include "JC_Math.h" -#include JC_Circle::JC_Circle(const JC_Point2d& P_in, const JC_Point2d& Q_in, Color color_in) : diff --git a/Engine/JC_Circle.h b/Engine/JC_Circle.h index 5b24b49d..f83727d9 100644 --- a/Engine/JC_Circle.h +++ b/Engine/JC_Circle.h @@ -2,13 +2,9 @@ #include "JC_Shape.h" -#include "JC_Math.h" -#include "JC_Vector2.h" -#include "Graphics.h" -#include "Camera.h" class JC_Circle : public JC_Shape diff --git a/Engine/JC_MP_Bezier.h b/Engine/JC_MP_Bezier.h new file mode 100644 index 00000000..f953c43a --- /dev/null +++ b/Engine/JC_MP_Bezier.h @@ -0,0 +1,40 @@ +#pragma once + +#include "JC_Shape.h" + + + + +// Atempt to write multi point bezier curve + + + +class JC_MP_Bezier : public JC_Shape +{ +public: + JC_MP_Bezier(std::vector &line, Color color_in = Colors::White) + : + point_data(line), + JC_Shape(color_in) + {} + + void Draw(Camera cam) override + { + cam.DrawMPBezier(point_data, Base_Color); + } + bool IsInRange(const JC_Point2d& M) override + { + return false; + } + + std::wstring MakeDescription() override + { + + + return std::wstring(L"Not yet operatable"); + + } + +private: + std::vector point_data; +}; \ No newline at end of file diff --git a/Engine/JC_Math.cpp b/Engine/JC_Math.cpp index d57fef55..8e3c04c6 100644 --- a/Engine/JC_Math.cpp +++ b/Engine/JC_Math.cpp @@ -1,5 +1,23 @@ #include "JC_Math.h" + +int CalcFactorial(int n) +{ + if (n > 1) + return n * CalcFactorial(n - 1); + else + return 1; +} + +int Binomial_Make(int N, int K) +{ + int f_N = CalcFactorial(N); + int f_K = CalcFactorial(K); + int f_NK = CalcFactorial(N - K); + + return (f_N / (f_K * f_NK)); +} + JC_Point2d CalculateCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) { //when we have 2 flat lines in order under right angle @@ -83,7 +101,6 @@ JC_Point2d ClosesPoint(const JC_Point2d & P, const JC_Point2d & Q, const JC_Poin double c = LineSlopeBetween2Points(P, Q); - //assert(c == 0); double a = InverceLineSlope(c); diff --git a/Engine/JC_Math.h b/Engine/JC_Math.h index a20d5c3d..2dc376b5 100644 --- a/Engine/JC_Math.h +++ b/Engine/JC_Math.h @@ -46,7 +46,12 @@ constexpr double PI_D = 3.1415926535897932; return -1 / m; } + + int CalcFactorial(int n); + int Binomial_Make(int N, int K); + + // We have couple of types of centre calculation: // When we can Determine slope of both lines, then we proces points in seen order. @@ -63,17 +68,12 @@ constexpr double PI_D = 3.1415926535897932; // First two points create line third we are exsamining JC_Point2d ClosesPoint (const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R); - template JC_Point2 TrasformPoint(JC_Point2 input) - { - //fixes disconection between screen and math coordinates - input.x += (T)(Camera_Pos.x); - input.y -= (T)(Camera_Pos.y); - - JC_Vector2 offset = { (T)(Graphics::ScreenWidth / 2), (T)(Graphics::ScreenHeight / 2) }; - input -= offset; - input.y *= -1; - return input; - } + bool IsBetween2Points(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R); + + + + + diff --git a/Engine/JC_Poli.h b/Engine/JC_Poli.h new file mode 100644 index 00000000..5aada5b6 --- /dev/null +++ b/Engine/JC_Poli.h @@ -0,0 +1,48 @@ +#pragma once + +#include "JC_Shape.h" + +class JC_Poliline : public JC_Shape +{ +public: + JC_Poliline(std::vector point_data, Color color_in = Colors::White) + : + PointData(point_data), + JC_Shape(color_in) + {} + + void Draw(Camera cam) override + { + cam.DrawPoliLine(PointData, Base_Color); + } + + bool IsInRange(const JC_Point2d& M) override + { + JC_Point2d Current; + JC_Point2d Previous; + JC_Point2d C; + for (int i = 1 ; i < PointData.size(); i++) + { + Current = PointData[i]; + Previous = PointData[i - 1]; + C = ClosesPoint(Previous, Current, M); + + if (IsBetween2Points(Previous, Current, C)) + { + if ((abs(GetDistanceTo(M, C)) < halfwidth)) + { + return true; + } + return false; + } + } + return false; + } + std::wstring MakeDescription() override + { + return std::wstring(L"Not yet operatable"); + } + +private: + std::vector PointData; +}; \ No newline at end of file diff --git a/Engine/MainWindow.cpp b/Engine/MainWindow.cpp index 106d1b30..975caf25 100644 --- a/Engine/MainWindow.cpp +++ b/Engine/MainWindow.cpp @@ -156,7 +156,10 @@ LRESULT MainWindow::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) AppendMenu(hSubMenu, MF_SEPARATOR, NULL, NULL); AppendMenu(hSubMenu, MF_STRING, ID_SHAPES_LineSegment, L"&Line Segment"); AppendMenu(hSubMenu, MF_SEPARATOR, NULL, NULL); - AppendMenu(hSubMenu, MF_STRING, ID_SHAPES_BezierCurve, L"&3Point Bezier Curve"); + AppendMenu(hSubMenu, MF_STRING, ID_SHAPES_PoliLine, L"&PoliLine"); + AppendMenu(hSubMenu, MF_SEPARATOR, NULL, NULL); + AppendMenu(hSubMenu, MF_STRING, ID_SHAPES_BezierCurve, L"&Bezier Curve"); + } @@ -192,6 +195,12 @@ LRESULT MainWindow::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) break; + case ID_SHAPES_PoliLine: + ShapeState = MWShapeState::PoliLine; + ShowMessageBox(L"Info", L" Create PoliLine"); + + break; + case ID_SHAPES_BezierCurve: ShapeState = MWShapeState::BezierCurve; ShowMessageBox(L"Info", L"Create 3 point Bezier Curve"); diff --git a/Engine/MainWindow.h b/Engine/MainWindow.h index 9bc2b0fd..026b0178 100644 --- a/Engine/MainWindow.h +++ b/Engine/MainWindow.h @@ -56,6 +56,7 @@ class MainWindow : public HWNDKey TwoPointCircle, ThreePointCircle, LineSegment, + PoliLine, BezierCurve, Count }; diff --git a/Engine/Resource.h b/Engine/Resource.h index 9d8f47cce215b4c3cc6c69e98071dcd83fb07909..87fafa5e7ed99517bd1790b53c6ac2caf487ccb3 100644 GIT binary patch delta 154 zcmeyxd5&wt7G{1<1_-odFaW{H{!F5i6 Date: Mon, 1 Apr 2019 02:13:51 +0200 Subject: [PATCH 83/84] Fixsed poli line selection error --- Engine/JC_Line.h | 2 +- Engine/JC_Math.cpp | 23 +++++++++++------------ Engine/JC_Math.h | 4 ++-- Engine/JC_Poli.h | 3 +-- Engine/JC_Vector2.h | 2 ++ 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Engine/JC_Line.h b/Engine/JC_Line.h index 3729752b..7e31f15b 100644 --- a/Engine/JC_Line.h +++ b/Engine/JC_Line.h @@ -19,7 +19,7 @@ class JC_Line : public JC_Shape } bool IsInRange(const JC_Point2d& M) override { - JC_Point2d C = ClosesPoint(P, Q, M); + JC_Point2d C = ClosestPoint(P, Q, M); if (IsBetween2Points(P, Q, C)) { diff --git a/Engine/JC_Math.cpp b/Engine/JC_Math.cpp index 8e3c04c6..1118fba5 100644 --- a/Engine/JC_Math.cpp +++ b/Engine/JC_Math.cpp @@ -95,27 +95,26 @@ JC_Point2d CalculateSpecificCentre(const JC_Point2d & P, const JC_Point2d & Q, c } -JC_Point2d ClosesPoint(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) +JC_Point2d ClosestPoint(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) { - - - double c = LineSlopeBetween2Points(P, Q); + const double a = P.y - Q.y; + const double b = Q.x - P.x; + const double c = P.x * Q.y - Q.x * P.y; + JC_Point2d C; - double a = InverceLineSlope(c); - - double b = R.y - (a * R.x); - double d = Q.y - (c * Q.x); + C.x = (b * (b * R.x - (a * R.y)) - (a * c)) / (Square(a) + Square(b)); + C.y = (a * ((-b * R.x )+ ( a * R.y)) - (b * c)) / (Square(a) + Square(b)); - double x = ((a*R.x) + b - d) / c; - double y = (a * x) + b; - return JC_Point2d(x, y); + return C; } + + bool IsBetween2Points(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R) { - JC_Point2d C = ClosesPoint(P, Q, R); + JC_Point2d C = ClosestPoint(P, Q, R); if ((GetDistanceTo(P, C) < GetDistanceTo(P, Q)) && (GetDistanceTo(Q, C) < GetDistanceTo(P, Q))) return true; diff --git a/Engine/JC_Math.h b/Engine/JC_Math.h index 2dc376b5..b9f9e245 100644 --- a/Engine/JC_Math.h +++ b/Engine/JC_Math.h @@ -2,7 +2,7 @@ #include "JC_Vector2.h" #include - +#include constexpr double PI_F = 3.1415926536; constexpr double PI_D = 3.1415926535897932; @@ -66,7 +66,7 @@ constexpr double PI_D = 3.1415926535897932; JC_Point2d CalculateSpecificCentre(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R); // First two points create line third we are exsamining - JC_Point2d ClosesPoint (const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R); + JC_Point2d ClosestPoint(const JC_Point2d & P, const JC_Point2d & Q, const JC_Point2d & R); diff --git a/Engine/JC_Poli.h b/Engine/JC_Poli.h index 5aada5b6..9cc8be6a 100644 --- a/Engine/JC_Poli.h +++ b/Engine/JC_Poli.h @@ -25,7 +25,7 @@ class JC_Poliline : public JC_Shape { Current = PointData[i]; Previous = PointData[i - 1]; - C = ClosesPoint(Previous, Current, M); + C = ClosestPoint(Previous, Current, M); if (IsBetween2Points(Previous, Current, C)) { @@ -33,7 +33,6 @@ class JC_Poliline : public JC_Shape { return true; } - return false; } } return false; diff --git a/Engine/JC_Vector2.h b/Engine/JC_Vector2.h index 56dc19af..99b12cde 100644 --- a/Engine/JC_Vector2.h +++ b/Engine/JC_Vector2.h @@ -226,6 +226,8 @@ template JC_Vector2 normalize(const JC_Vector2& v) + + template T GetDistanceToSq(const JC_Point2& v0, const JC_Point2& v1) { return ((v1.x - v0.x)*(v1.x - v0.x)+ (v1.y - v0.y)*(v1.y - v0.y)); From c7bb8342a735db8299c9c9cf539bed76c6bca9a6 Mon Sep 17 00:00:00 2001 From: Ka Mil Date: Mon, 1 Apr 2019 02:14:06 +0200 Subject: [PATCH 84/84] Prepared frame work foer text writting --- .../{Chili_Rectangle.h => ChiliRectangle.h} | 0 Engine/ChiliUtil.h | 43 +++++ Engine/ChiliWin.h | 10 +- Engine/Colors.h | 64 ++++--- Engine/Engine.vcxproj | 15 +- Engine/Engine.vcxproj.filters | 30 ++- Engine/Font.cpp | 61 ++++++ Engine/Font.h | 27 +++ Engine/GDIPlusManager.cpp | 42 +++++ Engine/GDIPlusManager.h | 36 ++++ Engine/Graphics.cpp | 18 +- Engine/Graphics.h | 100 +++++++++- Engine/SoundEffect.h | 62 +++++-- Engine/SpriteEffect.h | 141 ++++++++++++++ Engine/Surface.cpp | 175 ++++++++++++++++++ Engine/Surface.h | 29 +++ 16 files changed, 801 insertions(+), 52 deletions(-) rename Engine/{Chili_Rectangle.h => ChiliRectangle.h} (100%) create mode 100644 Engine/Font.cpp create mode 100644 Engine/Font.h create mode 100644 Engine/GDIPlusManager.cpp create mode 100644 Engine/GDIPlusManager.h create mode 100644 Engine/SpriteEffect.h create mode 100644 Engine/Surface.cpp create mode 100644 Engine/Surface.h diff --git a/Engine/Chili_Rectangle.h b/Engine/ChiliRectangle.h similarity index 100% rename from Engine/Chili_Rectangle.h rename to Engine/ChiliRectangle.h diff --git a/Engine/ChiliUtil.h b/Engine/ChiliUtil.h index 4bfeff77..a4569b92 100644 --- a/Engine/ChiliUtil.h +++ b/Engine/ChiliUtil.h @@ -1,5 +1,48 @@ #pragma once +#include + +// remove an element from a vector +// messes up the order of elements +// (faster than erase and doesn't need iter) +template +inline void remove_element(std::vector& vec, size_t index) +{ + // swap element to be removed with element at back + std::swap(vec[index], vec.back()); + // back is now what we want dead, so pop back! + vec.pop_back(); +} + +// binary search finds matching element +// otherwise returns end +// Acc is a functor used to access the search keys in the elements +template +auto binary_find(Iter begin, Iter end, const T& val, + Acc acc = [](const Iter::value_type& obj) + ->const Iter::value_type& { return obj; }) +{ + // Finds the lower bound in at most log(last - first) + 1 comparisons + const auto i = std::lower_bound(begin, end, val, + [acc](const Iter::value_type& lhs, const T& rhs) + { + return acc(lhs) < rhs; + } + ); + + // if i is end, not found and do not dereference + // else i is either greater than or equal to value + // if not greater than, must be equal, so return it + if (i != end && !(val < acc(*i))) + { + return i; // found + } + else + { + return end; // not found + } +} + // uses remove_if to remove elements matching predicate over entire container // and then calls erase to remove the 'empty' husks at the end template diff --git a/Engine/ChiliWin.h b/Engine/ChiliWin.h index 2a88abcc..f2602b5b 100644 --- a/Engine/ChiliWin.h +++ b/Engine/ChiliWin.h @@ -23,14 +23,15 @@ // target Windows 7 or later #define _WIN32_WINNT 0x0601 #include + // The following #defines disable a bunch of unused windows stuff. If you // get weird errors when trying to do some windows stuff, try removing some // (or all) of these defines (it will increase build time though). +#ifndef FULL_WINTARD #define WIN32_LEAN_AND_MEAN //to exclude APIs such as Cryptography, DDE, RPC, Shell, and Windows Sockets. #define NOGDICAPMASKS #define NOSYSMETRICS -//#define NOMENUS #define NOICONS #define NOSYSCOMMANDS #define NORASTEROPS @@ -39,12 +40,10 @@ #define NOCLIPBOARD #define NOCOLOR #define NOCTLMGR -//#define NODRAWTEXT #define NOKERNEL #define NONLS #define NOMEMMGR #define NOMETAFILE -#define NOMINMAX #define NOOPENFILE #define NOSCROLL #define NOSERVICE @@ -62,6 +61,11 @@ #define NOIMAGE #define NOTAPE +#endif // FULL_WINTARD + +//#define NODRAWTEXT +#define NOMINMAX +//#define NOMENUS #ifndef STRICT #define STRICT #endif diff --git a/Engine/Colors.h b/Engine/Colors.h index 23883414..da23791b 100644 --- a/Engine/Colors.h +++ b/Engine/Colors.h @@ -26,31 +26,39 @@ class Color unsigned int dword; public: constexpr Color() : dword() {} - constexpr Color( const Color& col ) + constexpr Color(const Color& col) : - dword( col.dword ) + dword(col.dword) {} - constexpr Color( unsigned int dw ) + constexpr Color(unsigned int dw) : - dword( dw ) + dword(dw) {} - constexpr Color( unsigned char x,unsigned char r,unsigned char g,unsigned char b ) + constexpr Color(unsigned char x, unsigned char r, unsigned char g, unsigned char b) : - dword( (x << 24u) | (r << 16u) | (g << 8u) | b ) + dword((x << 24u) | (r << 16u) | (g << 8u) | b) {} - constexpr Color( unsigned char r,unsigned char g,unsigned char b ) + constexpr Color(unsigned char r, unsigned char g, unsigned char b) : - dword( (r << 16u) | (g << 8u) | b ) + dword((r << 16u) | (g << 8u) | b) {} - constexpr Color( Color col,unsigned char x ) + constexpr Color(Color col, unsigned char x) : - Color( (x << 24u) | col.dword ) + Color((x << 24u) | col.dword) {} - Color& operator =( Color color ) + Color& operator =(Color color) { dword = color.dword; return *this; } + bool operator==(const Color& rhs) const + { + return dword == rhs.dword; + } + bool operator!=(const Color& rhs) const + { + return !(*this == rhs); + } constexpr unsigned char GetX() const { return dword >> 24u; @@ -71,23 +79,23 @@ class Color { return dword & 0xFFu; } - void SetX( unsigned char x ) + void SetX(unsigned char x) { dword = (dword & 0xFFFFFFu) | (x << 24u); } - void SetA( unsigned char a ) + void SetA(unsigned char a) { - SetX( a ); + SetX(a); } - void SetR( unsigned char r ) + void SetR(unsigned char r) { dword = (dword & 0xFF00FFFFu) | (r << 16u); } - void SetG( unsigned char g ) + void SetG(unsigned char g) { dword = (dword & 0xFFFF00FFu) | (g << 8u); } - void SetB( unsigned char b ) + void SetB(unsigned char b) { dword = (dword & 0xFFFFFF00u) | b; } @@ -95,18 +103,18 @@ class Color namespace Colors { - static constexpr Color MakeRGB( unsigned char r,unsigned char g,unsigned char b ) + static constexpr Color MakeRGB(unsigned char r, unsigned char g, unsigned char b) { return (r << 16) | (g << 8) | b; } - static constexpr Color White = MakeRGB( 255u,255u,255u ); - static constexpr Color Black = MakeRGB( 0u,0u,0u ); - static constexpr Color Gray = MakeRGB( 0x80u,0x80u,0x80u ); - static constexpr Color LightGray = MakeRGB( 0xD3u,0xD3u,0xD3u ); - static constexpr Color Red = MakeRGB( 255u,0u,0u ); - static constexpr Color Green = MakeRGB( 0u,255u,0u ); - static constexpr Color Blue = MakeRGB( 0u,0u,255u ); - static constexpr Color Yellow = MakeRGB( 255u,255u,0u ); - static constexpr Color Cyan = MakeRGB( 0u,255u,255u ); - static constexpr Color Magenta = MakeRGB( 255u,0u,255u ); + static constexpr Color White = MakeRGB(255u, 255u, 255u); + static constexpr Color Black = MakeRGB(0u, 0u, 0u); + static constexpr Color Gray = MakeRGB(0x80u, 0x80u, 0x80u); + static constexpr Color LightGray = MakeRGB(0xD3u, 0xD3u, 0xD3u); + static constexpr Color Red = MakeRGB(255u, 0u, 0u); + static constexpr Color Green = MakeRGB(0u, 255u, 0u); + static constexpr Color Blue = MakeRGB(0u, 0u, 255u); + static constexpr Color Yellow = MakeRGB(255u, 255u, 0u); + static constexpr Color Cyan = MakeRGB(0u, 255u, 255u); + static constexpr Color Magenta = MakeRGB(255u, 0u, 255u); } \ No newline at end of file diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index 7a66d6cc..1de8e2dc 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -21,7 +21,7 @@ {FFCA512B-49FC-4FC8-8A73-C4F87D322FF2} Engine - 10.0.16299.0 + 10.0.17134.0 @@ -80,6 +80,7 @@ Fast MultiThreadedDebug false + stdcpplatest @@ -94,6 +95,7 @@ VectorCall false MultiThreadedDebug + stdcpplatest @@ -110,6 +112,7 @@ MultiThreaded false NDEBUG;_UNICODE;UNICODE;%(PreprocessorDefinitions) + stdcpplatest true @@ -129,6 +132,7 @@ MultiThreaded false NDEBUG;_UNICODE;UNICODE;%(PreprocessorDefinitions) + stdcpplatest true @@ -140,6 +144,8 @@ + + @@ -155,15 +161,18 @@ - + + + + @@ -176,6 +185,8 @@ + + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index fa22fa01..fa9d4f72 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -37,6 +37,9 @@ {b9b4aa28-3d6d-4412-b8b4-6ff6c3af9881} + + {17f84fd5-42d9-44cc-a348-7ca1040c068a} + @@ -105,9 +108,6 @@ Header Files\Geometric shapes - - Header Files\Chili util - Header Files\Chili util @@ -117,6 +117,21 @@ Header Files\Chili util + + Header Files\Chili Spriite loading + + + Header Files\Chili Spriite loading + + + Header Files\Chili Spriite loading + + + Header Files\Chili Spriite loading + + + Header Files\Chili util + @@ -155,6 +170,15 @@ Header Files\Geometric shapes + + Source Files + + + Source Files + + + Source Files + diff --git a/Engine/Font.cpp b/Engine/Font.cpp new file mode 100644 index 00000000..07eed270 --- /dev/null +++ b/Engine/Font.cpp @@ -0,0 +1,61 @@ +#include "Font.h" +#include +#include "SpriteEffect.h" + +Font::Font(const std::wstring& filename, Color chroma) + : + surface(filename), + // calculate glyph dimensions from bitmap dimensions + glyphWidth(surface.GetWidth() / nColumns), + glyphHeight(surface.GetHeight() / nRows), + chroma(chroma) +{ + // verify that bitmap had valid dimensions + assert(glyphWidth * nColumns == surface.GetWidth()); + assert(glyphHeight * nRows == surface.GetHeight()); +} + +void Font::DrawText(const std::string& text, const JC_Vector2i& pos, Color color, Graphics& gfx) const +{ + // create effect functor + SpriteEffect::Substitution e{ chroma,color }; + // curPos is the pos that we are drawing to on the screen + auto curPos = pos; + for (auto c : text) + { + // on a newline character, reset x position and move down by 1 glyph height + if (c == '\n') + { + // carriage return + curPos.x = pos.x; + // line feed + curPos.y += glyphHeight; + // we don't want to advance the character position right for a newline + continue; + } + // only draw characters that are on the font sheet + // start at firstChar + 1 because might as well skip ' ' as well + else if (c >= firstChar + 1 && c <= lastChar) + { + // use DrawSpriteSubstitute so that we can choose the color of the font rendered + gfx.DrawSprite(curPos.x, curPos.y, MapGlyphRect(c), surface, e); + } + // advance screen pos for next character + curPos.x += glyphWidth; + } +} + +RectI Font::MapGlyphRect(char c) const +{ + assert(c >= firstChar && c <= lastChar); + // font sheet glyphs start at ' ', calculate index into sheet + const int glyphIndex = c - ' '; + // map 1d glyphIndex to 2D coordinates + const int yGlyph = glyphIndex / nColumns; + const int xGlyph = glyphIndex % nColumns; + // convert the sheet grid coords to pixel coords in sheet + return RectI( + { xGlyph * glyphWidth,yGlyph * glyphHeight }, + glyphWidth, glyphHeight + ); +} \ No newline at end of file diff --git a/Engine/Font.h b/Engine/Font.h new file mode 100644 index 00000000..0734d9c4 --- /dev/null +++ b/Engine/Font.h @@ -0,0 +1,27 @@ +#pragma once + +#include "Graphics.h" +#include "Surface.h" + +class Font +{ +public: + Font(const std::wstring& filename, Color chroma = Colors::White); + void DrawText(const std::string& text, const JC_Vector2i& pos, Color color, Graphics& gfx) const; +private: + RectI MapGlyphRect(char c) const; +private: + // holds the font sheet bitmap data + Surface surface; + // this gives the dimensions of a glyph in the font sheet + int glyphWidth; + int glyphHeight; + // number of rows / columns in the font sheet (this is fixed) + static constexpr int nColumns = 32; + static constexpr int nRows = 3; + // font sheet chroma color + Color chroma; + // start and end drawable character codes + static constexpr char firstChar = ' '; + static constexpr char lastChar = '~'; +}; \ No newline at end of file diff --git a/Engine/GDIPlusManager.cpp b/Engine/GDIPlusManager.cpp new file mode 100644 index 00000000..897401a8 --- /dev/null +++ b/Engine/GDIPlusManager.cpp @@ -0,0 +1,42 @@ +// gdiplus needs a lot of dumb windows shit +// enable that shit for this translation unit only#define FULL_WINTARD +#define FULL_WINTARD +#include "ChiliWin.h" +#include "GDIPlusManager.h" +// gdiplus needs min/max, but we disable that (even in +// full wintard mode), so we need to inject min/max into +// the Gdiplus namespace +#include +namespace Gdiplus +{ + using std::min; + using std::max; +} +#include + +// we need to link to the gdip library somewhere +// might as well be here +#pragma comment( lib,"gdiplus.lib" ) + +ULONG_PTR GDIPlusManager::token = 0; +int GDIPlusManager::refCount = 0; + +GDIPlusManager::GDIPlusManager() +{ + if (refCount++ == 0) + { + Gdiplus::GdiplusStartupInput input; + input.GdiplusVersion = 1; + input.DebugEventCallback = nullptr; + input.SuppressBackgroundThread = false; + Gdiplus::GdiplusStartup(&token, &input, nullptr); + } +} + +GDIPlusManager::~GDIPlusManager() +{ + if (--refCount == 0) + { + Gdiplus::GdiplusShutdown(token); + } +} diff --git a/Engine/GDIPlusManager.h b/Engine/GDIPlusManager.h new file mode 100644 index 00000000..29cdf1bd --- /dev/null +++ b/Engine/GDIPlusManager.h @@ -0,0 +1,36 @@ +/****************************************************************************************** +* Chili DirectX Framework Version 16.10.01 * +* GDIPlusManager.h * +* Copyright 2016 PlanetChili * +* * +* This file is part of The Chili DirectX Framework. * +* * +* The Chili DirectX Framework is free software: you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation, either version 3 of the License, or * +* (at your option) any later version. * +* * +* The Chili DirectX Framework is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with The Chili DirectX Framework. If not, see . * +******************************************************************************************/ +#pragma once +#include "ChiliWin.h" + +class GDIPlusManager +{ +public: + // when a gdipman is ctored when no others exist, it will init gdip + GDIPlusManager(); + // when a gdipman is dtored and it is the last existing, it will cleanup gdip + ~GDIPlusManager(); +private: + // gdip creation token (for API calls) + static ULONG_PTR token; + // refcount to keep track of when necessary to init/cleanup + static int refCount; +}; \ No newline at end of file diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index 31b374ca..d0cfe7f5 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -26,7 +26,7 @@ #include #include -#include "Chili_Rectangle.h" +#include "ChiliRectangle.h" // Ignore the intellisense error "cannot open source file" for .shh files. @@ -37,6 +37,21 @@ namespace FramebufferShaders #include "FramebufferVS.shh" } +Color Graphics::GetPixel(int x, int y) const +{ + assert(x >= 0); + assert(x < int(Graphics::ScreenWidth)); + assert(y >= 0); + assert(y < int(Graphics::ScreenHeight)); + return pSysBuffer[Graphics::ScreenWidth * y + x]; +} + +RectI Graphics::GetScreenRect() +{ + return{ 0,ScreenWidth,0,ScreenHeight }; +} + + #pragma comment( lib,"d3d11.lib" ) #define CHILI_GFX_EXCEPTION( hr,note ) Graphics::Exception( hr,note,_CRT_WIDE(__FILE__),__LINE__ ) @@ -204,6 +219,7 @@ Graphics::Graphics( HWNDKey& key ) throw CHILI_GFX_EXCEPTION( hr,L"Creating vertex buffer" ); } + ////////////////////////////////////////// // create input layout for fullscreen quad diff --git a/Engine/Graphics.h b/Engine/Graphics.h index afb1e8d9..0392bfcf 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -29,7 +29,8 @@ #include "Colors.h" #include "JC_Vector2.h" #include "JC_Math.h" -#include "Chili_Rectangle.h" +#include "ChiliRectangle.h" +#include "Surface.h" class Graphics { @@ -58,6 +59,9 @@ class Graphics Graphics& operator=( const Graphics& ) = delete; void EndFrame(); void BeginFrame(); + + Color GetPixel(int x, int y) const; + void PutPixel( int x,int y,int r,int g,int b ) { PutPixel( x,y,{ unsigned char( r ),unsigned char( g ),unsigned char( b ) } ); @@ -109,6 +113,98 @@ class Graphics /***** End Draw Arc Functions *****/ + + template + void DrawSprite(int x, int y, const Surface& s, E effect, bool reversed = false) + { + DrawSprite(x, y, s.GetRect(), s, effect, reversed); + } + template + void DrawSprite(int x, int y, const RectI& srcRect, const Surface& s, E effect, bool reversed = false) + { + DrawSprite(x, y, srcRect, GetScreenRect(), s, effect, reversed); + } + template + void DrawSprite(int x, int y, RectI srcRect, const RectI& clip, const Surface& s, E effect, bool reversed = false) + { + assert(srcRect.left >= 0); + assert(srcRect.right <= s.GetWidth()); + assert(srcRect.top >= 0); + assert(srcRect.bottom <= s.GetHeight()); + + // mirror in x depending on reversed bool switch + if (!reversed) + { + // cliping is different depending on mirroring status + if (x < clip.left) + { + srcRect.left += clip.left - x; + x = clip.left; + } + if (y < clip.top) + { + srcRect.top += clip.top - y; + y = clip.top; + } + if (x + srcRect.GetWidth() > clip.right) + { + srcRect.right -= x + srcRect.GetWidth() - clip.right; + } + if (y + srcRect.GetHeight() > clip.bottom) + { + srcRect.bottom -= y + srcRect.GetHeight() - clip.bottom; + } + for (int sy = srcRect.top; sy < srcRect.bottom; sy++) + { + for (int sx = srcRect.left; sx < srcRect.right; sx++) + { + effect( + // no mirroring + s.GetPixel(sx, sy), + x + sx - srcRect.left, + y + sy - srcRect.top, + *this + ); + } + } + } + else + { + if (x < clip.left) + { + srcRect.right -= clip.left - x; + x = clip.left; + } + if (y < clip.top) + { + srcRect.top += clip.top - y; + y = clip.top; + } + if (x + srcRect.GetWidth() > clip.right) + { + srcRect.left += x + srcRect.GetWidth() - clip.right; + } + if (y + srcRect.GetHeight() > clip.bottom) + { + srcRect.bottom -= y + srcRect.GetHeight() - clip.bottom; + } + const int xOffset = srcRect.left + srcRect.right - 1; + for (int sy = srcRect.top; sy < srcRect.bottom; sy++) + { + for (int sx = srcRect.left; sx < srcRect.right; sx++) + { + effect( + // mirror in x + s.GetPixel(xOffset - sx, sy), + x + sx - srcRect.left, + y + sy - srcRect.top, + *this + ); + } + } + } + } + ~Graphics(); private: Microsoft::WRL::ComPtr pSwapChain; @@ -127,4 +223,6 @@ class Graphics public: static constexpr int ScreenWidth =1440; static constexpr int ScreenHeight = 900; + static RectI GetScreenRect(); + }; \ No newline at end of file diff --git a/Engine/SoundEffect.h b/Engine/SoundEffect.h index b9e303d1..105f3a6d 100644 --- a/Engine/SoundEffect.h +++ b/Engine/SoundEffect.h @@ -1,5 +1,5 @@ -/****************************************************************************************** - * Chili DirectX Framework Sound Pack Version 16.11.11 * +/****************************************************************************************** + * Chili DirectX Framework Sound Pack Version 16.11.11 * * SoundEffect.h * * Copyright 2016 PlanetChili.net * * * @@ -23,26 +23,49 @@ #include #include #include +#include +#include class SoundEffect { public: - SoundEffect( const std::initializer_list& wavFiles,bool soft_fail = false,float freqStdDevFactor = 0.06f ) + // this ctor reads from a .sfx file to configure/load a sound effect + SoundEffect(const std::wstring& filename) + { + std::wifstream sfxFile(filename); + // first line is the freq stddev + float freqStdDevFactor; + sfxFile >> freqStdDevFactor; + sfxFile.ignore(); + // remaining lines are the sound files + std::vector soundFileNames; + for (std::wstring s; std::getline(sfxFile, s); ) + { + soundFileNames.push_back(std::move(s)); + } + // now load the dumb sound effect matrix + *this = SoundEffect(std::move(soundFileNames), true, freqStdDevFactor); + } + SoundEffect(std::vector wavFiles, bool soft_fail = false, float freqStdDevFactor = 0.06f) : - freqDist( 0.0f,freqStdDevFactor ), - soundDist( 0,unsigned int( wavFiles.size() - 1 ) ) + freqDist(0.0f, freqStdDevFactor), + soundDist(0, unsigned int(wavFiles.size() - 1)) { - sounds.reserve( wavFiles.size() ); - for( auto& f : wavFiles ) + sounds.reserve(wavFiles.size()); + for (auto& f : wavFiles) { try { - sounds.emplace_back( f ); + sounds.emplace_back(f); } - catch( const SoundSystem::FileException& e ) + catch (const SoundSystem::FileException& e) { - if( soft_fail ) + if (soft_fail) { +#ifndef NDEBUG + // throw anyways if in debug (we devs wanna know!) + throw e; +#endif sounds.emplace_back(); } else @@ -53,12 +76,23 @@ class SoundEffect } } template - void Play( T& rng,float vol = 1.0f ) + void Play(T& rng, float vol = 1.0f) const + { + sounds[soundDist(rng)].Play(exp2(freqDist(rng)), vol); + } + // NOT THREAD SAFE! + // calls main play function with default rng + void Play(float vol = 1.0f) const { - sounds[soundDist( rng )].Play( exp2( freqDist( rng ) ),vol ); + Play(defaultRng, vol); } private: - std::uniform_int_distribution soundDist; - std::normal_distribution freqDist; + // make distribs mutable so that Play can be const + // (dist call not really a substantial mutation anyways...) + mutable std::uniform_int_distribution soundDist; + mutable std::normal_distribution freqDist; std::vector sounds; + // global default rng for sound effects + // not thread safe! + static std::mt19937 defaultRng; }; \ No newline at end of file diff --git a/Engine/SpriteEffect.h b/Engine/SpriteEffect.h new file mode 100644 index 00000000..ea06b1ba --- /dev/null +++ b/Engine/SpriteEffect.h @@ -0,0 +1,141 @@ +#pragma once + +#include "Colors.h" +#include "Graphics.h" + +namespace SpriteEffect +{ + class Chroma + { + public: + Chroma(Color c) + : + chroma(c) + {} + void operator()(Color cSrc, int xDest, int yDest, Graphics& gfx) const + { + if (cSrc != chroma) + { + gfx.PutPixel(xDest, yDest, cSrc); + } + } + private: + Color chroma; + }; + class Substitution + { + public: + Substitution(Color c, Color s) + : + chroma(c), + sub(s) + {} + void operator()(Color cSrc, int xDest, int yDest, Graphics& gfx) const + { + if (cSrc != chroma) + { + gfx.PutPixel(xDest, yDest, sub); + } + } + private: + Color chroma = Colors::Magenta; + Color sub; + }; + class Copy + { + public: + void operator()(Color cSrc, int xDest, int yDest, Graphics& gfx) const + { + gfx.PutPixel(xDest, yDest, cSrc); + } + }; + class Ghost + { + public: + Ghost(Color c) + : + chroma(c) + {} + void operator()(Color src, int xDest, int yDest, Graphics& gfx) const + { + if (src != chroma) + { + const Color dest = gfx.GetPixel(xDest, yDest); + const Color blend = { + unsigned char((src.GetR() + dest.GetR()) / 2), + unsigned char((src.GetG() + dest.GetG()) / 2), + unsigned char((src.GetB() + dest.GetB()) / 2) + }; + gfx.PutPixel(xDest, yDest, blend); + } + } + private: + Color chroma; + }; + // dissolves image by scanline and blends drawn pixels with a color + // good for dying enemies i guess + class DissolveHalfTint + { + public: + DissolveHalfTint(Color chroma, Color tint, float percent) + : + chroma(chroma), + // divide channels by 2 via shift, mask to prevent bleeding between channels + tint_pre((tint.dword >> 1u) & 0b01111111011111110111111101111111u), + filled(int(float(height) * percent)) + {} + void operator()(Color src, int xDest, int yDest, Graphics& gfx) const + { + // height mask determines frequency of vertical dissolve sections + if (src != chroma && (yDest & height_mask) < filled) + { + const Color blend = tint_pre.dword + + // divide channels by 2 via shift, mask to prevent bleeding between channels + ((src.dword >> 1u) & 0b01111111011111110111111101111111u); + gfx.PutPixel(xDest, yDest, blend); + } + } + private: + Color chroma; + Color tint_pre; + static constexpr int height = 4; + static constexpr int height_mask = height - 1; + int filled; + }; + // blends sprite with whatever is on the screen + // using the per-pixel alpha stored in the src pixels + class AlphaBlendBaked + { + public: + void operator()(Color src, int xDest, int yDest, Graphics& gfx) const + { + // pre-extract alpha complement + const int cAlpha = 255 - src.GetA(); + // reject drawing pixels if alpha == 0 (full transparent) + // this will give a huge speedup if there are large sections + // of blank space (pretty common), but slower if unpredictable + // patters of transparency in a 50/50 mix (not really forseeable) + if (cAlpha != 255) + { + const Color dst = gfx.GetPixel(xDest, yDest); + // blend channels by linear interpolation using integer math + // (basic idea: src * alpha + dst * (1.0 - alpha), where alpha is from 0 to 1 + // we divide by 256 because it can be done with bit shift + // it gives us at most 0.4% error, but this is negligible + // optimized version has alpha premultiplied in src, all we need to do is + // scale dst by calpha and then pack back into dword and add to src dword + // there will be no overflow between channels because alpha + calpha == 255 + // + // we can multiply the red and blue channels together in one operation + // because the results will not overflow into neighboring channels + // after, we shift to divide, and then mask to clear out the shifted garbo + // channels are left in their byte position for easy combining with an add + const int rb = (((dst.dword & 0xFF00FFu) * cAlpha) >> 8) & 0xFF00FFu; + const int g = (((dst.dword & 0x00FF00u) * cAlpha) >> 8) & 0x00FF00u; + // add multiplied dst channels together with premultiplied src channels + // and write the resulting interpolated color to the screen + gfx.PutPixel(xDest, yDest, rb + g + src.dword); + } + } + }; +} \ No newline at end of file diff --git a/Engine/Surface.cpp b/Engine/Surface.cpp new file mode 100644 index 00000000..ec7d4524 --- /dev/null +++ b/Engine/Surface.cpp @@ -0,0 +1,175 @@ +#include "Surface.h" +// gdiplus needs a lot of dumb windows shit +// enable that shit for this translation unit only +#define FULL_WINTARD +#include "ChiliWin.h" +#include +// gdiplus needs min/max, but we disable that (even in +// full wintard mode), so we need to inject min/max into +// the Gdiplus namespace +namespace Gdiplus +{ + using std::min; + using std::max; +} +#include +#include +#include + +namespace gdi = Gdiplus; + +Surface::Surface(const std::wstring& filename) +{ + // filename must be at least 4 chars long + if (filename.length() < 4) + { + // generate narrow string of filename + std::string narrow(filename.begin(), filename.end()); + throw std::runtime_error("Surface::Surface bad file name: " + narrow); + } + + // open image file with gdiplus (not only .bmp files) + gdi::Bitmap bitmap(filename.c_str()); + + // check if file loaded successfully, throw exception if didn't + if (bitmap.GetLastStatus() != gdi::Ok) + { + // generate narrow string of filename + std::string narrow(filename.begin(), filename.end()); + // throw exception with error message + // could possibly add more info with lookup of error code name / desc + // but I don't want to right now cuz im lazy + throw std::runtime_error("Surface::Surface failed to load file: " + narrow); + } + + // allocate Surface resources and set dimensions + width = bitmap.GetWidth(); + height = bitmap.GetHeight(); + pPixels = new Color[width * height]; + + // test if pixel format is alpha, and save result + const bool isAlpha = gdi::IsAlphaPixelFormat(bitmap.GetPixelFormat()) == TRUE; + + // loop through image dimensions, copy from gdip bitmap to surface + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + // need this to receive color of pixel + gdi::Color pixel; + // read color from gdip bitmap + bitmap.GetPixel(x, y, &pixel); + // write to surface (with alpha channel if exists) + if (isAlpha) + { + PutPixel(x, y, { pixel.GetA(),pixel.GetR(),pixel.GetG(),pixel.GetB() }); + } + else + { + PutPixel(x, y, { pixel.GetR(),pixel.GetG(),pixel.GetB() }); + } + } + } + + // check to see whether filename starts with "pm_" + // (actually, being lazy so only checking if contains "pm_") + // if so, gotta bake that alpha yo + if (filename.find(L"pm_") != std::wstring::npos) + { + BakeAlpha(); + } +} + +Surface::Surface(int width, int height) + : + width(width), + height(height), + pPixels(new Color[width*height]) +{ +} + +Surface::Surface(const Surface& rhs) + : + Surface(rhs.width, rhs.height) +{ + const int nPixels = width * height; + for (int i = 0; i < nPixels; i++) + { + pPixels[i] = rhs.pPixels[i]; + } +} + +Surface::~Surface() +{ + delete[] pPixels; + pPixels = nullptr; +} + +Surface& Surface::operator=(const Surface& rhs) +{ + // prevent self assignment + if (this != &rhs) + { + width = rhs.width; + height = rhs.height; + + delete[] pPixels; + pPixels = new Color[width*height]; + + const int nPixels = width * height; + for (int i = 0; i < nPixels; i++) + { + pPixels[i] = rhs.pPixels[i]; + } + } + return *this; +} + +void Surface::PutPixel(int x, int y, Color c) +{ + assert(x >= 0); + assert(x < width); + assert(y >= 0); + assert(y < height); + pPixels[y * width + x] = c; +} + +Color Surface::GetPixel(int x, int y) const +{ + assert(x >= 0); + assert(x < width); + assert(y >= 0); + assert(y < height); + return pPixels[y * width + x]; +} + +int Surface::GetWidth() const +{ + return width; +} + +int Surface::GetHeight() const +{ + return height; +} + +RectI Surface::GetRect() const +{ + return{ 0,width,0,height }; +} + +void Surface::BakeAlpha() +{ + const int nPixels = GetWidth() * GetHeight(); + for (int i = 0; i < nPixels; i++) + { + auto pix = pPixels[i]; + const int alpha = pix.GetA(); + // premulitply alpha time each channel + pix.SetR((pix.GetR() * alpha) / 256); + pix.SetG((pix.GetG() * alpha) / 256); + pix.SetB((pix.GetB() * alpha) / 256); + // write back to surface + pPixels[i] = pix; + } +} \ No newline at end of file diff --git a/Engine/Surface.h b/Engine/Surface.h new file mode 100644 index 00000000..cc8f6860 --- /dev/null +++ b/Engine/Surface.h @@ -0,0 +1,29 @@ +#pragma once + +#include "Colors.h" +#include +#include "ChiliRectangle.h" + +class Surface +{ +public: + // loading filename that begins with "pm_" + // will trigger alpha premultiply 'baking' + Surface(const std::wstring& filename); + Surface(int width, int height); + Surface(const Surface&); + ~Surface(); + Surface& operator=(const Surface&); + void PutPixel(int x, int y, Color c); + Color GetPixel(int x, int y) const; + int GetWidth() const; + int GetHeight() const; + RectI GetRect() const; + // this function performs alpha premultiplication + // which enables more efficient alpha blending + void BakeAlpha(); +private: + Color* pPixels = nullptr; + int width; + int height; +}; \ No newline at end of file