五角星的坐标(DirectX)

本文介绍了一种使用C++和DirectX技术来绘制五角星图案的方法。通过数学计算确定五角星各顶点的位置,并定义了不同颜色的三角形条带以呈现立体效果。涉及三角函数计算坐标、色彩赋值及DirectX绘图命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 #define PI 3.1415926

#define lenth 250 //左边距
float ANGLE=PI/180;
int  R=150;
int r=R*sin(18*ANGLE)/cos(36*ANGLE);

 

int x[6],y[6],X[6],Y[6];
 for(int i=0;i<5;i++)
 {
  X[i]=lenth +R*cos((90+i*72)*ANGLE); /* 计算出大圆上的五个平均分布点的坐标*/
  Y[i]=lenth -R*sin((90+i*72)*ANGLE);
  x[i]=lenth +r*cos((54+i*72)*ANGLE); /* 计算出小圆上的五个平均分布点的坐标*/
  y[i]=lenth -r*sin((54+i*72)*ANGLE);
 }

///////////////////////////////////////////////////////////////////////////////////////////////////

CUSTOMVERTEX cvVertices[] =
   {
    { 250, 250,0.0,1.0,D3DCOLOR_XRGB(255, 0, 0)},
    {  x[0],y[0],0.0,1.0,D3DCOLOR_XRGB(255, 0, 255)},
    {  x[1],y[1],0.0,1.0,D3DCOLOR_XRGB(0, 255, 0)},
    {  X[0],Y[0],0.0,1.0,D3DCOLOR_XRGB(0, 0, 255)},
    { 250, 250,0.0,1.0,D3DCOLOR_XRGB(255, 0, 0)},
    {  x[1],y[1],0.0,1.0,D3DCOLOR_XRGB(255, 0, 255)},
    {  x[2],y[2],0.0,1.0,D3DCOLOR_XRGB(0, 255, 0)},
    {  X[1],Y[1],0.0,1.0,D3DCOLOR_XRGB(0, 0, 255)},
    { 250, 250,0.0,1.0,D3DCOLOR_XRGB(255, 0, 0)},
    {  x[2],y[2],0.0,1.0,D3DCOLOR_XRGB(255, 0, 255)},
    {  x[3],y[3],0.0,1.0,D3DCOLOR_XRGB(0, 255, 0)},
    {  X[2],Y[2],0.0,1.0,D3DCOLOR_XRGB(0, 0, 255)},
    { 250, 250,0.0,1.0,D3DCOLOR_XRGB(255, 0, 0)},
    {  x[3],y[3],0.0,1.0,D3DCOLOR_XRGB(255, 0, 255)},
    {  x[4],y[4],0.0,1.0,D3DCOLOR_XRGB(0, 255, 0)},
    {  X[3],Y[3],0.0,1.0,D3DCOLOR_XRGB(0, 0, 255)},
    { 250, 250,0.0,1.0,D3DCOLOR_XRGB(255, 0, 0)},
    {  x[4],y[4],0.0,1.0,D3DCOLOR_XRGB(255, 0, 255)},
    {  x[0],y[0],0.0,1.0,D3DCOLOR_XRGB(0, 255, 0)},
    {  X[4],Y[4],0.0,1.0,D3DCOLOR_XRGB(0, 0, 255)}
    
   };

////////////////////////////////////////////////////////////////////////////////////////////////////

  g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
  g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4, 2);
  g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 8, 2);
  g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 12, 2);
  g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 16, 2);

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值