• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 32  文章 - 94  trackbacks - 0
            <2009年6月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            常用鏈接

            留言簿(8)

            隨筆分類

            隨筆檔案

            好友連接

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            注意:如果需要轉(zhuǎn)載,請(qǐng)注明作者
            作者:陳昱(CY)



            最后一章,主要是說(shuō)明一下面生成的分析,其實(shí)這里所有元素,除了0維時(shí)的第一個(gè)點(diǎn)外,生成都是拉伸產(chǎn)生的(有玩過(guò)3Dmax的朋友應(yīng)該很了解那個(gè)Extrude建模,就是那樣了)

            之前在面結(jié)構(gòu)定義里包含了4個(gè)點(diǎn),這其實(shí)無(wú)法表達(dá)面的真正關(guān)系,面還是應(yīng)該由線來(lái)表達(dá)。因?yàn)槊媸怯删€拉伸產(chǎn)生的,和點(diǎn)沒(méi)有直接的聯(lián)系。
            面的產(chǎn)生中,在進(jìn)入2維前,都是空的,進(jìn)入2維的生成后,復(fù)制了一批面,新得到的每個(gè)面的每一條邊分別對(duì)應(yīng)原來(lái)每個(gè)面的第一條邊,再偏移“上一維的線的數(shù)量”這樣就完成了面的復(fù)制部分。拉伸產(chǎn)生的面部分,每個(gè)面的第一條邊分別是上一維度中的線,第二條邊則分別對(duì)應(yīng)“從上一維度復(fù)制產(chǎn)生”的線,這兩條邊有復(fù)制和被復(fù)制的關(guān)系,因此,實(shí)際上這時(shí)面的4個(gè)點(diǎn)已經(jīng)從這2條邊得到了。但是為了下一維度的復(fù)制,肯定不能不管后面的2條邊,后面的2條邊的頂點(diǎn)已經(jīng)知道了,2條邊的第一個(gè)點(diǎn)都是上一維度的點(diǎn),第二個(gè)點(diǎn)都是從上一維度復(fù)制產(chǎn)生的點(diǎn),而這2條邊則都是從上一維度到當(dāng)前維度拉伸部分產(chǎn)生的邊。于是找到第一條拉伸邊,再根據(jù)當(dāng)前面已知的第一條邊的2個(gè)頂點(diǎn)分別對(duì)于第一個(gè)頂點(diǎn)的偏移量,就可以分別根據(jù)這個(gè)偏移量得到該面的第3、第4條邊了。

            于是到這里,每個(gè)維度的點(diǎn)、邊、面都是按照這樣的結(jié)構(gòu)保存,非常有序,即使面結(jié)構(gòu)中沒(méi)有保存頂點(diǎn),也可以根據(jù)保存的邊直接確定openGL的繪畫順序。


            另外,由于需要看到高維體的內(nèi)部結(jié)構(gòu),面要弄成半透明的,但是當(dāng)一個(gè)高維體旋轉(zhuǎn)時(shí),面之間會(huì)交叉重疊,因此對(duì)面的遠(yuǎn)近排序仍然無(wú)法保證每個(gè)像素被正確混合渲染。因此,對(duì)每一個(gè)面加上一個(gè)該面的索引數(shù),另外還加上了霧效,都是為了方便眼睛上直覺(jué)看懂。

            為了播放順暢,把維度值設(shè)在3--8之間。


            程序:
            HyperCube.rar

            源文件:
              1#pragma once
              2#include "mainWindowStyle.h"
              3#include "common/Render/CY_Camera.h"
              4
              5class CSuperCube:public CY_Screen
              6{
              7    //-----------------------------------------------------------
              8    int MaxDim;//維度數(shù)量
              9    int *PointsCount;
             10    int *LinesCount;
             11    int *FaceCount;
             12    //-----------------------------------------------------------
             13
             14    float Length;//邊長(zhǎng)
             15    //-----------------------------------------------------------------------------------------
             16    bool isDone;//已經(jīng)可以渲染的標(biāo)志
             17
             18    float *Points;//n維空間中的點(diǎn)(以DimensionNum為一組為一個(gè)點(diǎn)坐標(biāo),PointNum為點(diǎn)數(shù)量,所以該float數(shù)組大小為DimensionNum*PointNum)
             19    int    DimensionNum;
             20    int PointNum;
             21
             22    struct SLine
             23    {
             24        float *points1;
             25        float *points2;
             26        SLine()
             27        {
             28            points1=0;
             29            points2=0;
             30        }

             31    }
            ;
             32    SLine *Lines;//n維空間中的線(以2個(gè)點(diǎn)的x坐標(biāo)索引為起始)
             33    int LineNum;
             34
             35    struct SFace
             36    {
             37        SLine *line1;
             38        SLine *line2;
             39        SLine *line3;
             40        SLine *line4;
             41        SFace()
             42        {
             43            line1=0;
             44            line2=0;
             45            line3=0;
             46            line4=0;
             47        }

             48    }
            ;
             49    int FaceNum;
             50    SFace *Faces;//n維空間中的面
             51    //---------------------------------------------------------------------------------------------
             52    //初始化各個(gè)維度的立方體中,點(diǎn)、線、面的數(shù)量
             53    //輸入:maxDim最大維數(shù)
             54    void InitMaxPLF(int maxDim);
             55
             56
             57    //計(jì)算Dim維度下的立方體的點(diǎn)、線、面
             58    void CaculatePLF(int Dim);
             59    void CaculatePHelp(int currentDim);
             60    void CaculateLHelp(int currentDim);
             61    void CaculateFHelp(int currentDim);
             62    
             63    //----------------------------------------------------------------------------------------------
             64
             65    //吉文斯矩陣旋轉(zhuǎn),
             66    //輸入:dimNum空間維度(>=2,<=15)、point點(diǎn)指針、theta角度、dim1旋轉(zhuǎn)面的第一個(gè)方向、dim2旋轉(zhuǎn)面的第二個(gè)方向(值從1---15)
             67    //輸出:point點(diǎn)的坐標(biāo)值
             68    inline void GivensRotateMatrix(int dimNum,float *point,float theta,int dim1,int dim2);
             69
             70    void Rotate(float theta,int dim1,int dim2);
             71
             72    //--------------------------------------------------------------------------------------------
             73    SFace **RenderFaces;
             74    CGLText *FacesIndexTex;
             75    
             76    void FaceSort();
             77
             78public:
             79    CSuperCube();
             80    ~CSuperCube();
             81
             82    //-----------------------------------
             83    CY_TextBox *DimensionInput;
             84    CY_Label *InputLabel;
             85    CY_Button  *CreateBtn;
             86    CY_CheckBox *FaceLineRender;
             87    CY_Label *Tips1,*Tips2,*Tips3;
             88
             89    CY_Camera theCamera;
             90    //------------------------------------
             91
             92    unsigned long lastTime;
             93    unsigned long currentTime;
             94    short lastMousePos[2];
             95    void UpDate();
             96
             97    void DrawScene();
             98
             99    void LineRender();
            100    void FaceRender();
            101
            102
            103    void OnKeyDown();
            104    void OnCreateBtnDown(CY_Controller *);
            105    void OnMouseWheel(const short &zDalta);
            106}
            ;

              1#include "Screens.h"
              2#include <math.h>
              3
              4float MateriaColor[3][4]={0.9f,0.9f,0.5f,0.2f,
              5                          0.9f,0.5f,0.9f,0.2f,
              6                          0.5f,0.9f,0.9f,0.2f}
            ;
              7CSuperCube::CSuperCube():CY_Screen()
              8{
              9    isDone=false;
             10    Length=50.0f;
             11    MaxDim=0;//維度數(shù)量
             12
             13    PointsCount=0;//點(diǎn)數(shù)
             14    LinesCount=0;//線數(shù)
             15    FaceCount=0;//面數(shù)
             16
             17    Points=0;//n維空間中的點(diǎn)(以DimensionNum為一組為一個(gè)點(diǎn)坐標(biāo),PointNum為點(diǎn)數(shù)量,所以該float數(shù)組大小為DimensionNum*PointNum)
             18    DimensionNum=0;
             19    PointNum=0;
             20
             21    Lines=0;//n維空間中的線(以2個(gè)點(diǎn)的x坐標(biāo)索引為起始)
             22    LineNum=0;
             23
             24    Faces=0;
             25    FaceNum=0;
             26
             27    RenderFaces=0;
             28    FacesIndexTex=0;
             29
             30    //------------------------------------------------
             31    InputLabel=new CY_Label(L"請(qǐng)輸入超立方體維度:",20,20);
             32    this->addContent(InputLabel);
             33    DimensionInput=new CY_TextBox(160,15,100);
             34    DimensionInput->SetNumberic();
             35    this->addContent(DimensionInput);
             36    CreateBtn=new CY_Button(L"馬上生成~~",windowWidth-150,20,100,30);
             37    CreateBtn->OnMouseUpEvent.Bind(this,&CSuperCube::OnCreateBtnDown);
             38    this->addContent(CreateBtn);
             39    FaceLineRender=new CY_CheckBox(400,18,L"線框渲染",true);
             40    this->addContent(FaceLineRender);
             41    Tips1=new CY_Label(L"操作:主鍵盤上0控制坐標(biāo)X,1控制坐標(biāo)Y,3控制坐標(biāo)Z,4控制坐標(biāo)W于此類推。",10,windowHeight-60);
             42    Tips2=new CY_Label(L"按住兩個(gè)坐標(biāo)鍵,即可以讓物體在這2個(gè)坐標(biāo)組成的平面上旋轉(zhuǎn),再按住shift鍵旋轉(zhuǎn)方向相反",10,windowHeight-40);
             43    Tips3=new CY_Label(L"按住鼠標(biāo)鍵,移動(dòng)鼠標(biāo)可以從其它角度觀察,鼠標(biāo)滾輪控制鏡頭遠(yuǎn)近",10,windowHeight-20);
             44    this->addContent(Tips1);
             45    this->addContent(Tips2);
             46    this->addContent(Tips3);
             47    
             48    theCamera.SetTargetPosition(Vector3(0,0,0));
             49    theCamera.SetPosition(Vector3(0,0,150));
             50    theCamera.SetUpVector(Vector3(0,1,0));
             51    theCamera.SetMinMaxDistance(100,300);
             52    theCamera.SetTargetEnable(true);
             53
             54
             55    currentTime=GetTickCount();
             56    lastTime=currentTime;
             57    lastMousePos[0]=MousePosition[0];
             58    lastMousePos[1]=MousePosition[1];
             59    //--------------------------------------------------
             60
             61    InitMaxPLF(15);
             62}

             63CSuperCube::~CSuperCube()
             64{
             65    if (PointsCount) delete []PointsCount;
             66    if(LinesCount) delete[]LinesCount;
             67    if(FaceCount)delete[]FaceCount;
             68
             69    if(Points)delete []Points;
             70    if(Lines)delete []Lines;
             71    if(Faces)delete []Faces;
             72
             73    if(RenderFaces) delete[]RenderFaces;
             74    if(FacesIndexTex)delete []FacesIndexTex;
             75}

             76//----------------------------------------------------------------------------------------------------------------------------
             77void CSuperCube::InitMaxPLF(int maxDim)
             78{
             79    if (MaxDim || maxDim<3 || maxDim>15)
             80        return;
             81    
             82    MaxDim=maxDim+1;
             83
             84    PointsCount=new int[MaxDim];
             85    LinesCount=new int[MaxDim];
             86    FaceCount=new int[MaxDim];
             87
             88    int i;
             89
             90    PointsCount[0]=1;
             91    for (i=1;i<MaxDim;++i)
             92        PointsCount[i]=PointsCount[i-1]*2;
             93
             94    LinesCount[0]=0;
             95    LinesCount[1]=1;
             96    for (i=2;i<MaxDim;++i)
             97        LinesCount[i]=LinesCount[i-1]*2+PointsCount[i-1];
             98
             99    FaceCount[0]=0;
            100    FaceCount[1]=0;
            101    FaceCount[2]=1;
            102    for(i=3;i<MaxDim;++i)
            103        FaceCount[i]=FaceCount[i-1]*2+LinesCount[i-1];
            104}

            105//------------------------------------------------------------------------------------------------------------------------
            106inline void CSuperCube::GivensRotateMatrix(int dimNum,float *point,float theta,int dim1,int dim2)
            107{
            108    if(dimNum<2 || dimNum>=16 || dim1<0 || dim1>dimNum || dim2<0 ||dim2>dimNum || dim1==dim2)return;
            109
            110    float temp1=cos(theta);
            111    float temp2=sin(theta);
            112    float temp=point[dim1]*temp1-point[dim2]*temp2;
            113    
            114    point[dim2]=point[dim1]*temp2+point[dim2]*temp1;
            115    point[dim1]=temp;
            116}

            117void CSuperCube::Rotate(float theta,int dim1,int dim2)
            118{
            119    for(int i=0;i<PointNum;++i)
            120        GivensRotateMatrix(DimensionNum,&Points[i*DimensionNum],theta,dim1,dim2);
            121}

            122//-----------------------------------------------------------------------------------------------------------------------------
            123void CSuperCube::CaculatePHelp(int currentDim)
            124{
            125    int i;
            126    //----------------------點(diǎn)計(jì)算
            127    if(currentDim==0)
            128        return;
            129    else
            130    {
            131        int targetStart=1<<(currentDim-1);//復(fù)制的起始點(diǎn)
            132        int targetEnd=1<<currentDim;//復(fù)制的結(jié)束點(diǎn)下一點(diǎn)
            133        for (i=targetStart;i<targetEnd;++i)
            134        {
            135            int index=DimensionNum*i;//目標(biāo)點(diǎn)的x坐標(biāo)索引
            136            int source=DimensionNum*targetStart;//來(lái)源點(diǎn)的x坐標(biāo)索引負(fù)偏移量
            137            for (int j=0;j<currentDim-1;++j)
            138            {
            139                Points[index+j]=Points[index-source+j];//復(fù)制
            140            }

            141            Points[index+currentDim-1]=Length;//新加的維度設(shè)為邊長(zhǎng)
            142        }

            143    }

            144}

            145void CSuperCube::CaculateLHelp(int currentDim)
            146{
            147    //---------------------------邊計(jì)算
            148    if (currentDim==0)return;
            149    if(currentDim==1)
            150    {
            151        Lines[0].points1=&Points[0];
            152        Lines[0].points2=&Points[DimensionNum];
            153        return;
            154    }

            155    else
            156    {
            157        //----------------------------------------------------------復(fù)制產(chǎn)生的邊
            158        int targetStar=LinesCount[currentDim-1];//復(fù)制的起始邊
            159        int targetEnd=LinesCount[currentDim-1]*2;//復(fù)制的結(jié)束邊下一條邊
            160        for(int i=targetStar;i<targetEnd;++i)
            161        {
            162            Lines[i].points1=Lines[i-targetStar].points1+DimensionNum*(1<<(currentDim-1));//指針偏移
            163            Lines[i].points2=Lines[i-targetStar].points2+DimensionNum*(1<<(currentDim-1));
            164        }

            165        //------------------------------------------復(fù)制部分完成,增加拉伸部分產(chǎn)生的邊
            166        targetStar=targetEnd;//拉伸邊存儲(chǔ)起始
            167        targetEnd=targetStar+(1<<(currentDim-1));//拉伸邊存儲(chǔ)結(jié)束的下一條邊
            168        for(int i=targetStar;i<targetEnd;++i)
            169        {
            170            Lines[i].points1=&Points[(i-targetStar)*DimensionNum];
            171            Lines[i].points2=&Points[(i-targetStar*2+targetEnd)*DimensionNum];
            172        }

            173    }

            174}

            175void CSuperCube::CaculateFHelp(int currentDim)
            176{
            177    if(currentDim<2)return;
            178    if (currentDim==2)
            179    {
            180        Faces[0].line1=&Lines[0];
            181        Faces[0].line2=&Lines[1];
            182        Faces[0].line3=&Lines[2];
            183        Faces[0].line4=&Lines[3];
            184    }

            185    else
            186    {
            187        int targetStar=FaceCount[currentDim-1];//復(fù)制的起始面
            188        int targetEnd=FaceCount[currentDim-1]*2;//復(fù)制結(jié)束面的下一個(gè)面
            189
            190        for(int i=targetStar;i<targetEnd;++i)
            191        {
            192            Faces[i].line1=Faces[i-targetStar].line1+LinesCount[currentDim-1];//邊指針偏移
            193            Faces[i].line2=Faces[i-targetStar].line2+LinesCount[currentDim-1];
            194            Faces[i].line3=Faces[i-targetStar].line3+LinesCount[currentDim-1];
            195            Faces[i].line4=Faces[i-targetStar].line4+LinesCount[currentDim-1];
            196        }

            197        //-------------面復(fù)制完成,增加拉伸產(chǎn)生的面
            198        targetStar=targetEnd;//拉伸面存儲(chǔ)起始
            199        targetEnd=targetStar+LinesCount[currentDim-1];//拉伸面存儲(chǔ)結(jié)束的下一個(gè)面
            200        for(int i=targetStar;i<targetEnd;++i)
            201        {
            202            Faces[i].line1=&Lines[i-targetStar];
            203            Faces[i].line2=Faces[i].line1+LinesCount[currentDim-1];
            204
            205            //非復(fù)制邊的起始索引:
            206            int NoCopyindex=LinesCount[currentDim]-PointsCount[currentDim];
            207            //該邊的對(duì)于非復(fù)制邊起始索引的偏移量:
            208            int offset=(Faces[i].line1->points1-Points)/DimensionNum;
            209            Faces[i].line3=&Lines[NoCopyindex+offset];
            210            offset=(Faces[i].line1->points2-Points)/DimensionNum;
            211            Faces[i].line4=&Lines[NoCopyindex+offset];
            212        }

            213    }

            214}

            215void CSuperCube::CaculatePLF(int Dim)
            216{
            217    if(!MaxDim || Dim<2 || Dim>=MaxDim)return;
            218
            219    if(isDone)
            220    {
            221        delete []Points;
            222        delete []Lines;
            223        delete []Faces;
            224    }

            225    
            226    //-------------------------------------分配好內(nèi)存空間
            227    DimensionNum=Dim;
            228    PointNum=PointsCount[DimensionNum];
            229    LineNum=LinesCount[DimensionNum];
            230    FaceNum=FaceCount[DimensionNum];
            231
            232    Points=new float[PointNum*DimensionNum];
            233    for (int i=0;i<PointNum*DimensionNum;++i)
            234    {
            235        Points[i]=0;
            236    }

            237    
            238    Lines=new SLine[LineNum];
            239    Faces=new SFace[FaceNum];
            240
            241    //-------------------------------------計(jì)算值
            242    int currentDim=0;
            243    while (currentDim<=DimensionNum)
            244    {
            245        CaculatePHelp(currentDim);
            246        CaculateLHelp(currentDim);
            247        CaculateFHelp(currentDim);
            248        ++currentDim;
            249    }

            250    //-----------------------------------把n維體中心移到原點(diǎn)
            251    for(int i=0;i<DimensionNum*PointNum;++i)
            252    {
            253        Points[i]-=(Length/2);
            254    }

            255
            256    //-----------------------------------
            257    if(RenderFaces)
            258        delete []RenderFaces;
            259    RenderFaces=new SFace*[FaceNum];
            260
            261    if(FacesIndexTex)delete []FacesIndexTex;
            262    FacesIndexTex=new CGLText[FaceNum];
            263    for(int i=0;i<FaceNum;++i)
            264    {
            265        FacesIndexTex[i].SetFont(L"幼圓",60);
            266        FacesIndexTex[i].SetColor(1,1,1,0.7f);
            267        FacesIndexTex[i].SetReverColor();
            268        FacesIndexTex[i].SetText(i);
            269    }

            270}

            271//---------------------------------------------------------------------------------------------------------------------------
            272void CSuperCube::UpDate()
            273{
            274    currentTime=GetTickCount();
            275    unsigned long dalta=currentTime-lastTime;
            276    lastTime=currentTime;
            277
            278    int i=-1,j=-1;
            279    for (i=0;i<DimensionNum;++i)
            280    {
            281        if(CY_KeyBoard[48+i])
            282            break;
            283    }

            284    for (j=i+1;j<DimensionNum;++j)
            285    {
            286        if(CY_KeyBoard[48+j])
            287            break;
            288    }

            289    if(i>=0 && j<DimensionNum)//開(kāi)始旋轉(zhuǎn)
            290    {
            291        float theta=dalta*0.0016f;
            292        if(CY_KeyBoard[16])//反方向
            293            Rotate(-theta,i,j);
            294        else
            295            Rotate(theta,i,j);
            296    }

            297    if(CY_MouseKey[0])
            298    {
            299        theCamera.RotateLeftRight((MousePosition[0]-lastMousePos[0])*0.002f);
            300        theCamera.RotateUpDown((MousePosition[1]-lastMousePos[1])*0.002f);
            301    }

            302    lastMousePos[0]=MousePosition[0];
            303    lastMousePos[1]=MousePosition[1];
            304}

            305void CSuperCube::LineRender()
            306{
            307    if(!isDone)return;
            308    glDisable(GL_LIGHTING);
            309    //glDisable(GL_FOG);
            310    glLineWidth(3.0f);
            311    glColor4f(1,1,1,1.0f);
            312    for (int i=0;i<LineNum;++i)
            313    {
            314        glBegin(GL_LINES);
            315        glVertex3fv(Lines[i].points1);
            316        glVertex3fv(Lines[i].points2);
            317        //glVertex3f(30,30,-10);
            318        //glVertex3f(-30,30,10);
            319        //glVertex3f(30,-30,0);
            320        glEnd();
            321    }

            322    
            323}

            324void CSuperCube::FaceRender()
            325{
            326    if(!isDone)return;
            327    
            328    
            329    for (int i=0;i<FaceNum;++i)
            330    {
            331        RenderFaces[i]=&Faces[i];
            332    }

            333    FaceSort();
            334    
            335
            336    GLfloat a[] = 0.0f0.0f0.0f};
            337    float length=VectorLength(theCamera.GetPosition());
            338    glFogfv(GL_FOG_COLOR, a);
            339    glFogi(GL_FOG_MODE, GL_LINEAR);
            340    glFogf(GL_FOG_START,length);
            341    glFogf(GL_FOG_END,length+28);
            342    glEnable(GL_FOG);
            343
            344    /*GLfloat fLightPos[]   = { 50, 50, 200,1.0f};
            345    GLfloat light0_ambient[]= { 0.1f, 0.0f, 0.0f, 0.1f };
            346    GLfloat light0_diffuse[]= { 0.7f, 0.5f, 0.1f, 0.1f };
            347    GLfloat light0_specular[] = { 1, 1, 1, 0.8f };
            348    glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
            349    glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
            350    glLightfv(GL_LIGHT0, GL_SPECULAR,light0_specular);
            351    glLightfv(GL_LIGHT0, GL_POSITION, fLightPos);
            352    glEnable(GL_LIGHTING);
            353    glEnable(GL_LIGHT0);*/

            354    glDisable(GL_LIGHTING);
            355
            356    glEnable(GL_BLEND);
            357    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
            358    //glBlendFunc(GL_SRC_COLOR,GL_ONE_MINUS_SRC_COLOR);
            359    //glBlendFunc(GL_SRC_ALPHA, GL_ONE);
            360    glDisable(GL_DEPTH_TEST);
            361
            362    //glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32);
            363    //glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,MateriaColor[0]);
            364    //glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MateriaColor[1]);
            365    //glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,MateriaColor[2]);
            366
            367
            368    /*glBegin(GL_QUADS);
            369    glColor4f(0,0,0,1);
            370    glVertex3f(-1000,-1000,-500);
            371    glVertex3f(1000,-1000,-500);
            372    glVertex3f(1000,1000,-500);
            373    glVertex3f(-1000,1000,-500);
            374    glEnd();*/

            375    
            376    int temp=1;
            377    for (int i=0;i<FaceNum;++i)
            378    {
            379        temp=RenderFaces[i]-Faces;
            380        glBindTexture(GL_TEXTURE_2D,FacesIndexTex[temp].GetTextureID());
            381        glBegin(GL_QUADS);
            382        glColor4fv(MateriaColor[temp%3]);
            383        glTexCoord2i(0,0);
            384        glVertex3fv(RenderFaces[i]->line1->points1);
            385        glTexCoord2i(0,1);
            386        glVertex3fv(RenderFaces[i]->line1->points2);
            387        glTexCoord2i(1,1);
            388        glVertex3fv(RenderFaces[i]->line2->points2);
            389        glTexCoord2i(1,0);
            390        glVertex3fv(RenderFaces[i]->line2->points1);
            391        glEnd();
            392    }

            393    glBindTexture(GL_TEXTURE_2D,0);
            394}

            395void CSuperCube::DrawScene()
            396{
            397    glLoadIdentity();
            398    glDisable(GL_CULL_FACE);
            399    theCamera.ApplyCamera();
            400
            401    if(FaceLineRender->GetIsCheck())
            402        LineRender();
            403    else 
            404    {
            405        glEnable(GL_TEXTURE_2D); 
            406        FaceRender();
            407        //glClear(GL_DEPTH_BUFFER_BIT);
            408        glEnable(GL_DEPTH_TEST);
            409        LineRender();
            410    }

            411}

            412//--------------------------------------------------------------------------------------------------------------------------------
            413void CSuperCube::FaceSort()//冒泡排序,以中點(diǎn)為準(zhǔn),但四邊形嵌入的話.
            414{
            415    SFace *temp;
            416    Vector3 frontV=theCamera.GetPosition()*-1;
            417    Vector3 ii,jj;
            418
            419    float value1,value2;
            420    for (int i=0;i<FaceNum-1;++i)
            421    {
            422        ii.x=RenderFaces[i]->line1->points1[0]+RenderFaces[i]->line1->points2[0]+RenderFaces[i]->line2->points1[0]+RenderFaces[i]->line2->points2[0];
            423        ii.y=RenderFaces[i]->line1->points1[1]+RenderFaces[i]->line1->points2[1]+RenderFaces[i]->line2->points1[1]+RenderFaces[i]->line2->points2[1];
            424        ii.z=RenderFaces[i]->line1->points1[2]+RenderFaces[i]->line1->points2[2]+RenderFaces[i]->line2->points1[2]+RenderFaces[i]->line2->points2[2];
            425        ii=ii+frontV;
            426        value1=ii*frontV;
            427
            428
            429        for (int j=i+1;j<FaceNum-i;++j)
            430        {
            431            jj.x=RenderFaces[j]->line1->points1[0]+RenderFaces[j]->line1->points2[0]+RenderFaces[j]->line2->points1[0]+RenderFaces[j]->line2->points2[0];
            432            jj.y=RenderFaces[j]->line1->points1[1]+RenderFaces[j]->line1->points2[1]+RenderFaces[j]->line2->points1[1]+RenderFaces[j]->line2->points2[1];
            433            jj.z=RenderFaces[j]->line1->points1[2]+RenderFaces[j]->line1->points2[2]+RenderFaces[j]->line2->points1[2]+RenderFaces[j]->line2->points2[2];
            434            jj=jj+frontV;
            435            value2=jj*frontV;
            436
            437            if (value1<value2)
            438            {
            439                temp=RenderFaces[i];
            440                RenderFaces[i]=RenderFaces[j];
            441                RenderFaces[j]=temp;
            442            }

            443        }

            444    }

            445
            446}

            447//---------------------------------------------------------------------------------------------------------------------------------
            448void CSuperCube::OnKeyDown()
            449{
            450    if(CY_KeyBoard[27])
            451        PostMessage(hwnd,WM_CLOSE,0,0);
            452}

            453void CSuperCube::OnCreateBtnDown(CY_Controller *btn)
            454{
            455    const wchar_t *content=DimensionInput->GetText();
            456    int Dim=_wtoi(content);
            457    {
            458        if (Dim>=3 && Dim<=8)
            459        {
            460            if (Dim<=6 || Dim>6 && my_OpenGL_Engine->myScreenManager->Show_CYMessageBox(L"大于6的維度可能會(huì)渲染較慢,真的要試試?",true)==true)
            461            {
            462                CaculatePLF(Dim);
            463                isDone=true;
            464            }

            465        }

            466        else
            467            my_OpenGL_Engine->myScreenManager->Show_CYMessageBox(L"請(qǐng)輸入3--8的維度值",false);
            468    }

            469    
            470}

            471void CSuperCube::OnMouseWheel(const short &zDalta)
            472{
            473    theCamera.MoveFontBack(zDalta*0.0002f);
            474}

            截圖:



            posted on 2009-08-03 22:29 陳昱(CY) 閱讀(2253) 評(píng)論(9)  編輯 收藏 引用 所屬分類: 圖形學(xué)算法

            FeedBack:
            # re: 一個(gè)想法,實(shí)習(xí)n維立方體!!! (結(jié)束) 2009-08-04 08:59 canbingzt
            下載鏈接錯(cuò)誤啊  回復(fù)  更多評(píng)論
              
            # re: 一個(gè)想法,實(shí)習(xí)n維立方體!!! (結(jié)束) 2009-08-04 09:09 陳昱(CY)
            已更正,另外還有一處提示寫錯(cuò):

            主鍵盤上0控制坐標(biāo)X,1控制坐標(biāo)Y,2控制坐標(biāo)Z,3控制坐標(biāo)W,以此類推  回復(fù)  更多評(píng)論
              
            # re: 一個(gè)想法,實(shí)習(xí)n維立方體!!! (結(jié)束) 2009-08-04 09:35 mybios
            呵呵,好東西。看來(lái)要找個(gè)立體眼鏡才能看的比較舒服  回復(fù)  更多評(píng)論
              
            # re: 一個(gè)想法,實(shí)習(xí)n維立方體!!! (結(jié)束) 2009-08-04 10:49 凡客誠(chéng)品
            好東西!收藏下來(lái)哦~  回復(fù)  更多評(píng)論
              
            # re: 一個(gè)想法,實(shí)習(xí)n維立方體!!! (結(jié)束) 2009-08-04 11:17 Touchsoft
            不能控制,不能生成多于3D的。  回復(fù)  更多評(píng)論
              
            # re: 一個(gè)想法,實(shí)習(xí)n維立方體!!! (結(jié)束) 2009-08-04 11:23 99讀書人
            不錯(cuò)  回復(fù)  更多評(píng)論
              
            # re: 一個(gè)想法,實(shí)習(xí)n維立方體!!! (結(jié)束) 2009-08-05 20:21 CY
            @Touchsoft
            按住2個(gè)鍵,一個(gè)要大于Z坐標(biāo)。當(dāng)然按住2個(gè)鍵都大于Z坐標(biāo),旋轉(zhuǎn)在3D空間是看不到的  回復(fù)  更多評(píng)論
              
            # re: 一個(gè)想法,實(shí)習(xí)n維立方體!!! (結(jié)束) 2009-08-05 20:25 CY
            @mybios
            立體眼鏡對(duì)這個(gè)沒(méi)有用。

            以前畢業(yè)設(shè)計(jì)做的那個(gè)游戲,倒是有專門為紅綠立體眼鏡設(shè)計(jì)  回復(fù)  更多評(píng)論
              
            # re: 一個(gè)想法,實(shí)習(xí)n維立方體!!! (結(jié)束) 2009-09-16 20:34 小熙
            效果很好看,欣賞一下  回復(fù)  更多評(píng)論
              
            亚洲精品久久久www| 欧美日韩中文字幕久久伊人| 成人午夜精品久久久久久久小说| 久久精品国产免费观看三人同眠| 久久久综合香蕉尹人综合网| 99久久精品免费看国产一区二区三区| 久久久久人妻一区精品色| 伊人久久综合成人网| 久久人人爽人人爽人人av东京热 | 久久综合九色综合网站| 精品多毛少妇人妻AV免费久久| 人妻无码久久精品| 日本加勒比久久精品| 亚洲色欲久久久久综合网| 亚洲AⅤ优女AV综合久久久| 亚洲日本久久久午夜精品| 久久人妻无码中文字幕| 人妻丰满AV无码久久不卡| 久久精品蜜芽亚洲国产AV| 国产精品一区二区久久国产| 狠狠88综合久久久久综合网 | 亚洲乱码日产精品a级毛片久久| 色欲综合久久躁天天躁| 人妻无码αv中文字幕久久琪琪布 人妻无码精品久久亚瑟影视 | 蜜臀久久99精品久久久久久| 欧美熟妇另类久久久久久不卡 | 国产麻豆精品久久一二三| 国产精品久久久久久久久久影院| 国产精品久久久久影视不卡| 人妻系列无码专区久久五月天| 欧美久久综合性欧美| 欧美伊香蕉久久综合类网站| 久久综合给合久久狠狠狠97色69| 久久精品成人欧美大片| 久久成人国产精品免费软件| 久久久久久国产精品无码下载| 伊人久久大香线蕉成人| 香蕉久久久久久狠狠色| 久久综合九色综合网站| 国内精品人妻无码久久久影院导航| 伊人久久五月天|