Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
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  Discussions / Miscellaneous Topics / Re: LWJGL collision with map and camera. on: 2013-10-28 00:10:53
I guess that isn't possible like that cause your FPS camera is just a single coordinate and a collision would only occur if the point is really inside one of the Triangles of your object which won't be the case i think. The fact that the camera movement is with sin and cos makes it be coordinates like this for example: 0.53423f etc. for each coordinate which will absolutely never be 100% on a Triangle. Checking collisions between a Face and some moving Point isn't that easy, but i guess if you save the Old Coordinate and the new Coordinate of the Camera and check if a line between those Coordinates touches a Triangle, that would work better no?

I got a deja-vu feeling I replied here already, but how or what is the best way to do it? What should I use instead of triangles? My OBJ loader is kind of depending on it.
2  Discussions / Miscellaneous Topics / LWJGL collision with map and camera. on: 2013-10-27 15:59:07
Hello,

I have a camera in my project. Basically it is based upon lloyd goodall's FPS camera found here: http://www.lloydgoodall.com/lwjgl-fpcamera.shtml, but I will post my code anyway;

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  
public class Camera {
   public Vector3f position = null;
   private float yaw = 0.0f;
   private float pitch = 0.0f;
   //private long dtime = System.currentTimeMillis();
  boolean jumping = false;
   boolean falling = false;
   
   public Camera(float x, float y, float z){
      position = new Vector3f(x,y-3.5f,z+20.0f);

   }
   
   public void yaw(float amount){
      yaw += amount;
   }
   
   public void pitch(float amount){
      if(amount <=180 && amount >= -180){
         pitch -= amount;  
      }
   }
   
   public void walkForward(float distance){
      position.x -= distance * (float)Math.sin(Math.toRadians(yaw));
      position.z += distance * (float)Math.cos(Math.toRadians(yaw));
   }
   
   public void walkBackwards(float distance){
      position.x += distance * (float)Math.sin(Math.toRadians(yaw));
      position.z -= distance * (float)Math.cos(Math.toRadians(yaw));
   }
   public void strafeLeft(float distance){
      position.x -= distance * (float)Math.sin(Math.toRadians(yaw-90));
      position.z += distance * (float)Math.cos(Math.toRadians(yaw-90));
   }
   
   public void strafeRight(float distance){
      position.x -= distance * (float)Math.sin(Math.toRadians(yaw+90));
      position.z += distance * (float)Math.cos(Math.toRadians(yaw+90));
   }
   
   public void jump(float distance){
      position.y -= distance * (float)Math.sin(Math.toRadians(yaw));
   }

   public void lookThrough(){
      // Pitch up.
     if(pitch >= -50){
         glRotatef(pitch,1.0f,0.0f,0.0f);
      }else if (pitch <= -50){
         pitch+= (8) + (Math.sin(8));
      }
      // Pitch down.
     if(pitch <= 50){
         glRotatef(pitch,1.0f,0.0f,0.0f);
      }else if (pitch >= 50){
         pitch-= (8) - (Math.sin(8));
      }
      glRotatef(yaw, 0.0f, 1.0f, 0.0f);
      glTranslatef(position.x, position.y, position.z);
   }
}


And I have loaded a map with a custom OBJ loader. The entire map is just one OBJ file. I did this with;

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  
public void loadModel(String model){
      Model m = null;
      try{
         m = OBJLoader.loadModel(new File(model));
      }catch(FileNotFoundException e){
         e.printStackTrace();
      } catch(IOException e){
         e.printStackTrace();
      }
      glTranslatef(0, 0, -20);
      for(Face face : m.faces){
         glBegin(GL_TRIANGLES);
           Vector3f n1 = m.normals.get((int) face.normal.x - 1);
           glNormal3f(n1.x, n1.y, n1.z);
           Vector3f v1 = m.vertices.get((int) face.vertex.x - 1);
           glVertex3f(v1.x, v1.y, v1.z);

           Vector3f n2 = m.normals.get((int) face.normal.y - 1);
           glNormal3f(n2.x, n2.y, n2.z);
           Vector3f v2 = m.vertices.get((int) face.vertex.y - 1);
           glVertex3f(v2.x, v2.y, v2.z);

           Vector3f n3 = m.normals.get((int) face.normal.z - 1);
           glNormal3f(n3.x, n3.y, n3.z);
           Vector3f v3 = m.vertices.get((int) face.vertex.z - 1);
           glVertex3f(v3.x, v3.y, v3.z);
           glEnd();
      }
   }


