• <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>
            隨筆 - 505  文章 - 1034  trackbacks - 0
            <2007年11月>
            28293031123
            45678910
            11121314151617
            18192021222324
            2526272829301
            2345678


            子曾經曰過:編程無他,唯手熟爾!

            常用鏈接

            留言簿(94)

            隨筆分類(649)

            隨筆檔案(505)

            相冊

            BCB

            Crytek

            • crymod
            • Crytek's Offical Modding Portal

            Game Industry

            OGRE

            other

            Programmers

            Qt

            WOW Stuff

            搜索

            •  

            積分與排名

            • 積分 - 911346
            • 排名 - 14

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            用到不少物理知識

            #include <QPaintEvent>
            #include 
            <QPainter>
            #include 
            <QTimer>

            #include 
            <math.h>

            #include 
            "cannonfield.h"

            CannonField::CannonField(QWidget 
            *parent)
                : QWidget(parent)
            {
                currentAngle 
            = 45;
                currentForce 
            = 0;
                timerCount 
            = 0;
                autoShootTimer 
            = new QTimer(this);
                connect(autoShootTimer, SIGNAL(timeout()), 
            this, SLOT(moveShot()));
                shootAngle 
            = 0;
                shootForce 
            = 0;
                setPalette(QPalette(QColor(
            250250200)));
                setAutoFillBackground(
            true);
            }

            void CannonField::setAngle(int angle)
            {
                
            if (angle < 5)
                    angle 
            = 5;
                
            if (angle > 70)
                    angle 
            = 70;
                
            if (currentAngle == angle)
                    
            return;
                currentAngle 
            = angle;
                update(cannonRect());
                emit angleChanged(currentAngle);
            }

            void CannonField::setForce(int force)
            {
                
            if (force < 0)
                    force 
            = 0;
                
            if (currentForce == force)
                    
            return;
                currentForce 
            = force;
                emit forceChanged(currentForce);
            }

            void CannonField::shoot()
            {
                
            if (autoShootTimer->isActive())
                    
            return;
                timerCount 
            = 0;
                shootAngle 
            = currentAngle;
                shootForce 
            = currentForce;
                autoShootTimer
            ->start(5);
            }

            void CannonField::moveShot()
            {
                QRegion region 
            = shotRect();
                
            ++timerCount;

                QRect shotR 
            = shotRect();

                
            if (shotR.x() > width() || shotR.y() > height()) {
                    autoShootTimer
            ->stop();
                } 
            else {
                    region 
            = region.unite(shotR); // 兩個區域的或
                }
                update(region);
            }

            void CannonField::paintEvent(QPaintEvent * /* event */)
            {
                QPainter painter(
            this);

                paintCannon(painter);
                
            if (autoShootTimer->isActive())
                    paintShot(painter);
            }

            void CannonField::paintShot(QPainter &painter)
            {
                painter.setPen(Qt::NoPen);
                painter.setBrush(Qt::black);
                painter.drawRect(shotRect());
            }

            const QRect barrelRect(30-52010); // 炮管區域

            void CannonField::paintCannon(QPainter &painter)
            {
                painter.setPen(Qt::NoPen);
                painter.setBrush(Qt::blue);

                painter.save();
                painter.translate(
            0, height());
                painter.drawPie(QRect(
            -35-357070), 090 * 16);
                painter.rotate(
            -currentAngle);
                painter.drawRect(barrelRect);
                painter.restore();
            }

            QRect CannonField::cannonRect() 
            const
            {
                QRect result(
            005050);
                result.moveBottomLeft(rect().bottomLeft());
                
            return result;
            }

            QRect CannonField::shotRect() 
            const
            {
                
            const double gravity = 4// 重力加速度

                
            double time = timerCount / 20.0;
                
            double velocity = shootForce; // 速度
                double radians = shootAngle * 3.14159265 / 180// 弧度

                
            double velx = velocity * cos(radians); // x 方向速度
                double vely = velocity * sin(radians); // y  方向速度
                double x0 = (barrelRect.right() + 5* cos(radians); // 炮彈初始位置 x
                double y0 = (barrelRect.right() + 5* sin(radians); // 炮彈初始位置 y
                double x = x0 + velx * time; // velx * time 為 time 時間內炮彈在x方向上行進的距離 
                double y = y0 + vely * time - 0.5 * gravity * time * time; // 公式 s = vt - 0.5* g * t * t

                QRect result(
            0066); // 炮彈的大小
                result.moveCenter( QPoint( qRound(x), height() - 1 - qRound(y) ) );
                
            return result;
            }
            posted on 2007-07-23 01:40 七星重劍 閱讀(519) 評論(0)  編輯 收藏 引用 所屬分類: PL--c/c++C++ lib -- Qt
            久久频这里精品99香蕉久| 久久国产热精品波多野结衣AV| 国产精品久久久久久| 超级碰久久免费公开视频| 久久国产影院| 久久久无码精品亚洲日韩京东传媒 | 久久久免费精品re6| 国产精品视频久久| 久久亚洲AV无码精品色午夜麻豆| 久久久一本精品99久久精品66| 欧美久久精品一级c片片| 久久精品国产亚洲AV忘忧草18 | 久久综合给合久久狠狠狠97色69| 99久久777色| 久久精品国产99久久久古代| 久久香蕉国产线看观看99| 久久久久久久久波多野高潮| 99久久精品免费看国产免费| 亚洲中文字幕无码久久精品1| 精品久久久久国产免费| 久久久久99精品成人片欧美| 久久综合久久伊人| 欧美亚洲另类久久综合| 久久九九精品99国产精品| 亚洲国产视频久久| 久久久精品久久久久久| 一本久久a久久精品综合夜夜 | 99久久久国产精品免费无卡顿| 国产精品久久婷婷六月丁香| 欧美精品丝袜久久久中文字幕| 亚洲国产成人久久综合碰碰动漫3d| 无码人妻久久一区二区三区免费丨 | 久久亚洲AV无码西西人体| 国产福利电影一区二区三区,免费久久久久久久精 | 老色鬼久久亚洲AV综合| 亚洲国产精品成人久久| 久久综合亚洲鲁鲁五月天| 91麻豆国产精品91久久久| 最新久久免费视频| 久久久久高潮综合影院| 伊人久久精品无码av一区|