I am using LibGDX for my game and I want the mouse to move the "head" of the player, eg. like in Minecraft. How would I achieve this? I have got it to kinda work with yaw and pitch values that glRotateF what is being rendered, but the mouse moves outside the window (obviously) after a while of turning right. I have tried to use the robot class to reset the pointer position to the center of the screen but then navigation is nearly impossible.
Here is my player class:
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;
}
}
Im sorry if the solution is very obvious, I am very new to 3D game development and LibGDX.
-
anyone know how to accomplish this?? I know it probably involves trigonometry which I dont understand (yet)...Displayname1234– Displayname12342012年04月03日 20:02:32 +00:00Commented Apr 3, 2012 at 20:02
1 Answer 1
Trigonometry :) I used gluLookAt to make the camera look at the coordinates that were calculated from the sine, cosine and negative cosine of the yaw and pitch. It works pretty well.