Game Development Community

Creating a city of cubes

by Markus Rudolph · in Torque 3D Beginner · 10/05/2012 (8:26 am) · 6 replies

Hi,
I want to load some data from a database or a XML file and build a city consisting of simple cubes.
First it would be enough to create a map of cubes (e.g. 100 x 100 cubes) and then rotate the camera around it.
How can I do this in Torque 3D (preferably written in C++)?

#1
10/05/2012 (8:49 am)
I know you can build your City of Cubes based on values between 0 and 1 in a black and white image.
Works the same way as those Push Pin toys, where you put the toy over your hand and the pins press upward around your fingers.
But the method I know isn't coded, it's done graphically and can be static or animated.

Interesting topic you have here. Perhaps some of the members that write code can chime in with their thoughts.
#2
10/05/2012 (9:09 am)
cgchan.com/suicidator

now u need a pythone script to load your xml data into blender.
#3
10/05/2012 (1:39 pm)
You might want to start writing the logic in TorqueScript then move it to C++ when you're happy with the algorithm. Assuming you have your XML data ready to go, you can parse it with a SimXMLDocument like in this example.

For your cubes, I'd suggest starting with ConvexShape objects, which you can create in script like this:
new ConvexShape() {
   Material = "Grid512_OrangeLines_Mat";
   position = %x SPC %y SPC %z;
   rotation = "1 0 0 0";
   scale = %w SPC %d SPC %h;
   canSave = "1";
   canSaveDynamicFields = "1";

   surface = "0 0 0 1 0 0 0.5";
   surface = "0 1 0 0 0 0 -0.5";
   surface = "0.707107 0 0 0.707107 0 0.5 0";
   surface = "0 0.707107 -0.707107 0 0 -0.5 0";
   surface = "0.5 0.5 -0.5 0.5 -0.5 0 0";
   surface = "0.5 -0.5 0.5 0.5 0.5 0 0";
};
That will create a cube centred at (%x, %y, %z) with dimensions (%w, %d, %h).
#4
10/05/2012 (7:57 pm)
This is one reason I love T3D. The features for creating objects are gold!
#5
10/07/2012 (5:29 am)
OK thanks :).

Where do I have to insert that code? I started with the "empty" template from the T3D toolbox. I'm reading through the TorqueScript but a hint would be nice :-).

And how can I rotate the camera around the cube? It seems that the camera class has no setPosition method :-(.
#6
08/02/2013 (5:29 am)
Sorry for the ridiculous late reply. This code will be complex to use in the stock templates; in short, you need to use it somewhere on the server. That means in scripts/server. Maybe try the onServerCreated function (and make sure to add your shaped to MissionCleanup).

Or, you could use t3d-bones and add the code to the onStart() function.