<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

        jMonkeyEngine譯文FlagRush6(2)控制交通工具

        來源:懂視網(wǎng) 責(zé)編:小采 時間:2020-11-09 07:43:01
        文檔

        jMonkeyEngine譯文FlagRush6(2)控制交通工具

        jMonkeyEngine譯文FlagRush6(2)控制交通工具:天氣有點(diǎn)冷,早上竟然出奇般的七點(diǎn)多就起床了,呵呵~~ 6.4 、 Actions 在第五課,我們創(chuàng)建一個 InputHandler ,它調(diào)用了 4 個分開的 InputAction : KeyNodeForwardAction , KeyNodeBackwardAction , KeyTurnLeftActi
        推薦度:
        導(dǎo)讀jMonkeyEngine譯文FlagRush6(2)控制交通工具:天氣有點(diǎn)冷,早上竟然出奇般的七點(diǎn)多就起床了,呵呵~~ 6.4 、 Actions 在第五課,我們創(chuàng)建一個 InputHandler ,它調(diào)用了 4 個分開的 InputAction : KeyNodeForwardAction , KeyNodeBackwardAction , KeyTurnLeftActi

        天氣有點(diǎn)冷,早上竟然出奇般的七點(diǎn)多就起床了,呵呵~~ 6.4 、 Actions 在第五課,我們創(chuàng)建一個 InputHandler ,它調(diào)用了 4 個分開的 InputAction : KeyNodeForwardAction , KeyNodeBackwardAction , KeyTurnLeftAction , KeyTurnRightAction 。我們現(xiàn)

        天氣有點(diǎn)冷,早上竟然出奇般的七點(diǎn)多就起床了,呵呵~~

        6.4、Actions

        在第五課,我們創(chuàng)建一個InputHandler,它調(diào)用了4個分開的InputAction:KeyNodeForwardAction,KeyNodeBackwardAction,KeyTurnLeftAction,KeyTurnRightAction。我們現(xiàn)在將編寫我們自定義的Action去使用新的Vehicle類。

        首先,我們想用一個加速vehicle的action替換KeyNodeForwardAction。我決定創(chuàng)建5個新的InputAction(比之前多了一個)。所以,為了替換keyNodeForwardAction,我們將創(chuàng)建AccelerateAction。

        我們不再需要關(guān)心action的速度,因為這是由vehicle決定的。我們只需要在action執(zhí)行的時候更新它的速度,然后基于這個新的速度移動vehicle。

        publicvoid performAction(InputActionEvent e) {

        node.accerate(e.getTime());

        Vector3f loc = node.getLocalTranslation();

        loc.addLocal(

        node.getLocalRotation().getRotationColumn(2,tempVa)

        .multLocal(node.getVelocity()*e.getTime())

        );

        node.setLocalTranslation(loc);

        }

        正如你看到的,我們僅僅調(diào)用Vehicle的accelerate方法(AccelerateAction也在構(gòu)造期間接收一個Vehicle對象,而不是Node),然后改變它的移動。

        BrakeAction也一樣,除了我們叫它brake之外。

        publicvoid performAction(InputActionEvent e) {

        node.brake(e.getTime());

        Vector3f loc = node.getLocalTranslation();

        loc.addLocal(

        node.getLocalRotation().getRotationColumn(2,tempVa)

        .multLocal(node.getVelocity()*e.getTime())

        );

        node.setLocalTranslation(loc);

        }

        這些action現(xiàn)在將允許我們加速和停止vehicle。現(xiàn)在我們需要允許它轉(zhuǎn)彎。正如你可能猜到它和KeyNodeTurn*Action類是一樣的,除了我們使用Vehicle的轉(zhuǎn)彎速度代替action的速度。一點(diǎn)不同的是我加入了判斷我們的速度是正的還是負(fù)的。如果它是正的,那么我們正常工作,但如果它是負(fù)的,Vehicle正在后退,所以轉(zhuǎn)彎的效果將相反。

        publicvoid performAction(InputActionEvent evt) {

        //我們想轉(zhuǎn)不同的方向,這取決于我們往哪個方向行駛

        if(vehicle.getVelocity() < 0) {

        incr.fromAngleNormalAxis(

        -vehicle.getTurnSpeed() * evt.getTime()

        , upAxis

        );

        } else {

        incr.fromAngleNormalAxis(

        vehicle.getTurnSpeed() * evt.getTime(),

        upAxis

        );

        }

        vehicle.getLocalRotation().fromRotationMatrix(

        incr.mult(

        vehicle.getLocalRotation()

        .toRotationMatrix(tempMa),

        tempMb

        )

        );

        vehicle.getLocalRotation().normalize();

        }

        publicvoid performAction(InputActionEvent evt) {

        if (vehicle.getVelocity() < 0) {

        incr.fromAngleNormalAxis(

        vehicle.getTurnSpeed() * evt.getTime(),

        upAxis

        );

        } else {

        incr.fromAngleNormalAxis(

        -vehicle.getTurnSpeed() * evt.getTime(),

        upAxis

        );

        }

        vehicle.getLocalRotation().fromRotationMatrix(

        incr.mult(

        vehicle.getLocalRotation()

        .toRotationMatrix(tempMa),

        tempMb

        )

        );

        vehicle.getLocalRotation().normalize();

        }

        我們最后的InputAction將處理vehicle的漂移。這個action是不同的,因為它不會由key觸發(fā),但在每次update都發(fā)生。這將在下一節(jié)講到。現(xiàn)在,我們調(diào)用Vehicle的drift方法并更新位置。

        publicvoid performAction(InputActionEvent evt) {

        vehicle.drift(evt.getTime());

        Vector3f loc = vehicle.getLocalTranslation();

        loc.addLocal(

        vehicle.getLocalRotation()

        .getRotationColumn(2, tempVa)

        .multLocal(

        vehicle.getVelocity() * evt.getTime()

        )

        );

        vehicle.setLocalTranslation(loc);

        }

        你可能注意到一堆重復(fù)的代碼。相當(dāng)于大多類都做相同的事情,只是調(diào)用vehicle不同的方法。下一節(jié),我們將清理并優(yōu)化。

        既然我們現(xiàn)在已經(jīng)有了我們5個新的aciton,我們需要在FlagRushHandler中調(diào)用它們。我們將賦予相同的鍵(WASD)。

        所以在setActions方法中我們只是創(chuàng)建4個移動action,傳入vehicle對象作為參數(shù)。

        Drift也被實例化而并沒有賦給一個觸發(fā)器。這是因為我們現(xiàn)在覆蓋了update方法。update調(diào)用super去檢查其他常規(guī)action,然后調(diào)用drift action。這確保了當(dāng)沒有鍵被按下時drift漂移。然而,這個邏輯有點(diǎn)瑕疵,這就給讀者作為練習(xí)去弄清那是什么。一點(diǎn)暗示,當(dāng)玩家按下W或S的時候發(fā)生了什么?我將在下一節(jié)課修復(fù)和討論這個瑕疵。是的,我現(xiàn)在給出作業(yè)了。

        6.5、FlagRushHandler.java

        import lesson6.actions.AccelerateAction;

        import lesson6.actions.DriftAction;

        import lesson6.actions.VehicleRotateLeftAction;

        import com.jme.input.InputHandler;

        import com.jme.input.KeyBindingManager;

        import com.jme.input.KeyInput;

        import com.jme.input.action.KeyNodeBackwardAction;

        import com.jme.input.action.KeyNodeRotateRightAction;

        /**

        * 游戲的InputHnadler。這控制了一個給出的Spatial

        * 允許我們?nèi)グ阉耙啤⑼笠坪妥笥倚D(zhuǎn)。

        * @author John

        *

        */

        publicclass FlagRushInputHandler extends InputHandler {

        private DriftAction drift;

        /**

        * 提供用于控制的node。api將處理input的創(chuàng)建

        * @param node 我們想移動的那個node

        * @param api library將處理input的創(chuàng)建

        */

        public FlagRushInputHandler(Vehicle node, String api){

        setKeyBindings(api);

        setActions(node);

        }

        /**

        * 將action類賦給trigger。這些action處理結(jié)點(diǎn)前移、后移和旋轉(zhuǎn)

        * @param node 用于控制的結(jié)點(diǎn)

        */

        privatevoid setActions(Vehicle node) {

        AccelerateAction forward =

        new AccelerateAction(node);

        addAction(forward,"forward",true);

        KeyNodeBackwardAction backward =

        new KeyNodeBackwardAction(node,15f);

        addAction(backward,"backward",true);

        VehicleRotateLeftAction rotateLeft =

        new VehicleRotateLeftAction(node);

        addAction(rotateLeft,"turnLeft",true);

        KeyNodeRotateRightAction rotateRight =

        new KeyNodeRotateRightAction(node,5f);

        rotateRight.setLockAxis(

        node.getLocalRotation().getRotationColumn(1)

        );

        addAction(rotateRight,"turnRight",true);

        //不由key觸發(fā)

        drift = new DriftAction(node);

        }

        /**

        * 創(chuàng)建keyboard對象,當(dāng)鍵被按下時允許我們獲取鍵盤的值。

        * 它接著設(shè)置action作為觸發(fā)器的基礎(chǔ),如果確認(rèn)了鍵被按下(WASD)

        * @param api

        */

        privatevoid setKeyBindings(String api) {

        KeyBindingManager keyboard =

        KeyBindingManager.getKeyBindingManager();

        keyboard.set("forward", KeyInput.KEY_W);

        keyboard.set("backward", KeyInput.KEY_S);

        keyboard.set("turnLeft", KeyInput.KEY_A);

        keyboard.set("turnRight", KeyInput.KEY_D);

        }

        @Override

        publicvoid update(float time) {

        if(!isEnabled()) return;

        super.update(time);

        //我們通常想讓摩擦力控制漂移

        drift.performAction(event);

        }

        }

        6.6、AccelerateAction.java

        import lesson6.Vehicle;

        import com.jme.input.action.InputAction;

        import com.jme.input.action.InputActionEvent;

        import com.jme.math.Vector3f;

        publicclass AccelerateAction extends InputAction {

        private Vehicle node;

        private Vector3f tempVa=new Vector3f();

        public AccelerateAction(Vehicle node){

        this.node = node;

        }

        @Override

        publicvoid performAction(InputActionEvent e) {

        node.accerate(e.getTime());

        Vector3f loc = node.getLocalTranslation();

        loc.addLocal(

        node.getLocalRotation().getRotationColumn(2,tempVa)

        .multLocal(node.getVelocity()*e.getTime())

        );

        node.setLocalTranslation(loc);

        }

        }

        6.7、BrakeAction.java

        import lesson6.Vehicle;

        import com.jme.input.action.InputAction;

        import com.jme.input.action.InputActionEvent;

        import com.jme.math.Vector3f;

        publicclass BrakeAction extends InputAction {

        private Vehicle node;

        private Vector3f tempVa=new Vector3f();

        public BrakeAction(Vehicle node){

        this.node = node;

        }

        @Override

        publicvoid performAction(InputActionEvent e) {

        node.brake(e.getTime());

        Vector3f loc = node.getLocalTranslation();

        loc.addLocal(

        node.getLocalRotation().getRotationColumn(2,tempVa)

        .multLocal(node.getVelocity()*e.getTime())

        );

        node.setLocalTranslation(loc);

        }

        }

        6.8、VehicleRotateLeftAction.java

        import lesson6.Vehicle;

        import com.jme.input.action.InputAction;

        import com.jme.input.action.InputActionEvent;

        import com.jme.math.Matrix3f;

        import com.jme.math.Vector3f;

        publicclass VehicleRotateLeftAction extends InputAction {

        //處理旋轉(zhuǎn)的臨時變量

        privatestaticfinal Matrix3f incr = new Matrix3f();

        privatestaticfinal Matrix3f tempMa = new Matrix3f();

        privatestaticfinal Matrix3f tempMb = new Matrix3f();

        //我們使用Y軸作為上

        private Vector3f upAxis = new Vector3f(0,1,0);

        //操縱的結(jié)點(diǎn)

        private Vehicle vehicle;

        public VehicleRotateLeftAction(Vehicle vehicle){

        this.vehicle = vehicle;

        }

        @Override

        publicvoid performAction(InputActionEvent evt) {

        //我們想轉(zhuǎn)不同的方向,這取決于我們往哪個方向行駛

        if(vehicle.getVelocity() < 0) {

        incr.fromAngleNormalAxis(

        -vehicle.getTurnSpeed() * evt.getTime()

        , upAxis

        );

        } else {

        incr.fromAngleNormalAxis(

        vehicle.getTurnSpeed() * evt.getTime(),

        upAxis

        );

        }

        vehicle.getLocalRotation().fromRotationMatrix(

        incr.mult(

        vehicle.getLocalRotation()

        .toRotationMatrix(tempMa),

        tempMb

        )

        );

        vehicle.getLocalRotation().normalize();

        }

        }

        6.9、VehicleRotateRightAction.java

        import lesson6.Vehicle;

        import com.jme.input.action.InputAction;

        import com.jme.input.action.InputActionEvent;

        import com.jme.math.Matrix3f;

        import com.jme.math.Vector3f;

        publicclass VehicleRotateRightAction extends InputAction {

        //用于處理旋轉(zhuǎn)的臨時變量

        privatestaticfinal Matrix3f incr = new Matrix3f();

        privatestaticfinal Matrix3f tempMa = new Matrix3f();

        privatestaticfinal Matrix3f tempMb = new Matrix3f();

        //用于操作的結(jié)點(diǎn)

        private Vehicle vehicle;

        private Vector3f upAxis = new Vector3f(0, 1, 0);

        public VehicleRotateRightAction(Vehicle vehicle){

        this.vehicle = vehicle;

        }

        @Override

        publicvoid performAction(InputActionEvent evt) {

        if (vehicle.getVelocity() < 0) {

        incr.fromAngleNormalAxis(

        vehicle.getTurnSpeed() * evt.getTime(),

        upAxis

        );

        } else {

        incr.fromAngleNormalAxis(

        -vehicle.getTurnSpeed() * evt.getTime(),

        upAxis

        );

        }

        vehicle.getLocalRotation().fromRotationMatrix(

        incr.mult(

        vehicle.getLocalRotation()

        .toRotationMatrix(tempMa),

        tempMb

        )

        );

        vehicle.getLocalRotation().normalize();

        }

        }

        6.10、DriftAction.java

        import lesson6.Vehicle;

        import com.jme.input.action.InputAction;

        import com.jme.input.action.InputActionEvent;

        import com.jme.math.Vector3f;

        publicclass DriftAction extends InputAction {

        private Vehicle vehicle;

        private Vector3f tempVa = new Vector3f();

        public DriftAction(Vehicle vehicle) {

        this.vehicle = vehicle;

        }

        @Override

        publicvoid performAction(InputActionEvent evt) {

        vehicle.drift(evt.getTime());

        Vector3f loc = vehicle.getLocalTranslation();

        loc.addLocal(

        vehicle.getLocalRotation()

        .getRotationColumn(2, tempVa)

        .multLocal(

        vehicle.getVelocity() * evt.getTime()

        )

        );

        vehicle.setLocalTranslation(loc);

        }

        }

        6.11、總結(jié)

        就那樣,我們現(xiàn)在已經(jīng)創(chuàng)建自己的action去允許我們的vehicle以一種更真實的方式運(yùn)行。這將給我們一種控制玩家執(zhí)行特性的能力,包括后面的敵人。

        下一步,我們將看看改善terrain和圖形外觀。

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        jMonkeyEngine譯文FlagRush6(2)控制交通工具

        jMonkeyEngine譯文FlagRush6(2)控制交通工具:天氣有點(diǎn)冷,早上竟然出奇般的七點(diǎn)多就起床了,呵呵~~ 6.4 、 Actions 在第五課,我們創(chuàng)建一個 InputHandler ,它調(diào)用了 4 個分開的 InputAction : KeyNodeForwardAction , KeyNodeBackwardAction , KeyTurnLeftActi
        推薦度:
        標(biāo)簽: 控制 譯文 jMonkeyEngine
        • 熱門焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 麻豆最新国产剧情AV原创免费 | 曰韩无码AV片免费播放不卡 | 色窝窝免费一区二区三区| 亚洲AV无码专区在线播放中文| jzzjzz免费观看大片免费| 亚洲?V无码乱码国产精品| 国产成人无码免费网站| 中文字幕亚洲第一| 免费无码H肉动漫在线观看麻豆| 亚洲综合AV在线在线播放 | 最近中文字幕国语免费完整| 亚洲人成影院在线| 免费做爰猛烈吃奶摸视频在线观看 | 国产一区二区三区免费看| 爱情岛亚洲论坛在线观看 | 亚洲精品无码成人片久久不卡| 最近中文字幕免费mv视频7| 色偷偷亚洲男人天堂| 亚洲精品无码专区久久同性男| xvideos永久免费入口| 久久精品国产亚洲av成人| 91免费在线播放| 亚洲av日韩av永久在线观看| 亚洲国产午夜福利在线播放| 国产精品偷伦视频观看免费 | 日韩毛片免费无码无毒视频观看 | 全黄大全大色全免费大片| 久久久久亚洲AV无码网站| 成人毛片18女人毛片免费96| 免费无码午夜福利片| 久久久亚洲AV波多野结衣| 精品国产免费观看久久久 | 日本在线高清免费爱做网站| 亚洲AV无码一区二区三区久久精品| 亚洲国产精品第一区二区三区| 久久国产免费一区| 亚洲欧美日韩久久精品| 亚洲精品无码mv在线观看网站| 91网站免费观看| 久久99久久成人免费播放| 在线观看免费视频网站色|