亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? cpolygonobject.cpp

?? 一個基于symbian s60 3rd 的3D汽車游戲演示程序,模擬器上編譯通過。
?? CPP
字號:
   /*
============================================================================
    * Name : CPolygonObject.cpp
    * Part of : Example3D
    * Description : Definition of CPolygonObject
    * Copyright (c) 2007 Nokia Corporation
============================================================================
    */

// INCLUDES
#include "CPolygonObject.h"
#include <e32math.h>
#include <e32svr.h>     // for debug prints

// CONSTANTS
const TUint KInvalidTextureObject = 0xffffffff;

// MEMBER FUNCTIONS

CPolygonObject* CPolygonObject::NewL( C3DBase* a3DBase, TInt aNumVertices, TInt aNumFaces )
    {
    CPolygonObject* self = new( ELeave )CPolygonObject( a3DBase, aNumVertices, aNumFaces );
    CleanupStack::PushL( self );
    self->ConstructL();
    CleanupStack::Pop( self );
    return self;
    }

CPolygonObject::~CPolygonObject()
    {
    delete[] iFace;
    delete[] iVertex;
    delete[] iRVertex;

    delete[] iDrawList;
    delete[] iFaceZ;
    delete[] iFaceN;
    delete[] iGlVerts;
    delete[] iGlTexCoords;
    delete[] iGlTris;
    if( iTextureObject != KInvalidTextureObject )
        {
        glDeleteTextures( 1, &iTextureObject );
        }
    }

CPolygonObject::CPolygonObject( C3DBase* a3DBase, TInt aNumVertices, TInt aNumFaces )
    : i3DBase( a3DBase )
    , iMaxNumVertices( aNumVertices )
    , iMaxNumFaces( aNumFaces )
    {
    }

void CPolygonObject::ConstructL()
    {
    iFace = new( ELeave )TFace[ iMaxNumFaces ];
    iVertex = new( ELeave )TVertex[ iMaxNumVertices ];
    iRVertex = new( ELeave )TVertex[ iMaxNumVertices ];

    iCos = i3DBase->CosTable();
    iSin = i3DBase->SinTable();

    iFaceN = new( ELeave )TInt[ iMaxNumFaces ];
    iFaceZ = new( ELeave )TInt[ iMaxNumFaces ];
    iDrawList = new( ELeave )TDrawFace[ iMaxNumFaces ];

    // OpenGl texture object handle
    // valid texture handle is '0'
    // so set the handle as KInvalidTextureObject here.
    iTextureObject = KInvalidTextureObject;
    }

void CPolygonObject::Draw( const TBitmap& aScreen, TMatrix* aRotateMatrix )
    {
    // Here the drawing is done with OpenGl ES
    // We are using Z-buffered draw with opengl
    // so we don't need to sort the polygons

    const TInt glShift = 16;

    // shift adjustor
    // OpenGl uses 16-bit decimals
    // and this example uses KShift-bit decimals
    // this is the difference to convert values to same decimal depth
    const TInt shift = glShift - KShift;
    const TInt mul = 1 << shift;

    glMatrixMode    (GL_MODELVIEW);
    
    // Generate rotate matrix for OpenGl from example's rotate matrix
    GLfixed mat[4*4]={ (*aRotateMatrix)[0]*mul, -(*aRotateMatrix)[4]*mul, -(*aRotateMatrix)[ 8]*mul, 0,
                       (*aRotateMatrix)[1]*mul, -(*aRotateMatrix)[5]*mul, -(*aRotateMatrix)[ 9]*mul, 0,
                       (*aRotateMatrix)[2]*mul, -(*aRotateMatrix)[6]*mul, -(*aRotateMatrix)[10]*mul, 0,
                       (*aRotateMatrix)[3]*mul, -(*aRotateMatrix)[7]*mul, -(*aRotateMatrix)[11]*mul, 1 << glShift };
    
    // Init OpenGl for drawing
    glLoadMatrixx( mat );
    
    glEnableClientState( GL_VERTEX_ARRAY );
    glVertexPointer( 3, GL_FIXED, 0, iGlVerts );
    
    if( iTextureObject != KInvalidTextureObject )
        {
        glBindTexture( GL_TEXTURE_2D, iTextureObject );
        glEnable( GL_TEXTURE_2D );
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
        glTexCoordPointer( 2, GL_FIXED, 0, iGlTexCoords );
        }
    else
        {
        glDisable( GL_TEXTURE_2D );
        glDisableClientState ( GL_TEXTURE_COORD_ARRAY );
        }
    glColor4x( 1<<glShift, 1<<glShift, 1<<glShift, 1<<glShift );
    glDrawElements( GL_TRIANGLES, iGlTriCount, GL_UNSIGNED_SHORT, iGlTris );

    // This isn't really accurate number of polygons drawn
    // but number of polygons feeded to OpenGL drawing pipeline
    // some of the polygons are backface culled off etc.
    i3DBase->AddPolygonCount( iGlTriCount );
    }

