Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 18 of 18

Thread: Model won't go to the coordinates I specified

  1. #1
    Junior Member
    Join Date
    Feb 2019
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question Model won't go to the coordinates I specified

    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:
    	ModelReader mre = new ModelReader();
            Iterator<?> it = ModelReader.getModFTNamesh().entrySet().iterator();
    	while (it.hasNext()) {
    		Map.Entry pair = (Map.Entry)it.next();
    		RawModel model = OBJLoader.loadObjModel((String) pair.getKey(), loader);
    		TexturedModel modelTex = new TexturedModel(model, new ModelTexture(loader.loadTexture((String) pair.getValue())), true);
    		Entity models = new Entity(modelTex, new Vector3f(mre.getX(), mre.getY(), mre.getZc()), 0,180,0,0.6f);
    		entities.add(models);
    		//it.remove();
     
    	    }
    			System.out.println(mre.getModFTNamesh() + "Model File & Texture File Names");
    			System.out.println(mre.getX() + "X coordinates");
    			System.out.println(mre.getY() + "X coordinates");
    			System.out.println(mre.getZc() + "Z coordinates");

    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:
    package engine.models;
     
    import com.opencsv.CSVReader;
    import com.opencsv.bean.CsvToBean;
    import com.opencsv.bean.CsvToBeanBuilder;
     
    import engine.models.textures.ModelTexture;
    import engine.objconverter.Vertex;
    imports... etc..
     
    import org.lwjgl.util.vector.Vector3f;
     
    /**
     * 
     * Reads the models.csv file
     * @author 
     *
     */
     
    public class ModelReader {
     
    	static int modelTotalNumber;
     
    	/*
    	 * 
    	 * Start of ArrayList for X,Y,Z coordinates
    	 */
    	//List<Float> x = new ArrayList<Float>();
    	//List<Float> y = new ArrayList<Float>();
    	//List<Float> z = new ArrayList<Float>();
    	/*
    	 * 
    	 * End of ArrayList for X,Y,Z coordinates
    	 */
     
    	/*
    	 * 
    	 * Start of HashMap test!
    	 */
    	static HashMap<String,String> modFTNamesh = new HashMap<String,String>();
    	static HashMap<Float, Float> xy = new HashMap<Float,Float>();
    	float x;
    	float y;
    	float zc;
    	public static HashMap<Float, Float> getXy() {
    		return xy;
    	}
     
    	public static HashMap<Float, Float> getZ() {
    		return z;
    	}
     
     
    	static HashMap<Float, Float> z = new HashMap<Float,Float>();
    	public static HashMap<String, String> getModFTNamesh() {
    		return modFTNamesh;
    	}
     
    	/*
    	 * 
    	 * End of Hashmap test!
    	 */
    	public ModelReader() {
     
    		try {
    			CSVReader reader = new CSVReader(new FileReader("res/read/models.csv"));
    			String[] nextLine;
    			int modelNum = 0;
    			while((nextLine = reader.readNext()) != null) {
    				modelNum++;
    				if(nextLine != null) {
    					String modelNumber = nextLine[0];
    					String modelName = nextLine[1];
    					String modelFileName = nextLine[2];
    					String modelTexture = nextLine[3];
    					String modelCoordX = nextLine[4];
    					String modelCoordY = nextLine[5];
    					String modelCoordZ = nextLine[6];
    					float modelCoordXFloat = Float.parseFloat(modelCoordX);
    					float modelCoordYFloat = Float.parseFloat(modelCoordY);
    					float modelCoordZFloat = Float.parseFloat(modelCoordZ);
    					zc = modelCoordZFloat;
    					x = modelCoordXFloat;
    					y = modelCoordYFloat;
     
    					/*
    					 * 
    					 * Start of HashMap 
    					 */
    					modFTNamesh.put(modelFileName, modelTexture);
    					xy.put(modelCoordXFloat, modelCoordYFloat);
    					z.put(modelCoordZFloat, 0f);
    					/*
    					 * 
    					 * End of Hashmap
    					 */
    				}
    			}
    		} catch(Exception e) {
    			System.out.println(e);
    		}	
    	}	
     
    	//get the value then get the row then get the x y z
     
     
    	public float getX() {
    		return x;
    	}
     
    	public float getY() {
    		return y;
    	}
     
    	public float getZc() {
    		return zc;
    	}
     
    	public static int getModelTotalNumber() {
    		return modelTotalNumber;
    	}
     
     
    }


    models csv file:
    1,stall,s2tall,stallTex,0f,10.0f,0f
    2,dragoon,dragon,test1,0f,0f,0f

    printLn result of coords and model filename and texture filename hashmap:
    Sun Feb 17 01:55:47 EET 2019 INFO:Use Java PNG Loader = true
    java.lang.ArrayIndexOutOfBoundsException: 1
    {s2tall=stallTex, dragon=test1}Model File & Texture File Names
    0.0X coordinates
    0.0X coordinates
    0.0Z coordinates



    Any help would be appreciated soooo much!!
    Thank you guys

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,324
    Thanks
    53
    Thanked 2,393 Times in 2,347 Posts

    Default Re: Model won't go to the coordinates I specified

    they are standing in the same coordinates which is 0,0,0
    Is that the expected location? Or is it a case of no values being read and the values are from uninitialized variables?

    java.lang.ArrayIndexOutOfBoundsException: 1
    Where is that exception happening?
    There should be a call to the printStackTrace method in the catch block to show where the exception happened.

    The code should check the size of the nextLine array before assuming that there are any elements in it at specific indexes. If the array's size is 1 there will not be a slot with index of 1.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    defiledx1 (February 16th, 2019)

  4. #3
    Junior Member
    Join Date
    Feb 2019
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Model won't go to the coordinates I specified

    Quote Originally Posted by Norm View Post
    Is that the expected location? Or is it a case of no values being read and the values are from uninitialized variables?


    Where is that exception happening?
    There should be a call to the printStackTrace method in the catch block to show where the exception happened.

    The code should check the size of the nextLine array before assuming that there are any elements in it at specific indexes. If the array's size is 1 there will not be a slot with index of 1.
    1. Yes that is the expected coordinates for the second 3D Model

    1,stall,s2tall,stallTex,0f,10.0f,0f
    2,dragoon,dragon,test1,[B]0f,0f,0f[/B]

    but the problem is that I want each model to be in its specified coordinates, but in my case the models (both 1 and 2) appear in the coordinates of model number 2..

    I'm stuck

    2. The ArrayIndexOutOfBoundsException isn't causing a problem so I won't worry about it now, I'm most worried about the coordinates...

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,324
    Thanks
    53
    Thanked 2,393 Times in 2,347 Posts

    Default Re: Model won't go to the coordinates I specified

    If the values are zero (default value for numeric variables) it looks like the code is not changing their values.
    A test would be to set the initial values to something other than 0 so you can quickly see if the variables are assigned a value. For example
    double someVar = -99.9;
    If you see -99 then you can guess the variable is not being assigned a value. Then track through the code to see why.

    won't worry about it
    Be sure to add a call to the printStackTrace method in the catch block.

    Also be sure to check the array's size before assuming there are values in it.
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    defiledx1 (February 16th, 2019)

  7. #5
    Junior Member
    Join Date
    Feb 2019
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Model won't go to the coordinates I specified

    Quote Originally Posted by Norm View Post
    If the values are zero (default value for numeric variables) it looks like the code is not changing their values.
    A test would be to set the initial values to something other than 0 so you can quickly see if the variables are assigned a value. For example
    double someVar = -99.9;
    If you see -99 then you can guess the variable is not being assigned a value. Then track through the code to see why.


    Be sure to add a call to the printStackTrace method in the catch block.

    Also be sure to check the array's size before assuming there are values in it.
    Thanks for the reply!

    Uhm, I've changed the coordinates, and same problem persisted...

    As you can see, the 2 models are in the same spot (x = 1, y = 1, z = 1) which are the coordinates set for model number 2.
    Screenshot_1.jpg

    and here you can see the println output:
    Screenshot_2.png

    and here you can see the coordinates set:
    modelNumber,modelName,modelFileName, ModelTEXTUREfileName, x coordinate(float), y coordinate(float), z coordinate (float)
    1,stall,s2tall,stallTex,2f,10.0f,5f
    2,dragoon,dragon,test1,1f,1f,1f

    I appreciate the time your taking to help me out !

  8. #6
    Junior Member
    Join Date
    Feb 2019
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Model won't go to the coordinates I specified

    Quote Originally Posted by Norm View Post
    Be sure to add a call to the printStackTrace method in the catch block.

    Also be sure to check the array's size before assuming there are values in it.
    I added a printStackTrace to the catch and this is what I got:

    java.lang.ArrayIndexOutOfBoundsException: 1
    java.lang.ArrayIndexOutOfBoundsException: 1
    	at engine.models.ModelReader.<init>(ModelReader.java:87)
    	at game.ExecuteMain.main(ExecuteMain.java:133)

  9. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,324
    Thanks
    53
    Thanked 2,393 Times in 2,347 Posts

    Default Re: Model won't go to the coordinates I specified

    Did you add code to test the size of the array? Was the size as expected?

    Another useful tool for debugging arrays is the Arrays class's toString method to display an array's contents:
      System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));

    I'm done for tonight. Back tomorrow.
    If you don't understand my answer, don't ignore it, ask a question.

  10. The Following User Says Thank You to Norm For This Useful Post:

    defiledx1 (February 16th, 2019)

  11. #8
    Junior Member
    Join Date
    Feb 2019
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Model won't go to the coordinates I specified

    Quote Originally Posted by Norm View Post
    Did you add code to test the size of the array? Was the size as expected?

    Another useful tool for debugging arrays is the Arrays class's toString method to display an array's contents:
      System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));

    I'm done for tonight. Back tomorrow.
    I'm not using an array, I'm using a Hashmap for the models, but the coords are straight data output from the CSVReader

    --- Update ---

    I'm done for tonight. Back tomorrow.
    Alright, Good Night!
    Thanks for the help!

  12. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,324
    Thanks
    53
    Thanked 2,393 Times in 2,347 Posts

    Default Re: Model won't go to the coordinates I specified

    I'm not using an array
    This line of code defines an array:
    			String[] nextLine;
    This line of code assigns it a value:
    while((nextLine = reader.readNext()) != null) {
    How many elements does that array hold?
    The code gets an exception when it tries to access the second slot in the array, but not the first slot. That says there is only one slot in the array.
    To see what is in the array use the Arrays class's toString method.
    If you don't understand my answer, don't ignore it, ask a question.

  13. The Following User Says Thank You to Norm For This Useful Post:

    defiledx1 (February 17th, 2019)

  14. #10
    Junior Member
    Join Date
    Feb 2019
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question Re: Model won't go to the coordinates I specified

    Quote Originally Posted by Norm View Post
    This line of code defines an array:
    			String[] nextLine;
    This line of code assigns it a value:
    while((nextLine = reader.readNext()) != null) {
    How many elements does that array hold?
    The code gets an exception when it tries to access the second slot in the array, but not the first slot. That says there is only one slot in the array.
    To see what is in the array use the Arrays class's toString method.
    I did the following in the end of the while((nextLine = reader.readNext()) != null) { loop:
    System.out.println("an ID "+ java.util.Arrays.toString(nextLine));
    System.out.println("Array length: " + nextLine.length);

    and got this:
    an ID [1, stall, s2tall, stallTex, 0f, 0f, 0f]
    Array length: 7
    an ID [2, dragoon, dragon, test1, 1f, 1f, 1f]
    Array length: 7


    Also I've made some major edits to the ModelReader class, but it still shows the second model in the second model's coordinates and the first model is not there.

    package engine.models;
     
    import com.opencsv.CSVReader;
    import com.opencsv.bean.CsvToBean;
    import com.opencsv.bean.CsvToBeanBuilder;
     
    import engine.models.entities.Entity;
    import engine.models.textures.ModelTexture;
    import engine.objconverter.Vertex;
    import game.ExecuteMain;
     
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.Reader;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import java.util.Scanner;
     
    import org.lwjgl.util.vector.Vector3f;
     
    /**
     * 
     * Reads the models.csv file
     * @author 
     *
     */
     
    public class ModelReader {
     
        static int modelTotalNumber;
     
        /*
         * 
         * Start of ArrayList for X,Y,Z coordinates
         */
        List<Float> x1 = new ArrayList<Float>();
        List<Float> y1 = new ArrayList<Float>();
     
        Entity entity;
     
        public Entity getEntity() {
            return entity;
        }
     
        public List<Float> getX1() {
            return x1;
        }
     
        public List<Float> getY1() {
            return y1;
        }
     
        public List<Float> getZ1() {
            return z1;
        }
     
     
        List<Float> z1 = new ArrayList<Float>();
        /*
         * 
         * End of ArrayList for X,Y,Z coordinates
         */
     
        /*
         * 
         * Start of HashMap test!
         */
        static HashMap<String,String> modFTNamesh = new HashMap<String,String>();
     
     
        public static HashMap<String, String> getModFTNamesh() {
            return modFTNamesh;
        }
     
        /*
         * 
         * End of Hashmap test!
         */
        public ModelReader() {
     
            try {
                CSVReader reader = new CSVReader(new FileReader("res/read/models.csv"));
                String[] nextLine;
                int modelNum = 0;
                while((nextLine = reader.readNext()) != null) {
                    modelNum++;
                    if(nextLine != null) {
                        String modelNumber = nextLine[0];
                        String modelName = nextLine[1];
                        String modelFileName = nextLine[2];
                        String modelTexture = nextLine[3];
                        String modelCoordX = nextLine[4];
                        String modelCoordY = nextLine[5];
                        String modelCoordZ = nextLine[6];
                        float modelCoordXFloat = Float.parseFloat(modelCoordX);
                        float modelCoordYFloat = Float.parseFloat(modelCoordY);
                        float modelCoordZFloat = Float.parseFloat(modelCoordZ);
                        x1.add(modelCoordXFloat);
                        y1.add(modelCoordYFloat);
                        z1.add(modelCoordZFloat);
                        modFTNamesh.put(modelFileName, modelTexture);
                        /*
                         * Testing
                         */
                        for(float x : x1) {
                        for(float y : y1) { 
                        for(float z : z1) {
                        Iterator it = modFTNamesh.entrySet().iterator();
                        while (it.hasNext()) {
                        Map.Entry pair = (Map.Entry)it.next();  
                        ModelLoader loader = ExecuteMain.getLoad();
                        RawModel model = OBJLoader.loadObjModel((String)pair.getKey(), loader);
                        TexturedModel modelTex = new TexturedModel(model, new ModelTexture(loader.loadTexture((String)pair.getValue())), true);
                        Entity models = new Entity(modelTex, new Vector3f(x,y,z), 0,180,0,0.6f);
                        entity = models;
                        }
                        }
                        }
                        }
                        /*
                         * Testing
                         */
                        /*
                         * 
                         * Start of HashMap 
                         */
     
     
                        /*
                         * 
                         * End of Hashmap
                         */
                    }
                }
            } catch(Exception e) {
                //e.printStackTrace();
                System.out.println(getModFTNamesh() + "Model File & Texture File Names");
                System.out.println(getX1() + "x coord");
                System.out.println(getY1() + "y coord");
                System.out.println(getZ1() + "z coord");
                //System.out.println("an ID "+ java.util.Arrays.toString(x1));
                System.out.println(e);
            }   
        }   
     
        //get the value then get the row then get the x y z
     
     
     
     
     
        public static int getModelTotalNumber() {
            return modelTotalNumber;
        }
     
     
    }

    Could you take a look at this part of the file?

                while((nextLine = reader.readNext()) != null) {
                    modelNum++;
                    if(nextLine != null) {
                        String modelNumber = nextLine[0];
                        String modelName = nextLine[1];
                        String modelFileName = nextLine[2];
                        String modelTexture = nextLine[3];
                        String modelCoordX = nextLine[4];
                        String modelCoordY = nextLine[5];
                        String modelCoordZ = nextLine[6];
                        float modelCoordXFloat = Float.parseFloat(modelCoordX);
                        float modelCoordYFloat = Float.parseFloat(modelCoordY);
                        float modelCoordZFloat = Float.parseFloat(modelCoordZ);
                        x1.add(modelCoordXFloat);
                        y1.add(modelCoordYFloat);
                        z1.add(modelCoordZFloat);
                        modFTNamesh.put(modelFileName, modelTexture);
                        /*
                         * Testing
                         */
                        for(float x : x1) {
                        for(float y : y1) { 
                        for(float z : z1) {
                        Iterator it = modFTNamesh.entrySet().iterator();
                        while (it.hasNext()) {
                        Map.Entry pair = (Map.Entry)it.next();  
                        ModelLoader loader = ExecuteMain.getLoad();
                        RawModel model = OBJLoader.loadObjModel((String)pair.getKey(), loader);
                        TexturedModel modelTex = new TexturedModel(model, new ModelTexture(loader.loadTexture((String)pair.getValue())), true);
                        Entity models = new Entity(modelTex, new Vector3f(x,y,z), 0,180,0,0.6f);
                        entity = models;
                        }
                        }
                        }
                        }

    Thank you!!

  15. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,324
    Thanks
    53
    Thanked 2,393 Times in 2,347 Posts

    Default Re: Model won't go to the coordinates I specified

    it still shows the second model in the second model's coordinates and the first model is not there.
    So the second model is ok.
    What does " first model is not there" mean? Where is "there"?

    Note: The nested for loops need to be indented to show there positions visually. All starting in the same column makes them hard to read and understand.

    Have you stopped getting Exceptions?
    Why so many debug print statements in the catch block?
    If you don't understand my answer, don't ignore it, ask a question.

  16. The Following User Says Thank You to Norm For This Useful Post:

    defiledx1 (February 17th, 2019)

  17. #12
    Junior Member
    Join Date
    Feb 2019
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Model won't go to the coordinates I specified

    The first model shows in the array when I System.out.println it, but in the game it doesn't show.

    also no i still get exceptions.. this is my whole console:

    Sun Feb 17 19:22:13 EET 2019 INFO:Use Java PNG Loader = true
    an ID [1, stall, s2tall, stallTex, 0f, 0f, 0f]
    Array length: 7
    an ID [2, dragoon, dragon, test1, 1f, 1f, 1f]
    Array length: 7
    java.lang.ArrayIndexOutOfBoundsException: 1
    {}Model File & Texture File Names
    [0.0, 1.0]x coord
    	at engine.models.ModelReader.<init>(ModelReader.java:101)
    	at game.ExecuteMain.main(ExecuteMain.java:137)
    [0.0, 1.0]y coord
    [0.0, 1.0]z coord
    java.lang.ArrayIndexOutOfBoundsException: 1

    also , i asked someone at campus today about the code, this was his reply:

    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.
    He's talking about the ModelReader.java class, is there anyway you could help me with that.. it probably is why the first model isn't rendering in-game

    thanks

  18. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,324
    Thanks
    53
    Thanked 2,393 Times in 2,347 Posts

    Default Re: Model won't go to the coordinates I specified

    i still get exceptions
    Where is the print statement that shows the array's contents? It needs to be immediately after the array has been assigned a value so that you can see what was in the line that caused the exception, BEFORE the code tries to access any elements in the array.

    The only print statement for the array's contents I see is commented out.
    If you don't understand my answer, don't ignore it, ask a question.

  19. The Following User Says Thank You to Norm For This Useful Post:

    defiledx1 (February 17th, 2019)

  20. #14
    Junior Member
    Join Date
    Feb 2019
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Model won't go to the coordinates I specified

    Quote Originally Posted by Norm View Post
    Where is the print statement that shows the array's contents? It needs to be immediately after the array has been assigned a value so that you can see what was in the line that caused the exception, BEFORE the code tries to access any elements in the array.

    The only print statement for the array's contents I see is commented out.
    I apologize, the code I gave you is without the print statement

    I have it at the end , before the end of the while((nextLine = reader.readNext()) != null) { code as shown:
                while((nextLine = reader.readNext()) != null) {
                    modelNum++;
                    if(nextLine != null) {
                        String modelNumber = nextLine[0];
                        String modelName = nextLine[1];
                        String modelFileName = nextLine[2];
                        String modelTexture = nextLine[3];
                        String modelCoordX = nextLine[4];
                        String modelCoordY = nextLine[5];
                        String modelCoordZ = nextLine[6];
                        float modelCoordXFloat = Float.parseFloat(modelCoordX);
                        float modelCoordYFloat = Float.parseFloat(modelCoordY);
                        float modelCoordZFloat = Float.parseFloat(modelCoordZ);
                        x1.add(modelCoordXFloat);
                        y1.add(modelCoordYFloat);
                        z1.add(modelCoordZFloat);
                        modFTNamesh.put(modelFileName, modelTexture);
                        /*
                         * Testing
                         */
                        for(float x : x1) {
                        for(float y : y1) { 
                        for(float z : z1) {
                        Iterator it = modFTNamesh.entrySet().iterator();
                        while (it.hasNext()) {
                        Map.Entry pair = (Map.Entry)it.next();  
                        ModelLoader loader = ExecuteMain.getLoad();
                        RawModel model = OBJLoader.loadObjModel((String)pair.getKey(), loader);
                        TexturedModel modelTex = new TexturedModel(model, new ModelTexture(loader.loadTexture((String)pair.getValue())), true);
                        Entity models = new Entity(modelTex, new Vector3f(x,y,z), 0,180,0,0.6f);
                        entity = models;
                        }
                        }
                        }
    System.out.println("an ID "+ java.util.Arrays.toString(nextLine));
    System.out.println("Array length: " + nextLine.length);
                        }

    EDIT:

    I placed it now after the first while loop (where nextLine has been assigned to a value) and this is what I got in my console:

    Sun Feb 17 20:22:59 EET 2019 INFO:Use Java PNG Loader = true
    an ID [1, stall, s2tall, stallTex, 0f, 0f, 0f]
    Array length: 7
    an ID [2, dragoon, dragon, test1, 1f, 1f, 1f]
    Array length: 7
    an ID []
    Array length: 1
    java.lang.ArrayIndexOutOfBoundsException: 1
     
    [B]THIS PART HERE IS SHOWN FROM THE CATCH EXCEPTION WHICH IS AT THE END AFTER THE MAIN WHILE LOOP: [/B]
    {s2tall=stallTex, dragon=test1}Model File & Texture File Names
    [0.0, 1.0]x coord
    [0.0, 1.0]y coord
    [0.0, 1.0]z coord
    java.lang.ArrayIndexOutOfBoundsException: 1
    	at engine.models.ModelReader.<init>(ModelReader.java:103)
    	at game.ExecuteMain.main(ExecuteMain.java:137)

    here is the code of the catch exception:

    		} catch(Exception e) {
    			e.printStackTrace();
    			System.out.println(getModFTNamesh() + "Model File & Texture File Names");
    			System.out.println(getX1() + "x coord");
    			System.out.println(getY1() + "y coord");
    			System.out.println(getZ1() + "z coord");
     
    			System.out.println(e);
    		}
    Last edited by defiledx1; February 17th, 2019 at 12:24 PM.

  21. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,324
    Thanks
    53
    Thanked 2,393 Times in 2,347 Posts

    Default Re: Model won't go to the coordinates I specified

    an ID []
    Array length: 1
    java.lang.ArrayIndexOutOfBoundsException: 1
    That shows an array with only one element.
    The code should test that array's length is >= 7 with an if statement
    If the length is not >=7 it should print an error message and skip the rest of the loop with a continue statement.


    Why have all the print statements in the catch block? The exception should never happen with the if statement I suggested.
    If you don't understand my answer, don't ignore it, ask a question.

  22. #16
    Junior Member
    Join Date
    Feb 2019
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Model won't go to the coordinates I specified

    Quote Originally Posted by Norm View Post
    That shows an array with only one element.
    The code should test that array's length is >= 7 with an if statement
    If the length is not >=7 it should print an error message and skip the rest of the loop with a continue statement.


    Why have all the print statements in the catch block? The exception should never happen with the if statement I suggested.
    Alright I've removed the print statements from the catch block

    and added this after the first while loop (nextLine ... etc..
                	if(!(nextLine.length >= 7)) 
                		continue;

    now the error is gone, thank you so much! but what about the first model not being in the game?

    this is my console currently:
    an ID [1, stall, s2tall, stallTex, 0f, 0f, 0f]
    Array length: 7
    an ID [2, dragoon, dragon, test1, 1f, 1f, 1f]
    Array length: 7

    Someone told me the following:
    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.
    that's probably why only the second model is appearing (dragoon) and not the first (stall), any thoughts .. I can't figure out what code to replace/edit

    the code from line 98 to 111:
    String modelNumber = nextLine[0];
                        String modelName = nextLine[1];
                        String modelFileName = nextLine[2];
                        String modelTexture = nextLine[3];
                        String modelCoordX = nextLine[4];
                        String modelCoordY = nextLine[5];
                        String modelCoordZ = nextLine[6];
                        float modelCoordXFloat = Float.parseFloat(modelCoordX);
                        float modelCoordYFloat = Float.parseFloat(modelCoordY);
                        float modelCoordZFloat = Float.parseFloat(modelCoordZ);
                        x1.add(modelCoordXFloat);
                        y1.add(modelCoordYFloat);
                        z1.add(modelCoordZFloat);
                        modFTNamesh.put(modelFileName, modelTexture);

    the code from line 115 to 129:

                        for(float x : x1) {
                        for(float y : y1) { 
                        for(float z : z1) {
                        Iterator it = modFTNamesh.entrySet().iterator();
                        while (it.hasNext()) {
                        Map.Entry pair = (Map.Entry)it.next();  
                        ModelLoader loader = ExecuteMain.getLoad();
                        RawModel model = OBJLoader.loadObjModel((String)pair.getKey(), loader);
                        TexturedModel modelTex = new TexturedModel(model, new ModelTexture(loader.loadTexture((String)pair.getValue())), true);
                        Entity models = new Entity(modelTex, new Vector3f(x,y,z), 0,180,0,0.6f);
                        entity = models;
                        }
                        }
                        }
                        }

    I appreciate your efforts to help me!

  23. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,324
    Thanks
    53
    Thanked 2,393 Times in 2,347 Posts

    Default Re: Model won't go to the coordinates I specified

    why only the second model is appearing (dragoon) and not the first (stall)
    The models need to be saved in some kind of list if you want more than just the last one to be available.
    If you don't understand my answer, don't ignore it, ask a question.

  24. #18
    Junior Member
    Join Date
    Feb 2019
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Model won't go to the coordinates I specified

    I did that! Thank you thank you thank you!!!!!!!!!!!!!!!!!

Similar Threads

  1. coordinates (GUI)
    By Django in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 8th, 2013, 09:24 AM
  2. Markov model
    By KobusJordaan in forum Algorithms & Recursion
    Replies: 1
    Last Post: October 19th, 2012, 09:06 PM
  3. Java Coordinates
    By qspec in forum Java Theory & Questions
    Replies: 1
    Last Post: September 13th, 2012, 10:15 PM
  4. Help with plotting x-y coordinates.
    By mixmagz in forum Object Oriented Programming
    Replies: 5
    Last Post: January 23rd, 2012, 08:41 AM
  5. Retrieve coordinates of other windows
    By Knox in forum AWT / Java Swing
    Replies: 1
    Last Post: April 10th, 2011, 02:03 PM

Tags for this Thread