大佬教程收集整理的这篇文章主要介绍了使用 C++ 围绕参考点旋转圆圈,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想围绕空间中的一个参考点创建一圈规则间隔的门。每次程序运行时,圆圈中的项目数量都会不同,因此它会自动重新调整以适应增加的项目数量。
我希望项目输出如下图所示:
我的代码是:
@H_696_17@ /**********
* Includes
*
**********/
#include <windows.h>
#include <gl/gl.h>
#include <math.h>
/**********
* Function Declarations
*
**********/
LRESulT CALLBACK WndProc (HWND hWnd,UINT message,WParaM wParam,LParaM lParam);
voID EnabLeopenGL (HWND hWnd,HDC *hDC,HglrC *hRC);
voID disabLeopenGL (HWND hWnd,HDC hDC,HglrC hRC);
int DrawAxis()
{
@R_502_5987@ i;
glClearcolor (0,1,1);
glPointSize(1);
glBegin (GL_POINTS);
glcolor3f(0,1);
for(i=-1;i<1;i=i+0.001)
{
glVertex2f(i,0);
glVertex2f(0,i);
}
glEnd ();
}
int SetPoint(@R_502_5987@ x,@R_502_5987@ y,int sizE)
{
glPointSize(sizE);
glBegin (GL_POINTS);
glcolor3f(1,1);
glVertex2f(x,y);
glEnd ();
}
int MovPoint(@R_502_5987@ x,@R_502_5987@ xt,@R_502_5987@ yt,1);
glVertex2f(xt+x/10,yt+y/10);
glEnd ();
}
int RotatePoint(@R_502_5987@ x,@R_502_5987@ Teta)
{
glPointSize(1);
glBegin(GL_POINTS);
glcolor3f(1,1);
Teta = Teta * 3.14 / 180;
x=x * cos(Teta) - y * sin(Teta);
y=x * sin(Teta) + y * cos(Teta);
@R_502_5987@ teta = 0;
@R_502_5987@ i = 0;
@R_502_5987@ r=0.4;
@R_502_5987@ Dtheta = 2 * 3.14 / 360;
glcolor3f(1,1);
glPointSize(3);
glBegin (GL_POINTS);
for (i = 0; i <360; i += 0.01)
{
teta = i * Dtheta;
glVertex2f( x+ r * cos(teta),y+ r * sin(teta) );
}
glEnd();
}
@R_502_5987@ dayereh (@R_502_5987@ x,@R_502_5987@ y)
{
@R_502_5987@ teta = 0;
@R_502_5987@ i = 0;
@R_502_5987@ r=0.4;
@R_502_5987@ Dtheta = 2 * 3.14 / 360;
glcolor3f(1,y+ r * sin(teta) );
}
glEnd ();
}
/**********
* WinMain
*
**********/
int WINAPI WinMain (HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdline,int iCmdshow)
{
WNDCLASS wc;
HWND hWnd;
HDC hDc;
HglrC hRc;
MSG msg;
BOol bQuit = falSE;
@R_502_5987@ theta = 0.0f;
/* register window class */
wc.style = CS_OWNDc;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoaDicon (NulL,IDI_APPliCATION);
wc.hcursor = Loadcursor (NulL,IDC_ARROW);
wc.hbrBACkground = (HBrush) GetStockObject (BLACK_Brush);
wc.lpszMenuname = NulL;
wc.lpszClassname = "GLSample";
RegisterClass (&wc);
/* create main window */
hWnd = CreateWindow (
"GLSample","OpenGL Sample",WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,550,60,456,NulL,hInstance,null);
/* enable OpenGL for the window */
EnabLeopenGL (hWnd,&hDC,&hRC);
/* program main loop */
while (!bQuit)
{
/* check for messages */
if (Peekmessage (&msg,PM_REMOVE))
{
/* handle or dispatch messages */
if (msg.message == WM_QUIT)
{
bQuit = TRUE;
}
else
{
Translatemessage (&msg);
dispatchmessage (&msg);
}
}
else
{
/* OpenGL animation code goes here */
glClearcolor (0,1);
glClear (GL_color_BUFFER_BIT);
DrawAxis();
// SetPoint(.9,5);
//MovPoint(0.5,0.5,-0.8,5);
//RotatePoint(.9,45);
// dayereh (-0.4,0);
// for (@R_502_5987@ r = 45; r < 360; r ++)
// for (@R_502_5987@ i = -0.4; i < 0; i += .1)
for (@R_502_5987@ j = 0; j < 1; j += .1)
{
RotatePoint(-0.3,j,45);
// RotatePoint(.6,i,45);
//// RotatePoint(0,45);
}
//RotatePoint(-0.3,-0.1,45);
// RotatePoint(-0.3,-0.2,47);
// RotatePoint(-0.3,-.3,55);
SwapBuffers (hDC);
theta += 0.2f;
Sleep (1);
}
}
/* shutdown OpenGL */
disabLeopenGL (hWnd,hDC,hRC);
/* destroy the window explicitly */
DestroyWindow (hWnd);
return msg.wParam;
}
/********
* Window Procedure
*
********/
LRESulT CALLBACK WndProc (HWND hWnd,LParaM lParam)
{
switch (messagE)
{
case WM_CREATE:
return 0;
case WM_CLOSE:
PostQuitmessage (0);
return 0;
case WM_DESTROY:
return 0;
case WM_KEYDOWN:
switch (wParam)
{
case VK_ESCAPE:
PostQuitmessage(0);
return 0;
}
return 0;
default:
return DefWindowProc (hWnd,message,wParam,lParam);
}
}
/*******
* Enable OpenGL
*
*******/
voID EnabLeopenGL (HWND hWnd,HglrC *hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
/* get the device context (DC) */
*hDC = GetDC (hWnd);
/* set the pixel format for the DC */
ZeroMemory (&pfd,sizeof (pfd));
pfd.nSize = sizeof (pfd);
pfd.nVersion = 1;
pfd.DWFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.ccolorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat (*hDC,&pfd);
SetPixelFormat (*hDC,iFormat,&pfd);
/* create and enable the render context (RC) */
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC,*hRC );
}
/******
* disable OpenGL
*
******/
voID disabLeopenGL (HWND hWnd,HglrC hRC)
{
wglMakeCurrent (NulL,null);
wgldeleteContext (hRC);
ReleaseDC (hWnd,hDC);
}
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的使用 C++ 围绕参考点旋转圆圈全部内容,希望文章能够帮你解决使用 C++ 围绕参考点旋转圆圈所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。