• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Model won't go to the coordinates I specified  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
First off, I'm new to this website and it seems awesome! I hope we get to share knowledge!

Alright, I'm developing a game in lwjgl and I'm trying to load the models basic information from a CSV file (model file name, texture file name, x, y, z coordinates, & rotations etc..), but I seem to have gotten into a wall..

I first load up the csv file and extract information while adding some of them into a hashmap as seen below in the ModelReader.java class, then I used these information that is in the hashmap in my main class in this way:

code that is used in my main method in my main class:


and when I run the game, I can see the 2 3d models, but they are standing in the same coordinates which is 0,0,0 and whenever I try to change the coordinates for a specific model in the csv file, they move together if I change in the first one, but in the second model nothing interesting happens.. I've tried making a hashmap for the coordinates but the same thing happens and when I println the coordinates it always shows as the first model's coordinates.. I've included the models.csv file and the output of the println.

Any help would be appreciated soooo much!!


ModelReader.java class:



models.csv file:


printLn result of coords and model filename and texture filename hashmap:




Any help would be appreciated soooo much!!
Thank you guys
 
Bartender
Posts: 5775
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only have one instance of x, y, and zc, per ModelReader object. You don't have one per file line.
 
Carey Brown
Bartender
Posts: 5775
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Almost never use "float" or "Float", use double and Double instead, they are usually more efficient and are the default types for floating point constants. Use "float" only in cases where you need to be compatible with legacy code.
 
Jake Martins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:Almost never use "float" or "Float", use double and Double instead, they are usually more efficient and are the default types for floating point constants. Use "float" only in cases where you need to be compatible with legacy code.



Ofcourse, but unfortunately Vector3f accepts 3 floats, but I could always cast it but it would be over redundants

Carey Brown wrote:You only have one instance of x, y, and zc, per ModelReader object. You don't have one per file line.



So what should I do exactly? make an enhanced for loop for the x,y,z in the main method of the main class? I already did that but it made the game extremely slow as I had to do 3 enhanced fors.. and it was useless same error as before..

Thank you for the time your taking to help me! I'm really thankful!

what do you think I should do?
 
Carey Brown
Bartender
Posts: 5775
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a guess because I don't know how you intend on accessing it (e.g. HashMap?).

It looks like you need a "Model" class (or something more appropriately named). For each line of the CSV you create a new Model, fill in the fields, and add it to your Map.


I suggest that you do not use float/double for the key into a map, any floating point round off errors may prevent you from finding what you're looking for. Can you look things up by modelNumber?
 
Jake Martins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:This is a guess because I don't know how you intend on accessing it (e.g. HashMap?).

It looks like you need a "Model" class (or something more appropriately named). For each line of the CSV you create a new Model, fill in the fields, and add it to your Map.


I suggest that you do not use float/double for the key into a map, any floating point round off errors may prevent you from finding what you're looking for. Can you look things up by modelNumber?



Thanks for the reply!

Uhm no I dont use the modelnumber to look up.. haven't got to that yet.
I'm gonna try what you wrote and get back to you asap!

thank you so much  !
 
Jake Martins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:This is a guess because I don't know how you intend on accessing it (e.g. HashMap?).

It looks like you need a "Model" class (or something more appropriately named). For each line of the CSV you create a new Model, fill in the fields, and add it to your Map.


I suggest that you do not use float/double for the key into a map, any floating point round off errors may prevent you from finding what you're looking for. Can you look things up by modelNumber?



Sorry to disturb you again!

I've done a version of what you said but in how my code is arranged and in a weird way you might say..
on System.out.println it shows me that everything is OK


but in the game it only shows the second model..

I've combined all the code into this class .. could you take a look and see if theres anything wrong?

ModelReader.java :


and this is the models.csv:


Thank you!




 
Carey Brown
Bartender
Posts: 5775
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jake Martins wrote:Uhm no I dont use the modelnumber to look up.. haven't got to that yet.
I'm gonna try what you wrote and get back to you asap!

Before getting to far along, perhaps you could tell us how these models are supposed to behave in your game. So, we'd need some requirements or use cases in order to keep you steered down the right track.
 
Sheriff
Posts: 24374
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks to me like lines 98 to 111 are supposed to process one model, which I assume is one line of the models.csv file.

Then I think you ought to do those lines for all lines in models.csv before carrying on to line 115 and so on, because it looks to me like they are supposed to be applied to all your models. Right now it looks to me like you're doing them for each model. (Correct indentation of your code would help a lot, but there's no } after line 111 so I'm pretty sure of what I'm saying.)

I'm also dubious about your static members; in object-oriented code they are often a way to make something happen with only the last thing processed. But I haven't looked closely enough to know for sure.
 
Carey Brown
Bartender
Posts: 5775
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jake Martins wrote:but in the game it only shows the second model..


What "game"? What data format is the "game" expecting?
 
Jake Martins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:

Jake Martins wrote:Uhm no I dont use the modelnumber to look up.. haven't got to that yet.
I'm gonna try what you wrote and get back to you asap!

Before getting to far along, perhaps you could tell us how these models are supposed to behave in your game. So, we'd need some requirements or use cases in order to keep you steered down the right track.



I'm really sorry, uhm I'm not sure how to explain how they behave but heres a try:

I load the models through Vector3f lwjgl obj loader & textures through Vector2f lwjgl tex loader & I manipulate my entities through the Entity class (I've pasted it down below)

then I load a model with its texture, coordinates, rotation, etc.. using this code: which I have explained within the code:




Entity.java:









 
Jake Martins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:It looks to me like lines 98 to 111 are supposed to process one model, which I assume is one line of the models.csv file.

Then I think you ought to do those lines for all lines in models.csv before carrying on to line 115 and so on, because it looks to me like they are supposed to be applied to all your models. Right now it looks to me like you're doing them for each model. (Correct indentation of your code would help a lot, but there's no } after line 111 so I'm pretty sure of what I'm saying.)

