Limiting the terrain that an actor can walk on

Some notes on things I learned: PNMImage uses 0 to [pixel dimension size] scheme for it’s coordinates, and the top left corner of the image is 0,0. So you need to map the terrain coordinates to the image coordinates.

Here’s an example:

I have a terrain image that is 1024x1024, and a terrain model that is 100 panda units square, with it’s origin in the middle. That means my terrain stretches from -50 to 50. To translate this, I use the following steps:

pandaX = pandaX + 50 #Converts from -50 to 50 range to 0 to 100 range
pandaX = pandaX / 100 #Converts from 0 to 100 range to 0-1 range (percentage)
imageX = int(pandaX * 1024) #Converts from percentage to number of pixels

Those steps would be duplicated for Y. You may also need to invert one of the coordinates, like I needed to invert my imageY coordinate. An easy way to figure that out is to texture your terrain with an image that has a different colored dot covering each corner, then load up the same image as a PNMImage and use print(image.getPixel(x,y)) to print the color of each corner of the image. That will tell you the image coordinates for each corner of your terrain.