// OpenGl uses it's own texture handles
void CPolygonObject::SetTexture( TInt aTextureObjectHandle )
    {
    iTextureObject = aTextureObjectHandle;
    }

void CPolygonObject::Reset( TInt aNumVertices, TInt aNumFaces )
    {
    iMaxNumVertices = aNumVertices;
    iMaxNumFaces = aNumFaces;

    delete[] iFace;
    iFace = new( ELeave )TFace[ iMaxNumFaces ];
    iNumFaces = 0;
    
    delete[] iVertex;
    iVertex = new( ELeave )TVertex[ iMaxNumVertices ];
    
    delete[] iRVertex;
    iRVertex = new( ELeave )TVertex[ iMaxNumVertices ];
    iNumVertices = 0;

    delete[] iFaceN;
    iFaceN = new( ELeave )TInt[ iMaxNumFaces ];

    delete[] iFaceZ;
    iFaceZ = new( ELeave )TInt[ iMaxNumFaces ];

    delete[] iDrawList;
    iDrawList = new( ELeave )TDrawFace[ iMaxNumFaces ];
    }

TInt CPolygonObject::AddVertex( const TVertex& aVertex )
    {
    __ASSERT_DEBUG( iNumVertices < iMaxNumVertices, User::Panic( _L("Too many vertices"), iNumVertices ) );

    iVertex[ iNumVertices++ ] = aVertex;
    return iNumVertices-1;
    }

void CPolygonObject::SetVertex( TInt aIndex, const TVertex& aVertex )
    {
    __ASSERT_DEBUG( aIndex < iNumVertices, User::Panic( _L("Illegal vertex index"), aIndex ) );
    iVertex[ aIndex ] = aVertex;
    }

TInt CPolygonObject::AddFace( const TFace& aFace )
    {
    __ASSERT_DEBUG( iNumFaces < iMaxNumFaces, User::Panic( _L("Too many faces"), iNumFaces ) );

    iFace[ iNumFaces++ ] = aFace;
    return iNumFaces;
    }

