class Z80Lib3D::Primitives::Vertex
Z80Lib3D::Primitives::Vertex
¶ ↑
A 3 element Vector
and 2 screen coordinates:
-
vec
:Vector
-
xp
:byte
-
yp
:byte
-
scr
:word
alias ofyp
|xp
Constants
- S
A struct to represent
Vertex
instances
Public Class Methods
make(x, y, z, scrx0:128, scry0:128, scrz0:128, persp_dshift:7)
click to toggle source
Creates a Vertex
data argument for given coordinates.
# File lib/z80lib3d/primitives.rb, line 46 def Vertex.make(x, y, z, scrx0:128, scry0:128, scrz0:128, persp_dshift:7) x, y, z = x.round, y.round, z.round scrxmax = scrx0 * 2 - 1 scrymax = scry0 * 2 - 1 xp = ((x << persp_dshift) / (z + scrz0)) + scrx0 yp = -((y << persp_dshift) / (z + scrz0)) + scry0 if xp < 0 || xp > scrxmax || yp < 0 || yp > scrymax raise ArgumentError, "Vertex.make: vertex screen coordinates out of bounds" end S.new(Vector::S.new(z, y, x), xp, yp) end
make_many(*args, scrx0:128, scry0:128, scrz0:128, persp_dshift:7)
click to toggle source
Creates many Vertex
data arguments from triplets: [x, y, z].
# File lib/z80lib3d/primitives.rb, line 59 def Vertex.make_many(*args, scrx0:128, scry0:128, scrz0:128, persp_dshift:7) args.map{|x, y, z| Vertex.make(x, y, z, scrx0:scrx0, scry0:scry0, scrz0:scrz0, persp_dshift:persp_dshift)} end
scale(sc, vertex, scrx0:128, scry0:128, scrz0:128, persp_dshift:7)
click to toggle source
Creates a re-scaled Vertex
data arguments.
# File lib/z80lib3d/primitives.rb, line 64 def Vertex.scale(sc, vertex, scrx0:128, scry0:128, scrz0:128, persp_dshift:7) if vertex.is_a?(Array) vertex.map{|v| Vertex.scale(sc, v, scrx0:scrx0, scry0:scry0, scrz0:scrz0, persp_dshift:persp_dshift)} else vec = vertex.vec Vertex.make(vec.x*sc, vec.y*sc, vec.z*sc, scrx0:scrx0, scry0:scry0, scrz0:scrz0, persp_dshift:persp_dshift) end end