09-23-2024, 03:40 PM
I'll try to explain it this way. I decided to include the skis. so I prepare everything before rendering. this ptv4 does that i invite this somewhere.
for example, I want a texture of any kind, in a given place, with a given normal vector calculation (2 types), with given texture coordinates, with a given fog type, and I parameterize whether this rectangle should be put in order (is it transparent and semi transparent part) This is of course called 6x for a cube. this is the insertion of a rectangle: not qb64, but basic.
Sub add_ptv4(lighttype As Int,nx As Float,ny As Float,nz As Float,SORT As Boolean,FOG As Byte,text As Int,t0 As Float,t1 As Float,t2 As Float,t3 As Float,t4 As Float,t5 As Float,t6 As Float,t7 As Float,d0 As Float,d1 As Float,d2 As Float,d3 As Float,d4 As Float,d5 As Float,d6 As Float,d7 As Float,d8 As Float,d9 As Float,d10 As Float,d11 As Float)
planf_vert(rend_dat(0)) = rend_dat(1)
' planf_txtc(rend_dat(0)) = rend_dat(2)
planf_poly(rend_dat(0)) = 4
planf_fog(rend_dat(0)) = FOG
planf_text(rend_dat(0)) = text
planf_sort(rend_dat(0)) = SORT
planf_lsun(rend_dat(0)) = False
If lighttype>0 Then planf_lsun(rend_dat(0)) = True
rend_dat(0) = rend_dat(0)+1
If lighttype = 1 Then
'planf normalvector FLAT -------------------------------------------------------------------------------------
Dim dis(4) As Float
dis(0) = (d0+d3+d6+d9)*.25-nx: dis(1) = (d1+d4+d7+d10)*.25-ny: dis(2) = (d2+d5+d8+d11)*.25-nz
For t = 0 To 3
rend_norm(rend_dat(1)+t*3+0) = dis(0): rend_norm(rend_dat(1)+t*3+2) = dis(1): rend_norm(rend_dat(1)+t*3+1) = dis(2)
Next
End If
If lighttype = 2 Then
'planf normalvector SMOOTH ------------------------------------------------------------------------------------------
rend_norm(rend_dat(1)+0) = d0-nx: rend_norm(rend_dat(1)+2) = d1-ny: rend_norm(rend_dat(1)+1) = d2-nz
rend_norm(rend_dat(1)+3) = d3-nx: rend_norm(rend_dat(1)+5) = d4-ny: rend_norm(rend_dat(1)+4) = d5-nz
rend_norm(rend_dat(1)+6) = d9-nx: rend_norm(rend_dat(1)+8) = d10-ny: rend_norm(rend_dat(1)+7) = d11-nz
rend_norm(rend_dat(1)+9) = d6-nx: rend_norm(rend_dat(1)+11) = d7-ny: rend_norm(rend_dat(1)+10) = d8-nz
End If
rend_vert(rend_dat(1)+0) = d0: rend_vert(rend_dat(1)+2) = d1: rend_vert(rend_dat(1)+1) = d2
rend_vert(rend_dat(1)+3) = d3: rend_vert(rend_dat(1)+5) = d4: rend_vert(rend_dat(1)+4) = d5
rend_vert(rend_dat(1)+6) = d9: rend_vert(rend_dat(1)+8) = d10: rend_vert(rend_dat(1)+7) = d11
rend_vert(rend_dat(1)+9) = d6: rend_vert(rend_dat(1)+11) = d7: rend_vert(rend_dat(1)+10) = d8
rend_dat(1) = rend_dat(1)+12
rend_txtc(rend_dat(2)+0) = t0: rend_txtc(rend_dat(2)+1) = t1: rend_txtc(rend_dat(2)+2) = t2: rend_txtc(rend_dat(2)+3) = t3
rend_txtc(rend_dat(2)+4) = t6: rend_txtc(rend_dat(2)+5) = t7: rend_txtc(rend_dat(2)+6) = t4: rend_txtc(rend_dat(2)+7) = t5
rend_dat(2) = rend_dat(2)+8
End Sub
The different parameters can be defined by planf vert/textc/poly (how many points define the planar 3/4 triangle, rectangle) /fog, text, sort
The relevant part will be important for you to understand!
you can see that it stores the vertices in the 'rend_vert' array, sequentially. for a rectangle, you can see, it increases the size by 12 coordinates. 12 coordinate points = 4 vertices = position of 4 points
rend_dat(1) is the counter of how many vertices are in the array.
The rend_norm array records the direction vectors belonging to the points. it also has rend_dat(1) as its counter, since it will have the same number of normal vectors as vertices.
you can see that sub gets d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11 . these are the 12 coordinate points mentioned above. x0y0z0, x1y1z1 ,x2y2z2 ,x3y3z3
these vertices !!!!
and the norm vector is based on these, and from the center of the object itself (the center of a cube, the center of a sphere, the center of whatever, from which the direction vectors start outward)
The center of the object is nx,ny,nz.
this sub must be called 6 times to insert the cube. all 6 times nx,ny,nz are unchanged! he is the center of the cube or sphere.
Knowing d0,d1,d2....,d11 and nx,ny,nz, there are 2 ways to create a normal vector (called lighttype in the code)
In one case, all points of the entire plane will point in 1 direction. (lighttype1) in the case of this cube, the rectangles falling in line should not have a staggered light.
In the other case, it calculates the normal vector directed exclusively from the center (lighttype2), which is nicer in the case of a sphere.
Both calculation methods can be used, there will be a small difference in the view.
there is one more very important thing !!!!!
The direction in which planar ridges are drawn.
all 6 sides must be approached in the correct order to the vertices. if one of them is not in sync with the others, there will be a negative light effect.
I also include the 'cube-insertion' sub, which contains the correct order of drawing the cube! this drawcube_direct inserts a cube into the render with the help of add_ptv4.
This may seem chaotic at first, but if you dig into it, you will get a feel for how to create the normal vector.
Sub drawcube_direct(lighttype As Int ,SORT As Boolean,FOG As Byte,x As Float, y As Float, z As Float, a1 As Float, a2 As Float, size As Float,texture As Int)
size = size/2
Dim p(4, 3), pc(8, 3) As Float 'Float
Dim side As Int
For t = 0 To 7
For t2 = 0 To 2
pc(t, t2) = size * math.cube_polars(t,t2) '+ cubes(makecube,0)
Next
math.rotate_2d (pc(t,0),pc(t,1),a1)
pc(t,0) = math.roti(0): pc(t,1) = math.roti(1)
math.rotate_2d (pc(t,0),pc(t,2),a2)
pc(t,0) = math.roti(0): pc(t,2) = math.roti(1)
pc(t,0) = pc(t,0)-x
pc(t,1) = pc(t,1)-z
pc(t,2) = pc(t,2)-y
Next
For t = 0 To 5
For t2 = 0 To 3
side = Asc("5476 0123 2367 1054 3175 0246".CharAt(t*5+t2))-48
For t3 = 0 To 2: p(t2, t3) = pc(side, t3)
Next
Next
add_ptv4 (lighttype,-x,-z,-y,SORT,FOG,texture,0,1,1,1,0,0,1,0,p(0,0),p(0,1),p(0,2),p(1,0),p(1,1),p(1,2),p(2,0),p(2,1),p(2,2),p(3,0),p(3,1),p(3,2))
Next
End Sub
for example, I want a texture of any kind, in a given place, with a given normal vector calculation (2 types), with given texture coordinates, with a given fog type, and I parameterize whether this rectangle should be put in order (is it transparent and semi transparent part) This is of course called 6x for a cube. this is the insertion of a rectangle: not qb64, but basic.
Sub add_ptv4(lighttype As Int,nx As Float,ny As Float,nz As Float,SORT As Boolean,FOG As Byte,text As Int,t0 As Float,t1 As Float,t2 As Float,t3 As Float,t4 As Float,t5 As Float,t6 As Float,t7 As Float,d0 As Float,d1 As Float,d2 As Float,d3 As Float,d4 As Float,d5 As Float,d6 As Float,d7 As Float,d8 As Float,d9 As Float,d10 As Float,d11 As Float)
planf_vert(rend_dat(0)) = rend_dat(1)
' planf_txtc(rend_dat(0)) = rend_dat(2)
planf_poly(rend_dat(0)) = 4
planf_fog(rend_dat(0)) = FOG
planf_text(rend_dat(0)) = text
planf_sort(rend_dat(0)) = SORT
planf_lsun(rend_dat(0)) = False
If lighttype>0 Then planf_lsun(rend_dat(0)) = True
rend_dat(0) = rend_dat(0)+1
If lighttype = 1 Then
'planf normalvector FLAT -------------------------------------------------------------------------------------
Dim dis(4) As Float
dis(0) = (d0+d3+d6+d9)*.25-nx: dis(1) = (d1+d4+d7+d10)*.25-ny: dis(2) = (d2+d5+d8+d11)*.25-nz
For t = 0 To 3
rend_norm(rend_dat(1)+t*3+0) = dis(0): rend_norm(rend_dat(1)+t*3+2) = dis(1): rend_norm(rend_dat(1)+t*3+1) = dis(2)
Next
End If
If lighttype = 2 Then
'planf normalvector SMOOTH ------------------------------------------------------------------------------------------
rend_norm(rend_dat(1)+0) = d0-nx: rend_norm(rend_dat(1)+2) = d1-ny: rend_norm(rend_dat(1)+1) = d2-nz
rend_norm(rend_dat(1)+3) = d3-nx: rend_norm(rend_dat(1)+5) = d4-ny: rend_norm(rend_dat(1)+4) = d5-nz
rend_norm(rend_dat(1)+6) = d9-nx: rend_norm(rend_dat(1)+8) = d10-ny: rend_norm(rend_dat(1)+7) = d11-nz
rend_norm(rend_dat(1)+9) = d6-nx: rend_norm(rend_dat(1)+11) = d7-ny: rend_norm(rend_dat(1)+10) = d8-nz
End If
rend_vert(rend_dat(1)+0) = d0: rend_vert(rend_dat(1)+2) = d1: rend_vert(rend_dat(1)+1) = d2
rend_vert(rend_dat(1)+3) = d3: rend_vert(rend_dat(1)+5) = d4: rend_vert(rend_dat(1)+4) = d5
rend_vert(rend_dat(1)+6) = d9: rend_vert(rend_dat(1)+8) = d10: rend_vert(rend_dat(1)+7) = d11
rend_vert(rend_dat(1)+9) = d6: rend_vert(rend_dat(1)+11) = d7: rend_vert(rend_dat(1)+10) = d8
rend_dat(1) = rend_dat(1)+12
rend_txtc(rend_dat(2)+0) = t0: rend_txtc(rend_dat(2)+1) = t1: rend_txtc(rend_dat(2)+2) = t2: rend_txtc(rend_dat(2)+3) = t3
rend_txtc(rend_dat(2)+4) = t6: rend_txtc(rend_dat(2)+5) = t7: rend_txtc(rend_dat(2)+6) = t4: rend_txtc(rend_dat(2)+7) = t5
rend_dat(2) = rend_dat(2)+8
End Sub
The different parameters can be defined by planf vert/textc/poly (how many points define the planar 3/4 triangle, rectangle) /fog, text, sort
The relevant part will be important for you to understand!
you can see that it stores the vertices in the 'rend_vert' array, sequentially. for a rectangle, you can see, it increases the size by 12 coordinates. 12 coordinate points = 4 vertices = position of 4 points
rend_dat(1) is the counter of how many vertices are in the array.
The rend_norm array records the direction vectors belonging to the points. it also has rend_dat(1) as its counter, since it will have the same number of normal vectors as vertices.
you can see that sub gets d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11 . these are the 12 coordinate points mentioned above. x0y0z0, x1y1z1 ,x2y2z2 ,x3y3z3
these vertices !!!!
and the norm vector is based on these, and from the center of the object itself (the center of a cube, the center of a sphere, the center of whatever, from which the direction vectors start outward)
The center of the object is nx,ny,nz.
this sub must be called 6 times to insert the cube. all 6 times nx,ny,nz are unchanged! he is the center of the cube or sphere.
Knowing d0,d1,d2....,d11 and nx,ny,nz, there are 2 ways to create a normal vector (called lighttype in the code)
In one case, all points of the entire plane will point in 1 direction. (lighttype1) in the case of this cube, the rectangles falling in line should not have a staggered light.
In the other case, it calculates the normal vector directed exclusively from the center (lighttype2), which is nicer in the case of a sphere.
Both calculation methods can be used, there will be a small difference in the view.
there is one more very important thing !!!!!
The direction in which planar ridges are drawn.
all 6 sides must be approached in the correct order to the vertices. if one of them is not in sync with the others, there will be a negative light effect.
I also include the 'cube-insertion' sub, which contains the correct order of drawing the cube! this drawcube_direct inserts a cube into the render with the help of add_ptv4.
This may seem chaotic at first, but if you dig into it, you will get a feel for how to create the normal vector.
Sub drawcube_direct(lighttype As Int ,SORT As Boolean,FOG As Byte,x As Float, y As Float, z As Float, a1 As Float, a2 As Float, size As Float,texture As Int)
size = size/2
Dim p(4, 3), pc(8, 3) As Float 'Float
Dim side As Int
For t = 0 To 7
For t2 = 0 To 2
pc(t, t2) = size * math.cube_polars(t,t2) '+ cubes(makecube,0)
Next
math.rotate_2d (pc(t,0),pc(t,1),a1)
pc(t,0) = math.roti(0): pc(t,1) = math.roti(1)
math.rotate_2d (pc(t,0),pc(t,2),a2)
pc(t,0) = math.roti(0): pc(t,2) = math.roti(1)
pc(t,0) = pc(t,0)-x
pc(t,1) = pc(t,1)-z
pc(t,2) = pc(t,2)-y
Next
For t = 0 To 5
For t2 = 0 To 3
side = Asc("5476 0123 2367 1054 3175 0246".CharAt(t*5+t2))-48
For t3 = 0 To 2: p(t2, t3) = pc(side, t3)
Next
Next
add_ptv4 (lighttype,-x,-z,-y,SORT,FOG,texture,0,1,1,1,0,0,1,0,p(0,0),p(0,1),p(0,2),p(1,0),p(1,1),p(1,2),p(2,0),p(2,1),p(2,2),p(3,0),p(3,1),p(3,2))
Next
End Sub