Skip to navigation

3D objects: GetObjectCoords

Name: GetObjectCoords [Show more] Type: Subroutine Category: 3D objects Summary: Get an object's coordinates
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * FollowGazeVector (Part 1 of 5) calls GetObjectCoords * GetRowVisibility (Part 1 of 2) calls GetObjectCoords

This routine fetches the cartesian coordinates of object #X as three 24-bit numbers, as follows: xCoord(Hi Lo Bot) yCoord(Hi Lo Bot) zCoord(Hi Lo Bot) The high byte can be thought of as the integer with low and bottom bytes as the fractional part. Tile corners are integers in the x- and z-axis, and objects are placed in the centre of tiles by setting the fractional part to 0.5. So an object that's been placed directly on the tile that's anchored at (2, y, 3) will appear at (2.5, y, 3.5). The y-coordinate - i.e. the altitude of the object above the tile itself - depends on the object type and whether it is stacked on top of another object.
Arguments: X An object number
.GetObjectCoords LDA #0 \ Set the bottom byte of each coordinate to zero STA xCoordBot STA yCoordBot STA zCoordBot LDA #128 \ Set the low byte of the x- and -z-coordinates to 128 STA xCoordLo \ (which represents 0.5, so the object sits in the STA zCoordLo \ middle of the tile on which it is placed) LDA yObjectLo,X \ Set the low byte of the y-coordinate to the altitude STA yCoordLo \ of object #X LDA xObject,X \ Set the high byte of the x-coordinate to the value for STA xCoordHi \ object #X from the xObject table LDA yObjectHi,X \ Set the high byte of the y-coordinate to the value for STA yCoordHi \ object #X from the yObjectHi table LDA zObject,X \ Set the high byte of the z-coordinate to the value for STA zCoordHi \ object #X from the zObject table RTS \ Return from the subroutine