This is based upon 2 other classes, but I am sure you get the idea.

Now as I descibed earlier, this OBJ model is the entire map, and I want collision between the camera and the map. What is the easiest way to do this?

EDIT: I noticed the OBJLoader had a loadModel function too. Not to be confused with the function above.

Thanks,  Smiley
3  Discussions / Miscellaneous Topics / Re: Capping the mouse and jumping. on: 2013-10-21 15:54:01
You need to limit the pitch, or whatever you want to call it.

for example:
1  
pitch = Math.min(Math.max(yaw+mouseDiff, MIN_PITCH), MAX_PITCH);


As for jumping, just subtract a number from your z and bound this number between 0 and a number, add a number to this and bound it every step to create gravity.

1  
2  
3  
void doJump() {
 if (z == 0) z -= 10;
}


and in your step:

1  
z = Math.min(0, z + gravity);


Now where does the pitch come in? Can you help me in forms of the code I provided? I suck at this.

EDIT: Oh, thought the pitch was jump related. That is what got me confused.

EDIT 2: Got it working with your code! Thank you Smiley He is jumping very fast though. Can I fix this?
4  Discussions / Miscellaneous Topics / Re: Capping the mouse and jumping. on: 2013-10-21 15:38:30
For the jumping part I add this code in my class that handles input:

1  
2  
3  
4  
5  
6  
if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)){
            jumping = true;
            if(jumping){
               
            }
        }


Now for the interesting. What should be inside

1  
if(jumping)


I have a camera class with a 3D vector for position. How can I use the Y-axis for jumping in it? The camera position is defined by:
1  
camera.position.y


Please help.
5  Discussions / Miscellaneous Topics / Capping the mouse and jumping. on: 2013-10-16 14:38:32
Hello everyone,

First of all, I don't know if my title makes sense. But I have followed http://www.lloydgoodall.com/tutorials/first-person-camera-control-with-lwjgl/ in order to get a sort of FPS camera going.

It works aaalmost perfectly, but if you look for example too much up, I end up looking upside down, and I can spin all the way around. Does anyone know how to "cap" the axis at a specific point to prevent this?

Yet another question, I am using this code to move also. But is there anyone who knows how to jump? I guess there is a lot of velocity and stuff involved, but can anyone give a good example?

Thanks,

EDIT: Kind of fixed the capping now by adding if statements in the lookThrough method inside the Camera class. Just checked if the axis hit a specific angle and increasing / decreasing the pitch by respective angle. Quick and dirty fix and the camera is jittering, but it works.
6  Game Development / Newbie & Debugging Questions / Re: Hot Code Replace problem. on: 2013-10-14 14:37:22
Your code works!

So it was my code all along. Thanks for your help, now I know that my settings in Eclipse are just fine.
7  Game Development / Newbie & Debugging Questions / Re: Hot Code Replace problem. on: 2013-10-14 14:30:04
By default, Eclipse changes entire methods, not individual lines of code. For a replaced method to  become effective, is has to be called. This means that when multiple threads are accessing this method, each may be executing its own version of the method.

Is there a way to solve it?

Anyhow, figured out something interesting. I set a breakpoint on "System.out.println" and it stopped running the code when it hit it, so I ran it a few times getting the same value of X printed out. I changed the value and then continued to run it, breaking a few times at the breakpoint. This worked though, the X value was showing the changed value.

