.GetLandscapeBelowVertex STMFD R13!, {R8-R9, R14} \ Store the registers that we want to use on \ the stack so they can be preserved LDR R8, [R0] \ Add xCamera to the x-coordinate in R8 to LDR R1, [R11, #xCamera] \ get the vertex position in the game's ADD R8, R8, R1 \ world coordinate system LDR R9, [R0, #8] \ Add zCamera to the z-coordinate in R8 to LDR R1, [R11, #zCamera] \ get the vertex position in the game's ADD R9, R9, R1 \ world coordinate system SUB R9, R9, #LANDSCAPE_Z \ Move the z-coordinate forward by the \ landscape offset, as the altitude \ calculation needs the coordinate to be \ relative to the front-centre point of the \ landscape \ The (x, z) coordinate in (R8, R9) is now \ relative to the game's coordinate system, \ rather than the camera or the landscape \ offset, which is what we need in order \ to calculate the altitude of the landscape \ at this point BL GetLandscapeAltitude \ Set R0 to the altitude of the landscape at \ coordinates (x, z) = (R8, R9), which is \ the point directly below the vertex LDR R14, [R11, #yCamera] \ Subtract yCamera from the altitude so the SUB R0, R0, R14 \ result is relative to the camera position LDMFD R13!, {R8-R9, PC} \ Retrieve the registers that we stored on \ the stack and return from the subroutineName: GetLandscapeBelowVertex [Show more] Type: Subroutine Category: Landscape Summary: Calculate the landscape altitude directly below an object's vertex Deep dive: Generating the landscape Drawing 3D objectsContext: See this subroutine in context in the source code References: This subroutine is called as follows: * DrawObject (Part 2 of 5) calls GetLandscapeBelowVertex
Arguments: R0 The address containing the object's vertex (x, y, z), relative to the camera position
Returns: R0 The altitude (y-coordinate) of the landscape directly below the coordinate
[X]
Subroutine GetLandscapeAltitude (category: Landscape)
Calculate the altitude of the landscape for a given coordinate
[X]
Configuration variable LANDSCAPE_Z = LANDSCAPE_Z_DEPTH + (10 * TILE_SIZE)
The z-coordinate of the landscape offset, which is set to push the landscape away from the viewer by ten tile sizes
[X]
Configuration variable xCamera = &13C
The 3D x-coordinate of the camera position (though note that the camera position is actually at the back of the on-screen landscape, not the front)
[X]
Configuration variable yCamera = &140
The 3D y-coordinate of the camera position (though note that the camera position is actually at the back of the on-screen landscape, not the front)
[X]
Configuration variable zCamera = &144
The 3D z-coordinate of the camera position (though note that the camera position is actually at the back of the on-screen landscape, not the front, so the camera's z-coordinate is larger than it would be for a more traditional camera position; it is more like the camera's focal point than position, in a sense)