Terrain Textures: Place By Latitude
by Andy Schatz · 07/03/2006 (11:22 am) · 1 comments
This is a relatively simple resource to implement and expand upon. Most of the changes are in the GUI, with only a few minor code changes.
This resource will allow you to define different sections of your map to have different placement rules, independent of terrain height or slope. It's particularly useful if, for instance, you want to use the automated terrain painter (instead of painting the terrain manually) but you want different sections of the map to have different looks. For instance, if you want the north end of your map to be snowy, but the southern end of your map to be warm, this sort of placement rule is very helpful.
Here's how to implement it (in TGE 1.4):
In engine/editor/terraformer.cc, add the following around line 1234:
In engine/editor/terraformer.h, add the following around line 143:
The next block is the one that actually defines the mask. Inside the double loop, we generate the 0.0-1.0 value based upon the y coordinate of the input value. Other functions can easily be created using this as a base.
In engine/editor/terraformerTexture.cc, add the following around line 351:
In creator/editor/EditorGui.cs, add the following around line 1527:
In creator/editor/EditorGui.gui, add the following around line 2847:
That's it! Terrain texture automation can really speed up workflow, and making new operations may help to make your game look distinct from the many other terrain-based Torque games out there.
This resource will allow you to define different sections of your map to have different placement rules, independent of terrain height or slope. It's particularly useful if, for instance, you want to use the automated terrain painter (instead of painting the terrain manually) but you want different sections of the map to have different looks. For instance, if you want the north end of your map to be snowy, but the southern end of your map to be warm, this sort of placement rule is very helpful.
Here's how to implement it (in TGE 1.4):
In engine/editor/terraformer.cc, add the following around line 1234:
ConsoleMethod( Terraformer, maskLatitude, bool, 6, 6, "(int dst_register, Filter arr, bool distort_factor, int distort_register)")
{
Filter filter;
filter.set(1, &argv[3]);
return object->maskLatitude( dAtoi(argv[2]), filter, dAtob(argv[4]), dAtoi(argv[5]) );
}In engine/editor/terraformer.h, add the following around line 143:
bool maskLatitude(U32 r_dst, const Filter &filter, bool distort, U32 r_distort);
The next block is the one that actually defines the mask. Inside the double loop, we generate the 0.0-1.0 value based upon the y coordinate of the input value. Other functions can easily be created using this as a base.
In engine/editor/terraformerTexture.cc, add the following around line 351:
bool Terraformer::maskLatitude(U32 r_dst, const Filter &filter, bool distort, U32 r_distort)
{
Heightfield *dst = getRegister(r_dst);
scale(r_dst, r_dst, 0.0f, 1.0f);
for (S32 y=0; y<blockSize; y++)
{
for (S32 x=0; x<blockSize; x++)
{
dst->val(x, y) = filter.getValue( ((F32)y)/blockSize );
}
}
if (distort)
{
Heightfield *d = getRegister(r_distort);
for (S32 i=0; i < (blockSize*blockSize); i++)
dst->val(i) *= d->val(i);
}
return true;
}In creator/editor/EditorGui.cs, add the following around line 1527:
Texture_operation_menu.add("Place by Latitude", 5);Same file, add around line 1665:case "Place by Latitude":
%id = Texture::addOperation("Place by Latitude\ttab_LatitudeMask\t" @ $nextTextureRegister++ @ "\t" @ %dreg @ "\ttextureLatitudeFilter\t0 0.2 0.4 0.6 0.8 1.0\tlatitudeDistort\ttrue");Same file around line 1871:case "Place by Latitude":
terraformer.maskLatitude( %reg, getField(%data,5), getField(%data,7), %dreg );Same file around line 2134:tab_LatitudeMask.setVisible(false);
In creator/editor/EditorGui.gui, add the following around line 2847:
new GuiControl(tab_LatitudeMask) {
profile = "GuiDefaultProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "2 0";
extent = "261 200";
minExtent = "8 8";
visible = "0";
helpTag = "0";
new GuiTextCtrl() {
profile = "GuiTextProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "4 1";
extent = "103 18";
minExtent = "8 8";
visible = "1";
helpTag = "0";
text = "Latitude Mask Settings:";
maxLength = "255";
};
new GuiTextCtrl() {
profile = "GuiTextProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "4 26";
extent = "26 18";
minExtent = "8 8";
visible = "1";
helpTag = "0";
text = "Filter:";
maxLength = "255";
};
new GuiFilterCtrl(TextureLatitudeFilter) {
profile = "GuiDefaultProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "46 26";
extent = "130 130";
minExtent = "8 8";
visible = "1";
command = "Texture::saveOperation();Texture::previewOperation();";
helpTag = "0";
controlPoints = "6";
filter = "0.000000 0.200000 0.400000 0.600000 0.800000 1.000000";
};
new GuiCheckBoxCtrl(latitudeDistort) {
profile = "GuiCheckBoxProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "45 165";
extent = "129 20";
minExtent = "8 8";
visible = "1";
command = "Texture::saveOperation();Texture::previewOperation();";
helpTag = "0";
text = "Use Fractal Distortion";
groupNum = "-1";
buttonType = "ToggleButton";
};
new GuiTextEditSliderCtrl() {
profile = "GuiTextEditProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "185 134";
extent = "64 18";
minExtent = "8 8";
visible = "1";
variable = "TextureLatitudeFilter.controlPoints";
command = "TextureLatitudeFilter.controlPoints = $ThisControl.getValue();Texture::saveOperation();Texture::previewOperation();";
helpTag = "0";
maxLength = "255";
historySize = "0";
password = "0";
tabComplete = "0";
format = "%3.0f";
range = "2 20";
increment = "1";
};
new GuiTextCtrl() {
profile = "GuiTextProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "185 115";
extent = "69 18";
minExtent = "8 8";
visible = "1";
helpTag = "0";
text = "Control Points:";
maxLength = "255";
};
};That's it! Terrain texture automation can really speed up workflow, and making new operations may help to make your game look distinct from the many other terrain-based Torque games out there.
About the author

Torque Owner Surge
MDNAMEDIA