I'm also dubious about your static members; in object-oriented code they are often a way to make something happen with only the last thing processed. But I haven't looked closely enough to know for sure.



Hello,

from lines 98 to 111 : here Im getting whats in the csv file then adding "what I need from them" to arrays OR hashmaps, then using these array & hashmap(s) in the a loop with the model code

 
Jake Martins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:Is this an Android app?



No, this is a LWJGL 2 (OpenGL) Desktop 3D Game
 
Carey Brown
Bartender
Posts: 5775
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest that you temporarily put the CSV stuff aside and hard code data for a single entity and see if you can get that to display.
 
Jake Martins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:I would suggest that you temporarily put the CSV stuff aside and hard code data for a single entity and see if you can get that to display.



I have done that, and I have several trees that were hard coded + a player that was hard coded.
I'm trying to do the csv stuff so I could make a world editor that can save versions of models.csv files
 
Carey Brown
Bartender
Posts: 5775
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
posx, y, and z, don't appear to be used anywhere. Why are they Lists?
 
Jake Martins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:posx, y, and z, don't appear to be used anywhere. Why are they Lists?



oh sorry, I was testing something earlier, these aren't in use currently
 
Paul Clapham
Sheriff
Posts: 24374
55
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jake Martins wrote:from lines 98 to 111 : here Im getting whats in the csv file then adding "what I need from them" to arrays OR hashmaps, then using these array & hashmap(s) in the a loop with the model code



No; from lines 98 to 111 you get one line of the CSV file and add one entry to a HashMap.

And then from lines 115 to 129 you iterate through the HashMap entries you have so far (not necessarily all of them which you will eventually create) -- and not only that, you do that iteration once for the first row and eight times for the second row. And not only that, but the end result of each of those iterations is an Entity object -- however you only store the last of those nine Entity objects in the variable named Entity. All of the earlier ones are overwritten.

As it happens, this is exactly the same result you'd get by only using the last line of the CSV file.
 
Jake Martins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Jake Martins wrote:from lines 98 to 111 : here Im getting whats in the csv file then adding "what I need from them" to arrays OR hashmaps, then using these array & hashmap(s) in the a loop with the model code



No; from lines 98 to 111 you get one line of the CSV file and add one entry to a HashMap.

And then from lines 115 to 129 you iterate through the HashMap entries you have so far (not necessarily all of them which you will eventually create) -- and not only that, you do that iteration once for the first row and eight times for the second row. And not only that, but the end result of each of those iterations is an Entity object -- however you only store the last of those nine Entity objects in the variable named Entity. All of the earlier ones are overwritten.

As it happens, this is exactly the same result you'd get by only using the last line of the CSV file.



I did not mean any insult or injury, Im sorry if my cold response did that.

If by anychance you could advise me to a solution or a show me the way, I would really appreciate that!  I'm having the worst headache because of this code, but its part of the learning process :/

thanks a bunch for your analysis!
 
Jake Martins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I store the last one in the entity

I made a variable named entity and I made a getter and add the entity to my Entity arraylist that is found in my ExecuteMain.java class
   
In ModelReader.java          


In ExecuteMain.java:



so this one, i think is not a problem

but how can I read all the rows and colomns and run them to get every model I have in the csv file to be added into the entities arraylist and rendered?

thanks!
 
Paul Clapham
Sheriff
Posts: 24374
55
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jake Martins wrote:I did not mean any insult or injury, Im sorry if my cold response did that.



No, no, it's fine, I didn't notice anything adverse.

If by anychance you could advise me to a solution or a show me the way, I would really appreciate that!  I'm having the worst headache because of this code, but its part of the learning process :/

thanks a bunch for your analysis!



So you're starting with a CSV file. It looks to me like each line in the file is a model? And an Entity is supposed to contain a single model? If that's the case then your ModelReader class needs to produce a list of Entity objects, one for each model.

And if that's the case then ModelReader doesn't need lists of x, y, and z (it shouldn't have them anyway but that's another story) and it doesn't need that map for model files. Here's my rough sketch of what it should do for each line in the CSV file:

1. Read and interpret the data from one line of the CSV (that's lines 98 to 107).

2. Build an Entity from that data (that's lines 121 to 124, modified to use the data directly).

3. Add that to the ModelReader's list of Entity objects.

On the other hand if I have misunderstood the architecture of models and entities, then that isn't the way to do it.
 
Jake Martins
Greenhorn
Posts: 12
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Jake Martins wrote:I did not mean any insult or injury, Im sorry if my cold response did that.



No, no, it's fine, I didn't notice anything adverse.

If by anychance you could advise me to a solution or a show me the way, I would really appreciate that!  I'm having the worst headache because of this code, but its part of the learning process :/

thanks a bunch for your analysis!



So you're starting with a CSV file. It looks to me like each line in the file is a model? And an Entity is supposed to contain a single model? If that's the case then your ModelReader class needs to produce a list of Entity objects, one for each model.

And if that's the case then ModelReader doesn't need lists of x, y, and z (it shouldn't have them anyway but that's another story) and it doesn't need that map for model files. Here's my rough sketch of what it should do for each line in the CSV file:

1. Read and interpret the data from one line of the CSV (that's lines 98 to 107).

2. Build an Entity from that data (that's lines 121 to 124, modified to use the data directly).

3. Add that to the ModelReader's list of Entity objects.

On the other hand if I have misunderstood the architecture of models and entities, then that isn't the way to do it.



Thank you so much! I did that and it worked! Thank you thank you thank you!!!
 
You get good luck from rubbing the belly of a tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!