小言_互联网的博客

C语言画一个正方体

367人阅读  评论(0)

程序截图

 

操作方法

鼠标拖动。左键拖动及滚轮能看到不同角度下正方体的形状,右键拖动能将最近的正方体顶点挪到这个投影面的相应位置。

按键控制。wasd 控制投影面旋转,ws 关于 x 轴旋转,ad 关于 y 轴旋转。

个人思路

首先投影面的确立需要两个量,一个 x 轴方向的单位向量,一个 y 轴方向的单位向量,求原点与三维空间中的点的连线到这两个单位向量的投影就能得到三维空间中的点在二维投影面中的坐标。记 x 轴方向单位向量为 X,y 轴方向单位向量为 Y,X 与 Y 互相垂直,模都为 1。

正方体的八个顶点位置随意,X,Y 两个单位向量只需是互相垂直的非零向量即可。

鼠标横向拖动时,X 关于 Y 旋转,这是怎么做到的呢。要做到这一点,就需要一个新的向量,也就是投影面的法向量,投影面的法向量可以根据两向量叉乘得到。叉乘的推法用的是线性代数的方法,但是不好理解,我用我的方法推出来,希望能方便理解。

设投影面法向量为 Z(x2, y2, z2),X(x0, y0, z0) 和 Y(x1, y1, z1) 与 Z 的点乘为 0,这就能列出两个式子:

① x0x2+y0y2+z0z2 = 0

② x1x2+y1y2+z1z2 = 0

将①式转化为以 x2 和 y2 表示的 z2 得

③ z2 = - (x0x2 + y0y2) / z0

将②式和③式结合转化为以 x2 表示的 y2 得

④ y2 = (x0z1 - x1z0) / (y1z0 - y0z1) * x2

④式代回③式得

⑤ z2 = (x1y0 - x0y1) / (y1z0 - y0z1) * x2 (推这一步时负号别忘了看)

也就是 Z = [x2, (x0z1 - x1z0) / (y1z0 - y0z1) * x2, (x1y0 - x0y1) / (y1z0 - y0z1) * x2]

仔细观察 Z 只有一个变量 x2,不妨先放大(y1z0 - y0z1)倍,得到

Z = [(y1z0 - y0z1) * x2, (x0z1 - x1z0) * x2, (x1y0 - x0y1) * x2]

把 x2 提取出来,Z 就是 Z = x2 * [(y1z0 - y0z1), (x0z1 - x1z0), (x1y0 - x0y1)]

令 x2 = 1,Z[(y1z0 - y0z1), (x0z1 - x1z0), (x1y0 - x0y1)] 就是投影面的法向量。到这一步还没有结束,因为垂直于一个面的法向量有两个,一个符合右手坐标系,一个符合左手坐标系,将 X(1, 0, 0),Y(0, 1, 0) 代入得 Z(0, 0, -1),所以这个 Z 是符合左手坐标系的投影面法向量,要转换成右手坐标系只需乘个 -1 就行,也就是 Z 最终为 (y0z1 - y1z0, x1z0 - x0z1, x0y1 - x1y0)。

由于 X,Y 都是单位向量,这个 Z 还是投影面的单位法向量。

Z 求出来了,X 关于 Y 旋转可以看做 X 在 XOZ 平面上旋转,问题转化成了求平面中某个向量转过θ度后的向量,如下图,将 X 看做下图中的红色向量,Z 看做下图中的绿色向量,虚线为向量旋转后θ度后的向量,可以发现 cos(θ)X - sin(θ)Z,就能求出 X 顺时针转动θ度后的向量,而 cos(θ)Z + sin(θ)X 就能求出 Z 顺时针转动θ度后的向量。

 

其它的旋转方式皆可以此类推。

代码实现

