游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1076|回复: 0

求助 关于向量问题

[复制链接]

8

主题

19

帖子

23

积分

注册会员

Rank: 2

积分
23
发表于 2007-4-18 09:36:00 | 显示全部楼层 |阅读模式
void Torus(float MinorRadius, float MajorRadius, float x, float y, float z)                                       
{
        int i, j;
        glPushMatrix();
        glTranslatef(x,y,z);
        glRotatef(45, 1.0, 1.0, 1.0);

        glTranslatef(0.0f,0.0f,zspeed);                                                                                // 移入/移出屏幕 z 个单位

        glRotatef(xrot,1.0f,0.0f,0.0f);                                                                        // 绕X轴旋转
        glRotatef(yrot,0.0f,1.0f,0.0f);                                                                        // 绕Y轴旋转
        glBegin( GL_QUAD_STRIP );                                                                       
                for (i=0; i<180; i++ )                                                                               
                {
                        for (j=0; j<361; j++)                              //把园环360等分                                               
                        {
                                float wrapFrac = (j%360)/(float)360;    // 把
                                float phi = PI2*wrapFrac;        //计算等分 的 角度
                                float sinphi = float(sin(phi));  //
                                float cosphi = float(cos(phi));

                                float r = MajorRadius + MinorRadius*cosphi;  //计算半径

                                glNormal3f(float(sin(PI2*(i%360+wrapFrac)/(float)360))*cosphi, sinphi, float(cos(PI2*(i%360+wrapFrac)/(float)360))*cosphi);
                                glVertex3f(float(sin(PI2*(i%360+wrapFrac)/(float)360))*r,MinorRadius*sinphi,float(cos(PI2*(i%360+wrapFrac)/(float)360))*r);

                                glNormal3f(float(sin(PI2*((i+1)%360+wrapFrac)/(float)360))*cosphi, sinphi, float(cos(PI2*((i+1)%360+wrapFrac)/(float)360))*cosphi);
                                glVertex3f(float(sin(PI2*((i+1)%360+wrapFrac)/(float)360))*r,MinorRadius*sinphi,float(cos(PI2*((i+1)%360+wrapFrac)/(float)360))*r);
                        }
                }
        glEnd();
        xrot+=xspeed;                                                                                                        // xrot 增加 xspeed 单位
        yrot+=yspeed;                                                                                                        // yrot 增加 yspeed 单位
        glPopMatrix();
}


上面是一个圆环的代码,那位大侠帮我解释以下
主要是float r = MajorRadius + MinorRadius*cosphi;  //计算半径

glNormal3f(float(sin(PI2*(i%360+wrapFrac)/(float)360))*cosphi, sinphi, float(cos(PI2*(i%360+wrapFrac)/(float)360))*cosphi);

glNormal3f(float(sin(PI2*((i+1)%360+wrapFrac)/(float)360))*cosphi, sinphi, float(cos(PI2*((i+1)%360+wrapFrac)/(float)360))*cosphi);

我觉得 float r = MajorRadius + MinorRadius*cosphi;  //计算半径
计算出来不是等份圆环的半径

两个法向量是如何计算
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-26 18:06

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表