So I guess it only works if I hit the breakpoints though. Weird, but a clue.
8  Game Development / Newbie & Debugging Questions / Re: Hot Code Replace problem. on: 2013-10-14 14:08:45
That worked for me. How are you trying to change it? Are you setting a break point?

I am not setting any breakpoints, just running it in Debug mode and it starts printing the value of X, I am trying to change the value and saving but it does not change.

You may check if there are any problems with automatic building. First look at the project icon in the project explorer view, if there is a exclamation mark at it then it possibly cannot build automatically.  You would have to open the "problems" view in "Window -> Show view -> problems". A window will popup. I've run to such problems several times and its pretty annoying.

I checked the "Problems" window, but there is nothing there it seems. And I do not think I have some exclamation mark if the "Package Explorer" is what you mean.
9  Game Development / Newbie & Debugging Questions / Hot Code Replace problem. on: 2013-10-14 13:25:34
Hello,

Up until I reformatted my computer and reinstalled Windows 8 on it, I have not been able to get Hotswapping working again. It worked fine before, but now it wont react at all. I am running a small segment of code to try it out;

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public class GameComponent {
   
   public static void main(String[] args) {
      GameComponent gc = new GameComponent();
      gc.run();
   }

   public void run(){
      int x = 0;
      boolean running = true;
      while(running)
      {
         System.out.println("X = " + x);
         x = 2;
      }
   }
}


With this I should be able to run it in Debug mode and change the X value to print something else, but it does not seem to work. All my settings in Eclipse is default and I am having "Build Automatically" checked. Is there any more suggestions? Someone on LWJGL IRC said something about the build path but I think everything is OK there too.

Thanks,
10  Discussions / Miscellaneous Topics / Re: Rate my coding timelapse. on: 2013-10-13 11:04:30
No problem. And it's just hotswapping, what else could one mean. :-)
11  Discussions / Miscellaneous Topics / Re: Rate my coding timelapse. on: 2013-10-10 13:08:58
About the timelapse - like the music Smiley I suggest You use static imports in Eclipse so You dont have to type GL11 everywhere (you can find it in Window -> Preferences -> Java -> Editor -> Content assist -> Favories).

And yeah, You would be fine flipping the player image in code. AFAIK TextureLoader.load takes a boolean parameter that indicates that.



Thanks for your response and your tips. I am using static imports now, just changed it. It is more efficient! :-) I'll see what parameters the TextureLoader takes when I get back home.
12  Discussions / Miscellaneous Topics / Re: Rate my coding timelapse. on: 2013-10-09 18:43:58
Yeah, I think I disabled it to break on some specific breakpoints too.
13  Discussions / Miscellaneous Topics / Re: Rate my coding timelapse. on: 2013-10-09 17:56:00
Run in debug-mode, F11 in Eclipse.
14  Discussions / Miscellaneous Topics / Re: Rate my coding timelapse. on: 2013-10-09 14:28:20
Thanks for your response! :-)

This was originally made for someone I know who wanted me to code a game from scratch. So I sat for a while explaining everything for him in the video. So it was kind of slow.

It turned out he didn't want to watch the footage for whatever reason so I didn't want to throw all the footage away, that's why I made it into a timelapse and thought I shared it with you. :-)

Again, thanks for watching and please let me know if I should do more of these.
15  Discussions / Miscellaneous Topics / Rate my coding timelapse. on: 2013-10-09 11:50:57
Hello guys,

This is my first post on this forum and I wanted to introduce myself with a timelapse. Please give feedback or something! :-)
<a href="http://www.youtube.com/v/SUn6UV6_vD4?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/SUn6UV6_vD4?version=3&amp;hl=en_US&amp;start=</a>

I am kind of new to LWJGL and Slick2D in general and the code is way beyond optimized.

Anyhow, thanks!  Roll Eyes
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 (75 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

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
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!