TCW_GUI.h:


  
  1. #pragma once
  2. #include<graphics.h>
  3. #include<string>
  4. #include<list>
  5. #include<functional>
  6. #define TCW_GUI_BUTTON_MYSELF 0
  7. namespace TCW_GUI
  8. {
  9. enum class State
  10. {
  11. general = 0,
  12. touch = 1,
  13. press = 2,
  14. release = 3,
  15. forbidden = 4
  16. };
  17. class Vec2
  18. {
  19. public:
  20. double x, y;
  21. Vec2() :x( 0), y( 0) {}
  22. Vec2(double xx, double yy) :x(xx), y(yy) {};
  23. Vec2 operator+(Vec2 num)
  24. {
  25. return Vec2(x + num.x, y + num.y);
  26. }
  27. Vec2 operator-(Vec2 num)
  28. {
  29. return Vec2(x - num.x, y - num.y);
  30. }
  31. Vec2 operator/(double num)
  32. {
  33. return Vec2(x / num, y / num);
  34. }
  35. Vec2 operator*(double num)
  36. {
  37. return Vec2(x * num, y * num);
  38. }
  39. };
  40. class Rect
  41. {
  42. public:
  43. Rect() :size(), position() {}
  44. Rect(Vec2 position, Vec2 size) :size(size), position(position) {}
  45. Vec2 size;
  46. Vec2 position;
  47. bool isInRect(Vec2 point)
  48. {
  49. Vec2 left_top = position - size / 2.0;
  50. Vec2 right_buttom = position + size / 2.0;
  51. if (point.x >= left_top.x && point.y >= left_top.y &&
  52. point.x <= right_buttom.x && point.y <= right_buttom.y) return true;
  53. return false;
  54. }
  55. };
  56. class Button
  57. {
  58. private:
  59. double textsize = 20;
  60. double textareasize = 0.9;
  61. Vec2 defaultsize = Vec2(textwidth(L "...") / textareasize, textheight(L "...") / textareasize);
  62. Vec2 defaulttext = Vec2(textwidth(L "..."), textheight(L "..."));
  63. State nowstate = State::general;
  64. void DrawButton_General();
  65. void DrawButton_Touch();
  66. void DrawButton_Press();
  67. void DrawButton_Forbidden();
  68. bool isPress = false;
  69. public:
  70. Button() :boundingbox(), buttontext() {}
  71. Button(Rect boundingbox, std::wstring buttontext, std::function<int(void*)> releaseFunc, void* releaseParam) :
  72. boundingbox(boundingbox), buttontext(buttontext), releaseFunc(releaseFunc), releaseParam(releaseParam) {}
  73. std::wstring buttontext;
  74. Rect boundingbox;
  75. std::function<int(void*)> releaseFunc = nullptr;
  76. void* releaseParam = nullptr;
  77. void DrawButton();
  78. void receiver(ExMessage* msg);
  79. void ForbidButton() { this->nowstate = State::forbidden; } // 禁用按钮
  80. void RefreshButton() { this->nowstate = State::general; } // 恢复按钮
  81. void SetTextSize(double size)
  82. {
  83. textsize = size;
  84. defaultsize = Vec2(textsize * 1.5 / textareasize, textsize / textareasize);
  85. defaulttext = Vec2(textsize * 1.5, textsize);
  86. }
  87. void SetTextAreaSize(double size)
  88. {
  89. textareasize = size;
  90. defaultsize = Vec2(textsize * 1.5 / textareasize, textsize / textareasize);
  91. defaulttext = Vec2(textsize * 1.5, textsize);
  92. }
  93. };
  94. class ButtonManager
  95. {
  96. std::list<Button> buttonlist;
  97. public:
  98. Button* AddButton(Button button);
  99. void ReceiveMessage(ExMessage* msg);
  100. void DrawButton();
  101. };
  102. void Rectangle_TCW(Vec2 left_top, Vec2 right_buttom)
  103. {
  104. rectangle(left_top.x, left_top.y, right_buttom.x, right_buttom.y);
  105. }
  106. void Fillrectangle_TCW(Vec2 left_top, Vec2 right_buttom)
  107. {
  108. fillrectangle(left_top.x, left_top.y, right_buttom.x, right_buttom.y);
  109. }
  110. void Outtextxy_TCW(Vec2 position, const WCHAR* str)
  111. {
  112. outtextxy(position.x, position.y, str);
  113. }
  114. void Button::DrawButton_General()
  115. {
  116. LOGFONT log;
  117. COLORREF textcol;
  118. COLORREF linecol;
  119. COLORREF fillcol;
  120. int bkmode;
  121. gettextstyle(&log);
  122. bkmode = getbkmode();
  123. textcol = gettextcolor();
  124. linecol = getlinecolor();
  125. fillcol = getfillcolor();
  126. settextstyle(textsize, 0, TEXT( "微软雅黑"));
  127. settextcolor(BLACK);
  128. setbkmode(TRANSPARENT);
  129. setlinecolor(BLACK);
  130. setfillcolor(WHITE);
  131. Vec2 size_button = Vec2( this->boundingbox.size * textareasize);
  132. Vec2 size_text = Vec2(textwidth( this->buttontext.c_str()), textsize);
  133. if (boundingbox.size.x > defaultsize.x && boundingbox.size.y > defaultsize.y)
  134. {
  135. Rectangle_TCW( this->boundingbox.position - this->boundingbox.size / 2.0,
  136. this->boundingbox.position + this->boundingbox.size / 2.0);
  137. Fillrectangle_TCW( this->boundingbox.position - this->boundingbox.size / 2.0,
  138. this->boundingbox.position + this->boundingbox.size / 2.0);
  139. if (size_button.x >= size_text.x && size_button.y >= size_text.y)
  140. {
  141. Outtextxy_TCW( this->boundingbox.position - size_text / 2.0, buttontext.c_str());
  142. }
  143. else
  144. {
  145. int wordnum = size_button.x / textwidth(buttontext.c_str()) * buttontext.size() - 2;
  146. std::wstring realstr = buttontext.substr( 0, wordnum);
  147. realstr += L "...";
  148. size_text = Vec2(textwidth(realstr.c_str()), textsize);
  149. Outtextxy_TCW( this->boundingbox.position - size_text / 2.0, realstr.c_str());
  150. }
  151. }
  152. else
  153. {
  154. Rectangle_TCW( this->boundingbox.position - this->defaultsize / 2.0,
  155. this->boundingbox.position + this->defaultsize / 2.0);
  156. Fillrectangle_TCW( this->boundingbox.position - this->defaultsize / 2.0,
  157. this->boundingbox.position + this->defaultsize / 2.0);
  158. if (defaulttext.x >= size_text.x && defaulttext.y >= size_text.y)
  159. Outtextxy_TCW( this->boundingbox.position - size_text / 2.0, buttontext.c_str());
  160. else Outtextxy_TCW( this->boundingbox.position - defaulttext / 2.0, TEXT( "..."));
  161. }
  162. settextstyle(&log);
  163. settextcolor(textcol);
  164. setbkmode(bkmode);
  165. setlinecolor(linecol);
  166. setfillcolor(fillcol);
  167. }
  168. void Button::DrawButton_Touch()
  169. {
  170. LOGFONT log;
  171. COLORREF textcol;
  172. COLORREF linecol;
  173. COLORREF fillcol;
  174. int bkmode;
  175. gettextstyle(&log);
  176. bkmode = getbkmode();
  177. textcol = gettextcolor();
  178. linecol = getlinecolor();
  179. fillcol = getfillcolor();
  180. settextstyle(textsize, 0, TEXT( "微软雅黑"));
  181. settextcolor(BLACK);
  182. setbkmode(TRANSPARENT);
  183. setlinecolor(BLACK);
  184. setfillcolor(RGB( 240, 240, 240));
  185. Vec2 size_button = Vec2( this->boundingbox.size * textareasize);
  186. Vec2 size_text = Vec2(textwidth( this->buttontext.c_str()), textsize);
  187. if (boundingbox.size.x > defaultsize.x && boundingbox.size.y > defaultsize.y)
  188. {
  189. Rectangle_TCW( this->boundingbox.position - this->boundingbox.size / 2.0,
  190. this->boundingbox.position + this->boundingbox.size / 2.0);
  191. Fillrectangle_TCW( this->boundingbox.position - this->boundingbox.size / 2.0,
  192. this->boundingbox.position + this->boundingbox.size / 2.0);
  193. if (size_button.x >= size_text.x && size_button.y >= size_text.y)
  194. {
  195. Outtextxy_TCW( this->boundingbox.position - size_text / 2.0, buttontext.c_str());
  196. }
  197. else
  198. {
  199. int wordnum = size_button.x / textwidth(buttontext.c_str()) * buttontext.size() - 2;
  200. std::wstring realstr = buttontext.substr( 0, wordnum);
  201. realstr += L "...";
  202. size_text = Vec2(textwidth(realstr.c_str()), textsize);
  203. Outtextxy_TCW( this->boundingbox.position - size_text / 2.0, realstr.c_str());
  204. }
  205. }
  206. else
  207. {
  208. Rectangle_TCW( this->boundingbox.position - this->defaultsize / 2.0,
  209. this->boundingbox.position + this->defaultsize / 2.0);
  210. Fillrectangle_TCW( this->boundingbox.position - this->defaultsize / 2.0,
  211. this->boundingbox.position + this->defaultsize / 2.0);
  212. if (defaulttext.x >= size_text.x && defaulttext.y >= size_text.y)
  213. Outtextxy_TCW( this->boundingbox.position - size_text / 2.0, buttontext.c_str());
  214. else Outtextxy_TCW( this->boundingbox.position - defaulttext / 2.0, TEXT( "..."));
  215. }
  216. settextstyle(&log);
  217. settextcolor(textcol);
  218. setbkmode(bkmode);
  219. setlinecolor(linecol);
  220. setfillcolor(fillcol);
  221. }
  222. void Button::DrawButton_Press()
  223. {
  224. LOGFONT log;
  225. COLORREF textcol;
  226. COLORREF linecol;
  227. COLORREF fillcol;
  228. int bkmode;
  229. gettextstyle(&log);
  230. bkmode = getbkmode();
  231. textcol = gettextcolor();
  232. linecol = getlinecolor();
  233. fillcol = getfillcolor();
  234. settextstyle(textsize, 0, TEXT( "微软雅黑")); // 设置字体为宽高 20 的字,有一些字体的中文宽度为字母的两倍
  235. settextcolor(BLACK);
  236. setbkmode(TRANSPARENT);
  237. setlinecolor(BLACK);
  238. setfillcolor(RGB( 240, 240, 240));
  239. Vec2 size_button = Vec2( this->boundingbox.size * textareasize);
  240. Vec2 size_text = Vec2(textwidth( this->buttontext.c_str()), textsize);
  241. if (boundingbox.size.x > defaultsize.x && boundingbox.size.y > defaultsize.y)
  242. {
  243. Rectangle_TCW( this->boundingbox.position - this->boundingbox.size / 2.0,
  244. this->boundingbox.position + this->boundingbox.size / 2.0);
  245. Fillrectangle_TCW( this->boundingbox.position - this->boundingbox.size / 2.0,
  246. this->boundingbox.position + this->boundingbox.size / 2.0);
  247. if (size_button.x >= size_text.x && size_button.y >= size_text.y)
  248. {
  249. Outtextxy_TCW( this->boundingbox.position - size_text / 2.0 + Vec2( 2, 2), buttontext.c_str());
  250. }
  251. else
  252. {
  253. int wordnum = size_button.x / textwidth(buttontext.c_str()) * buttontext.size() - 2;
  254. std::wstring realstr = buttontext.substr( 0, wordnum);
  255. realstr += L "...";
  256. size_text = Vec2(textwidth(realstr.c_str()), textsize);
  257. Outtextxy_TCW( this->boundingbox.position - size_text / 2.0, realstr.c_str());
  258. }
  259. }
  260. else
  261. {
  262. Rectangle_TCW( this->boundingbox.position - this->defaultsize / 2.0,
  263. this->boundingbox.position + this->defaultsize / 2.0);
  264. Fillrectangle_TCW( this->boundingbox.position - this->defaultsize / 2.0,
  265. this->boundingbox.position + this->defaultsize / 2.0);
  266. if (defaulttext.x >= size_text.x && defaulttext.y >= size_text.y)
  267. Outtextxy_TCW( this->boundingbox.position - size_text / 2.0 + Vec2( 2, 2), buttontext.c_str());
  268. else Outtextxy_TCW( this->boundingbox.position - defaulttext / 2.0 + Vec2( 2, 2), TEXT( "..."));
  269. }
  270. settextstyle(&log);
  271. settextcolor(textcol);
  272. setbkmode(bkmode);
  273. setlinecolor(linecol);
  274. setfillcolor(fillcol);
  275. }
  276. void Button::DrawButton_Forbidden()
  277. {
  278. LOGFONT log;
  279. COLORREF textcol;
  280. COLORREF linecol;
  281. COLORREF fillcol;
  282. int bkmode;
  283. gettextstyle(&log);
  284. bkmode = getbkmode();
  285. textcol = gettextcolor();
  286. linecol = getlinecolor();
  287. fillcol = getfillcolor();
  288. settextstyle(textsize, 0, TEXT( "微软雅黑"));
  289. settextcolor(RGB( 128, 128, 128));
  290. setbkmode(TRANSPARENT);
  291. setlinecolor(BLACK);
  292. setfillcolor(WHITE);
  293. Vec2 size_button = Vec2( this->boundingbox.size * textareasize);
  294. Vec2 size_text = Vec2(textwidth( this->buttontext.c_str()), textsize);
  295. if (boundingbox.size.x > defaultsize.x && boundingbox.size.y > defaultsize.y)
  296. {
  297. Rectangle_TCW( this->boundingbox.position - this->boundingbox.size / 2.0,
  298. this->boundingbox.position + this->boundingbox.size / 2.0);
  299. Fillrectangle_TCW( this->boundingbox.position - this->boundingbox.size / 2.0,
  300. this->boundingbox.position + this->boundingbox.size / 2.0);
  301. if (size_button.x >= size_text.x && size_button.y >= size_text.y)
  302. {
  303. Outtextxy_TCW( this->boundingbox.position - size_text / 2.0, buttontext.c_str());
  304. }
  305. else
  306. {
  307. int wordnum = size_button.x / textwidth(buttontext.c_str()) * buttontext.size() - 2;
  308. std::wstring realstr = buttontext.substr( 0, wordnum);
  309. realstr += L "...";
  310. size_text = Vec2(textwidth(realstr.c_str()), textsize);
  311. Outtextxy_TCW( this->boundingbox.position - size_text / 2.0, realstr.c_str());
  312. }
  313. }
  314. else
  315. {
  316. Rectangle_TCW( this->boundingbox.position - this->defaultsize / 2.0,
  317. this->boundingbox.position + this->defaultsize / 2.0);
  318. Fillrectangle_TCW( this->boundingbox.position - this->defaultsize / 2.0,
  319. this->boundingbox.position + this->defaultsize / 2.0);
  320. if (defaulttext.x >= size_text.x && defaulttext.y >= size_text.y)
  321. Outtextxy_TCW( this->boundingbox.position - size_text / 2.0, buttontext.c_str());
  322. else Outtextxy_TCW( this->boundingbox.position - defaulttext / 2.0, TEXT( "..."));
  323. }
  324. settextstyle(&log);
  325. settextcolor(textcol);
  326. setbkmode(bkmode);
  327. setlinecolor(linecol);
  328. setfillcolor(fillcol);
  329. }
  330. void Button::DrawButton()
  331. {
  332. switch ( this->nowstate)
  333. {
  334. case State::general:
  335. DrawButton_General();
  336. break;
  337. case State::touch:
  338. DrawButton_Touch();
  339. break;
  340. case State::press:
  341. DrawButton_Press();
  342. break;
  343. case State::release:
  344. DrawButton_Touch();
  345. if (releaseFunc != nullptr)
  346. {
  347. if (releaseParam == TCW_GUI_BUTTON_MYSELF)releaseFunc( this);
  348. else releaseFunc(releaseParam);
  349. }
  350. this->nowstate = State::touch;
  351. break;
  352. case State::forbidden:
  353. DrawButton_Forbidden();
  354. break;
  355. default:
  356. break;
  357. }
  358. }
  359. void Button::receiver(ExMessage* msg)
  360. {
  361. if ( this->nowstate == State::forbidden) return;
  362. // 先 general 后 touch 再 press 一个 release 后重新 general
  363. if (!isPress && ! this->boundingbox.isInRect(Vec2(msg->x, msg->y)))
  364. {
  365. this->nowstate = State::general;
  366. }
  367. else if (!isPress && this->boundingbox.isInRect(Vec2(msg->x, msg->y)))
  368. {
  369. if (!msg->lbutton)
  370. this->nowstate = State::touch;
  371. else if ( this->nowstate == State::touch)
  372. {
  373. isPress = true;
  374. this->nowstate = State::press;
  375. }
  376. }
  377. else if (isPress && this->boundingbox.isInRect(Vec2(msg->x, msg->y)))
  378. {
  379. if (!msg->lbutton)
  380. {
  381. isPress = false;
  382. this->nowstate = State::release;
  383. }
  384. else this->nowstate = State::press;
  385. }
  386. else if (isPress && ! this->boundingbox.isInRect(Vec2(msg->x, msg->y)))
  387. {
  388. if (!msg->lbutton)
  389. {
  390. isPress = false;
  391. this->nowstate = State::general;
  392. }
  393. else this->nowstate = State::press;
  394. }
  395. }
  396. Button* ButtonManager::AddButton(Button button)
  397. {
  398. this->buttonlist.push_back(button);
  399. return &buttonlist.back();
  400. }
  401. void ButtonManager::ReceiveMessage(ExMessage* msg)
  402. {
  403. for (Button& button : this->buttonlist)
  404. {
  405. button.receiver(msg);
  406. }
  407. }
  408. void ButtonManager::DrawButton()
  409. {
  410. for (Button& button : this->buttonlist)
  411. {
  412. button.DrawButton();
  413. }
  414. }
  415. }

