2012-04-03 64 views
1

我爲我的遊戲使用了LibGDX,我希望鼠標移動播放器的「頭部」,例如。就像在Minecraft中一樣。我將如何實現這一目標?我已經得到了它的工作與偏航和瀝青價值glRotateF什麼被渲染,但鼠標移到窗外(顯然)一段時間後右轉。我曾嘗試使用機器人類將指針位置重置爲屏幕中心,但導航幾乎不可能。如何製作鼠標導航?

這裏是我的播放器類:

package com.amzoft.gdxracingtestgamething; 

import com.badlogic.gdx.Gdx; 
import com.badlogic.gdx.InputProcessor; 
import com.badlogic.gdx.graphics.GL11; 

public class Player implements InputProcessor{ 

    int pitch = 0; 
    int yaw = 0; 

    public Player() 
    { 

    } 

    public void render() 
    { 
     GL11 gl = Gdx.gl11; 
     gl.glRotatef(-yaw, 0, 1, 0); 
     gl.glRotatef(-pitch, 1, 0, 0); 
    } 

    /*....a ton of unused implemented methods*/ 

    int xBefore = 0; 
    int yBefore = 0; 

    @Override 
    public boolean touchMoved(int x, int y) 
    { 
     if(xBefore<x-3) 
     { 
      yaw += 1; 
     } 
     if(xBefore>x+3) 
     { 
      yaw -= 1; 
     } 
     if(yBefore<y-3) 
     { 
      pitch -= 1; 
     } 
     if(yBefore>y+3) 
     { 
      pitch += 1; 
     } 
     if(yaw > 90)yaw = 90; 
     if(yaw < -90)yaw = -90; 
     if(pitch > 90)pitch = 90; 
     if(pitch < -90)pitch = -90; 
     xBefore = x; 
     yBefore = y; 
     return true; 
    } 

    @Override 
    public boolean scrolled(int amount) 
    { 
     return false; 
    } 

} 

對不起,如果該解決方案是非常明顯的,我是很新的3D遊戲開發和LibGDX。

+0

任何人都知道如何做到這一點?我知道它可能涉及三角我不明白(但)... – Nik 2012-04-03 20:02:32

回答

1

三角函數:) 我使用gluLookAt讓相機查看由偏航和俯仰的正弦,餘弦和負餘弦計算出的座標。它工作得很好。