[XNA 4.0] Bounding box/sphere placement

Started by
5 comments, last by GWDev 12 years, 2 months ago
Hey

I have a question about placing multiple bounding boxes/spheres in the area of one model. Since this will be my first 3D project, please correct me if my assumptions are wrong. First I will give you the project background and the work I've done so far. I was offered by my college professor to work in a team of students that should create a simulator that represents an assembly line - since this is a complex project, my generation will only lay the foundations for the final product. My part is to create the graphical engine that will display the model of the assembly line (I've created the basic model, it is not pretty but it serves the purpose for now), get the commands from a file (most likely XML) and perform the appropriate actions. So far, I managed to display my model of the assembly line, and a simple box, and also I enabled the user to start, stop and restart the "process" - when the process is started, the box goes down the assembly line, if stop key is pressed it stops, and if restart is pressed, the box is placed at the start position. This is all very simple, but it is only the beginning. My next step is to make the box stop at certain locations without the users interventions (the assembly line has 3 "workstations", depending on the data provided by the XML file the box will have to stop at one or all of them) - I've done some reading and I see that the Bounding boxes or Bounding spheres are used for this type of problems. So my first question is which one will serve my purpose better? Second, do I have to create a Bounding box/sphere for both "workstation" and "box"? And third, and most important, how can I find the proper coordinates for my Bounding boxes/spheres - is there a way to determine them or will I have to hard code the coordinates and adjust them by experimenting?

If you have any suggestions concerning any part of this project, please share.
Thanks
Advertisement
Hello NDraskovic,

usually you get the dimensions of the model and adjust the boundingbox/shere.

Like explained here: http://www.toymaker.info/Games/XNA/html/xna_bounding_box.html

On a project i had some problems with some models doing that. (Probaly a mistake by me). As i had to solve it quick i simply worte a script that parsed all model files and calculated the boundboxes/sheres before the build. I simply included a (XML-)file, holding all the boundbox/shere information into the solution and parsed this onLoad. So i had my collision data ([color=#FF0000]works for NOT moving objects). It is the quick and dirty solution, but worked for me.

-- GWDev
Hey
I managed to solve this problem by hard coding the coordinates at which I want the box to stop - it's good enough for now. Will this cause problems if the published file is used on a computer that has different resolution?
Hey
I have a question that builds on to the previous one, so I think I don't need to make a new topic. This is the question - now that I have these workstations defined, and my program works fine (for a certain example), I want to add the possibility of enabling/disabling a certain workstation - that means that if a workstation is enabled the box will stop in front of it (and possibly trigger some other method), and if it is disabled the box will just pass it without any additional methods being triggered. I could hard code this, but I think that the program would be much more flexible if I used a XML file that would contain simple informations for each workstation (and starting and ending points). The first information would be enabled/disabled property, second increment counter possibility and so on.. My question is: is this solution possible and is it the optimal one, and can you give me a link to some tutorial that could help me solve this problem (using XML files or any other method you think is better). As for the XML files, they will be created by another application (that application is not being created by me, but I am allowed to suggest how the result file should look like), and should be loaded into my application during run-time.
Thanks
Hi NDraskovic,

that sounds like a good way to do it. You could give your 'workstation'-object simply the property (boolean) enabled. Than when parsing the XML file(s) with the workstation data you simply set this property.

To parse the file you could use the XMLReader Class (see MSDN) or buld your own with a FileReader and handling the XML Tags manually.

--GWDev

PS: I try to find my old implementation of this. If I can find it, I'll send it to you.

You could give your 'workstation'-object simply the property (boolean) enabled.

Yes, that is exactly what I'm trying to do, but I'm having a lot of problems with implementing my solution. First, if I use my own class as "Asset Type" in xml file then the compiler throws an error "MyProject.MyClass is an unknown type" (I'm not sure if that is the real text of the error, but you get the point). When I try to change it to something like System.String I get an error "Error while deserializing intermediate XML. 'Element' is an invalid XMLNodeType...."
I found a project on AppHub (here is the link) that uses XML files to control particle system - this is pretty complex, but I'm hoping that I will be able to see how they did it and apply similar solution to my project. The real problem is that I have to do practically everything - I designed the project (I got the "user request" from my professor but from there on I was on my own ), I created the models and did the programming, and I used only on-line materials (nobody on my college ever used XNA, at least nobody I know, so I can't consult with someone who already knows something about XNA or even game development ), - this is a great experience, I really learned a lot, but it takes a lot of time (and since I just got an internship in a company that is probably as far from game development as it gets, I am very limited with spare time). So if you have any ideas that might speed things up, I would be most grateful.
Hello NDrascovic,

if you serialize your workstation object to xml and open the created xml file in an editor you can search for the enabled/disabled property value. You have to make sure that this property is serialized with the rest of the object. Now you have a 'workstation'-xml template. Change around what you need and save it.

If you application now deserializes the xml to object it uses the values from the xml for the object. The xml files do not have to be part of the project as Visual Studio does not need to do anaything with it. You could use a openFileDialog to select the xmls that should be loaded or simply load everything in a directory.

--GWDev

This topic is closed to new replies.

Advertisement