• <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
            <2012年2月>
            2930311234
            567891011
            12131415161718
            19202122232425
            26272829123
            45678910

            常用鏈接

            留言簿(8)

            隨筆分類

            隨筆檔案

            好友連接

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            注意:如果需要轉載,請注明作者
            作者:陳昱(CY)



            最后一章,主要是說明一下面生成的分析,其實這里所有元素,除了0維時的第一個點外,生成都是拉伸產生的(有玩過3Dmax的朋友應該很了解那個Extrude建模,就是那樣了)

            之前在面結構定義里包含了4個點,這其實無法表達面的真正關系,面還是應該由線來表達。因為面是由線拉伸產生的,和點沒有直接的聯系。
            面的產生中,在進入2維前,都是空的,進入2維的生成后,復制了一批面,新得到的每個面的每一條邊分別對應原來每個面的第一條邊,再偏移“上一維的線的數量”這樣就完成了面的復制部分。拉伸產生的面部分,每個面的第一條邊分別是上一維度中的線,第二條邊則分別對應“從上一維度復制產生”的線,這兩條邊有復制和被復制的關系,因此,實際上這時面的4個點已經從這2條邊得到了。但是為了下一維度的復制,肯定不能不管后面的2條邊,后面的2條邊的頂點已經知道了,2條邊的第一個點都是上一維度的點,第二個點都是從上一維度復制產生的點,而這2條邊則都是從上一維度到當前維度拉伸部分產生的邊。于是找到第一條拉伸邊,再根據當前面已知的第一條邊的2個頂點分別對于第一個頂點的偏移量,就可以分別根據這個偏移量得到該面的第3、第4條邊了。

            于是到這里,每個維度的點、邊、面都是按照這樣的結構保存,非常有序,即使面結構中沒有保存頂點,也可以根據保存的邊直接確定openGL的繪畫順序。


            另外,由于需要看到高維體的內部結構,面要弄成半透明的,但是當一個高維體旋轉時,面之間會交叉重疊,因此對面的遠近排序仍然無法保證每個像素被正確混合渲染。因此,對每一個面加上一個該面的索引數,另外還加上了霧效,都是為了方便眼睛上直覺看懂。

            為了播放順暢,把維度值設在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;//維度數量
              9    int *PointsCount;
             10    int *LinesCount;
             11    int *FaceCount;
             12    //-----------------------------------------------------------
             13
             14    float Length;//邊長
             15    //-----------------------------------------------------------------------------------------
             16    bool isDone;//已經可以渲染的標志
             17
             18    float *Points;//n維空間中的點(以DimensionNum為一組為一個點坐標,PointNum為點數量,所以該float數組大小為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個點的x坐標索引為起始)
             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    //初始化各個維度的立方體中,點、線、面的數量
             53    //輸入:maxDim最大維數
             54    void InitMaxPLF(int maxDim);
             55
             56
             57    //計算Dim維度下的立方體的點、線、面
             58    void CaculatePLF(int Dim);
             59    void CaculatePHelp(int currentDim);
             60    void CaculateLHelp(int currentDim);
             61    void CaculateFHelp(int currentDim);
             62    
             63    //----------------------------------------------------------------------------------------------
             64
             65    //吉文斯矩陣旋轉,
             66    //輸入:dimNum空間維度(>=2,<=15)、point點指針、theta角度、dim1旋轉面的第一個方向、dim2旋轉面的第二個方向(值從1---15)
             67    //輸出:point點的坐標值
             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;//維度數量
             12
             13    PointsCount=0;//點數
             14    LinesCount=0;//線數
             15    FaceCount=0;//面數
             16
             17    Points=0;//n維空間中的點(以DimensionNum為一組為一個點坐標,PointNum為點數量,所以該float數組大小為DimensionNum*PointNum)
             18    DimensionNum=0;
             19    PointNum=0;
             20
             21    Lines=0;//n維空間中的線(以2個點的x坐標索引為起始)
             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"請輸入超立方體維度:",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控制坐標X,1控制坐標Y,3控制坐標Z,4控制坐標W于此類推。",10,windowHeight-60);
             42    Tips2=new CY_Label(L"按住兩個坐標鍵,即可以讓物體在這2個坐標組成的平面上旋轉,再按住shift鍵旋轉方向相反",10,windowHeight-40);
             43    Tips3=new CY_Label(L"按住鼠標鍵,移動鼠標可以從其它角度觀察,鼠標滾輪控制鏡頭遠近",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    //----------------------點計算
            127    if(currentDim==0)
            128        return;
            129    else
            130    {
            131        int targetStart=1<<(currentDim-1);//復制的起始點
            132        int targetEnd=1<<currentDim;//復制的結束點下一點
            133        for (i=targetStart;i<targetEnd;++i)
            134        {
            135            int index=DimensionNum*i;//目標點的x坐標索引
            136            int source=DimensionNum*targetStart;//來源點的x坐標索引負偏移量
            137            for (int j=0;j<currentDim-1;++j)
            138            {
            139                Points[index+j]=Points[index-source+j];//復制
            140            }

            141            Points[index+currentDim-1]=Length;//新加的維度設為邊長
            142        }

            143    }

            144}

            145void CSuperCube::CaculateLHelp(int currentDim)
            146{
            147    //---------------------------邊計算
            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        //----------------------------------------------------------復制產生的邊
            158        int targetStar=LinesCount[currentDim-1];//復制的起始邊
            159        int targetEnd=LinesCount[currentDim-1]*2;//復制的結束邊下一條邊
            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        //------------------------------------------復制部分完成,增加拉伸部分產生的邊
            166        targetStar=targetEnd;//拉伸邊存儲起始
            167        targetEnd=targetStar+(1<<(currentDim-1));//拉伸邊存儲結束的下一條邊
            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];//復制的起始面
            188        int targetEnd=FaceCount[currentDim-1]*2;//復制結束面的下一個面
            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        //-------------面復制完成,增加拉伸產生的面
            198        targetStar=targetEnd;//拉伸面存儲起始
            199        targetEnd=targetStar+LinesCount[currentDim-1];//拉伸面存儲結束的下一個面
            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            //非復制邊的起始索引:
            206            int NoCopyindex=LinesCount[currentDim]-PointsCount[currentDim];
            207            //該邊的對于非復制邊起始索引的偏移量:
            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    //-------------------------------------分配好內存空間
            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    //-------------------------------------計算值
            242    int currentDim=0;
            243    while (currentDim<=DimensionNum)
            244    {
            245        CaculatePHelp(currentDim);
            246        CaculateLHelp(currentDim);
            247        CaculateFHelp(currentDim);
            248        ++currentDim;
            249    }

            250    //-----------------------------------把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)//開始旋轉
            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()//冒泡排序,以中點為準,但四邊形嵌入的話.
            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的維度可能會渲染較慢,真的要試試?",true)==true)
            461            {
            462                CaculatePLF(Dim);
            463                isDone=true;
            464            }

            465        }

            466        else
            467            my_OpenGL_Engine->myScreenManager->Show_CYMessageBox(L"請輸入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) 閱讀(2255) 評論(9)  編輯 收藏 引用 所屬分類: 圖形學算法

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

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

            以前畢業設計做的那個游戲,倒是有專門為紅綠立體眼鏡設計  回復  更多評論
              
            # re: 一個想法,實習n維立方體!!! (結束) 2009-09-16 20:34 小熙
            效果很好看,欣賞一下  回復  更多評論
              
            亚洲AV无码久久| 久久久久久久波多野结衣高潮| 精品久久人人做人人爽综合 | 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 日韩人妻无码精品久久免费一| 精品久久一区二区| 94久久国产乱子伦精品免费| 囯产精品久久久久久久久蜜桃| 国产91久久综合| 午夜精品久久久久久影视riav| 人妻无码中文久久久久专区| 久久毛片一区二区| 久久精品午夜一区二区福利| 亚洲国产视频久久| 国产一区二区三区久久| 无码精品久久久天天影视| 久久久久亚洲爆乳少妇无| 一本色道久久综合狠狠躁| 合区精品久久久中文字幕一区 | 国产精品无码久久四虎| 97久久久精品综合88久久| 久久精品中文无码资源站| 欧美日韩中文字幕久久久不卡| 99久久精品国产毛片| 久久精品国产久精国产| 久久国产色AV免费看| 久久精品夜夜夜夜夜久久| 中文字幕日本人妻久久久免费| 亚洲国产精品一区二区三区久久| 国产精品嫩草影院久久| 国产精品无码久久久久| 国产精品狼人久久久久影院| 亚洲嫩草影院久久精品| 91麻精品国产91久久久久| 亚洲国产精品久久久久婷婷老年| 久久电影网一区| 亚洲欧洲日产国码无码久久99| 亚洲精品tv久久久久久久久 | 久久精品国产亚洲AV嫖农村妇女| 久久精品国产2020| 无码人妻久久久一区二区三区|