void CPolygonObject::Init()
    {
    //
    // Calculate bounding radius for object clipping
    //
    TInt r = 0;

    TInt i;
    for( i=0; i<iNumVertices; i++ )
        {
        TVertex& v = iVertex[ i ];
        TInt r2 = v.iX * v.iX + v.iY * v.iY + v.iZ * v.iZ;
        if( r2 > r ) r = r2;
        }
    TReal ra;
    Math::Sqrt( ra, r );
    iBoundingRadius = ( TInt )ra;

    // if using OpenGL ES, convert vertices and faces
    // to opengl world

    delete[] iGlVerts;
    delete[] iGlTexCoords;
    delete[] iGlTris;
    
    iGlTriCount = iNumFaces*3;
    iGlVerts=new GLfixed[ iGlTriCount*3];
    iGlTexCoords=new GLfixed[ iGlTriCount*2 ];
    iGlTris=new GLushort[ iGlTriCount ];

    TInt ic=0;
    TInt vc=0;

    const TInt textureSize = 256;
    const TInt GlShift = 16;
    const TInt shift = GlShift - KShift;

    for (i=0;i<iNumFaces;i++)
        {
        int a,b,c;
        a=iFace[i].iV1;
        b=iFace[i].iV2;
        c=iFace[i].iV3;

        iGlVerts[vc*3] = iVertex[a].iX << shift;
        iGlVerts[vc*3+1] = iVertex[a].iY << shift;
        iGlVerts[vc*3+2] = iVertex[a].iZ << shift;

        iGlTexCoords[vc*2] = ( iFace[i].iTx1 << GlShift ) / textureSize;
        iGlTexCoords[vc*2+1] = ( iFace[i].iTy1 << GlShift ) / textureSize;
        iGlTris[ic] = (GLushort)vc;
        ic++;   
        vc++;

        iGlVerts[vc*3] = iVertex[b].iX << shift;
        iGlVerts[vc*3+1] = iVertex[b].iY << shift;
        iGlVerts[vc*3+2] = iVertex[b].iZ << shift;
        iGlTexCoords[vc*2] = ( iFace[i].iTx2 << GlShift ) / textureSize;
        iGlTexCoords[vc*2+1] = ( iFace[i].iTy2 << GlShift ) / textureSize;
        iGlTris[ic] = (GLushort)vc;
        ic++;
        vc++;

        iGlVerts[vc*3] = iVertex[c].iX << shift;
        iGlVerts[vc*3+1] = iVertex[c].iY << shift;
        iGlVerts[vc*3+2] = iVertex[c].iZ << shift;
        iGlTexCoords[vc*2] = ( iFace[i].iTx3 << GlShift) / textureSize;
        iGlTexCoords[vc*2+1] = ( iFace[i].iTy3 << GlShift) / textureSize;
        iGlTris[ic] = (GLushort)vc;
        ic++;
        vc++;       
        }
    }

void CPolygonObject::Rotate()
    {
    // multiply all vertices by rotate matrix
    // rotate matrix is calculated by C3DRenderer

    for( TInt i=0; i<iNumVertices; i++ )
        {
        iRVertex[ i ] = iVertex[ i ];
        iRVertex[ i ].MulMatrix( iRotateMatrix );
        }
    }

void CPolygonObject::Project( TDrawFace* aFaceList, TInt aNumFaces )
    {
    const TInt mul = 512;
    TInt i;
    TInt mx = iScreen.iSize.iWidth / 2;
    TInt my = iScreen.iSize.iHeight / 2;
    
    for( i=0; i<aNumFaces; i++ )
        {
        TDrawFace& f = aFaceList[ i ];
        
        f.iV1.iX = f.iV1.iX * mul / f.iV1.iZ + mx;
        f.iV1.iY = f.iV1.iY * mul / f.iV1.iZ + my;
        f.iV2.iX = f.iV2.iX * mul / f.iV2.iZ + mx;
        f.iV2.iY = f.iV2.iY * mul / f.iV2.iZ + my;
        f.iV3.iX = f.iV3.iX * mul / f.iV3.iZ + mx;
        f.iV3.iY = f.iV3.iY * mul / f.iV3.iZ + my;      
        }
    }

inline void CPolygonObject::Swap( TAny* aV1, TAny* aV2 )
    {
    TUint32 temp = *(TUint32*)aV1;
    *(TUint32*)aV1 = *(TUint32*)aV2;
    *(TUint32*)aV2 = temp;
    }

    // disable warning of local variable may be used without initialized
    // these variables are always initialized but compiler doesn't know it.
#pragma warning( disable : 4701 )

