• <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
            <2008年3月>
            2425262728291
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345


            子曾經(jīng)曰過(guò):編程無(wú)他,唯手熟爾!

            常用鏈接

            留言簿(94)

            隨筆分類(649)

            隨筆檔案(505)

            相冊(cè)

            BCB

            Crytek

            • crymod
            • Crytek's Offical Modding Portal

            Game Industry

            OGRE

            other

            Programmers

            Qt

            WOW Stuff

            搜索

            •  

            積分與排名

            • 積分 - 914467
            • 排名 - 14

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            用到不少物理知識(shí)

            #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); // 兩個(gè)區(qū)域的或
                }
                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); // 炮管區(qū)域

            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 時(shí)間內(nèi)炮彈在x方向上行進(jìn)的距離 
                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 七星重劍 閱讀(523) 評(píng)論(0)  編輯 收藏 引用 所屬分類: PL--c/c++C++ lib -- Qt
            久久精品国产色蜜蜜麻豆| 亚洲国产一成久久精品国产成人综合| 久久综合亚洲鲁鲁五月天| 亚洲日本久久久午夜精品| 无码久久精品国产亚洲Av影片| 久久香综合精品久久伊人| 91精品国产91久久久久久青草| 久久夜色精品国产www| 久久久久亚洲av成人网人人软件| 精品久久8x国产免费观看| 久久国产成人午夜AV影院| 色诱久久久久综合网ywww| 精品久久久久久亚洲| 人妻无码精品久久亚瑟影视 | 欧美精品九九99久久在观看| 欧美黑人激情性久久| 久久久久亚洲AV无码专区网站 | 一级a性色生活片久久无少妇一级婬片免费放 | 人妻精品久久久久中文字幕69| 久久国产成人午夜aⅴ影院| 久久久久亚洲av无码专区| 久久综合久久鬼色| 亚洲一区中文字幕久久| 99精品久久精品| 欧美一区二区三区久久综合| 18禁黄久久久AAA片| 久久国产美女免费观看精品| 久久91精品国产91久久小草 | 国产精品内射久久久久欢欢| 97久久超碰成人精品网站| 亚洲精品无码久久久久久| 国产69精品久久久久APP下载| 国产AⅤ精品一区二区三区久久 | 国产成人精品三上悠亚久久| 欧美久久一区二区三区| 久久有码中文字幕| 久久免费视频6| 久久久高清免费视频| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 久久精品国产秦先生| 久久婷婷久久一区二区三区|