Skip to navigation


3D geometry: SetObjectCoords (Part 8 of 11)

Name: SetObjectCoords (Part 8 of 11) [Show more] Type: Subroutine Category: 3D geometry Summary: Process the object Deep dive: 3D objects
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.objc9 \ By this point we have pre-processed any special \ objects, so now to process it \ We now translate the base location of the object, \ in (xObject, yObject, zObject), by subtracting the \ current plane coordinates (xPlane, altitude, zPlane) \ to give the vector from the plane's location to the \ object's location LDX GG \ Set X to the value of GG: \ \ * For bullets, this is the value of GG that is \ passed to the routine, i.e. 98 \ \ * For other objects, this is 216 + object ID, so \ points 216 to 255 contain the calculated \ coordinates for objects 0 to 39 \ \ So in the following, we set the coordinates of the \ point whose ID is in GG, i.e. point GG \ We do the following calculation with 24-bit values, \ so we can do the visibility checks. This means we \ calculate: \ \ xPoint = xObject - xPlane \ yPoint = yObject - yPlane \ zPoint = zObject - zPlane \ \ but in each case, the values have three bytes. To take \ the x-axis calculation: \ \ xPoint is (A xPointHi xPointLo) \ xObject is (0 xObjectHi xObjectLo) \ xPlane is (xPlaneTop xPlaneHi xPlaneLo) \ \ and we pass the top byte of the result, in A, to the \ CheckObjDistance routine, so it can be used in the \ visibility check (a high value in A means the object \ is a very long way away) SEC \ Set the x-coordinate of point GG: LDA xObjectLo,Y \ SBC xPlaneLo \ xPoint = xObject - xPlane STA xPointLo,X \ \ starting with the low bytes LDA xObjectHi,Y \ And then the high bytes SBC xPlaneHi STA xPointHi,X STA T \ Set T = xPointHi to pass to CheckObjDistance LDA #0 \ And then the top bytes SBC xPlaneTop JSR CheckObjDistance \ Check whether the object is close enough to be visible \ in the direction of the x-axis BNE objc10 \ If it is too far away to be visible, jump to objc10 to \ either move on to the next object in the group, or \ tidy up and return from the subroutine SEC \ Set the y-coordinate of point GG: LDA yObjectLo,Y \ SBC yPlaneLo \ yPoint = yObject - yPlane STA yPointLo,X \ \ starting with the low bytes LDA yObjectHi,Y \ And then the high bytes SBC yPlaneHi STA yPointHi,X STA T \ Set T = yPointHi to pass to CheckObjDistance LDA #0 \ And then the top bytes SBC yPlaneTop JSR CheckObjDistance \ Check whether the object is close enough to be visible \ in the direction of the y-axis BNE objc10 \ If it is too far away to be visible, jump to objc10 to \ either move on to the next object in the group, or \ tidy up and return from the subroutine SEC \ Set the z-coordinate of point GG: LDA zObjectLo,Y \ SBC zPlaneLo \ zPoint = zObject - zPlane STA zPointLo,X \ \ starting with the low bytes LDA zObjectHi,Y \ And then the high bytes SBC zPlaneHi STA zPointHi,X STA T \ Set T = zPointHi to pass to CheckObjDistance LDA #0 \ And then the top bytes SBC zPlaneTop JSR CheckObjDistance \ Check whether the object is close enough to be visible \ in the direction of the z-axis BNE objc10 \ If it is too far away to be visible, jump to objc10 to \ either move on to the next object in the group, or \ tidy up and return from the subroutine LDA #0 \ Set the matrix number so the call to SetPointCoords STA matrixNumber \ uses matrix 1 in the calculation, which will rotate \ the point by the plane's pitch, roll and yaw angles, \ transforming it from the outside world's frame of \ reference to the plane's frame of reference JSR SetPointCoords \ Rotate the coordinates for point GG: \ \ * For bullets, this is point 98 \ \ * For other objects, this is 216 + object ID, so \ points 216 to 255 will contain the calculated \ coordinates for objects 0 to 39 \ \ and update the coordinates in (xPoint, yPoint, zPoint) LDY objectId \ Fetch the object ID into Y LDA showLine \ If showLine is non-zero, which means the line is not BNE objc12 \ visible, jump to objc12 to return from the subroutine \ without setting bit 7 of the object's status byte LDA #%11000000 \ Set A = %11000000 to set bits 6 and 7 of the object's \ status byte, to denote that the object has had its \ coordinates calculated, and that it is visible BNE objc13 \ Jump to objc13 to set the object's status byte and \ return from the subroutine (this BNE is effectively a \ JMP as A is never zero)