{"id":2112,"date":"2019-05-23T21:47:07","date_gmt":"2019-05-23T13:47:07","guid":{"rendered":"http:\/\/www.hyzgame.com\/?p=2112"},"modified":"2019-05-23T21:49:19","modified_gmt":"2019-05-23T13:49:19","slug":"2d-3d%e6%8a%9b%e7%89%a9%e7%ba%bf","status":"publish","type":"post","link":"http:\/\/www.hyzgame.com\/?p=2112","title":{"rendered":"2D\/3D\u629b\u7269\u7ebf"},"content":{"rendered":"<p>#include&lt;iostream&gt;<\/p>\n<p>using namespace std;<br \/>\nusing uint=unsigned int;<\/p>\n<p>struct vec2<br \/>\n{<br \/>\nfloat x,y;<br \/>\n};<\/p>\n<p>struct vec3<br \/>\n{<br \/>\nfloat x,y,z;<br \/>\n};<\/p>\n<p>\/**<br \/>\n* \u7b97\u51fa\u6307\u5b9a\u6570\u91cf\u7684\u629b\u7269\u7ebf\u9ad8\u5ea6\u503c<br \/>\n* @param count \u7ed3\u679c\u6570\u91cf<br \/>\n* @param start \u8d77\u59cb\u65f6\u95f4\u91cf\uff0c\u4e00\u822c\u4e3a-1<br \/>\n* @param end \u7ed3\u675f\u65f6\u95f4\u91cf\uff0c\u4e00\u822c\u4e3a+1<br \/>\n*\/<br \/>\nfloat *Parabolic(const uint count,const float time_start=-1,const float time_end=1)<br \/>\n{<br \/>\nif(count&lt;=0)return(nullptr);<\/p>\n<p>float *result=new float[count];<\/p>\n<p>float rate;<br \/>\nfloat cur=time_start;<br \/>\nfloat total_time=time_end-time_start;<\/p>\n<p>for(uint i=0;i&lt;count;i++)<br \/>\n{<br \/>\nrate=float(i)\/float(count);<\/p>\n<p>cur=time_start+rate*total_time;<\/p>\n<p>result[i]=1-cur*cur;<\/p>\n<p>cout&lt;&lt;&#8220;height[&#8220;&lt;&lt;i&lt;&lt;&#8220;] &#8220;&lt;&lt;result[i]&lt;&lt;endl;<br \/>\n}<\/p>\n<p>return result;<br \/>\n}<\/p>\n<p>\/**<br \/>\n* \u753b2D\u629b\u7269\u7ebf<br \/>\n* @param start \u8d77\u59cb\u70b9<br \/>\n* @param end \u7ed3\u675f\u70b9<br \/>\n* @param up \u5355\u4f4d\u5411\u4e0a\u91cf<br \/>\n* @param height \u9ad8\u5ea6\u503c<br \/>\n* @param count \u6570\u91cf<br \/>\n*\/<br \/>\nvoid Put2D(const vec2 &amp;start,const vec2 &amp;end,const vec2 &amp;up,const float *height,const uint count)<br \/>\n{<br \/>\nvec2 total;<br \/>\nvec2 pos;<br \/>\nfloat rate;<\/p>\n<p>total.x=end.x-start.x;<br \/>\ntotal.y=end.y-start.y;<\/p>\n<p>cout&lt;&lt;&#8220;from &#8220;&lt;&lt;start.x&lt;&lt;&#8220;,&#8221;&lt;&lt;start.y&lt;&lt;&#8221; to &#8220;&lt;&lt;end.x&lt;&lt;&#8220;,&#8221;&lt;&lt;end.y&lt;&lt;endl;<\/p>\n<p>for(uint i=0;i&lt;count;i++)<br \/>\n{<br \/>\nrate=float(i)\/float(count);<\/p>\n<p>pos.x=start.x+rate*total.x;<br \/>\npos.y=start.y+rate*total.y;<\/p>\n<p>pos.x+=height[i]*up.x;<br \/>\npos.y+=height[i]*up.y;<\/p>\n<p>cout&lt;&lt;i&lt;&lt;&#8220;: &#8220;&lt;&lt;pos.x&lt;&lt;&#8220;,&#8221;&lt;&lt;pos.y&lt;&lt;endl;<br \/>\n}<br \/>\n}<\/p>\n<p>\/**<br \/>\n* \u753b3D\u629b\u7269\u7ebf<br \/>\n* @param start \u8d77\u59cb\u70b9<br \/>\n* @param end \u7ed3\u675f\u70b9<br \/>\n* @param up \u5355\u4f4d\u5411\u4e0a\u91cf<br \/>\n* @param height \u9ad8\u5ea6\u503c<br \/>\n* @param count \u6570\u91cf<br \/>\n*\/<br \/>\nvoid Put3D(const vec3 &amp;start,const vec3 &amp;end,const vec3 &amp;up,const float *height,const uint count)<br \/>\n{<br \/>\nvec3 total;<br \/>\nvec3 pos;<br \/>\nfloat rate;<\/p>\n<p>total.x=end.x-start.x;<br \/>\ntotal.y=end.y-start.y;<br \/>\ntotal.z=end.z-start.z;<\/p>\n<p>cout&lt;&lt;&#8220;from &#8220;&lt;&lt;start.x&lt;&lt;&#8220;,&#8221;&lt;&lt;start.y&lt;&lt;&#8220;,&#8221;&lt;&lt;start.z&lt;&lt;&#8221; to &#8220;&lt;&lt;end.x&lt;&lt;&#8220;,&#8221;&lt;&lt;end.y&lt;&lt;&#8220;,&#8221;&lt;&lt;end.z&lt;&lt;endl;<\/p>\n<p>for(uint i=0;i&lt;count;i++)<br \/>\n{<br \/>\nrate=float(i)\/float(count);<\/p>\n<p>pos.x=start.x+rate*total.x;<br \/>\npos.y=start.y+rate*total.y;<br \/>\npos.z=start.z+rate*total.z;<\/p>\n<p>pos.x+=height[i]*up.x;<br \/>\npos.y+=height[i]*up.y;<br \/>\npos.z+=height[i]*up.z;<\/p>\n<p>cout&lt;&lt;i&lt;&lt;&#8220;: &#8220;&lt;&lt;pos.x&lt;&lt;&#8220;,&#8221;&lt;&lt;pos.y&lt;&lt;&#8220;,&#8221;&lt;&lt;pos.z&lt;&lt;endl;<br \/>\n}<br \/>\n}<\/p>\n<p>void Test2D(float *height,const uint count)<br \/>\n{<br \/>\nvec2 start,end,up;<\/p>\n<p>start.x=0;<br \/>\nstart.y=0;<\/p>\n<p>end.x=100;<br \/>\nend.y=0;<\/p>\n<p>up.x=0;<br \/>\nup.y=100;<\/p>\n<p>Put2D(start,end,up,height,count);<br \/>\n}<\/p>\n<p>void Test3D(float *height,const uint count)<br \/>\n{<br \/>\nvec3 start,end,up;<\/p>\n<p>start.x=0;<br \/>\nstart.y=0;<br \/>\nstart.z=0;<\/p>\n<p>end.x=100;<br \/>\nend.y=0;<br \/>\nend.z=100;<\/p>\n<p>up.x=0;<br \/>\nup.y=100;<br \/>\nup.z=0;<\/p>\n<p>Put3D(start,end,up,height,count);<br \/>\n}<\/p>\n<p>void main()<br \/>\n{<br \/>\nconstexpr uint count=10;<\/p>\n<p>float *height=Parabolic(count);<\/p>\n<p>Test2D(height,count);<br \/>\nTest3D(height,count);<\/p>\n<p>delete[] height;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#include&lt;iostream&gt; using namespace std; using uin [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2112","post","type-post","status-publish","format-standard","hentry","category-1"],"_links":{"self":[{"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=\/wp\/v2\/posts\/2112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2112"}],"version-history":[{"count":3,"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=\/wp\/v2\/posts\/2112\/revisions"}],"predecessor-version":[{"id":2120,"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=\/wp\/v2\/posts\/2112\/revisions\/2120"}],"wp:attachment":[{"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2112"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}