Skip to navigation

Lander on the Acorn Archimedes

Maths (Geometry): AddVectorToVertices

Name: AddVectorToVertices [Show more] Type: Subroutine Category: Maths (Geometry) Summary: Add a vector to the rotated vertex coordinates to get the vertex coordinates in 3D space
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * AddVectors calls AddVectorToVertices * DrawObject (Part 2 of 5) calls AddVectorToVertices

Calculate the following: [ xCoord ] [ R0 ] + [ xVertexRotated ] [ yCoord ] = [ R0+4 ] + [ yVertexRotated ] [ zCoord ] [ R0+8 ] + [ zVertexRotated ] This routine is only ever called with R0 = xObject, so this adds the rotated vertex coordinate to the object's coordinate, giving the vertex's coordinate in the game's coordinate system.
Arguments: R0 The address of the 3D vector to add in the above calculation
Other entry points: AddVectorToVertices+8 Enter the routine with R0 to R3 already set
.AddVectorToVertices LDMIA R0, {R0-R2} \ Fetch the coordinate from R0 into \ (R0, R1, R2) ADD R3, R11, #xVertexRotated \ Set R3 to the address of the coordinates \ in xVertexRotated STMFD R13!, {R5-R6} \ Store the registers that we want to use on \ the stack so they can be preserved LDMIA R3, {R3-R5} \ Fetch the vector at xVertexRotated into \ (R3, R4, R5) ADD R0, R0, R3 \ Set R0 = R0 + R3 \ = R0 + xVertexRotated ADD R1, R1, R4 \ Set R1 = R1 + R4 \ = R0+4 + yVertexRotated ADD R2, R2, R5 \ Set R2 = R2 + R5 \ = R0+8 + zVertexRotated ADD R3, R11, #xCoord \ Store (R0, R1, R2) in (xCoord, yCoord, STMIA R3, {R0-R2} \ zCoord) LDMFD R13!, {R5-R6} \ Retrieve the registers that we stored on \ the stack MOV PC, R14 \ Return from the subroutine