void CPolygonObject::DrawTexTri( TDrawVertex* aV1, TDrawVertex* aV2, TDrawVertex* aV3 )
    {
    TInt d = ( aV1->iX - aV3->iX ) * ( aV2->iY - aV3->iY ) -
             ( aV2->iX - aV3->iX ) * ( aV1->iY - aV3->iY );
    
    if( d <= 0 ) return;

    TInt id = ( 1 << 24 ) / d;

    TInt dudx = ( ( aV1->iTx - aV3->iTx ) * ( aV2->iY - aV3->iY ) -
                  ( aV2->iTx - aV3->iTx ) * ( aV1->iY - aV3->iY ) ) * id / ( 1 << 16 );

    TInt dvdx = ( ( aV1->iTy - aV3->iTy ) * ( aV2->iY - aV3->iY ) -
                  ( aV2->iTy - aV3->iTy ) * ( aV1->iY - aV3->iY ) ) * id / ( 1 << 16 );
    
    if( aV1->iY > aV2->iY ) { Swap( &aV1, &aV2 ); d = -d; }
    if( aV2->iY > aV3->iY ) { Swap( &aV2, &aV3 ); d = -d; }
    if( aV1->iY > aV2->iY ) { Swap( &aV1, &aV2 ); d = -d; }
    
    TInt h1 = ( aV2->iY - aV1->iY );
    TInt h2 = ( aV3->iY - aV2->iY );
    TInt h3 = ( aV3->iY - aV1->iY );

    if( h3 == 0 ) return;

    TInt h1i = 0;
    if( h1 ) h1i = 65536 / h1; 
    TInt h2i = 0;
    if( h2 ) h2i = 65536 / h2; 
    TInt h3i = 65536 / h3;

    TInt y = aV1->iY;

    TInt x1, x2;
    TInt x1a, x2a;
    TInt txya;
    TInt tyya;
    TInt otx;
    TInt oty;
    
    for( ;; )
        {

        //
        // First half:
        //
        if( y==aV1->iY )
            {
            x1 = 256 * aV1->iX;
            x2 = x1;
            if( d > 0 ) // long side left
                {
                x1a = h3i * ( aV3->iX - aV1->iX ) >> 8;
                x2a = h1i * ( aV2->iX - aV1->iX ) >> 8;

                txya = h3i * ( aV3->iTx - aV1->iTx ) >> 8;
                tyya = h3i * ( aV3->iTy - aV1->iTy ) >> 8;
                otx = aV1->iTx << 8;
                oty = aV1->iTy << 8;
                }
            else        // long side right
                {
                x1a = h1i * ( aV2->iX - aV1->iX ) >> 8;
                x2a = h3i * ( aV3->iX - aV1->iX ) >> 8;
                txya = h1i * ( aV2->iTx - aV1->iTx ) >> 8;
                tyya = h1i * ( aV2->iTy - aV1->iTy ) >> 8;
                otx = aV1->iTx << 8;
                oty = aV1->iTy << 8;
                }

            }

        //
        // Second half:
        //
        if( y==aV2->iY )
            {
            if( d > 0 ) // long side left
                {
                x1a = h3i * ( aV3->iX - aV1->iX ) >> 8;
                x2a = h2i * ( aV3->iX - aV2->iX ) >> 8;
                x1 = 256 * aV1->iX + x1a * h1;
                x2 = 256 * aV2->iX;

                txya = h3i * ( aV3->iTx - aV1->iTx ) >> 8;
                tyya = h3i * ( aV3->iTy - aV1->iTy ) >> 8;
                otx = 256 * aV1->iTx + txya * h1;
                oty = 256 * aV1->iTy + tyya * h1;
                }
            else        // long side right
                {
                x1a = h2i * ( aV3->iX - aV2->iX ) >> 8;
                x2a = h3i * ( aV3->iX - aV1->iX ) >> 8;
                x1 = 256 * aV2->iX;
                x2 = 256 * aV1->iX + x2a * h1;

                txya = h2i * ( aV3->iTx - aV2->iTx ) >> 8;
                tyya = h2i * ( aV3->iTy - aV2->iTy ) >> 8;
                otx = 256 * aV2->iTx;
                oty = 256 * aV2->iTy;
                }
            }

        //
        // End of polygon
        //
        if( y==aV3->iY )
            {
            break;
            }
        
        // Left edge pointer
        TUint16* p = (TUint16*)iScreen.iData + y * iScreen.iSize.iWidth;

        // Right edge pointer
        TUint16* p2 = p + ( x2 >> 8 );
        p += x1 >> 8;

        TInt tx = otx;
        TInt ty = oty;
        
        // scanline filler
        register TUint16* sp = iTexture;
        register TInt txa = dudx;
        register TInt tya = dvdx;
        while( p <= p2 )
            {
            *p++ = sp[ ( tx >> 8 ) + ( ty & 0xff00 ) ];
            tx += txa;
            ty += tya;
            }

        x1 += x1a;
        x2 += x2a;
        otx += txya;
        oty += tyya;
        y++;
        }
    }

    // enable warning "local variable may be used without initialized"
