• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java LWJGL float issue  RSS feed

 
Max svendsen
Greenhorn
Posts: 7
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
Hope i placed the thread the right place, couldnt see an Java OpenGL thread (not lwjgl either)

Okay so i've been sitting with this for about a day now, just a passion project so nothing really urgent-
This code is about boundaries, which this code is my first go at. Basicly i am using a camera method, which has a vector3f called position (of the camera) and when i do the controls everything works fine. -
- but when i then tried to activate my boundaries it didnt seem to work, and so i started going at it- and found that the positions (floats) seemed to reset back to 0,0,0 as the code exited the class, so i first off tried to store it directly from where it was changed (that i syso'd out to see that it was changing) and both the position.x(y,z) and the regular floats also had the correct value, so if pos.x = 1 so would float x.

But still it wouldnt seem to stay put- and whenever the class had been called and finished it would return 0 once more- so i made a few set get methods and tried that, still no pie, so i then decided to make a "player" class to store it in another class directly, which i thought would work, and at first it seemed- cause i syso'd the coordinates as i would set them which also showed (I.E float x = 1), so it should work- but then Again it seemed to reset the float, and after some time now again theorizing i decided to ask perhaps someone with a fresh view of things. My logic might be flawed in the code but keep in mind- i've tried solutions aplenty. So if anyone have a proper solution, have a go at it. Thank yo



Keep in mind that when saying "set X(Y,Z) to" it prints out the correct value.
Oh and, another thing i know i might have coded some things inproperly, i am fairly new to opengl.
- Please dont sent link's elsewhere or "read this to learn about X",
- but do feel free to pick and prod at my code, even call me names if necesary- thank you.

Thank you, hope you guys can lend me a hand =)
 
Stephan van Hulst
Saloon Keeper
Posts: 7969
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Max. Welcome to CodeRanch!

Your question isn't very clear. It's hard to tell which part exactly you're having problems with, that is, which variables you expect to have which values, and at what part in the code.

It would help if you posted an SSCCE.

Note that you can not make *any* guarantees about the state of your program, because your fields are not private. As far as I'm concerned, this program is completely undeterministic.
 
Max svendsen
Greenhorn
Posts: 7
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would post an error report- but there is none as the program runs smoothly- and the more or less exact issue is;

My float x,y and z of player is returning 0, which it should by no means.
I setCoords directly from where i calculate the movement (i.e forward), when i do it DOES however return a float that is accurate- but once it has set the value in Player, it returns 0.

Here is an example (using netbeans ide; console output);
set X to;-1.2239387
set Y to;-0.057934295
set Z to;1.7725245
getting X;0.0
getting Y;0.0
getting Z;0.0
pass

So as you see, when i then get X(Y,Z) it then returns 0, which it should not.

And to reply to your note, yes i am aware, but i did remove a few private and public notions trying to figure out or atleast narrow down weather that was the issue (I.E Vector3f Position used to be private)
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you getting the values from the same object you're setting the values of?
 
Max svendsen
Greenhorn
Posts: 7
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im not sure i understand what you're trying to say.

I am taking the camera's Vector3f Position (which does give the value) and then setting the coordinates X Y and Z in the player's set method. But when i then try to use the coordinates from the player's GET methods, they return 0.
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But is that the same player object? Because if you first set values, and then getting them returns the default values, it appears that a different object is used for getting the values.
 
Max svendsen
Greenhorn
Posts: 7
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is only 1 player object- Made the player class to store the value seeing as how getting the position.x(y,z) directly from the camera vector didnt work either.

The player has set and get for each coordinate, so the player has float x,y,z. And whenever the camera moves, it sets the coordinate's in the player class. And then when the camera moves it checks boundaries, where it gets the player coordinates, and when it tries to get them, it returns 0.

Im not sure if that answered it correctly as i am not exactly sure what you mean. Might just be lost in the logic here =)
 
Max svendsen
Greenhorn
Posts: 7
Chrome Java Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After quite some time i've managed to find the solution, using UUID i found out that my player object's flow (like said in the reply above made by Rob) made 4 different player objects, was quite difficult to realise. Which has now been resolved-

Thank you for the support, allowed me to through time find the proper solution by my self =)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!