1

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.

asked Apr 3, 2012 at 15:55
1
  • anyone know how to accomplish this?? I know it probably involves trigonometry which I dont understand (yet)... Commented Apr 3, 2012 at 20:02

1 Answer 1

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.

answered Aug 24, 2012 at 10:25
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.