#pragma warning( default : 4701 )

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩国产欧美三级| 成人h动漫精品一区二区| 国产一区二区中文字幕| 色狠狠桃花综合| 久久九九久精品国产免费直播| 亚洲日本欧美天堂| 国产精品综合网| 欧美丰满嫩嫩电影| 亚洲欧美日韩国产综合在线| 久久99热这里只有精品| 欧美性生活影院| **性色生活片久久毛片| 精品综合免费视频观看| 欧美日韩国产首页| 一区二区三区四区亚洲| www.欧美色图| 国产精品不卡一区二区三区| 国产麻豆精品视频| 久久网这里都是精品| 性久久久久久久久| 久久嫩草精品久久久精品| 午夜精品视频在线观看| 欧美日韩一卡二卡三卡| 一区二区在线免费| 色视频成人在线观看免| 亚洲欧美电影院| 色综合色狠狠天天综合色| 中文字幕亚洲欧美在线不卡| 成人av网站大全| 国产精品美女久久久久久久| 成人福利视频网站| 亚洲欧美影音先锋| 日本道在线观看一区二区| 亚洲日本在线观看| 欧美亚洲高清一区| 一区二区三区欧美| 欧美日韩国产美| 日韩电影在线一区| 欧美va在线播放| 色综合色综合色综合色综合色综合| 久久奇米777| 国产成人精品综合在线观看 | 99久久综合99久久综合网站| 久久久精品国产免大香伊| 国产91富婆露脸刺激对白| 国产欧美一区二区在线| 成人激情文学综合网| 国产肉丝袜一区二区| 99久久久国产精品| 亚洲一区二区三区四区不卡| 欧美一级片在线观看| 久久99精品国产.久久久久| 日韩欧美国产综合一区 | 欧美电影免费观看高清完整版在线观看 | 日本欧美一区二区| 精品国产精品网麻豆系列| 成人视屏免费看| 亚洲一区二区三区四区五区黄 | 日韩精品免费专区| 久久无码av三级| 色香色香欲天天天影视综合网| 亚洲免费三区一区二区| 7777精品伊人久久久大香线蕉 | 日韩欧美国产一区在线观看| 国产乱子伦视频一区二区三区| 国产精品三级av| 欧美久久久久久久久中文字幕| 狂野欧美性猛交blacked| 国产精品毛片久久久久久久| 欧美日韩一区二区在线视频| 激情综合色播激情啊| 一区二区三区中文字幕精品精品 | 国内精品伊人久久久久av一坑| 国产精品美女久久福利网站| 538在线一区二区精品国产| 国产成人精品亚洲777人妖| 亚洲免费av在线| 久久中文娱乐网| 欧美色欧美亚洲另类二区| 国产毛片精品视频| 日韩专区中文字幕一区二区| 日本一区二区电影| 日韩精品一区二区三区老鸭窝| 一本久久a久久免费精品不卡| 日韩av一级电影| 亚洲精品欧美综合四区| 国产欧美日韩视频在线观看| 欧美精三区欧美精三区| 成人av电影免费观看| 色吊一区二区三区| 国产一区二区三区精品欧美日韩一区二区三区 | 不卡的看片网站| 精品一区二区三区不卡| 亚洲成人中文在线| 亚洲欧美欧美一区二区三区| 久久久久国产精品厨房| 91精品国产综合久久久蜜臀图片| 91蝌蚪porny九色| 豆国产96在线|亚洲| 精品一区二区三区免费播放| 午夜精品久久久久久久99水蜜桃| 亚洲精品国产无天堂网2021| 中文字幕不卡三区| 国产区在线观看成人精品| 精品欧美久久久| 欧美一区二区人人喊爽| 欧美人动与zoxxxx乱| 欧美日韩精品免费观看视频| 在线观看亚洲精品| 日本精品视频一区二区三区| 99精品欧美一区| voyeur盗摄精品| 99国产精品视频免费观看| 国产成人精品免费网站| 国产精品亚洲午夜一区二区三区| 精品在线视频一区| 激情综合色综合久久| 国产在线精品不卡| 国产成人精品免费网站| 福利一区二区在线观看| www.爱久久.com| 色94色欧美sute亚洲13| 欧美综合在线视频| 欧美日本在线播放| 欧美不卡一区二区三区四区| 2欧美一区二区三区在线观看视频 337p粉嫩大胆噜噜噜噜噜91av | 成人免费视频caoporn| 成人av资源在线观看| 91在线观看视频| 欧美午夜免费电影| 日韩一区二区在线看片| 26uuu国产电影一区二区| 国产人伦精品一区二区| 亚洲久本草在线中文字幕| 亚洲福利视频一区二区| 日本中文在线一区| 国产激情一区二区三区四区 | 欧美伦理影视网| 日韩美女主播在线视频一区二区三区| 日韩免费电影网站| 国产精品久久国产精麻豆99网站| 亚洲精品美腿丝袜| 日韩成人精品在线| 国产91丝袜在线播放0| 91视视频在线直接观看在线看网页在线看 | 亚洲男人的天堂在线aⅴ视频| 亚洲一区二区三区美女| 精品亚洲成av人在线观看| av不卡一区二区三区| 欧美老肥妇做.爰bbww| 久久色.com| 亚洲一区中文在线| 国产精品一线二线三线| 91蜜桃网址入口| 日韩视频在线永久播放| 18涩涩午夜精品.www| 日韩激情av在线| 成人国产一区二区三区精品| 欧美男女性生活在线直播观看| 精品少妇一区二区三区在线播放| 最新不卡av在线| 另类小说图片综合网| 色综合久久中文综合久久97| 精品国产99国产精品| 一区二区免费视频| 粉嫩av亚洲一区二区图片| 欧美久久久久久久久| 亚洲免费在线观看视频| 国产九九视频一区二区三区| 69堂成人精品免费视频| ...xxx性欧美| 国产成人亚洲精品狼色在线| 欧美精品电影在线播放| 伊人色综合久久天天人手人婷| 国产91丝袜在线18| 欧美哺乳videos| 亚洲在线观看免费| 99久久久国产精品| 久久精品综合网| 国内成+人亚洲+欧美+综合在线| 在线观看91精品国产入口| 日本一区二区三区在线不卡 | 亚洲成a人片在线不卡一二三区| 国产成人鲁色资源国产91色综| 欧美一卡在线观看| 亚洲综合一二区| 91网站在线观看视频| 国产精品网站一区| 国产精品一区免费在线观看| 欧美xxxxxxxxx| 免费欧美在线视频| 91超碰这里只有精品国产| 亚洲午夜电影网| 欧美天天综合网| 亚洲国产日韩a在线播放| 在线视频欧美区| 亚洲激情欧美激情| 欧美做爰猛烈大尺度电影无法无天| 亚洲特黄一级片| 91网站视频在线观看|