mirror of
https://github.com/irmen/prog8.git
synced 2024-09-30 15:57:06 +00:00
implemented hidden line removal
This commit is contained in:
parent
63a653cdf0
commit
c376e42092
@ -2,6 +2,8 @@
|
|||||||
%import cx16lib
|
%import cx16lib
|
||||||
%import conv
|
%import conv
|
||||||
|
|
||||||
|
; TODO add all other Elite's ships, show their name, advance to next ship on keypress
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
; storage for rotated coordinates
|
; storage for rotated coordinates
|
||||||
@ -9,10 +11,6 @@ main {
|
|||||||
word[shipdata.totalNumberOfPoints] rotatedy
|
word[shipdata.totalNumberOfPoints] rotatedy
|
||||||
word[shipdata.totalNumberOfPoints] rotatedz
|
word[shipdata.totalNumberOfPoints] rotatedz
|
||||||
|
|
||||||
|
|
||||||
; TODO hidden surface removal - this needs surfaces data and surface normal calculations.
|
|
||||||
; TODO add all other Elite's ships, show their name, advance to next ship on keypress
|
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
uword anglex
|
uword anglex
|
||||||
uword angley
|
uword angley
|
||||||
@ -25,7 +23,6 @@ main {
|
|||||||
cx16.GRAPH_clear()
|
cx16.GRAPH_clear()
|
||||||
print_ship_name()
|
print_ship_name()
|
||||||
|
|
||||||
|
|
||||||
repeat {
|
repeat {
|
||||||
rotate_vertices(msb(anglex), msb(angley), msb(anglez))
|
rotate_vertices(msb(anglex), msb(angley), msb(anglez))
|
||||||
|
|
||||||
@ -41,8 +38,8 @@ main {
|
|||||||
draw_lines_hiddenremoval()
|
draw_lines_hiddenremoval()
|
||||||
;draw_lines()
|
;draw_lines()
|
||||||
|
|
||||||
anglex -= 505
|
anglex += 217
|
||||||
angley += 217
|
angley -= 505
|
||||||
anglez += 452
|
anglez += 452
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,10 +142,8 @@ main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub draw_lines_hiddenremoval() {
|
sub draw_lines_hiddenremoval() {
|
||||||
; complex routine that draws the ship model based on its faces
|
; complex drawing routine that draws the ship model based on its faces,
|
||||||
; where it uses the surface normals to determine visibility.
|
; where it uses the surface normals to determine visibility.
|
||||||
; TODO use a pointer to the edges and points instead of indexing
|
|
||||||
|
|
||||||
memset(edgestodraw, shipdata.totalNumberOfEdges, true)
|
memset(edgestodraw, shipdata.totalNumberOfEdges, true)
|
||||||
ubyte @zp edgeIdx = 0
|
ubyte @zp edgeIdx = 0
|
||||||
ubyte @zp pointIdx = 0
|
ubyte @zp pointIdx = 0
|
||||||
@ -195,26 +190,19 @@ main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub facing_away(ubyte edgePointsIdx) -> ubyte {
|
sub facing_away(ubyte edgePointsIdx) -> ubyte {
|
||||||
; todo hidden line removal check
|
; simplistic visibility determination by checking the Z component of the surface normal
|
||||||
; ubyte p1x = shipdata.
|
ubyte p1 = shipdata.facesPoints[edgePointsIdx]
|
||||||
;
|
edgePointsIdx++
|
||||||
; word normal_z
|
ubyte p2 = shipdata.facesPoints[edgePointsIdx]
|
||||||
;
|
edgePointsIdx++
|
||||||
; def normal_z(self, points: Tuple) -> float:
|
ubyte p3 = shipdata.facesPoints[edgePointsIdx]
|
||||||
; p1 = self.rotated_coords[points[0]]
|
word p1x = rotatedx[p1] / 128
|
||||||
; p2 = self.rotated_coords[points[1]]
|
word p1y = rotatedy[p1] / 128
|
||||||
; p3 = self.rotated_coords[points[2]]
|
word p2x = rotatedx[p2] / 128
|
||||||
; # So for a triangle p1, p2, p3, if the vector U = p2 - p1 and the vector V = p3 - p1
|
word p2y = rotatedy[p2] / 128
|
||||||
; # then the normal N = U * V and can be calculated by:
|
word p3x = rotatedx[p3] / 128
|
||||||
; # Nx = UyVz - UzVy
|
word p3y = rotatedy[p3] / 128
|
||||||
; # Ny = UzVx - UxVz
|
return (p2x-p3x)*(p1y-p3y) - (p2y-p3y)*(p1x-p3x) > 0
|
||||||
; # Nz = UxVy - UyVx
|
|
||||||
; ux = p2[0]-p3[0]
|
|
||||||
; uy = p2[1]-p3[1]
|
|
||||||
; vx = p1[0]-p3[0]
|
|
||||||
; vy = p1[1]-p3[1]
|
|
||||||
; return ux*vy - uy*vx
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ubyte[shipdata.totalNumberOfEdges] edgestodraw
|
ubyte[shipdata.totalNumberOfEdges] edgestodraw
|
||||||
|
Loading…
Reference in New Issue
Block a user