main.cpp:


  
  1. // 程序:一个正方体
  2. // 编译环境:Visual Studio 2019,EasyX_20211109
  3. //
  4. #include<math.h>
  5. #include<conio.h>
  6. #include"TCW_GUI.h"
  7. #define WIDTH 640 // 窗口宽度
  8. #define HEIGHT 480 // 窗口高度
  9. #define PI 3.14159265 // π
  10. #define SIDE (min(WIDTH, HEIGHT) / 4) // 正方体边长
  11. #define GAMEPAD (SIDE / 2) // 手柄,控制面旋转幅度的量
  12. #define DISPLAY 3 // 展示出来顶点的尺寸
  13. #define ARROWS 3 // 箭头尺寸
  14. #define PIECE 360
  15. double FocalLength = 6; // 观察点到投影面的距离
  16. // 8 个顶点的颜色,用于分辨 8 个不同的点
  17. COLORREF VertexColor[ 8] =
  18. {
  19. RED, YELLOW, BLUE, GREEN, BROWN, MAGENTA, CYAN, WHITE
  20. };
  21. struct Vec2
  22. {
  23. double x, y;
  24. };
  25. Vec2 operator*(Vec2 a, double num)
  26. {
  27. return { a.x * num, a.y * num };
  28. }
  29. Vec2 operator+(Vec2 a, Vec2 b)
  30. {
  31. return { a.x + b.x, a.y + b.y };
  32. }
  33. Vec2 operator-(Vec2 a, Vec2 b)
  34. {
  35. return { a.x - b.x, a.y - b.y };
  36. }
  37. double operator*(Vec2 a, Vec2 b)
  38. {
  39. return a.x * b.x + a.y * b.y;
  40. }
  41. Vec2 operator/(Vec2 a, double num)
  42. {
  43. return { a.x / num, a.y / num };
  44. }
  45. // 三维向量,也可以表示一个坐标
  46. struct Vec3
  47. {
  48. double x, y, z;
  49. };
  50. typedef struct Vec3;
  51. // 求两向量相减
  52. Vec3 operator-(Vec3 a, Vec3 b)
  53. {
  54. return { a.x - b.x, a.y - b.y, a.z - b.z };
  55. }
  56. // 求两向量相加
  57. Vec3 operator+(Vec3 a, Vec3 b)
  58. {
  59. return { a.x + b.x, a.y + b.y, a.z + b.z };
  60. }
  61. // 得到两向量点乘的值
  62. double operator*(Vec3 a, Vec3 b)
  63. {
  64. return a.x * b.x + a.y * b.y + a.z * b.z;
  65. }
  66. // 得到向量缩短 num 倍后的向量
  67. Vec3 operator/(Vec3 a, long double num)
  68. {
  69. Vec3 result;
  70. result.x = a.x / num;
  71. result.y = a.y / num;
  72. result.z = a.z / num;
  73. return result;
  74. }
  75. // 得到向量延长 num 倍后的向量
  76. Vec3 operator*(Vec3 a, long double num)
  77. {
  78. Vec3 result;
  79. result.x = a.x * num;
  80. result.y = a.y * num;
  81. result.z = a.z * num;
  82. return result;
  83. }
  84. // 得到一个向量的模长
  85. double GetVec3Length(Vec3 vec)
  86. {
  87. return sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z);
  88. }
  89. // 得到向量 a 与向量 b 的夹角余弦值
  90. double GetCosineOfTheAngle(Vec3 a, Vec3 b)
  91. {
  92. return a * b / GetVec3Length(a) / GetVec3Length(b);
  93. }
  94. // 得到向量 A 在向量 B 上的投影
  95. Vec3 GetProjectionAOntoB(Vec3 A, Vec3 B)
  96. {
  97. double num = GetCosineOfTheAngle(A, B); // 得到向量 A,B 的夹角余弦值
  98. double length = GetVec3Length(A) * num; // 向量 A 的模长乘 num 为向量 A 在向量 B 上投影的模长
  99. Vec3 result = B * ( abs(length) / GetVec3Length(B)); // 向量 B 延长 length 倍再缩短 B 的模长倍就是向量 A 在向量 B 上的投影
  100. // 如果 length 比 0 小说明 num 小于 0,也就是两向量夹角大于 90 度,结果要变为相反向量
  101. if (length > 0) return result;
  102. return result * ( -1.0);
  103. }
  104. // 根据投影面 x,y 轴正方向向量求出投影面法向量
  105. Vec3 getVerticalAxis(Vec3 AuxiliaryVector[2])
  106. {
  107. double x0 = AuxiliaryVector[ 0].x;
  108. double y0 = AuxiliaryVector[ 0].y;
  109. double z0 = AuxiliaryVector[ 0].z;
  110. double x1 = AuxiliaryVector[ 1].x;
  111. double y1 = AuxiliaryVector[ 1].y;
  112. double z1 = AuxiliaryVector[ 1].z;
  113. Vec3 result = { y0 * z1 - y1 * z0, x1 * z0 - x0 * z1, x0 * y1 - x1 * y0 };
  114. return result;
  115. }
  116. // 将三维的点的值转换为在对应 xoy 面上的投影的坐标
  117. typedef Vec3 DoubleVec3[ 2];
  118. Vec2 Transform3DTo2D(Vec3 vertex, DoubleVec3 AuxiliaryVector, bool isParallel)
  119. {
  120. Vec2 result;
  121. Vec3 tempX = GetProjectionAOntoB(vertex, AuxiliaryVector[ 0]); // 得到三维向量在 x 轴上的投影
  122. Vec3 tempY = GetProjectionAOntoB(vertex, AuxiliaryVector[ 1]); // 得到三维向量在 y 轴上的投影
  123. result.x = GetVec3Length(tempX); // 得到 tempX 的模长,模长就是结果的 x 值的绝对值
  124. result.y = GetVec3Length(tempY); // 得到 tempY 的模长,模长就是结果的 y 值的绝对值
  125. if (tempX * AuxiliaryVector[ 0] < 0)result.x *= -1; // 如果 tempX 向量与 x 轴正方向的向量夹角大于 90 度,也就是向量点乘为负数,那么结果的 x 值为负数
  126. if (tempY * AuxiliaryVector[ 1] < 0)result.y *= -1; // 如果 tempY 向量与 y 轴正方向的向量夹角大于 90 度,也就是向量点乘为负数,那么结果的 y 值为负数
  127. if (isParallel) return result;
  128. Vec3 Vec_Z = getVerticalAxis(AuxiliaryVector) * SIDE * FocalLength;
  129. Vec3 target = vertex - Vec_Z;
  130. return result * (SIDE * FocalLength / GetVec3Length( GetProjectionAOntoB(target, Vec_Z)));
  131. }
  132. // 画一个正方体
  133. void drawCube(Vec3 Vertex[8], Vec3 AuxiliaryVector[2], Vec2 pericenter, bool isParallel)
  134. {
  135. Vec2 Temp[ 8];
  136. for ( int i = 0; i < 8; i++)
  137. {
  138. Vec2 temp = Transform3DTo2D(Vertex[i], AuxiliaryVector, isParallel);
  139. Temp[i] = temp;
  140. setfillcolor(VertexColor[i]);
  141. solidcircle(temp.x + pericenter.x, temp.y + pericenter.y, DISPLAY);
  142. }
  143. line(Temp[ 0].x + pericenter.x, Temp[ 0].y + pericenter.y, Temp[ 3].x + pericenter.x, Temp[ 3].y + pericenter.y);
  144. line(Temp[ 0].x + pericenter.x, Temp[ 0].y + pericenter.y, Temp[ 1].x + pericenter.x, Temp[ 1].y + pericenter.y);
  145. line(Temp[ 0].x + pericenter.x, Temp[ 0].y + pericenter.y, Temp[ 4].x + pericenter.x, Temp[ 4].y + pericenter.y);
  146. line(Temp[ 1].x + pericenter.x, Temp[ 1].y + pericenter.y, Temp[ 2].x + pericenter.x, Temp[ 2].y + pericenter.y);
  147. line(Temp[ 1].x + pericenter.x, Temp[ 1].y + pericenter.y, Temp[ 5].x + pericenter.x, Temp[ 5].y + pericenter.y);
  148. line(Temp[ 2].x + pericenter.x, Temp[ 2].y + pericenter.y, Temp[ 3].x + pericenter.x, Temp[ 3].y + pericenter.y);
  149. line(Temp[ 2].x + pericenter.x, Temp[ 2].y + pericenter.y, Temp[ 6].x + pericenter.x, Temp[ 6].y + pericenter.y);
  150. line(Temp[ 3].x + pericenter.x, Temp[ 3].y + pericenter.y, Temp[ 7].x + pericenter.x, Temp[ 7].y + pericenter.y);
  151. line(Temp[ 4].x + pericenter.x, Temp[ 4].y + pericenter.y, Temp[ 5].x + pericenter.x, Temp[ 5].y + pericenter.y);
  152. line(Temp[ 4].x + pericenter.x, Temp[ 4].y + pericenter.y, Temp[ 7].x + pericenter.x, Temp[ 7].y + pericenter.y);
  153. line(Temp[ 5].x + pericenter.x, Temp[ 5].y + pericenter.y, Temp[ 6].x + pericenter.x, Temp[ 6].y + pericenter.y);
  154. line(Temp[ 6].x + pericenter.x, Temp[ 6].y + pericenter.y, Temp[ 7].x + pericenter.x, Temp[ 7].y + pericenter.y);
  155. char arr[ 128];
  156. WCHAR ano[ 128];
  157. settextstyle( 0, 0, _T( "Consolas"));
  158. settextcolor(WHITE);
  159. sprintf_s(arr, "x:(%f, %f, %f)", AuxiliaryVector[ 0].x, AuxiliaryVector[ 0].y, AuxiliaryVector[ 0].z);
  160. MultiByteToWideChar(CP_ACP, 0, arr, -1, ano, 128);
  161. outtextxy( 10, HEIGHT / 6 * 5, ano);
  162. sprintf_s(arr, "y:(%f, %f, %f)", AuxiliaryVector[ 1].x, AuxiliaryVector[ 1].y, AuxiliaryVector[ 1].z);
  163. MultiByteToWideChar(CP_ACP, 0, arr, -1, ano, 128);
  164. outtextxy( 10, HEIGHT / 9 * 8, ano);
  165. }
  166. // 得到两个点之间的距离(二维)
  167. double getTwoPointDistance(Vec2 a, Vec2 b)
  168. {
  169. return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
  170. }
  171. // 得到 8 个顶点中距离 point 这个二维点最近的点,p 是判断两点间距离是否符合要求的
  172. int getNearestIndex(Vec3 Vertex[8], Vec3 AuxiliaryVector[2], Vec2 point, bool isParallel, bool (*p)(double) = nullptr)
  173. {
  174. int result = 0;
  175. double nearestDistance = getTwoPointDistance( Transform3DTo2D(Vertex[ 0], AuxiliaryVector, isParallel), point);
  176. for ( int i = 1; i < 8; i++)
  177. {
  178. double temp = getTwoPointDistance( Transform3DTo2D(Vertex[i], AuxiliaryVector, isParallel), point);
  179. if (temp < nearestDistance)
  180. {
  181. result = i;
  182. nearestDistance = temp;
  183. }
  184. }
  185. if (p != nullptr && ! p(nearestDistance)) return -1;
  186. return result;
  187. }
  188. void Line(Vec2 begin, Vec2 end)
  189. {
  190. line(begin.x, begin.y, end.x, end.y);
  191. }
  192. // grading 是粒度,一条线分为几份,0.1 是 10 份
  193. void progressiveLine(Vec3 begincol, Vec3 endcol, Vec2 started, Vec2 finaled, double grading = 0.1)
  194. {
  195. Vec2 AddLine = (finaled - started) * grading;
  196. Vec3 AddCol = (endcol - begincol) * grading;
  197. Vec3 nowcol = begincol;
  198. for ( int i = 0; i < 1 / grading; i++)
  199. {
  200. nowcol = nowcol + AddCol;
  201. setlinecolor( RGB(nowcol.x, nowcol.y, nowcol.z));
  202. Line(started + AddLine * i, started + AddLine * (i + 1));
  203. }
  204. }
  205. // 画坐标轴,pericenter 是中心点,size 是一个单位长度的长度
  206. void drawCoordinateAxis(Vec2 pericenter, double size)
  207. {
  208. setlinestyle(PS_SOLID, 1);
  209. setlinecolor(WHITE);
  210. settextcolor(WHITE);
  211. settextstyle( 20, 0, _T( "Consolas"));
  212. double index_X = size * sqrt( 3) / sqrt( 5);
  213. double index_Y = size * sqrt( 2) / sqrt( 5);
  214. progressiveLine({ 0, 0, 0 }, { 255, 255, 255 }, pericenter + Vec2({ -index_X, -index_Y }),
  215. pericenter + Vec2({ index_X, index_Y }));
  216. line(pericenter.x + index_X - ARROWS, pericenter.y + index_Y, pericenter.x + index_X, pericenter.y + index_Y);
  217. line(pericenter.x + index_X, pericenter.y + index_Y - ARROWS, pericenter.x + index_X, pericenter.y + index_Y);
  218. outtextxy(pericenter.x + index_X, pericenter.y + index_Y, L"y");
  219. progressiveLine({ 0, 0, 0 }, { 255, 255, 255 }, pericenter + Vec2({ index_X, -index_Y }),
  220. pericenter + Vec2({ -index_X, +index_Y }));
  221. line(pericenter.x - index_X + ARROWS, pericenter.y + index_Y, pericenter.x - index_X, pericenter.y + index_Y);
  222. line(pericenter.x - index_X, pericenter.y + index_Y - ARROWS, pericenter.x - index_X, pericenter.y + index_Y);
  223. outtextxy(pericenter.x - index_X, pericenter.y + index_Y, L"x");
  224. progressiveLine({ 0, 0, 0 }, { 255, 255, 255 }, pericenter + Vec2({ 0, index_X }),
  225. pericenter + Vec2({ 0, -index_X }));
  226. line(pericenter.x + ARROWS, pericenter.y - index_X + ARROWS, pericenter.x, pericenter.y - index_X);
  227. line(pericenter.x - ARROWS, pericenter.y - index_X + ARROWS, pericenter.x, pericenter.y - index_X);
  228. outtextxy(pericenter.x, pericenter.y - index_X - 20, L"z");
  229. }
  230. // 画出辅助向量
  231. void drawAuxiliaryVector(Vec3 AuxiliaryVector[2], Vec2 pericenter, double size, bool isParallel)
  232. {
  233. settextstyle( 20, 0, _T( "Consolas"));
  234. Vec3 Auxiliary[ 2] = { { -1, 1, 0}, { -1, -1, 1} };
  235. Auxiliary[ 0] = Auxiliary[ 0] / GetVec3Length(Auxiliary[ 0]);
  236. Auxiliary[ 1] = Auxiliary[ 1] / GetVec3Length(Auxiliary[ 1]);
  237. Vec2 temp[ 2];
  238. temp[ 0] = Transform3DTo2D(AuxiliaryVector[ 0] * size, Auxiliary, isParallel); // x 轴
  239. temp[ 1] = Transform3DTo2D(AuxiliaryVector[ 1] * size, Auxiliary, isParallel); // y 轴
  240. double Cos_XX = GetCosineOfTheAngle( getVerticalAxis(Auxiliary), AuxiliaryVector[ 0]);
  241. double Cos_YY = GetCosineOfTheAngle( getVerticalAxis(Auxiliary), AuxiliaryVector[ 1]);
  242. if (Cos_XX < 0.0 && Cos_YY < 0.0)
  243. {
  244. setlinestyle(PS_SOLID, 2);
  245. progressiveLine({ 127, 0, 0 }, { 127 + 127 * Cos_XX, 0, 0 }, pericenter,
  246. pericenter + Vec2({ temp[ 0].x, -temp[ 0].y }));
  247. progressiveLine({ 127, 0, 0 }, { 127 + 127 * Cos_YY, 0, 0 }, pericenter,
  248. pericenter + Vec2({ temp[ 1].x, -temp[ 1].y }));
  249. drawCoordinateAxis(pericenter, size);
  250. }
  251. else if (Cos_XX >= 0.0 && Cos_YY < 0.0)
  252. {
  253. setlinestyle(PS_SOLID, 2);
  254. progressiveLine({ 127, 0, 0 }, { 127 + 127 * Cos_YY, 0, 0 }, pericenter,
  255. pericenter + Vec2({ temp[ 1].x, -temp[ 1].y }));
  256. drawCoordinateAxis(pericenter, size);
  257. setlinestyle(PS_SOLID, 2);
  258. progressiveLine({ 127, 0, 0 }, { 127 + 127 * Cos_XX, 0, 0 }, pericenter,
  259. pericenter + Vec2({ temp[ 0].x, -temp[ 0].y }));
  260. }
  261. else if (Cos_XX < 0.0 && Cos_YY >= 0.0)
  262. {
  263. setlinestyle(PS_SOLID, 2);
  264. progressiveLine({ 127, 0, 0 }, { 127 + 127 * Cos_XX, 0, 0 }, pericenter,
  265. pericenter + Vec2({ temp[ 0].x, -temp[ 0].y }));
  266. drawCoordinateAxis(pericenter, size);
  267. setlinestyle(PS_SOLID, 2);
  268. progressiveLine({ 127, 0, 0 }, { 127 + 127 * Cos_YY, 0, 0 }, pericenter,
  269. pericenter + Vec2({ temp[ 1].x, -temp[ 1].y }));
  270. }
  271. else if (Cos_XX >= 0.0 && Cos_YY >= 0.0)
  272. {
  273. drawCoordinateAxis(pericenter, size);
  274. setlinestyle(PS_SOLID, 2);
  275. progressiveLine({ 127, 0, 0 }, { 127 + 127 * Cos_XX, 0, 0 }, pericenter,
  276. pericenter + Vec2({ temp[ 0].x, -temp[ 0].y }));
  277. progressiveLine({ 127, 0, 0 }, { 127 + 127 * Cos_YY, 0, 0 }, pericenter,
  278. pericenter + Vec2({ temp[ 1].x, -temp[ 1].y }));
  279. }
  280. settextcolor(RED);
  281. outtextxy(pericenter.x + temp[ 0].x, pericenter.y - temp[ 0].y, L"X");
  282. outtextxy(pericenter.x + temp[ 1].x, pericenter.y - temp[ 1].y, L"Y");
  283. setlinestyle(PS_SOLID, 1);
  284. setlinecolor(WHITE);
  285. }
  286. // x 轴固定在 xoy 平面上,旋转 x 轴和 z 轴就能看到这个三维物体的所有角度!!!
  287. int main()
  288. {
  289. bool isExit = false;
  290. initgraph(WIDTH, HEIGHT);
  291. BeginBatchDraw();
  292. Vec3 AuxiliaryVector[ 2] = { { sqrt( 2) / 2.0, sqrt( 2) / 2.0, 0 },
  293. { - sqrt( 3) / 3.0, sqrt( 3) / 3, sqrt( 3) / 3.0 } }; // 辅助向量,分别是 x 轴,y 轴的单位向量
  294. bool isParallel = false;
  295. TCW_GUI::Button* button_param[ 2];
  296. TCW_GUI::ButtonManager manager;
  297. TCW_GUI::Button* button_temp = manager. AddButton(TCW_GUI:: Button(TCW_GUI:: Rect(TCW_GUI:: Vec2(WIDTH * 5 / 6.0, HEIGHT / 6.0),
  298. TCW_GUI:: Vec2(WIDTH / 7.0, HEIGHT / 7.0)), L"透视投影",
  299. [&]( void* param)
  300. {
  301. TCW_GUI::Button** button = (TCW_GUI::Button**)param;
  302. if (isParallel)
  303. {
  304. button[ 0]->buttontext = L"透视投影";
  305. button[ 1]-> RefreshButton();
  306. isParallel = false;
  307. }
  308. else
  309. {
  310. button[ 0]->buttontext = L"平行投影";
  311. button[ 1]-> ForbidButton();
  312. isParallel = true;
  313. }
  314. return 0;
  315. }, nullptr));
  316. button_temp->releaseParam = button_param;
  317. button_param[ 0] = button_temp;
  318. button_param[ 1] = manager. AddButton(TCW_GUI:: Button(TCW_GUI:: Rect(TCW_GUI:: Vec2(WIDTH * 5 / 6.0, HEIGHT / 3.0),
  319. TCW_GUI:: Vec2(WIDTH / 7.0, HEIGHT / 7.0)), L"透视距离",
  320. [&]( void* param)
  321. {
  322. WCHAR arr[ 128];
  323. char ano[ 128];
  324. InputBox(arr, 128, L"请输入透视距离(推荐 1~10, 可小数)");
  325. WideCharToMultiByte(CP_UTF8, 0, arr, -1, ano, 128, NULL, FALSE);
  326. sscanf(ano, "%lf", &FocalLength);
  327. return 0;
  328. }, nullptr));
  329. manager. AddButton(TCW_GUI:: Button(TCW_GUI:: Rect(TCW_GUI:: Vec2(WIDTH * 5 / 6.0, HEIGHT / 2.0),
  330. TCW_GUI:: Vec2(WIDTH / 7.0, HEIGHT / 7.0)), L"结束程序",
  331. []( void* param)
  332. {
  333. bool* isExit = ( bool*)param;
  334. *isExit = true;
  335. return 0;
  336. }, &isExit));
  337. Vec3 Vertex[ 8]; // 8 个顶点的坐标
  338. // 初始化 8 个顶点,这 8 个顶点是固定的,可以改变为任意坐标值,我们只是从不同的角度看这 8 个顶点
  339. Vertex[ 0] = { -GAMEPAD, -GAMEPAD, -GAMEPAD };
  340. Vertex[ 1] = { GAMEPAD, -GAMEPAD, -GAMEPAD };
  341. Vertex[ 2] = { GAMEPAD, GAMEPAD, -GAMEPAD };
  342. Vertex[ 3] = { -GAMEPAD, GAMEPAD, -GAMEPAD };
  343. Vertex[ 4] = { -GAMEPAD, -GAMEPAD, GAMEPAD };
  344. Vertex[ 5] = { GAMEPAD, -GAMEPAD, GAMEPAD };
  345. Vertex[ 6] = { GAMEPAD, GAMEPAD, GAMEPAD };
  346. Vertex[ 7] = { -GAMEPAD, GAMEPAD, GAMEPAD };
  347. ExMessage msg; // 鼠标信息
  348. bool ispress = false; // 是否按下
  349. bool isLpress = false; // 是否按下左键
  350. bool isRpress = false; // 是否按下右键
  351. double originalX = 0, originalY = 0; // 原来的坐标
  352. int vertexIndex = 0; // 右键点击时要操作的顶点的坐标
  353. while (!isExit)
  354. {
  355. while ( peekmessage(&msg, EM_MOUSE))
  356. {
  357. if (!ispress && (msg.lbutton || msg.rbutton))
  358. {
  359. ispress = true;
  360. if (msg.lbutton)isLpress = true; // 左键按下
  361. else if (msg.rbutton) // 右键按下
  362. {
  363. isRpress = true;
  364. vertexIndex = getNearestIndex(Vertex, AuxiliaryVector, // 得到距离按下的位置最近的正方体顶点的下标
  365. { ( double)msg.x - WIDTH / 2, ( double)msg.y - HEIGHT / 2 }, isParallel,
  366. []( double num) { if (num < DISPLAY) return true; return false; }); // 这个 lambda 表达式是为了让点到的地方距离最近的正方体顶点距离小于展示出来正方体顶点的尺寸才能生效
  367. }
  368. originalX = msg.x;
  369. originalY = msg.y;
  370. }
  371. else if (isLpress && msg.lbutton)
  372. {
  373. double DelFi = (msg.y - originalY) / 6 / GAMEPAD * PI;
  374. double DelTh = (msg.x - originalX) / GAMEPAD / 6 * PI;
  375. Vec3 tempVectorX = AuxiliaryVector[ 0];
  376. Vec3 tempVectorY = AuxiliaryVector[ 1];
  377. Vec3 tempVectorZ = getVerticalAxis(AuxiliaryVector);
  378. AuxiliaryVector[ 0] = tempVectorX * cos(DelTh) + tempVectorZ * sin(DelTh); // 改变 x 轴向量
  379. tempVectorZ = tempVectorZ * cos(DelTh) - tempVectorX * sin(DelTh);
  380. AuxiliaryVector[ 1] = tempVectorY * cos(DelFi) + tempVectorZ * sin(DelFi); // 改变 y 轴向量
  381. originalX = msg.x;
  382. originalY = msg.y;
  383. }
  384. else if (isRpress && msg.rbutton && vertexIndex != -1)
  385. {
  386. double lengthX = msg.x - originalX; // 在投影面横坐标上移动的距离
  387. double lengthY = msg.y - originalY; // 在投影面纵坐标上移动的距离
  388. // 对于选中的顶点,它变为它自身的向量加上投影面上的向量
  389. Vertex[vertexIndex] =
  390. Vertex[vertexIndex] +
  391. AuxiliaryVector[ 0] * lengthX / GetVec3Length(AuxiliaryVector[ 0]) +
  392. AuxiliaryVector[ 1] * lengthY / GetVec3Length(AuxiliaryVector[ 1]);
  393. originalX = msg.x;
  394. originalY = msg.y;
  395. }
  396. else if (ispress && !msg.lbutton)
  397. {
  398. ispress = false;
  399. isLpress = false;
  400. isRpress = false;
  401. }
  402. else if (msg.wheel)
  403. {
  404. double DelTh = msg.wheel / 120.0 * PI / 60.0; // 滚动 120 度旋转 3 度
  405. Vec3 tempVectorX = AuxiliaryVector[ 0];
  406. Vec3 tempVectorY = AuxiliaryVector[ 1];
  407. Vec3 tempVectorZ = getVerticalAxis(AuxiliaryVector);
  408. AuxiliaryVector[ 0] = tempVectorX * cos(DelTh) + tempVectorY * sin(DelTh); // 改变 x 轴向量
  409. AuxiliaryVector[ 1] = tempVectorY * cos(DelTh) - tempVectorX * sin(DelTh); // 改变 y 轴向量
  410. }
  411. }
  412. // 用鼠标不能进行精密控制,在这里用 wasd 实现键盘控制
  413. if (_kbhit())
  414. {
  415. // 按一下移动 3 度
  416. double DelFi = 0, DelTh = 0;
  417. Vec3 tempVectorX = AuxiliaryVector[ 0];
  418. Vec3 tempVectorY = AuxiliaryVector[ 1];
  419. Vec3 tempVectorZ = getVerticalAxis(AuxiliaryVector);
  420. switch (_getch())
  421. {
  422. case 'w':DelFi -= PI / 60.0; break;
  423. case 'a':DelTh += PI / 60.0; break;
  424. case 's':DelFi += PI / 60.0; break;
  425. case 'd':DelTh -= PI / 60.0; break;
  426. default:
  427. break;
  428. }
  429. AuxiliaryVector[ 0] = tempVectorX * cos(DelTh) + tempVectorZ * sin(DelTh); // 改变 x 轴向量
  430. tempVectorZ = tempVectorZ * cos(DelTh) - tempVectorZ * sin(DelTh);
  431. AuxiliaryVector[ 1] = tempVectorY * cos(DelFi) + tempVectorZ * sin(DelFi); // 改变 y 轴向量
  432. }
  433. cleardevice();
  434. drawCube(Vertex, AuxiliaryVector, { WIDTH / 2.0, HEIGHT / 2.0 }, isParallel);
  435. drawAuxiliaryVector(AuxiliaryVector, { WIDTH / 6 * 5, HEIGHT / 6 * 5 }, min(WIDTH, HEIGHT) / 9,
  436. isParallel);
  437. manager. ReceiveMessage(&msg);
  438. manager. DrawButton();
  439. FlushBatchDraw();
  440. }
  441. closegraph();
  442. return 0;
  443. }

c语言基础学习的个人空间-c语言基础学习个人主页-哔哩哔哩视频哔哩哔哩c语言基础学习的个人空间,提供c语言基础学习分享的视频、音频、文章、动态、收藏等内容,关注c语言基础学习账号,第一时间了解UP注动态。每天分享一个编程技术C/C++游戏源码素材及各种安装包:724050348 私信不常看!https://space.bilibili.com/2061978075?spm_id_from=333.788.0.0


转载:https://blog.csdn.net/yx5666/article/details/128569821
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场