Skip to navigation

Lander on the Acorn Archimedes

Landscape: GetLandscapeBelowVertex

Name: 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 objects
Context: 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
.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 subroutine