Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Games Center / Cube World Projects / Re: Troubles with the 3D Camera on: 2013-08-11 18:31:33
This is one of the things that sets OpenGL apart from most other libraries like DirectX which tend to use left handed system by default.
Just a note... Modern OpenGL doesn't use one or the other. In the programmable pipeline, you need to construct your own projection and modelview matrices.

This is different from the fixed-function pipeline (glTranslate, glRotate, glOrtho, etc), which became deprecated five years ago.
Modern OpenGL? so OpenGL > 3?
"You need to construct your own projection and modelview matrices" sounds really hard... is this very complicated? I am asking, because I just started using OpenGL so I might swap to the "modernGL" Cheesy
Is there anything you can recommend to read or to look up?
2  Games Center / Cube World Projects / Re: Troubles with the 3D Camera on: 2013-08-11 18:14:59
OK, I see. OpenGL uses a right handed coordinate system, which means that unless you do something funky, positive z is pointing out of the screen towards you. You can try it with your right hand - put thumb, 1st and 2nd finger (or 1st, 2nd, 3rd if you're a pianist) at 90 degrees to each other. Then put it against the screen with thumb pointing right (x axis), 1st finger pointing up (y axis) and see where your second finger (z axis) points.

This is one of the things that sets OpenGL apart from most other libraries like DirectX which tend to use left handed system by default.
ahhh ok Cheesy moving in the positiv z direction looks like moving backwards. thank you Cheesy
looking forward and moving forward. yaw = 0, direction = 0
pos.z = cos(0 + 0)
pos.z = 1!!! so this should make the camera moving into the screen, but the opposite is true. I got it! Cheesy
3  Games Center / Cube World Projects / Re: Troubles with the 3D Camera on: 2013-08-11 17:57:48
right, my forward is not fixed.
and i don't give the movement direction as a fixed angle. I already calculate my direction every time i turn the camera.
and i think every movement will result in moving along the z & x axis Cheesy
I am just looking for the error in my code, why W = moving backwards, S = moving forward and maybe a little math explanation.
4  Games Center / Cube World Projects / Re: Troubles with the 3D Camera on: 2013-08-11 17:46:01
well, thanks for the reply, but jeah, thats not rly what I want Cheesy
This sounds correct for me:
1  
2  
3  
4  
void moveCamera(float direction) { // direction is in degrees
  pos.x += Math.sin(Math.toRadians(yaw + direction));
   pos.z += Math.cos(Math.toRadians(yaw + direction));
}

so lets say I look forward and move forward. yaw = 0, direction = 0
pos.x = 0;
pos.z = 1 * SPEED
This is correct math. But in fact it feels wrong, because pressing W for moving forward will make you moving backwards.! And thats what I don't understand.
5  Games Center / Cube World Projects / Troubles with the 3D Camera on: 2013-08-11 16:04:04
Hey Guys,
as I try to develop a little Voxel Engine to improve my 3D Skills I think this is the right place?

I started with some Cubes and Chunks and now I try to manage those Chunks... However, atm I have problems to set up a camera. I just want to fly around my Chunks and later implement a player, but for now I have trouble with the movement of the camera.

Here is my Camera.class:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.util.vector.Vector3f;
import static org.lwjgl.opengl.GL11.*;

public class Camera {  
   //3d vector to store the camera's position in
   //the rotation around the Y axis of the camera
   //the rotation around the X axis of the camera
   public Vector3f position = null;
    private float yaw = 0.0f;
    private float pitch = 0.0f;
   private float movementSpeed = 5.0f;
   private float mouseSensitivity = 0.5f;
   
   private float dtt;
 
    /**
     * Creates a new Camera that takes the starting x, y, z location<br>
     * Call the update() method every frame to use the camera<br>
     * Do not forget to set the movementSpeed(default 10) and mouseSensitivity (default 0.5) by calling the
     * setMovementSpeed() and setMouseSensitivity() methods
     *
     * @param x x location
     * @param y y location
     * @param z z location
     */

    public Camera(float x, float y, float z)
    {
        position = new Vector3f(x, y, z);
    }

    /**
     * updates the camera<br>
     * CALL THIS <b>BEFORE</b> YOU RENDER YOUR SCENE!<br>
     * @param dt deltaTime for indie movement
     */

    public void update(float dt) {
       
       // ignore this :D
      dtt = dtt + dt;
       if(dtt >= 1) {
          System.out.println(position);
          dtt = 0;
       }
         
        //control camera yaw from x movement from the mouse
       yaw(-Mouse.getDX() * mouseSensitivity);
        //control camera pitch from y movement from the mouse
       pitch(Mouse.getDY() * mouseSensitivity);
       
        if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
           moveCamera(0, movementSpeed*dt);
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
           moveCamera(180, movementSpeed*dt);
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
           moveCamera(90, movementSpeed*dt);
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
           moveCamera(270, movementSpeed*dt);
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
            flyUp(movementSpeed*dt);
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
            flyDown(movementSpeed*dt);
        }
        glLoadIdentity();
        lookThrough();
    }
   
    /**
     *    increment the camera's current yaw rotation
     * @param amount increment the yaw by the amount param
     */

    private void yaw(float amount) {
        yaw += amount;
        if(yaw > 359)
           yaw = yaw - 359;
        else if(yaw < 0)
           yaw = yaw + 360;
    }

    /**
     * increment the camera's current pitch rotation
     * @param amount increment the pitch by the amount
     */

    private void pitch(float amount) {
       pitch += amount;
       if(pitch > 90)
          pitch = 90;
       else if(pitch < -90)
          pitch = -90;
    }
   
    private void moveCamera(float direction, float distance) {
       position.x += Math.sin(Math.toRadians(yaw + direction)) * distance;
       position.z += Math.cos(Math.toRadians(yaw + direction)) * distance;
    }
   
    private void flyUp(float distance) {
       position.y += distance;
    }
   
    private void flyDown(float distance) {
       position.y -= distance;
    }

    /**
     * translates and rotate the matrix so that it looks through the camera
     */

    private void lookThrough() {
        //roatate the pitch around the X axis
       glRotatef(-pitch, 1.0f, 0.0f, 0.0f);
        //roatate the yaw around the Y axis
       glRotatef(-yaw, 0.0f, 1.0f, 0.0f);
        //translate to the position vector's location
       glTranslatef(-position.x, -position.y, -position.z);
    }
}

Maybe some of you can try out this class? There is something weird about the movement and I think thats because of positive and negative... Well I don't really got this Sad
I just wanted to write a camera based on this tutorial, but it seems not to work...
http://www.java-gaming.org/topics/creating-a-3d-camera/27906/view.html
 So 0 degrees should be moving forward, 180 degree backward, 270 right and 90 left.

Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (18 views)
2014-04-15 18:08:23

BurntPizza (15 views)
2014-04-15 03:46:01

UprightPath (28 views)
2014-04-14 17:39:50

UprightPath (13 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (54 views)
2014-04-10 04:04:31

BurntPizza (111 views)
2014-04-08 23:06:04

tom_mai78101 (212 views)
2014-04-05 13:34:39

trollwarrior1 (181 views)
2014-04-04 12:06:45

CJLetsGame (187 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!